Skip to content

Commit

Permalink
Add windows integTest to OpenSearch Clusters (#2761)
Browse files Browse the repository at this point in the history
* Add new setups

Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>

* Add windows integTest to OpenSearch Clusters

Signed-off-by: Your Name <you@example.com>
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>

* Restructure zip tests

Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>

Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
Signed-off-by: Your Name <you@example.com>
Co-authored-by: Your Name <you@example.com>
  • Loading branch information
peterzhuamazon and Your Name authored Oct 19, 2022
1 parent eadd668 commit 35bb902
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 4 deletions.
43 changes: 43 additions & 0 deletions src/test_workflow/integ_test/distribution_zip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import logging
import os
import subprocess

from system.zip_file import ZipFile
from test_workflow.integ_test.distribution import Distribution


class DistributionZip(Distribution):
def __init__(self, filename: str, version: str, work_dir: str) -> None:
super().__init__(filename, version, work_dir)

@property
def install_dir(self) -> str:
return os.path.join(self.work_dir, f"{self.filename}-{self.version}")

@property
def config_dir(self) -> str:
return os.path.join(self.install_dir, "config")

def install(self, bundle_name: str) -> None:
logging.info(f"Installing {bundle_name} in {self.install_dir}")
with ZipFile(bundle_name, "r") as zip:
zip.extractall(self.work_dir)

@property
def start_cmd(self) -> str:
start_cmd_map = {
"opensearch": "./opensearch-windows-install.bat",
"opensearch-dashboards": "./opensearch-dashboards.bat",
}
return start_cmd_map[self.filename]

def uninstall(self) -> None:
logging.info(f"Cleanup {self.work_dir}/* content after the test")
subprocess.check_call(f"rm -rf {self.work_dir}/*", shell=True)
2 changes: 2 additions & 0 deletions src/test_workflow/integ_test/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from test_workflow.integ_test.distribution import Distribution
from test_workflow.integ_test.distribution_rpm import DistributionRpm
from test_workflow.integ_test.distribution_tar import DistributionTar
from test_workflow.integ_test.distribution_zip import DistributionZip


class Distributions:
DISTRIBUTIONS_MAP = {
"tar": DistributionTar,
"rpm": DistributionRpm,
"zip": DistributionZip,
}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/test_workflow/integ_test/integ_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def execute_tests(self) -> TestComponentResults:
def execute_integtest_sh(self, endpoint: str, port: int, security: bool, test_config: str) -> int:
script = ScriptFinder.find_integ_test_script(self.component.name, self.repo.working_directory)
if os.path.exists(script):
cmd = f"{script} -b {endpoint} -p {port} -s {str(security).lower()} -v {self.bundle_manifest.build.version}"
cmd = f"bash {script} -b {endpoint} -p {port} -s {str(security).lower()} -v {self.bundle_manifest.build.version}"
self.repo_work_dir = os.path.join(
self.repo.dir, self.test_config.working_directory) if self.test_config.working_directory is not None else self.repo.dir
(status, stdout, stderr) = execute(cmd, self.repo_work_dir, True, False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import yaml
from requests.models import Response

from system.os import current_platform
from test_workflow.dependency_installer import DependencyInstaller
from test_workflow.integ_test.distribution import Distribution
from test_workflow.integ_test.distributions import Distributions
Expand Down Expand Up @@ -66,7 +67,8 @@ def __set_logging_dest(self) -> None:
def __remove_security(self) -> None:
self.security_plugin_dir = os.path.join(self.install_dir, "plugins", "securityDashboards")
if os.path.isdir(self.security_plugin_dir):
subprocess.check_call("./opensearch-dashboards-plugin remove --allow-root securityDashboards", cwd=self.executable_dir, shell=True)
plugin_script = "opensearch-dashboards-plugin.bat" if current_platform() == "windows" else "bash opensearch-dashboards-plugin"
subprocess.check_call(f"{plugin_script} remove --allow-root securityDashboards", cwd=self.executable_dir, shell=True)

with open(self.opensearch_dashboards_yml_dir, "w") as yamlfile:
yamlfile.close()
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import os
import unittest
from unittest.mock import MagicMock, Mock, patch

from test_workflow.integ_test.distribution_zip import DistributionZip


class TestDistributionZipOpenSearch(unittest.TestCase):

def setUp(self) -> None:

self.work_dir = os.path.join(os.path.dirname(__file__), "data")
self.product = "opensearch"
self.version = "2.4.0"
self.distribution_zip = DistributionZip(self.product, self.version, self.work_dir)

def test_distribution_zip_vars(self) -> None:
self.assertEqual(self.distribution_zip.filename, self.product)
self.assertEqual(self.distribution_zip.version, self.version)
self.assertEqual(self.distribution_zip.work_dir, self.work_dir)

def test_install_dir(self) -> None:
self.assertEqual(self.distribution_zip.install_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}"))

def test_config_dir(self) -> None:
self.assertEqual(self.distribution_zip.config_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}", "config"))

def test_install(self) -> None:
with patch("test_workflow.integ_test.distribution_zip.ZipFile") as mock_zipfile_open:
mock_zipfile_extractall = MagicMock()
mock_zipfile_open.return_value.__enter__.return_value.extractall = mock_zipfile_extractall

self.distribution_zip.install(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip"))

mock_zipfile_open.assert_called_with(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip"), "r")
mock_zipfile_extractall.assert_called_with(self.work_dir)

def test_start_cmd(self) -> None:
self.assertEqual(self.distribution_zip.start_cmd, "./opensearch-windows-install.bat")

@patch("subprocess.check_call")
def test_uninstall(self, check_call_mock: Mock) -> None:
self.distribution_zip.uninstall()
args_list = check_call_mock.call_args_list

self.assertEqual(check_call_mock.call_count, 1)
self.assertEqual(f"rm -rf {self.work_dir}/*", args_list[0][0][0])


class TestDistributionZipOpenSearchDashboards(unittest.TestCase):

def setUp(self) -> None:

self.work_dir = os.path.join(os.path.dirname(__file__), "data")
self.product = "opensearch-dashboards"
self.version = "2.4.0"
self.distribution_zip = DistributionZip(self.product, self.version, self.work_dir)

def test_distribution_zip_vars(self) -> None:
self.assertEqual(self.distribution_zip.filename, self.product)
self.assertEqual(self.distribution_zip.version, self.version)
self.assertEqual(self.distribution_zip.work_dir, self.work_dir)

def test_install_dir(self) -> None:
self.assertEqual(self.distribution_zip.install_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}"))

def test_config_dir(self) -> None:
self.assertEqual(self.distribution_zip.config_dir, os.path.join(self.work_dir, f"{self.product}-{self.version}", "config"))

def test_install(self) -> None:
with patch("test_workflow.integ_test.distribution_zip.ZipFile") as mock_zipfile_open:
mock_zipfile_extractall = MagicMock()
mock_zipfile_open.return_value.__enter__.return_value.extractall = mock_zipfile_extractall

self.distribution_zip.install(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip"))

mock_zipfile_open.assert_called_with(os.path.join(self.work_dir, "artifacts", "dist", f"{self.product}-min-{self.version}-windows-x64.zip"), "r")
mock_zipfile_extractall.assert_called_with(self.work_dir)

def test_start_cmd(self) -> None:
self.assertEqual(self.distribution_zip.start_cmd, "./opensearch-dashboards.bat")

@patch("subprocess.check_call")
def test_uninstall(self, check_call_mock: Mock) -> None:
self.distribution_zip.uninstall()
args_list = check_call_mock.call_args_list

self.assertEqual(check_call_mock.call_count, 1)
self.assertEqual(f"rm -rf {self.work_dir}/*", args_list[0][0][0])
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_execute_integtest_sh(self, mock_execute: Mock, mock_git: Mock, mock_tes
status = suite.execute_integtest_sh("test_endpoint", 1234, True, "with-security")

self.assertEqual(status, "test_status")
mock_execute.assert_called_once_with('./integtest.sh -b test_endpoint -p 1234 -s true -v 1.2.0',
mock_execute.assert_called_once_with('bash ./integtest.sh -b test_endpoint -p 1234 -s true -v 1.2.0',
os.path.join("dir", "test_working_directory"), True, False)

mock_test_result_data.assert_called_once_with(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any
from unittest.mock import MagicMock, Mock, PropertyMock, call, mock_open, patch

from system.os import current_platform
from test_workflow.dependency_installer import DependencyInstaller
from test_workflow.integ_test.service_opensearch_dashboards import ServiceOpenSearchDashboards

Expand Down Expand Up @@ -119,8 +120,9 @@ def test_start_without_security(self, mock_tarfile_open: Mock, mock_dump: Mock,
[call(os.path.join(self.work_dir, "opensearch-dashboards-1.1.0", "config", "opensearch_dashboards.yml"), "a")],
)

plugin_script = "opensearch-dashboards-plugin.bat" if current_platform() == "windows" else "bash opensearch-dashboards-plugin"
mock_check_call.assert_called_once_with(
"./opensearch-dashboards-plugin remove --allow-root securityDashboards",
f"{plugin_script} remove --allow-root securityDashboards",
cwd=os.path.join("test_work_dir", "opensearch-dashboards-1.1.0", "bin"),
shell=True
)
Expand Down

0 comments on commit 35bb902

Please sign in to comment.