87
88
self.networks = kwargs['requested_networks']
89
90
self.networks = None
92
if 'user_data' in kwargs:
93
self.user_data = kwargs['user_data']
90
95
return [{'id': '1234', 'display_name': 'fakeinstance',
119
124
server['networks'] = network_list
120
125
return {'server': server}
127
def _create_user_data_request_dict(self, user_data):
129
server['name'] = 'new-server-test'
130
server['imageRef'] = 1
131
server['flavorRef'] = 1
132
server['user_data'] = user_data
133
return {'server': server}
122
135
def _get_create_request_json(self, body_dict):
123
136
req = webob.Request.blank('/v1.1/123/os-create-server-ext')
124
137
req.headers['Content-Type'] = 'application/json'
178
191
self._run_create_instance_with_mock_compute_api(request)
179
192
return request, response, compute_api.networks
194
def _create_instance_with_user_data_json(self, networks):
195
body_dict = self._create_user_data_request_dict(networks)
196
request = self._get_create_request_json(body_dict)
197
compute_api, response = \
198
self._run_create_instance_with_mock_compute_api(request)
199
return request, response, compute_api.user_data
181
201
def _create_instance_with_networks_xml(self, networks):
182
202
body_dict = self._create_networks_request_dict(networks)
183
203
request = self._get_create_request_xml(body_dict)
304
324
self.assertEquals(response.status_int, 202)
305
325
self.assertEquals(compute_api.networks,
306
326
[('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)])
328
def test_create_instance_with_userdata(self):
329
user_data_contents = '#!/bin/bash\necho "Oh no!"\n'
330
user_data_contents = base64.b64encode(user_data_contents)
331
request, response, user_data = \
332
self._create_instance_with_user_data_json(user_data_contents)
333
self.assertEquals(response.status_int, 202)
334
self.assertEquals(user_data, user_data_contents)
336
def test_create_instance_with_userdata_none(self):
337
user_data_contents = None
338
request, response, user_data = \
339
self._create_instance_with_user_data_json(user_data_contents)
340
self.assertEquals(response.status_int, 202)
341
self.assertEquals(user_data, user_data_contents)
343
def test_create_instance_with_userdata_with_non_b64_content(self):
344
user_data_contents = '#!/bin/bash\necho "Oh no!"\n'
345
request, response, user_data = \
346
self._create_instance_with_user_data_json(user_data_contents)
347
self.assertEquals(response.status_int, 400)
348
self.assertEquals(user_data, None)