From aef6a6243865c0ee0ac593470bd81936cd9b19ba Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 20 Mar 2024 20:03:23 +0000 Subject: [PATCH 1/2] Allow current user to join os/osd group during deb/rpm test Signed-off-by: Peter Zhu --- src/test_workflow/integ_test/distribution_deb.py | 6 ++++-- src/test_workflow/integ_test/distribution_rpm.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test_workflow/integ_test/distribution_deb.py b/src/test_workflow/integ_test/distribution_deb.py index dbaf0dec24..a26cbdb2fb 100644 --- a/src/test_workflow/integ_test/distribution_deb.py +++ b/src/test_workflow/integ_test/distribution_deb.py @@ -48,7 +48,9 @@ def install(self, bundle_name: str) -> None: '&&', f'sudo chmod 0666 {self.config_path}', '&&', - f'sudo chmod 0755 {os.path.dirname(self.config_path)} {self.log_dir}' + f'sudo chmod 0755 {os.path.dirname(self.config_path)} {self.log_dir}', + '&&', + f'sudo usermod -a -G {self.filename} `whoami`' ] ) subprocess.check_call(deb_install_cmd, cwd=self.work_dir, shell=True) @@ -59,4 +61,4 @@ def start_cmd(self) -> str: def uninstall(self) -> None: logging.info(f"Uninstall {self.filename} package after the test") - subprocess.check_call(f"sudo dpkg --purge {self.filename}", shell=True) + subprocess.check_call(f"sudo dpkg --purge {self.filename} && rm -rf {os.path.dirname(self.config_path)} {self.log_dir}", shell=True) diff --git a/src/test_workflow/integ_test/distribution_rpm.py b/src/test_workflow/integ_test/distribution_rpm.py index 9b8a6b4bc9..e74eec0c3f 100644 --- a/src/test_workflow/integ_test/distribution_rpm.py +++ b/src/test_workflow/integ_test/distribution_rpm.py @@ -61,4 +61,4 @@ def start_cmd(self) -> str: def uninstall(self) -> None: logging.info(f"Uninstall {self.filename} package after the test") - subprocess.check_call(f"sudo yum remove -y {self.filename}", shell=True) + subprocess.check_call(f"sudo yum remove -y {self.filename} && rm -rf {os.path.dirname(self.config_path)} {self.log_dir}", shell=True) From d877eebc5ac97e1997313e7dea7ea088ed801068 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 20 Mar 2024 20:49:32 +0000 Subject: [PATCH 2/2] Add more Signed-off-by: Peter Zhu --- ...est.almalinux8.systemd-base.x64.arm64.ppc64le.dockerfile | 2 +- ...est.ubuntu2004.systemd-base.x64.arm64.ppc64le.dockerfile | 2 +- .../test.rockylinux8.systemd-base.x64.arm64.dockerfile | 2 +- src/test_workflow/integ_test/distribution_deb.py | 2 +- src/test_workflow/integ_test/distribution_rpm.py | 6 ++++-- .../test_integ_workflow/integ_test/test_distribution_deb.py | 3 ++- .../test_integ_workflow/integ_test/test_distribution_rpm.py | 3 ++- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docker/ci/dockerfiles/current/test.almalinux8.systemd-base.x64.arm64.ppc64le.dockerfile b/docker/ci/dockerfiles/current/test.almalinux8.systemd-base.x64.arm64.ppc64le.dockerfile index 288535b6d4..72d31cc128 100644 --- a/docker/ci/dockerfiles/current/test.almalinux8.systemd-base.x64.arm64.ppc64le.dockerfile +++ b/docker/ci/dockerfiles/current/test.almalinux8.systemd-base.x64.arm64.ppc64le.dockerfile @@ -111,7 +111,7 @@ RUN dnf install -y sudo && \ usermod -a -G opensearch $CONTAINER_USER && \ usermod -a -G opensearch-dashboards $CONTAINER_USER && \ id && \ - echo "$CONTAINER_USER ALL=(root) NOPASSWD:`which systemctl`, `which env`, `which dnf`, `which yum`, `which rpm`, `which chmod`, `which kill`, `which curl`, /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin" >> /etc/sudoers.d/$CONTAINER_USER + echo "$CONTAINER_USER ALL=(root) NOPASSWD:`which systemctl`, `which env`, `which usermod`, `which dnf`, `which yum`, `which rpm`, `which chmod`, `which kill`, `which curl`, /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin" >> /etc/sudoers.d/$CONTAINER_USER # Copy from Stage0 COPY --from=linux_stage_0 --chown=$CONTAINER_USER:$CONTAINER_USER $CONTAINER_USER_HOME $CONTAINER_USER_HOME diff --git a/docker/ci/dockerfiles/current/test.ubuntu2004.systemd-base.x64.arm64.ppc64le.dockerfile b/docker/ci/dockerfiles/current/test.ubuntu2004.systemd-base.x64.arm64.ppc64le.dockerfile index 62d67698da..b87925ef71 100644 --- a/docker/ci/dockerfiles/current/test.ubuntu2004.systemd-base.x64.arm64.ppc64le.dockerfile +++ b/docker/ci/dockerfiles/current/test.ubuntu2004.systemd-base.x64.arm64.ppc64le.dockerfile @@ -129,7 +129,7 @@ RUN apt-get install -y sudo && \ usermod -a -G opensearch $CONTAINER_USER && \ usermod -a -G opensearch-dashboards $CONTAINER_USER && \ id && \ - echo "$CONTAINER_USER ALL=(root) NOPASSWD:`which systemctl`, `which env`, `which apt`, `which apt-get`, `which apt-key`, `which dpkg`, `which chmod`, `which kill`, `which curl`, `which tee`, /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin" >> /etc/sudoers.d/$CONTAINER_USER + echo "$CONTAINER_USER ALL=(root) NOPASSWD:`which systemctl`, `which env`, `which usermod`, `which apt`, `which apt-get`, `which apt-key`, `which dpkg`, `which chmod`, `which kill`, `which curl`, `which tee`, /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin" >> /etc/sudoers.d/$CONTAINER_USER # Copy from Stage0 COPY --from=linux_stage_0 --chown=$CONTAINER_USER:$CONTAINER_USER $CONTAINER_USER_HOME $CONTAINER_USER_HOME diff --git a/docker/ci/dockerfiles/legacy/test.rockylinux8.systemd-base.x64.arm64.dockerfile b/docker/ci/dockerfiles/legacy/test.rockylinux8.systemd-base.x64.arm64.dockerfile index 8160b8acf0..31c3d6aae9 100644 --- a/docker/ci/dockerfiles/legacy/test.rockylinux8.systemd-base.x64.arm64.dockerfile +++ b/docker/ci/dockerfiles/legacy/test.rockylinux8.systemd-base.x64.arm64.dockerfile @@ -111,7 +111,7 @@ RUN dnf install -y sudo && \ usermod -a -G opensearch $CONTAINER_USER && \ usermod -a -G opensearch-dashboards $CONTAINER_USER && \ id && \ - echo "$CONTAINER_USER ALL=(root) NOPASSWD:`which systemctl`, `which env`, `which dnf`, `which yum`, `which rpm`, `which chmod`, `which kill`, `which curl`, /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin" >> /etc/sudoers.d/$CONTAINER_USER + echo "$CONTAINER_USER ALL=(root) NOPASSWD:`which systemctl`, `which env`, `which usermod`, `which dnf`, `which yum`, `which rpm`, `which chmod`, `which kill`, `which curl`, /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin" >> /etc/sudoers.d/$CONTAINER_USER # Copy from Stage0 COPY --from=linux_stage_0 --chown=$CONTAINER_USER:$CONTAINER_USER $CONTAINER_USER_HOME $CONTAINER_USER_HOME diff --git a/src/test_workflow/integ_test/distribution_deb.py b/src/test_workflow/integ_test/distribution_deb.py index a26cbdb2fb..0068eb8bbe 100644 --- a/src/test_workflow/integ_test/distribution_deb.py +++ b/src/test_workflow/integ_test/distribution_deb.py @@ -61,4 +61,4 @@ def start_cmd(self) -> str: def uninstall(self) -> None: logging.info(f"Uninstall {self.filename} package after the test") - subprocess.check_call(f"sudo dpkg --purge {self.filename} && rm -rf {os.path.dirname(self.config_path)} {self.log_dir}", shell=True) + subprocess.check_call(f"sudo dpkg --purge {self.filename}", shell=True) diff --git a/src/test_workflow/integ_test/distribution_rpm.py b/src/test_workflow/integ_test/distribution_rpm.py index e74eec0c3f..49123451c7 100644 --- a/src/test_workflow/integ_test/distribution_rpm.py +++ b/src/test_workflow/integ_test/distribution_rpm.py @@ -50,7 +50,9 @@ def install(self, bundle_name: str) -> None: '&&', f'sudo chmod 0666 {self.config_path}', '&&', - f'sudo chmod 0755 {os.path.dirname(self.config_path)} {self.log_dir}' + f'sudo chmod 0755 {os.path.dirname(self.config_path)} {self.log_dir}', + '&&', + f'sudo usermod -a -G {self.filename} `whoami`' ] ) subprocess.check_call(rpm_install_cmd, cwd=self.work_dir, shell=True) @@ -61,4 +63,4 @@ def start_cmd(self) -> str: def uninstall(self) -> None: logging.info(f"Uninstall {self.filename} package after the test") - subprocess.check_call(f"sudo yum remove -y {self.filename} && rm -rf {os.path.dirname(self.config_path)} {self.log_dir}", shell=True) + subprocess.check_call(f"sudo yum remove -y {self.filename}", shell=True) diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py index ffced7adbe..ad59c10cda 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_deb.py @@ -48,7 +48,8 @@ def test_install(self, check_call_mock: Mock) -> None: "sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! " "dpkg --install opensearch.deb && " f"sudo chmod 0666 {self.distribution_deb.config_path} && " - f"sudo chmod 0755 {os.path.dirname(self.distribution_deb.config_path)} {self.distribution_deb.log_dir}" + f"sudo chmod 0755 {os.path.dirname(self.distribution_deb.config_path)} {self.distribution_deb.log_dir} && " + f"sudo usermod -a -G opensearch `whoami`" ), args_list[0][0][0], ) diff --git a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py index f60fed1034..d851b3773b 100644 --- a/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py +++ b/tests/tests_test_workflow/test_integ_workflow/integ_test/test_distribution_rpm.py @@ -48,7 +48,8 @@ def test_install(self, check_call_mock: Mock) -> None: "sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! " "yum install -y opensearch.rpm && " f"sudo chmod 0666 {self.distribution_rpm.config_path} && " - f"sudo chmod 0755 {os.path.dirname(self.distribution_rpm.config_path)} {self.distribution_rpm.log_dir}" + f"sudo chmod 0755 {os.path.dirname(self.distribution_rpm.config_path)} {self.distribution_rpm.log_dir} && " + f"sudo usermod -a -G opensearch `whoami`" ), args_list[0][0][0], )