FWaaSv2 - Enable to specify 'any' for protocol

This commits fixes to specify 'any' for protocol in firewall_rule.

Change-Id: I5d0012afdc319b67877c5ccaea4e6b41efbf6a9e
Closes-Bug: #1658598
This commit is contained in:
Yushiro FURUKAWA 2017-01-23 20:22:30 +09:00
parent 74ae453d6c
commit 9fa08d1bd0
2 changed files with 20 additions and 3 deletions

View File

@ -147,7 +147,8 @@ def _get_common_attrs(client_manager, parsed_args, is_create=True):
if parsed_args.description:
attrs['description'] = str(parsed_args.description)
if parsed_args.protocol:
attrs['protocol'] = parsed_args.protocol
protocol = parsed_args.protocol
attrs['protocol'] = None if protocol == 'any' else protocol
if parsed_args.action:
attrs['action'] = parsed_args.action
if parsed_args.ip_version:

View File

@ -56,6 +56,8 @@ def _generate_req_and_res(verifylist):
new_value = True
elif (key == 'disable' or key == 'disable_rule') and val:
new_value = False
elif (key == 'protocol' and val and val.lower() == 'any'):
new_value = None
else:
new_value = val
request[converted] = new_value
@ -256,7 +258,7 @@ class TestCreateFirewallRule(TestFirewallRule, common.TestCreateFWaaS):
self.check_parser, self.cmd, arglist, verifylist)
def test_create_with_all_params_protocol_upper_capitalized(self):
for protocol in ('TCP', 'Tcp', 'ANY', 'AnY'):
for protocol in ('TCP', 'Tcp', 'ANY', 'AnY', 'iCMp'):
arglist, verifylist = self._set_all_params({'protocol': protocol})
self.assertRaises(
testtools.matchers._impl.MismatchError,
@ -354,7 +356,7 @@ class TestSetFirewallRule(TestFirewallRule, common.TestSetFWaaS):
result = self.cmd.take_action(parsed_args)
self.mocked.assert_called_once_with(
target, {self.res: {'protocol': protocol}})
target, {self.res: {'protocol': None}})
self.assertIsNone(result)
def test_set_protocol_with_udp(self):
@ -640,6 +642,20 @@ class TestUnsetFirewallRule(TestFirewallRule, common.TestUnsetFWaaS):
self.mocked = self.neutronclient.update_fwaas_firewall_rule
self.cmd = firewallrule.UnsetFirewallRule(self.app, self.namespace)
def test_unset_protocol_and_raise(self):
self.neutronclient.update_fwaas_firewall_rule.side_effect = Exception
target = self.resource['id']
arglist = [
target,
'--protocol',
]
verifylist = [
(self.res, target),
('protocol', False)
]
self.assertRaises(utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
def test_unset_source_port(self):
target = self.resource['id']
arglist = [