From: Adam Israel Date: Tue, 31 Oct 2017 13:19:51 +0000 (-0400) Subject: Add more robust type checking X-Git-Tag: v3.0.0rc14^0 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F34%2F5634%2F1;p=osm%2FSO.git Add more robust type checking Add additional type checking when an application is referenced or deployed, and while checking its status. Signed-off-by: Adam Israel --- diff --git a/common/python/rift/mano/utils/juju_api.py b/common/python/rift/mano/utils/juju_api.py index c4e3923b..a06c1e7e 100755 --- a/common/python/rift/mano/utils/juju_api.py +++ b/common/python/rift/mano/utils/juju_api.py @@ -187,6 +187,10 @@ class JujuApi(object): if not self.authenticated: await self.login() + # Check that the charm is valid and exists. + if charm is None: + return None + app = await self.get_application(name) if app is None: # TODO: Handle the error if the charm isn't found. @@ -219,7 +223,7 @@ class JujuApi(object): self.log.debug("JujuApi: Getting application {}".format(application)) app = None - if self.model: + if application and self.model: if self.model.applications: if application in self.model.applications: app = self.model.applications[application] @@ -234,11 +238,10 @@ class JujuApi(object): app = await self.get_application(application) if app: status = app.status - - self.log.debug("JujuApi: Status of application {} is {}".format( - application, - str(status), - )) + self.log.debug("JujuApi: Status of application {} is {}".format( + application, + str(status), + )) return status get_service_status = get_application_status @@ -546,7 +549,7 @@ class JujuApi(object): for key in config: if config[key] != newconf[key]: self.log.debug("JujuApi: Config not set! Key {} Value {} doesn't match {}".format(key, config[key], newconf[key])) - + async def set_parameter(self, parameter, value, application=None): """Set a config parameter for a service."""