Skip to content

Commit

Permalink
Update the test spec file parameter to read from test manifest (#5370)
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <zelinhao@amazon.com>
  • Loading branch information
zelinh authored Mar 7, 2025
1 parent a7b2f8d commit 04727bd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/test_workflow/smoke_test/smoke_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def __init__(self, args: TestArgs, test_manifest: TestManifest) -> None:
def start_test(self, work_dir: Path) -> Any:
pass

def extract_paths_from_yaml(self, component: str, version: str) -> Any:
def extract_paths_from_yaml(self, component: str, test_spec: str, version: str) -> Any:
base_path = os.path.dirname(os.path.abspath(__file__))
paths = [
os.path.join(base_path, "smoke_tests_spec", f"{version.split('.')[0]}.x", f"{component}.yml"),
os.path.join(base_path, "smoke_tests_spec", "default", f"{component}.yml")
os.path.join(base_path, "smoke_tests_spec", f"{version.split('.')[0]}.x", test_spec),
os.path.join(base_path, "smoke_tests_spec", "default", test_spec)
]
for file_path in paths:
if os.path.exists(file_path):
Expand All @@ -57,6 +57,8 @@ def extract_paths_from_yaml(self, component: str, version: str) -> Any:
# Extract paths
paths = data.get('paths', {})
return paths
else:
logging.info(f"No spec found at f{file_path}")
logging.error("No spec found.")
sys.exit(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def start_test(self, work_dir: Path) -> TestSuiteResults:
for component in self.test_manifest.components.select(self.args.components):
if component.smoke_test:
logging.info(f"Running smoke test on {component.name} component.")
component_spec = self.extract_paths_from_yaml(component.name, self.version)
component_spec = self.extract_paths_from_yaml(component.name, component.smoke_test.get("test-spec"), self.version)
logging.info(f"component spec is {component_spec}")
test_results = TestComponentResults()
for api_requests, api_details in component_spec.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self) -> None:
mock_components = MagicMock()
mock_component = MagicMock()
mock_component.name = "opensearch"
mock_component.smoke_test = True
mock_component.smoke_test = {"test-spec": "mock_component.yml"}
mock_components.select.return_value = [mock_component]
self.test_manifest.components = mock_components

Expand All @@ -45,11 +45,11 @@ def test_extract_paths_from_yaml(self, mock_exists: Mock, mock_dirname: Mock, mo
component_name = "test_component"

# Run extract_paths_from_yaml and check output
result = runner.extract_paths_from_yaml(component_name, "2.19.0")
result = runner.extract_paths_from_yaml(component_name, "mock_component.yml", "2.19.0")
expected_output = {"/_cat/plugins": {"get": {"parameters": []}}} # type: Any

self.assertEqual(result, expected_output)
mock_open_file.assert_called_once_with(os.path.join("/dummy-path", "smoke_tests_spec", "2.x", f"{component_name}.yml"), 'r')
mock_open_file.assert_called_once_with(os.path.join("/dummy-path", "smoke_tests_spec", "2.x", "mock_component.yml"), 'r')

@patch("test_workflow.smoke_test.smoke_test_runner.TestRecorder")
def test_convert_parameter_json(self, mock_recorder: Mock) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self) -> None:
mock_components = MagicMock()
mock_component = MagicMock()
mock_component.name = "opensearch"
mock_component.smoke_test = True
mock_component.smoke_test = {"test-spec": "mock_component.yml"}
mock_components.select.return_value = [mock_component]
self.test_manifest.components = mock_components

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_smoke_test_runner_opensearch_start_test(self, mock_dirname: Mock, mock_

results = runner.start_test(work_dir=Path("/temp/path"))
self.assertTrue(results)
mock_extract_spec.assert_called_with("opensearch", "2.19.0")
mock_extract_spec.assert_called_with("opensearch", "mock_component.yml", "2.19.0")
self.test_manifest.components.select.assert_called()
mock_get.assert_has_calls(
[call('https://localhost:9200/', verify=False, auth=('admin', 'myStrongPassword123!'),
Expand Down

0 comments on commit 04727bd

Please sign in to comment.