From 48291a360c49b88ed212dbcfd19569ee753498a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20R=C3=B6hrich?= Date: Tue, 5 Nov 2024 10:07:26 +0100 Subject: [PATCH] Wip/fix get harvester kubeconfig (#1628) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix getting Harvester kubeconfig Signed-off-by: Moritz Röhrich * Rancher API: Fix generate kubeconfig, debug logs Fix generate kubeconfig function: fix oder of keyword parameters. Add debug logging (use with pytest `-v -s` options) Signed-off-by: Moritz Röhrich --------- Signed-off-by: Moritz Röhrich --- apiclient/rancher_api/api.py | 16 ++++++++++++---- apiclient/rancher_api/managers.py | 5 +++++ harvester_e2e_tests/fixtures/settings.py | 4 +++- .../integrations/test_9_rancher_integration.py | 9 ++++++++- harvester_e2e_tests/integrations/test_upgrade.py | 3 ++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/apiclient/rancher_api/api.py b/apiclient/rancher_api/api.py index da36de401..28d33f13f 100644 --- a/apiclient/rancher_api/api.py +++ b/apiclient/rancher_api/api.py @@ -67,19 +67,27 @@ def __repr__(self): def _get(self, path, **kwargs): url = urljoin(self.endpoint, path) - return self.session.get(url, **kwargs) + resp = self.session.get(url, **kwargs) + print(f"{resp.request.method} {resp.request.url}") + return resp def _post(self, path, **kwargs): url = urljoin(self.endpoint, path) - return self.session.post(url, **kwargs) + resp = self.session.post(url, **kwargs) + print(f"{resp.request.method} {resp.request.url}") + return resp def _put(self, path, **kwargs): url = urljoin(self.endpoint, path) - return self.session.put(url, **kwargs) + resp = self.session.put(url, **kwargs) + print(f"{resp.request.method} {resp.request.url}") + return resp def _delete(self, path, **kwargs): url = urljoin(self.endpoint, path) - return self.session.delete(url, **kwargs) + resp = self.session.delete(url, **kwargs) + print(f"{resp.request.method} {resp.request.url}") + return resp def authenticate(self, user, passwd, **kwargs): path = "v3-public/localProviders/local?action=login" diff --git a/apiclient/rancher_api/managers.py b/apiclient/rancher_api/managers.py index e7ff3da95..efcf7348b 100644 --- a/apiclient/rancher_api/managers.py +++ b/apiclient/rancher_api/managers.py @@ -678,6 +678,7 @@ def delete(self, name, *, raw=False): class ClusterManager(BaseManager): PATH_fmt = "v3/cluster/{uid}" + PATH1_fmt = "v3/clusters/{uid}" def create_data(self, name, k8s_version, kubeconfig): @@ -808,6 +809,10 @@ def create(self, name, k8s_version, kubeconfig, *, raw=False): def delete(self, name, *, raw=False): return self._delete(self.PATH_fmt.format(uid=name), raw=raw) + def generate_kubeconfig(self, name, *, raw=False): + params = {'action': 'generateKubeconfig'} + return self._create(f"v3/clusters/{name}", raw=raw, params=params) + def explore(self, name): from .cluster_api import ClusterExploreAPI # circular dependency return ClusterExploreAPI(self.api.endpoint, self.api.session, name) diff --git a/harvester_e2e_tests/fixtures/settings.py b/harvester_e2e_tests/fixtures/settings.py index 982c9a13a..9122554e1 100644 --- a/harvester_e2e_tests/fixtures/settings.py +++ b/harvester_e2e_tests/fixtures/settings.py @@ -15,7 +15,9 @@ def __init__(self): def _storage_net_configured(self): code, data = self.settings.get('storage-network') - if (cs := data.get('status', {}).get('conditions')): + + cs = data.get('status', {}).get('conditions') + if cs: if 'True' == cs[-1].get('status') and 'Completed' == cs[-1].get('reason'): return True, (code, data) return False, (code, data) diff --git a/harvester_e2e_tests/integrations/test_9_rancher_integration.py b/harvester_e2e_tests/integrations/test_9_rancher_integration.py index 14e451404..877bc516f 100644 --- a/harvester_e2e_tests/integrations/test_9_rancher_integration.py +++ b/harvester_e2e_tests/integrations/test_9_rancher_integration.py @@ -130,7 +130,14 @@ def harvester_mgmt_cluster(api_client, rancher_api_client, unique_name, polling_ @pytest.fixture(scope='module') def harvester_cloud_credential(api_client, rancher_api_client, harvester_mgmt_cluster, unique_name): - harvester_kubeconfig = api_client.generate_kubeconfig() + code, data = rancher_api_client.clusters.generate_kubeconfig( + harvester_mgmt_cluster['id'] + ) + assert 200 == code, ( + f"Failed to create kubconfig with error: {code}, {data}" + ) + harvester_kubeconfig = data['config'] + code, data = rancher_api_client.cloud_credentials.create( unique_name, harvester_kubeconfig, diff --git a/harvester_e2e_tests/integrations/test_upgrade.py b/harvester_e2e_tests/integrations/test_upgrade.py index b7fac4ba1..15cce1606 100644 --- a/harvester_e2e_tests/integrations/test_upgrade.py +++ b/harvester_e2e_tests/integrations/test_upgrade.py @@ -507,7 +507,8 @@ def test_degraded_volume(self, api_client, wait_timeout, vm_shell_from_host, # https://github.com/harvester/harvester/issues/6425 code, data = api_client.hosts.get() assert 200 == code, (code, data) - if (cluster_size := len(data['data'])) < 3: + cluster_size = len(data['data']) + if cluster_size < 3: pytest.skip( f"Degraded volumes only checked on 3+ nodes cluster, skip on {cluster_size}." )