OLD | NEW |
1 # This file is part of the Juju GUI, which lets users view and manage Juju | 1 # This file is part of the Juju GUI, which lets users view and manage Juju |
2 # environments within a graphical interface (https://launchpad.net/juju-gui). | 2 # environments within a graphical interface (https://launchpad.net/juju-gui). |
3 # Copyright (C) 2012-2013 Canonical Ltd. | 3 # Copyright (C) 2012-2013 Canonical Ltd. |
4 # | 4 # |
5 # This program is free software: you can redistribute it and/or modify it under | 5 # This program is free software: you can redistribute it and/or modify it under |
6 # the terms of the GNU Affero General Public License version 3, as published by | 6 # the terms of the GNU Affero General Public License version 3, as published by |
7 # the Free Software Foundation. | 7 # the Free Software Foundation. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, but WITHOUT | 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | 10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
11 # SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 # SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 # Affero General Public License for more details. | 12 # Affero General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU Affero General Public License | 14 # You should have received a copy of the GNU Affero General Public License |
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
17 """Juju GUI test helpers.""" | 17 """Juju GUI test helpers.""" |
18 | 18 |
19 from collections import namedtuple | 19 from collections import namedtuple |
20 from functools import wraps | 20 from functools import wraps |
21 import json | 21 import json |
22 import os | 22 import os |
| 23 import random |
23 import re | 24 import re |
| 25 import string |
24 import subprocess | 26 import subprocess |
25 import time | 27 import time |
26 | 28 |
27 import websocket | 29 import websocket |
28 import yaml | 30 import yaml |
29 | 31 |
30 | 32 |
31 class ProcessError(subprocess.CalledProcessError): | 33 class ProcessError(subprocess.CalledProcessError): |
32 """Error running a shell command.""" | 34 """Error running a shell command.""" |
33 | 35 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 except subprocess.CalledProcessError: | 195 except subprocess.CalledProcessError: |
194 # Current juju-core exposes a version subcommand. | 196 # Current juju-core exposes a version subcommand. |
195 output = subprocess.check_output(['juju', 'version']) | 197 output = subprocess.check_output(['juju', 'version']) |
196 match = _juju_version_expression.match(output) | 198 match = _juju_version_expression.match(output) |
197 if match is None: | 199 if match is None: |
198 raise ValueError('invalid juju version: {!r}'.format(output)) | 200 raise ValueError('invalid juju version: {!r}'.format(output)) |
199 to_int = lambda num: 0 if num is None else int(num) | 201 to_int = lambda num: 0 if num is None else int(num) |
200 return Version._make(map(to_int, match.groups())) | 202 return Version._make(map(to_int, match.groups())) |
201 | 203 |
202 | 204 |
| 205 def make_service_name(prefix='service-'): |
| 206 """Generate a long, random service name.""" |
| 207 characters = string.ascii_lowercase |
| 208 suffix = ''.join([random.choice(characters) for _ in range(20)]) |
| 209 return prefix + suffix |
| 210 |
| 211 |
203 def stop_services(hostname, services): | 212 def stop_services(hostname, services): |
204 """Stop the given upstart services running on hostname.""" | 213 """Stop the given upstart services running on hostname.""" |
205 target = 'ubuntu@{}'.format(hostname) | 214 target = 'ubuntu@{}'.format(hostname) |
206 for service in services: | 215 for service in services: |
207 ssh(target, 'sudo', 'service', service, 'stop') | 216 ssh(target, 'sudo', 'service', service, 'stop') |
208 | 217 |
209 | 218 |
210 def wait_for_unit(sevice): | 219 def wait_for_unit(sevice): |
211 """Wait for the first unit of the given service to be started. | 220 """Wait for the first unit of the given service to be started. |
212 | 221 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 """ | 260 """ |
252 self._conn.send(json.dumps(request)) | 261 self._conn.send(json.dumps(request)) |
253 response = self._conn.recv() | 262 response = self._conn.recv() |
254 return json.loads(response) | 263 return json.loads(response) |
255 | 264 |
256 def close(self): | 265 def close(self): |
257 """Close the WebSocket connection.""" | 266 """Close the WebSocket connection.""" |
258 if self._conn is not None: | 267 if self._conn is not None: |
259 self._conn.close() | 268 self._conn.close() |
260 self._conn = None | 269 self._conn = None |
OLD | NEW |