Exemplo n.º 1
0
    def test_nsd_scalar_fields(self):
        """
        Test that setxattr correctly sets the value specified by an xpath.

        """
        # Define a simple NSD
        nsd = NsdYang.YangData_Nsd_NsdCatalog_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"))

        # 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")

        # 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"))
Exemplo n.º 2
0
    def test_nsd_elements(self):
        """
        Test that a particular element in a list is corerctly retrieved. In
        this case, we are trying to retrieve an NSD from the NSD catalog.

        """
        # Create the initial NSD catalog
        nsd_catalog = NsdYang.YangData_Nsd_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(
            id=nsd_id, ))

        # Retrieve the NSD using and xpath expression
        xpath = '/nsd:nsd-catalog/nsd:nsd[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")

        name = rwxpath.getxattr(nsd_catalog, xpath + "/nsd:name")
        self.assertEqual("test-name", name)
Exemplo n.º 3
0
 def test_update_nsd(self):
     nsd_msg = NsdYang.YangData_Nsd_NsdCatalog_Nsd(id=str(uuid.uuid4()),
                                                   name="nsd_name")
     yield from self._loop.run_in_executor(None, self._onboarder.update,
                                           nsd_msg)
     self.assertEqual(self._handler_info.last_request_message, nsd_msg)
     self.assertEqual(self._handler_info.last_descriptor_type, "nsd")
     self.assertEqual(self._handler_info.last_method, "PUT")
Exemplo n.º 4
0
 def get_msg(self, desc=None):
     if desc is None:
         desc = NsdYang.YangData_Nsd_NsdCatalog_Nsd(id=str(uuid.uuid4()),
                                                    name="nsd_name")
     serializer = OnboardTestCase.DESC_SERIALIZER_MAP['nsd']
     jstr = serializer.to_json_string(desc, project_ns=False)
     self._desc = jstr
     hdl = io.BytesIO(str.encode(jstr))
     return serializer.from_file_hdl(hdl, ".json")
Exemplo n.º 5
0
    def test_bad_descriptor_type(self):
        nsd_msg = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
        with self.assertRaises(TypeError):
            yield from self._loop.run_in_executor(None, self._onboarder.update,
                                                  nsd_msg)

        with self.assertRaises(TypeError):
            yield from self._loop.run_in_executor(None,
                                                  self._onboarder.onboard,
                                                  nsd_msg)
Exemplo n.º 6
0
    def test_null_arguments(self):
        """
        If None is passed to the substitutor for either the NSD or the NSR
        config, no exception should be raised.

        """
        nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
        nsr_config = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr()

        self.substitute_input_parameters(None, None)
        self.substitute_input_parameters(nsd, None)
        self.substitute_input_parameters(None, nsr_config)
Exemplo n.º 7
0
    def test_timeout(self):
        # Set the timeout to something minimal to speed up test
        self._onboarder.timeout = .1

        nsd_msg = NsdYang.YangData_Nsd_NsdCatalog_Nsd(id=str(uuid.uuid4()),
                                                      name="nsd_name")

        # Force the request to timeout by running the call synchronously so the
        with self.assertRaises(onboard.OnboardError):
            self._onboarder.onboard(nsd_msg)

        # Force the request to timeout by running the call synchronously so the
        with self.assertRaises(onboard.UpdateError):
            self._onboarder.update(nsd_msg)
Exemplo n.º 8
0
    def test_bad_port(self):
        # Use a port not used by the instantiated server
        new_port = self._port - 1
        self._onboarder.port = new_port
        nsd_msg = NsdYang.YangData_Nsd_NsdCatalog_Nsd(id=str(uuid.uuid4()),
                                                      name="nsd_name")

        with self.assertRaises(onboard.OnboardError):
            yield from self._loop.run_in_executor(None,
                                                  self._onboarder.onboard,
                                                  nsd_msg)

        with self.assertRaises(onboard.UpdateError):
            yield from self._loop.run_in_executor(None, self._onboarder.update,
                                                  nsd_msg)
Exemplo n.º 9
0
    def test_substitution(self):
        """
        Test that substitution of input parameters occurs as expected.

        """
        # Define the original NSD
        nsd = NsdYang.YangData_Nsd_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(
                xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                label="NSD Name",
            ),
            NsdYang.YangData_Nsd_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.input_parameter.extend([
            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
                xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                value="robert",
            ),
            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
                xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name",
                value="bob",
            ),
        ])

        self.substitute_input_parameters(nsd, nsr_config)

        # Verify that both the 'name' and 'short-name' fields are correctly
        # replaced.
        self.assertEqual("robert", nsd.name)
        self.assertEqual("bob", nsd.short_name)
Exemplo n.º 10
0
    def test_illegal_input_parameter(self):
        """
        In the NSD there is a list of the parameters that are allowed to be
        sbustituted by input parameters. This test checks that when an input
        parameter is provided in the NSR config that is not in the NSD, it is
        not applied.

        """
        # Define the original NSD
        nsd = NsdYang.YangData_Nsd_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(
                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.input_parameter.extend([
            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
                xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name",
                value="alice",
            ),
            NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter(
                xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name",
                value="alice",
            ),
        ])

        self.substitute_input_parameters(nsd, nsr_config)

        # Verify that only the parameter in the input_parameter_xpath list is
        # modified after the input parameters have been applied.
        self.assertEqual("alice", nsd.name)
        self.assertEqual("bob", nsd.short_name)
Exemplo n.º 11
0
 def from_xml_file_hdl(cls, hdl):
     hdl.seek(0)
     descriptor = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
     descriptor.from_xml_v2(RiftNSD.model, hdl.read())
     return cls(descriptor)
Exemplo n.º 12
0
    })
    vnf_config.initial_config_primitive.append(init_config)

    for seq, (intf, cidr) in enumerate(intf_ip_pairs, start=2):
        params = [{"name": "iface-name", "value": intf}]
        if cidr is not None:
            params.append({"name": "cidr", "value": cidr})

        vnf_config.initial_config_primitive.add().from_dict({
            "seq": seq,
            "name": "configure-interface",
            "parameter": params
        })


nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd()
add_pe_vnf(nsd, 1, [
    ("eth1", "10.10.10.9/30"),
    ("eth2", "10.10.10.1/30"),
    ("eth3", None),
])

add_pe_vnf(nsd, 2, [
    ("eth1", "10.10.10.10/30"),
    ("eth2", "10.10.10.6/30"),
    ("eth3", None),
])

add_pe_vnf(nsd, 3, [
    ("eth1", "10.10.10.2/30"),
    ("eth2", "10.10.10.5/30"),