Skip to content

Commit

Permalink
Merge pull request #619 from coreycb/block-until-charm-channel
Browse files Browse the repository at this point in the history
Add (async_)block_until_charm_channel support
  • Loading branch information
ajkavanagh authored Oct 26, 2023
2 parents 3577f16 + 14c14c0 commit ff396eb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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

0 comments on commit ff396eb

Please sign in to comment.