989
1062
class VirtualInterfacesXmlTest(VirtualInterfacesJsonTest):
1066
class CloudPipeSampleJsonTest(ApiSampleTestBase):
1067
extension_name = "nova.api.openstack.compute.contrib.cloudpipe.Cloudpipe"
1070
super(CloudPipeSampleJsonTest, self).setUp()
1072
def get_user_data(self, project_id):
1073
"""Stub method to generate user data for cloudpipe tests"""
1074
return "VVNFUiBEQVRB\n"
1076
def network_api_get(self, context, network_uuid):
1077
"""Stub to get a valid network and its information"""
1078
return {'vpn_public_address': '127.0.0.1',
1079
'vpn_public_port': 22}
1081
self.stubs.Set(CloudPipe, 'get_encoded_zip', get_user_data)
1082
self.stubs.Set(NetworkManager, "get_network", network_api_get)
1084
def test_cloud_pipe_create(self):
1085
"""Get api samples of cloud pipe extension creation"""
1086
CONF.vpn_image_id = fake.get_valid_image_id()
1087
project = {'project_id': 'cloudpipe-' + str(uuid.uuid4())}
1088
response = self._do_post('os-cloudpipe', 'cloud-pipe-create-req',
1090
self.assertEqual(response.status, 200)
1091
subs = self._get_regexes()
1092
subs.update(project)
1093
subs['image_id'] = CONF.vpn_image_id
1094
self._verify_response('cloud-pipe-create-resp', subs, response)
1097
def test_cloud_pipe_list(self):
1098
"""Get api samples of cloud pipe extension get request"""
1099
project = self.test_cloud_pipe_create()
1100
response = self._do_get('os-cloudpipe')
1101
self.assertEqual(response.status, 200)
1102
subs = self._get_regexes()
1103
subs.update(project)
1104
subs['image_id'] = CONF.vpn_image_id
1105
return self._verify_response('cloud-pipe-get-resp', subs, response)
1108
class CloudPipeSampleXmlTest(CloudPipeSampleJsonTest):
1112
class AggregatesSampleJsonTest(ServersSampleBase):
1113
extension_name = "nova.api.openstack.compute.contrib" + \
1114
".aggregates.Aggregates"
1116
def test_aggregate_create(self):
1118
"aggregate_id": '(?P<id>\d+)'
1120
response = self._do_post('os-aggregates', 'aggregate-post-req', subs)
1121
self.assertEqual(response.status, 200)
1122
subs.update(self._get_regexes())
1123
return self._verify_response('aggregate-post-resp', subs, response)
1125
def test_list_aggregates(self):
1126
self.test_aggregate_create()
1127
response = self._do_get('os-aggregates')
1128
subs = self._get_regexes()
1129
return self._verify_response('aggregates-list-get-resp',
1132
def test_aggregate_get(self):
1133
agg_id = self.test_aggregate_create()
1134
response = self._do_get('os-aggregates/%s' % agg_id)
1135
subs = self._get_regexes()
1136
return self._verify_response('aggregates-get-resp', subs, response)
1138
def test_add_metadata(self):
1139
agg_id = self.test_aggregate_create()
1140
response = self._do_post('os-aggregates/%s/action' % agg_id,
1141
'aggregate-metadata-post-req',
1142
{'action': 'set_metadata'})
1143
subs = self._get_regexes()
1144
return self._verify_response('aggregates-metadata-post-resp',
1147
def test_add_host(self):
1148
aggregate_id = self.test_aggregate_create()
1150
"host_name": self.compute.host,
1152
response = self._do_post('os-aggregates/%s/action' % aggregate_id,
1153
'aggregate-add-host-post-req', subs)
1154
subs.update(self._get_regexes())
1155
return self._verify_response('aggregates-add-host-post-resp',
1158
def test_remove_host(self):
1159
self.test_add_host()
1161
"host_name": self.compute.host,
1163
response = self._do_post('os-aggregates/1/action',
1164
'aggregate-remove-host-post-req', subs)
1165
subs.update(self._get_regexes())
1166
return self._verify_response('aggregates-remove-host-post-resp',
1169
def test_update_aggregate(self):
1170
aggregate_id = self.test_aggregate_create()
1171
response = self._do_put('os-aggregates/%s' % aggregate_id,
1172
'aggregate-update-post-req', {})
1173
subs = self._get_regexes()
1174
return self._verify_response('aggregate-update-post-resp',
1178
class AggregatesSampleXmlTest(AggregatesSampleJsonTest):
1182
class CertificatesSamplesJsonTest(ApiSampleTestBase):
1183
extension_name = ("nova.api.openstack.compute.contrib.certificates."
1187
super(CertificatesSamplesJsonTest, self).setUp()
1189
def test_create_certificates(self):
1190
response = self._do_post('os-certificates',
1191
'certificate-create-req', {})
1192
self.assertEqual(response.status, 200)
1193
subs = self._get_regexes()
1194
return self._verify_response('certificate-create-resp', subs, response)
1196
def test_get_root_certificate(self):
1197
response = self._do_get('os-certificates/root')
1198
self.assertEqual(response.status, 200)
1199
subs = self._get_regexes()
1200
return self._verify_response('certificate-get-root-resp', subs,
1204
class CertificatesSamplesXmlTest(CertificatesSamplesJsonTest):
1208
class UsedLimitsSamplesJsonTest(ApiSampleTestBase):
1209
extension_name = ("nova.api.openstack.compute.contrib.used_limits."
1212
def test_get_used_limits(self):
1213
"""Get api sample to used limits"""
1214
response = self._do_get('limits')
1215
self.assertEqual(response.status, 200)
1216
subs = self._get_regexes()
1217
return self._verify_response('usedlimits-get-resp', subs, response)
1220
class UsedLimitsSamplesXmlTest(UsedLimitsSamplesJsonTest):
1224
class MultipleCreateJsonTest(ServersSampleBase):
1225
extension_name = ("nova.api.openstack.compute.contrib.multiple_create."
1228
def test_multiple_create(self):
1230
'image_id': fake.get_valid_image_id(),
1231
'host': self._get_host(),
1235
response = self._do_post('servers', 'multiple-create-post-req', subs)
1236
self.assertEqual(response.status, 202)
1237
subs.update(self._get_regexes())
1238
return self._verify_response('multiple-create-post-resp',
1241
def test_multiple_create_without_reservation_id(self):
1243
'image_id': fake.get_valid_image_id(),
1244
'host': self._get_host(),
1248
response = self._do_post('servers', 'multiple-create-no-resv-post-req',
1250
self.assertEqual(response.status, 202)
1251
subs.update(self._get_regexes())
1252
return self._verify_response('multiple-create-no-resv-post-resp',
1256
class MultipleCreateXmlTest(MultipleCreateJsonTest):
1260
class SimpleTenantUsageSampleJsonTest(ServersSampleBase):
1261
extension_name = ("nova.api.openstack.compute.contrib.simple_tenant_usage."
1262
"Simple_tenant_usage")
1265
"""setUp method for simple tenant usage"""
1266
super(SimpleTenantUsageSampleJsonTest, self).setUp()
1268
timeutils.set_time_override(timeutils.utcnow() +
1269
datetime.timedelta(hours=1))
1271
'start': str(timeutils.utcnow() - datetime.timedelta(hours=1)),
1272
'end': str(timeutils.utcnow())
1276
"""tearDown method for simple tenant usage"""
1277
super(SimpleTenantUsageSampleJsonTest, self).tearDown()
1278
timeutils.clear_time_override()
1280
def test_get_tenants_usage(self):
1281
"""Get api sample to get all tenants usage request"""
1282
response = self._do_get('os-simple-tenant-usage?%s' % (
1283
urllib.urlencode(self.query)))
1284
self.assertEqual(response.status, 200)
1285
subs = self._get_regexes()
1286
self._verify_response('simple-tenant-usage-get', subs, response)
1288
def test_get_tenant_usage_details(self):
1289
"""Get api sample to get specific tenant usage request"""
1290
tenant_id = 'openstack'
1291
response = self._do_get('os-simple-tenant-usage/%s?%s' % (tenant_id,
1292
urllib.urlencode(self.query)))
1293
self.assertEqual(response.status, 200)
1294
subs = self._get_regexes()
1295
self._verify_response('simple-tenant-usage-get-specific', subs,
1299
class SimpleTenantUsageSampleXmlTest(SimpleTenantUsageSampleJsonTest):
1303
class ServerDiagnosticsSamplesJsonTest(ServersSampleBase):
1304
extension_name = ("nova.api.openstack.compute.contrib.server_diagnostics."
1305
"Server_diagnostics")
1307
def test_server_diagnostics_get(self):
1308
uuid = self._post_server()
1309
response = self._do_get('servers/%s/diagnostics' % uuid)
1310
self.assertEqual(response.status, 200)
1311
subs = self._get_regexes()
1312
return self._verify_response('server-diagnostics-get-resp', subs,
1316
class ServerDiagnosticsSamplesXmlTest(ServerDiagnosticsSamplesJsonTest):
1320
class AvailabilityZoneJsonTest(ServersSampleBase):
1321
extension_name = ("nova.api.openstack.compute.contrib.availability_zone."
1322
"Availability_zone")
1324
def test_create_availability_zone(self):
1326
'image_id': fake.get_valid_image_id(),
1327
'host': self._get_host(),
1328
"availability_zone": "nova"
1330
response = self._do_post('servers', 'availability-zone-post-req', subs)
1331
self.assertEqual(response.status, 202)
1332
subs.update(self._get_regexes())
1333
return self._verify_response('availability-zone-post-resp',
1337
class AvailabilityZoneXmlTest(AvailabilityZoneJsonTest):
1341
class AdminActionsSamplesJsonTest(ServersSampleBase):
1342
extension_name = ("nova.api.openstack.compute.contrib.admin_actions."
1346
"""setUp Method for AdminActions api samples extension
1347
This method creates the server that will be used in each tests"""
1348
super(AdminActionsSamplesJsonTest, self).setUp()
1349
self.uuid = self._post_server()
1351
def test_post_pause(self):
1352
"""Get api samples to pause server request"""
1353
response = self._do_post('servers/%s/action' % self.uuid,
1354
'admin-actions-pause', {})
1355
self.assertEqual(response.status, 202)
1357
def test_post_unpause(self):
1358
"""Get api samples to unpause server request"""
1359
self.test_post_pause()
1360
response = self._do_post('servers/%s/action' % self.uuid,
1361
'admin-actions-unpause', {})
1362
self.assertEqual(response.status, 202)
1364
def test_post_suspend(self):
1365
"""Get api samples to suspend server request"""
1366
response = self._do_post('servers/%s/action' % self.uuid,
1367
'admin-actions-suspend', {})
1368
self.assertEqual(response.status, 202)
1370
def test_post_resume(self):
1371
"""Get api samples to server resume request"""
1372
self.test_post_suspend()
1373
response = self._do_post('servers/%s/action' % self.uuid,
1374
'admin-actions-resume', {})
1375
self.assertEqual(response.status, 202)
1377
def test_post_migrate(self):
1378
"""Get api samples to migrate server request"""
1379
response = self._do_post('servers/%s/action' % self.uuid,
1380
'admin-actions-migrate', {})
1381
self.assertEqual(response.status, 202)
1383
def test_post_reset_network(self):
1384
"""Get api samples to reset server network request"""
1385
response = self._do_post('servers/%s/action' % self.uuid,
1386
'admin-actions-reset-network', {})
1387
self.assertEqual(response.status, 202)
1389
def test_post_inject_network_info(self):
1390
"""Get api samples to inject network info request"""
1391
response = self._do_post('servers/%s/action' % self.uuid,
1392
'admin-actions-inject-network-info', {})
1393
self.assertEqual(response.status, 202)
1395
def test_post_lock_server(self):
1396
"""Get api samples to lock server request"""
1397
response = self._do_post('servers/%s/action' % self.uuid,
1398
'admin-actions-lock-server', {})
1399
self.assertEqual(response.status, 202)
1401
def test_post_unlock_server(self):
1402
"""Get api samples to unlock server request"""
1403
self.test_post_lock_server()
1404
response = self._do_post('servers/%s/action' % self.uuid,
1405
'admin-actions-unlock-server', {})
1406
self.assertEqual(response.status, 202)
1408
def test_post_backup_server(self):
1409
"""Get api samples to backup server request"""
1410
def image_details(self, context, **kwargs):
1411
"""This stub is specifically used on the backup action."""
1412
# NOTE(maurosr): I've added this simple stub cause backup action
1413
# was trapped in infinite loop during fetch image phase since the
1414
# fake Image Service always returns the same set of images
1417
self.stubs.Set(fake._FakeImageService, 'detail', image_details)
1419
response = self._do_post('servers/%s/action' % self.uuid,
1420
'admin-actions-backup-server', {})
1421
self.assertEqual(response.status, 202)
1423
def test_post_live_migrate_server(self):
1424
"""Get api samples to server live migrate request"""
1425
def fake_live_migration_src_check(self, context, instance_ref):
1426
"""Skip live migration scheduler checks"""
1429
def fake_live_migration_dest_check(self, context, instance_ref, dest):
1430
"""Skip live migration scheduler checks"""
1433
def fake_live_migration_common(self, context, instance_ref, dest):
1434
"""Skip live migration scheduler checks"""
1436
self.stubs.Set(driver.Scheduler, '_live_migration_src_check',
1437
fake_live_migration_src_check)
1438
self.stubs.Set(driver.Scheduler, '_live_migration_dest_check',
1439
fake_live_migration_dest_check)
1440
self.stubs.Set(driver.Scheduler, '_live_migration_common_check',
1441
fake_live_migration_common)
1443
def fake_get_compute(context, host):
1444
service = dict(host=host,
1445
binary='nova-compute',
1449
hypervisor_type='bar',
1450
hypervisor_version='1',
1452
return [{'compute_node': [service]}]
1453
self.stubs.Set(db, "service_get_all_compute_by_host", fake_get_compute)
1455
response = self._do_post('servers/%s/action' % self.uuid,
1456
'admin-actions-live-migrate',
1457
{'hostname': self.compute.host})
1458
self.assertEqual(response.status, 202)
1460
def test_post_reset_state(self):
1461
"""get api samples to server reset state request"""
1462
response = self._do_post('servers/%s/action' % self.uuid,
1463
'admin-actions-reset-server-state', {})
1464
self.assertEqual(response.status, 202)
1467
class AdminActionsSamplesXmlTest(AdminActionsSamplesJsonTest):
1471
class ConsolesSampleJsonTests(ServersSampleBase):
1472
extension_name = ("nova.api.openstack.compute.contrib"
1473
".consoles.Consoles")
1475
def test_get_vnc_console(self):
1476
uuid = self._post_server()
1477
response = self._do_post('servers/%s/action' % uuid,
1478
'get-vnc-console-post-req',
1479
{'action': 'os-getVNCConsole'})
1480
self.assertEqual(response.status, 200)
1481
subs = self._get_regexes()
1483
"((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"
1484
return self._verify_response('get-vnc-console-post-resp',
1488
class ConsoleOutputSampleXmlTests(ConsoleOutputSampleJsonTest):