NFP - Orchestrator Enhancements
Changeset includes, a) Added supported_vendors conf support. b) Support to serialize device up state machine events. c) Delete path optimizations. d) Corresponding unit test changes. Change-Id: I9e75da993da2ea41ac7e17fd6bcd844afa41b1a5
This commit is contained in:
committed by
Subrahmanyam Ongole
parent
1785e4f289
commit
6dfc23f404
@@ -82,7 +82,7 @@ class NFPDBTestCase(SqlTestCase):
|
||||
'service_chain_id': 'service_chain_id',
|
||||
'service_profile_id': 'service_profile_id',
|
||||
'service_config': 'service_config',
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'status': 'status'
|
||||
}
|
||||
return self.nfp_db.create_network_function(self.session, attributes)
|
||||
@@ -96,7 +96,7 @@ class NFPDBTestCase(SqlTestCase):
|
||||
'service_chain_id': 'service_chain_id',
|
||||
'service_profile_id': 'service_profile_id',
|
||||
'service_config': 'service_config',
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'status': 'status'
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class NFPDBTestCase(SqlTestCase):
|
||||
self.assertEqual(attrs_mandatory[key], network_function[key])
|
||||
self.assertIsNotNone(network_function['id'])
|
||||
non_mandatory_args = ['service_chain_id', 'service_config',
|
||||
'heat_stack_id']
|
||||
'config_policy_id']
|
||||
for arg in non_mandatory_args:
|
||||
self.assertIsNone(network_function[arg])
|
||||
|
||||
@@ -131,7 +131,7 @@ class NFPDBTestCase(SqlTestCase):
|
||||
'service_chain_id': 'service_chain_id',
|
||||
'service_profile_id': 'service_profile_id',
|
||||
'service_config': 'service_config',
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'status': 'status'
|
||||
}
|
||||
network_function = self.create_network_function(attrs_all)
|
||||
@@ -243,7 +243,8 @@ class NFPDBTestCase(SqlTestCase):
|
||||
'name': 'name',
|
||||
'tenant_id': 'tenant_id',
|
||||
'network_function_id': network_function['id'],
|
||||
'status': 'status'
|
||||
'status': 'status',
|
||||
'port_info': []
|
||||
}
|
||||
network_function_instance = (
|
||||
self.nfp_db.create_network_function_instance(
|
||||
@@ -561,3 +562,134 @@ class NFPDBTestCase(SqlTestCase):
|
||||
self.nfp_db.get_port_info,
|
||||
self.session,
|
||||
mgmt_port_id)
|
||||
|
||||
def create_network_function_device_interface(self, attributes=None,
|
||||
create_nfd=True):
|
||||
if attributes is None:
|
||||
nfd = (self.create_network_function_device()['id']
|
||||
if create_nfd else None)
|
||||
attributes = {
|
||||
'tenant_id': 'tenant_id',
|
||||
'plugged_in_port_id': {
|
||||
'id': 'myid2_ha_port',
|
||||
'port_model': nfp_constants.NEUTRON_PORT,
|
||||
'port_classification': nfp_constants.MONITOR,
|
||||
'port_role': nfp_constants.ACTIVE_PORT
|
||||
},
|
||||
'interface_position': 1,
|
||||
'mapped_real_port_id': 'myid2',
|
||||
'network_function_device_id': nfd
|
||||
}
|
||||
return self.nfp_db.create_network_function_device_interface(
|
||||
self.session, attributes)
|
||||
|
||||
def test_create_network_function_device_interface(self):
|
||||
attrs = {
|
||||
'tenant_id': 'tenant_id',
|
||||
'plugged_in_port_id': {
|
||||
'id': 'myid2_ha_port',
|
||||
'port_model': nfp_constants.NEUTRON_PORT,
|
||||
'port_classification': nfp_constants.MONITOR,
|
||||
'port_role': nfp_constants.ACTIVE_PORT
|
||||
},
|
||||
'interface_position': 1,
|
||||
'mapped_real_port_id': 'myid2',
|
||||
'network_function_device_id': (
|
||||
self.create_network_function_device()['id'])
|
||||
}
|
||||
|
||||
network_function_device_interface = (
|
||||
self.create_network_function_device_interface(attrs))
|
||||
for key in attrs:
|
||||
if key == 'mgmt_port_id':
|
||||
self.assertEqual(attrs[key]['id'],
|
||||
network_function_device_interface[key])
|
||||
continue
|
||||
self.assertEqual(attrs[key],
|
||||
network_function_device_interface[key])
|
||||
self.assertIsNotNone(network_function_device_interface['id'])
|
||||
|
||||
def test_get_network_function_device_interface(self):
|
||||
attrs_all = {
|
||||
'tenant_id': 'tenant_id',
|
||||
'plugged_in_port_id': {
|
||||
'id': 'myid2_ha_port',
|
||||
'port_model': nfp_constants.NEUTRON_PORT,
|
||||
'port_classification': nfp_constants.MONITOR,
|
||||
'port_role': nfp_constants.ACTIVE_PORT
|
||||
},
|
||||
'interface_position': 1,
|
||||
'mapped_real_port_id': 'myid2',
|
||||
'network_function_device_id': (
|
||||
self.create_network_function_device()['id'])
|
||||
}
|
||||
network_function_device_interface = (
|
||||
self.create_network_function_device_interface(attrs_all))
|
||||
db_network_function_device_interface = (
|
||||
self.nfp_db.get_network_function_device_interface(
|
||||
self.session, network_function_device_interface['id']))
|
||||
for key in attrs_all:
|
||||
self.assertEqual(attrs_all[key],
|
||||
db_network_function_device_interface[key])
|
||||
|
||||
def test_list_network_function_device_interface(self):
|
||||
network_function_device_interface = (
|
||||
self.create_network_function_device_interface())
|
||||
network_function_device_interfaces = (
|
||||
self.nfp_db.get_network_function_device_interfaces(
|
||||
self.session))
|
||||
self.assertEqual(1, len(network_function_device_interfaces))
|
||||
self.assertEqual(network_function_device_interface['id'],
|
||||
network_function_device_interfaces[0]['id'])
|
||||
|
||||
def test_list_network_function_device_interfaces_with_filters(self):
|
||||
attrs = {
|
||||
'tenant_id': 'tenant_id',
|
||||
'plugged_in_port_id': {
|
||||
'id': 'myid2_ha_port',
|
||||
'port_model': nfp_constants.NEUTRON_PORT,
|
||||
'port_classification': nfp_constants.MONITOR,
|
||||
'port_role': nfp_constants.ACTIVE_PORT
|
||||
},
|
||||
'interface_position': 1,
|
||||
'mapped_real_port_id': 'myid2',
|
||||
'network_function_device_id': (
|
||||
self.create_network_function_device()['id'])
|
||||
}
|
||||
network_function_device_interface = (
|
||||
self.create_network_function_device_interface(attrs))
|
||||
filters = {
|
||||
'interface_position': [1]
|
||||
}
|
||||
network_function_device_interfaces = (
|
||||
self.nfp_db.get_network_function_device_interfaces(
|
||||
self.session, filters=filters))
|
||||
self.assertEqual(1, len(network_function_device_interfaces))
|
||||
self.assertEqual(network_function_device_interface['id'],
|
||||
network_function_device_interfaces[0]['id'])
|
||||
filters = {'interface_position': [100]}
|
||||
network_function_device_interfaces = (
|
||||
self.nfp_db.get_network_function_device_interfaces(
|
||||
self.session, filters=filters))
|
||||
self.assertEqual([], network_function_device_interfaces)
|
||||
|
||||
def test_update_network_function_device_interface(self):
|
||||
network_function_device_interface = (
|
||||
self.create_network_function_device_interface())
|
||||
self.assertIsNotNone(network_function_device_interface['id'])
|
||||
updated_nfdi = {'interface_position': 2}
|
||||
nfdi = self.nfp_db.update_network_function_device_interface(
|
||||
self.session, network_function_device_interface['id'],
|
||||
updated_nfdi)
|
||||
self.assertEqual(2, nfdi['interface_position'])
|
||||
|
||||
def test_delete_network_function_device_interface(self):
|
||||
network_function_device_interface = (
|
||||
self.create_network_function_device_interface())
|
||||
self.assertIsNotNone(network_function_device_interface['id'])
|
||||
self.nfp_db.delete_network_function_device_interface(
|
||||
self.session, network_function_device_interface['id'])
|
||||
self.assertRaises(nfp_exc.NetworkFunctionDeviceInterfaceNotFound,
|
||||
self.nfp_db.get_network_function_device_interface,
|
||||
self.session,
|
||||
network_function_device_interface['id'])
|
||||
|
||||
@@ -45,89 +45,12 @@ NFP_NEUTRON_NETWORK_DRIVER_CLASS_PATH = ('gbpservice.nfp.orchestrator'
|
||||
mock.MagicMock(return_value=None))
|
||||
class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
|
||||
def test_get_nfd_sharing_info_when_device_sharing_unsupported(self):
|
||||
driver = orchestration_driver.OrchestrationDriver(
|
||||
cfg.CONF, supports_device_sharing=False)
|
||||
device_data = {'tenant_id': 'tenant_id',
|
||||
'service_details': {'device_type': 'xyz',
|
||||
'service_type': 'firewall',
|
||||
'service_vendor': 'vyos',
|
||||
'network_mode': 'gbp'}}
|
||||
self.assertIsNone(driver.get_network_function_device_sharing_info(
|
||||
device_data))
|
||||
|
||||
def test_select_network_function_device_when_device_sharing_unsupported(
|
||||
self):
|
||||
driver = orchestration_driver.OrchestrationDriver(
|
||||
cfg.CONF, supports_device_sharing=False)
|
||||
device_data = {'service_details': {'device_type': 'xyz',
|
||||
'service_type': 'firewall',
|
||||
'service_vendor': 'vyos',
|
||||
'network_mode': 'gbp'},
|
||||
|
||||
'ports': [{'id': '2',
|
||||
'port_classification': 'provider',
|
||||
'port_model': 'gbp'}]
|
||||
}
|
||||
devices = [
|
||||
{'id': '1',
|
||||
'interfaces_in_use': 9}
|
||||
]
|
||||
self.assertIsNone(driver.select_network_function_device(devices,
|
||||
device_data))
|
||||
|
||||
def test_select_network_function_device(self):
|
||||
driver = orchestration_driver.OrchestrationDriver(
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=True,
|
||||
max_interfaces=10)
|
||||
driver.identity_handler.get_admin_token = mock.MagicMock(
|
||||
return_value='token')
|
||||
driver.compute_handler_nova.get_image_metadata = mock.MagicMock(
|
||||
return_value='metadata')
|
||||
driver.identity_handler.get_keystone_creds = mock.MagicMock(
|
||||
return_value=(_, _, 'admin_tenant_name', _))
|
||||
driver.identity_handler.get_tenant_id = mock.MagicMock(
|
||||
return_value='admin_tenant_id')
|
||||
# test to get device when max interfaces is permissible
|
||||
devices = [
|
||||
{'id': '1',
|
||||
'interfaces_in_use': 9,
|
||||
'network_functions': []}
|
||||
]
|
||||
device_data = {'service_details': {'device_type': 'xyz',
|
||||
'service_type': 'firewall',
|
||||
'service_vendor': 'vyos',
|
||||
'network_mode': 'gbp'},
|
||||
|
||||
'ports': [{'id': '2',
|
||||
'port_classification': 'provider',
|
||||
'port_model': 'gbp'}]
|
||||
}
|
||||
self.assertIsNone(driver.select_network_function_device(
|
||||
devices,
|
||||
device_data),
|
||||
msg=('Device sharing is broken with respect to'
|
||||
' maximum interfaces that'
|
||||
' the device supports'))
|
||||
|
||||
# test to get device when max interfaces is not permissible
|
||||
device_data['ports'].append({'id': '3',
|
||||
'port_classification': 'consumer',
|
||||
'port_model': 'gbp'})
|
||||
self.assertIsNone(driver.select_network_function_device(devices,
|
||||
device_data),
|
||||
msg=('Device sharing is broken with respect to'
|
||||
' maximum interfaces that'
|
||||
' the device supports'))
|
||||
|
||||
def test_create_network_function_device(self):
|
||||
driver = orchestration_driver.OrchestrationDriver(
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=True,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
driver.network_handler = driver.network_handlers['gbp']
|
||||
|
||||
# Mock the client methods
|
||||
@@ -169,6 +92,8 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
'service_vendor': 'vyos',
|
||||
'network_mode': 'gbp'},
|
||||
'name': 'FIREWALL.vyos.1.2',
|
||||
'volume_support': None,
|
||||
'volume_size': None,
|
||||
'management_network_info': {'id': '2'},
|
||||
'ports': [{'id': '3',
|
||||
'port_model': 'gbp',
|
||||
@@ -203,7 +128,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=True,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
driver.network_handler = driver.network_handlers['gbp']
|
||||
|
||||
# Mock the client methods
|
||||
@@ -236,7 +161,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=True,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
|
||||
# Mock the client methods
|
||||
driver.identity_handler.get_admin_token = mock.MagicMock(
|
||||
@@ -270,7 +195,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=False,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
driver.network_handler = driver.network_handlers['gbp']
|
||||
# Mock the client methods
|
||||
driver.identity_handler.get_admin_token = mock.MagicMock(
|
||||
@@ -285,6 +210,8 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
return_value=None)
|
||||
driver.compute_handler_nova.attach_interface = mock.MagicMock(
|
||||
return_value=None)
|
||||
driver.compute_handler_nova.get_image_metadata = mock.MagicMock(
|
||||
return_value={})
|
||||
driver.network_handler.get_port_id = mock.MagicMock(return_value='7')
|
||||
|
||||
device_data = {'id': '1',
|
||||
@@ -298,6 +225,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
{'id': '4',
|
||||
'port_model': 'neutron',
|
||||
'port_classification': 'consumer'}],
|
||||
'vendor_data': {},
|
||||
'token': str(pyuuid.uuid4()),
|
||||
'tenant_id': str(pyuuid.uuid4())}
|
||||
|
||||
@@ -312,7 +240,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=False,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
driver.network_handler = driver.network_handlers['gbp']
|
||||
|
||||
driver.identity_handler.get_admin_token = mock.MagicMock(
|
||||
@@ -323,13 +251,17 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
return_value=(None, None, 'admin', None))
|
||||
driver.compute_handler_nova.detach_interface = mock.MagicMock(
|
||||
return_value=None)
|
||||
driver.compute_handler_nova.get_image_metadata = mock.MagicMock(
|
||||
return_value={})
|
||||
driver.network_handler.get_port_id = mock.MagicMock(return_value='7')
|
||||
|
||||
device_data = {'id': '1',
|
||||
'tenant_id': 'tenant_id',
|
||||
'service_details': {'device_type': 'xyz',
|
||||
'service_type': 'firewall',
|
||||
'service_vendor': 'vyos',
|
||||
'network_mode': 'gbp'},
|
||||
'vendor_data': {},
|
||||
'ports': [{'id': '3',
|
||||
'port_model': 'gbp',
|
||||
'port_classification': 'provider'},
|
||||
@@ -348,7 +280,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=False,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
|
||||
device_data = {'id': '1',
|
||||
'mgmt_ip_address': 'a.b.c.d'}
|
||||
@@ -362,7 +294,7 @@ class OrchestrationDriverTestCase(unittest.TestCase):
|
||||
cfg.CONF,
|
||||
supports_device_sharing=True,
|
||||
supports_hotplug=False,
|
||||
max_interfaces=10)
|
||||
max_interfaces=8)
|
||||
driver.network_handler = driver.network_handlers['gbp']
|
||||
|
||||
driver.identity_handler.get_admin_token = mock.MagicMock(
|
||||
|
||||
@@ -634,7 +634,7 @@ class DummyDictionaries(object):
|
||||
'network_function': {
|
||||
'status': 'ACTIVE',
|
||||
'description': '',
|
||||
'heat_stack_id': '57d6b523-ae89-41cd-9b63-9bfb054a20b6',
|
||||
'config_policy_id': '57d6b523-ae89-41cd-9b63-9bfb054a20b6',
|
||||
'tenant_id': 'ee27b1d0d7f04ac390ee7ec4b2fd5b13',
|
||||
'network_function_instances': [
|
||||
'4693118c-149a-46e7-b92c-cc729b536a2e'],
|
||||
@@ -663,7 +663,7 @@ class DummyDictionaries(object):
|
||||
'description': '',
|
||||
'service_vendor': None,
|
||||
'tenant_id': 'ee27b1d0d7f04ac390ee7ec4b2fd5b13',
|
||||
'max_interfaces': 10,
|
||||
'max_interfaces': 8,
|
||||
'mgmt_port_id': '4497a287-d947-4845-af29-a9d6ad6515e9',
|
||||
'reference_count': 1,
|
||||
'interfaces_in_use': 2,
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
|
||||
import copy
|
||||
from gbpservice.nfp.orchestrator.db import nfp_db as nfpdb
|
||||
from gbpservice.nfp.orchestrator.modules import (
|
||||
device_orchestrator)
|
||||
|
||||
|
||||
from gbpservice.nfp.lib import transport
|
||||
import mock
|
||||
@@ -25,6 +24,21 @@ import unittest
|
||||
import uuid as pyuuid
|
||||
|
||||
|
||||
with mock.patch('oslo_config.cfg.CONF.register_opts') as opt:
|
||||
from gbpservice.nfp.orchestrator.modules import (
|
||||
device_orchestrator)
|
||||
|
||||
|
||||
class DummyController(object):
|
||||
def event_complete(self, event):
|
||||
return
|
||||
|
||||
|
||||
class DummyDesc(object):
|
||||
def to_dict(self):
|
||||
return {}
|
||||
|
||||
|
||||
class DummyEvent(object):
|
||||
|
||||
def __init__(self, data, status, ref_count=0):
|
||||
@@ -58,9 +72,14 @@ class DummyEvent(object):
|
||||
self.data['resource_owner_context'] = {'admin_token': str(
|
||||
pyuuid.uuid4()), 'tenant_id': str(pyuuid.uuid4()),
|
||||
'admin_tenant_id': str(pyuuid.uuid4())}
|
||||
self.data['admin_token'] = str(pyuuid.uuid4())
|
||||
self.data['provider'] = {'ptg': None}
|
||||
self.data['consumer'] = {'ptg': None}
|
||||
self.binding_key = self.data['service_details'][
|
||||
'service_vendor'] + self.data[
|
||||
'network_function']['id']
|
||||
self.context = {}
|
||||
self.desc = DummyDesc()
|
||||
|
||||
|
||||
class Desc(object):
|
||||
@@ -238,7 +257,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
|
||||
def _initialize_ndo_handler(self):
|
||||
ndo_handler = device_orchestrator.DeviceOrchestrator(
|
||||
object, cfg.CONF)
|
||||
DummyController, cfg.CONF)
|
||||
self.event = DummyEvent(100, 'PENDING_CREATE')
|
||||
return ndo_handler
|
||||
|
||||
@@ -255,10 +274,10 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
mock_device_configuration_complete.assert_called_with(self.event)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_check_device_up(self, mock_update_nsd):
|
||||
def test_check_device_up(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
ndo_handler._controller = mock.MagicMock(return_value='')
|
||||
mock_update_nsd.return_value = 100
|
||||
mock_update_nfd.return_value = 100
|
||||
orig_event_data = {}
|
||||
orchestration_driver.get_network_function_device_status = (
|
||||
mock.MagicMock(return_value='ACTIVE'))
|
||||
@@ -282,14 +301,14 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
poll_status = ndo_handler.check_device_is_up(self.event)
|
||||
self.assertEqual(poll_status, {'poll': False})
|
||||
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
orig_event_data['id'],
|
||||
orig_event_data)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_health_check(self, mock_update_nsd):
|
||||
def test_health_check(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
mock_update_nsd.return_value = 100
|
||||
mock_update_nfd.return_value = 100
|
||||
|
||||
ndo_handler.configurator_rpc.create_network_function_device_config = (
|
||||
mock.MagicMock(return_value=101))
|
||||
@@ -316,17 +335,17 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
'key': self.event.key}
|
||||
|
||||
ndo_handler.perform_health_check(self.event)
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
orig_event_data['id'],
|
||||
orig_event_data)
|
||||
ndo_handler.configurator_rpc.create_network_function_device_config.\
|
||||
assert_called_with(orig_event_data, param_req)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_plug_interfaces(self, mock_update_nsd):
|
||||
def test_plug_interfaces(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
|
||||
mock_update_nsd.return_value = 100
|
||||
mock_update_nfd.return_value = 100
|
||||
orig_event_data = copy.deepcopy(self.event.data)
|
||||
ndo_handler._prepare_device_data = mock.MagicMock(
|
||||
return_value=orig_event_data)
|
||||
@@ -339,9 +358,11 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
orig_event_data['interfaces_in_use'] += len(orig_event_data['ports'])
|
||||
|
||||
ndo_handler.plug_interfaces(self.event)
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
orig_event_data['id'],
|
||||
orig_event_data)
|
||||
{'interfaces_in_use': (
|
||||
orig_event_data[
|
||||
'interfaces_in_use'])})
|
||||
|
||||
orchestration_driver.plug_network_function_device_interfaces = (
|
||||
mock.MagicMock(return_value=(False)))
|
||||
@@ -355,7 +376,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
is_internal_event=True)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_create_device_configuration(self, mock_update_nsd):
|
||||
def test_create_device_configuration(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
config_params = {'param1': 'value1', 'parama2': 'value2'}
|
||||
orchestration_driver.get_create_network_function_device_config_info = (
|
||||
@@ -385,6 +406,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
'consumer']['port']['mac_address']
|
||||
device['id'] = self.event.data['id']
|
||||
device['nfp_context'] = {'event_desc': self.event.desc.to_dict(),
|
||||
'binding_key': self.event.binding_key,
|
||||
'id': self.event.id, 'key': self.event.key,
|
||||
'network_function_device': self.event.data[
|
||||
'network_function_device']}
|
||||
@@ -405,7 +427,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_device_configuration_complete(self,
|
||||
mock_update_nsd):
|
||||
mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
tmp_data = copy.deepcopy(self.event.data)
|
||||
device = self.event.data
|
||||
@@ -415,23 +437,27 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
device['nfp_context']['network_function_device']['status'] = status
|
||||
device['nfp_context']['network_function_device'][
|
||||
'status_description'] = ndo_handler.status_map[status]
|
||||
device['nfp_context']['network_function_device'][
|
||||
'reference_count'] += 1
|
||||
reference_count = device['nfp_context']['network_function_device'][
|
||||
'reference_count'] + 1
|
||||
event_desc = Desc()
|
||||
device['nfp_context']['event_desc'] = event_desc.to_dict()
|
||||
device['nfp_context']['key'] = self.event.key
|
||||
device['nfp_context']['binding_key'] = self.event.binding_key
|
||||
ndo_handler._prepare_device_data = mock.MagicMock(return_value=device)
|
||||
ndo_handler._create_event = mock.MagicMock(return_value=True)
|
||||
ndo_handler.nsf_db.get_network_function_device = (
|
||||
mock.MagicMock(return_value={'reference_count': (
|
||||
reference_count - 1)}))
|
||||
self.event.data = device
|
||||
ndo_handler._controller = mock.MagicMock(return_value=True)
|
||||
ndo_handler.device_configuration_complete(self.event)
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
device[
|
||||
'nfp_context'][
|
||||
'network_function_device'][
|
||||
'id'],
|
||||
device['nfp_context'][
|
||||
'network_function_device'])
|
||||
{'reference_count': (
|
||||
reference_count)})
|
||||
|
||||
self.event.data = tmp_data
|
||||
|
||||
@@ -440,25 +466,26 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'get_network_function')
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'get_port_info')
|
||||
def test_delete_network_function_device(self, mock_get_port, mock_get_nf,
|
||||
mock_update_nsd, mock_get_nsd):
|
||||
mock_update_nfd, mock_get_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
delete_event_req = DummyEvent(100, 'ACTIVE')
|
||||
delete_event_req.data = \
|
||||
{'network_function_device_id': 'device-id',
|
||||
'network_function_instance': {'id': 'nfi-id',
|
||||
'port_info': []},
|
||||
'network_function_id': 'network_function_id'}
|
||||
'network_function_device': {'id': 'device-id'}}
|
||||
mgmt_port_id = {'id': 'port-id', 'port_model': 'port-policy'}
|
||||
ndo_handler._prepare_device_data = mock.MagicMock(
|
||||
ndo_handler._prepare_device_data_fast = mock.MagicMock(
|
||||
return_value=delete_event_req.data)
|
||||
ndo_handler._get_service_type = mock.MagicMock(
|
||||
return_value='service-type')
|
||||
ndo_handler._get_port = mock.MagicMock(return_value=mgmt_port_id)
|
||||
|
||||
mock_get_port.return_value = mgmt_port_id
|
||||
mock_get_nsd.return_value = {'id': 'device-id',
|
||||
mock_get_nfd.return_value = {'id': 'device-id',
|
||||
'mgmt_port_id': ['mgmt-data-port-id']}
|
||||
|
||||
delete_event_req.data.update(
|
||||
{'event_desc': delete_event_req.desc.to_dict()})
|
||||
event_id = 'DELETE_CONFIGURATION'
|
||||
ndo_handler._create_event = mock.MagicMock(return_value=True)
|
||||
|
||||
@@ -469,7 +496,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
is_internal_event=True)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_delete_device_configuration(self, mock_update_nsd):
|
||||
def test_delete_device_configuration(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
config_params = {'param1': 'value1', 'parama2': 'value2'}
|
||||
self.event = DummyEvent(101, 'ACTIVE')
|
||||
@@ -483,7 +510,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
assert_called_with(self.event.data, config_params)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_unplug_interfaces(self, mock_update_nsd):
|
||||
def test_unplug_interfaces(self, mock_update_nfd):
|
||||
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
self.event = DummyEvent(101, 'ACTIVE')
|
||||
@@ -495,12 +522,17 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
orchestration_driver.unplug_network_function_device_interfaces = (
|
||||
mock.MagicMock(return_value=(True, [])))
|
||||
|
||||
ndo_handler._controller.event_complete = mock.MagicMock(
|
||||
return_value=None)
|
||||
|
||||
ndo_handler.unplug_interfaces(self.event)
|
||||
|
||||
orig_event_data['interfaces_in_use'] -= len(orig_event_data['ports'])
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
orig_event_data['id'],
|
||||
orig_event_data)
|
||||
{'interfaces_in_use': (
|
||||
orig_event_data[
|
||||
'interfaces_in_use'])})
|
||||
orig_event_data = copy.deepcopy(self.event.data)
|
||||
orig_event_data['status_description'] = (
|
||||
ndo_handler.status_map['ACTIVE'])
|
||||
@@ -509,13 +541,15 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
mock.MagicMock(return_value=(False, [])))
|
||||
|
||||
ndo_handler.unplug_interfaces(self.event)
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
orig_event_data['id'],
|
||||
orig_event_data)
|
||||
{'interfaces_in_use': (
|
||||
orig_event_data[
|
||||
'interfaces_in_use'])})
|
||||
|
||||
"""
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'delete_network_function_device')
|
||||
def test_device_delete(self, mock_delete_nsd):
|
||||
def test_device_delete(self, mock_delete_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
self.event = DummyEvent(101, 'ACTIVE', 1)
|
||||
ndo_handler._prepare_device_data = mock.MagicMock(
|
||||
@@ -530,7 +564,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
event_id = 'DEVICE_DELETED'
|
||||
orig_event_data['reference_count'] -= 1
|
||||
|
||||
mock_delete_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_delete_nfd.assert_called_with(ndo_handler.db_session,
|
||||
self.event.data['id'])
|
||||
ndo_handler._create_event.assert_called_with(event_id=event_id,
|
||||
event_data=orig_event_data)
|
||||
@@ -550,23 +584,25 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
event_data=orig_event_data)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_handle_device_not_up(self, mock_update_nsd):
|
||||
def test_handle_device_not_up(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
status = 'ERROR'
|
||||
desc = 'Device not became ACTIVE'
|
||||
self.event = DummyEvent(101, status, 1)
|
||||
orig_event_data = copy.deepcopy(self.event.data)
|
||||
orig_event_data['status_description'] = desc
|
||||
orig_event_data.pop('interfaces_in_use', None)
|
||||
orig_event_data.pop('reference_count', None)
|
||||
ndo_handler._create_event = mock.MagicMock(return_value=True)
|
||||
|
||||
ndo_handler.handle_device_not_up(self.event)
|
||||
orig_event_data['network_function_device_id'] = orig_event_data['id']
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
orig_event_data['id'],
|
||||
orig_event_data)
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_handle_device_not_reachable(self, mock_update_nsd):
|
||||
def test_handle_device_not_reachable(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
status = 'ERROR'
|
||||
self.event = DummyEvent(101, status, 1)
|
||||
@@ -574,7 +610,9 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
tmp_data = copy.deepcopy(self.event.data)
|
||||
device = self.event.data
|
||||
device = {'nfp_context': device,
|
||||
'id': self.event.data['network_function_device']['id']}
|
||||
'id': self.event.data['network_function_device']['id'],
|
||||
'network_function_device_id': (
|
||||
self.event.data['network_function_device']['id'])}
|
||||
device['nfp_context']['network_function_device']['reference_count'] = 0
|
||||
device['nfp_context']['network_function_device']['status'] = status
|
||||
device['nfp_context']['network_function_device'][
|
||||
@@ -588,7 +626,11 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
ndo_handler._controller = mock.MagicMock(return_value=True)
|
||||
self.event.data = device
|
||||
ndo_handler.handle_device_not_reachable(self.event)
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
device['nfp_context']['network_function_device'].pop(
|
||||
'reference_count', None)
|
||||
device['nfp_context']['network_function_device'].pop(
|
||||
'interfaces_in_use', None)
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
device['nfp_context'][
|
||||
'network_function_device'][
|
||||
'id'],
|
||||
@@ -597,7 +639,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
self.event.data = tmp_data
|
||||
|
||||
@mock.patch.object(nfpdb.NFPDbBase, 'update_network_function_device')
|
||||
def test_handle_device_config_failed(self, mock_update_nsd):
|
||||
def test_handle_device_config_failed(self, mock_update_nfd):
|
||||
ndo_handler = self._initialize_ndo_handler()
|
||||
status = 'ERROR'
|
||||
self.event = DummyEvent(101, status, 1)
|
||||
@@ -610,20 +652,25 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
|
||||
device['nfp_context']['network_function_device']['status'] = status
|
||||
device['nfp_context']['network_function_device'][
|
||||
'status_description'] = desc
|
||||
device['nfp_context']['network_function_device'][
|
||||
'reference_count'] += 1
|
||||
reference_count = device['nfp_context']['network_function_device'][
|
||||
'reference_count'] + 1
|
||||
event_desc = Desc()
|
||||
device['nfp_context']['event_desc'] = event_desc.to_dict()
|
||||
device['nfp_context']['key'] = self.event.key
|
||||
device['nfp_context']['binding_key'] = self.event.binding_key
|
||||
ndo_handler._create_event = mock.MagicMock(return_value=True)
|
||||
ndo_handler._controller = mock.MagicMock(return_value=True)
|
||||
ndo_handler.nsf_db.get_network_function_device = (
|
||||
mock.MagicMock(return_value={'reference_count': (
|
||||
reference_count - 1)}))
|
||||
self.event.data = device
|
||||
ndo_handler.handle_device_config_failed(self.event)
|
||||
mock_update_nsd.assert_called_with(ndo_handler.db_session,
|
||||
mock_update_nfd.assert_called_with(ndo_handler.db_session,
|
||||
device['nfp_context'][
|
||||
'network_function_device'][
|
||||
'id'],
|
||||
device)
|
||||
{'reference_count': (
|
||||
reference_count)})
|
||||
|
||||
self.event.data = tmp_data
|
||||
|
||||
|
||||
@@ -173,7 +173,8 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
super(ServiceOrchestratorTestCase, self).setUp()
|
||||
self.controller = mock.Mock()
|
||||
self.context = mock.Mock()
|
||||
cfg.CONF.set_override("auth_version", "v1", group="keystone_authtoken")
|
||||
cfg.CONF.set_override("auth_version", "v1",
|
||||
group="nfp_keystone_authtoken")
|
||||
with mock.patch.object(identity_client, "Client"):
|
||||
self.service_orchestrator = nso.ServiceOrchestrator(
|
||||
self.controller,
|
||||
@@ -214,8 +215,10 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
'consumer': None,
|
||||
'resource_owner_context': {'admin_token': str(pyuuid.uuid4()),
|
||||
'admin_tenant_id': str(pyuuid.uuid4())},
|
||||
'service_chain_instance': {'id': str(pyuuid.uuid4())},
|
||||
'service_chain_node': {'id': str(pyuuid.uuid4())},
|
||||
'service_chain_instance': {'id': str(pyuuid.uuid4()),
|
||||
'name': str(pyuuid.uuid4())},
|
||||
'service_chain_node': {'id': str(pyuuid.uuid4()),
|
||||
'name': str(pyuuid.uuid4())},
|
||||
'service_profile': {'id': str(pyuuid.uuid4()),
|
||||
'service_flavor': None,
|
||||
'service_type': 'xyz'},
|
||||
@@ -261,11 +264,16 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
'network_function_mode': 'gbp',
|
||||
'management_ptg_id': None
|
||||
}
|
||||
transport.parse_service_flavor_string = mock.MagicMock(
|
||||
return_value={'device_type': 'VM',
|
||||
'service_vendor': 'vyos'})
|
||||
return_value = (
|
||||
self.service_orchestrator._validate_create_service_input(
|
||||
self.context, network_function))
|
||||
self.assertIsNone(return_value)
|
||||
|
||||
@mock.patch.object(
|
||||
openstack_driver.KeystoneClient, "get_admin_tenant_id")
|
||||
@mock.patch.object(
|
||||
openstack_driver.KeystoneClient, "get_admin_token")
|
||||
@mock.patch.object(
|
||||
@@ -274,8 +282,13 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
nso.NSOConfiguratorRpcApi, "delete_network_function_user_config")
|
||||
def test_delete_network_function_without_nfi(self, mock_rpc,
|
||||
mock_get_service_profile,
|
||||
mock_get_admin_token):
|
||||
mock_get_admin_token,
|
||||
mock_get_admin_tenant_id):
|
||||
network_function = self.create_network_function()
|
||||
nfp_core_context.get_nfp_context = mock.MagicMock(
|
||||
return_value={})
|
||||
mock_get_admin_token.return_value = 'admin_token'
|
||||
mock_get_admin_tenant_id.return_value = 'admin_tenant_id'
|
||||
transport.parse_service_flavor_string = mock.MagicMock(
|
||||
return_value={'device_type': 'VM',
|
||||
'service_vendor': 'vyos'})
|
||||
@@ -287,6 +300,8 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
self.assertFalse(self.controller.event.called)
|
||||
self.assertFalse(self.controller.rpc_event.called)
|
||||
|
||||
@mock.patch.object(
|
||||
openstack_driver.KeystoneClient, "get_admin_tenant_id")
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
@mock.patch.object(
|
||||
@@ -298,36 +313,29 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
def test_delete_network_function_with_nfi(self, mock_rpc,
|
||||
mock_get_service_profile,
|
||||
mock_get_admin_token,
|
||||
mock_create_event):
|
||||
mock_create_event,
|
||||
mock_get_admin_tenant_id):
|
||||
network_function_instance = self.create_network_function_instance()
|
||||
network_function_id = network_function_instance['network_function_id']
|
||||
network_function = self.nfp_db.get_network_function(
|
||||
self.session, network_function_id)
|
||||
mock_get_admin_token.return_value = 'admin_token'
|
||||
mock_get_admin_tenant_id.return_value = 'admin_tenant_id'
|
||||
nfp_core_context.get_nfp_context = mock.MagicMock(
|
||||
return_value={})
|
||||
transport.parse_service_flavor_string = mock.MagicMock(
|
||||
return_value={'device_type': 'VM',
|
||||
'service_vendor': 'vyos'})
|
||||
tag_str = 'heat_config'
|
||||
self.service_orchestrator.delete_network_function(
|
||||
self.context, network_function_id)
|
||||
network_function = self.nfp_db.get_network_function(
|
||||
self.session, network_function_id)
|
||||
self.assertEqual('PENDING_DELETE', network_function['status'])
|
||||
network_function_details = (
|
||||
self.service_orchestrator.get_network_function_details(
|
||||
network_function['id']))
|
||||
del network_function_details['service_type']
|
||||
service_config = network_function['service_config']
|
||||
network_function_data = {
|
||||
'service_type': mock.ANY,
|
||||
'network_function_details': network_function_details
|
||||
}
|
||||
mock_rpc.assert_called_once_with(
|
||||
network_function_data, service_config, tag_str)
|
||||
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
def test_event_create_network_function_instance(self, mock_create_event):
|
||||
network_function = self.create_network_function()
|
||||
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',
|
||||
@@ -348,6 +356,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
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',
|
||||
@@ -359,18 +368,8 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
'provider': {'pt': None}
|
||||
}
|
||||
test_event = Event(data=create_nfi_request)
|
||||
self.assertEqual([], network_function['network_function_instances'])
|
||||
self.service_orchestrator.create_network_function_instance(
|
||||
test_event)
|
||||
db_network_function = self.nfp_db.get_network_function(
|
||||
self.session, network_function['id'])
|
||||
self.assertEqual(
|
||||
1, len(db_network_function['network_function_instances']))
|
||||
# The value of port_info in network_function_instance is a list
|
||||
# when we do a DB get, the order changes resulting in test failing
|
||||
# if we validate the event data
|
||||
mock_create_event.assert_called_once_with(
|
||||
'CREATE_NETWORK_FUNCTION_DEVICE', event_data=mock.ANY)
|
||||
|
||||
def test_event_handle_device_created(self):
|
||||
nfd = self.create_network_function_device()
|
||||
@@ -418,7 +417,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
db_nf = self.nfp_db.get_network_function(
|
||||
self.session, nfi['network_function_id'])
|
||||
self.assertEqual(nfd['id'], db_nfi['network_function_device_id'])
|
||||
self.assertIsNotNone(db_nf['heat_stack_id'])
|
||||
self.assertIsNotNone(db_nf['config_policy_id'])
|
||||
|
||||
def test_event_handle_device_create_failed(self):
|
||||
nfd = self.create_network_function_device()
|
||||
@@ -450,8 +449,9 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
# Verify return status IN_PROGRESS from cfg.CONF driver
|
||||
mock_is_config_complete.return_value = "IN_PROGRESS"
|
||||
request_data = {
|
||||
'service_details': {'service_vendor': 'vyos'},
|
||||
'tenant_id': network_function['tenant_id'],
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id'],
|
||||
'network_function_details': network_function_details,
|
||||
'network_function': {'id': network_function['id']},
|
||||
@@ -472,8 +472,9 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
mock_is_config_complete.reset_mock()
|
||||
mock_is_config_complete.return_value = "ERROR"
|
||||
request_data = {
|
||||
'service_details': {'service_vendor': 'vyos'},
|
||||
'tenant_id': network_function['tenant_id'],
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id'],
|
||||
'network_function_details': network_function_details,
|
||||
'network_function': {'id': network_function['id']},
|
||||
@@ -495,8 +496,9 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
mock_is_config_complete.reset_mock()
|
||||
mock_is_config_complete.return_value = "COMPLETED"
|
||||
request_data = {
|
||||
'service_details': {'service_vendor': 'vyos'},
|
||||
'tenant_id': network_function['tenant_id'],
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id'],
|
||||
'network_function_details': network_function_details,
|
||||
'network_function': {'id': network_function['id']},
|
||||
@@ -516,7 +518,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
def test_event_handle_user_config_applied(self):
|
||||
network_function = self.create_network_function()
|
||||
request_data = {
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id']
|
||||
}
|
||||
test_event = Event(data=request_data)
|
||||
@@ -528,7 +530,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
def test_event_handle_user_config_failed(self):
|
||||
network_function = self.create_network_function()
|
||||
request_data = {
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id']
|
||||
}
|
||||
test_event = Event(data=request_data)
|
||||
@@ -548,19 +550,20 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
mock_is_config_delete_complete.return_value = "IN_PROGRESS"
|
||||
request_data = {
|
||||
'tenant_id': network_function['tenant_id'],
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id']}
|
||||
test_event = Event(data=request_data)
|
||||
status = self.service_orchestrator.check_for_user_config_deleted(
|
||||
test_event)
|
||||
mock_is_config_delete_complete.assert_called_once_with(
|
||||
request_data['heat_stack_id'], network_function['tenant_id'],
|
||||
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['heat_stack_id'],
|
||||
db_nf['heat_stack_id'])
|
||||
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
|
||||
@@ -568,13 +571,14 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
mock_is_config_delete_complete.return_value = "ERROR"
|
||||
request_data = {
|
||||
'tenant_id': network_function['tenant_id'],
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id']}
|
||||
test_event = Event(data=request_data)
|
||||
status = self.service_orchestrator.check_for_user_config_deleted(
|
||||
test_event)
|
||||
mock_is_config_delete_complete.assert_called_once_with(
|
||||
request_data['heat_stack_id'], network_function['tenant_id'],
|
||||
request_data['config_policy_id'],
|
||||
network_function['tenant_id'],
|
||||
network_function)
|
||||
event_data = {
|
||||
'network_function_id': network_function['id']
|
||||
@@ -591,50 +595,24 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
mock_is_config_delete_complete.return_value = "COMPLETED"
|
||||
request_data = {
|
||||
'tenant_id': network_function['tenant_id'],
|
||||
'heat_stack_id': 'heat_stack_id',
|
||||
'config_policy_id': 'config_policy_id',
|
||||
'network_function_id': network_function['id'],
|
||||
'action': 'update'}
|
||||
test_event = Event(data=request_data)
|
||||
status = self.service_orchestrator.check_for_user_config_deleted(
|
||||
test_event)
|
||||
mock_is_config_delete_complete.assert_called_once_with(
|
||||
request_data['heat_stack_id'], network_function['tenant_id'],
|
||||
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(None, db_nf['heat_stack_id'])
|
||||
self.assertEqual(None, db_nf['config_policy_id'])
|
||||
mock_create_event.assert_called_once_with(
|
||||
'UPDATE_USER_CONFIG_IN_PROGRESS', event_data=request_data,
|
||||
original_event=test_event)
|
||||
self.assertEqual(status, nso.STOP_POLLING)
|
||||
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
@mock.patch.object(
|
||||
openstack_driver.KeystoneClient, "get_admin_token")
|
||||
@mock.patch.object(
|
||||
openstack_driver.GBPClient, "get_service_profile")
|
||||
@mock.patch.object(
|
||||
nso.NSOConfiguratorRpcApi, "delete_network_function_user_config")
|
||||
def test_event_handle_user_config_deleted(self, mock_delete_rpc,
|
||||
mock_get_admin_token,
|
||||
mock_get_service_profile,
|
||||
mock_create_event):
|
||||
nfi = self.create_network_function_instance()
|
||||
request_data = {
|
||||
'network_function_id': nfi['network_function_id']
|
||||
}
|
||||
transport.parse_service_flavor_string = mock.MagicMock(
|
||||
return_value={'device_type': 'VM',
|
||||
'service_vendor': 'vyos'})
|
||||
test_event = Event(data=request_data)
|
||||
# test_event.status = 'PTG_ADD_IN_PROGRESS'
|
||||
test_event.data['status'] = 'status'
|
||||
self.service_orchestrator.handle_user_config_deleted(test_event)
|
||||
mock_create_event.assert_called_once_with(
|
||||
'DELETE_NETWORK_FUNCTION_INSTANCE', event_data=nfi['id'],
|
||||
is_internal_event=True)
|
||||
|
||||
def test_event_handle_user_config_delete_failed(self):
|
||||
network_function = self.create_network_function()
|
||||
request_data = {
|
||||
@@ -646,6 +624,8 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
self.session, network_function['id'])
|
||||
self.assertEqual('ERROR', db_nf['status'])
|
||||
|
||||
@mock.patch.object(
|
||||
openstack_driver.KeystoneClient, "get_admin_tenant_id")
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
@mock.patch.object(
|
||||
@@ -656,32 +636,25 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
nso.NSOConfiguratorRpcApi, "delete_network_function_user_config")
|
||||
def test_delete_network_function(self, mock_rpc, mock_get_service_profile,
|
||||
mock_get_admin_token,
|
||||
mock_create_event):
|
||||
mock_create_event,
|
||||
mock_get_admin_tenant_id):
|
||||
nfi = self.create_network_function_instance()
|
||||
network_function = self.nfp_db.get_network_function(
|
||||
self.session, nfi['network_function_id'])
|
||||
transport.parse_service_flavor_string = mock.MagicMock(
|
||||
return_value={'device_type': 'VM',
|
||||
'service_vendor': 'vyos'})
|
||||
tag_str = 'heat_config'
|
||||
self.assertEqual([nfi['id']],
|
||||
network_function['network_function_instances'])
|
||||
mock_get_admin_token.return_value = 'admin_token'
|
||||
mock_get_admin_tenant_id.return_value = 'admin_tenant_id'
|
||||
nfp_core_context.get_nfp_context = mock.MagicMock(
|
||||
return_value={})
|
||||
self.service_orchestrator.delete_network_function(
|
||||
self.context, network_function['id'])
|
||||
db_nf = self.nfp_db.get_network_function(
|
||||
self.session, network_function['id'])
|
||||
self.assertEqual('PENDING_DELETE', db_nf['status'])
|
||||
network_function_details = (
|
||||
self.service_orchestrator.get_network_function_details(
|
||||
network_function['id']))
|
||||
del network_function_details['service_type']
|
||||
service_config = network_function['service_config']
|
||||
network_function_data = {
|
||||
'service_type': mock.ANY,
|
||||
'network_function_details': network_function_details
|
||||
}
|
||||
mock_rpc.assert_called_once_with(
|
||||
network_function_data, service_config, tag_str)
|
||||
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
@@ -691,20 +664,13 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
self.session, nfi['network_function_id'])
|
||||
self.assertEqual([nfi['id']],
|
||||
network_function['network_function_instances'])
|
||||
test_event = Event(data=nfi['id'])
|
||||
data = {'network_function_instance': nfi}
|
||||
test_event = Event(data=data)
|
||||
self.service_orchestrator.delete_network_function_instance(
|
||||
test_event)
|
||||
db_nfi = self.nfp_db.get_network_function_instance(
|
||||
self.session, nfi['id'])
|
||||
self.assertEqual(nfp_constants.PENDING_DELETE, db_nfi['status'])
|
||||
delete_event_data = {
|
||||
'network_function_id': nfi['network_function_id'],
|
||||
'network_function_device_id': nfi['network_function_device_id'],
|
||||
'network_function_instance': db_nfi
|
||||
}
|
||||
mock_create_event.assert_called_once_with(
|
||||
'DELETE_NETWORK_FUNCTION_DEVICE',
|
||||
event_data=delete_event_data)
|
||||
|
||||
def test_event_handle_device_deleted(self):
|
||||
nfi = self.create_network_function_instance()
|
||||
@@ -749,7 +715,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
self.context, network_function_id, policy_target)
|
||||
db_nf = self.nfp_db.get_network_function(
|
||||
self.session, nfi['network_function_id'])
|
||||
self.assertIsNotNone(db_nf['heat_stack_id'])
|
||||
self.assertIsNotNone(db_nf['config_policy_id'])
|
||||
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
@@ -777,7 +743,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
self.context, network_function_id, policy_target)
|
||||
db_nf = self.nfp_db.get_network_function(
|
||||
self.session, nfi['network_function_id'])
|
||||
self.assertIsNotNone(db_nf['heat_stack_id'])
|
||||
self.assertIsNotNone(db_nf['config_policy_id'])
|
||||
|
||||
@mock.patch.object(
|
||||
nso.ServiceOrchestrator, "_create_event")
|
||||
@@ -809,7 +775,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
db_nf = self.nfp_db.get_network_function(
|
||||
self.session, nfi['network_function_id'])
|
||||
tag_str = 'heat_config'
|
||||
self.assertIsNotNone(db_nf['heat_stack_id'])
|
||||
self.assertIsNotNone(db_nf['config_policy_id'])
|
||||
service_config = db_nf['service_config']
|
||||
network_function_details = (
|
||||
self.service_orchestrator.get_network_function_details(
|
||||
@@ -855,7 +821,7 @@ class ServiceOrchestratorTestCase(NSOModuleTestCase):
|
||||
db_nf = self.nfp_db.get_network_function(
|
||||
self.session, nfi['network_function_id'])
|
||||
tag_str = 'heat_config'
|
||||
self.assertIsNotNone(db_nf['heat_stack_id'])
|
||||
self.assertIsNotNone(db_nf['config_policy_id'])
|
||||
service_config = db_nf['service_config']
|
||||
network_function_details = (
|
||||
self.service_orchestrator.get_network_function_details(
|
||||
|
||||
@@ -64,7 +64,8 @@ class MockHeatClient(object):
|
||||
def __init__(self, api_version, endpoint, **kwargs):
|
||||
self.stacks = MockHeatClientFunctions()
|
||||
|
||||
cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token')
|
||||
cfg.CONF.import_group('nfp_keystone_authtoken',
|
||||
'gbpservice.nfp.orchestrator.modules.__init__')
|
||||
IS_SERVICE_ADMIN_OWNED = True
|
||||
SVC_MGMT_PTG_NAME = 'svc_management_ptg'
|
||||
RESOURCE_OWNER_TENANT_ID = '8ae6701128994ab281dde6b92207bb19'
|
||||
@@ -87,13 +88,13 @@ class TestHeatDriver(unittest.TestCase):
|
||||
group='heat_driver')
|
||||
cfg.CONF.set_override('admin_user',
|
||||
'neutron',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
cfg.CONF.set_override('admin_password',
|
||||
'admin_pass',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
cfg.CONF.set_override('admin_tenant_name',
|
||||
'admin',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
# cfg.CONF.set_override('resource_owner_tenant_id',
|
||||
# RESOURCE_OWNER_TENANT_ID,
|
||||
# group='heat_driver')
|
||||
@@ -548,7 +549,7 @@ class TestHeatDriver(unittest.TestCase):
|
||||
service_details['consumer_port'] = self.mock_dict.consumer_port
|
||||
service_details['provider_port'] = self.mock_dict.port_info['port']
|
||||
service_details['mgmt_ip'] = '11.3.4.5'
|
||||
service_details['heat_stack_id'] = (
|
||||
service_details['config_policy_id'] = (
|
||||
'70754fdd-0325-4856-8a39-f171b65617d6')
|
||||
self.heat_driver_obj.get_service_details = mock.Mock(
|
||||
return_value=service_details)
|
||||
@@ -594,7 +595,7 @@ class TestHeatDriver(unittest.TestCase):
|
||||
service_details['consumer_port'] = self.mock_dict.consumer_port
|
||||
service_details['provider_port'] = self.mock_dict.port_info['port']
|
||||
service_details['mgmt_ip'] = '11.3.4.5'
|
||||
service_details['heat_stack_id'] = (
|
||||
service_details['config_policy_id'] = (
|
||||
'70754fdd-0325-4856-8a39-f171b65617d6')
|
||||
self.heat_driver_obj.get_service_details = mock.Mock(
|
||||
return_value=service_details)
|
||||
@@ -635,7 +636,7 @@ class TestHeatDriver(unittest.TestCase):
|
||||
service_details['consumer_port'] = self.mock_dict.consumer_port
|
||||
service_details['provider_port'] = self.mock_dict.port_info['port']
|
||||
service_details['mgmt_ip'] = '11.3.4.5'
|
||||
service_details['heat_stack_id'] = (
|
||||
service_details['config_policy_id'] = (
|
||||
'70754fdd-0325-4856-8a39-f171b65617d6')
|
||||
self.heat_driver_obj.get_service_details = mock.Mock(
|
||||
return_value=service_details)
|
||||
@@ -677,7 +678,7 @@ class TestHeatDriver(unittest.TestCase):
|
||||
service_details['consumer_port'] = self.mock_dict.consumer_port
|
||||
service_details['provider_port'] = self.mock_dict.port_info['port']
|
||||
service_details['mgmt_ip'] = '11.3.4.5'
|
||||
service_details['heat_stack_id'] = (
|
||||
service_details['config_policy_id'] = (
|
||||
'70754fdd-0325-4856-8a39-f171b65617d6')
|
||||
self.heat_driver_obj.get_service_details = mock.Mock(
|
||||
return_value=service_details)
|
||||
|
||||
@@ -20,7 +20,8 @@ from keystoneclient.v2_0 import client as identity_client
|
||||
from neutronclient.v2_0 import client as neutron_client
|
||||
from novaclient import client as nova_client
|
||||
|
||||
cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token')
|
||||
cfg.CONF.import_group('nfp_keystone_authtoken',
|
||||
'gbpservice.nfp.orchestrator.modules.__init__')
|
||||
|
||||
|
||||
class SampleData(unittest.TestCase):
|
||||
@@ -28,8 +29,8 @@ class SampleData(unittest.TestCase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SampleData, self).__init__(*args, **kwargs)
|
||||
self.AUTH_TOKEN = '6db9dfa4d29d442eb2b23811ad4b3a6d'
|
||||
self.AUTH_URL = 'https://127.0.0.1:35357/None/'
|
||||
self.ENDPOINT_URL = 'https://127.0.0.1:9696/'
|
||||
self.AUTH_URL = 'http://localhost:5000/v2.0/'
|
||||
self.ENDPOINT_URL = 'http://localhost:9696/'
|
||||
self.FLAVOR_NAME = 'm1.tiny'
|
||||
self.IMAGE_NAME = 'cirros-0.3.4-x86_64-uec'
|
||||
self.IMAGE_ID = '7022c5a4-ef0c-4f7e-a2c8-b7f5b36c9086'
|
||||
@@ -51,16 +52,16 @@ class TestKeystoneClient(SampleData):
|
||||
def setUp(self):
|
||||
cfg.CONF.set_override('admin_user',
|
||||
'neutron',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
cfg.CONF.set_override('admin_password',
|
||||
'neutron_pass',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
cfg.CONF.set_override('admin_tenant_name',
|
||||
'service',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
cfg.CONF.set_override('auth_version',
|
||||
'None',
|
||||
group='keystone_authtoken')
|
||||
group='nfp_keystone_authtoken')
|
||||
|
||||
def test_get_admin_token(self, mock_obj):
|
||||
instance = mock_obj.return_value
|
||||
@@ -213,15 +214,16 @@ class TestNovaClient(SampleData):
|
||||
self.FLAVOR_NAME,
|
||||
None,
|
||||
"name",
|
||||
"secgroup_name",
|
||||
"metadata={}",
|
||||
"files=[]",
|
||||
"config_drive=False",
|
||||
"userdata=None",
|
||||
"key_name=''",
|
||||
"different_hosts=None",
|
||||
"volume_support=False",
|
||||
"volume_size='2'")
|
||||
False,
|
||||
'2',
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
False,
|
||||
None,
|
||||
'',
|
||||
None
|
||||
)
|
||||
|
||||
self.assertEqual(retval, obj1)
|
||||
mock_obj.assert_called_once_with('2', auth_token=self.AUTH_TOKEN,
|
||||
|
||||
Reference in New Issue
Block a user