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
1=== modified file 'Makefile'
2--- Makefile 2014-04-07 09:03:11 +0000
3+++ Makefile 2014-09-08 18:10:40 +0000
4@@ -23,7 +23,7 @@
5
6 $(VENV_ACTIVATE): test-requirements.pip requirements.pip
7 virtualenv --distribute -p $(PYTHON) $(VENV)
8- $(VENV)/bin/pip install --use-mirrors -r test-requirements.pip || \
9+ $(VENV)/bin/pip install -r test-requirements.pip || \
10 (touch test-requirements.pip; exit 1)
11 @touch $(VENV_ACTIVATE)
12
13
14=== modified file 'quickstart/juju.py'
15--- quickstart/juju.py 2014-06-03 20:39:11 +0000
16+++ quickstart/juju.py 2014-09-08 18:10:40 +0000
17@@ -19,16 +19,23 @@
18 from __future__ import unicode_literals
19
20 import logging
21+import ssl
22
23 import jujuclient
24-import ssl
25 import websocket
26
27
28+OPCODE_TEXT = websocket.ABNF.OPCODE_TEXT
29+# Define the options used to initiate the secure WebSocket connection.
30+SSLOPT = {
31+ 'cert_reqs': ssl.CERT_NONE,
32+ 'ssl_version': ssl.PROTOCOL_TLSv1,
33+}
34+
35+
36 def connect(api_url):
37 """Return an Environment instance connected to the given API URL."""
38- connection = WebSocketConnection(
39- sslopt={'ssl_version': ssl.PROTOCOL_TLSv1})
40+ connection = WebSocketConnection(sslopt=SSLOPT)
41 # See the websocket.create_connection function.
42 connection.settimeout(websocket.default_timeout)
43 connection.connect(api_url, origin=api_url)
44@@ -124,19 +131,23 @@
45 class WebSocketConnection(websocket.WebSocket):
46 """A WebSocket client connection."""
47
48- def send(self, message):
49+ def send(self, payload, opcode=OPCODE_TEXT):
50 """Send the given WebSocket message.
51
52- Overridden to add logging.
53+ Overridden to add logging in the case the payload is text.
54 """
55- logging.debug('API message: --> {}'.format(message.decode('utf-8')))
56- return super(WebSocketConnection, self).send(message)
57+ if opcode == OPCODE_TEXT:
58+ message = payload.decode('utf-8')
59+ logging.debug('API message: --> {}'.format(message))
60+ return super(WebSocketConnection, self).send(payload, opcode=opcode)
61
62 def recv(self):
63 """Receive a message from the WebSocket server.
64
65- Overridden to add logging.
66+ Overridden to add logging in the case the received data is text.
67 """
68- message = super(WebSocketConnection, self).recv()
69- logging.debug('API message: <-- {}'.format(message.decode('utf-8')))
70- return message
71+ data = super(WebSocketConnection, self).recv()
72+ if isinstance(data, bytes):
73+ message = data.decode('utf-8')
74+ logging.debug('API message: <-- {}'.format(message))
75+ return data
76
77=== modified file 'quickstart/tests/helpers.py'
78--- quickstart/tests/helpers.py 2014-04-23 13:08:12 +0000
79+++ quickstart/tests/helpers.py 2014-09-08 18:10:40 +0000
80@@ -36,8 +36,11 @@
81 """
82 with mock.patch('logging.{}'.format(level.lower())) as mock_log:
83 yield
84- expected_calls = [mock.call(message) for message in messages]
85- mock_log.assert_has_calls(expected_calls)
86+ if messages:
87+ expected_calls = [mock.call(message) for message in messages]
88+ mock_log.assert_has_calls(expected_calls)
89+ else:
90+ assert not mock_log.called, 'logging unexpectedly called'
91
92
93 class BundleFileTestsMixin(object):
94
95=== modified file 'quickstart/tests/test_juju.py'
96--- quickstart/tests/test_juju.py 2014-06-03 19:10:21 +0000
97+++ quickstart/tests/test_juju.py 2014-09-08 18:10:40 +0000
98@@ -21,7 +21,6 @@
99 import unittest
100
101 import mock
102-import ssl
103 import websocket
104
105 from quickstart import juju
106@@ -39,8 +38,7 @@
107 def test_environment_connection(self, mock_conn):
108 # A connected Environment instance is correctly returned.
109 env = juju.connect(self.api_url)
110- mock_conn.assert_called_once_with(
111- sslopt={'ssl_version': ssl.PROTOCOL_TLSv1})
112+ mock_conn.assert_called_once_with(sslopt=juju.SSLOPT)
113 conn = mock_conn()
114 conn.assert_has_calls([
115 mock.call.settimeout(websocket.default_timeout),
116@@ -65,7 +63,8 @@
117 api_url = self.api_url
118 with mock.patch('websocket.create_connection') as mock_connect:
119 self.env = juju.Environment(api_url)
120- mock_connect.assert_called_once_with(api_url, origin=api_url)
121+ mock_connect.assert_called_once_with(
122+ api_url, origin=api_url, sslopt=juju.SSLOPT)
123 # Keep track of watcher changes in the changesets list.
124 self.changesets = []
125
126@@ -325,10 +324,9 @@
127 snowman = 'Here is a snowman\u00a1: \u2603'
128
129 def setUp(self):
130- with mock.patch('socket.socket') as mock_socket:
131- self.conn = juju.WebSocketConnection()
132- # Patch the socket.send() function used by the send method.
133- self.mock_send = mock_socket().send
134+ self.conn = juju.WebSocketConnection()
135+ # The send method calls the send_frame one.
136+ self.conn.send_frame = self.mock_send = mock.Mock()
137 # The recv method calls the recv_data one.
138 self.conn.recv_data = self.mock_recv = mock.Mock()
139
140@@ -345,17 +343,31 @@
141 self.conn.send(self.snowman.encode('utf-8'))
142 self.assertTrue(self.mock_send.called)
143
144+ def test_send_not_text(self):
145+ # Outgoing non-textual messages are not logged.
146+ with helpers.assert_logs([], 'debug'):
147+ self.conn.send(0x0, opcode=websocket.ABNF.OPCODE_BINARY)
148+ self.assertTrue(self.mock_send.called)
149+
150 def test_recv(self):
151 # Incoming messages are properly logged.
152- self.mock_recv.return_value = (42, 'my message')
153+ self.mock_recv.return_value = (juju.OPCODE_TEXT, b'my message')
154 with helpers.assert_logs(['API message: <-- my message'], 'debug'):
155 self.conn.recv()
156 self.mock_recv.assert_called_once_with()
157
158 def test_recv_unicode(self):
159 # Incoming unicode messages are properly logged.
160- self.mock_recv.return_value = (42, self.snowman.encode('utf-8'))
161+ self.mock_recv.return_value = (
162+ juju.OPCODE_TEXT, self.snowman.encode('utf-8'))
163 expected = 'API message: <-- {}'.format(self.snowman)
164 with helpers.assert_logs([expected], 'debug'):
165 self.conn.recv()
166 self.mock_recv.assert_called_once_with()
167+
168+ def test_recv_not_text(self):
169+ # Incoming non-textual messages are not logged.
170+ self.mock_recv.return_value = (websocket.ABNF.OPCODE_BINARY, 0x0)
171+ with helpers.assert_logs([], 'debug'):
172+ self.conn.recv()
173+ self.mock_recv.assert_called_once_with()
174
175=== modified file 'requirements.pip'
176--- requirements.pip 2014-06-09 20:31:01 +0000
177+++ requirements.pip 2014-09-08 18:10:40 +0000
178@@ -25,7 +25,7 @@
179 # version of websocket-client to use. Remove websocket-client as a dependency
180 # here when moving to a newer jujuclient that correctly specifies the
181 # version.
182-websocket-client==0.12.0
183-jujuclient==0.17.5
184-PyYAML==3.10
185-urwid==1.1.1
186+websocket-client==0.18.0
187+jujuclient==0.18.4
188+PyYAML==3.11
189+urwid==1.2.1
190
191=== modified file 'test-requirements.pip'
192--- test-requirements.pip 2014-06-09 20:31:01 +0000
193+++ test-requirements.pip 2014-09-08 18:10:40 +0000
194@@ -17,7 +17,7 @@
195 # along with this program. If not, see <http://www.gnu.org/licenses/>.
196
197 coverage==3.7.1
198-flake8==2.1.0
199+flake8==2.2.3
200 mock==1.0.1
201-nose==1.3.1
202+nose==1.3.4
203 -r requirements.pip

Subscribers

People subscribed via source and target branches