Skip to content

Commit

Permalink
Fix fixtures for functests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaser committed Feb 19, 2025
1 parent b700ec9 commit 7c23030
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
22 changes: 18 additions & 4 deletions magnum_cluster_api/tests/functional/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# SPDX-License-Identifier: Apache-2.0


import fixtures # type: ignore
import fixtures
import pykube # type: ignore

from magnum_cluster_api import resources
from magnum_cluster_api import magnum_cluster_api, resources


class ClusterClassFixture(fixtures.Fixture):
Expand Down Expand Up @@ -32,17 +33,30 @@ def get_object_override():


class ClusterFixture(fixtures.Fixture):
def __init__(self, context, api, namespace, magnum_cluster, mutate_callback=None):
def __init__(
self,
context,
api: magnum_cluster_api.KubeClient,
pykube_api: pykube.HTTPClient,
namespace,
magnum_cluster,
mutate_callback=None,
):
super(ClusterFixture, self).__init__()
self.context = context
self.api = api
self.pykube_api = pykube_api
self.namespace = namespace
self.magnum_cluster = magnum_cluster
self.mutate_callback = mutate_callback

def _setUp(self):
self.cluster = resources.Cluster(
self.context, self.api, self.magnum_cluster, namespace=self.namespace.name
self.context,
self.api,
self.pykube_api,
self.magnum_cluster,
namespace=self.namespace.name,
)

original_get_object = self.cluster.get_object
Expand Down
19 changes: 14 additions & 5 deletions magnum_cluster_api/tests/functional/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
from oslotest import base # type: ignore
from tenacity import retry, retry_if_exception_type, stop_after_delay, wait_fixed

from magnum_cluster_api import clients, exceptions, objects, resources
from magnum_cluster_api import (
clients,
exceptions,
magnum_cluster_api,
objects,
resources,
)
from magnum_cluster_api.tests.functional import fixtures as mcapi_fixtures


Expand Down Expand Up @@ -80,7 +86,8 @@ def setUp(self):
)
)

self.api = clients.get_pykube_api()
self.api = magnum_cluster_api.KubeClient()
self.pykube_api = clients.get_pykube_api()

alphabet = string.ascii_lowercase + string.digits
su = shortuuid.ShortUUID(alphabet=alphabet)
Expand Down Expand Up @@ -124,6 +131,7 @@ def _test_disable_api_server_floating_ip(
mcapi_fixtures.ClusterFixture(
self.context,
self.api,
self.pykube_api,
self.namespace,
cluster,
)
Expand Down Expand Up @@ -177,7 +185,7 @@ def setUp(self):
self.api, namespace=self.namespace.name
)

cc = objects.ClusterClass.objects(self.api, namespace=self.namespace.name).get(
cc = objects.ClusterClass.objects(self.pykube_api, namespace=self.namespace.name).get(
name=resources.CLUSTER_CLASS_NAME
)

Expand All @@ -203,7 +211,7 @@ def mutate_cluster_class_extra_var(resource):
)
).cluster_class

cc = objects.ClusterClass.objects(self.api, namespace=self.namespace.name).get(
cc = objects.ClusterClass.objects(self.pykube_api, namespace=self.namespace.name).get(
name=self.cluster_class_extra_var.get_object().name
)

Expand Down Expand Up @@ -241,14 +249,15 @@ def _get_cluster_object(self, mutate_callback=None):
mcapi_fixtures.ClusterFixture(
self.context,
self.api,
self.pykube_api,
self.namespace,
self.cluster,
mutate_callback=mutate_callback,
)
)

capi_cluster = fixture.cluster
return objects.Cluster.objects(self.api, namespace=self.namespace.name).get(
return objects.Cluster.objects(self.pykube_api, namespace=self.namespace.name).get(
name=capi_cluster.get_object().name
)

Expand Down

0 comments on commit 7c23030

Please sign in to comment.