diff --git a/integration-tests/test_collection.py b/integration-tests/test_collection.py index 2db02bae..956c3e58 100644 --- a/integration-tests/test_collection.py +++ b/integration-tests/test_collection.py @@ -9,16 +9,12 @@ import contextlib import os import tarfile -import glob import json import pytest import conftest import uuid -ARCHIVE_CACHE_DIRECTORY = "/var/cache/insights-client" - - def test_output_file_valid_parameters(insights_client, tmp_path): """ :id: 011e38c7-c6dc-4c17-add4-d67f0775f5cd @@ -284,7 +280,7 @@ def test_cmd_timeout(insights_client): @pytest.mark.usefixtures("register_subman") -def test_branch_info(insights_client, test_config, subman): +def test_branch_info(insights_client, test_config, subman, tmp_path): """ :id: 22c7063c-e09d-4fdf-80ea-864a7027d2ee :title: Test branch_info file includes all required information @@ -296,43 +292,28 @@ def test_branch_info(insights_client, test_config, subman): https://docs.google.com/document/d/193mN5aBwxtzpP4U-vnL3yVawPxiG20n0zkzDYsam-eU/edit :tags: Tier 2 :steps: - 1. Register insights-client - 2. Run insights-client with the --no-upload option to generate the - branch_info file - 3. Extract the latest archive - 4. Inspect the branch_info file to verify it contains correct values + 1. Run insights-client with --output-dir + 2. Inspect the branch_info file to verify it contains correct values :expectedresults: - 1. The insights-client is registered - 2. The branch_info file is generated - 3. The latest archive is successfully extracted - 4. The branch_info includes correct values + 1. The branch_info file is generated + 2. The branch_info includes correct values """ - insights_client.register() - assert conftest.loop_until(lambda: insights_client.is_registered) - - insights_client.run("--no-upload") - - list_of_files = glob.glob(f"{ARCHIVE_CACHE_DIRECTORY}/*.tar.gz") - latest_file = max(list_of_files, key=os.path.getctime) - - with tarfile.open(latest_file, "r:gz") as tar: - tar.extractall(path="/var/cache/insights-client/", filter="data") - directory_name = latest_file.replace(".tar.gz", "") + insights_client.run("--output-dir", tmp_path.name) - branch_info_path = os.path.join(directory_name, "branch_info") + branch_info_path: str = os.path.join(tmp_path.name, "branch_info") with open(branch_info_path, "r") as file: data = json.load(file) - if "satellite" in test_config.environment: - assert data["product"]["type"] == "Satellite" - assert isinstance(uuid.UUID(data["remote_branch"]), uuid.UUID) - assert uuid.UUID(data["remote_leaf"]) == subman.uuid - else: - assert data["remote_branch"] == -1, "Incorrect remote_branch value" - assert data["remote_leaf"] == -1, "Incorrect remote_leaf value" + if "satellite" in test_config.environment: + assert data["product"]["type"] == "Satellite" + assert isinstance(uuid.UUID(data["remote_branch"]), uuid.UUID) + assert uuid.UUID(data["remote_leaf"]) == subman.uuid + else: + assert data["remote_branch"] == -1, "Incorrect remote_branch value" + assert data["remote_leaf"] == -1, "Incorrect remote_leaf value" -@pytest.mark.usefixtures("register_subman") -def test_archive_structure(insights_client): + +def test_archive_structure(insights_client, tmp_path): """ :id: 7a78cf8f-ed32-4011-8d15-787231f867c9 :title: Test archive structure @@ -342,20 +323,16 @@ def test_archive_structure(insights_client): and subdirectories :tags: Tier 1 :steps: - 1. Register insights-client - 2. Run insights-client with --no-upload - 3. Extract the latest archive - 4. Verify that all required directories are present in the archive - 5. Verify that all required subdirectories are present under the + 1. Run insights-client with --output-dir + 2. Verify that all required directories are present in the archive + 3. Verify that all required subdirectories are present under the data directory :expectedresults: - 1. Insights-client is registered - 2. The archive is generated - 3. The latest archive is extracted - 4. All required directories are present - 5. All required subdirectories are present + 1. The archive is saved uncompressed into a directory + 2. Expected directories are present + 3. Expected subdirectories are present """ - dirs_list = [ + archive_content = [ "blacklist_report", "branch_info", "data", @@ -365,36 +342,23 @@ def test_archive_structure(insights_client): "version_info", ] - subdirs_list = [ + archive_data_content = [ "branch_info", "version_info", - "boot", "etc", "insights_commands", "proc", - "run", "sys", "usr", - "var", ] - insights_client.register() - assert conftest.loop_until(lambda: insights_client.is_registered) - - insights_client.run("--no-upload") - - list_of_files = glob.glob(f"{ARCHIVE_CACHE_DIRECTORY}/*.tar.gz") - latest_file = max(list_of_files, key=os.path.getctime) - - with tarfile.open(latest_file, "r:gz") as tar: - tar.extractall(path="/var/cache/insights-client/", filter="data") - directory_name = latest_file.replace(".tar.gz", "") + insights_client.run("--output-dir", tmp_path.name) - extracted_dirs_files = os.listdir(directory_name) - missing_dirs = [d for d in dirs_list if d not in extracted_dirs_files] + extracted_dirs_files = os.listdir(tmp_path.name) # type: list[str] + missing_dirs = [f for f in archive_content if f not in extracted_dirs_files] assert not missing_dirs, f"Missing directories {missing_dirs}" - data_dir_path = os.path.join(directory_name, "data") - data_subdirs = os.listdir(data_dir_path) - missing_subdirs = [d for d in subdirs_list if d not in data_subdirs] + data_dir_path = os.path.join(tmp_path.name, "data") + data_subdirs = os.listdir(data_dir_path) # type: list[str] + missing_subdirs = [f for f in archive_data_content if f not in data_subdirs] assert not missing_subdirs, f"Missing subdirectory {missing_subdirs}"