Merge lp:~patrick-hetu/jrapi/ssh-master-key into lp:jrapi
- ssh-master-key
- Merge into jrapi
Proposed by
Patrick Hetu
Status: | Needs review |
---|---|
Proposed branch: | lp:~patrick-hetu/jrapi/ssh-master-key |
Merge into: | lp:jrapi |
Diff against target: |
400 lines (+46/-151) 6 files modified
debian/jrapi.postinst (+6/-0) jrapi/api/base.py (+1/-10) jrapi/api/environment.py (+23/-28) jrapi/storage/dummy.py (+1/-4) jrapi/storage/filesystem.py (+9/-82) tests/test_environment.py (+6/-27) |
To merge this branch: | bzr merge lp:~patrick-hetu/jrapi/ssh-master-key |
Related bugs: | |
Related blueprints: |
Deploy with an ssh master key
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juan L. Negron | Pending | ||
Review via email: mp+121345@code.launchpad.net |
Commit message
Description of the change
1. Minor fix to get the environment tests to work
2. Use an ssh master key for bootstraping
To post a comment you must log in.
Unmerged revisions
- 80. By Patrick Hetu
-
use a master ssh key for bootstraping
- 79. By Patrick Hetu
-
fix environment tests
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/jrapi.postinst' | |||
2 | --- debian/jrapi.postinst 2012-05-25 20:48:33 +0000 | |||
3 | +++ debian/jrapi.postinst 2012-08-26 19:06:19 +0000 | |||
4 | @@ -35,11 +35,17 @@ | |||
5 | 35 | usermod -g jrapi jrapi | 35 | usermod -g jrapi jrapi |
6 | 36 | fi | 36 | fi |
7 | 37 | 37 | ||
8 | 38 | if [ ! -e /var/lib/jrapi/.ssh/ ]; then | ||
9 | 39 | mkdir /var/lib/jrapi/.ssh/ | ||
10 | 40 | ssh-keygen -q -t rsa -f /var/lib/jrapi/.ssh/id_rsa -C 'juju_master_key' -N '' | ||
11 | 41 | fi | ||
12 | 42 | |||
13 | 38 | if [ -z "$2" ]; then | 43 | if [ -z "$2" ]; then |
14 | 39 | # New install - blanket permissions | 44 | # New install - blanket permissions |
15 | 40 | chown -R jrapi:jrapi /var/lib/jrapi/ /etc/jrapi /var/log/jrapi | 45 | chown -R jrapi:jrapi /var/lib/jrapi/ /etc/jrapi /var/log/jrapi |
16 | 41 | fi | 46 | fi |
17 | 42 | 47 | ||
18 | 48 | |||
19 | 43 | chmod 0600 /etc/jrapi/jrapi.conf | 49 | chmod 0600 /etc/jrapi/jrapi.conf |
20 | 44 | chmod 0700 /etc/jrapi | 50 | chmod 0700 /etc/jrapi |
21 | 45 | chmod 0700 /var/log/jrapi | 51 | chmod 0700 /var/log/jrapi |
22 | 46 | 52 | ||
23 | === modified file 'jrapi/api/base.py' | |||
24 | --- jrapi/api/base.py 2012-07-20 00:14:50 +0000 | |||
25 | +++ jrapi/api/base.py 2012-08-26 19:06:19 +0000 | |||
26 | @@ -45,17 +45,8 @@ | |||
27 | 45 | :param failure: The failure object ( type ) | 45 | :param failure: The failure object ( type ) |
28 | 46 | :param request: The twisted request object | 46 | :param request: The twisted request object |
29 | 47 | ''' | 47 | ''' |
39 | 48 | if failure.type == errors.EnvironmentNotFound: | 48 | msg = failure.getErrorMessage() |
31 | 49 | error_type = "EnvironmentNotFound" | ||
32 | 50 | msg = failure.getErrorMessage() | ||
33 | 51 | request.setResponseCode(404) | ||
34 | 52 | else: | ||
35 | 53 | error_type = "Unknown" | ||
36 | 54 | msg = failure.getErrorMessage() | ||
37 | 55 | request.setResponseCode(500) | ||
38 | 56 | |||
40 | 57 | logging.error(msg) | 49 | logging.error(msg) |
41 | 58 | request.write(jsonify({"error": {error_type: msg}})) | ||
42 | 59 | 50 | ||
43 | 60 | request.finish() | 51 | request.finish() |
44 | 61 | 52 | ||
45 | 62 | 53 | ||
46 | === modified file 'jrapi/api/environment.py' | |||
47 | --- jrapi/api/environment.py 2012-07-24 17:17:20 +0000 | |||
48 | +++ jrapi/api/environment.py 2012-08-26 19:06:19 +0000 | |||
49 | @@ -60,7 +60,8 @@ | |||
50 | 60 | try: | 60 | try: |
51 | 61 | env_conf_yaml = storage.get_environment(username, name) | 61 | env_conf_yaml = storage.get_environment(username, name) |
52 | 62 | except IOError: | 62 | except IOError: |
54 | 63 | raise EnvironmentNotFound('Environment not found.') | 63 | request.setResponseCode(404, "Environment not found") |
55 | 64 | raise EnvironmentNotFound("Environment not found.") | ||
56 | 64 | 65 | ||
57 | 65 | env_config = EnvironmentsConfig() | 66 | env_config = EnvironmentsConfig() |
58 | 66 | 67 | ||
59 | @@ -82,19 +83,18 @@ | |||
60 | 82 | 83 | ||
61 | 83 | # continue when we will have a dns_name | 84 | # continue when we will have a dns_name |
62 | 84 | dns_name = machine.dns_name | 85 | dns_name = machine.dns_name |
63 | 86 | |||
64 | 85 | LOG.debug("Got dns_name: %s" % dns_name) | 87 | LOG.debug("Got dns_name: %s" % dns_name) |
65 | 86 | 88 | ||
66 | 87 | if not dns_name: | 89 | if not dns_name: |
67 | 88 | request.setResponseCode(503) | 90 | request.setResponseCode(503) |
68 | 89 | raise EnvironmentNotFound("Environment not ready yet.") | 91 | raise EnvironmentNotFound("Environment not ready yet.") |
69 | 90 | 92 | ||
70 | 93 | environment.dns_name = dns_name | ||
71 | 94 | |||
72 | 91 | # get the fingerprint | 95 | # get the fingerprint |
73 | 92 | LOG.debug("add_known_host") | 96 | LOG.debug("add_known_host") |
79 | 93 | storage.add_known_host(username, name, dns_name) # #@UndefinedVariable | 97 | storage.add_known_host(username, name, dns_name) |
75 | 94 | |||
76 | 95 | LOG.debug("add_ssh_config") | ||
77 | 96 | # add ssh config for the new host | ||
78 | 97 | storage.add_ssh_config(username, name, dns_name) # #@UndefinedVariable | ||
80 | 98 | 98 | ||
81 | 99 | returnValue(environment) | 99 | returnValue(environment) |
82 | 100 | 100 | ||
83 | @@ -161,6 +161,7 @@ | |||
84 | 161 | return self | 161 | return self |
85 | 162 | else: | 162 | else: |
86 | 163 | deferred = get_environment(request, name, self.username) | 163 | deferred = get_environment(request, name, self.username) |
87 | 164 | deferred.addErrback(self._errorRender, request) | ||
88 | 164 | environment = Environment(deferred, name, self.username) | 165 | environment = Environment(deferred, name, self.username) |
89 | 165 | return environment | 166 | return environment |
90 | 166 | 167 | ||
91 | @@ -186,20 +187,13 @@ | |||
92 | 186 | if not hasattr(conf, 'admin-secret'): | 187 | if not hasattr(conf, 'admin-secret'): |
93 | 187 | conf['admin-secret'] = uuid.uuid4().hex | 188 | conf['admin-secret'] = uuid.uuid4().hex |
94 | 188 | 189 | ||
102 | 189 | # upload/create ssh private/public key | 190 | if 'authorized-keys' in conf.keys(): |
103 | 190 | private_key_path = storage.add_sshkey( # @UndefinedVariable | 191 | conf['authorized-keys'] += '\n %s' % (open('/var/lib/jrapi/.ssh/id_rsa.pub').read()) |
104 | 191 | self.username, conf['name']) | 192 | else: |
105 | 192 | 193 | conf['authorized-keys'] = open('/var/lib/jrapi/.ssh/id_rsa.pub').read() | |
99 | 193 | LOG.debug('Setting private_key_path to : %s' % \ | ||
100 | 194 | private_key_path + '.pub') | ||
101 | 195 | conf['authorized-keys-path'] = private_key_path + '.pub' | ||
106 | 196 | 194 | ||
107 | 197 | env_conf_yaml = yaml.safe_dump({'environments': {conf['name']: conf}}) | 195 | env_conf_yaml = yaml.safe_dump({'environments': {conf['name']: conf}}) |
108 | 198 | 196 | ||
109 | 199 | LOG.debug("Add environment: %s" % env_conf_yaml) | ||
110 | 200 | storage.add_environment(self.username, # #@UndefinedVariable | ||
111 | 201 | conf['name'], env_conf_yaml) | ||
112 | 202 | |||
113 | 203 | env_config = EnvironmentsConfig() | 197 | env_config = EnvironmentsConfig() |
114 | 204 | 198 | ||
115 | 205 | LOG.debug("Configuring the environment") | 199 | LOG.debug("Configuring the environment") |
116 | @@ -217,6 +211,9 @@ | |||
117 | 217 | LOG.debug("Launch the actual bootstrap") | 211 | LOG.debug("Launch the actual bootstrap") |
118 | 218 | yield provider.bootstrap(my_constraints) | 212 | yield provider.bootstrap(my_constraints) |
119 | 219 | 213 | ||
120 | 214 | LOG.debug("Save the environment: %s" % env_conf_yaml) | ||
121 | 215 | storage.add_environment(self.username, conf['name'], env_conf_yaml) | ||
122 | 216 | |||
123 | 220 | request.setResponseCode(201) | 217 | request.setResponseCode(201) |
124 | 221 | 218 | ||
125 | 222 | 219 | ||
126 | @@ -255,9 +252,10 @@ | |||
127 | 255 | ''' | 252 | ''' |
128 | 256 | LOG.debug("Received an environment details request") | 253 | LOG.debug("Received an environment details request") |
129 | 257 | 254 | ||
133 | 258 | result = self._get(request) | 255 | self.deferred.addCallback(self._get, request) |
134 | 259 | 256 | self.deferred.addCallback(self._delayedRender, request) | |
135 | 260 | return jsonify(result) | 257 | self.deferred.addErrback(self._errorRender, request) |
136 | 258 | return NOT_DONE_YET | ||
137 | 261 | 259 | ||
138 | 262 | def render_DELETE(self, request): | 260 | def render_DELETE(self, request): |
139 | 263 | ''' | 261 | ''' |
140 | @@ -277,7 +275,7 @@ | |||
141 | 277 | LOG.debug('Envrionment getChild with name: "%s"' % name) | 275 | LOG.debug('Envrionment getChild with name: "%s"' % name) |
142 | 278 | return self | 276 | return self |
143 | 279 | 277 | ||
145 | 280 | def _get(self, request): | 278 | def _get(self, environment, request): |
146 | 281 | ''' | 279 | ''' |
147 | 282 | Returns the details of a single environment | 280 | Returns the details of a single environment |
148 | 283 | :param request: A Twisted request object | 281 | :param request: A Twisted request object |
149 | @@ -286,9 +284,9 @@ | |||
150 | 286 | 284 | ||
151 | 287 | try: | 285 | try: |
152 | 288 | env_conf_yaml = storage.get_environment(self.username, self.name) | 286 | env_conf_yaml = storage.get_environment(self.username, self.name) |
156 | 289 | except EnvironmentNotFound: | 287 | except IOError: |
157 | 290 | request.setResponseCode(404) | 288 | request.setResponseCode(404, "Environment not found") |
158 | 291 | return {'error': {'EnvironmentNotFound': "Environment not found"}} | 289 | raise EnvironmentNotFound("Environment not ready yet.") |
159 | 292 | 290 | ||
160 | 293 | env_conf = yaml.load(env_conf_yaml) | 291 | env_conf = yaml.load(env_conf_yaml) |
161 | 294 | 292 | ||
162 | @@ -297,8 +295,6 @@ | |||
163 | 297 | env_conf['environments'][self.name]} | 295 | env_conf['environments'][self.name]} |
164 | 298 | single_environment['environment']['name'] = self.name | 296 | single_environment['environment']['name'] = self.name |
165 | 299 | 297 | ||
166 | 300 | del single_environment['environment']['authorized-keys-path'] | ||
167 | 301 | |||
168 | 302 | request.setResponseCode(200) | 298 | request.setResponseCode(200) |
169 | 303 | return single_environment | 299 | return single_environment |
170 | 304 | 300 | ||
171 | @@ -312,7 +308,6 @@ | |||
172 | 312 | provider = environment.get_machine_provider() | 308 | provider = environment.get_machine_provider() |
173 | 313 | yield provider.destroy_environment() | 309 | yield provider.destroy_environment() |
174 | 314 | 310 | ||
177 | 315 | storage.delete_environment( # #@UndefinedVariable | 311 | storage.delete_environment(self.username, environment.name, environment.dns_name) |
176 | 316 | self.username, self.name) | ||
178 | 317 | 312 | ||
179 | 318 | request.setResponseCode(204) | 313 | request.setResponseCode(204) |
180 | 319 | 314 | ||
181 | === modified file 'jrapi/storage/dummy.py' | |||
182 | --- jrapi/storage/dummy.py 2012-07-14 14:53:32 +0000 | |||
183 | +++ jrapi/storage/dummy.py 2012-08-26 19:06:19 +0000 | |||
184 | @@ -16,14 +16,11 @@ | |||
185 | 16 | # You should have received a copy of the GNU Affero General Public License | 16 | # You should have received a copy of the GNU Affero General Public License |
186 | 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/>. |
187 | 18 | 18 | ||
188 | 19 | from juju import errors | ||
189 | 20 | |||
190 | 21 | DUMMY_ENV = """ | 19 | DUMMY_ENV = """ |
191 | 22 | environments: | 20 | environments: |
192 | 23 | dummy: | 21 | dummy: |
193 | 24 | type: dummy | 22 | type: dummy |
194 | 25 | foo: bar | 23 | foo: bar |
195 | 26 | authorized-keys-path: /should/not/see/id_rsa | ||
196 | 27 | """ | 24 | """ |
197 | 28 | 25 | ||
198 | 29 | DUMMY_ENV_JSON ="""{ | 26 | DUMMY_ENV_JSON ="""{ |
199 | @@ -44,7 +41,7 @@ | |||
200 | 44 | if env_name == 'dummy': | 41 | if env_name == 'dummy': |
201 | 45 | return DUMMY_ENV | 42 | return DUMMY_ENV |
202 | 46 | else: | 43 | else: |
204 | 47 | raise errors.EnvironmentNotFound('Environment Not found') | 44 | raise IOError |
205 | 48 | 45 | ||
206 | 49 | def get_environments(self, username): | 46 | def get_environments(self, username): |
207 | 50 | return [{'name':'sample'}] | 47 | return [{'name':'sample'}] |
208 | 51 | 48 | ||
209 | === modified file 'jrapi/storage/filesystem.py' | |||
210 | --- jrapi/storage/filesystem.py 2012-07-24 17:17:20 +0000 | |||
211 | +++ jrapi/storage/filesystem.py 2012-08-26 19:06:19 +0000 | |||
212 | @@ -22,7 +22,6 @@ | |||
213 | 22 | import subprocess | 22 | import subprocess |
214 | 23 | 23 | ||
215 | 24 | from jrapi.config import CONF | 24 | from jrapi.config import CONF |
216 | 25 | from jrapi.common import ssh_keygen | ||
217 | 26 | from jrapi.openstack.common import cfg | 25 | from jrapi.openstack.common import cfg |
218 | 27 | 26 | ||
219 | 28 | from jrapi.storage.errors import BadStoreConfiguration | 27 | from jrapi.storage.errors import BadStoreConfiguration |
220 | @@ -71,12 +70,12 @@ | |||
221 | 71 | # LOG.error(reason) | 70 | # LOG.error(reason) |
222 | 72 | # raise IOError | 71 | # raise IOError |
223 | 73 | 72 | ||
230 | 74 | # try: | 73 | try: |
231 | 75 | # os.makedirs(env_path) | 74 | os.makedirs(env_path) |
232 | 76 | # except IOError: | 75 | except IOError: |
233 | 77 | # reason = _("Unable to create user dir: %s") % user_path | 76 | reason = _("Unable to create user dir: %s") % user_path |
234 | 78 | # LOG.error(reason) | 77 | LOG.error(reason) |
235 | 79 | # raise | 78 | raise |
236 | 80 | 79 | ||
237 | 81 | 80 | ||
238 | 82 | env_conf_file = os.path.join(env_path, "environments.yaml") | 81 | env_conf_file = os.path.join(env_path, "environments.yaml") |
239 | @@ -118,15 +117,14 @@ | |||
240 | 118 | 117 | ||
241 | 119 | return environments | 118 | return environments |
242 | 120 | 119 | ||
245 | 121 | 120 | def delete_environment(self, username, env_name, ip): | |
244 | 122 | def delete_environment(self, username, env_name): | ||
246 | 123 | user_path = self._get_user_path(username) | 121 | user_path = self._get_user_path(username) |
247 | 124 | env_path = os.path.join(user_path, env_name) | 122 | env_path = os.path.join(user_path, env_name) |
248 | 125 | 123 | ||
249 | 126 | user_known_host_file = os.path.join(env_path, "known_host") | 124 | user_known_host_file = os.path.join(env_path, "known_host") |
250 | 127 | user_identity_file = os.path.join(env_path, "id_rsa") | 125 | user_identity_file = os.path.join(env_path, "id_rsa") |
251 | 128 | 126 | ||
253 | 129 | self.remove_ssh_config(username, env_name) | 127 | subprocess.Popen('ssh-keygen -R %s' % ip) |
254 | 130 | 128 | ||
255 | 131 | if os.path.exists(env_path): | 129 | if os.path.exists(env_path): |
256 | 132 | try: | 130 | try: |
257 | @@ -145,45 +143,8 @@ | |||
258 | 145 | LOG.error(reason) | 143 | LOG.error(reason) |
259 | 146 | raise IOError | 144 | raise IOError |
260 | 147 | 145 | ||
261 | 148 | |||
262 | 149 | |||
263 | 150 | def add_sshkey(self, username, env_name): | ||
264 | 151 | user_path = self._get_user_path(username) | ||
265 | 152 | env_path = os.path.join(user_path, env_name) | ||
266 | 153 | key_file = os.path.join(user_path, env_name, "id_rsa") | ||
267 | 154 | |||
268 | 155 | try: | ||
269 | 156 | os.makedirs(env_path) | ||
270 | 157 | except IOError: | ||
271 | 158 | reason = "Unable to create user dir: %s" % user_path | ||
272 | 159 | LOG.error(reason) | ||
273 | 160 | raise | ||
274 | 161 | |||
275 | 162 | if not os.path.exists(key_file): | ||
276 | 163 | key_dict = ssh_keygen() | ||
277 | 164 | |||
278 | 165 | private_key_fp = open("%s/id_rsa" % env_path, "w") | ||
279 | 166 | private_key_fp.write(key_dict['private_key']) | ||
280 | 167 | private_key_fp.close() | ||
281 | 168 | |||
282 | 169 | public_key_fp = open("%s/id_rsa.pub" % env_path, "w") | ||
283 | 170 | public_key_fp.write(key_dict['public_key']) | ||
284 | 171 | public_key_fp.close() | ||
285 | 172 | |||
286 | 173 | os.chmod("%s/id_rsa" % env_path, 0600) | ||
287 | 174 | os.chmod("%s/id_rsa.pub" % env_path, 0600) | ||
288 | 175 | |||
289 | 176 | return key_file | ||
290 | 177 | |||
291 | 178 | |||
292 | 179 | def add_known_host(self, username, env_name, ip): | 146 | def add_known_host(self, username, env_name, ip): |
300 | 180 | user_path = self._get_user_path(username) | 147 | known_host_file = os.path.join(self.datadir, ".ssh/known_host") |
294 | 181 | env_path = os.path.join(user_path, env_name) | ||
295 | 182 | |||
296 | 183 | known_host_file = os.path.join(env_path, "known_host") | ||
297 | 184 | |||
298 | 185 | if os.path.exists(known_host_file): | ||
299 | 186 | return | ||
301 | 187 | 148 | ||
302 | 188 | output = subprocess.check_output( | 149 | output = subprocess.check_output( |
303 | 189 | ["ssh-keyscan", "-H", "-t", "ecdsa-sha2-nistp256", ip], | 150 | ["ssh-keyscan", "-H", "-t", "ecdsa-sha2-nistp256", ip], |
304 | @@ -195,37 +156,3 @@ | |||
305 | 195 | except IOError as e: | 156 | except IOError as e: |
306 | 196 | raise | 157 | raise |
307 | 197 | 158 | ||
308 | 198 | def add_ssh_config(self, username, env_name, ip): | ||
309 | 199 | user_path = self._get_user_path(username) | ||
310 | 200 | env_path = os.path.join(user_path, env_name) | ||
311 | 201 | |||
312 | 202 | ssh_config_file = os.path.join(self.datadir, ".ssh/config") | ||
313 | 203 | user_known_host_file = os.path.join(env_path, "known_host") | ||
314 | 204 | user_identity_file = os.path.join(env_path, "id_rsa") | ||
315 | 205 | |||
316 | 206 | config_block = """Host %s | ||
317 | 207 | UserKnownHostsFile=%s | ||
318 | 208 | IdentityFile=%s | ||
319 | 209 | """ % (ip, user_known_host_file, user_identity_file) | ||
320 | 210 | |||
321 | 211 | with open(ssh_config_file, "r+") as f: | ||
322 | 212 | old = f.readlines() # read everything in the file | ||
323 | 213 | if "Host %s\n" % ip in old: | ||
324 | 214 | return | ||
325 | 215 | else: | ||
326 | 216 | f.seek(0) # rewind | ||
327 | 217 | f.write(config_block + "".join(old)) | ||
328 | 218 | |||
329 | 219 | def remove_ssh_config(self, username, env_name): | ||
330 | 220 | user_path = self._get_user_path(username) | ||
331 | 221 | env_path = os.path.join(user_path, env_name) | ||
332 | 222 | |||
333 | 223 | ssh_config_file = os.path.join(self.datadir, ".ssh/config") | ||
334 | 224 | user_known_host_file = os.path.join(env_path, "known_host") | ||
335 | 225 | user_identity_file = os.path.join(env_path, "id_rsa") | ||
336 | 226 | |||
337 | 227 | with open(ssh_config_file, "r+") as f: | ||
338 | 228 | old = f.read() | ||
339 | 229 | old = re.sub(r'.* #%s' % env_path, '', old) | ||
340 | 230 | f.seek(0) | ||
341 | 231 | f.write(old) | ||
342 | 232 | 159 | ||
343 | === modified file 'tests/test_environment.py' | |||
344 | --- tests/test_environment.py 2012-07-14 14:53:32 +0000 | |||
345 | +++ tests/test_environment.py 2012-08-26 19:06:19 +0000 | |||
346 | @@ -2,7 +2,6 @@ | |||
347 | 2 | 2 | ||
348 | 3 | from juju.environment.tests.test_config import EnvironmentsConfigTestBase | 3 | from juju.environment.tests.test_config import EnvironmentsConfigTestBase |
349 | 4 | 4 | ||
350 | 5 | from jrapi.auth import JRAPIAuthSessionWrapper | ||
351 | 6 | from jrapi.apiroot import APIRoot | 5 | from jrapi.apiroot import APIRoot |
352 | 7 | from jrapi.storage.dummy import DUMMY_ENV, DUMMY_ENV_JSON | 6 | from jrapi.storage.dummy import DUMMY_ENV, DUMMY_ENV_JSON |
353 | 8 | 7 | ||
354 | @@ -14,16 +13,11 @@ | |||
355 | 14 | @inlineCallbacks | 13 | @inlineCallbacks |
356 | 15 | def setUp(self): | 14 | def setUp(self): |
357 | 16 | yield super(EnvironmentTest, self).setUp() | 15 | yield super(EnvironmentTest, self).setUp() |
359 | 17 | self.web = DummySite(JRAPIAuthSessionWrapper(APIRoot())) | 16 | self.web = DummySite(APIRoot()) |
360 | 18 | self.write_config(DUMMY_ENV) | 17 | self.write_config(DUMMY_ENV) |
361 | 19 | self.config.load() | 18 | self.config.load() |
362 | 20 | 19 | ||
363 | 21 | @inlineCallbacks | 20 | @inlineCallbacks |
364 | 22 | def test_bootstrap(self): | ||
365 | 23 | response = yield self.web.put("/environments/", content=DUMMY_ENV_JSON) | ||
366 | 24 | self.assertEqual(response.responseCode, 201), | ||
367 | 25 | |||
368 | 26 | @inlineCallbacks | ||
369 | 27 | def test_list(self): | 21 | def test_list(self): |
370 | 28 | response = yield self.web.get("/environments/") | 22 | response = yield self.web.get("/environments/") |
371 | 29 | self.assertEqual(response.responseCode, 200), | 23 | self.assertEqual(response.responseCode, 200), |
372 | @@ -45,23 +39,8 @@ | |||
373 | 45 | def test_get_not_existing(self): | 39 | def test_get_not_existing(self): |
374 | 46 | response = yield self.web.get("/environments/not_existing/") | 40 | response = yield self.web.get("/environments/not_existing/") |
375 | 47 | self.assertEqual(response.responseCode, 404), | 41 | self.assertEqual(response.responseCode, 404), |
396 | 48 | self.assertEqual(response.value(), """{ | 42 | |
397 | 49 | "error": { | 43 | @inlineCallbacks |
398 | 50 | "EnvironmentNotFound": "Environment not found" | 44 | def test_zdestroy_not_existing(self): |
399 | 51 | } | 45 | response = yield self.web.delete("/environments/not_existing/") |
400 | 52 | }""") | 46 | self.assertEqual(response.responseCode, 404), |
381 | 53 | |||
382 | 54 | # @inlineCallbacks | ||
383 | 55 | # def test_zdestroy(self): | ||
384 | 56 | # response = yield self.web.delete("/environments/dummy/") | ||
385 | 57 | # self.assertEqual(response.responseCode, 204), | ||
386 | 58 | |||
387 | 59 | # @inlineCallbacks | ||
388 | 60 | # def test_zdestroy_not_existing(self): | ||
389 | 61 | # response = yield self.web.delete("/environments/not_existing/") | ||
390 | 62 | # self.assertEqual(response.responseCode, 404), | ||
391 | 63 | # self.assertEqual(response.value(), """{ | ||
392 | 64 | # "error": { | ||
393 | 65 | # "EnvironmentNotFound": "juju environment not found: Environment ready yet." | ||
394 | 66 | # } | ||
395 | 67 | #}""") |