X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Fmodel.py;h=b7318992351bbf51d2823a167ed9c823129ef35e;hb=0d04ff68bd882b448c0770f23f14e9ec59e0d513;hp=9d14f82bb0b76775d6471140b05cdaf422ee7e43;hpb=a46a011e5de69144f3290f112dd22813ea6c3e55;p=osm%2FN2VC.git diff --git a/juju/model.py b/juju/model.py index 9d14f82..b731899 100644 --- a/juju/model.py +++ b/juju/model.py @@ -576,15 +576,24 @@ class Model(object): entity_id = await q.get() return self.state._live_entity_map(entity_type)[entity_id] - async def _wait_for_new(self, entity_type, entity_id, predicate=None): + async def _wait_for_new(self, entity_type, entity_id=None, predicate=None): """Wait for a new object to appear in the Model and return it. Waits for an object of type ``entity_type`` with id ``entity_id``. + If ``entity_id`` is ``None``, it will wait for the first new entity + of the correct type. This coroutine blocks until the new object appears in the model. """ - return await self._wait(entity_type, entity_id, 'add', predicate) + # if the entity is already in the model, just return it + if entity_id in self.state._live_entity_map(entity_type): + return self.state._live_entity_map(entity_type)[entity_id] + # if we know the entity_id, we can trigger on any action that puts + # the enitty into the model; otherwise, we have to watch for the + # next "add" action on that entity_type + action = 'add' if entity_id is None else None + return await self._wait(entity_type, entity_id, action, predicate) async def wait_for_action(self, action_id): """Given an action, wait for it to complete.""" @@ -1352,6 +1361,8 @@ class BundleHandler(object): # do the do log.info('Deploying %s', charm) await self.app_facade.Deploy([app]) + # ensure the app is in the model for future operations + await self.model._wait_for_new('application', application) return application async def addUnit(self, application, to):