Skip to content

Commit

Permalink
Only invoke .lower() on non-None protocols
Browse files Browse the repository at this point in the history
When using source group based security group rules (rather than CIDR
based ones), it's permissible to not set a protocol and port. However,
Nova would always try to convert the protocol to lower case, which would
fail if the protocol wasn't set.

Fixes bug 1010514

Change-Id: I9b1519a52ececd16a497acebfe022508cbe96126
  • Loading branch information
sorenisanerd authored and ttx committed Jun 11, 2012
1 parent f0a9f47 commit 3ee026e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<sandy.walsh@rackspace.com> <sandy@sandywalsh.com>
<sleepsonthefloor@gmail.com> <root@tonbuntu>
<soren.hansen@rackspace.com> <soren@linux2go.dk>
<soren@linux2go.dk> <sorhanse@cisco.com>
<throughnothing@gmail.com> <will.wolf@rackspace.com>
<tim.simpson@rackspace.com> <tim.simpson4@gmail.com>
<todd@ansolabs.com> <todd@lapex>
Expand Down
7 changes: 7 additions & 0 deletions nova/tests/test_libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,10 @@ def test_static_filters(self):
'to_port': 81,
'group_id': src_secgroup['id']})

db.security_group_rule_create(admin_ctxt,
{'parent_group_id': secgroup['id'],
'group_id': src_secgroup['id']})

db.instance_add_security_group(admin_ctxt, instance_ref['uuid'],
secgroup['id'])
db.instance_add_security_group(admin_ctxt, src_instance_ref['uuid'],
Expand Down Expand Up @@ -1798,6 +1802,9 @@ def fake_iptables_execute(*cmd, **kwargs):
'--dports 80:81 -s %s' % ip['address'])
self.assertTrue(len(filter(regex.match, self.out_rules)) > 0,
"TCP port 80/81 acceptance rule wasn't added")
regex = re.compile('-A .* -j ACCEPT -s %s' % ip['address'])
self.assertTrue(len(filter(regex.match, self.out_rules)) > 0,
"Protocol/port-less acceptance rule wasn't added")

regex = re.compile('-A .* -j ACCEPT -p tcp '
'-m multiport --dports 80:81 -s 192.168.10.0/24')
Expand Down
6 changes: 5 additions & 1 deletion nova/virt/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ def instance_rules(self, instance, network_info):
else:
fw_rules = ipv6_rules

protocol = rule.protocol.lower()
protocol = rule.protocol

if protocol:
protocol = rule.protocol.lower()

if version == 6 and protocol == 'icmp':
protocol = 'icmpv6'

Expand Down

0 comments on commit 3ee026e

Please sign in to comment.