More changes for projects support 39/1539/1
authorPhilip Joseph <philip.joseph@riftio.com>
Fri, 7 Apr 2017 10:06:32 +0000 (15:36 +0530)
committerPhilip Joseph <philip.joseph@riftio.com>
Mon, 10 Apr 2017 15:02:03 +0000 (15:02 +0000)
Signed-off-by: Philip Joseph <philip.joseph@riftio.com>
12 files changed:
common/python/rift/mano/sdn/config.py
common/python/rift/mano/sdn/operdata.py
common/python/rift/mano/utils/project.py
models/plugins/yang/nsr.role.xml
models/plugins/yang/nsr.yang
rwcal/plugins/vala/CMakeLists.txt
rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/publisher/copy_status.py
rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/rpc.py
rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/rwpkgmgr.py
rwlaunchpad/plugins/rwvns/vala/CMakeLists.txt
rwmon/plugins/vala/CMakeLists.txt
rwprojectmano/plugins/rwprojectmano/rift/tasklets/rwprojectmano/rolesmano.py

index 20b17cc..1ae65a5 100644 (file)
@@ -78,9 +78,10 @@ class SDNAccountConfigCallbacks(object):
 class SDNAccountConfigSubscriber(object):
     XPATH = "C,/rw-sdn:sdn/rw-sdn:account"
 
-    def __init__(self, dts, log, rwlog_hdl, sdn_callbacks, acctstore):
+    def __init__(self, dts, log, project, rwlog_hdl, sdn_callbacks, acctstore):
         self._dts = dts
         self._log = log
+        self._project = project
         self._rwlog_hdl = rwlog_hdl
         self._reg = None
 
@@ -205,8 +206,9 @@ class SDNAccountConfigSubscriber(object):
 
             xact_info.respond_xpath(rwdts.XactRspCode.ACK)
 
+        xpath = self._project.add_project(SDNAccountConfigSubscriber.XPATH)
         self._log.debug("Registering for SDN Account config using xpath: %s",
-                        SDNAccountConfigSubscriber.XPATH,
+                        xpath,
                         )
 
         acg_handler = rift.tasklets.AppConfGroup.Handler(
@@ -215,7 +217,7 @@ class SDNAccountConfigSubscriber(object):
 
         with self._dts.appconf_group_create(acg_handler) as acg:
             self._reg = acg.register(
-                    xpath=SDNAccountConfigSubscriber.XPATH,
+                    xpath=xpath,
                     flags=rwdts.Flag.SUBSCRIBER | rwdts.Flag.DELTA_READY | rwdts.Flag.CACHE,
                     on_prepare=on_prepare,
                     )
index 094d804..732c600 100644 (file)
@@ -29,10 +29,11 @@ class SDNAccountNotFound(Exception):
 
 
 class SDNAccountDtsOperdataHandler(object):
-    def __init__(self, dts, log, loop):
+    def __init__(self, dts, log, loop, project):
         self._dts = dts
         self._log = log
         self._loop = loop
+        self._project = project
 
         self.sdn_accounts = {}
         self._oper = None
@@ -63,9 +64,10 @@ class SDNAccountDtsOperdataHandler(object):
 
     def _register_show_status(self):
         def get_xpath(sdn_name=None):
-            return "D,/rw-sdn:sdn/account{}/connection-status".format(
-                    "[name='%s']" % sdn_name if sdn_name is not None else ''
-                    )
+            return self._project.add_project("D,/rw-sdn:sdn/account{}/connection-status".
+                                             format(
+                                                 "[name='%s']" % sdn_name
+                                                 if sdn_name is not None else ''))
 
         @asyncio.coroutine
         def on_prepare(xact_info, action, ks_path, msg):
index 9157f89..96d1de5 100644 (file)
@@ -651,12 +651,14 @@ class ProjectHandler(object):
         except Exception as e:
             self._log.exception("Project {} create for {} failed: {}".
                                 format(name, self._get_tasklet_name(), e))
+            raise e
 
         try:
             yield from self._get_project(name).register()
         except Exception as e:
             self._log.exception("Project {} register for tasklet {} failed: {}".
                                 format(name, self._get_tasklet_name(), e))
+            raise e
 
     @asyncio.coroutine
     def on_delete_prepare(self, name):
index 4353911..0548c7b 100644 (file)
@@ -19,6 +19,7 @@
       <permissions>read execute</permissions>
       <path>/rw-project:project/nsr:ns-instance-config</path>
       <path>/rw-project:project/nsr:ns-instance-opdata</path>
+      <path>/rw-project:project/nsr:key-pair</path>
     </authorize>
   </role-definition>
 
@@ -29,6 +30,7 @@
       <permissions>create read update delete execute</permissions>
       <path>/rw-project:project/nsr:ns-instance-config</path>
       <path>/rw-project:project/nsr:ns-instance-opdata</path>
+      <path>/rw-project:project/nsr:key-pair</path>
       <path>/nsr:exec-scale-out</path>
       <path>/nsr:exec-scale-in</path>
       <path>/nsr:exec-ns-service-primitive</path>
index 50bbc0d..efddc77 100644 (file)
@@ -112,7 +112,7 @@ module nsr
       leaf key-pair-ref {
         description "A reference to the key pair entry in the global key pair table";
         type leafref {
-          path "/nsr:key-pair/nsr:name";
+          path "../../../../key-pair/name";
         }
       }
     }
@@ -137,28 +137,13 @@ module nsr
         leaf key-pair-ref {
           description "A reference to the key pair entry in the global key pair table";
           type leafref {
-            path "/nsr:key-pair/nsr:name";
+            path "../../../../../key-pair/nsr:name";
           }
         }
       }
     }
   }
 
-  list key-pair {
-    key "name";
-    description "Used to configure the list of public keys to be injected as part
-                 of ns instantiation";
-    leaf name {
-      description "Name of this key pair";
-      type string;
-    }
-
-    leaf key {
-      description "Key associated with this key pair";
-      type string;
-    }
-  }
-
   augment "/rw-project:project" {
     list key-pair {
       key "name";
index 7ef9879..9cf53f9 100644 (file)
@@ -35,7 +35,7 @@ rift_add_vala(
   VALA_PACKAGES
     rw_types-1.0 rw_yang-1.0 rw_keyspec-1.0 rw_yang_pb-1.0 rw_schema_proto-1.0
     rw_log_yang-1.0 rw_base_yang-1.0 rwcal_yang-1.0 rw_manifest_yang-1.0 protobuf_c-1.0 ietf_netconf_yang-1.0
-    rw_log-1.0 rw_project_yang-1.0
+    rw_log-1.0 rw_project_yang-1.0 rw_user_yang-1.0
   VAPI_DIRS ${RIFT_SUBMODULE_BINARY_ROOT}/rwcal/plugins/yang
             ${RIFT_SUBMODULE_BINARY_ROOT}/models/plugins/yang
             ${RIFT_SUBMODULE_BINARY_ROOT}/rwvcs/plugins/yang
index 927331c..1fc6801 100644 (file)
@@ -34,16 +34,16 @@ if sys.version_info < (3, 4, 4):
 
 class CopyStatusPublisher(mano_dts.DtsHandler, url_downloader.DownloaderProtocol): 
 
-    def __init__(self, log, dts, loop, tasklet_info):
-        super().__init__(log, dts, loop
-        self.tasks = {} 
-        self.tasklet_info = tasklet_info
+    def __init__(self, log, dts, loop, project):
+        super().__init__(log, dts, loop, project)
+        self.tasks = {}
+        self.tasklet_info = project.tasklet.tasklet_info
 
     def xpath(self, transaction_id=None):
-        return ("D,/rw-pkg-mgmt:copy-jobs/rw-pkg-mgmt:job" +
+        return self.project.add_project("D,/rw-pkg-mgmt:copy-jobs/rw-pkg-mgmt:job" +
             ("[transaction-id='{}']".format(transaction_id) if transaction_id else ""))
         pass
-    
+
     @asyncio.coroutine
     def register(self):
         self.reg = yield from self.dts.register(xpath=self.xpath(),
index d360640..e05a042 100644 (file)
@@ -68,12 +68,12 @@ class EndpointDiscoveryRpcHandler(mano_dts.AbstractRpcHandler):
 class SchemaRpcHandler(mano_dts.AbstractRpcHandler):
     """RPC handler to generate the schema for the packages.
     """
-    def __init__(self, log, dts, loop, project, proxy):
+    def __init__(self, log, dts, loop, proxy):
         """
         Args:
             proxy: Any impl of .proxy.AbstractPackageManagerProxy
         """
-        super().__init__(log, dts, loop, project)
+        super().__init__(log, dts, loop)
         self.proxy = proxy
 
     @property
index 0fcabe3..438f9de 100644 (file)
@@ -40,7 +40,7 @@ from rift.mano.utils.project import (
 from . import rpc
 from .proxy import filesystem
 from . import publisher as pkg_publisher
-from . import subscriber 
+from . import subscriber
 
 class PackageManagerProject(ManoProject):
 
@@ -51,22 +51,26 @@ class PackageManagerProject(ManoProject):
 
         args = [self.log, self.dts, self.loop, self]
         self.job_handler = pkg_publisher.DownloadStatusPublisher(*args)
-        self.copy_publisher = pkg_publisher.CopyStatusPublisher(*args + [self.tasklet.tasklet_info])
+        self.copy_publisher = pkg_publisher.CopyStatusPublisher(*args)
 
-        # create catalog subscribers 
+        # create catalog subscribers
         self.vnfd_catalog_sub = subscriber.VnfdStatusSubscriber(*args)
         self.nsd_catalog_sub = subscriber.NsdStatusSubscriber(*args)
-        
+
         args.append(proxy)
         self.copy_rpc = rpc.PackageCopyOperationsRpcHandler(*(args + [self.copy_publisher]))
 
     @asyncio.coroutine
     def register (self):
-        yield from self.vnfd_catalog_sub.register()
-        yield from self.nsd_catalog_sub.register()
-        yield from self.copy_rpc.register()
-        yield from self.copy_publisher.register()
-        yield from self.job_handler.register()
+        try:
+            yield from self.vnfd_catalog_sub.register()
+            yield from self.nsd_catalog_sub.register()
+            yield from self.copy_rpc.register()
+            yield from self.copy_publisher.register()
+            yield from self.job_handler.register()
+        except Exception as e:
+            self.log.exception("Exception registering project {}: {}".
+                               format(self.name, e))
 
     def deregister (self):
         yield from self.job_handler.deregister()
@@ -135,7 +139,6 @@ class PackageManagerTasklet(rift.tasklets.Tasklet):
         yield from self.delete_rpc.register()
 
         self.log.debug("creating project handler")
-        self.project_handler = ProjectHandler(self, PackageManagerProject)
         self.project_handler.register()
 
     @asyncio.coroutine
index d3aa299..81e8ec4 100644 (file)
@@ -36,7 +36,7 @@ rift_add_vala(
     rw_log_yang-1.0 rw_base_yang-1.0 rwcal_yang-1.0 rwsdnal_yang-1.0 rw_manifest_yang-1.0 protobuf_c-1.0 ietf_netconf_yang-1.0
     ietf_network_yang-1.0 ietf_network_topology_yang-1.0
     ietf_l2_topology_yang-1.0 rw_topology_yang-1.0
-    rw_log-1.0 rw_project_yang-1.0
+    rw_log-1.0 rw_project_yang-1.0 rw_user_yang-1.0
   VAPI_DIRS 
     ${RIFT_SUBMODULE_BINARY_ROOT}/models/plugins/yang
     ${RIFT_SUBMODULE_BINARY_ROOT}/rwcal/plugins/yang
index 5fd03fc..a30179e 100644 (file)
@@ -35,7 +35,7 @@ rift_add_vala(
   VALA_PACKAGES
     rw_types-1.0 rw_yang-1.0 rw_keyspec-1.0 rw_yang_pb-1.0 rw_schema_proto-1.0
     rw_log_yang-1.0 rw_base_yang-1.0 rwmon_yang-1.0 rw_manifest_yang-1.0 protobuf_c-1.0 ietf_netconf_yang-1.0
-    rw_log-1.0 rwcal_yang-1.0 rw_project_yang-1.0
+    rw_log-1.0 rwcal_yang-1.0 rw_project_yang-1.0 rw_user_yang-1.0
   VAPI_DIRS ${RIFT_SUBMODULE_BINARY_ROOT}/rwmon/plugins/yang
             ${RIFT_SUBMODULE_BINARY_ROOT}/rwcal/plugins/yang
             ${RIFT_SUBMODULE_BINARY_ROOT}/models/plugins/yang
index 0083c06..2988a20 100644 (file)
@@ -60,6 +60,7 @@ class ProjectConfigSubscriber(object):
 
         self.users = {}
         self.pub = RoleConfigPublisher(project)
+        self.proj_roles = [role['mano-role'] for role in MANO_PROJECT_ROLES]
 
     def get_xpath(self):
         return "C,/{}[name='{}']/project-config/user".format(NS_PROJECT, self.project_name)
@@ -201,6 +202,17 @@ class ProjectConfigSubscriber(object):
                     self._log.debug("User {}: on_prepare add request".
                                     format(user.key))
 
+                for role in msg.mano_role:
+                    if role.role not in self.proj_roles:
+                        errmsg = "Invalid MANO role {} for user {}". \
+                                 format(role.role, user.key)
+                        self._log.error(errmsg)
+                        xact_info.send_error_xpath(RwTypes.RwStatus.FAILURE,
+                                                   self.get_xpath(),
+                                                   errmsg)
+                        xact_info.respond_xpath(rwdts.XactRspCode.NACK)
+                        return
+
             elif action == rwdts.QueryAction.DELETE:
                 # Check if the user got deleted
                 fref = ProtobufC.FieldReference.alloc()