Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (async_)block_until_charm_channel support #619

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions unit_tests/test_zaza_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
AsyncTimeoutError = asyncio.futures.TimeoutError

import copy
import collections
import concurrent
import datetime
import mock
Expand All @@ -38,6 +39,7 @@
import unit_tests.utils as ut_utils

import zaza.model as model
import zaza.utilities.ro_types as ro_types
import zaza


Expand Down Expand Up @@ -1771,6 +1773,31 @@ async def _get_status(*args):
with self.assertRaises(AsyncTimeoutError):
model.block_until_charm_url('app', 'something wrong', timeout=0.1)

def test_block_until_charm_channel(self):

async def _block_until(f, timeout=None):
rc = await f()
if not rc:
raise AsyncTimeoutError

async def _get_status(*args):
return self.juju_status
self.patch_object(model, 'Model')
self.Model.return_value = self.Model_mock
self.patch_object(model, 'async_block_until')
self.async_block_until.side_effect = _block_until
self.patch_object(model, 'async_get_status')
self.async_get_status.side_effect = _get_status
target_channel = '2023.2/stable'
charm_channel = collections.OrderedDict(
{'charm_channel': target_channel})
self.juju_status.applications[self.application] = (
ro_types.resolve_immutable(charm_channel))
model.block_until_charm_channel('app', target_channel)
with self.assertRaises(AsyncTimeoutError):
model.block_until_charm_channel(
'app', 'something wrong', timeout=0.1)

def block_until_service_status_base(self, rou_return):

async def _block_until(f, timeout=None):
Expand Down
28 changes: 28 additions & 0 deletions zaza/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,34 @@ async def _check_charm_url():
block_until_charm_url = sync_wrapper(async_block_until_charm_url)


async def async_block_until_charm_channel(application, target_channel,
model_name=None, timeout=2700):
"""Block until the charm channel matches target_channel.

An example accessing this function via its sync wrapper::

block_until_charm_channel('cinder', '2023.2/stable')

:param application_name: Name of application
:type application_name: str
:param target_channel: Target charm channel
:type target_channel: str
:param model_name: Name of model to interact with.
:type model_name: str
:param timeout: Time to wait for status to be achieved
:type timeout: float
"""
async def _check_charm_channel():
model_status = await async_get_status(model_name)
charm_channel = model_status.applications[application].charm_channel
return charm_channel == target_channel

await async_block_until(_check_charm_channel, timeout=timeout)


block_until_charm_channel = sync_wrapper(async_block_until_charm_channel)


async def async_block_until_service_status(unit_name, services, target_status,
model_name=None, timeout=2700,
pgrep_full=False):
Expand Down
Loading