Merge "Allow security group rules to have their own group as a source"

This commit is contained in:
Jenkins 2012-07-22 12:06:15 +00:00 committed by Gerrit Code Review
commit 76246c6b18
3 changed files with 41 additions and 2 deletions

View File

@ -97,8 +97,7 @@ class AddRule(forms.SelfHandlingForm):
current_group_id = initials.get('security_group_id', 0)
security_groups = initials.get('security_group_list', [])
security_groups_choices = [("", "CIDR")] # default choice is CIDR
group_choices = [s for s in security_groups
if str(s[0]) != current_group_id]
group_choices = [s for s in security_groups]
if len(group_choices): # add group choice if available
security_groups_choices.append(('Security Group', group_choices))
self.fields['source_group'].choices = security_groups_choices

View File

@ -179,6 +179,34 @@ class SecurityGroupsViewTests(test.TestCase):
msg = 'Either CIDR or Source Group may be specified, but not both.'
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):
sec_group = self.security_groups.first()
sec_group_list = self.security_groups.list()

View File

@ -229,12 +229,24 @@ def data(TEST):
'to_port': u"5",
'parent_group_id': 1,
'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)
rule_obj2 = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
icmp_rule)
rule_obj3 = rules.SecurityGroupRule(rules.SecurityGroupRuleManager(None),
group_rule)
TEST.security_group_rules.add(rule_obj)
TEST.security_group_rules.add(rule_obj2)
TEST.security_group_rules.add(rule_obj3)
sec_group_1.rules = [rule_obj]
sec_group_2.rules = [rule_obj]