From 9fa08d1bd0314ac63ad7923cae1c3129c64174e3 Mon Sep 17 00:00:00 2001 From: Yushiro FURUKAWA Date: Mon, 23 Jan 2017 20:22:30 +0900 Subject: [PATCH] FWaaSv2 - Enable to specify 'any' for protocol This commits fixes to specify 'any' for protocol in firewall_rule. Change-Id: I5d0012afdc319b67877c5ccaea4e6b41efbf6a9e Closes-Bug: #1658598 --- neutronclient/osc/v2/fwaas/firewallrule.py | 3 ++- .../unit/osc/v2/fwaas/test_firewallrule.py | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/neutronclient/osc/v2/fwaas/firewallrule.py b/neutronclient/osc/v2/fwaas/firewallrule.py index a7d9051f3..e63f0cdbd 100644 --- a/neutronclient/osc/v2/fwaas/firewallrule.py +++ b/neutronclient/osc/v2/fwaas/firewallrule.py @@ -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: diff --git a/neutronclient/tests/unit/osc/v2/fwaas/test_firewallrule.py b/neutronclient/tests/unit/osc/v2/fwaas/test_firewallrule.py index dd730ee49..1aa73b304 100644 --- a/neutronclient/tests/unit/osc/v2/fwaas/test_firewallrule.py +++ b/neutronclient/tests/unit/osc/v2/fwaas/test_firewallrule.py @@ -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 = [