Skip to content

Commit

Permalink
Test Information
Browse files Browse the repository at this point in the history
Annotate the test information with Rancher/RKE version information. This
helps the test report HTML files to be less ambiguous about the
configuration under test.

Signed-off-by: Moritz Röhrich <moritz.rohrich@suse.com>
  • Loading branch information
m-ildefons committed Sep 19, 2024
1 parent 4d4d22b commit f21a1ab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
24 changes: 21 additions & 3 deletions apiclient/rancher_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,27 @@ def __init__(self, endpoint, token=None, session=None):
def cluster_version(self):
if not self._version:
code, data = self.settings.get('server-version')
ver = data['value']
# XXX: fix master-xxx-head to 8.8.8, need the API fix the problem
self._version = parse_version('8.8.8' if 'master' in ver else ver)
version = data['value']

# Rancher versions look like v2.9.2, or v2.9.2-suffix but also
# possibly v2.9-abcdef0123-head
try:
# Split off the version name
# parse the version name into a Version object if possible
# save the suffixes as one string, e.g.:
# v2.9.2 => <Version('2.9.2')>, suffix = None
# v2.9.2-rc1 => <Version('2.9.2')>, suffix = "rc1"
# v2.9.2-dev-20240912 => <Version('2.9.2')>, suffix = "dev-20240912"
# master-head => <Version('8.8.8')>, suffix = "head"
# v1.4-ba586eaf-head => <Version('1.4')>, suffix = "ba586eaf-head"
parts = version.split('-')
self._version = parse_version("v8.8.8" if "master" in parts[0] else parts[0])
self._version.suffix = '-'.join(parts[1:]) if len(parts) > 1 else None
except ValueError:
self._version = parse_version(version)

# store the raw version string for reference
self._version.raw = version
return self._version

def __repr__(self):
Expand Down
23 changes: 16 additions & 7 deletions harvester_e2e_tests/fixtures/rancher_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.fixture(scope="session")
def rancher_api_client(request):
def rancher_api_client(request, harvester_metadata):
endpoint = request.config.getoption("--rancher-endpoint")
password = request.config.getoption("--rancher-admin-password")
ssl_verify = request.config.getoption("--ssl_verify", False)
Expand All @@ -17,6 +17,9 @@ def rancher_api_client(request):

api.session.verify = ssl_verify

harvester_metadata['Rancher Endpoint'] = endpoint
harvester_metadata['Rancher Version'] = api.cluster_version.raw

return api


Expand All @@ -42,34 +45,40 @@ def _pickup_k8s_version(versions, target_version):


@pytest.fixture(scope='session')
def rke1_version(request, rancher_api_client):
def rke1_version(request, rancher_api_client, harvester_metadata):
target_ver = request.config.getoption("--k8s-version")

code, data = rancher_api_client.settings.get("k8s-versions-current")
assert 200 == code, (code, data)
supported_vers = data["value"].split(",")

return _pickup_k8s_version(supported_vers, target_ver)
ver = _pickup_k8s_version(supported_vers, target_ver)
harvester_metadata['RKE1 Version'] = ver
return ver


@pytest.fixture(scope="session")
def rke2_version(request, api_client, rancher_api_client):
def rke2_version(request, rancher_api_client, harvester_metadata):
target_ver = request.config.getoption("--k8s-version")

# Ref. https://github.com/rancher/dashboard/blob/master/shell/edit/provisioning.cattle.io.cluster/rke2.vue # noqa
resp = rancher_api_client._get("v1-rke2-release/releases")
assert resp.ok
supported_vers = [r['id'] for r in resp.json()['data']]

return _pickup_k8s_version(supported_vers, target_ver)
ver = _pickup_k8s_version(supported_vers, target_ver)
harvester_metadata['RKE2 Version'] = ver
return ver


@pytest.fixture(scope="session")
def k3s_version(request, api_client, rancher_api_client):
def k3s_version(request, rancher_api_client, harvester_metadata):
target_ver = request.config.getoption("--k8s-version")

resp = rancher_api_client._get("v1-k3s-release/releases")
assert resp.ok
supported_vers = [r['id'] for r in resp.json()['data']]

return _pickup_k8s_version(supported_vers, target_ver)
ver = _pickup_k8s_version(supported_vers, target_ver)
harvester_metadata['K3S Version'] = ver
return ver

0 comments on commit f21a1ab

Please sign in to comment.