Fix create call for security group rules
Reasons: - The security group rule create call was expecting from_port, to_port, and protocol as arguments, but the Trove API was ignoring these since it picks these up from the respective datastore confs. Changes: - Removing the extra arguments from the security-group-rule create command: - from_port - to_port - protocol Note that even though the user was able to specify the ports for the rule these were _never_ being honored since these were being picked up from the respective config files. Usage before change: - trove secgroup-add-rule <security_group> <protocol> <from_port> <to_port> <cidr> Usage after change: - trove secgroup-add-rule <security_group> <cidr> Change-Id: Ic1440f735b6cf2b8b4f29c5ab9f48bcb427ca9e6 Closes-Bug: #1298749
This commit is contained in:
parent
5b713c009b
commit
b9507417fe
|
@ -82,32 +82,28 @@ class SecGroupRuleTest(testtools.TestCase):
|
|||
self.security_group_rule.from_port = 80
|
||||
self.security_group_rule.to_port = 80
|
||||
self.security_group_rule.cidr = "0.0.0.0//0"
|
||||
representation = \
|
||||
"<SecurityGroupRule: ( \
|
||||
Security Group id: %d, \
|
||||
Protocol: %s, \
|
||||
From_Port: %d, \
|
||||
To_Port: %d, \
|
||||
CIDR: %s )>" % (1, "tcp", 80, 80, "0.0.0.0//0")
|
||||
representation = (
|
||||
"<SecurityGroupRule: "
|
||||
"( Security Group id: %d, "
|
||||
"Protocol: %s, From_Port: %d, "
|
||||
"To_Port: %d, CIDR: %s )>"
|
||||
% (1, "tcp", 80, 80, "0.0.0.0//0")
|
||||
)
|
||||
|
||||
self.assertEqual(representation,
|
||||
self.security_group_rule.__repr__())
|
||||
|
||||
def test_create(self):
|
||||
def side_effect_func(path, body, inst):
|
||||
def side_effect_func(path, body, inst, return_raw=True):
|
||||
return path, body, inst
|
||||
|
||||
self.security_group_rules._create = mock.Mock(
|
||||
side_effect=side_effect_func
|
||||
)
|
||||
p, b, i = self.security_group_rules.create(1, "tcp",
|
||||
80, 80, "0.0.0.0//0")
|
||||
p, b, i = self.security_group_rules.create(1, "0.0.0.0//0")
|
||||
self.assertEqual("/security-group-rules", p)
|
||||
self.assertEqual("security_group_rule", i)
|
||||
self.assertEqual(1, b["security_group_rule"]["group_id"])
|
||||
self.assertEqual("tcp", b["security_group_rule"]["protocol"])
|
||||
self.assertEqual(80, b["security_group_rule"]["from_port"])
|
||||
self.assertEqual(80, b["security_group_rule"]["to_port"])
|
||||
self.assertEqual("0.0.0.0//0", b["security_group_rule"]["cidr"])
|
||||
|
||||
def test_delete(self):
|
||||
|
|
|
@ -138,7 +138,7 @@ def _print(pt, order):
|
|||
print(strutils.safe_encode(pt.get_string(sortby=order)))
|
||||
|
||||
|
||||
def print_list(objs, fields, formatters={}, order_by=None):
|
||||
def print_list(objs, fields, formatters={}, order_by=None, obj_is_dict=False):
|
||||
try:
|
||||
_output_override(objs, 'list')
|
||||
return
|
||||
|
@ -158,7 +158,10 @@ def print_list(objs, fields, formatters={}, order_by=None):
|
|||
field_name = field.replace(' ', '_')
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
if not obj_is_dict:
|
||||
data = getattr(o, field_name, '')
|
||||
else:
|
||||
data = o.get(field_name, '')
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class SecurityGroup(base.Resource):
|
|||
"""
|
||||
Security Group is a resource used to hold security group information.
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
return "<SecurityGroup: %s>" % self.name
|
||||
|
||||
|
@ -57,15 +58,14 @@ class SecurityGroupRule(base.Resource):
|
|||
Security Group Rule is a resource used to hold security group
|
||||
rule related information.
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
return \
|
||||
"<SecurityGroupRule: ( \
|
||||
Security Group id: %d, \
|
||||
Protocol: %s, \
|
||||
From_Port: %d, \
|
||||
To_Port: %d, \
|
||||
CIDR: %s )>" % (self.group_id, self.protocol, self.from_port,
|
||||
self.to_port, self.cidr)
|
||||
return ("<SecurityGroupRule: "
|
||||
"( Security Group id: %d, "
|
||||
"Protocol: %s, From_Port: %d, "
|
||||
"To_Port: %d, CIDR: %s )>"
|
||||
% (self.group_id, self.protocol,
|
||||
self.from_port, self.to_port, self.cidr))
|
||||
|
||||
|
||||
class SecurityGroupRules(base.ManagerWithFind):
|
||||
|
@ -74,19 +74,16 @@ class SecurityGroupRules(base.ManagerWithFind):
|
|||
"""
|
||||
resource_class = SecurityGroupRule
|
||||
|
||||
def create(self, group_id, protocol, from_port, to_port, cidr):
|
||||
def create(self, group_id, cidr):
|
||||
"""
|
||||
Create a new security group rule.
|
||||
"""
|
||||
body = {"security_group_rule": {
|
||||
"group_id": group_id,
|
||||
"protocol": protocol,
|
||||
"from_port": from_port,
|
||||
"to_port": to_port,
|
||||
"cidr": cidr
|
||||
}}
|
||||
return self._create("/security-group-rules", body,
|
||||
"security_group_rule")
|
||||
"security_group_rule", return_raw=True)
|
||||
|
||||
def delete(self, security_group_rule):
|
||||
"""
|
||||
|
|
|
@ -569,22 +569,16 @@ def do_secgroup_show(cs, args):
|
|||
|
||||
@utils.arg('security_group', metavar='<security_group>',
|
||||
help='Security group name.')
|
||||
@utils.arg('protocol', metavar='<protocol>',
|
||||
help='IP protocol (icmp, tcp, udp).')
|
||||
@utils.arg('from_port', metavar='<from_port>',
|
||||
help='Port at start of range.')
|
||||
@utils.arg('to_port', metavar='<to_port>', help='Port at end of range.')
|
||||
@utils.arg('cidr', metavar='<cidr>', help='CIDR address.')
|
||||
@utils.service_type('database')
|
||||
def do_secgroup_add_rule(cs, args):
|
||||
"""Creates a security group rule."""
|
||||
rule = cs.security_group_rules.create(args.security_group,
|
||||
args.protocol,
|
||||
args.from_port,
|
||||
args.to_port,
|
||||
args.cidr)
|
||||
rules = cs.security_group_rules.create(
|
||||
args.security_group, args.cidr)
|
||||
|
||||
_print_instance(rule)
|
||||
utils.print_list(rules, [
|
||||
'id', 'security_group_id', 'protocol',
|
||||
'from_port', 'to_port', 'cidr', 'created'], obj_is_dict=True)
|
||||
|
||||
|
||||
@utils.arg('security_group_rule', metavar='<security_group_rule>',
|
||||
|
|
Loading…
Reference in New Issue