Merge lp:~hazmat/txaws/fix-s3-port-and-bucket-op into lp:txaws

Proposed by Kapil Thangavelu
Status: Merged
Merged at revision: 99
Proposed branch: lp:~hazmat/txaws/fix-s3-port-and-bucket-op
Merge into: lp:txaws
Prerequisite: lp:~clint-fewbar/txaws/fix-s3-port
Diff against target: 143 lines (+85/-3)
5 files modified
txaws/ec2/client.py (+13/-2)
txaws/ec2/tests/test_client.py (+32/-0)
txaws/s3/client.py (+2/-0)
txaws/s3/tests/test_client.py (+1/-1)
txaws/testing/payload.py (+37/-0)
To merge this branch: bzr merge lp:~hazmat/txaws/fix-s3-port-and-bucket-op
Reviewer Review Type Date Requested Status
Thomas Herve Approve
Review via email: mp+73293@code.launchpad.net

Description of the change

This builds on clint's s3-port-fix branch to solve two other openstack compatibility issues.

- Bucket/collection operations need to have the bucket urls with a '/' appended. Confirmed this also done by boto.

- Security group descriptions may omit port information. This is a workaround for nova bug: 829609.
  This change revents txaws from blowing up an trying to turn a None value into an integer.

To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :

Looks good, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txaws/ec2/client.py'
2--- txaws/ec2/client.py 2011-05-12 14:48:26 +0000
3+++ txaws/ec2/client.py 2011-08-29 20:27:23 +0000
4@@ -658,9 +658,20 @@
5 if ip_permissions is None:
6 ip_permissions = ()
7 for ip_permission in ip_permissions:
8+
9+ # openstack doesn't handle self authorized groups properly
10+ # XXX this is an upstream problem and should be addressed there
11+ # lp bug #829609
12 ip_protocol = ip_permission.findtext("ipProtocol")
13- from_port = int(ip_permission.findtext("fromPort"))
14- to_port = int(ip_permission.findtext("toPort"))
15+ from_port = ip_permission.findtext("fromPort")
16+ to_port = ip_permission.findtext("toPort")
17+
18+ if from_port:
19+ from_port = int(from_port)
20+
21+ if to_port:
22+ to_port = int(to_port)
23+
24 for groups in ip_permission.findall("groups/item") or ():
25 user_id = groups.findtext("userId")
26 group_name = groups.findtext("groupName")
27
28=== modified file 'txaws/ec2/tests/test_client.py'
29--- txaws/ec2/tests/test_client.py 2011-05-12 14:38:37 +0000
30+++ txaws/ec2/tests/test_client.py 2011-08-29 20:27:23 +0000
31@@ -522,6 +522,38 @@
32 d = ec2.describe_security_groups("WebServers")
33 return d.addCallback(check_result)
34
35+ def test_describe_security_groups_with_openstack(self):
36+ """
37+ L{EC2Client.describe_security_groups} can work with openstack
38+ responses, which may lack proper port information for
39+ self-referencing group. Verifying that the response doesn't
40+ cause an internal error, workaround for nova launchpad bug
41+ #829609.
42+ """
43+ class StubQuery(object):
44+
45+ def __init__(stub, action="", creds=None, endpoint=None,
46+ other_params={}):
47+ self.assertEqual(action, "DescribeSecurityGroups")
48+ self.assertEqual(creds.access_key, "foo")
49+ self.assertEqual(creds.secret_key, "bar")
50+ self.assertEqual(other_params, {"GroupName.1": "WebServers"})
51+
52+ def submit(self):
53+ return succeed(
54+ payload.sample_describe_security_groups_with_openstack)
55+
56+ def check_result(security_groups):
57+ [security_group] = security_groups
58+ self.assertEquals(security_group.name, "WebServers")
59+ self.assertEqual(
60+ security_group.allowed_groups[0].group_name, "WebServers")
61+
62+ creds = AWSCredentials("foo", "bar")
63+ ec2 = client.EC2Client(creds, query_factory=StubQuery)
64+ d = ec2.describe_security_groups("WebServers")
65+ return d.addCallback(check_result)
66+
67 def test_create_security_group(self):
68 """
69 L{EC2Client.create_security_group} returns a C{Deferred} that
70
71=== modified file 'txaws/s3/client.py'
72--- txaws/s3/client.py 2011-08-29 20:27:23 +0000
73+++ txaws/s3/client.py 2011-08-29 20:27:23 +0000
74@@ -54,6 +54,8 @@
75 if not self.object_name.startswith("/"):
76 path += "/"
77 path += self.object_name
78+ elif self.bucket is not None and not path.endswith("/"):
79+ path += "/"
80 return path
81
82 def get_url(self):
83
84=== modified file 'txaws/s3/tests/test_client.py'
85--- txaws/s3/tests/test_client.py 2011-08-29 20:27:23 +0000
86+++ txaws/s3/tests/test_client.py 2011-08-29 20:27:23 +0000
87@@ -34,7 +34,7 @@
88
89 def test_get_path_with_bucket(self):
90 url_context = client.URLContext(self.endpoint, bucket="mystuff")
91- self.assertEquals(url_context.get_path(), "/mystuff")
92+ self.assertEquals(url_context.get_path(), "/mystuff/")
93
94 def test_get_path_with_bucket_and_object(self):
95 url_context = client.URLContext(
96
97=== modified file 'txaws/testing/payload.py'
98--- txaws/testing/payload.py 2011-03-26 12:40:36 +0000
99+++ txaws/testing/payload.py 2011-08-29 20:27:23 +0000
100@@ -178,6 +178,43 @@
101 """ % (version.ec2_api,)
102
103
104+sample_describe_security_groups_with_openstack = """\
105+<?xml version="1.0"?>
106+<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/%s/">
107+ <requestId>7d4e4dbd-0a33-4d3a-864a-b5ce0f1c9cbf</requestId>
108+ <securityGroupInfo>
109+ <item>
110+ <ipPermissions>
111+ <item>
112+ <toPort>22</toPort>
113+ <ipProtocol>tcp</ipProtocol>
114+ <ipRanges>
115+ <item><cidrIp>0.0.0.0/0</cidrIp></item>
116+ </ipRanges>
117+ <groups/>
118+ <fromPort>22</fromPort>
119+ </item>
120+ <item>
121+ <toPort/>
122+ <ipProtocol/>
123+ <ipRanges/>
124+ <groups>
125+ <item>
126+ <groupName>WebServers</groupName>
127+ <userId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</userId>
128+ </item>
129+ </groups>
130+ <fromPort/>
131+ </item>
132+ </ipPermissions>
133+ <groupName>WebServers</groupName>
134+ <groupDescription>Web servers</groupDescription>
135+ <ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
136+ </item>
137+ </securityGroupInfo>
138+</DescribeSecurityGroupsResponse>
139+""" % (version.ec2_api,)
140+
141 sample_describe_security_groups_result = """\
142 <?xml version="1.0"?>
143 <DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/%s/">

Subscribers

People subscribed via source and target branches