Explicit service port configuration

Device Orchestrator changes to add any explicit device configuration.

Change-Id: Id3a36136418b165f57800985986b616b60a50e61
Closes-Bug: 1651306
This commit is contained in:
Vikash082
2016-12-12 10:18:39 +05:30
committed by Yogesh Rajmane
parent 749696f5f0
commit a63567262a
2 changed files with 123 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ import unittest
import uuid as pyuuid
dummy_data = {}
with mock.patch('oslo_config.cfg.CONF.register_opts') as opt:
from gbpservice.nfp.orchestrator.modules import (
@@ -265,7 +266,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def _initialize_ndo_handler(self):
ndo_handler = device_orchestrator.DeviceOrchestrator(
DummyController, cfg.CONF)
self.event = DummyEvent(100, 'PENDING_CREATE')
self.event = DummyEvent(dummy_data, 'PENDING_CREATE')
return ndo_handler
@unittest.skip('skipping')
@@ -274,7 +275,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def test_handle_event(self, mock_device_configuration_complete):
ndo_mgr = device_orchestrator.DeviceOrchestrator(object, cfg.CONF)
mock_device_configuration_complete.return_value = True
self.event = DummyEvent(100, 'DEVICE_CONFIGURED')
self.event = DummyEvent(dummy_data, 'DEVICE_CONFIGURED')
self.event.id = 'DEVICE_CONFIGURED'
ndo_mgr.handle_event(self.event)
@@ -397,6 +398,48 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
ndo_handler._create_event = mock.MagicMock(return_value=True)
ndo_handler._controller.event_complete = mock.MagicMock(
return_value=None)
self._update_event()
device = self._get_device()
ndo_handler.create_device_configuration(self.event)
event_id = "UPDATE_DEVICE_CONFIG_PARAMETERS"
nfp_context = copy.deepcopy(device['nfp_context'])
nfp_context.update(resource_owner_context=self.event.data[
'resource_owner_context'],
management=self.event.data['management'],
admin_token=self.event.data['admin_token'],
service_chain_specs=self.event.data[
'service_chain_specs'],
network_function_device_id=self.event.data[
'network_function_device_id'],
provider=self.event.data['provider'],
id=self.event.data['network_function_device_id'],
reference_count=self.event.data['reference_count'],
network_function_instance=self.event.data[
'network_function_instance'],
mgmt_port_id=[{'port_role': 'active',
'port_model': 'neutron',
'id': 'myid1',
'port_classification': (
'management')}],
network_function=self.event.data[
'network_function'],
network_function_id='network_function_id',
service_details=self.event.data['service_details'],
network_function_instance_id=(
'network_function_instance_id'),
consumer=self.event.data['consumer'],
ports=self.event.data['ports'],
interfaces_in_use=self.event.data[
'interfaces_in_use'],
status='PENDING_CREATE')
nfp_context.pop('binding_key', None)
nfp_context.pop('key', None)
event_data = {'device': device, 'nfp_context': nfp_context,
'config_params': config_params}
ndo_handler._create_event.assert_called_with(event_id=event_id,
event_data=event_data)
def _update_event(self):
self.event.data['management'] = {'port': {'ip_address': '127.0.0.1'}}
self.event.data['provider']['port'] = {
'ip_address': '127.0.0.1', 'mac_address': 'xx:xx:xx:xx'}
@@ -407,10 +450,12 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
self.event.data['consumer']['subnet'] = {
'cidr': '11.0.0.0/24', 'gateway_ip': '11.0.0.1'}
self.event.data['network_function_device'][
'mgmt_ip_address'] = self.event.data['management']['port'][
'ip_address']
'mgmt_ip_address'] = self.event.data['management']['port'][
'ip_address']
self.event.data['service_chain_specs'] = []
self.event.desc = Desc()
def _get_device(self):
device = {}
device['mgmt_ip_address'] = self.event.data[
'management']['port']['ip_address']
@@ -426,9 +471,9 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
'binding_key': self.event.binding_key,
'id': self.event.id, 'key': self.event.key,
'network_function_device': self.event.data[
'network_function_device']}
'network_function_device']}
device['tenant_id'] = self.event.data[
'resource_owner_context']['admin_tenant_id']
'resource_owner_context']['admin_tenant_id']
device.update({
'provider_mac': self.event.data['provider']['port']['mac_address'],
'network_function_instance_id': self.event.data[
@@ -439,8 +484,37 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
'consumer_ip': self.event.data['consumer']['port']['ip_address'],
'consumer_cidr': self.event.data['consumer']['subnet']['cidr'],
'provider_cidr': self.event.data['provider']['subnet']['cidr']})
return device
ndo_handler.create_device_configuration(self.event)
def test_update_config_params(self):
ndo_handler = self._initialize_ndo_handler()
ndo_handler._controller.event_complete = mock.MagicMock(
return_value=None)
ndo_handler.update_config_params(self.event)
ndo_handler._create_event.assert_called_with(
event_id='DEVICE_CONFIG_PARAMETERS_UPDATED',
event_data=self.event.data, is_internal_event=True)
def test_device_configuration_updated(self):
ndo_handler = self._initialize_ndo_handler()
ndo_handler._create_event = mock.MagicMock(return_value=True)
ndo_handler._controller.event_complete = mock.MagicMock(
return_value=None)
ndo_handler.configurator_rpc.create_network_function_device_config = (
mock.MagicMock(return_value=True))
config_params = {
'param1': 'value1',
'param2': 'value2',
'config': [{'resource_data': {'forward_route': True}}]}
orchestration_driver.get_network_function_device_config = (
mock.MagicMock(return_value=config_params))
self._update_event()
device = self._get_device()
self.event.data['device'] = device
self.event.data['nfp_context'] = {'service_chain_specs': []}
self.event.data['config_params'] = config_params
ndo_handler.device_configuration_updated(self.event)
ndo_handler.configurator_rpc.create_network_function_device_config.\
assert_called_with(device, config_params)
@@ -492,7 +566,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def test_delete_network_function_device(self, mock_get_port, mock_get_nf,
mock_update_nfd, mock_get_nfd):
ndo_handler = self._initialize_ndo_handler()
delete_event_req = DummyEvent(100, 'ACTIVE')
delete_event_req = DummyEvent(dummy_data, 'ACTIVE')
delete_event_req.data = \
{'network_function_device_id': 'device-id',
'network_function_instance': {'id': 'nfi-id',
@@ -523,7 +597,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
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')
self.event = DummyEvent(dummy_data, 'ACTIVE')
orchestration_driver.get_network_function_device_config = (
mock.MagicMock(return_value=config_params))
ndo_handler.configurator_rpc.delete_network_function_device_config = (
@@ -538,7 +612,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def test_unplug_interfaces(self, mock_update_nfd, mock_get_nfd):
ndo_handler = self._initialize_ndo_handler()
self.event = DummyEvent(101, 'ACTIVE')
self.event = DummyEvent(dummy_data, 'ACTIVE')
ndo_handler._prepare_device_data = mock.MagicMock(
return_value=self.event.data)
orig_event_data = copy.deepcopy(self.event.data)
@@ -601,7 +675,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def test_handle_device_create_error(self):
ndo_handler = self._initialize_ndo_handler()
event_id = status = 'DEVICE_CREATE_FAILED'
self.event = DummyEvent(101, status, 1)
self.event = DummyEvent(dummy_data, status, 1)
orig_event_data = copy.deepcopy(self.event.data)
orig_event_data['network_function_device_id'] = orig_event_data['id']
ndo_handler._create_event = mock.MagicMock(return_value=True)
@@ -620,7 +694,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
return_value=None)
status = 'ERROR'
desc = 'Device not became ACTIVE'
self.event = DummyEvent(101, status, 1)
self.event = DummyEvent(dummy_data, status, 1)
orig_event_data = copy.deepcopy(self.event.data)
orig_event_data['status_description'] = desc
orig_event_data.pop('interfaces_in_use', None)
@@ -637,7 +711,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def test_handle_device_not_reachable(self, mock_update_nfd):
ndo_handler = self._initialize_ndo_handler()
status = 'ERROR'
self.event = DummyEvent(101, status, 1)
self.event = DummyEvent(dummy_data, status, 1)
desc = 'Device not reachable, Health Check Failed'
tmp_data = copy.deepcopy(self.event.data)
device = self.event.data
@@ -675,7 +749,7 @@ class DeviceOrchestratorTestCase(unittest.TestCase):
def test_handle_device_config_failed(self, mock_update_nfd, mock_get_nfd):
ndo_handler = self._initialize_ndo_handler()
status = 'ERROR'
self.event = DummyEvent(101, status, 1)
self.event = DummyEvent(dummy_data, status, 1)
desc = 'Configuring Device Failed.'
tmp_data = copy.deepcopy(self.event.data)
device = self.event.data

View File

@@ -61,7 +61,9 @@ def events_init(controller, config, device_orchestrator):
'DEVICE_BEING_DELETED',
'DEVICE_NOT_REACHABLE',
'DEVICE_CONFIGURATION_FAILED', 'PERFORM_HEALTH_CHECK',
'PLUG_INTERFACES', 'UNPLUG_INTERFACES']
'PLUG_INTERFACES', 'UNPLUG_INTERFACES',
'UPDATE_DEVICE_CONFIG_PARAMETERS',
'DEVICE_CONFIG_PARAMETERS_UPDATED']
events_to_register = []
for event in events:
events_to_register.append(
@@ -255,7 +257,10 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
"DEVICE_CONFIGURATION_FAILED": self.handle_device_config_failed,
"DEVICE_ERROR": self.handle_device_create_error,
"DEVICE_NOT_UP": self.handle_device_not_up,
"DRIVER_ERROR": self.handle_driver_error
"DRIVER_ERROR": self.handle_driver_error,
'UPDATE_DEVICE_CONFIG_PARAMETERS': self.update_config_params,
'DEVICE_CONFIG_PARAMETERS_UPDATED': (
self.device_configuration_updated)
}
if event_id not in event_handler_mapping:
raise Exception("Invalid event ID")
@@ -528,7 +533,8 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
consumer = nfp_context['consumer']
provider = nfp_context['provider']
ports = self._make_ports_dict(consumer, provider, 'pt')
ports = self._make_ports_dict(nfp_context.get(
'explicit_consumer', consumer), provider, 'pt')
device_data['provider_name'] = provider['ptg']['name']
device_data['management_network_info'] = management_network_info
@@ -567,6 +573,11 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
device = self._update_device_data(driver_device_info, device_data)
device['network_function_device_id'] = device['id']
# check for any explicit interface and its type.
for interface in nfp_context.get('explicit_interfaces', []):
if interface['type'] == 'gateway':
device['gateway_port'] = interface['port']
name = '%s_%s_%s_%s' % (
device['provider_name'],
service_details['service_type'],
@@ -624,6 +635,8 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
self.config.device_orchestrator.volume_support)
device_data['volume_size'] = (
self.config.device_orchestrator.volume_size)
device_data['explicit_interfaces'] = nfp_context.get(
'explicit_interfaces', [])
driver_device_info = (
orchestration_driver.create_network_function_device(
device_data))
@@ -936,7 +949,9 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
orchestration_driver = self._get_orchestration_driver(
service_details['service_vendor'])
ports = self._make_ports_dict(consumer, provider, 'port')
ports = self._make_ports_dict(
nfp_context.get('explicit_consumer', consumer),
provider, 'port')
device = {
'id': network_function_device['id'],
@@ -1035,6 +1050,16 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
is_internal_event=True)
self._controller.event_complete(event, result="FAILED")
return None
event_data = {'device': device, 'nfp_context': nfp_context,
'config_params': config_params}
self._create_event(event_id='UPDATE_DEVICE_CONFIG_PARAMETERS',
event_data=event_data)
def device_configuration_updated(self, event):
nfp_context, config_params, device = (
event.data['nfp_context'], event.data['config_params'],
event.data['device'])
# Set forward_route as False in resource_data for configurator to
# handle routes differently, when vpn is in service chain
if nfp_utils.is_vpn_in_service_chain(
@@ -1047,6 +1072,7 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
# Sends RPC to configurator to create generic config
self.configurator_rpc.create_network_function_device_config(
device, config_params)
self._controller.event_complete(event=event, result='SUCCESS')
def configuration_complete(self, event):
nfp_context = event.data
@@ -1292,6 +1318,11 @@ class DeviceOrchestrator(nfp_api.NfpEventHandler):
self._create_event(event_id='DEVICE_CREATE_FAILED',
event_data=device)
def update_config_params(self, event):
self._create_event(event_id='DEVICE_CONFIG_PARAMETERS_UPDATED',
event_data=event.data, is_internal_event=True)
self._controller.event_complete(event=event, result='SUCCESS')
class NDOConfiguratorRpcApi(object):
"""Service Manager side of the Service Manager to Service agent RPC API"""