def test_create_vnf_mgmt_driver_exception(self, mock_mgmt_call): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() mock_mgmt_call.side_effect = exceptions.MgmtDriverException vnf_dict = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertEqual(constants.ERROR, vnf_dict['status'])
def test_create_vnf_with_invalid_param_and_config_format(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() vnf_obj['vnf']['attributes']['param_values'] = 'image_name' vnf_obj['vnf']['attributes']['config'] = 'test' self.assertRaises(vnfm.InvalidAPIAttributeType, self.vnfm_plugin.create_vnf, self.context, vnf_obj)
def test_create_vnf_create_wait_failed_exception(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() self.create_wait.side_effect = vnfm.VNFCreateWaitFailed( reason="failed") vnf_dict = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertEqual(constants.ERROR, vnf_dict['status'])
def test_create_vnf_with_vnfd(self): self._insert_dummy_device_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertIn('id', result) self.assertIn('instance_id', result) self.assertIn('status', result) self.assertIn('attributes', result) self.assertIn('mgmt_url', result) self.assertIn('created_at', result) self.assertIn('updated_at', result) self._device_manager.invoke.assert_called_with('test_vim', 'create', plugin=mock.ANY, context=mock.ANY, vnf=mock.ANY, auth_attr=mock.ANY) self._pool.spawn_n.assert_called_once_with(mock.ANY) self._cos_db_plugin.create_event.assert_called_with( self.context, evt_type=constants.RES_EVT_CREATE, res_id=mock.ANY, res_state=mock.ANY, res_type=constants.RES_TYPE_VNF, tstamp=mock.ANY, details=mock.ANY)
def test_create_vnf_duplicate_name(self): self._insert_dummy_device_template() self._insert_dummy_device() vnf_obj = utils.get_dummy_vnf_obj() vnf_obj['vnf']['name'] = 'fake_device' self.assertRaises(exceptions.DuplicateResourceName, self.vnfm_plugin.create_vnf, self.context, vnf_obj)
def test_create_vnf_fail_with_invalid_infra_driver_exception(self): self.vim_client.get_vim.return_value['vim_type'] = 'test_invalid_vim' self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() self.assertRaises(vnfm.InvalidInfraDriver, self.vnfm_plugin.create_vnf, self.context, vnf_obj)
def test_create_vnf_fail(self, mock_delete_vnf): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() self.create.side_effect = vnfm.HeatClientException(msg='test') self.assertRaises(vnfm.HeatClientException, self.vnfm_plugin.create_vnf, self.context, vnf_obj) vnf_id = self.vnfm_plugin.delete_vnf.call_args[0][1] mock_delete_vnf.assert_called_once_with(self.context, vnf_id)
def test_create_vnf_with_config_option(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() config = utils.get_dummy_vnf_config_obj() vnf_obj['vnf']['attributes'] = config['vnf']['attributes'] result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertEqual(vnf_obj['vnf']['attributes']['config'], result['attributes']['config']) self.assertEqual('ACTIVE', result['status'])
def test_create_vnf_with_param_values(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() vnf_obj['vnf']['attributes'] = {'param_values': {'image_name': 'cirros-0.4.0-x86_64-disk', 'flavor': 'm1.tiny'}} result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertEqual(vnf_obj['vnf']['attributes']['param_values'], result['attributes']['param_values']) self.assertEqual('ACTIVE', result['status'])
def test_create_vnf_sync(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() vnf_dict = self.vnfm_plugin.create_vnf_sync(self.context, vnf_obj['vnf']) self.assertIsNotNone(vnf_dict) self.assertEqual('ACTIVE', vnf_dict['status']) self._cos_db_plugin.create_event.assert_called_with( self.context, evt_type=constants.RES_EVT_CREATE, res_id=mock.ANY, res_state=mock.ANY, res_type=constants.RES_TYPE_VNF, tstamp=mock.ANY, details=mock.ANY)
def test_create_vnf_with_param_values(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() vnf_obj['vnf']['attributes'] = { 'param_values': { 'image_name': 'cirros-0.4.0-x86_64-disk', 'flavor': 'm1.tiny' } } result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertEqual(vnf_obj['vnf']['attributes']['param_values'], result['attributes']['param_values']) self.assertEqual('ACTIVE', result['status'])
def test_create_vnf(self): self._insert_dummy_device_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertIn('id', result) self.assertIn('instance_id', result) self.assertIn('status', result) self.assertIn('attributes', result) self.assertIn('mgmt_url', result) self._device_manager.invoke.assert_called_with(mock.ANY, mock.ANY, plugin=mock.ANY, context=mock.ANY, device=mock.ANY) self._pool.spawn_n.assert_called_once_with(mock.ANY)
def test_create_vnf(self): self._insert_dummy_device_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertIn('id', result) self.assertIn('instance_id', result) self.assertIn('status', result) self.assertIn('attributes', result) self.assertIn('mgmt_url', result) self._device_manager.invoke.assert_called_with(mock.ANY, mock.ANY, plugin=mock.ANY, context=mock.ANY, device=mock.ANY, auth_attr=mock.ANY) self._pool.spawn_n.assert_called_once_with(mock.ANY)
def test_create_cvnf_with_vnfd(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertIn('id', result) self.assertIn('instance_id', result) self.assertIn('status', result) self.assertIn('attributes', result) self.assertIn('mgmt_ip_address', result) self.assertIn('created_at', result) self.assertIn('updated_at', result) self.assertEqual('ACTIVE', result['status']) self._cos_db_plugin.create_event.assert_called_with( self.context, evt_type=constants.RES_EVT_CREATE, res_id=mock.ANY, res_state=mock.ANY, res_type=constants.RES_TYPE_VNF, tstamp=mock.ANY, details=mock.ANY)
def test_create_vnf_with_vnfd(self): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertIn('id', result) self.assertIn('instance_id', result) self.assertIn('status', result) self.assertIn('attributes', result) self.assertIn('mgmt_ip_address', result) self.assertIn('created_at', result) self.assertIn('updated_at', result) self.assertEqual('ACTIVE', result['status']) self._cos_db_plugin.create_event.assert_called_with( self.context, evt_type=constants.RES_EVT_CREATE, res_id=mock.ANY, res_state=mock.ANY, res_type=constants.RES_TYPE_VNF, tstamp=mock.ANY, details=mock.ANY)
def test_create_vnf_with_alarm_url(self, mock_create_vnf_status, mock_create_vnf_pre, mock_create_vnf_post): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() alarm_url_dict = {'vdu_hcpu_usage_scaling_out': 'http://localhost/identity', 'vdu_lcpu_usage_scaling_in': 'http://localhost/identity'} self._vnf_alarm_monitor.update_vnf_with_alarm.return_value = \ alarm_url_dict dummy_vnf = self._get_dummy_vnf(utils.vnfd_alarm_scale_tosca_template, status='PENDING_CREATE') mock_create_vnf_pre.return_value = dummy_vnf vnf_dict = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertEqual(alarm_url_dict['vdu_lcpu_usage_scaling_in'], vnf_dict['attributes']['vdu_lcpu_usage_scaling_in']) self.assertEqual(alarm_url_dict['vdu_hcpu_usage_scaling_out'], vnf_dict['attributes']['vdu_hcpu_usage_scaling_out'])
def test_create_vnf_with_alarm_url(self, mock_create_vnf_status, mock_create_vnf_pre, mock_create_vnf_post): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() alarm_url_dict = { 'vdu_hcpu_usage_scaling_out': 'http://localhost/identity', 'vdu_lcpu_usage_scaling_in': 'http://localhost/identity' } self._vnf_alarm_monitor.update_vnf_with_alarm.return_value = \ alarm_url_dict dummy_vnf = self._get_dummy_vnf(utils.vnfd_alarm_scale_tosca_template, status='PENDING_CREATE') mock_create_vnf_pre.return_value = dummy_vnf vnf_dict = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertEqual(alarm_url_dict['vdu_lcpu_usage_scaling_in'], vnf_dict['attributes']['vdu_lcpu_usage_scaling_in']) self.assertEqual(alarm_url_dict['vdu_hcpu_usage_scaling_out'], vnf_dict['attributes']['vdu_hcpu_usage_scaling_out'])
def test_create_vnf(self): self._insert_dummy_device_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertIsNotNone(result) self.assertIn('id', result) self.assertIn('instance_id', result) self.assertIn('status', result) self.assertIn('attributes', result) self.assertIn('mgmt_url', result) self.assertIn('created_at', result) self.assertIn('updated_at', result) self._device_manager.invoke.assert_called_with('test_vim', 'create', plugin=mock.ANY, context=mock.ANY, vnf=mock.ANY, auth_attr=mock.ANY) self._pool.spawn_n.assert_called_once_with(mock.ANY) self._cos_db_plugin.create_event.assert_called_with( self.context, evt_type=constants.RES_EVT_CREATE, res_id=mock.ANY, res_state=mock.ANY, res_type=constants.RES_TYPE_VNF, tstamp=mock.ANY, details=mock.ANY)
def test_show_vnf_details_vnf_inactive(self): self._insert_dummy_device_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertRaises(vnfm.VNFInactive, self.vnfm_plugin.get_vnf_resources, self.context, result['id'])
def test_show_vnf_details_vnf_inactive(self, mock_create_vnf_wait): self._insert_dummy_vnf_template() vnf_obj = utils.get_dummy_vnf_obj() result = self.vnfm_plugin.create_vnf(self.context, vnf_obj) self.assertRaises(vnfm.VNFInactive, self.vnfm_plugin.get_vnf_resources, self.context, result['id'])