Merge "Fix bug 564"
authorAdam Israel <adam.israel@canonical.com>
Tue, 19 Mar 2019 21:21:08 +0000 (22:21 +0100)
committerGerrit Code Review <root@osm.etsi.org>
Tue, 19 Mar 2019 21:21:08 +0000 (22:21 +0100)
1  2 
n2vc/vnf.py
tests/base.py

diff --combined n2vc/vnf.py
@@@ -769,11 -769,11 +769,11 @@@ class N2VC
  
                  await self.disconnect_model(self.monitors[model_name])
  
-                 # Notify the callback that this charm has been removed.
                  self.notify_callback(
                      model_name,
                      application_name,
                      "removed",
+                     "Removing charm {}".format(application_name),
                      callback,
                      *callback_args,
                  )
              except JujuError as e:
                  if "already exists" not in e.message:
                      raise e
 +
 +            # Create an observer for this model
 +            await self.create_model_monitor(ns_uuid)
 +
          return True
  
      async def DestroyNetworkService(self, ns_uuid):
  
          # Do not delete the default model. The default model was used by all
          # Network Services, prior to the implementation of a model per NS.
-         if ns_uuid.lower() is "default":
+         if ns_uuid.lower() == "default":
              return False
  
          if not self.authenticated:
  
          try:
              await self.controller.destroy_models(ns_uuid)
-         except JujuError as e:
+         except JujuError:
              raise NetworkServiceDoesNotExist(
                  "The Network Service '{}' does not exist".format(ns_uuid)
              )
              self.refcount['model'] += 1
  
              # Create an observer for this model
 +            await self.create_model_monitor(model_name)
 +
 +        return self.models[model_name]
 +
 +    async def create_model_monitor(self, model_name):
 +        """Create a monitor for the model, if none exists."""
 +        if not self.authenticated:
 +            await self.login()
 +
 +        if model_name not in self.monitors:
              self.monitors[model_name] = VCAMonitor(model_name)
              self.models[model_name].add_observer(self.monitors[model_name])
  
 -        return self.models[model_name]
 +        return True
  
      async def login(self):
          """Login to the Juju controller."""
diff --combined tests/base.py
@@@ -568,12 -568,17 +568,17 @@@ class TestN2VC(object)
                      )
                      subprocess.check_call(shlex.split(cmd))
  
-                 self.artifacts[charm] = {
-                     'tmpdir': builds,
-                     'charm': "{}/builds/{}".format(builds, charm),
-                 }
              except subprocess.CalledProcessError as e:
-                 raise Exception("charm build failed: {}.".format(e))
+                 # charm build will return error code 100 if the charm fails
+                 # the auto-run of charm proof, which we can safely ignore for
+                 # our CI charms.
+                 if e.returncode != 100:
+                     raise Exception("charm build failed: {}.".format(e))
+             self.artifacts[charm] = {
+                 'tmpdir': builds,
+                 'charm': "{}/builds/{}".format(builds, charm),
+             }
  
          return self.artifacts[charm]['charm']
  
          if not self.n2vc:
              self.n2vc = get_n2vc(loop=loop)
  
 +        debug("Creating model for Network Service {}".format(self.ns_name))
 +        await self.n2vc.CreateNetworkService(self.ns_name)
 +
          application = self.n2vc.FormatApplicationName(
              self.ns_name,
              self.vnf_name,
                  try:
                      await self.n2vc.RemoveCharms(self.ns_name, application)
  
 +                    await self.n2vc.DestroyNetworkService(self.ns_name)
 +
                      while True:
                          # Wait for the application to be removed
                          await asyncio.sleep(10)
                              application,
                          ):
                              break
+                     await self.n2vc.DestroyNetworkService(self.ns_name)
  
                      # Need to wait for the charm to finish, because native charms
                      if self.state[application]['container']: