def test_event_handle_user_config_failed(self): (self.service_orchestrator.db_handler. update_node_instance_network_function_map) = mock.MagicMock( return_value=None) network_function = self.create_network_function() request_data = { 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id'] } test_event = Event(data=request_data, context=request_data) test_event.context['log_context'] = nfp_context.init_log_context() self.service_orchestrator.handle_user_config_failed(test_event) db_nf = self.nfp_db.get_network_function(self.session, network_function['id']) self.assertEqual('ERROR', db_nf['status'])
def test_event_handle_user_config_failed(self): (self.service_orchestrator.db_handler. update_node_instance_network_function_map) = mock.MagicMock( return_value=None) network_function = self.create_network_function() request_data = { 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id'] } test_event = Event(data=request_data, context=request_data) test_event.context['log_context'] = nfp_context.init_log_context() self.service_orchestrator.handle_user_config_failed(test_event) db_nf = self.nfp_db.get_network_function( self.session, network_function['id']) self.assertEqual('ERROR', db_nf['status'])
def test_event_create_network_function_instance(self): network_function_instance = self.create_network_function_instance() network_function = self.nfp_db.get_network_function( self.session, network_function_instance['network_function_id']) network_function_port_info = [{ 'id': 'provider_port_id', 'port_model': nfp_constants.GBP_PORT, 'port_classification': nfp_constants.PROVIDER }, { 'id': 'consumer_port_id', 'port_model': nfp_constants.GBP_PORT, 'port_classification': nfp_constants.CONSUMER }] management_network_info = { 'id': 'management_ptg_id', 'port_model': nfp_constants.GBP_PORT } create_nfi_request = { 'network_function': network_function, 'network_function_port_info': network_function_port_info, 'network_function_instance': network_function_instance, 'management_network_info': management_network_info, 'service_type': 'service_type', 'service_details': { 'service_vendor': 'vendor', 'service_type': 'xyz' }, 'service_vendor': 'vendor', 'share_existing_device': True, 'service_profile': None, 'consumer': { 'pt': None }, 'provider': { 'pt': None } } test_event = Event(data=create_nfi_request) test_event.context = create_nfi_request test_event.context['log_context'] = nfp_context.init_log_context() self.service_orchestrator.create_network_function_instance(test_event)
def test_event_handle_device_create_failed(self): (self.service_orchestrator.db_handler. update_node_instance_network_function_map) = mock.MagicMock( return_value=None) nfd = self.create_network_function_device() nfi = self.create_network_function_instance(create_nfd=False) request_data = { 'network_function_instance_id': nfi['id'], 'network_function_device_id': nfd['id'] } test_event = Event(data=request_data, context=request_data) test_event.context['log_context'] = nfp_context.init_log_context() self.assertIsNone(nfi['network_function_device_id']) self.service_orchestrator.handle_device_create_failed(test_event) db_nfi = self.nfp_db.get_network_function_instance( self.session, nfi['id']) db_nf = self.nfp_db.get_network_function(self.session, nfi['network_function_id']) self.assertEqual(nfp_constants.ERROR, db_nfi['status']) self.assertEqual(nfp_constants.ERROR, db_nf['status'])
def test_event_create_network_function_instance(self): network_function_instance = self.create_network_function_instance() network_function = self.nfp_db.get_network_function( self.session, network_function_instance['network_function_id']) network_function_port_info = [ { 'id': 'provider_port_id', 'port_model': nfp_constants.GBP_PORT, 'port_classification': nfp_constants.PROVIDER }, { 'id': 'consumer_port_id', 'port_model': nfp_constants.GBP_PORT, 'port_classification': nfp_constants.CONSUMER } ] management_network_info = { 'id': 'management_ptg_id', 'port_model': nfp_constants.GBP_PORT } create_nfi_request = { 'network_function': network_function, 'network_function_port_info': network_function_port_info, 'network_function_instance': network_function_instance, 'management_network_info': management_network_info, 'service_type': 'service_type', 'service_details': {'service_vendor': 'vendor', 'service_type': 'xyz'}, 'service_vendor': 'vendor', 'share_existing_device': True, 'service_profile': None, 'consumer': {'pt': None}, 'provider': {'pt': None} } test_event = Event(data=create_nfi_request) test_event.context = create_nfi_request test_event.context['log_context'] = nfp_context.init_log_context() self.service_orchestrator.create_network_function_instance( test_event)
def test_event_handle_device_create_failed(self): (self.service_orchestrator.db_handler. update_node_instance_network_function_map) = mock.MagicMock( return_value=None) nfd = self.create_network_function_device() nfi = self.create_network_function_instance(create_nfd=False) request_data = { 'network_function_instance_id': nfi['id'], 'network_function_device_id': nfd['id'] } test_event = Event(data=request_data, context=request_data) test_event.context['log_context'] = nfp_context.init_log_context() self.assertIsNone(nfi['network_function_device_id']) self.service_orchestrator.handle_device_create_failed( test_event) db_nfi = self.nfp_db.get_network_function_instance( self.session, nfi['id']) db_nf = self.nfp_db.get_network_function( self.session, nfi['network_function_id']) self.assertEqual(nfp_constants.ERROR, db_nfi['status']) self.assertEqual(nfp_constants.ERROR, db_nf['status'])
def test_event_check_for_user_config_deleted(self, mock_create_event, mock_service_type): (self.service_orchestrator.db_handler. update_node_instance_network_function_map) = mock.MagicMock( return_value=None) network_function = self.create_network_function() with mock.patch.object( self.service_orchestrator.config_driver, "is_config_delete_complete") as mock_is_config_delete_complete: # Verify return status IN_PROGRESS from cfg.CONF driver mock_is_config_delete_complete.return_value = "IN_PROGRESS" request_data = { 'tenant_id': network_function['tenant_id'], 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id']} test_event = Event(data=request_data) test_event.context = request_data mock_service_type.return_value = 'firewall' status = self.service_orchestrator.check_for_user_config_deleted( test_event) mock_is_config_delete_complete.assert_called_once_with( request_data['config_policy_id'], network_function['tenant_id'], network_function) db_nf = self.nfp_db.get_network_function( self.session, network_function['id']) self.assertEqual(network_function['status'], db_nf['status']) self.assertEqual(network_function['config_policy_id'], db_nf['config_policy_id']) self.assertEqual(status, nso.CONTINUE_POLLING) # Verify return status ERROR from cfg.CONF driver mock_is_config_delete_complete.reset_mock() mock_is_config_delete_complete.return_value = "ERROR" request_data = { 'tenant_id': network_function['tenant_id'], 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id']} test_event = Event(data=request_data) test_event.context = request_data status = self.service_orchestrator.check_for_user_config_deleted( test_event) mock_is_config_delete_complete.assert_called_once_with( request_data['config_policy_id'], network_function['tenant_id'], network_function) mock_create_event.assert_called_once_with( 'USER_CONFIG_DELETE_FAILED', event_data=request_data, is_internal_event=True) self.assertEqual(status, nso.STOP_POLLING) # Verify return status COMPLETED from cfg.CONF driver self.controller.poll_event_done.reset_mock() mock_is_config_delete_complete.reset_mock() mock_create_event.reset_mock() mock_is_config_delete_complete.return_value = "COMPLETED" request_data = { 'tenant_id': network_function['tenant_id'], 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id'], 'action': 'update'} test_event = Event(data=request_data) test_event.context = request_data test_event.context['log_context'] = nfp_context.init_log_context() status = self.service_orchestrator.check_for_user_config_deleted( test_event) mock_is_config_delete_complete.assert_called_once_with( request_data['config_policy_id'], network_function['tenant_id'], network_function) db_nf = self.nfp_db.get_network_function( self.session, network_function['id']) self.assertEqual('config_policy_id', db_nf['config_policy_id']) self.assertEqual(status, nso.STOP_POLLING)
def test_event_check_for_user_config_deleted(self, mock_create_event, mock_service_type): (self.service_orchestrator.db_handler. update_node_instance_network_function_map) = mock.MagicMock( return_value=None) network_function = self.create_network_function() with mock.patch.object( self.service_orchestrator.config_driver, "is_config_delete_complete") as mock_is_config_delete_complete: # Verify return status IN_PROGRESS from cfg.CONF driver mock_is_config_delete_complete.return_value = "IN_PROGRESS" request_data = { 'tenant_id': network_function['tenant_id'], 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id'] } test_event = Event(data=request_data) test_event.context = request_data mock_service_type.return_value = 'firewall' status = self.service_orchestrator.check_for_user_config_deleted( test_event) mock_is_config_delete_complete.assert_called_once_with( request_data['config_policy_id'], network_function['tenant_id'], network_function) db_nf = self.nfp_db.get_network_function(self.session, network_function['id']) self.assertEqual(network_function['status'], db_nf['status']) self.assertEqual(network_function['config_policy_id'], db_nf['config_policy_id']) self.assertEqual(status, nso.CONTINUE_POLLING) # Verify return status ERROR from cfg.CONF driver mock_is_config_delete_complete.reset_mock() mock_is_config_delete_complete.return_value = "ERROR" request_data = { 'tenant_id': network_function['tenant_id'], 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id'] } test_event = Event(data=request_data) test_event.context = request_data status = self.service_orchestrator.check_for_user_config_deleted( test_event) mock_is_config_delete_complete.assert_called_once_with( request_data['config_policy_id'], network_function['tenant_id'], network_function) mock_create_event.assert_called_once_with( 'USER_CONFIG_DELETE_FAILED', event_data=request_data, is_internal_event=True) self.assertEqual(status, nso.STOP_POLLING) # Verify return status COMPLETED from cfg.CONF driver self.controller.poll_event_done.reset_mock() mock_is_config_delete_complete.reset_mock() mock_create_event.reset_mock() mock_is_config_delete_complete.return_value = "COMPLETED" request_data = { 'tenant_id': network_function['tenant_id'], 'config_policy_id': 'config_policy_id', 'network_function_id': network_function['id'], 'action': 'update' } test_event = Event(data=request_data) test_event.context = request_data test_event.context['log_context'] = nfp_context.init_log_context() status = self.service_orchestrator.check_for_user_config_deleted( test_event) mock_is_config_delete_complete.assert_called_once_with( request_data['config_policy_id'], network_function['tenant_id'], network_function) db_nf = self.nfp_db.get_network_function(self.session, network_function['id']) self.assertEqual('config_policy_id', db_nf['config_policy_id']) self.assertEqual(status, nso.STOP_POLLING)