Exemplo n.º 1
0
    def test_heal_vnf_with_infra_heal_vnf_wait_fail(self, mock_log, mock_save):
        heal_vnf_req = objects.HealVnfRequest(
            vnfc_instance_id=[uuidsentinel.vnfc_instance_id_1])

        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED,
            task_state=fields.VnfInstanceTaskState.HEALING)

        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id
        self._mock_vnf_manager(fail_method_name='heal_vnf_wait')
        driver = vnflcm_driver.VnfLcmDriver()
        # It won't raise any exception if infra driver raises
        # heal_vnf_wait because there is a possibility the vnfc
        # resources could go into inconsistent state so it would
        # proceed further and call post_heal_vnf with a hope
        # it will work and vnflcm can update the vnfc resources
        # properly and hence the _vnf_manager.invoke.call_count
        # should be 3 instead of 2.
        driver.heal_vnf(self.context, vnf_instance, heal_vnf_req)
        self.assertEqual(1, mock_save.call_count)
        self.assertEqual(3, self._vnf_manager.invoke.call_count)

        self.assertEqual(None, vnf_instance.task_state)
        expected_msg = ('Failed to update vnf %(id)s resources for '
                        'instance%(instance)s. Error: %(error)s')
        mock_log.error.assert_called_with(
            expected_msg, {
                'id': vnf_instance.id,
                'instance': vnf_instance.instantiated_vnf_info.instance_id,
                'error': 'heal_vnf_wait failed'
            })
Exemplo n.º 2
0
    def test_heal_vnf_with_infra_post_heal_vnf_fail(self, mock_log, mock_save):
        heal_vnf_req = objects.HealVnfRequest(
            vnfc_instance_id=[uuidsentinel.vnfc_instance_id_1])

        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED,
            task_state=fields.VnfInstanceTaskState.HEALING)

        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id
        self._mock_vnf_manager(fail_method_name='post_heal_vnf')
        driver = vnflcm_driver.VnfLcmDriver()
        self.assertRaises(exceptions.VnfHealFailed, driver.heal_vnf,
                          self.context, vnf_instance, heal_vnf_req)
        self.assertEqual(1, mock_save.call_count)
        self.assertEqual(3, self._vnf_manager.invoke.call_count)

        self.assertEqual(fields.VnfInstanceTaskState.ERROR,
                         vnf_instance.task_state)
        expected_msg = ('Failed to store updated resources information for '
                        'instance %(instance)s for vnf %(id)s. '
                        'Error: %(error)s')
        mock_log.error.assert_called_with(
            expected_msg, {
                'instance': vnf_instance.instantiated_vnf_info.instance_id,
                'id': vnf_instance.id,
                'error': 'post_heal_vnf failed'
            })
Exemplo n.º 3
0
    def test_instantiate_vnf_with_short_notation(self, mock_vnf_instance_save,
                                                 mock_vnf_package_vnfd,
                                                 mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        instantiate_vnf_req_dict = fakes.get_dummy_instantiate_vnf_request()
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        base_path = os.path.dirname(os.path.abspath(__file__))
        sample_vnf_package_zip = os.path.join(
            base_path, "../../etc/samples/"
            "sample_vnf_package_csar_with_short_notation.zip")
        extracted_zip_path = fake_csar
        zipfile.ZipFile(sample_vnf_package_zip,
                        'r').extractall(extracted_zip_path)
        self._mock_vnf_manager(vnf_resource_count=2)
        driver = vnflcm_driver.VnfLcmDriver()
        driver.instantiate_vnf(self.context, vnf_instance_obj,
                               instantiate_vnf_req_obj)
        self.assertEqual(2, mock_create.call_count)
        self.assertEqual("INSTANTIATED", vnf_instance_obj.instantiation_state)
        shutil.rmtree(fake_csar)
Exemplo n.º 4
0
    def test_instantiate_vnf_with_short_notation(self, mock_vnf_instance_save,
                                                 mock_vnf_package_vnfd,
                                                 mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        instantiate_vnf_req_dict = fakes.get_dummy_instantiate_vnf_request()
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        self._copy_csar_files(fake_csar,
                              "sample_vnf_package_csar_with_short_notation")
        self._mock_vnf_manager(vnf_resource_count=2)
        driver = vnflcm_driver.VnfLcmDriver()
        driver.instantiate_vnf(self.context, vnf_instance_obj,
                               instantiate_vnf_req_obj)
        self.assertEqual(2, mock_create.call_count)
        self.assertEqual("INSTANTIATED", vnf_instance_obj.instantiation_state)
        shutil.rmtree(fake_csar)
Exemplo n.º 5
0
    def test_instantiate_vnf_infra_fails_to_wait_after_instantiate(
            self, mock_vnf_instance_save, mock_vnf_package_vnfd, mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        vim_connection_info = fakes.get_dummy_vim_connection_info()
        instantiate_vnf_req_dict = \
            fakes.get_dummy_instantiate_vnf_request(**vim_connection_info)
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        self._copy_csar_files(fake_csar, "vnflcm4")
        self._mock_vnf_manager(fail_method_name='create_wait')
        driver = vnflcm_driver.VnfLcmDriver()
        error = self.assertRaises(exceptions.VnfInstantiationWaitFailed,
                                  driver.instantiate_vnf, self.context,
                                  vnf_instance_obj, instantiate_vnf_req_obj)
        expected_error = ("Vnf instantiation wait failed for vnf %s, error: "
                          "create_wait failed")

        self.assertEqual(expected_error % vnf_instance_obj.id, str(error))
        self.assertEqual("NOT_INSTANTIATED",
                         vnf_instance_obj.instantiation_state)
        self.assertEqual(3, mock_vnf_instance_save.call_count)
        self.assertEqual(5, self._vnf_manager.invoke.call_count)

        shutil.rmtree(fake_csar)
Exemplo n.º 6
0
    def test_instantiate_vnf_with_ext_virtual_links(self,
                                                    mock_vnf_instance_save,
                                                    mock_vnf_package_vnfd,
                                                    mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        req_body = fakes.get_instantiate_vnf_request_with_ext_virtual_links()
        instantiate_vnf_req_dict = utils.convert_camelcase_to_snakecase(
            req_body)
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        self._copy_csar_files(fake_csar, "vnflcm4")
        self._mock_vnf_manager()
        driver = vnflcm_driver.VnfLcmDriver()
        driver.instantiate_vnf(self.context, vnf_instance_obj,
                               instantiate_vnf_req_obj)

        self.assertEqual("INSTANTIATED", vnf_instance_obj.instantiation_state)
        self.assertEqual(2, mock_vnf_instance_save.call_count)
        self.assertEqual(4, self._vnf_manager.invoke.call_count)
        shutil.rmtree(fake_csar)
Exemplo n.º 7
0
 def __init__(self, host, conf=None):
     if conf:
         self.conf = conf
     else:
         self.conf = CONF
     super(Conductor, self).__init__(host=self.conf.host)
     self.vnfm_plugin = plugin.VNFMPlugin()
     self.vnflcm_driver = vnflcm_driver.VnfLcmDriver()
Exemplo n.º 8
0
    def test_heal_vnf_without_vnfc_instance(self, mock_log, mock_save,
                                            mock_vnf_resource_list,
                                            mock_resource_destroy,
                                            mock_resource_create, mock_vim,
                                            mock_vnf_package_vnfd):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        self._copy_csar_files(fake_csar, "vnflcm4")
        mock_vnf_resource_list.return_value = [fakes.return_vnf_resource()]
        # Heal as per SOL003 i.e. without vnfcInstanceId
        heal_vnf_req = objects.HealVnfRequest()

        vim_obj = {
            'vim_id': uuidsentinel.vim_id,
            'vim_name': 'fake_vim',
            'vim_type': 'openstack',
            'vim_auth': {
                'auth_url': 'http://localhost/identity',
                'password': '******',
                'username': '******',
                'project_name': 'test_project'
            }
        }

        mock_vim.return_value = vim_obj

        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED)

        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id
        self._mock_vnf_manager()
        driver = vnflcm_driver.VnfLcmDriver()
        driver.heal_vnf(self.context, vnf_instance, heal_vnf_req)
        self.assertEqual(1, mock_save.call_count)
        # vnf resource software images will be deleted during
        # deleting vnf instance.
        self.assertEqual(1, mock_resource_destroy.call_count)
        # Vnf resource software images will be created during
        # instantiation.
        self.assertEqual(1, mock_resource_create.call_count)
        # Invoke will be called 7 times, 3 for deleting the vnf
        # resources  and 4 during instantiation.
        self.assertEqual(7, self._vnf_manager.invoke.call_count)
        expected_msg = ("Request received for healing vnf '%s' "
                        "is completed successfully")
        mock_log.info.assert_called_with(expected_msg, vnf_instance.id)

        shutil.rmtree(fake_csar)
Exemplo n.º 9
0
    def test_heal_vnf_without_vnfc_instance_infra_instantiate_vnf_fail(
            self, mock_log, mock_save, mock_vnf_resource_list,
            mock_resource_destroy, mock_resource_create, mock_vim,
            mock_vnf_package_vnfd):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        base_path = os.path.dirname(os.path.abspath(__file__))
        sample_vnf_package_zip = os.path.join(
            base_path, "../../etc/samples/sample_vnf_package_csar.zip")
        extracted_zip_path = fake_csar
        zipfile.ZipFile(sample_vnf_package_zip,
                        'r').extractall(extracted_zip_path)

        mock_vnf_resource_list.return_value = [fakes.return_vnf_resource()]
        # Heal as per SOL003 i.e. without vnfcInstanceId
        heal_vnf_req = objects.HealVnfRequest()

        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED)

        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id
        self._mock_vnf_manager(fail_method_name='instantiate_vnf')
        driver = vnflcm_driver.VnfLcmDriver()
        self.assertRaises(exceptions.VnfHealFailed, driver.heal_vnf,
                          self.context, vnf_instance, heal_vnf_req)
        self.assertEqual(1, mock_save.call_count)
        # vnf resource software images will be deleted during
        # deleting vnf instance.
        self.assertEqual(1, mock_resource_destroy.call_count)
        # Vnf resource software images will be created during
        # instantiation.
        self.assertEqual(1, mock_resource_create.call_count)

        self.assertEqual(5, self._vnf_manager.invoke.call_count)
        self.assertEqual(fields.VnfInstanceTaskState.ERROR,
                         vnf_instance.task_state)
        expected_msg = ('Failed to instantiate vnf instance %s '
                        'after termination. The vnf is in inconsistent '
                        'state. Error: Vnf instantiation failed for vnf %s, '
                        'error: instantiate_vnf failed')
        mock_log.error.assert_called_with(expected_msg %
                                          (vnf_instance.id, vnf_instance.id))
Exemplo n.º 10
0
    def test_terminate_vnf_delete_wait_instance_failed(self, mock_vim,
            mock_vnf_instance_save):
        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED)
        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id
        terminate_vnf_req = objects.TerminateVnfRequest(
            termination_type=fields.VnfInstanceTerminationType.FORCEFUL)

        self._mock_vnf_manager(fail_method_name='delete_wait')
        driver = vnflcm_driver.VnfLcmDriver()
        error = self.assertRaises(InfraDriverException, driver.terminate_vnf,
            self.context, vnf_instance, terminate_vnf_req)
        self.assertEqual("delete_wait failed", str(error))
        self.assertEqual(2, mock_vnf_instance_save.call_count)
        self.assertEqual(2, self._vnf_manager.invoke.call_count)
Exemplo n.º 11
0
    def test_terminate_vnf_graceful_no_timeout(self, mock_resource_destroy,
            mock_resource_list, mock_vim, mock_vnf_instance_save):
        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED)
        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id

        mock_resource_list.return_value = [fakes.return_vnf_resource()]
        terminate_vnf_req = objects.TerminateVnfRequest(
            termination_type=fields.VnfInstanceTerminationType.GRACEFUL)

        self._mock_vnf_manager()
        driver = vnflcm_driver.VnfLcmDriver()
        driver.terminate_vnf(self.context, vnf_instance, terminate_vnf_req)
        self.assertEqual(2, mock_vnf_instance_save.call_count)
        self.assertEqual(1, mock_resource_destroy.call_count)
Exemplo n.º 12
0
    def test_heal_vnf_with_vnfc_instance(self, mock_log, mock_save):
        heal_vnf_req = objects.HealVnfRequest(
            vnfc_instance_id=[uuidsentinel.vnfc_instance_id_1])

        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED,
            task_state=fields.VnfInstanceTaskState.HEALING)

        self._mock_vnf_manager()
        driver = vnflcm_driver.VnfLcmDriver()
        driver.heal_vnf(self.context, vnf_instance, heal_vnf_req)
        self.assertEqual(1, mock_save.call_count)
        self.assertEqual(3, self._vnf_manager.invoke.call_count)

        self.assertEqual(None, vnf_instance.task_state)
        expected_msg = ("Request received for healing vnf '%s' "
                        "is completed successfully")
        mock_log.info.assert_called_with(expected_msg, vnf_instance.id)
Exemplo n.º 13
0
    def test_heal_vnf_without_vnfc_instance_infra_delete_fail(
            self, mock_log, mock_save):
        # Heal as per SOL003 i.e. without vnfcInstanceId
        heal_vnf_req = objects.HealVnfRequest()

        vnf_instance = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED)

        vnf_instance.instantiated_vnf_info.instance_id =\
            uuidsentinel.instance_id
        self._mock_vnf_manager(fail_method_name='delete')
        driver = vnflcm_driver.VnfLcmDriver()
        self.assertRaises(exceptions.VnfHealFailed, driver.heal_vnf,
                          self.context, vnf_instance, heal_vnf_req)
        self.assertEqual(1, mock_save.call_count)
        self.assertEqual(1, self._vnf_manager.invoke.call_count)
        self.assertEqual(fields.VnfInstanceTaskState.ERROR,
                         vnf_instance.task_state)
        expected_msg = ('Failed to delete vnf resources for vnf instance %s '
                        'before respawning. The vnf is in inconsistent '
                        'state. Error: delete failed')
        mock_log.error.assert_called_with(expected_msg % vnf_instance.id)
Exemplo n.º 14
0
    def test_instantiate_vnf_infra_fails_to_instantiate(
            self, mock_vnf_instance_save, mock_vnf_package_vnfd, mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        vim_connection_info = fakes.get_dummy_vim_connection_info()
        instantiate_vnf_req_dict = \
            fakes.get_dummy_instantiate_vnf_request(**vim_connection_info)
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        base_path = os.path.dirname(os.path.abspath(__file__))
        sample_vnf_package_zip = os.path.join(
            base_path, "../../etc/samples/sample_vnf_package_csar.zip")
        extracted_zip_path = fake_csar
        zipfile.ZipFile(sample_vnf_package_zip,
                        'r').extractall(extracted_zip_path)

        self._mock_vnf_manager(fail_method_name="instantiate_vnf")
        driver = vnflcm_driver.VnfLcmDriver()
        error = self.assertRaises(exceptions.VnfInstantiationFailed,
                                  driver.instantiate_vnf, self.context,
                                  vnf_instance_obj, instantiate_vnf_req_obj)
        expected_error = ("Vnf instantiation failed for vnf %s, error: "
                          "instantiate_vnf failed")

        self.assertEqual(expected_error % vnf_instance_obj.id, str(error))
        self.assertEqual("NOT_INSTANTIATED",
                         vnf_instance_obj.instantiation_state)
        self.assertEqual(2, mock_vnf_instance_save.call_count)
        self.assertEqual(2, self._vnf_manager.invoke.call_count)

        shutil.rmtree(fake_csar)