Skip to content

Commit

Permalink
Wip/fix get harvester kubeconfig (#1628)
Browse files Browse the repository at this point in the history
* fix getting Harvester kubeconfig

Signed-off-by: Moritz Röhrich <moritz.rohrich@suse.com>

* 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 <moritz.rohrich@suse.com>

---------

Signed-off-by: Moritz Röhrich <moritz.rohrich@suse.com>
  • Loading branch information
m-ildefons authored Nov 5, 2024
1 parent 2448a02 commit 48291a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
16 changes: 12 additions & 4 deletions apiclient/rancher_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions apiclient/rancher_api/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion harvester_e2e_tests/fixtures/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion harvester_e2e_tests/integrations/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
)
Expand Down

0 comments on commit 48291a3

Please sign in to comment.