SFC plugin: fix dictionary parameters
Service function parameters could not be set on a port pair, and "None" correlation value was not accepted Chain parameters were passed incorrectly to server on a port chain On a port pair group, lb_fields must be passed to the API with an underscore Fix check on empty dictionary parameters (we get [], not None) Also fix related unit tests Change-Id: Ie60c609b8d33731a7fed732d97ed92982523956b Closes-Bug: #1719584
This commit is contained in:
@@ -324,13 +324,11 @@ def _get_common_attrs(client_manager, parsed_args, is_create=True):
|
||||
attrs['name'] = parsed_args.name
|
||||
if parsed_args.description is not None:
|
||||
attrs['description'] = parsed_args.description
|
||||
if ('port_pair_groups' in parsed_args and
|
||||
parsed_args.port_pair_groups is not None):
|
||||
if parsed_args.port_pair_groups:
|
||||
attrs['port_pair_groups'] = [(_get_id(client_manager.neutronclient,
|
||||
ppg, 'port_pair_group'))
|
||||
for ppg in parsed_args.port_pair_groups]
|
||||
if ('flow_classifiers' in parsed_args and
|
||||
parsed_args.flow_classifiers is not None):
|
||||
if parsed_args.flow_classifiers:
|
||||
attrs['flow_classifiers'] = [(_get_id(client_manager.neutronclient, fc,
|
||||
'flow_classifier'))
|
||||
for fc in parsed_args.flow_classifiers]
|
||||
@@ -340,8 +338,14 @@ def _get_common_attrs(client_manager, parsed_args, is_create=True):
|
||||
|
||||
|
||||
def _get_attrs(attrs, parsed_args):
|
||||
if 'chain_parameters' in parsed_args:
|
||||
attrs['chain_parameters'] = parsed_args.chain_parameters
|
||||
if parsed_args.chain_parameters is not None:
|
||||
chain_params = {}
|
||||
for chain_param in parsed_args.chain_parameters:
|
||||
if 'correlation' in chain_param:
|
||||
chain_params['correlation'] = chain_param['correlation']
|
||||
if 'symmetric' in chain_param:
|
||||
chain_params['symmetric'] = chain_param['symmetric']
|
||||
attrs['chain_parameters'] = chain_params
|
||||
|
||||
|
||||
def _get_id(client, id_or_name, resource):
|
||||
|
||||
@@ -206,10 +206,23 @@ def _get_attrs(client_manager, attrs, parsed_args):
|
||||
if parsed_args.egress is not None:
|
||||
attrs['egress'] = _get_id(client_manager.neutronclient,
|
||||
parsed_args.egress, 'port')
|
||||
if 'service_function_parameters' in parsed_args:
|
||||
attrs['service_function_parameters'] = (
|
||||
if parsed_args.service_function_parameters is not None:
|
||||
attrs['service_function_parameters'] = _get_service_function_params(
|
||||
parsed_args.service_function_parameters)
|
||||
|
||||
|
||||
def _get_service_function_params(sf_params):
|
||||
attrs = {}
|
||||
for sf_param in sf_params:
|
||||
if 'correlation' in sf_param:
|
||||
if sf_param['correlation'] == 'None':
|
||||
attrs['correlation'] = None
|
||||
else:
|
||||
attrs['correlation'] = sf_param['correlation']
|
||||
if 'weight' in sf_param:
|
||||
attrs['weight'] = sf_param['weight']
|
||||
return attrs
|
||||
|
||||
|
||||
def _get_id(client, id_or_name, resource):
|
||||
return client.find_resource(resource, id_or_name)['id']
|
||||
|
||||
@@ -257,8 +257,8 @@ class UnsetSfcPortPairGroup(command.Command):
|
||||
def _get_ppg_param(attrs, ppg):
|
||||
attrs['port_pair_group_parameters'] = {}
|
||||
for key, value in ppg.items():
|
||||
if key == 'lb_fields':
|
||||
attrs['port_pair_group_parameters'][key] = ([
|
||||
if key == 'lb-fields':
|
||||
attrs['port_pair_group_parameters']['lb_fields'] = ([
|
||||
field for field in value.split('&') if field])
|
||||
else:
|
||||
attrs['port_pair_group_parameters'][key] = value
|
||||
@@ -281,8 +281,7 @@ def _get_common_attrs(client_manager, parsed_args, is_create=True):
|
||||
|
||||
|
||||
def _get_attrs(attrs, parsed_args):
|
||||
if ('port_pair_group_parameters' in parsed_args and
|
||||
parsed_args.port_pair_group_parameters is not None):
|
||||
if parsed_args.port_pair_group_parameters is not None:
|
||||
attrs['port_pair_group_parameters'] = (
|
||||
_get_ppg_param(attrs, parsed_args.port_pair_group_parameters))
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class TestCreateSfcPortChain(fakes.TestNeutronClientOSCV2):
|
||||
# Get the command object to test
|
||||
self.cmd = sfc_port_chain.CreateSfcPortChain(self.app, self.namespace)
|
||||
|
||||
def test_create_port_chain_dafault_options(self):
|
||||
def test_create_port_chain_default_options(self):
|
||||
arglist = [
|
||||
self._port_chain['name'],
|
||||
"--port-pair-group", self._port_chain['port_pair_groups']
|
||||
@@ -80,9 +80,7 @@ class TestCreateSfcPortChain(fakes.TestNeutronClientOSCV2):
|
||||
self.neutronclient.create_sfc_port_chain.assert_called_once_with({
|
||||
'port_chain': {
|
||||
'name': self._port_chain['name'],
|
||||
'port_pair_groups': [self._port_chain['port_pair_groups']],
|
||||
'flow_classifiers': [],
|
||||
'chain_parameters': None}
|
||||
'port_pair_groups': [self._port_chain['port_pair_groups']]}
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
@@ -96,14 +94,14 @@ class TestCreateSfcPortChain(fakes.TestNeutronClientOSCV2):
|
||||
"--chain-parameters", 'correlation=mpls,symmetric=true',
|
||||
]
|
||||
|
||||
cp = [{'correlation': 'mpls', 'symmetric': 'true'}]
|
||||
cp = {'correlation': 'mpls', 'symmetric': 'true'}
|
||||
|
||||
verifylist = [
|
||||
('port_pair_groups', [self._port_chain['port_pair_groups']]),
|
||||
('name', self._port_chain['name']),
|
||||
('description', self._port_chain['description']),
|
||||
('flow_classifiers', [self._port_chain['flow_classifiers']]),
|
||||
('chain_parameters', cp)
|
||||
('chain_parameters', [cp])
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@@ -75,7 +75,6 @@ class TestCreateSfcPortPair(fakes.TestNeutronClientOSCV2):
|
||||
'port_pair': {'name': self._port_pair['name'],
|
||||
'ingress': self._port_pair['ingress'],
|
||||
'egress': self._port_pair['egress'],
|
||||
'service_function_parameters': None,
|
||||
}
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
@@ -91,27 +90,30 @@ class TestCreateSfcPortPair(fakes.TestNeutronClientOSCV2):
|
||||
'correlation=%s,weight=1' % correlation,
|
||||
]
|
||||
|
||||
sfp = [{'correlation': correlation, 'weight': '1'}]
|
||||
|
||||
verifylist = [
|
||||
('ingress', self._port_pair['ingress']),
|
||||
('egress', self._port_pair['egress']),
|
||||
('name', self._port_pair['name']),
|
||||
('description', self._port_pair['description']),
|
||||
('service_function_parameters', sfp)
|
||||
('service_function_parameters',
|
||||
[{'correlation': correlation, 'weight': '1'}])
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = (self.cmd.take_action(parsed_args))
|
||||
|
||||
if correlation == "None":
|
||||
correlation_param = None
|
||||
else:
|
||||
correlation_param = correlation
|
||||
self.neutronclient.create_sfc_port_pair.assert_called_once_with({
|
||||
'port_pair': {'name': self._port_pair['name'],
|
||||
'ingress': self._port_pair['ingress'],
|
||||
'egress': self._port_pair['egress'],
|
||||
'description': self._port_pair['description'],
|
||||
'service_function_parameters':
|
||||
[{'correlation': correlation, 'weight':
|
||||
'1'}],
|
||||
{'correlation': correlation_param, 'weight':
|
||||
'1'},
|
||||
}
|
||||
})
|
||||
self.assertEqual(self.columns, columns)
|
||||
|
||||
Reference in New Issue
Block a user