Merge "358 - Handling Vnf delete conflicts from RO"
authorvelandy <rajesh.velandy@riftio.com>
Wed, 11 Oct 2017 23:26:18 +0000 (01:26 +0200)
committerGerrit Code Review <root@osm.etsi.org>
Wed, 11 Oct 2017 23:26:18 +0000 (01:26 +0200)
common/python/rift/mano/config_agent/operdata.py
models/openmano/python/rift/openmano/rift2openmano.py
rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/jujuconf.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py

index 49f5b03..94e9976 100644 (file)
@@ -69,8 +69,12 @@ class JujuClient(object):
                 loop=loop,
             ))
         except Exception as e:
+            loop.close()
+
             msg = "JujuClient: Connection Failed: %s", str(e)
             self._log.error(msg)
+            status = "failure"
+            details = msg
             raise Exception(msg)
         else:
             self._log.error("Success reached.")
index 91ae8a9..e02269b 100755 (executable)
@@ -273,19 +273,19 @@ def rift2openmano_vnfd_nsd(rift_nsd, rift_vnfds, openmano_vnfd_ids, http_api, ri
 
 
 def cloud_init(rift_vnfd_id, vdu, project_name='default'):
-    """ Populate cloud_init with script from
+    """ Populate cloud-init with script from
          either the inline contents or from the file provided
     """
     vnfd_package_store = rift.package.store.VnfdPackageFilesystemStore(logger, project=project_name)
 
     cloud_init_msg = None
-    if 'cloud_init' in vdu:
-        logger.debug("cloud_init script provided inline %s", vdu['cloud_init'])
-        cloud_init_msg = vdu['cloud_init']
-    elif 'cloud_init_file' in vdu:
+    if 'cloud-init' in vdu:
+        logger.debug("cloud-init script provided inline %s", vdu['cloud-init'])
+        cloud_init_msg = vdu['cloud-init']
+    elif 'cloud-init-file' in vdu:
     # Get cloud-init script contents from the file provided in the cloud_init_file param
-        logger.debug("cloud_init script provided in file %s", vdu['cloud_init_file'])
-        filename = vdu['cloud_init_file']
+        logger.debug("cloud-init script provided in file %s", vdu['cloud-init-file'])
+        filename = vdu['cloud-init-file']
         vnfd_package_store.refresh()
         stored_package = vnfd_package_store.get_package(rift_vnfd_id)
         cloud_init_extractor = rift.package.cloud_init.PackageCloudInitExtractor(logger)
@@ -319,37 +319,35 @@ def config_file_init(rift_vnfd_id, vdu, cfg_file, project_name='default'):
     logger.debug("Current config file msg is {}".format(cfg_file_msg))
     return cfg_file_msg
 
-def rift2openmano_vnfd(rift_vnfd, rift_nsd, http_api):
+def rift2openmano_vnfd(rift_vnfd, rift_nsd, http_api, project):
     try:
         openmano_vnfd_im_body = json.loads(rift_vnfd.from_dict())
         
         # All type_yang leafs renamed to type
         
-
         vnfd_dict = openmano_vnfd_im_body['vnfd-catalog']['vnfd'][0]
         
         if 'vdu' in vnfd_dict:
             for vdu in vnfd_dict['vdu']:
-                if 'cloud_init_file' in vdu:
+                if 'cloud-init-file' in vdu:
                     # Replacing the leaf with the actual contents of the file.
                     # The RO does not have the ability to read files yet.
-                    vdu['cloud_init_file'] = cloud_init(openmano_vnfd_im_body.id, vdu)
-                elif 'cloud_init' in vdu:
-                    vdu['cloud_init'] = cloud_init(openmano_vnfd_im_body.id, vdu)
+                    vdu['cloud-init-file'] = cloud_init(vnfd_dict['id'], vdu, project)
+                elif 'cloud-init' in vdu:
+                    vdu['cloud-init'] = cloud_init(vnfd_dict['id'], vdu, project)
 
-                if 'supplemental_boot_data' in vdu:
-                    if 'config_file' in vdu['supplemental_boot_data']:
-                        for config_file in vdu['supplemental_boot_data']['config_file']:
+                if 'supplemental-boot-data' in vdu:
+                    if 'config-file' in vdu['supplemental-boot-data']:
+                        for config_file in vdu['supplemental-boot-data']['config-file']:
                             # Replacing the leaf with the actual contents of the file.
                             # The RO does not have the ability to read files yet.
-                            config_file['source'] = config_file_init(openmano_vnfd_im_body.id, vdu, config_file['source'])
+                            config_file['source'] = config_file_init(vnfd_dict['id'], vdu, config_file['source'], project)
         
         openmano_vnfd_api_format = {
                                     "vnfd:vnfd-catalog": {
                                         "vnfd": [vnfd_dict]
                                     }
                                 }
-
         openmano_vnfd = http_api.post_vnfd_v3(openmano_vnfd_api_format)
         
         return openmano_vnfd
index 2691ec5..0b7ecae 100644 (file)
@@ -25,8 +25,9 @@ import rift.mano.utils.juju_api as juju
 from . import riftcm_config_plugin
 
 
-# Charm service name accepts only a to z and -.
 def get_vnf_unique_name(nsr_name, vnfr_name, member_vnf_index):
+    """Get the unique VNF name.
+    Charm names accepts only a to z and non-consecutive - characters."""
     name = "{}-{}-{}".format(nsr_name, vnfr_name, member_vnf_index)
     new_name = ''
     for c in name:
@@ -35,7 +36,7 @@ def get_vnf_unique_name(nsr_name, vnfr_name, member_vnf_index):
         elif not c.isalpha():
             c = "-"
         new_name += c
-    return new_name.lower()
+    return re.sub('\-+', '-', new_name.lower())
 
 
 class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
@@ -185,12 +186,11 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
                                 'launchpad/packages/vnfd',
                                 self._project.name,
                                 agent_vnfr.vnfr_msg.vnfd.id,
-                                'charms/trusty',
+                                'charms',
                                 charm)
             self._log.debug("jujuCA: Charm dir is {}".format(path))
             if not os.path.isdir(path):
-                self._log.error("jujuCA: Did not find the charm directory at {}".
-                                format(path))
+                self._log.error("jujuCA: Did not find the charm directory at {}".format(path))
                 path = None
         except Exception as e:
             self.log.exception(e)
@@ -559,6 +559,7 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
 
         try:
             vnfr = self._juju_vnfs[agent_vnfr.id].vnfr
+            service = vnfr['vnf_juju_name']
         except KeyError:
             self._log.debug("Did not find VNFR %s in Juju plugin",
                             agent_vnfr.name)
@@ -618,9 +619,6 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
                         self._log.error(msg)
                         return False
 
-                    elif rc == "pending":
-                        action_ids.append(eid)
-
                 elif primitive.name:
                     config = {}
                     if primitive.name == 'config':
index 3761d1b..fa933ba 100644 (file)
@@ -161,7 +161,8 @@ class VnfrConsoleOperdataDtsHandler(object):
 
 
 class OpenmanoVnfr(object):
-    def __init__(self, log, loop, cli_api, http_api, vnfr, nsd, ssh_key=None):
+    def __init__(self, project, log, loop, cli_api, http_api, vnfr, nsd, ssh_key=None):
+        self._project = project
         self._log = log
         self._loop = loop
         self._cli_api = cli_api
@@ -195,7 +196,7 @@ class OpenmanoVnfr(object):
     @property
     def openmano_vnfd(self):
         self._log.debug("Converting vnfd %s from rift to openmano", self.vnfd.id)
-        openmano_vnfd = rift2openmano.rift2openmano_vnfd(self.vnfd, self.nsd, self._http_api)
+        openmano_vnfd = rift2openmano.rift2openmano_vnfd(self.vnfd, self.nsd, self._http_api, self._project)
         return openmano_vnfd
 
     @property
@@ -574,7 +575,7 @@ class OpenmanoNsr(object):
 
     @asyncio.coroutine
     def add_vnfr(self, vnfr):
-        vnfr = OpenmanoVnfr(self._log, self._loop, self._cli_api, self.http_api,
+        vnfr = OpenmanoVnfr(self._project, self._log, self._loop, self._cli_api, self.http_api,
                                 vnfr, nsd=self.nsd, ssh_key=self._ssh_key)
         yield from vnfr.create()
         self._vnfrs.append(vnfr)