Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial empty dictionary for None additional cluster configs in OSD IntegTest #3593

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def __setup_cluster_and_execute_test_config(self, config: str) -> int:
self.additional_cluster_config = self.test_config.integ_test.get("additional-cluster-configs")
logging.info(f"Additional config found: {self.additional_cluster_config}")

if self.additional_cluster_config is None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just initialize self.additional_cluster_config as empty directory and check the len or keys() method to check if it has any values? @peterzhuamazon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be done but right now I am just matching the OS side implementation.
We can improve this in later PRs.

Copy link
Member

@dblock dblock Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm late to this game, but assigning of a default should happen in the constructor, not inside the path of execution because it becomes a surprising side-effect of the latter.

Otherwise do self.additional_cluster_config or {} anywhere it's used.

self.additional_cluster_config = {}

with LocalTestClusterOpenSearchDashboards.create(
self.dependency_installer,
self.dependency_installer_opensearch_dashboards,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def setUp(self) -> None:

self.test_config = MagicMock()
self.test_config.working_directory = "test_working_directory"
self.test_config.integ_test = {"test-configs": ['with-security', 'without-security'], "additional-cluster-configs": {'server.host': '0.0.0.0'}}
self.test_config.integ_test = {"test-configs": ['with-security', 'without-security']}

self.test_config_additional_config = MagicMock()
self.test_config_additional_config.working_directory = "test_working_directory"
self.test_config_additional_config.integ_test = {"test-configs": ['with-security', 'without-security'], "additional-cluster-configs": {'server.host': '0.0.0.0'}}

self.bundle_manifest_opensearch = MagicMock()
self.bundle_manifest_opensearch.build.version = "1.2.0"
Expand Down Expand Up @@ -93,6 +97,58 @@ def test_execute_tests(self, mock_execute: Mock, mock_git: Mock, mock_test_resul
call("test_endpoint", 1234, False, "without-security")
])

self.assertEqual(str(suite.additional_cluster_config), "{}")

@patch("os.chdir")
@patch("os.path.exists")
@patch("test_workflow.integ_test.integ_test_suite_opensearch_dashboards.TestResultData")
@patch("test_workflow.integ_test.integ_test_suite_opensearch_dashboards.GitRepository")
@patch("test_workflow.integ_test.integ_test_suite_opensearch_dashboards.execute", return_value=True)
def test_execute_tests_additional_config(self, mock_execute: Mock, mock_git: Mock, mock_test_result_data: Mock, mock_localTestClusterOSD: Mock, mock_path_exists: Mock, *mock: Any) -> None:
mock_find = MagicMock()
mock_find.return_value = "./integtest.sh"

ScriptFinder.find_integ_test_script = mock_find # type: ignore

mock_git_object = MagicMock()
mock_git_object.dir = "https://test.github.com"
mock_git.return_value = mock_git_object

mock_execute.return_value = ("test_status", "test_stdout", "")

mock_test_result_data_object = MagicMock()
mock_test_result_data.return_value = mock_test_result_data_object

mock_path_exists.return_value = True

mock_create = MagicMock()
mock_create.return_value.__enter__.return_value = ("test_endpoint", 1234)
LocalTestClusterOpenSearchDashboards.create = mock_create # type: ignore

suite = IntegTestSuiteOpenSearchDashboards(
self.dependency_installer_opensearch,
self.dependency_installer_opensearch_dashboards,
self.component,
self.test_config_additional_config,
self.bundle_manifest_opensearch,
self.bundle_manifest_opensearch_dashboards,
self.build_manifest_opensearch,
self.build_manifest_opensearch_dashboards,
self.work_dir,
self.test_recorder
)

mock_execute_integtest_sh = MagicMock()
suite.execute_integtest_sh = mock_execute_integtest_sh # type: ignore

# call the test target
suite.execute_tests()

mock_execute_integtest_sh.assert_has_calls([
call("test_endpoint", 1234, True, "with-security"),
call("test_endpoint", 1234, False, "without-security")
])

self.assertEqual(str(suite.additional_cluster_config), "{'server.host': '0.0.0.0'}")

# test base class
Expand Down