Allow UPPER case in protocol/action for FW Rule

Currently firewall rule create/update allows only lower case values for
its protocol and action arguments. Limiting the protocol/action attribute
to lower case is not very user friendly. This patch allows the user to
provide protocol and action fields in UPPER/lower case.

Change-Id: Ib8b278fc89f81d89d30f4e8dde9797e9149d3919
Co-Authored-By:Akihiro Motoki<motoki@da.jp.nec.com>
Closes-Bug: #1508753
This commit is contained in:
reedip
2015-12-14 09:57:52 +09:00
committed by Reedip
parent 9f792d0b9c
commit d35643974c
2 changed files with 21 additions and 6 deletions

View File

@@ -103,18 +103,20 @@ class CreateFirewallRule(neutronv20.CreateCommand):
help=_('Whether to enable or disable this rule.'))
parser.add_argument(
'--protocol', choices=['tcp', 'udp', 'icmp', 'any'],
type=utils.convert_to_lowercase,
required=True,
help=_('Protocol for the firewall rule.'))
parser.add_argument(
'--action',
required=True,
type=utils.convert_to_lowercase,
choices=['allow', 'deny', 'reject'],
help=_('Action for the firewall rule.'))
def args2body(self, parsed_args):
body = {}
neutronv20.update_dict(parsed_args, body,
['name', 'description', 'shared', 'protocol',
['name', 'description', 'shared',
'source_ip_address', 'destination_ip_address',
'source_port', 'destination_port',
'action', 'enabled', 'tenant_id',
@@ -135,7 +137,10 @@ class UpdateFirewallRule(neutronv20.UpdateCommand):
parser.add_argument(
'--protocol', choices=['tcp', 'udp', 'icmp', 'any'],
required=False,
type=utils.convert_to_lowercase,
help=_('Protocol for the firewall rule.'))
# TODO(reedip) : Need to add the option for action once
# action also comes into Update Firewall Rule
def args2body(self, parsed_args):
body = {}

View File

@@ -58,8 +58,9 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
def test_create_disabled_firewall_rule_with_mandatory_params(self):
self._test_create_firewall_rule_with_mandatory_params(enabled='False')
def _setup_create_firewall_rule_with_all_params(self, protocol='tcp',
ip_version='4'):
def _setup_create_firewall_rule_with_all_params(
self, protocol='tcp', protocol_cli=None,
action='allow', action_cli=None, ip_version='4'):
# firewall-rule-create with all params set.
resource = 'firewall_rule'
cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout),
@@ -70,19 +71,18 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
destination_ip = '192.168.2.0/24'
source_port = '0:65535'
destination_port = '0:65535'
action = 'allow'
tenant_id = 'my-tenant'
my_id = 'myid'
enabled = 'True'
args = ['--description', description,
'--shared',
'--protocol', protocol,
'--protocol', protocol_cli or protocol,
'--ip-version', ip_version,
'--source-ip-address', source_ip,
'--destination-ip-address', destination_ip,
'--source-port', source_port,
'--destination-port', destination_port,
'--action', action,
'--action', action_cli or action,
'--enabled', enabled,
'--admin-state-up',
'--tenant-id', tenant_id]
@@ -126,6 +126,16 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
def test_create_firewall_rule_with_invalid_IP_version(self):
self._setup_create_firewall_rule_with_all_params(ip_version='5')
def test_create_firewall_rule_with_proto_action_upper_capitalized(self):
for protocol in ('TCP', 'Tcp', 'ANY', 'AnY'):
self._setup_create_firewall_rule_with_all_params(
protocol=protocol.lower(),
protocol_cli=protocol)
for action in ('Allow', 'DENY', 'reject'):
self._setup_create_firewall_rule_with_all_params(
action=action.lower(),
action_cli=action)
def test_list_firewall_rules(self):
# firewall-rule-list.
resources = "firewall_rules"