- # register application with observer
- observer.register_application(application=application, db_dict=db_dict)
-
- self.debug('waiting for application deployed... {}'.format(application.entity_id))
- retries = await observer.wait_for_application(
- application_id=application.entity_id,
- progress_timeout=progress_timeout,
- total_timeout=total_timeout)
- self.debug('application deployed')
-
- else:
-
- # register application with observer
- observer.register_application(application=application, db_dict=db_dict)
-
- # application already exists, but not finalised
- self.debug('application already exists, waiting for deployed...')
- retries = await observer.wait_for_application(
- application_id=application.entity_id,
- progress_timeout=progress_timeout,
- total_timeout=total_timeout)
- self.debug('application deployed')
-
- return application, retries
-
- async def _juju_execute_action(
- self,
- model_name: str,
- application_name: str,
- action_name: str,
- db_dict: dict,
- progress_timeout: float = None,
- total_timeout: float = None,
- **kwargs
- ) -> Action:
-
- # get juju model and observer
- model = await self._juju_get_model(model_name=model_name)
- observer = self.juju_observers[model_name]
-
- application = await self._juju_get_application(model_name=model_name, application_name=application_name)
-
- self.debug('trying to execute action {}'.format(action_name))
- unit = application.units[0]
- if unit is not None:
- actions = await application.get_actions()
- if action_name in actions:
- self.debug('executing action {} with params {}'.format(action_name, kwargs))
- action = await unit.run_action(action_name, **kwargs)
-
- # register action with observer
- observer.register_action(action=action, db_dict=db_dict)
-
- self.debug(' waiting for action completed or error...')
- await observer.wait_for_action(
- action_id=action.entity_id,
- progress_timeout=progress_timeout,
- total_timeout=total_timeout)
- self.debug('action completed with status: {}'.format(action.status))
- output = await model.get_action_output(action_uuid=action.entity_id)
- status = await model.get_action_status(uuid_or_prefix=action.entity_id)
- if action.entity_id in status:
- status = status[action.entity_id]
- else:
- status = 'failed'
- return output, status
-
- raise N2VCExecutionException(
- message='Cannot execute action on charm',
- primitive_name=action_name
- )
-
- async def _juju_configure_application(
- self,
- model_name: str,
- application_name: str,
- config: dict,
- db_dict: dict,
- progress_timeout: float = None,
- total_timeout: float = None
- ):
-
- # get the application
- application = await self._juju_get_application(model_name=model_name, application_name=application_name)
-
- self.debug('configuring the application {} -> {}'.format(application_name, config))
- res = await application.set_config(config)
- self.debug('application {} configured. res={}'.format(application_name, res))
-
- # Verify the config is set
- new_conf = await application.get_config()
- for key in config:
- value = new_conf[key]['value']
- self.debug(' {} = {}'.format(key, value))
- if config[key] != value:
- raise N2VCException(
- message='key {} is not configured correctly {} != {}'.format(key, config[key], new_conf[key])