Skip to content

Commit

Permalink
Revert functional test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaser committed Jun 14, 2024
1 parent 8d19db3 commit 287babd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions magnum_cluster_api/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import yaml
from magnum import objects as magnum_objects
from oslo_serialization import base64
from tenacity import Retrying, retry_if_result, stop_after_delay, wait_fixed

from magnum_cluster_api import exceptions

Expand All @@ -39,6 +40,28 @@ def events(self):
def observed_generation(self):
return self.obj.get("status", {}).get("observedGeneration")

def wait_for_observed_generation_changed(
self,
existing_observed_generation: int = 0,
timeout: int = 10,
interval: int = 1,
):
if existing_observed_generation == 0:
existing_observed_generation = self.observed_generation

for attempt in Retrying(
retry=(
retry_if_result(lambda g: g == existing_observed_generation)
| retry_if_result(lambda g: g is None)
),
stop=stop_after_delay(timeout),
wait=wait_fixed(interval),
):
with attempt:
self.reload()
if not attempt.retry_state.outcome.failed:
attempt.retry_state.set_result(self.observed_generation)


class EndpointSlice(NamespacedAPIObject):
version = "discovery.k8s.io/v1"
Expand Down
9 changes: 9 additions & 0 deletions magnum_cluster_api/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import pytest

from magnum_cluster_api import objects


@pytest.fixture
def cluster(
Expand All @@ -27,6 +29,13 @@ def cluster(
try:
ubuntu_driver.create_cluster(context, cluster_obj, 60)

cluster_resource = objects.Cluster.for_magnum_cluster(
ubuntu_driver.k8s_api, cluster_obj
)
cluster_resource.wait_for_observed_generation_changed(
existing_observed_generation=1
)

cluster_obj.save.assert_called_once()
cluster_obj.save.reset_mock()

Expand Down

0 comments on commit 287babd

Please sign in to comment.