Merge lp:~frankban/juju-quickstart/utopic-update-dependencies into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 98
Proposed branch: lp:~frankban/juju-quickstart/utopic-update-dependencies
Merge into: lp:juju-quickstart
Diff against target: 203 lines (+56/-30)
6 files modified
Makefile (+1/-1)
quickstart/juju.py (+22/-11)
quickstart/tests/helpers.py (+5/-2)
quickstart/tests/test_juju.py (+22/-10)
requirements.pip (+4/-4)
test-requirements.pip (+2/-2)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/utopic-update-dependencies
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+233770@code.launchpad.net

Description of the change

Updated quickstart dependencies for utopic.

Quickstart now uses the dependency versions we
expect to be available in utopic.

Update the code parts in which quickstart interacts
with the juju client and the websocket Python
libraries: ensure we only log the textual WebSocket
messages we are interested in.

Also remove the deprecated --use-mirrors pip option.

Tests: `make check`

QA:
Use quickstart as usual to bootstrap local, ec2 and HP
environments: `.venv/bin/python juju-quickstart -e ...`

https://codereview.appspot.com/139350043/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :
Download full text (8.8 KiB)

Reviewers: mp+233770_code.launchpad.net,

Message:
Please take a look.

Description:
Updated quickstart dependencies for utopic.

Quickstart now uses the dependency versions we
expect to be available in utopic.

Update the code parts in which quickstart interacts
with the juju client and the websocket Python
libraries: ensure we only log the textual WebSocket
messages we are interested in.

Also remove the deprecated --use-mirrors pip option.

Tests: `make check`

QA:
Use quickstart as usual to bootstrap local, ec2 and HP
environments: `.venv/bin/python juju-quickstart -e ...`

https://code.launchpad.net/~frankban/juju-quickstart/utopic-update-dependencies/+merge/233770

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/139350043/

Affected files (+58, -30 lines):
   M Makefile
   A [revision details]
   M quickstart/juju.py
   M quickstart/tests/helpers.py
   M quickstart/tests/test_juju.py
   M requirements.pip
   M test-requirements.pip

Index: Makefile
=== modified file 'Makefile'
--- Makefile 2014-04-07 09:03:11 +0000
+++ Makefile 2014-09-05 14:54:31 +0000
@@ -23,7 +23,7 @@

  $(VENV_ACTIVATE): test-requirements.pip requirements.pip
   virtualenv --distribute -p $(PYTHON) $(VENV)
- $(VENV)/bin/pip install --use-mirrors -r test-requirements.pip || \
+ $(VENV)/bin/pip install -r test-requirements.pip || \
    (touch test-requirements.pip; exit 1)
   @touch $(VENV_ACTIVATE)

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision:
<email address hidden>
+New revision:
<email address hidden>

Index: requirements.pip
=== modified file 'requirements.pip'
--- requirements.pip 2014-06-09 20:31:01 +0000
+++ requirements.pip 2014-09-05 14:54:31 +0000
@@ -25,7 +25,7 @@
  # version of websocket-client to use. Remove websocket-client as a
dependency
  # here when moving to a newer jujuclient that correctly specifies the
  # version.
-websocket-client==0.12.0
-jujuclient==0.17.5
-PyYAML==3.10
-urwid==1.1.1
+websocket-client==0.18.0
+jujuclient==0.18.4
+PyYAML==3.11
+urwid==1.2.1

Index: test-requirements.pip
=== modified file 'test-requirements.pip'
--- test-requirements.pip 2014-06-09 20:31:01 +0000
+++ test-requirements.pip 2014-09-05 14:54:31 +0000
@@ -17,7 +17,7 @@
  # along with this program. If not, see <http://www.gnu.org/licenses/>.

  coverage==3.7.1
-flake8==2.1.0
+flake8==2.2.3
  mock==1.0.1
-nose==1.3.1
+nose==1.3.4
  -r requirements.pip

Index: quickstart/juju.py
=== modified file 'quickstart/juju.py'
--- quickstart/juju.py 2014-06-03 20:39:11 +0000
+++ quickstart/juju.py 2014-09-08 17:49:51 +0000
@@ -19,16 +19,23 @@
  from __future__ import unicode_literals

  import logging
+import ssl

  import jujuclient
-import ssl
  import websocket

+OPCODE_TEXT = websocket.ABNF.OPCODE_TEXT
+# Define the options used to initiate the secure WebSocket connection.
+SSLOPT = {
+ 'cert_reqs': ssl.CERT_NONE,
+ 'ssl_version': ssl.PROTOCOL_TLSv1,
+}
+
+
  def connect(api_u...

Read more...

Revision history for this message
Richard Harding (rharding) wrote :
Revision history for this message
Jeff Pihach (hatch) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Updated quickstart dependencies for utopic.

Quickstart now uses the dependency versions we
expect to be available in utopic.

Update the code parts in which quickstart interacts
with the juju client and the websocket Python
libraries: ensure we only log the textual WebSocket
messages we are interested in.

Also remove the deprecated --use-mirrors pip option.

Tests: `make check`

QA:
Use quickstart as usual to bootstrap local, ec2 and HP
environments: `.venv/bin/python juju-quickstart -e ...`

R=rharding, jeff.pihach
CC=
https://codereview.appspot.com/139350043

https://codereview.appspot.com/139350043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2014-04-07 09:03:11 +0000
+++ Makefile 2014-09-08 18:10:40 +0000
@@ -23,7 +23,7 @@
2323
24$(VENV_ACTIVATE): test-requirements.pip requirements.pip24$(VENV_ACTIVATE): test-requirements.pip requirements.pip
25 virtualenv --distribute -p $(PYTHON) $(VENV)25 virtualenv --distribute -p $(PYTHON) $(VENV)
26 $(VENV)/bin/pip install --use-mirrors -r test-requirements.pip || \26 $(VENV)/bin/pip install -r test-requirements.pip || \
27 (touch test-requirements.pip; exit 1)27 (touch test-requirements.pip; exit 1)
28 @touch $(VENV_ACTIVATE)28 @touch $(VENV_ACTIVATE)
2929
3030
=== modified file 'quickstart/juju.py'
--- quickstart/juju.py 2014-06-03 20:39:11 +0000
+++ quickstart/juju.py 2014-09-08 18:10:40 +0000
@@ -19,16 +19,23 @@
19from __future__ import unicode_literals19from __future__ import unicode_literals
2020
21import logging21import logging
22import ssl
2223
23import jujuclient24import jujuclient
24import ssl
25import websocket25import websocket
2626
2727
28OPCODE_TEXT = websocket.ABNF.OPCODE_TEXT
29# Define the options used to initiate the secure WebSocket connection.
30SSLOPT = {
31 'cert_reqs': ssl.CERT_NONE,
32 'ssl_version': ssl.PROTOCOL_TLSv1,
33}
34
35
28def connect(api_url):36def connect(api_url):
29 """Return an Environment instance connected to the given API URL."""37 """Return an Environment instance connected to the given API URL."""
30 connection = WebSocketConnection(38 connection = WebSocketConnection(sslopt=SSLOPT)
31 sslopt={'ssl_version': ssl.PROTOCOL_TLSv1})
32 # See the websocket.create_connection function.39 # See the websocket.create_connection function.
33 connection.settimeout(websocket.default_timeout)40 connection.settimeout(websocket.default_timeout)
34 connection.connect(api_url, origin=api_url)41 connection.connect(api_url, origin=api_url)
@@ -124,19 +131,23 @@
124class WebSocketConnection(websocket.WebSocket):131class WebSocketConnection(websocket.WebSocket):
125 """A WebSocket client connection."""132 """A WebSocket client connection."""
126133
127 def send(self, message):134 def send(self, payload, opcode=OPCODE_TEXT):
128 """Send the given WebSocket message.135 """Send the given WebSocket message.
129136
130 Overridden to add logging.137 Overridden to add logging in the case the payload is text.
131 """138 """
132 logging.debug('API message: --> {}'.format(message.decode('utf-8')))139 if opcode == OPCODE_TEXT:
133 return super(WebSocketConnection, self).send(message)140 message = payload.decode('utf-8')
141 logging.debug('API message: --> {}'.format(message))
142 return super(WebSocketConnection, self).send(payload, opcode=opcode)
134143
135 def recv(self):144 def recv(self):
136 """Receive a message from the WebSocket server.145 """Receive a message from the WebSocket server.
137146
138 Overridden to add logging.147 Overridden to add logging in the case the received data is text.
139 """148 """
140 message = super(WebSocketConnection, self).recv()149 data = super(WebSocketConnection, self).recv()
141 logging.debug('API message: <-- {}'.format(message.decode('utf-8')))150 if isinstance(data, bytes):
142 return message151 message = data.decode('utf-8')
152 logging.debug('API message: <-- {}'.format(message))
153 return data
143154
=== modified file 'quickstart/tests/helpers.py'
--- quickstart/tests/helpers.py 2014-04-23 13:08:12 +0000
+++ quickstart/tests/helpers.py 2014-09-08 18:10:40 +0000
@@ -36,8 +36,11 @@
36 """36 """
37 with mock.patch('logging.{}'.format(level.lower())) as mock_log:37 with mock.patch('logging.{}'.format(level.lower())) as mock_log:
38 yield38 yield
39 expected_calls = [mock.call(message) for message in messages]39 if messages:
40 mock_log.assert_has_calls(expected_calls)40 expected_calls = [mock.call(message) for message in messages]
41 mock_log.assert_has_calls(expected_calls)
42 else:
43 assert not mock_log.called, 'logging unexpectedly called'
4144
4245
43class BundleFileTestsMixin(object):46class BundleFileTestsMixin(object):
4447
=== modified file 'quickstart/tests/test_juju.py'
--- quickstart/tests/test_juju.py 2014-06-03 19:10:21 +0000
+++ quickstart/tests/test_juju.py 2014-09-08 18:10:40 +0000
@@ -21,7 +21,6 @@
21import unittest21import unittest
2222
23import mock23import mock
24import ssl
25import websocket24import websocket
2625
27from quickstart import juju26from quickstart import juju
@@ -39,8 +38,7 @@
39 def test_environment_connection(self, mock_conn):38 def test_environment_connection(self, mock_conn):
40 # A connected Environment instance is correctly returned.39 # A connected Environment instance is correctly returned.
41 env = juju.connect(self.api_url)40 env = juju.connect(self.api_url)
42 mock_conn.assert_called_once_with(41 mock_conn.assert_called_once_with(sslopt=juju.SSLOPT)
43 sslopt={'ssl_version': ssl.PROTOCOL_TLSv1})
44 conn = mock_conn()42 conn = mock_conn()
45 conn.assert_has_calls([43 conn.assert_has_calls([
46 mock.call.settimeout(websocket.default_timeout),44 mock.call.settimeout(websocket.default_timeout),
@@ -65,7 +63,8 @@
65 api_url = self.api_url63 api_url = self.api_url
66 with mock.patch('websocket.create_connection') as mock_connect:64 with mock.patch('websocket.create_connection') as mock_connect:
67 self.env = juju.Environment(api_url)65 self.env = juju.Environment(api_url)
68 mock_connect.assert_called_once_with(api_url, origin=api_url)66 mock_connect.assert_called_once_with(
67 api_url, origin=api_url, sslopt=juju.SSLOPT)
69 # Keep track of watcher changes in the changesets list.68 # Keep track of watcher changes in the changesets list.
70 self.changesets = []69 self.changesets = []
7170
@@ -325,10 +324,9 @@
325 snowman = 'Here is a snowman\u00a1: \u2603'324 snowman = 'Here is a snowman\u00a1: \u2603'
326325
327 def setUp(self):326 def setUp(self):
328 with mock.patch('socket.socket') as mock_socket:327 self.conn = juju.WebSocketConnection()
329 self.conn = juju.WebSocketConnection()328 # The send method calls the send_frame one.
330 # Patch the socket.send() function used by the send method.329 self.conn.send_frame = self.mock_send = mock.Mock()
331 self.mock_send = mock_socket().send
332 # The recv method calls the recv_data one.330 # The recv method calls the recv_data one.
333 self.conn.recv_data = self.mock_recv = mock.Mock()331 self.conn.recv_data = self.mock_recv = mock.Mock()
334332
@@ -345,17 +343,31 @@
345 self.conn.send(self.snowman.encode('utf-8'))343 self.conn.send(self.snowman.encode('utf-8'))
346 self.assertTrue(self.mock_send.called)344 self.assertTrue(self.mock_send.called)
347345
346 def test_send_not_text(self):
347 # Outgoing non-textual messages are not logged.
348 with helpers.assert_logs([], 'debug'):
349 self.conn.send(0x0, opcode=websocket.ABNF.OPCODE_BINARY)
350 self.assertTrue(self.mock_send.called)
351
348 def test_recv(self):352 def test_recv(self):
349 # Incoming messages are properly logged.353 # Incoming messages are properly logged.
350 self.mock_recv.return_value = (42, 'my message')354 self.mock_recv.return_value = (juju.OPCODE_TEXT, b'my message')
351 with helpers.assert_logs(['API message: <-- my message'], 'debug'):355 with helpers.assert_logs(['API message: <-- my message'], 'debug'):
352 self.conn.recv()356 self.conn.recv()
353 self.mock_recv.assert_called_once_with()357 self.mock_recv.assert_called_once_with()
354358
355 def test_recv_unicode(self):359 def test_recv_unicode(self):
356 # Incoming unicode messages are properly logged.360 # Incoming unicode messages are properly logged.
357 self.mock_recv.return_value = (42, self.snowman.encode('utf-8'))361 self.mock_recv.return_value = (
362 juju.OPCODE_TEXT, self.snowman.encode('utf-8'))
358 expected = 'API message: <-- {}'.format(self.snowman)363 expected = 'API message: <-- {}'.format(self.snowman)
359 with helpers.assert_logs([expected], 'debug'):364 with helpers.assert_logs([expected], 'debug'):
360 self.conn.recv()365 self.conn.recv()
361 self.mock_recv.assert_called_once_with()366 self.mock_recv.assert_called_once_with()
367
368 def test_recv_not_text(self):
369 # Incoming non-textual messages are not logged.
370 self.mock_recv.return_value = (websocket.ABNF.OPCODE_BINARY, 0x0)
371 with helpers.assert_logs([], 'debug'):
372 self.conn.recv()
373 self.mock_recv.assert_called_once_with()
362374
=== modified file 'requirements.pip'
--- requirements.pip 2014-06-09 20:31:01 +0000
+++ requirements.pip 2014-09-08 18:10:40 +0000
@@ -25,7 +25,7 @@
25# version of websocket-client to use. Remove websocket-client as a dependency25# version of websocket-client to use. Remove websocket-client as a dependency
26# here when moving to a newer jujuclient that correctly specifies the26# here when moving to a newer jujuclient that correctly specifies the
27# version.27# version.
28websocket-client==0.12.028websocket-client==0.18.0
29jujuclient==0.17.529jujuclient==0.18.4
30PyYAML==3.1030PyYAML==3.11
31urwid==1.1.131urwid==1.2.1
3232
=== modified file 'test-requirements.pip'
--- test-requirements.pip 2014-06-09 20:31:01 +0000
+++ test-requirements.pip 2014-09-08 18:10:40 +0000
@@ -17,7 +17,7 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
19coverage==3.7.119coverage==3.7.1
20flake8==2.1.020flake8==2.2.3
21mock==1.0.121mock==1.0.1
22nose==1.3.122nose==1.3.4
23-r requirements.pip23-r requirements.pip

Subscribers

People subscribed via source and target branches