Merge lp:~dreamhosters/txaws/921349-get-bucket-logging-method into lp:txaws

Proposed by Arsene Rei
Status: Merged
Merged at revision: 130
Proposed branch: lp:~dreamhosters/txaws/921349-get-bucket-logging-method
Merge into: lp:txaws
Diff against target: 198 lines (+150/-1)
4 files modified
txaws/s3/client.py (+20/-1)
txaws/s3/model.py (+8/-0)
txaws/s3/tests/test_client.py (+109/-0)
txaws/testing/payload.py (+13/-0)
To merge this branch: bzr merge lp:~dreamhosters/txaws/921349-get-bucket-logging-method
Reviewer Review Type Date Requested Status
Duncan McGreggor Needs Fixing
Review via email: mp+90540@code.launchpad.net

Description of the change

Add GET Bucket logging functionality.

To post a comment you must log in.
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

[1] So, it looks like you've used the wrong payload for this branch? You're getting Status from "VersioningConfiguration"...

The XML payload you're really going to be looking at is this one:

<?xml version="1.0" encoding="UTF-8"?>
<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01">
  <LoggingEnabled>
    <TargetBucket>mybucketlogs</TargetBucket>
    <TargetPrefix>mybucket-access_log-/</TargetPrefix>
    <TargetGrants>
      <Grant>
        <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:type="AmazonCustomerByEmail">
          <EmailAddress><email address hidden></EmailAddress>
        </Grantee>
        <Permission>READ</Permission>
      </Grant>
    </TargetGrants>
  </LoggingEnabled>
</BucketLoggingStatus>

Or this:

<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" />

The former (obviously) needing more modeling than just setting a status attribute ;-)

review: Needs Fixing
136. By Arsene Rei

change get bucket logging tests to correct versioning ones

I looked at the wrong bug when I first create the branch which led to me
call everything logging.

137. By Arsene Rei

make further modifications for logging to versioning

* LoggingStatus -> VersioningConfiguration
* Rename some testing methods
* Fix some tests

Revision history for this message
Arsene Rei (arsene-rei) wrote :

I think bzr/lp is smart and recognizes that this was merged as part of another set of commits. I had not taken the wrong payload. Rather, I had begun referencing the wrong bug! >.<

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txaws/s3/client.py'
2--- txaws/s3/client.py 2012-01-27 19:54:27 +0000
3+++ txaws/s3/client.py 2012-01-27 23:05:28 +0000
4@@ -23,7 +23,7 @@
5 from txaws.s3.model import (
6 Bucket, BucketItem, BucketListing, ItemOwner, LifecycleConfiguration,
7 LifecycleConfigurationRule, NotificationConfiguration, RequestPayment,
8- WebsiteConfiguration)
9+ VersioningConfiguration, WebsiteConfiguration)
10 from txaws.s3.exception import S3Error
11 from txaws.service import AWSServiceEndpoint, S3_ENDPOINT
12 from txaws.util import XML, calculate_md5
13@@ -253,6 +253,25 @@
14
15 return NotificationConfiguration(topic, event)
16
17+ def get_bucket_versioning_config(self, bucket):
18+ """
19+ Get the versioning configuration of a bucket.
20+
21+ @param bucket: The name of the bucket. @return: A C{Deferred} that
22+ will request the bucket's versioning configuration.
23+ """
24+ query = self.query_factory(
25+ action='GET', creds=self.creds, endpoint=self.endpoint,
26+ bucket=bucket, object_name='?versioning')
27+ return query.submit().addCallback(self._parse_versioning_config)
28+
29+ def _parse_versioning_config(self, xml_bytes):
30+ """Parse a C{VersioningConfiguration} XML document."""
31+ root = XML(xml_bytes)
32+ status = root.findtext("Status")
33+
34+ return VersioningConfiguration(status)
35+
36 def get_bucket_acl(self, bucket):
37 """
38 Get the access control policy for a bucket.
39
40=== modified file 'txaws/s3/model.py'
41--- txaws/s3/model.py 2012-01-27 19:47:22 +0000
42+++ txaws/s3/model.py 2012-01-27 23:05:28 +0000
43@@ -90,6 +90,14 @@
44 self.event = event
45
46
47+class VersioningConfiguration(object):
48+ """
49+ Container for the bucket versioning configuration.
50+ """
51+ def __init__(self, status=None):
52+ self.status = status
53+
54+
55 class FileChunk(object):
56 """
57 An Amazon S3 file chunk.
58
59=== modified file 'txaws/s3/tests/test_client.py'
60--- txaws/s3/tests/test_client.py 2012-01-27 20:44:11 +0000
61+++ txaws/s3/tests/test_client.py 2012-01-27 23:05:28 +0000
62@@ -462,6 +462,115 @@
63 d = s3.get_bucket_notification_config("mybucket")
64 return d.addCallback(check_results)
65
66+ def test_get_bucket_versioning_config(self):
67+ """
68+ L{S3Client.get_bucket_versioning_configuration} creates a L{Query} to
69+ get a bucket's versioning status. It parses the returned
70+ C{VersioningConfiguration} XML document and returns a C{Deferred} that
71+ requests the bucket's versioning configuration.
72+ """
73+
74+ class StubQuery(client.Query):
75+
76+ def __init__(query, action, creds, endpoint, bucket=None,
77+ object_name=None):
78+ super(StubQuery, query).__init__(action=action, creds=creds,
79+ bucket=bucket,
80+ object_name=object_name)
81+ self.assertEquals(action, "GET")
82+ self.assertEqual(creds.access_key, "foo")
83+ self.assertEqual(creds.secret_key, "bar")
84+ self.assertEqual(query.bucket, "mybucket")
85+ self.assertEqual(query.object_name, "?versioning")
86+ self.assertEqual(query.data, "")
87+ self.assertEqual(query.metadata, {})
88+ self.assertEqual(query.amz_headers, {})
89+
90+ def submit(query, url_context=None):
91+ return succeed(payload.sample_s3_get_bucket_versioning_result)
92+
93+ def check_results(versioning_config):
94+ self.assertEquals(versioning_config.status, None)
95+
96+ creds = AWSCredentials("foo", "bar")
97+ s3 = client.S3Client(creds, query_factory=StubQuery)
98+ d = s3.get_bucket_versioning_config("mybucket")
99+ return d.addCallback(check_results)
100+
101+ def test_get_bucket_versioning_config_enabled(self):
102+ """
103+ L{S3Client.get_bucket_versioning_config} creates a L{Query} to get a
104+ bucket's versioning configuration. It parses the returned
105+ C{VersioningConfiguration} XML document and returns a C{Deferred} that
106+ requests the bucket's versioning configuration that has a enabled
107+ status.
108+ """
109+
110+ class StubQuery(client.Query):
111+
112+ def __init__(query, action, creds, endpoint, bucket=None,
113+ object_name=None):
114+ super(StubQuery, query).__init__(action=action, creds=creds,
115+ bucket=bucket,
116+ object_name=object_name)
117+ self.assertEquals(action, "GET")
118+ self.assertEqual(creds.access_key, "foo")
119+ self.assertEqual(creds.secret_key, "bar")
120+ self.assertEqual(query.bucket, "mybucket")
121+ self.assertEqual(query.object_name, "?versioning")
122+ self.assertEqual(query.data, "")
123+ self.assertEqual(query.metadata, {})
124+ self.assertEqual(query.amz_headers, {})
125+
126+ def submit(query, url_context=None):
127+ return succeed(payload.
128+ sample_s3_get_bucket_versioning_enabled_result)
129+
130+ def check_results(versioning_config):
131+ self.assertEquals(versioning_config.status, 'Enabled')
132+
133+ creds = AWSCredentials("foo", "bar")
134+ s3 = client.S3Client(creds, query_factory=StubQuery)
135+ d = s3.get_bucket_versioning_config("mybucket")
136+ return d.addCallback(check_results)
137+
138+ def test_get_bucket_versioning_config_suspended(self):
139+ """
140+ L{S3Client.get_bucket_versioning_config} creates a L{Query} to get a
141+ bucket's versioning configuration. It parses the returned
142+ C{VersioningConfiguration} XML document and returns a C{Deferred} that
143+ requests the bucket's versioning configuration that has a suspended
144+ status.
145+ """
146+
147+ class StubQuery(client.Query):
148+
149+ def __init__(query, action, creds, endpoint, bucket=None,
150+ object_name=None):
151+ super(StubQuery, query).__init__(action=action, creds=creds,
152+ bucket=bucket,
153+ object_name=object_name)
154+ self.assertEquals(action, "GET")
155+ self.assertEqual(creds.access_key, "foo")
156+ self.assertEqual(creds.secret_key, "bar")
157+ self.assertEqual(query.bucket, "mybucket")
158+ self.assertEqual(query.object_name, "?versioning")
159+ self.assertEqual(query.data, "")
160+ self.assertEqual(query.metadata, {})
161+ self.assertEqual(query.amz_headers, {})
162+
163+ def submit(query, url_context=None):
164+ return succeed(payload.
165+ sample_s3_get_bucket_versioning_suspended_result)
166+
167+ def check_results(versioning_config):
168+ self.assertEquals(versioning_config.status, 'Suspended')
169+
170+ creds = AWSCredentials("foo", "bar")
171+ s3 = client.S3Client(creds, query_factory=StubQuery)
172+ d = s3.get_bucket_versioning_config("mybucket")
173+ return d.addCallback(check_results)
174+
175 def test_delete_bucket(self):
176
177 class StubQuery(client.Query):
178
179=== modified file 'txaws/testing/payload.py'
180--- txaws/testing/payload.py 2012-01-27 20:08:20 +0000
181+++ txaws/testing/payload.py 2012-01-27 23:05:28 +0000
182@@ -1071,3 +1071,16 @@
183 <Event>s3:ReducedRedundancyLostObject</Event>
184 </TopicConfiguration>
185 </NotificationConfiguration>"""
186+
187+sample_s3_get_bucket_versioning_result = """\
188+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"/>"""
189+
190+sample_s3_get_bucket_versioning_enabled_result = """\
191+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
192+ <Status>Enabled</Status>
193+</VersioningConfiguration>"""
194+
195+sample_s3_get_bucket_versioning_suspended_result = """\
196+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
197+ <Status>Suspended</Status>
198+</VersioningConfiguration>"""

Subscribers

People subscribed via source and target branches