def test_destroy(self, mock_vnf_destroy): vnf_resource = objects.VnfResource(context=self.context, **fakes.fake_vnf_resource_data( self.vnf_instance.id)) vnf_resource.create() vnf_resource.destroy(self.context) mock_vnf_destroy.assert_called_with(self.context, vnf_resource.id)
def test_save_error(self): vnf_resource = objects.VnfResource(context=self.context, **fakes.fake_vnf_resource_data( self.vnf_instance.id)) vnf_resource.create() vnf_resource.destroy(self.context) vnf_resource.resource_name = 'fake' self.assertRaises(exceptions.VnfResourceNotFound, vnf_resource.save)
def test_create_with_id(self): vnf_resource_data = fakes.fake_vnf_resource_data(self.vnf_instance.id) vnf_resource_data.update({'id': uuidsentinel.uuid}) vnf_resource_obj = objects.VnfResource(context=self.context, **vnf_resource_data) self.assertRaises(exceptions.ObjectActionError, vnf_resource_obj.create)
def test_get_by_vnf_instance_id(self): vnf_resource = objects.VnfResource(context=self.context, **fakes.fake_vnf_resource_data( self.vnf_instance.id)) vnf_resource.create() vnf_resource_list = objects.VnfResourceList() result = vnf_resource_list.get_by_vnf_instance_id( self.context, self.vnf_instance.id) self.assertIsInstance(result.objects, list) self.assertTrue(result.objects)
def get_vnf_resource_object(resource_name="VDU1", resource_type="OS::Nova::Server"): vnf_resource = objects.VnfResource( resource_identifier=uuidsentinel.resource_identifier, id=uuidsentinel.vnf_resource_id, resource_name=resource_name, resource_type=resource_type, vnf_instance_id=uuidsentinel.vnf_instance_id) return vnf_resource
def test_save(self, mock_resource_update): vnf_resource = objects.VnfResource(context=self.context, **fakes.fake_vnf_resource_data( self.vnf_instance.id)) vnf_resource.create() mock_resource_update.return_value = \ fakes.vnf_resource_model_object(vnf_resource) vnf_resource.resource_name = 'fake' vnf_resource.save() mock_resource_update.assert_called_with(self.context, vnf_resource.id, {'resource_name': 'fake'})
def return_vnf_resource(): version_obj = objects.VnfResource( created_at=datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), deleted=False, deleted_at=None, id=uuidsentinel.vnf_resource_id, resource_identifier=uuidsentinel.resource_identifier, resource_name='test-image', resource_status='CREATED', resource_type='image', updated_at=None, vnf_instance_id=uuidsentinel.vnf_instance_id) return version_obj
def pre_instantiation_vnf(self, context, vnf_instance, vim_connection_info, vnf_software_images): glance_client = gc.GlanceClient(vim_connection_info) vnf_resources = {} def _roll_back_images(): # Delete all previously created images for vnf for key, resources in vnf_resources.items(): for vnf_resource in resources: try: glance_client.delete(vnf_resource.resource_identifier) except Exception: LOG.error( "Failed to delete image %(uuid)s " "for vnf %(id)s", { "uuid": vnf_resource.resource_identifier, "id": vnf_instance.id }) for node_name, vnf_sw_image in vnf_software_images.items(): name = vnf_sw_image.name image_path = vnf_sw_image.image_path is_url = utils.is_url(image_path) if not is_url: filename = image_path else: filename = None try: LOG.info("Creating image %(name)s for vnf %(id)s", { "name": name, "id": vnf_instance.id }) image_data = { "min_disk": vnf_sw_image.min_disk, "min_ram": vnf_sw_image.min_ram, "disk_format": vnf_sw_image.disk_format, "container_format": vnf_sw_image.container_format, "visibility": "private" } if filename: image_data.update({"filename": filename}) image = glance_client.create(name, **image_data) LOG.info("Image %(name)s created successfully for vnf %(id)s", { "name": name, "id": vnf_instance.id }) except Exception as exp: with excutils.save_and_reraise_exception(): exp.reraise = False LOG.error( "Failed to create image %(name)s for vnf %(id)s" "due to error: %(error)s", { "name": name, "id": vnf_instance.id, "error": encodeutils.exception_to_unicode(exp) }) # Delete previously created images _roll_back_images() raise exceptions.VnfPreInstantiationFailed( id=vnf_instance.id, error=encodeutils.exception_to_unicode(exp)) try: if is_url: glance_client.import_image(image, image_path) self._image_create_wait(image.id, vnf_sw_image.hash, glance_client, 'active', vnflcm.ImageCreateWaitFailed) vnf_resource = objects.VnfResource( context=context, vnf_instance_id=vnf_instance.id, resource_name=name, resource_type="image", resource_status="CREATED", resource_identifier=image.id) vnf_resources[node_name] = [vnf_resource] except Exception as exp: with excutils.save_and_reraise_exception(): exp.reraise = False LOG.error( "Image %(name)s not active for vnf %(id)s" "error: %(error)s", { "name": name, "id": vnf_instance.id, "error": encodeutils.exception_to_unicode(exp) }) err_msg = "Failed to delete image %(uuid)s for vnf %(id)s" # Delete the image try: glance_client.delete(image.id) except Exception: LOG.error(err_msg, { "uuid": image.id, "id": vnf_instance.id }) # Delete all previously created images for vnf _roll_back_images() raise exceptions.VnfPreInstantiationFailed( id=vnf_instance.id, error=encodeutils.exception_to_unicode(exp)) return vnf_resources
def test_create(self): vnf_resource = objects.VnfResource(context=self.context, **fakes.fake_vnf_resource_data( self.vnf_instance.id)) vnf_resource.create() self.assertTrue(vnf_resource.id)
def test_destroy_failure_without_id(self): vnf_resource_obj = objects.VnfResource(context=self.context) self.assertRaises(exceptions.ObjectActionError, vnf_resource_obj.destroy, self.context)
def test_generate_hot_from_tosca(self): tosca_file = './data/etsi_nfv/' \ 'tosca_generate_hot_from_tosca.yaml' hot_file = './data/etsi_nfv/hot/' \ 'hot_generate_hot_from_tosca.yaml' vnfd_dict = self._load_yaml(tosca_file, update_import=True) # Input params dev_attrs = {} data = [{ "id": 'VL1', "resource_id": 'neutron-network-uuid_VL1', "ext_cps": [{ "cpd_id": "CP1", "cp_config": [{ "cp_protocol_data": [{ "layer_protocol": "IP_OVER_ETHERNET", "ip_over_ethernet": { "mac_address": 'fa:16:3e:11:11:11', "ip_addresses": [{ 'type': 'IPV4', 'fixed_addresses': ['1.1.1.1'], 'subnet_id': 'neutron-subnet-uuid_CP1'}]} }] }]}]}, { "id": 'VL2', "resource_id": 'neutron-network-uuid_VL2', "ext_cps": [{ "cpd_id": 'CP2', "cp_config": [{ "link_port_id": uuidsentinel.link_port_id, "cp_protocol_data": [{ "layer_protocol": "IP_OVER_ETHERNET"}]}] }], "ext_link_ports": [{ "id": uuidsentinel.link_port_id, "resource_handle": { "resource_id": 'neutron-port-uuid_CP2'} }]}] ext_mg_vl = [{'id': 'VL3', 'vnf_virtual_link_desc_id': 'VL3', 'resource_id': 'neutron-network-uuid_VL3'}] request = {'ext_managed_virtual_links': ext_mg_vl, 'ext_virtual_links': data, 'flavour_id': 'simple'} ctxt = context.get_admin_context() inst_req_info = objects.InstantiateVnfRequest.obj_from_primitive( request, ctxt) # image and info grant_info = { 'VDU1': [objects.VnfResource(id=uuidsentinel.id, vnf_instance_id=uuidsentinel.vnf_instance_id, resource_type='image', resource_identifier='glance-image-uuid_VDU1')]} self.tth._generate_hot_from_tosca(vnfd_dict, dev_attrs, inst_req_info, grant_info) expected_hot_tpl = self._load_yaml(hot_file) actual_hot_tpl = yaml.safe_load(self.tth.heat_template_yaml) self.assertEqual(expected_hot_tpl, actual_hot_tpl)