Skip to content

Commit 5e646a5

Browse files
committed
feat: Add archive modification workflow test
* Card ID: CCT-994 Added the test to verify the archive file modification and upload workflow. This test extracts and modifies files within insights archives, re-packages modified data into new archive, and uploads modified archive using --payload option. Co-Authored-By: Claude (claude-sonnet-4)
1 parent 606bda8 commit 5e646a5

File tree

1 file changed

+71
-5
lines changed

1 file changed

+71
-5
lines changed

integration-tests/test_file_workflow.py

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,69 @@ def test_file_workflow_archive_update_host_info(insights_client, external_invent
164164
set_hostname(current_hostname)
165165

166166

167+
@pytest.mark.tier1
168+
def test_file_workflow_archive_modification_and_upload(insights_client, tmp_path):
169+
"""
170+
:id: 00eb48cd-29a5-4325-bca1-1db846cbbf2b
171+
:title: Verify Archive File Modification and Upload Workflow
172+
:reference: https://issues.redhat.com/browse/CCT-994
173+
:description:
174+
Verify that modifying files within a collected Insights Archive
175+
and uploading the modified archive works as expected
176+
:tags: Tier 1
177+
:steps:
178+
1. Register the system with insights-client and confirm data upload
179+
2. Collect insights data into a directory structure
180+
3. Modify hostname files within the collected data
181+
4. Package the modified data into a new archive
182+
5. Upload the modified archive using --payload option
183+
:expectedresults:
184+
1. The system is registered and initial data collection succeeds
185+
2. Data collection to directory succeeds
186+
3. Hostname files are successfully modified with test data
187+
4. Modified data is packaged into a valid archive
188+
5. The upload process starts and the output message is as expected
189+
6. Modified archive uploads successfully with the message as expected
190+
"""
191+
insights_client.register()
192+
assert conftest.loop_until(lambda: insights_client.is_registered)
193+
194+
# Collect data into a directory
195+
new_hostname = generate_random_hostname()
196+
archive_name = tmp_path / "archive.tar.gz"
197+
insights_client.run(f"--output-file={archive_name}")
198+
199+
# Extract the archive to modify files
200+
extract_dir = tmp_path / "extracted"
201+
extract_dir.mkdir()
202+
203+
insights_client.run(f"--output-dir={extract_dir}")
204+
dir_name = os.listdir(extract_dir)[0]
205+
206+
# Overwrite hostname file content in the archive
207+
hostname_file = extract_dir / dir_name / "data" / "insights_commands" / "hostname"
208+
hostname_f_file = (
209+
extract_dir / dir_name / "data" / "insights_commands" / "hostname_-f"
210+
)
211+
212+
# Update hostname files with new hostname
213+
hostname_file.parent.mkdir(parents=True, exist_ok=True)
214+
hostname_file.write_text(new_hostname + "\n")
215+
hostname_f_file.write_text(new_hostname + "\n")
216+
217+
# Recreate the modified archive
218+
modified_archive = tmp_path / "modified_archive.tar.gz"
219+
with tarfile.open(modified_archive, "w:gz") as tar:
220+
tar.add(extract_dir / dir_name, arcname=dir_name)
221+
222+
# Upload using --payload and --content-type
223+
upload_result = insights_client.run(
224+
f"--payload={modified_archive}", "--content-type=gz", check=False
225+
)
226+
assert "Uploading Insights data" in upload_result.stdout
227+
assert "Successfully uploaded report" in upload_result.stdout
228+
229+
167230
def remove_files_from_archive(original_archive, files_to_remove, modified_archive):
168231
with tarfile.open(original_archive, "r:gz") as tar:
169232
file_list = tar.getnames()
@@ -181,10 +244,13 @@ def remove_files_from_archive(original_archive, files_to_remove, modified_archiv
181244

182245
def set_hostname(hostname=None):
183246
if hostname is None:
184-
hostname = (
185-
"".join(random.choices(string.ascii_lowercase + string.digits, k=10))
186-
+ "-new-hostname.example.com"
187-
)
188-
247+
hostname = generate_random_hostname()
189248
subprocess.run(["hostnamectl", "set-hostname", hostname], check=True)
190249
return hostname
250+
251+
252+
def generate_random_hostname():
253+
return (
254+
"".join(random.choices(string.ascii_lowercase + string.digits, k=10))
255+
+ "-new-hostname.example.com"
256+
)

0 commit comments

Comments
 (0)