update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / test / utest_rwnsm.py
index e125739..48b4ff2 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
-# 
-#   Copyright 2016 RIFT.IO Inc
+#
+#   Copyright 2016-17 RIFT.IO Inc
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
@@ -25,15 +25,29 @@ import unittest
 import uuid
 import xmlrunner
 
+import gi
+gi.require_version('ProjectNsdYang', '1.0')
+gi.require_version('NsrYang', '1.0')
+
+#Setting RIFT_VAR_ROOT if not already set for unit test execution
+if "RIFT_VAR_ROOT" not in os.environ:
+    os.environ['RIFT_VAR_ROOT'] = os.path.join(os.environ['RIFT_INSTALL'], 'var/rift/unittest')
+
 from gi.repository import (
-        NsdYang,
-        NsrYang,
-        )
+    ProjectNsdYang,
+    NsrYang,
+)
+
 
 logger = logging.getLogger('test-rwnsmtasklet')
 
 import rift.tasklets.rwnsmtasklet.rwnsmtasklet as rwnsmtasklet
 import rift.tasklets.rwnsmtasklet.xpath as rwxpath
+from rift.mano.utils.project import ManoProject
+
+
+def prefix_project(xpath):
+    return "/rw-project:project" + xpath
 
 class TestGiXpath(unittest.TestCase):
     def setUp(self):
@@ -46,26 +60,27 @@ class TestGiXpath(unittest.TestCase):
 
         """
         # Create the initial NSD catalog
-        nsd_catalog = NsdYang.YangData_Nsd_NsdCatalog()
+        nsd_catalog = ProjectNsdYang.YangData_RwProject_Project_NsdCatalog()
 
         # Create an NSD, set its 'id', and add it to the catalog
         nsd_id = str(uuid.uuid4())
         nsd_catalog.nsd.append(
-                NsdYang.YangData_Nsd_NsdCatalog_Nsd(
+                ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd(
                     id=nsd_id,
                     )
                 )
 
         # Retrieve the NSD using and xpath expression
-        xpath = '/nsd:nsd-catalog/nsd:nsd[nsd:id={}]'.format(nsd_id)
+        xpath = prefix_project('/project-nsd:nsd-catalog/project-nsd:nsd[project-nsd:id={}]'.
+                               format(nsd_id))
         nsd = rwxpath.getxattr(nsd_catalog, xpath)
 
         self.assertEqual(nsd_id, nsd.id)
 
         # Modified the name of the NSD using an xpath expression
-        rwxpath.setxattr(nsd_catalog, xpath + "/nsd:name", "test-name")
+        rwxpath.setxattr(nsd_catalog, xpath + "/project-nsd:name", "test-name")
 
-        name = rwxpath.getxattr(nsd_catalog, xpath + "/nsd:name")
+        name = rwxpath.getxattr(nsd_catalog, xpath + "/project-nsd:name")
         self.assertEqual("test-name", name)
 
     def test_nsd_scalar_fields(self):
@@ -74,24 +89,27 @@ class TestGiXpath(unittest.TestCase):
 
         """
         # Define a simple NSD
-        nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
+        nsd = ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd()
+
+        xpath = prefix_project('/project-nsd:nsd-catalog/project-nsd:nsd')
 
         # Check that the unset fields are in fact set to None
-        self.assertEqual(None, rwxpath.getxattr(nsd, "/nsd:nsd-catalog/nsd:nsd/nsd:name"))
-        self.assertEqual(None, rwxpath.getxattr(nsd, "/nsd:nsd-catalog/nsd:nsd/nsd:short-name"))
+        self.assertEqual(None, rwxpath.getxattr(nsd, xpath + "/project-nsd:name"))
+        self.assertEqual(None, rwxpath.getxattr(nsd, xpath + "/project-nsd:short-name"))
 
         # Set the values of the 'name' and 'short-name' fields
-        rwxpath.setxattr(nsd, "/nsd:nsd-catalog/nsd:nsd/nsd:name", "test-name")
-        rwxpath.setxattr(nsd, "/nsd:nsd-catalog/nsd:nsd/nsd:short-name", "test-short-name")
+        rwxpath.setxattr(nsd, xpath + "/project-nsd:name", "test-name")
+        rwxpath.setxattr(nsd, xpath + "/project-nsd:short-name", "test-short-name")
 
         # Check that the 'name' and 'short-name' fields are correctly set
-        self.assertEqual(nsd.name, rwxpath.getxattr(nsd, "/nsd:nsd-catalog/nsd:nsd/nsd:name"))
-        self.assertEqual(nsd.short_name, rwxpath.getxattr(nsd, "/nsd:nsd-catalog/nsd:nsd/nsd:short-name"))
+        self.assertEqual(nsd.name, rwxpath.getxattr(nsd, xpath + "/project-nsd:name"))
+        self.assertEqual(nsd.short_name, rwxpath.getxattr(nsd, xpath + "/project-nsd:short-name"))
 
 
 class TestInputParameterSubstitution(unittest.TestCase):
     def setUp(self):
-        self.substitute_input_parameters = rwnsmtasklet.InputParameterSubstitution(logger)
+        project = ManoProject(logger)
+        self.substitute_input_parameters = rwnsmtasklet.InputParameterSubstitution(logger, project)
 
     def test_null_arguments(self):
         """
@@ -99,8 +117,8 @@ class TestInputParameterSubstitution(unittest.TestCase):
         config, no exception should be raised.
 
         """
-        nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
-        nsr_config = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr()
+        nsd = ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd()
+        nsr_config = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr()
 
         self.substitute_input_parameters(None, None)
         self.substitute_input_parameters(nsd, None)
@@ -115,26 +133,26 @@ class TestInputParameterSubstitution(unittest.TestCase):
 
         """
         # Define the original NSD
-        nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
+        nsd = ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd()
         nsd.name = "robert"
         nsd.short_name = "bob"
 
         # Define which parameters may be modified
         nsd.input_parameter_xpath.append(
-                NsdYang.YangData_Nsd_NsdCatalog_Nsd_InputParameterXpath(
+                ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd_InputParameterXpath(
                     xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                     label="NSD Name",
                     )
                 )
 
         # Define the input parameters that are intended to be modified
-        nsr_config = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr()
+        nsr_config = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr()
         nsr_config.input_parameter.extend([
-            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
+            NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter(
                 xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                 value="alice",
                 ),
-            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
+            NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter(
                 xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name",
                 value="alice",
                 ),
@@ -153,30 +171,30 @@ class TestInputParameterSubstitution(unittest.TestCase):
 
         """
         # Define the original NSD
-        nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
-        nsd.name = "robert"
-        nsd.short_name = "bob"
+        nsd = ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd()
+        nsd.name = "robert"
+        nsd.short_name = "bob"
 
         # Define which parameters may be modified
         nsd.input_parameter_xpath.extend([
-                NsdYang.YangData_Nsd_NsdCatalog_Nsd_InputParameterXpath(
+                ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd_InputParameterXpath(
                     xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                     label="NSD Name",
                     ),
-                NsdYang.YangData_Nsd_NsdCatalog_Nsd_InputParameterXpath(
+                ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd_InputParameterXpath(
                     xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name",
                     label="NSD Short Name",
                     ),
                 ])
 
         # Define the input parameters that are intended to be modified
-        nsr_config = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr()
+        nsr_config = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr()
         nsr_config.input_parameter.extend([
-            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
+            NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter(
                 xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                 value="robert",
                 ),
-            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
+            NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter(
                 xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name",
                 value="bob",
                 ),