Fix bug 564
[osm/N2VC.git] / tests / base.py
index 0959059..4d26a7f 100644 (file)
@@ -25,8 +25,7 @@ here = os.path.dirname(os.path.realpath(__file__))
 def is_bootstrapped():
     result = subprocess.run(['juju', 'switch'], stdout=subprocess.PIPE)
     return (
 def is_bootstrapped():
     result = subprocess.run(['juju', 'switch'], stdout=subprocess.PIPE)
     return (
-        result.returncode == 0 and
-        len(result.stdout.decode().strip()) > 0)
+        result.returncode == 0 and len(result.stdout.decode().strip()) > 0)
 
 
 bootstrapped = pytest.mark.skipif(
 
 
 bootstrapped = pytest.mark.skipif(
@@ -65,9 +64,9 @@ def debug(msg):
     logging.debug(
         "[{}] {}".format(now.strftime('%Y-%m-%dT%H:%M:%S'), msg)
     )
     logging.debug(
         "[{}] {}".format(now.strftime('%Y-%m-%dT%H:%M:%S'), msg)
     )
-    print(
-        "[{}] {}".format(now.strftime('%Y-%m-%dT%H:%M:%S'), msg)
-    )
+    print(
+        "[{}] {}".format(now.strftime('%Y-%m-%dT%H:%M:%S'), msg)
+    )
 
 
 def get_charm_path():
 
 
 def get_charm_path():
@@ -432,9 +431,6 @@ class TestN2VC(object):
         self.ns_name = self.nsd['name']
         self.vnf_name = self.vnfd['name']
 
         self.ns_name = self.nsd['name']
         self.vnf_name = self.vnfd['name']
 
-        # Hard-coded to default for now, but this may change in the future.
-        self.model = "default"
-
         self.charms = {}
         self.parse_vnf_descriptor()
         assert self.charms is not {}
         self.charms = {}
         self.parse_vnf_descriptor()
         assert self.charms is not {}
@@ -553,7 +549,7 @@ class TestN2VC(object):
         # Make sure the charm snap is installed
         try:
             subprocess.check_call(['which', 'charm'])
         # Make sure the charm snap is installed
         try:
             subprocess.check_call(['which', 'charm'])
-        except subprocess.CalledProcessError as e:
+        except subprocess.CalledProcessError:
             raise Exception("charm snap not installed.")
 
         if charm not in self.artifacts:
             raise Exception("charm snap not installed.")
 
         if charm not in self.artifacts:
@@ -565,19 +561,24 @@ class TestN2VC(object):
                 builds = get_charm_path()
 
                 if not os.path.exists("{}/builds/{}".format(builds, charm)):
                 builds = get_charm_path()
 
                 if not os.path.exists("{}/builds/{}".format(builds, charm)):
-                    cmd = "charm build {}/{} -o {}/".format(
+                    cmd = "charm build --no-local-layers {}/{} -o {}/".format(
                         get_layer_path(),
                         charm,
                         builds,
                     )
                     subprocess.check_call(shlex.split(cmd))
 
                         get_layer_path(),
                         charm,
                         builds,
                     )
                     subprocess.check_call(shlex.split(cmd))
 
-                self.artifacts[charm] = {
-                    'tmpdir': builds,
-                    'charm': "{}/builds/{}".format(builds, charm),
-                }
             except subprocess.CalledProcessError as e:
             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']
 
 
         return self.artifacts[charm]['charm']
 
@@ -891,16 +892,17 @@ class TestN2VC(object):
 
             for application in self.charms:
                 try:
 
             for application in self.charms:
                 try:
-                    await self.n2vc.RemoveCharms(self.model, application)
+                    await self.n2vc.RemoveCharms(self.ns_name, application)
 
                     while True:
                         # Wait for the application to be removed
                         await asyncio.sleep(10)
                         if not await self.n2vc.HasApplication(
 
                     while True:
                         # Wait for the application to be removed
                         await asyncio.sleep(10)
                         if not await self.n2vc.HasApplication(
-                            self.model,
+                            self.ns_name,
                             application,
                         ):
                             break
                             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']:
 
                     # Need to wait for the charm to finish, because native charms
                     if self.state[application]['container']:
@@ -962,7 +964,7 @@ class TestN2VC(object):
         )
 
         await self.n2vc.ExecutePrimitive(
         )
 
         await self.n2vc.ExecutePrimitive(
-            self.model,
+            self.ns_name,
             application,
             "config",
             None,
             application,
             "config",
             None,
@@ -987,7 +989,7 @@ class TestN2VC(object):
             Re-run those actions so we can inspect the status.
             """
             uuids = await self.n2vc.ExecuteInitialPrimitives(
             Re-run those actions so we can inspect the status.
             """
             uuids = await self.n2vc.ExecuteInitialPrimitives(
-                self.model,
+                self.ns_name,
                 application,
                 init_config,
             )
                 application,
                 init_config,
             )
@@ -1019,7 +1021,7 @@ class TestN2VC(object):
             debug("Collecting metrics for {}".format(application))
 
             metrics = await self.n2vc.GetMetrics(
             debug("Collecting metrics for {}".format(application))
 
             metrics = await self.n2vc.GetMetrics(
-                self.model,
+                self.ns_name,
                 application,
             )
 
                 application,
             )
 
@@ -1069,7 +1071,7 @@ class TestN2VC(object):
 
                     debug("Getting status of {} ({})...".format(uid, status))
                     status = await self.n2vc.GetPrimitiveStatus(
 
                     debug("Getting status of {} ({})...".format(uid, status))
                     status = await self.n2vc.GetPrimitiveStatus(
-                        self.model,
+                        self.ns_name,
                         uid,
                     )
                     debug("...state of {} is {}".format(uid, status))
                         uid,
                     )
                     debug("...state of {} is {}".format(uid, status))