Merge lp:~jaypipes/nova/nova-virt-connection into lp:~hudson-openstack/nova/trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Eric Day
Approved revision: 219
Merged at revision: 261
Proposed branch: lp:~jaypipes/nova/nova-virt-connection
Merge into: lp:~hudson-openstack/nova/trunk
Prerequisite: lp:~jaypipes/nova/pylint
Diff against target: 230 lines (+63/-26)
2 files modified
nova/tests/api_unittest.py (+58/-25)
nova/virt/connection.py (+5/-1)
To merge this branch: bzr merge lp:~jaypipes/nova/nova-virt-connection
Reviewer Review Type Date Requested Status
Vish Ishaya (community) Approve
Review via email: mp+32208@code.launchpad.net

Description of the change

pylint fixes for /nova/virt/connection.py

To post a comment you must log in.
Revision history for this message
Vish Ishaya (vishvananda) wrote :
Download full text (9.6 KiB)

Not a huge deal, but pylint gives me a deprecation warning on disable-msg,
and says to use disable instead.

Vish

On Tue, Aug 10, 2010 at 7:26 AM, Jay Pipes <email address hidden> wrote:

> Jay Pipes has proposed merging lp:~jaypipes/nova/nova-virt-connection into
> lp:nova with lp:~jaypipes/nova/pylint as a prerequisite.
>
> Requested reviews:
> Nova Core (nova-core)
>
>
> pylint fixes for /nova/virt/connection.py
> --
> https://code.launchpad.net/~jaypipes/nova/nova-virt-connection/+merge/32208
> Your team Nova Core is requested to review the proposed merge of
> lp:~jaypipes/nova/nova-virt-connection into lp:nova.
>
> === modified file 'nova/tests/api_unittest.py'
> --- nova/tests/api_unittest.py 2010-07-27 04:07:28 +0000
> +++ nova/tests/api_unittest.py 2010-08-10 14:25:59 +0000
> @@ -16,6 +16,8 @@
> # License for the specific language governing permissions and
> limitations
> # under the License.
>
> +"""Unit tests for the API endpoint"""
> +
> import boto
> from boto.ec2 import regioninfo
> import httplib
> @@ -38,7 +40,15 @@
> # circuit boto calls and feed them into our tornado
> handlers,
> # it's pretty damn circuitous so apologies if you have to
> fix
> # a bug in it
> -def boto_to_tornado(method, path, headers, data, host, connection=None):
> +# NOTE(jaypipes) The pylint disables here are for R0913 (too many args)
> which
> +# isn't controllable since boto's HTTPRequest needs that
> many
> +# args, and for the version-differentiated import of
> tornado's
> +# httputil.
> +# NOTE(jaypipes): The disable-msg=E1101 and E1103 below is because pylint
> is
> +# unable to introspect the deferred's return value
> properly
> +
> +def boto_to_tornado(method, path, headers, data, # pylint:
> disable-msg=R0913
> + host, connection=None):
> """ translate boto requests into tornado requests
>
> connection should be a FakeTornadoHttpConnection instance
> @@ -46,7 +56,7 @@
> try:
> headers = httpserver.HTTPHeaders()
> except AttributeError:
> - from tornado import httputil
> + from tornado import httputil # pylint: disable-msg=E0611
> headers = httputil.HTTPHeaders()
> for k, v in headers.iteritems():
> headers[k] = v
> @@ -61,57 +71,64 @@
> return req
>
>
> -def raw_to_httpresponse(s):
> - """ translate a raw tornado http response into an httplib.HTTPResponse
> """
> - sock = FakeHttplibSocket(s)
> +def raw_to_httpresponse(response_string):
> + """translate a raw tornado http response into an
> httplib.HTTPResponse"""
> + sock = FakeHttplibSocket(response_string)
> resp = httplib.HTTPResponse(sock)
> resp.begin()
> return resp
>
>
> class FakeHttplibSocket(object):
> - """ a fake socket implementation for httplib.HTTPResponse, trivial """
> - def __init__(self, s):
> - self.fp = StringIO.StringIO(s)
> + """a fake socket implementation for httplib.HTTPResponse, trivial"""
> + def __init__(self, response_string):
> + self._buffer = StringIO.StringIO(response_string)
>
> - def makefile(self, mode, othe...

Read more...

Revision history for this message
Vish Ishaya (vishvananda) wrote :

lgtm, regardless

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

Must be a pylint version thing...I don't see the deprecation warning. Do you get it only on the block-level disable-msg at the top of the file? or all the disable-msg locations?

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Attempt to merge lp:~jaypipes/nova/nova-virt-connection into lp:nova failed due to merge conflicts:

text conflict in nova/virt/connection.py

Revision history for this message
Jay Pipes (jaypipes) wrote :

Conflicts resolved...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/tests/api_unittest.py'
--- nova/tests/api_unittest.py 2010-07-27 04:07:28 +0000
+++ nova/tests/api_unittest.py 2010-08-30 13:27:43 +0000
@@ -16,6 +16,8 @@
16# License for the specific language governing permissions and limitations16# License for the specific language governing permissions and limitations
17# under the License.17# under the License.
1818
19"""Unit tests for the API endpoint"""
20
19import boto21import boto
20from boto.ec2 import regioninfo22from boto.ec2 import regioninfo
21import httplib23import httplib
@@ -38,7 +40,15 @@
38# circuit boto calls and feed them into our tornado handlers,40# circuit boto calls and feed them into our tornado handlers,
39# it's pretty damn circuitous so apologies if you have to fix41# it's pretty damn circuitous so apologies if you have to fix
40# a bug in it42# a bug in it
41def boto_to_tornado(method, path, headers, data, host, connection=None):43# NOTE(jaypipes) The pylint disables here are for R0913 (too many args) which
44# isn't controllable since boto's HTTPRequest needs that many
45# args, and for the version-differentiated import of tornado's
46# httputil.
47# NOTE(jaypipes): The disable-msg=E1101 and E1103 below is because pylint is
48# unable to introspect the deferred's return value properly
49
50def boto_to_tornado(method, path, headers, data, # pylint: disable-msg=R0913
51 host, connection=None):
42 """ translate boto requests into tornado requests52 """ translate boto requests into tornado requests
4353
44 connection should be a FakeTornadoHttpConnection instance54 connection should be a FakeTornadoHttpConnection instance
@@ -46,7 +56,7 @@
46 try:56 try:
47 headers = httpserver.HTTPHeaders()57 headers = httpserver.HTTPHeaders()
48 except AttributeError:58 except AttributeError:
49 from tornado import httputil59 from tornado import httputil # pylint: disable-msg=E0611
50 headers = httputil.HTTPHeaders()60 headers = httputil.HTTPHeaders()
51 for k, v in headers.iteritems():61 for k, v in headers.iteritems():
52 headers[k] = v62 headers[k] = v
@@ -61,57 +71,64 @@
61 return req71 return req
6272
6373
64def raw_to_httpresponse(s):74def raw_to_httpresponse(response_string):
65 """ translate a raw tornado http response into an httplib.HTTPResponse """75 """translate a raw tornado http response into an httplib.HTTPResponse"""
66 sock = FakeHttplibSocket(s)76 sock = FakeHttplibSocket(response_string)
67 resp = httplib.HTTPResponse(sock)77 resp = httplib.HTTPResponse(sock)
68 resp.begin()78 resp.begin()
69 return resp79 return resp
7080
7181
72class FakeHttplibSocket(object):82class FakeHttplibSocket(object):
73 """ a fake socket implementation for httplib.HTTPResponse, trivial """83 """a fake socket implementation for httplib.HTTPResponse, trivial"""
74 def __init__(self, s):84 def __init__(self, response_string):
75 self.fp = StringIO.StringIO(s)85 self._buffer = StringIO.StringIO(response_string)
7686
77 def makefile(self, mode, other):87 def makefile(self, _mode, _other):
78 return self.fp88 """Returns the socket's internal buffer"""
89 return self._buffer
7990
8091
81class FakeTornadoStream(object):92class FakeTornadoStream(object):
82 """ a fake stream to satisfy tornado's assumptions, trivial """93 """a fake stream to satisfy tornado's assumptions, trivial"""
83 def set_close_callback(self, f):94 def set_close_callback(self, _func):
95 """Dummy callback for stream"""
84 pass96 pass
8597
8698
87class FakeTornadoConnection(object):99class FakeTornadoConnection(object):
88 """ a fake connection object for tornado to pass to its handlers100 """A fake connection object for tornado to pass to its handlers
89101
90 web requests are expected to write to this as they get data and call102 web requests are expected to write to this as they get data and call
91 finish when they are done with the request, we buffer the writes and103 finish when they are done with the request, we buffer the writes and
92 kick off a callback when it is done so that we can feed the result back104 kick off a callback when it is done so that we can feed the result back
93 into boto.105 into boto.
94 """106 """
95 def __init__(self, d):107 def __init__(self, deferred):
96 self.d = d108 self._deferred = deferred
97 self._buffer = StringIO.StringIO()109 self._buffer = StringIO.StringIO()
98110
99 def write(self, chunk):111 def write(self, chunk):
112 """Writes a chunk of data to the internal buffer"""
100 self._buffer.write(chunk)113 self._buffer.write(chunk)
101114
102 def finish(self):115 def finish(self):
103 s = self._buffer.getvalue()116 """Finalizes the connection and returns the buffered data via the
104 self.d.callback(s)117 deferred callback.
118 """
119 data = self._buffer.getvalue()
120 self._deferred.callback(data)
105121
106 xheaders = None122 xheaders = None
107123
108 @property124 @property
109 def stream(self):125 def stream(self): # pylint: disable-msg=R0201
126 """Required property for interfacing with tornado"""
110 return FakeTornadoStream()127 return FakeTornadoStream()
111128
112129
113class FakeHttplibConnection(object):130class FakeHttplibConnection(object):
114 """ a fake httplib.HTTPConnection for boto to use131 """A fake httplib.HTTPConnection for boto to use
115132
116 requests made via this connection actually get translated and routed into133 requests made via this connection actually get translated and routed into
117 our tornado app, we then wait for the response and turn it back into134 our tornado app, we then wait for the response and turn it back into
@@ -123,7 +140,9 @@
123 self.deferred = defer.Deferred()140 self.deferred = defer.Deferred()
124141
125 def request(self, method, path, data, headers):142 def request(self, method, path, data, headers):
126 req = boto_to_tornado143 """Creates a connection to a fake tornado and sets
144 up a deferred request with the supplied data and
145 headers"""
127 conn = FakeTornadoConnection(self.deferred)146 conn = FakeTornadoConnection(self.deferred)
128 request = boto_to_tornado(connection=conn,147 request = boto_to_tornado(connection=conn,
129 method=method,148 method=method,
@@ -131,12 +150,16 @@
131 headers=headers,150 headers=headers,
132 data=data,151 data=data,
133 host=self.host)152 host=self.host)
134 handler = self.app(request)153 self.app(request)
135 self.deferred.addCallback(raw_to_httpresponse)154 self.deferred.addCallback(raw_to_httpresponse)
136155
137 def getresponse(self):156 def getresponse(self):
157 """A bit of deferred magic for catching the response
158 from the previously deferred request"""
138 @defer.inlineCallbacks159 @defer.inlineCallbacks
139 def _waiter():160 def _waiter():
161 """Callback that simply yields the deferred's
162 return value."""
140 result = yield self.deferred163 result = yield self.deferred
141 defer.returnValue(result)164 defer.returnValue(result)
142 d = _waiter()165 d = _waiter()
@@ -144,14 +167,16 @@
144 # this deferred has already been called by the time167 # this deferred has already been called by the time
145 # we get here, we are going to cheat and return168 # we get here, we are going to cheat and return
146 # the result of the callback169 # the result of the callback
147 return d.result170 return d.result # pylint: disable-msg=E1101
148171
149 def close(self):172 def close(self):
173 """Required for compatibility with boto/tornado"""
150 pass174 pass
151175
152176
153class ApiEc2TestCase(test.BaseTestCase):177class ApiEc2TestCase(test.BaseTestCase):
154 def setUp(self):178 """Unit test for the cloud controller on an EC2 API"""
179 def setUp(self): # pylint: disable-msg=C0103,C0111
155 super(ApiEc2TestCase, self).setUp()180 super(ApiEc2TestCase, self).setUp()
156181
157 self.manager = manager.AuthManager()182 self.manager = manager.AuthManager()
@@ -171,12 +196,16 @@
171 self.mox.StubOutWithMock(self.ec2, 'new_http_connection')196 self.mox.StubOutWithMock(self.ec2, 'new_http_connection')
172197
173 def expect_http(self, host=None, is_secure=False):198 def expect_http(self, host=None, is_secure=False):
199 """Returns a new EC2 connection"""
174 http = FakeHttplibConnection(200 http = FakeHttplibConnection(
175 self.app, '%s:%d' % (self.host, FLAGS.cc_port), False)201 self.app, '%s:%d' % (self.host, FLAGS.cc_port), False)
202 # pylint: disable-msg=E1103
176 self.ec2.new_http_connection(host, is_secure).AndReturn(http)203 self.ec2.new_http_connection(host, is_secure).AndReturn(http)
177 return http204 return http
178205
179 def test_describe_instances(self):206 def test_describe_instances(self):
207 """Test that, after creating a user and a project, the describe
208 instances call to the API works properly"""
180 self.expect_http()209 self.expect_http()
181 self.mox.ReplayAll()210 self.mox.ReplayAll()
182 user = self.manager.create_user('fake', 'fake', 'fake')211 user = self.manager.create_user('fake', 'fake', 'fake')
@@ -187,14 +216,18 @@
187216
188217
189 def test_get_all_key_pairs(self):218 def test_get_all_key_pairs(self):
219 """Test that, after creating a user and project and generating
220 a key pair, that the API call to list key pairs works properly"""
190 self.expect_http()221 self.expect_http()
191 self.mox.ReplayAll()222 self.mox.ReplayAll()
192 keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") for x in range(random.randint(4, 8)))223 keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") \
224 for x in range(random.randint(4, 8)))
193 user = self.manager.create_user('fake', 'fake', 'fake')225 user = self.manager.create_user('fake', 'fake', 'fake')
194 project = self.manager.create_project('fake', 'fake', 'fake')226 project = self.manager.create_project('fake', 'fake', 'fake')
195 self.manager.generate_key_pair(user.id, keyname)227 self.manager.generate_key_pair(user.id, keyname)
196228
197 rv = self.ec2.get_all_key_pairs()229 rv = self.ec2.get_all_key_pairs()
198 self.assertTrue(filter(lambda k: k.name == keyname, rv))230 results = [k for k in rv if k.name == keyname]
231 self.assertEquals(len(results), 1)
199 self.manager.delete_project(project)232 self.manager.delete_project(project)
200 self.manager.delete_user(user)233 self.manager.delete_user(user)
201234
=== modified file 'nova/virt/connection.py'
--- nova/virt/connection.py 2010-08-13 10:51:33 +0000
+++ nova/virt/connection.py 2010-08-30 13:27:43 +0000
@@ -17,6 +17,11 @@
17# License for the specific language governing permissions and limitations17# License for the specific language governing permissions and limitations
18# under the License.18# under the License.
1919
20"""Abstraction of the underlying virtualization API"""
21
22import logging
23import sys
24
20from nova import flags25from nova import flags
21from nova.virt import fake26from nova.virt import fake
22from nova.virt import libvirt_conn27from nova.virt import libvirt_conn
@@ -35,7 +40,6 @@
35 Any object returned here must conform to the interface documented by40 Any object returned here must conform to the interface documented by
36 FakeConnection.41 FakeConnection.
37 """42 """
38
39 # TODO(termie): maybe lazy load after initial check for permissions43 # TODO(termie): maybe lazy load after initial check for permissions
40 # TODO(termie): check whether we can be disconnected44 # TODO(termie): check whether we can be disconnected
41 t = FLAGS.connection_type45 t = FLAGS.connection_type