Merge "Allow security group rules to have their own group as a source"
This commit is contained in:
commit
76246c6b18
@ -97,8 +97,7 @@ class AddRule(forms.SelfHandlingForm):
|
|||||||
current_group_id = initials.get('security_group_id', 0)
|
current_group_id = initials.get('security_group_id', 0)
|
||||||
security_groups = initials.get('security_group_list', [])
|
security_groups = initials.get('security_group_list', [])
|
||||||
security_groups_choices = [("", "CIDR")] # default choice is CIDR
|
security_groups_choices = [("", "CIDR")] # default choice is CIDR
|
||||||
group_choices = [s for s in security_groups
|
group_choices = [s for s in security_groups]
|
||||||
if str(s[0]) != current_group_id]
|
|
||||||
if len(group_choices): # add group choice if available
|
if len(group_choices): # add group choice if available
|
||||||
security_groups_choices.append(('Security Group', group_choices))
|
security_groups_choices.append(('Security Group', group_choices))
|
||||||
self.fields['source_group'].choices = security_groups_choices
|
self.fields['source_group'].choices = security_groups_choices
|
||||||
|
@ -179,6 +179,34 @@ class SecurityGroupsViewTests(test.TestCase):
|
|||||||
msg = 'Either CIDR or Source Group may be specified, but not both.'
|
msg = 'Either CIDR or Source Group may be specified, but not both.'
|
||||||
self.assertFormErrors(res, count=1, message=msg)
|
self.assertFormErrors(res, count=1, message=msg)
|
||||||
|
|
||||||
|
def test_edit_rules_add_rule_self_as_source_group(self):
|
||||||
|
sec_group = self.security_groups.first()
|
||||||
|
sec_group_list = self.security_groups.list()
|
||||||
|
rule = self.security_group_rules.get(id=3)
|
||||||
|
|
||||||
|
self.mox.StubOutWithMock(api, 'security_group_rule_create')
|
||||||
|
self.mox.StubOutWithMock(api, 'security_group_list')
|
||||||
|
api.security_group_rule_create(IsA(http.HttpRequest),
|
||||||
|
sec_group.id,
|
||||||
|
rule.ip_protocol,
|
||||||
|
int(rule.from_port),
|
||||||
|
int(rule.to_port),
|
||||||
|
None,
|
||||||
|
u'%s' % sec_group.id).AndReturn(rule)
|
||||||
|
api.security_group_list(
|
||||||
|
IsA(http.HttpRequest)).AndReturn(sec_group_list)
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
formData = {'method': 'AddRule',
|
||||||
|
'security_group_id': sec_group.id,
|
||||||
|
'from_port': rule.from_port,
|
||||||
|
'to_port': rule.to_port,
|
||||||
|
'ip_protocol': rule.ip_protocol,
|
||||||
|
'cidr': '0.0.0.0/0',
|
||||||
|
'source_group': sec_group.id}
|
||||||
|
res = self.client.post(self.edit_url, formData)
|
||||||
|
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||||
|
|
||||||
def test_edit_rules_invalid_port_range(self):
|
def test_edit_rules_invalid_port_range(self):
|
||||||
sec_group = self.security_groups.first()
|
sec_group = self.security_groups.first()
|
||||||
sec_group_list = self.security_groups.list()
|
sec_group_list = self.security_groups.list()
|
||||||
|
@ -229,12 +229,24 @@ def data(TEST):
|
|||||||
'to_port': u"5",
|
'to_port': u"5",
|
||||||
'parent_group_id': 1,
|
'parent_group_id': 1,
|
||||||
'ip_range': {'cidr': u"0.0.0.0/32"}}
|
'ip_range': {'cidr': u"0.0.0.0/32"}}
|
||||||
|
|
||||||
|
group_rule = {'id': 3,
|
||||||
|
'ip_protocol': u"tcp",
|
||||||
|
'from_port': u"80",
|
||||||
|
'to_port': u"80",
|
||||||
|
'parent_group_id': 1,
|
||||||
|
'source_group_id': 1}
|
||||||
|
|
||||||
rule_obj = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
|
rule_obj = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
|
||||||
rule)
|
rule)
|
||||||
rule_obj2 = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
|
rule_obj2 = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
|
||||||
icmp_rule)
|
icmp_rule)
|
||||||
|
rule_obj3 = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
|
||||||
|
group_rule)
|
||||||
|
|
||||||
TEST.security_group_rules.add(rule_obj)
|
TEST.security_group_rules.add(rule_obj)
|
||||||
TEST.security_group_rules.add(rule_obj2)
|
TEST.security_group_rules.add(rule_obj2)
|
||||||
|
TEST.security_group_rules.add(rule_obj3)
|
||||||
|
|
||||||
sec_group_1.rules = [rule_obj]
|
sec_group_1.rules = [rule_obj]
|
||||||
sec_group_2.rules = [rule_obj]
|
sec_group_2.rules = [rule_obj]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user