Add help information of 'firewall-rule-create'

This patch adds information about ip-version to firewall-rule-create's
help output.

Change-Id: I799cdb98e12c90fb83965ca32e8fa21fc925856b
Closes-Bug: #1495427
This commit is contained in:
Kenji Yasui
2015-09-15 00:13:17 +00:00
parent ff57cf6e5e
commit 96eff78ce9
2 changed files with 41 additions and 13 deletions

View File

@@ -81,6 +81,10 @@ class CreateFirewallRule(neutronv20.CreateCommand):
action='store_true', action='store_true',
help=_('Set shared to True (default is False).'), help=_('Set shared to True (default is False).'),
default=argparse.SUPPRESS) default=argparse.SUPPRESS)
parser.add_argument(
'--ip-version',
type=int, choices=[4, 6], default=4,
help=_('IP version for the firewall rule (default is 4).'))
parser.add_argument( parser.add_argument(
'--source-ip-address', '--source-ip-address',
help=_('Source IP address or subnet.')) help=_('Source IP address or subnet.'))
@@ -113,7 +117,8 @@ class CreateFirewallRule(neutronv20.CreateCommand):
['name', 'description', 'shared', 'protocol', ['name', 'description', 'shared', 'protocol',
'source_ip_address', 'destination_ip_address', 'source_ip_address', 'destination_ip_address',
'source_port', 'destination_port', 'source_port', 'destination_port',
'action', 'enabled', 'tenant_id']) 'action', 'enabled', 'tenant_id',
'ip_version'])
protocol = parsed_args.protocol protocol = parsed_args.protocol
if protocol == 'any': if protocol == 'any':
protocol = None protocol = None

View File

@@ -32,6 +32,7 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
my_id = 'myid' my_id = 'myid'
protocol = 'tcp' protocol = 'tcp'
action = 'allow' action = 'allow'
ip_version = 4
args = ['--tenant-id', tenant_id, args = ['--tenant-id', tenant_id,
'--admin-state-up', '--admin-state-up',
'--protocol', protocol, '--protocol', protocol,
@@ -42,7 +43,8 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
self._test_create_resource(resource, cmd, name, my_id, args, self._test_create_resource(resource, cmd, name, my_id, args,
position_names, position_values, position_names, position_values,
protocol=protocol, action=action, protocol=protocol, action=action,
enabled=enabled, tenant_id=tenant_id) enabled=enabled, tenant_id=tenant_id,
ip_version=ip_version)
def test_create_enabled_firewall_rule_with_mandatory_params_lcase(self): def test_create_enabled_firewall_rule_with_mandatory_params_lcase(self):
self._test_create_firewall_rule_with_mandatory_params(enabled='true') self._test_create_firewall_rule_with_mandatory_params(enabled='true')
@@ -56,7 +58,8 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
def test_create_disabled_firewall_rule_with_mandatory_params(self): def test_create_disabled_firewall_rule_with_mandatory_params(self):
self._test_create_firewall_rule_with_mandatory_params(enabled='False') self._test_create_firewall_rule_with_mandatory_params(enabled='False')
def _setup_create_firewall_rule_with_all_params(self, protocol='tcp'): def _setup_create_firewall_rule_with_all_params(self, protocol='tcp',
ip_version='4'):
# firewall-rule-create with all params set. # firewall-rule-create with all params set.
resource = 'firewall_rule' resource = 'firewall_rule'
cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout), cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout),
@@ -74,6 +77,7 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
args = ['--description', description, args = ['--description', description,
'--shared', '--shared',
'--protocol', protocol, '--protocol', protocol,
'--ip-version', ip_version,
'--source-ip-address', source_ip, '--source-ip-address', source_ip,
'--destination-ip-address', destination_ip, '--destination-ip-address', destination_ip,
'--source-port', source_port, '--source-port', source_port,
@@ -86,16 +90,29 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
position_values = [] position_values = []
if protocol == 'any': if protocol == 'any':
protocol = None protocol = None
self._test_create_resource(resource, cmd, name, my_id, args, if ip_version == '4' or ip_version == '6':
position_names, position_values, self._test_create_resource(resource, cmd, name, my_id, args,
description=description, shared=True, position_names, position_values,
protocol=protocol, description=description, shared=True,
source_ip_address=source_ip, protocol=protocol,
destination_ip_address=destination_ip, ip_version=int(ip_version),
source_port=source_port, source_ip_address=source_ip,
destination_port=destination_port, destination_ip_address=destination_ip,
action=action, enabled='True', source_port=source_port,
tenant_id=tenant_id) destination_port=destination_port,
action=action, enabled='True',
tenant_id=tenant_id)
else:
self.assertRaises(SystemExit, self._test_create_resource,
resource, cmd, name, my_id, args,
position_names, position_values,
ip_version=int(ip_version),
source_ip_address=source_ip,
destination_ip_address=destination_ip,
source_port=source_port,
destination_port=destination_port,
action=action, enabled='True',
tenant_id=tenant_id)
def test_create_firewall_rule_with_all_params(self): def test_create_firewall_rule_with_all_params(self):
self._setup_create_firewall_rule_with_all_params() self._setup_create_firewall_rule_with_all_params()
@@ -103,6 +120,12 @@ class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
def test_create_firewall_rule_with_proto_any(self): def test_create_firewall_rule_with_proto_any(self):
self._setup_create_firewall_rule_with_all_params(protocol='any') self._setup_create_firewall_rule_with_all_params(protocol='any')
def test_create_firewall_rule_with_IP_version_6(self):
self._setup_create_firewall_rule_with_all_params(ip_version='6')
def test_create_firewall_rule_with_invalid_IP_version(self):
self._setup_create_firewall_rule_with_all_params(ip_version='5')
def test_list_firewall_rules(self): def test_list_firewall_rules(self):
# firewall-rule-list. # firewall-rule-list.
resources = "firewall_rules" resources = "firewall_rules"