From e1b4ed2f47bc2c64448d23d51c4a6a9082b99078 Mon Sep 17 00:00:00 2001 From: Lanfon Fan Date: Tue, 30 Jul 2024 02:26:32 +0800 Subject: [PATCH] + [e2e] add support bundle tests --- .../apis/test_support_bundle.py | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/harvester_e2e_tests/apis/test_support_bundle.py b/harvester_e2e_tests/apis/test_support_bundle.py index c3609f6ee..cb83e12f5 100644 --- a/harvester_e2e_tests/apis/test_support_bundle.py +++ b/harvester_e2e_tests/apis/test_support_bundle.py @@ -16,11 +16,13 @@ # you may find current contact information at www.suse.com import re +import tarfile from io import BytesIO from time import sleep from zipfile import ZipFile from datetime import datetime, timedelta +import yaml import pytest pytest_plugins = [ @@ -104,6 +106,79 @@ def test_logfile_exists(self, support_bundle_state): f"Some file(s) not found, files: {matches}\npatterns: {patterns}" ) + @pytest.mark.dependency(depends=["donwnload support bundle"]) + def test_secret_file_exists(self, support_bundle_state): + ''' ref: https://github.com/harvester/tests/issues/603 ''' + pattern = r"^.*/yamls/namespaced/fleet-local/v1/secrets\.yaml" + for fname in support_bundle_state.files: + if re.match(pattern, fname): + break + else: + raise AssertionError("secret file is not available in namespaced/fleet-local") + + with ZipFile(support_bundle_state.fio, 'r') as zf: + ctx = zf.read(fname) + + secret = yaml.safe_load(ctx) + assert secret.get('items') + + fails = [] + for it in secret['items']: + if it.get('type') != "rke.cattle.io/machine-plan" or not it.get('data'): + fails.append(it) + + assert not fails, ( + f"Got {len(fails)} incorrect item(s) from secret file," + " expected type should be 'rke.cattle.io/machine-plan'" + " and `data` field should not be empty but got:\n" + f"{fails}" + ) + + support_bundle_state.fio.seek(0) + + @pytest.mark.dependency(depends=["donwnload support bundle"]) + def test_hardware_info_exists(self, support_bundle_state): + ''' ref: https://github.com/harvester/tests/issues/569 ''' + nodes, pattern = [], r"^.*/nodes/.*.zip" + + for fname in support_bundle_state.files: + if re.match(pattern, fname): + nodes.append(fname) + assert nodes, "Host information is not generated" + + with ZipFile(support_bundle_state.fio, 'r') as zf: + b_nodes = [zf.read(n) for n in nodes] + support_bundle_state.fio.seek(0) + + fails, txz_pattern = [], r"^.*/scc_supportconfig.*.txz" + for npath, node_byte in zip(nodes, b_nodes): + node_name = npath.rsplit("/", 1)[-1] + with ZipFile(BytesIO(node_byte), 'r') as zf: + try: + txz_file = next(i for i in zf.namelist() if re.match(txz_pattern, i)) + txz_byte = zf.read(txz_file) + except StopIteration: + fails.append(f"`.txz` file is not available in {node_name}") + continue + try: + with tarfile.open(mode="r:xz", fileobj=BytesIO(txz_byte)) as xz: + txt_m = next(m for m in xz.getmembers() if m.name.endswith("hardware.txt")) + hardware_ctx = xz.extractfile(txt_m).read().decode() + except StopIteration: + fails.append(f"`hardware.txt` file is not available in {node_name}") + continue + + if "lsusb" not in hardware_ctx or "hwinfo" not in hardware_ctx: + fails.append( + f"Node {node_name}'s Hardware info not contains lsusb/hwinfo command ouput\n" + f"got: {hardware_ctx}" + ) + + assert not fails, ( + f"Got {len(fails)} incorrect item(s):\n" + "\n".join(fails) + ) + @pytest.mark.dependency(depends=["get support bundle"]) def test_delete(self, api_client, support_bundle_state): code, data = api_client.supportbundle.delete(support_bundle_state.uid)