def generate_nsr(name, nsd_ref, short_name="test short name", description="test description", admin_status="ENABLED", nsr_id=None): ''' A helper method for generating an NSR Arguments: name - name of the nsr being generated nsd_ref - reference to the nsd this NSR is an instance of short_name - short name of the nsr being generated description - description of the nsr being generated admin_status - flag indicating NSR admin status (enabled/disabled) nsr_id - unique identifier of this NSR ''' nsr = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() nsr.name = rift.auto.mano.resource_name(name) nsr.nsd_ref = nsd_ref nsr.short_name = short_name nsr.description = description nsr.admin_status = "ENABLED" if nsr_id: nsr.id = nsr_id else: nsr.id = str(uuid.uuid4()) return nsr
def create_nsr_from_nsd_id(nsd_id): nsr = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() nsr.id = str(uuid.uuid4()) nsr.name = "UTM-only" nsr.short_name = "UTM-only" nsr.description = "1 VNFs with 5 VLs" nsr.nsd_ref = nsd_id nsr.admin_status = "ENABLED" return nsr
def create_nsr_from_nsd_id(nsd_id): nsr = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() nsr.id = str(uuid.uuid4()) nsr.name = "TG-Vrouter-TS-EPA-SRIOV" nsr.short_name = "TG-Vrouter-TS-EPA-SRIOV" nsr.description = "3 VNFs with Trafgen, Vrouter and Trafsink EPA SRIOV" nsr.nsd_ref = nsd_id nsr.admin_status = "ENABLED" return nsr
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)
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)
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)