1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
|
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2011 OpenStack Foundation
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import datetime
import re
from urllib import parse
import mock
from oslo_utils import strutils
import novaclient
from novaclient import api_versions
from novaclient import client as base_client
from novaclient import exceptions
from novaclient.tests.unit import fakes
from novaclient.tests.unit import utils
from novaclient.v2 import client
# regex to compare callback to result of get_endpoint()
# checks version number (vX or vX.X where X is a number)
# and also checks if the id is on the end
ENDPOINT_RE = re.compile(
r"^get_http:__nova_api:8774_v\d(_\d)?_\w{32}$")
# accepts formats like v2 or v2.1
ENDPOINT_TYPE_RE = re.compile(r"^v\d(\.\d)?$")
# accepts formats like v2 or v2_1
CALLBACK_RE = re.compile(r"^get_http:__nova_api:8774_v\d(_\d)?$")
# fake image uuids
FAKE_IMAGE_UUID_1 = 'c99d7632-bd66-4be9-aed5-3dd14b223a76'
FAKE_IMAGE_UUID_2 = 'f27f479a-ddda-419a-9bbc-d6b56b210161'
FAKE_IMAGE_UUID_SNAPSHOT = '555cae93-fb41-4145-9c52-f5b923538a26'
FAKE_IMAGE_UUID_SNAP_DEL = '55bb23af-97a4-4068-bdf8-f10c62880ddf'
FAKE_IMAGE_UUID_BACKUP = '2f87e889-41a4-4778-8553-83f5eea68c5d'
# fake request id
FAKE_REQUEST_ID = fakes.FAKE_REQUEST_ID
FAKE_REQUEST_ID_LIST = fakes.FAKE_REQUEST_ID_LIST
FAKE_RESPONSE_HEADERS = {'x-openstack-request-id': FAKE_REQUEST_ID}
FAKE_SERVICE_UUID_1 = '75e9eabc-ed3b-4f11-8bba-add1e7e7e2de'
FAKE_SERVICE_UUID_2 = '1f140183-c914-4ddf-8757-6df73028aa86'
SERVER_TOPOLOGY = {
"nodes": [
{
"cpu_pinning": {
"0": 0,
"1": 5
},
"host_node": 0,
"memory_mb": 1024,
"siblings": [
[
0,
1
]
],
"vcpu_set": [
0,
1
]
},
{
"cpu_pinning": {
"2": 1,
"3": 8
},
"host_node": 1,
"memory_mb": 2048,
"siblings": [
[
2,
3
]
],
"vcpu_set": [
2,
3
]
}
],
"pagesize_kb": 4
}
class FakeClient(fakes.FakeClient, client.Client):
def __init__(self, api_version, *args, **kwargs):
client.Client.__init__(self, username='username', password='password',
project_id='project_id', auth_url='auth_url',
extensions=kwargs.get('extensions'),
direct_use=False, api_version=api_version)
self.client = FakeSessionClient(api_version=api_version, **kwargs)
class FakeSessionClient(base_client.SessionClient):
def __init__(self, *args, **kwargs):
self.callstack = []
self.visited = []
self.auth = mock.Mock()
self.session = mock.Mock()
self.service_type = 'service_type'
self.service_name = None
self.endpoint_override = None
self.interface = None
self.region_name = None
self.version = None
self.api_version = kwargs.get('api_version')
self.auth.get_auth_ref.return_value.project_id = 'tenant_id'
# determines which endpoint to return in get_endpoint()
# NOTE(augustina): this is a hacky workaround, ultimately
# we need to fix our whole mocking architecture (fixtures?)
if 'endpoint_type' in kwargs:
self.endpoint_type = kwargs['endpoint_type']
else:
self.endpoint_type = 'endpoint_type'
self.logger = mock.MagicMock()
def get_endpoint(self, **kwargs):
# check if endpoint matches expected format (eg, v2.1)
if (hasattr(self, 'endpoint_type') and
ENDPOINT_TYPE_RE.search(self.endpoint_type)):
return "http://nova-api:8774/%s/" % self.endpoint_type
else:
return (
"http://nova-api:8774/v2.1/190a755eef2e4aac9f06aa6be9786385")
def request(self, url, method, **kwargs):
return self._cs_request(url, method, **kwargs)
def _cs_request(self, url, method, **kwargs):
# Check that certain things are called correctly
if method in ['GET', 'DELETE']:
assert 'body' not in kwargs
elif method == 'PUT':
assert 'body' in kwargs
if url is not None:
# Call the method
args = parse.parse_qsl(parse.urlparse(url)[4])
kwargs.update(args)
munged_url = url.rsplit('?', 1)[0]
munged_url = munged_url.strip('/').replace('/', '_')
munged_url = munged_url.replace('.', '_')
munged_url = munged_url.replace('-', '_')
munged_url = munged_url.replace(' ', '_')
munged_url = munged_url.replace('!', '_')
munged_url = munged_url.replace('@', '_')
munged_url = munged_url.replace('%20', '_')
munged_url = munged_url.replace('%3A', '_')
munged_url = munged_url.replace('%', '_')
callback = "%s_%s" % (method.lower(), munged_url)
if url is None or callback == "get_http:__nova_api:8774":
# To get API version information, it is necessary to GET
# a nova endpoint directly without "v2/<tenant-id>".
callback = "get_versions"
elif CALLBACK_RE.search(callback):
callback = "get_current_version"
elif ENDPOINT_RE.search(callback):
# compare callback to result of get_endpoint()
# NOTE(sdague): if we try to call a thing that doesn't
# exist, just return a 404. This allows the stack to act
# more like we'd expect when making REST calls.
raise exceptions.NotFound('404')
# Handle fake glance v2 requests
v2_image = False
if callback.startswith('get_v2_images'):
v2_image = True
callback = callback.replace('get_v2_', 'get_')
simulate_pagination_next_links = [
'get_os_simple_tenant_usage',
'get_os_simple_tenant_usage_tenant_id',
]
if callback in simulate_pagination_next_links:
while callback in self.visited:
callback += '_next'
if not hasattr(self, callback):
raise AssertionError('Called unknown API method: %s %s, '
'expected fakes method name: %s' %
(method, url, callback))
# Note the call
self.visited.append(callback)
self.callstack.append((method, url, kwargs.get('body')))
status, headers, body = getattr(self, callback)(**kwargs)
# If we're dealing with a glance v2 image response, the response
# isn't wrapped like the compute images API proxy is, so handle that.
if body and v2_image and 'image' in body:
body = body['image']
r = utils.TestResponse({
"status_code": status,
"text": body,
"headers": headers,
})
if status >= 400:
raise exceptions.from_response(r, body, url, method)
return r, body
def get_versions(self):
return (200, FAKE_RESPONSE_HEADERS, {
"versions": [
{"status": "SUPPORTED", "updated": "2011-01-21T11:33:21Z",
"links": [{"href": "http://nova-api:8774/v2/",
"rel": "self"}],
"min_version": "",
"version": "",
"id": "v2.0"},
{"status": "CURRENT", "updated": "2013-07-23T11:33:21Z",
"links": [{"href": "http://nova-api:8774/v2.1/",
"rel": "self"}],
"min_version": novaclient.API_MIN_VERSION.get_string(),
"version": novaclient.API_MAX_VERSION.get_string(),
"id": "v2.1"}
]})
def get_current_version(self):
versions = {
# v2 doesn't contain version or min_version fields
"v2": {
"version": {
"status": "SUPPORTED",
"updated": "2011-01-21T11:33:21Z",
"links": [{
"href": "http://nova-api:8774/v2/",
"rel": "self"
}],
"id": "v2.0"
}
},
"v2.1": {
"version": {
"status": "CURRENT",
"updated": "2013-07-23T11:33:21Z",
"links": [{
"href": "http://nova-api:8774/v2.1/",
"rel": "self"
}],
"min_version": novaclient.API_MIN_VERSION.get_string(),
"version": novaclient.API_MAX_VERSION.get_string(),
"id": "v2.1"
}
}
}
# if an endpoint_type that matches a version wasn't initialized,
# default to v2.1
endpoint = 'v2.1'
if hasattr(self, 'endpoint_type'):
if ENDPOINT_TYPE_RE.search(self.endpoint_type):
if self.endpoint_type in versions:
endpoint = self.endpoint_type
else:
raise AssertionError(
"Unknown endpoint_type:%s" % self.endpoint_type)
return (200, FAKE_RESPONSE_HEADERS, versions[endpoint])
#
# agents
#
def get_os_agents(self, **kw):
hypervisor = kw.get('hypervisor', 'kvm')
return (200, {}, {
'agents':
[{'hypervisor': hypervisor,
'os': 'win',
'architecture': 'x86',
'version': '7.0',
'url': 'xxx://xxxx/xxx/xxx',
'md5hash': 'add6bb58e139be103324d04d82d8f545',
'id': 1},
{'hypervisor': hypervisor,
'os': 'linux',
'architecture': 'x86',
'version': '16.0',
'url': 'xxx://xxxx/xxx/xxx1',
'md5hash': 'add6bb58e139be103324d04d82d8f546',
'id': 2}]})
def post_os_agents(self, body):
return (200, {}, {'agent': {
'url': '/xxx/xxx/xxx',
'hypervisor': body['agent']['hypervisor'],
'md5hash': 'add6bb58e139be103324d04d82d8f546',
'version': '7.0',
'architecture': 'x86',
'os': 'win',
'id': 1}})
def delete_os_agents_1(self, **kw):
return (202, {}, None)
def put_os_agents_1(self, body, **kw):
return (200, {}, {
"agent": {"url": "/yyy/yyyy/yyyy",
"version": "8.0",
"md5hash": "add6bb58e139be103324d04d82d8f546",
'id': 1}})
#
# Limits
#
def get_limits(self, **kw):
absolute = {
"maxTotalRAMSize": 51200,
"maxServerMeta": 5,
"maxImageMeta": 5
}
# 2.57 removes injected_file* entries from the response.
if self.api_version < api_versions.APIVersion('2.57'):
absolute.update({"maxPersonality": 5, "maxPersonalitySize": 10240})
return (200, {}, {"limits": {
"rate": [
{
"uri": "*",
"regex": ".*",
"limit": [
{
"value": 10,
"verb": "POST",
"remaining": 2,
"unit": "MINUTE",
"next-available": "2011-12-15T22:42:45Z"
},
{
"value": 10,
"verb": "PUT",
"remaining": 2,
"unit": "MINUTE",
"next-available": "2011-12-15T22:42:45Z"
},
{
"value": 100,
"verb": "DELETE",
"remaining": 100,
"unit": "MINUTE",
"next-available": "2011-12-15T22:42:45Z"
}
]
},
{
"uri": "*/servers",
"regex": "^/servers",
"limit": [
{
"verb": "POST",
"value": 25,
"remaining": 24,
"unit": "DAY",
"next-available": "2011-12-15T22:42:45Z"
}
]
}
],
"absolute": absolute,
}})
#
# Servers
#
def get_servers(self, **kw):
servers = {"servers": [
{'id': '1234', 'name': 'sample-server'},
{'id': '5678', 'name': 'sample-server2'},
{'id': '9014', 'name': 'help'}
]}
if self.api_version >= api_versions.APIVersion('2.69'):
# include "partial results" from non-responsive part of
# infrastructure.
servers['servers'].append(
{'id': '9015',
'status': "UNKNOWN",
"links": [
{
"href": "http://fake/v2.1/",
"rel": "self"
},
{
"href": "http://fake",
"rel": "bookmark"
}
]}
)
return (200, {}, servers)
def get_servers_detail(self, **kw):
servers = {"servers": [
{
"id": '1234',
"name": "sample-server",
"image": {
"id": FAKE_IMAGE_UUID_2,
"name": "sample image",
},
"flavor": {
"id": 1,
"name": "256 MiB Server",
},
"hostId": "e4d909c290d0fb1ca068ffaddf22cbd0",
"status": "BUILD",
"progress": 60,
"addresses": {
"public": [
{
"version": 4,
"addr": "1.2.3.4",
},
{
"version": 4,
"addr": "5.6.7.8",
}],
"private": [{
"version": 4,
"addr": "10.11.12.13",
}],
},
"metadata": {
"Server Label": "Web Head 1",
"Image Version": "2.1"
},
"OS-EXT-SRV-ATTR:host": "computenode1",
"security_groups": [{
'id': 1, 'name': 'securitygroup1',
'description': 'FAKE_SECURITY_GROUP',
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7'
}],
"OS-EXT-MOD:some_thing": "mod_some_thing_value",
},
{
"id": '5678',
"name": "sample-server2",
"image": {
"id": FAKE_IMAGE_UUID_1,
"name": "sample image",
},
"flavor": {
"id": 1,
"name": "256 MiB Server",
},
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
"addresses": {
"public": [
{
"version": 4,
"addr": "4.5.6.7",
},
{
"version": 4,
"addr": "5.6.9.8",
}],
"private": [{
"version": 4,
"addr": "10.13.12.13",
}],
},
"metadata": {
"Server Label": "DB 1"
},
"OS-EXT-SRV-ATTR:host": "computenode2",
"security_groups": [
{
'id': 1, 'name': 'securitygroup1',
'description': 'FAKE_SECURITY_GROUP',
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7'
},
{
'id': 2, 'name': 'securitygroup2',
'description': 'ANOTHER_FAKE_SECURITY_GROUP',
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7'
}],
},
{
"id": '9012',
"name": "sample-server3",
"image": "",
"flavor": {
"id": 1,
"name": "256 MiB Server",
},
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
"addresses": {
"public": [
{
"version": 4,
"addr": "4.5.6.7",
},
{
"version": 4,
"addr": "5.6.9.8",
}],
"private": [{
"version": 4,
"addr": "10.13.12.13",
}],
},
"metadata": {
"Server Label": "DB 1"
}
},
{
"id": '9013',
"name": "sample-server4",
"flavor": {
"id": '80645cf4-6ad3-410a-bbc8-6f3e1e291f51',
},
"image": {
"id": '3e861307-73a6-4d1f-8d68-f68b03223032',
},
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
},
{
"id": '9014',
"name": "help",
"flavor": {
"id": '80645cf4-6ad3-410a-bbc8-6f3e1e291f51',
},
"image": {
"id": '3e861307-73a6-4d1f-8d68-f68b03223032',
},
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
},
]}
if self.api_version >= api_versions.APIVersion('2.69'):
# include "partial results" from non-responsive part of
# infrastructure.
servers['servers'].append(
{
"id": "9015",
"status": "UNKNOWN",
"tenant_id": "6f70656e737461636b20342065766572",
"created": "2018-12-03T21:06:18Z",
"links": [
{
"href": "http://fake/v2.1/",
"rel": "self"
},
{
"href": "http://fake",
"rel": "bookmark"
}
]
}
)
return (200, {}, servers)
def post_servers(self, body, **kw):
assert set(body.keys()) <= set(['server', 'os:scheduler_hints'])
fakes.assert_has_keys(
body['server'],
required=['name', 'imageRef', 'flavorRef'],
optional=['metadata', 'personality'])
if 'personality' in body['server']:
for pfile in body['server']['personality']:
fakes.assert_has_keys(pfile, required=['path', 'contents'])
if body['server']['name'] == 'some-bad-server':
return (202, {}, self.get_servers_1235()[2])
else:
return (202, {}, self.get_servers_1234()[2])
def post_os_volumes_boot(self, body, **kw):
assert set(body.keys()) <= set(['server', 'os:scheduler_hints'])
fakes.assert_has_keys(
body['server'],
required=['name', 'flavorRef'],
optional=['imageRef'])
# Require one, and only one, of the keys for bdm
if 'block_device_mapping' not in body['server']:
if 'block_device_mapping_v2' not in body['server']:
raise AssertionError(
"missing required keys: 'block_device_mapping'"
)
elif 'block_device_mapping_v2' in body['server']:
raise AssertionError("found extra keys: 'block_device_mapping'")
return (202, {}, self.get_servers_9012()[2])
def get_servers_1234(self, **kw):
server = self.get_servers_detail()[2]['servers'][0]
if self.api_version >= api_versions.APIVersion('2.71'):
server.update(
{'server_groups': ['a67359fb-d397-4697-88f1-f55e3ee7c499']})
return (200, {}, {'server': server})
def get_servers_1235(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][0]}
r['server']['id'] = '1235'
r['server']['status'] = 'error'
r['server']['fault'] = {'message': 'something went wrong!'}
return (200, {}, r)
def get_servers_5678(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][1]}
return (200, {}, r)
def get_servers_9012(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][2]}
return (200, {}, r)
def get_servers_9013(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][3]}
return (200, {}, r)
def get_servers_9014(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][4]}
return (200, {}, r)
def get_servers_9015(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][5]}
r['server']["OS-EXT-AZ:availability_zone"] = 'geneva'
r['server']["OS-EXT-STS:power_state"] = 0
flavor = {
"disk": 1,
"ephemeral": 0,
"original_name": "m1.tiny",
"ram": 512,
"swap": 0,
"vcpus": 1,
"extra_specs": {}
}
image = {
"id": "c99d7632-bd66-4be9-aed5-3dd14b223a76",
}
r['server']['image'] = image
r['server']['flavor'] = flavor
r['server']['user_id'] = "fake"
return (200, {}, r)
def delete_os_server_groups_12345(self, **kw):
return (202, {}, None)
def delete_os_server_groups_56789(self, **kw):
return (202, {}, None)
def delete_servers_1234(self, **kw):
return (202, {}, None)
def delete_servers_5678(self, **kw):
return (202, {}, None)
def delete_servers_1234_metadata_key1(self, **kw):
return (204, {}, None)
def delete_servers_1234_metadata_key2(self, **kw):
return (204, {}, None)
def post_servers_1234_metadata(self, **kw):
return (204, {}, {'metadata': {'test_key': 'test_value'}})
def get_servers_1234_diagnostics(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def post_servers_uuid1_metadata(self, **kw):
return (204, {}, {'metadata': {'key1': 'val1'}})
def post_servers_uuid2_metadata(self, **kw):
return (204, {}, {'metadata': {'key1': 'val1'}})
def post_servers_uuid3_metadata(self, **kw):
return (204, {}, {'metadata': {'key1': 'val1'}})
def post_servers_uuid4_metadata(self, **kw):
return (204, {}, {'metadata': {'key1': 'val1'}})
def post_servers_uuid5_metadata(self, **kw):
return (204, {}, {'metadata': {'key1': 'val1'}})
def post_servers_uuid6_metadata(self, **kw):
return (204, {}, {'metadata': {'key1': 'val1'}})
def delete_servers_uuid1_metadata_key1(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def delete_servers_uuid2_metadata_key1(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def delete_servers_uuid3_metadata_key1(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def delete_servers_uuid4_metadata_key1(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def delete_servers_uuid5_metadata_key1(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def delete_servers_uuid6_metadata_key1(self, **kw):
return (200, {}, {'data': 'Fake diagnostics'})
def get_servers_1234_os_security_groups(self, **kw):
return (200, {}, {
"security_groups": [{
'id': 1,
'name': 'securitygroup1',
'description': 'FAKE_SECURITY_GROUP',
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7',
'rules': []}]
})
def get_servers_1234_topology(self, **kw):
return 200, {}, SERVER_TOPOLOGY
#
# Server password
#
# Testing with the following password and key
#
# Clear password: FooBar123
#
# RSA Private Key: novaclient/tests/unit/idfake.pem
#
# Encrypted password
# OIuEuQttO8Rk93BcKlwHQsziDAnkAm/V6V8VPToA8ZeUaUBWwS0gwo2K6Y61Z96r
# qG447iRz0uTEEYq3RAYJk1mh3mMIRVl27t8MtIecR5ggVVbz1S9AwXJQypDKl0ho
# QFvhCBcMWPohyGewDJOhDbtuN1IoFI9G55ZvFwCm5y7m7B2aVcoLeIsJZE4PLsIw
# /y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N
# tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk
# Hi/fmZZNQQqj1Ijq0caOIw==
def get_servers_1234_os_server_password(self, **kw):
return (200, {}, {
'password':
'OIuEuQttO8Rk93BcKlwHQsziDAnkAm/V6V8VPToA8ZeUaUBWwS0gwo2K6Y61Z96r'
'qG447iRz0uTEEYq3RAYJk1mh3mMIRVl27t8MtIecR5ggVVbz1S9AwXJQypDKl0ho'
'QFvhCBcMWPohyGewDJOhDbtuN1IoFI9G55ZvFwCm5y7m7B2aVcoLeIsJZE4PLsIw'
'/y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N'
'tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk'
'Hi/fmZZNQQqj1Ijq0caOIw=='})
def delete_servers_1234_os_server_password(self, **kw):
return (202, {}, None)
#
# Server actions
#
none_actions = ['revertResize', 'os-stop', 'os-start',
'forceDelete', 'restore', 'pause', 'unpause', 'unlock',
'unrescue', 'resume', 'suspend', 'shelve',
'shelveOffload', 'resetNetwork']
type_actions = ['os-getVNCConsole', 'os-getSPICEConsole',
'os-getRDPConsole']
@classmethod
def check_server_actions(cls, body):
action = list(body)[0]
if action == 'reboot':
assert list(body[action]) == ['type']
assert body[action]['type'] in ['HARD', 'SOFT']
elif action == 'resize':
assert 'flavorRef' in body[action]
elif action in cls.none_actions:
assert body[action] is None
elif action == 'changePassword':
assert list(body[action]) == ['adminPass']
elif action in cls.type_actions:
assert list(body[action]) == ['type']
elif action == 'os-resetState':
assert list(body[action]) == ['state']
elif action == 'resetNetwork':
assert body[action] is None
elif action in ['addSecurityGroup', 'removeSecurityGroup']:
assert list(body[action]) == ['name']
elif action == 'trigger_crash_dump':
assert body[action] is None
else:
return False
return True
def post_servers_1234_action(self, body, **kw):
_headers = dict()
_body = None
resp = 202
assert len(body.keys()) == 1
action = list(body)[0]
if self.check_server_actions(body):
# NOTE(snikitin): No need to do any operations here. This 'pass'
# is needed to avoid AssertionError in the last 'else' statement
# if we found 'action' in method check_server_actions and
# raise AssertionError if we didn't find 'action' at all.
pass
elif action == 'os-migrateLive':
expected = set(['host', 'block_migration'])
if self.api_version >= api_versions.APIVersion("2.30"):
if 'force' in body[action].keys():
# force can be optional
expected.add('force')
if self.api_version < api_versions.APIVersion("2.25"):
expected.add('disk_over_commit')
assert set(body[action].keys()) == expected
elif action == 'migrate':
if self.api_version < api_versions.APIVersion("2.56"):
assert body[action] is None
else:
expected = set()
if 'host' in body[action].keys():
# host can be optional
expected.add('host')
assert set(body[action].keys()) == expected
elif action == 'lock':
if self.api_version < api_versions.APIVersion("2.73"):
assert body[action] is None
else:
# In 2.73 and above, we allow body to be one of these:
# a) {'lock': None}
# b) {'lock': {}}
# c) {'lock': {locked_reason': 'blah'}}
if body[action] is not None:
expected = set()
if 'locked_reason' in body[action].keys():
# reason can be optional
expected.add('locked_reason')
assert set(body[action].keys()) == expected
else:
assert body[action] is None
elif action == 'unshelve':
if self.api_version < api_versions.APIVersion("2.77"):
assert body[action] is None
else:
# In 2.77 and above, we allow body to be one of these:
# {'unshelve': None}
# {'unshelve': {'availability_zone': 'foo-az'}}
if body[action] is not None:
assert set(body[action].keys()) == set(
['availability_zone'])
elif action == 'rebuild':
body = body[action]
adminPass = body.get('adminPass', 'randompassword')
assert 'imageRef' in body
_body = self.get_servers_1234()[2]
_body['server']['adminPass'] = adminPass
elif action == 'confirmResize':
assert body[action] is None
# This one method returns a different response code
return (204, {}, None)
elif action == 'rescue':
if body[action]:
keys = set(body[action].keys())
assert not (keys - set(['adminPass', 'rescue_image_ref']))
else:
assert body[action] is None
_body = {'adminPass': 'RescuePassword'}
elif action == 'createImage':
assert set(body[action].keys()) == set(['name', 'metadata'])
if self.api_version < api_versions.APIVersion('2.45'):
_headers = dict(location="http://blah/images/%s" %
FAKE_IMAGE_UUID_SNAPSHOT)
else:
_body = {'image_id': FAKE_IMAGE_UUID_SNAPSHOT}
if body[action]['name'] == 'mysnapshot_deleted':
_headers = dict(location="http://blah/images/%s" %
FAKE_IMAGE_UUID_SNAP_DEL)
elif action == 'createBackup':
assert set(body[action].keys()) == set(['name', 'backup_type',
'rotation'])
if self.api_version < api_versions.APIVersion('2.45'):
_headers = dict(location="http://blah/images/%s" %
FAKE_IMAGE_UUID_BACKUP)
else:
_body = {'image_id': FAKE_IMAGE_UUID_BACKUP}
elif action == 'os-getConsoleOutput':
assert list(body[action]) == ['length']
return (202, {}, {'output': 'foo'})
elif action == 'evacuate':
keys = list(body[action])
if 'adminPass' in keys:
keys.remove('adminPass')
if 'host' in keys:
keys.remove('host')
if 'onSharedStorage' in keys:
keys.remove('onSharedStorage')
if 'force' in keys:
keys.remove('force')
assert set(keys) == set()
else:
raise AssertionError("Unexpected server action: %s" % action)
_headers.update(FAKE_RESPONSE_HEADERS)
return (resp, _headers, _body)
def post_servers_5678_action(self, body, **kw):
return self.post_servers_1234_action(body, **kw)
#
# Flavors
#
def get_flavors(self, **kw):
status, header, flavors = self.get_flavors_detail(**kw)
included_fields = ['id', 'name']
if self.api_version >= api_versions.APIVersion('2.55'):
included_fields.append('description')
if self.api_version >= api_versions.APIVersion('2.61'):
included_fields.append('extra_specs')
for flavor in flavors['flavors']:
for k in list(flavor):
if k not in included_fields:
del flavor[k]
return (200, FAKE_RESPONSE_HEADERS, flavors)
def get_flavors_detail(self, **kw):
flavors = {'flavors': [
{'id': 1, 'name': '256 MiB Server', 'ram': 256, 'disk': 10,
'OS-FLV-EXT-DATA:ephemeral': 10,
'os-flavor-access:is_public': True,
'links': {}},
{'id': 2, 'name': '512 MiB Server', 'ram': 512, 'disk': 20,
'OS-FLV-EXT-DATA:ephemeral': 20,
'os-flavor-access:is_public': False,
'links': {}},
{'id': 4, 'name': '1024 MiB Server', 'ram': 1024, 'disk': 10,
'OS-FLV-EXT-DATA:ephemeral': 10,
'os-flavor-access:is_public': True,
'links': {}},
{'id': 'aa1', 'name': '128 MiB Server', 'ram': 128, 'disk': 0,
'OS-FLV-EXT-DATA:ephemeral': 0,
'os-flavor-access:is_public': True,
'links': {}}
]}
if 'is_public' not in kw:
filter_is_public = True
else:
if kw['is_public'].lower() == 'none':
filter_is_public = None
else:
filter_is_public = strutils.bool_from_string(kw['is_public'],
True)
if filter_is_public is not None:
if filter_is_public:
flavors['flavors'] = [
v for v in flavors['flavors']
if v['os-flavor-access:is_public']
]
else:
flavors['flavors'] = [
v for v in flavors['flavors']
if not v['os-flavor-access:is_public']
]
# Add description in the response for all flavors.
if self.api_version >= api_versions.APIVersion('2.55'):
for flavor in flavors['flavors']:
flavor['description'] = None
# Add a new flavor that is a copy of the first but with a different
# name, flavorid and a description set.
new_flavor = copy.deepcopy(flavors['flavors'][0])
new_flavor['id'] = 'with-description'
new_flavor['name'] = 'with-description'
new_flavor['description'] = 'test description'
flavors['flavors'].append(new_flavor)
# Add extra_specs in the response for all flavors.
if self.api_version >= api_versions.APIVersion('2.61'):
for flavor in flavors['flavors']:
flavor['extra_specs'] = {'test': 'value'}
return (200, FAKE_RESPONSE_HEADERS, flavors)
def get_flavors_1(self, **kw):
return (
200,
FAKE_RESPONSE_HEADERS,
{'flavor':
self.get_flavors_detail(is_public='None')[2]['flavors'][0]}
)
def get_flavors_2(self, **kw):
return (
200,
{},
{'flavor':
self.get_flavors_detail(is_public='None')[2]['flavors'][1]}
)
def get_flavors_3(self, **kw):
# Diablo has no ephemeral
return (
200,
FAKE_RESPONSE_HEADERS,
{'flavor': {
'id': 3,
'name': '256 MiB Server',
'ram': 256,
'disk': 10,
}},
)
def get_flavors_512_MiB_Server(self, **kw):
raise exceptions.NotFound('404')
def get_flavors_128_MiB_Server(self, **kw):
raise exceptions.NotFound('404')
def get_flavors_80645cf4_6ad3_410a_bbc8_6f3e1e291f51(self, **kw):
raise exceptions.NotFound('404')
def get_flavors_aa1(self, **kw):
# Alphanumeric flavor id are allowed.
return (
200,
FAKE_RESPONSE_HEADERS,
{'flavor':
self.get_flavors_detail(is_public='None')[2]['flavors'][3]}
)
def get_flavors_4(self, **kw):
return (
200,
{},
{'flavor':
self.get_flavors_detail(is_public='None')[2]['flavors'][2]}
)
def get_flavors_with_description(self, **kw):
return (
200,
{},
{'flavor':
self.get_flavors_detail(is_public='None')[2]['flavors'][-1]}
)
def delete_flavors_flavordelete(self, **kw):
return (202, FAKE_RESPONSE_HEADERS, None)
def delete_flavors_2(self, **kw):
return (202, FAKE_RESPONSE_HEADERS, None)
def post_flavors(self, body, **kw):
return (
202,
FAKE_RESPONSE_HEADERS,
{'flavor':
self.get_flavors_detail(is_public='None')[2]['flavors'][0]}
)
def put_flavors_with_description(self, body, **kw):
assert 'flavor' in body
assert 'description' in body['flavor']
flavor = self.get_flavors_with_description(**kw)[2]
# Fake out the actual update of the flavor description for the response
flavor['description'] = body['flavor']['description']
return (200, {}, {'flavor': flavor})
def get_flavors_1_os_extra_specs(self, **kw):
return (
200,
{},
{'extra_specs': {"k1": "v1"}})
def get_flavors_2_os_extra_specs(self, **kw):
return (
200,
{},
{'extra_specs': {"k2": "v2"}})
def get_flavors_aa1_os_extra_specs(self, **kw):
return (
200, {},
{'extra_specs': {"k3": "v3"}})
def get_flavors_4_os_extra_specs(self, **kw):
return (
200,
{},
{'extra_specs': {"k4": "v4"}})
def post_flavors_1_os_extra_specs(self, body, **kw):
assert list(body) == ['extra_specs']
fakes.assert_has_keys(body['extra_specs'],
required=['k1'])
return (
200,
FAKE_RESPONSE_HEADERS,
{'extra_specs': {"k1": "v1"}})
def post_flavors_4_os_extra_specs(self, body, **kw):
assert list(body) == ['extra_specs']
return (
200,
FAKE_RESPONSE_HEADERS,
body)
def delete_flavors_1_os_extra_specs_k1(self, **kw):
return (204, {}, None)
#
# Flavor access
#
def get_flavors_2_os_flavor_access(self, **kw):
return (
200, FAKE_RESPONSE_HEADERS,
{'flavor_access': [{'flavor_id': '2', 'tenant_id': 'proj1'},
{'flavor_id': '2', 'tenant_id': 'proj2'}]})
def post_flavors_2_action(self, body, **kw):
return (202, FAKE_RESPONSE_HEADERS,
self.get_flavors_2_os_flavor_access()[2])
#
# Images
#
def get_images(self, **kw):
images = [
{
"id": FAKE_IMAGE_UUID_SNAPSHOT,
"name": "My Server Backup",
"serverId": '1234',
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"status": "SAVING",
"progress": 80,
"links": {},
},
{
"id": FAKE_IMAGE_UUID_SNAP_DEL,
"name": "My Server Backup Deleted",
"serverId": '1234',
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"status": "DELETED",
"fault": {'message': 'Image has been deleted.'},
"links": {},
},
{
'id': FAKE_IMAGE_UUID_1,
'name': 'CentOS 5.2',
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"status": "ACTIVE",
"test_key": "test_value",
"links": {},
},
{
"id": FAKE_IMAGE_UUID_2,
"name": "My Server Backup",
"serverId": '1234',
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"status": "SAVING",
"progress": 80,
"links": {},
},
{
"id": FAKE_IMAGE_UUID_BACKUP,
"name": "back1",
"serverId": '1234',
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"status": "SAVING",
"progress": 80,
"links": {},
},
]
if 'id' in kw:
requested = kw['id'].replace('in:', '').split(',')
images = [i for i in images if i['id'] in requested]
if 'names' in kw:
requested = kw['names'].replace('in:', '').split(',')
images = [i for i in images if i['name'] in requested]
return (200, {}, {'images': images})
def get_images_555cae93_fb41_4145_9c52_f5b923538a26(self, **kw):
return (200, {}, {'image': self.get_images()[2]['images'][0]})
def get_images_55bb23af_97a4_4068_bdf8_f10c62880ddf(self, **kw):
return (200, {}, {'image': self.get_images()[2]['images'][1]})
def get_images_c99d7632_bd66_4be9_aed5_3dd14b223a76(self, **kw):
return (200, {}, {'image': self.get_images()[2]['images'][2]})
def get_images_f27f479a_ddda_419a_9bbc_d6b56b210161(self, **kw):
return (200, {}, {'image': self.get_images()[2]['images'][3]})
def get_images_2f87e889_41a4_4778_8553_83f5eea68c5d(self, **kw):
return (200, {}, {'image': self.get_images()[2]['images'][4]})
def get_images_3e861307_73a6_4d1f_8d68_f68b03223032(self):
raise exceptions.NotFound('404')
#
# Keypairs
#
def get_os_keypairs_test(self, *kw):
return (200, {}, {'keypair':
self.get_os_keypairs()[2]['keypairs'][0]['keypair']})
def get_os_keypairs(self, user_id=None, limit=None, marker=None, *kw):
return (200, {}, {
"keypairs": [{"keypair": {
"public_key": "FAKE_SSH_RSA",
"private_key": "FAKE_PRIVATE_KEY",
"user_id": "81e373b596d6466e99c4896826abaa46",
"name": "test",
"deleted": False,
"created_at": "2014-04-19T02:16:44.000000",
"updated_at": "2014-04-19T10:12:3.000000",
"figerprint": "FAKE_KEYPAIR",
"deleted_at": None,
"id": 4}}
]})
def delete_os_keypairs_test(self, **kw):
return (202, {}, None)
def post_os_keypairs(self, body, **kw):
assert list(body) == ['keypair']
fakes.assert_has_keys(body['keypair'],
required=['name'])
r = {'keypair': self.get_os_keypairs()[2]['keypairs'][0]['keypair']}
return (202, {}, r)
#
# Quotas
#
def get_os_quota_sets_tenant_id(self, **kw):
return (200, {}, {
'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'keypairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def get_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, **kw):
return (200, {}, {
'quota_set': {
'tenant_id': '97f4c221bff44578b0300df4ef119353',
'metadata_items': [],
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'keypairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def get_os_quota_sets_97f4c221bff44578b0300df4ef119353_detail(self, **kw):
return (200, {}, {
'quota_set': {
'tenant_id': '97f4c221bff44578b0300df4ef119353',
'cores': {
'in_use': 0,
'limit': 20,
'reserved': 0
},
'fixed_ips': {
'in_use': 0,
'limit': -1,
'reserved': 0
},
'floating_ips': {
'in_use': 0,
'limit': 10,
'reserved': 0
},
'injected_file_content_bytes': {
'in_use': 0,
'limit': 10240,
'reserved': 0
},
'injected_file_path_bytes': {
'in_use': 0,
'limit': 255,
'reserved': 0
},
'injected_files': {
'in_use': 0,
'limit': 5,
'reserved': 0
},
'instances': {
'in_use': 0,
'limit': 10,
'reserved': 0
},
'key_pairs': {
'in_use': 0,
'limit': 100,
'reserved': 0
},
'metadata_items': {
'in_use': 0,
'limit': 128,
'reserved': 0
},
'ram': {
'in_use': 0,
'limit': 51200,
'reserved': 0
},
'security_group_rules': {
'in_use': 0,
'limit': 20,
'reserved': 0
},
'security_groups': {
'in_use': 0,
'limit': 10,
'reserved': 0
},
'server_group_members': {
'in_use': 0,
'limit': 10,
'reserved': 0
},
'server_groups': {
'in_use': 0,
'limit': 10,
'reserved': 0
}
}})
def get_os_quota_sets_97f4c221bff44578b0300df4ef119353_defaults(self):
return (200, {}, {
'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'keypairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def get_os_quota_sets_tenant_id_defaults(self):
return (200, {}, {
'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'keypairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def put_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, body, **kw):
assert list(body) == ['quota_set']
fakes.assert_has_keys(body['quota_set'])
return (200, {}, {
'quota_set': {
'tenant_id': '97f4c221bff44578b0300df4ef119353',
'metadata_items': [],
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'keypairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def delete_os_quota_sets_97f4c221bff44578b0300df4ef119353(self, **kw):
return (202, {}, {})
#
# Quota Classes
#
def get_os_quota_class_sets_test(self, **kw):
# 2.57 removes injected_file* entries from the response.
if self.api_version >= api_versions.APIVersion('2.57'):
return (200, FAKE_RESPONSE_HEADERS, {
'quota_class_set': {
'id': 'test',
'metadata_items': 1,
'ram': 1,
'instances': 1,
'cores': 1,
'key_pairs': 1,
'server_groups': 1,
'server_group_members': 1}})
if self.api_version >= api_versions.APIVersion('2.50'):
return (200, FAKE_RESPONSE_HEADERS, {
'quota_class_set': {
'id': 'test',
'metadata_items': 1,
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'key_pairs': 1,
'server_groups': 1,
'server_group_members': 1}})
return (200, FAKE_RESPONSE_HEADERS, {
'quota_class_set': {
'id': 'test',
'metadata_items': 1,
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'fixed_ips': -1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'key_pairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def put_os_quota_class_sets_test(self, body, **kw):
assert list(body) == ['quota_class_set']
# 2.57 removes injected_file* entries from the response.
if self.api_version >= api_versions.APIVersion('2.57'):
return (200, {}, {
'quota_class_set': {
'metadata_items': 1,
'ram': 1,
'instances': 1,
'cores': 1,
'key_pairs': 1,
'server_groups': 1,
'server_group_members': 1}})
if self.api_version >= api_versions.APIVersion('2.50'):
return (200, {}, {
'quota_class_set': {
'metadata_items': 1,
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'key_pairs': 1,
'server_groups': 1,
'server_group_members': 1}})
return (200, {}, {
'quota_class_set': {
'metadata_items': 1,
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'fixed_ips': -1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'key_pairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
def put_os_quota_class_sets_97f4c221bff44578b0300df4ef119353(self,
body, **kw):
assert list(body) == ['quota_class_set']
return (200, {}, {
'quota_class_set': {
'metadata_items': 1,
'injected_file_content_bytes': 1,
'injected_file_path_bytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
'key_pairs': 1,
'security_groups': 1,
'security_group_rules': 1}})
#
# Tenant Usage
#
def get_os_simple_tenant_usage(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usages': [{
'total_memory_mb_usage': 25451.762807466665,
'total_vcpus_usage': 49.71047423333333,
'total_hours': 49.71047423333333,
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'stop': '2012-01-22 19:48:41.750722',
'server_usages': [{
'hours': 49.71047423333333,
'uptime': 27035,
'local_gb': 0,
'ended_at': None,
'name': 'f15image1',
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
'vcpus': 1,
'memory_mb': 512,
'state': 'active',
'flavor': 'm1.tiny',
'started_at': '2012-01-20 18:06:06.479998',
}],
'start': '2011-12-25 19:48:41.750687',
'total_local_gb_usage': 0.0}]})
def get_os_simple_tenant_usage_next(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usages': [{
'total_memory_mb_usage': 25451.762807466665,
'total_vcpus_usage': 49.71047423333333,
'total_hours': 49.71047423333333,
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'stop': '2012-01-22 19:48:41.750722',
'server_usages': [{
'hours': 49.71047423333333,
'uptime': 27035,
'local_gb': 0,
'ended_at': None,
'name': 'f15image1',
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'instance_id': 'f079e394-2222-457b-b350-bb5ecc685cdd',
'vcpus': 1,
'memory_mb': 512,
'state': 'active',
'flavor': 'm1.tiny',
'started_at': '2012-01-20 18:06:06.479998',
}],
'start': '2011-12-25 19:48:41.750687',
'total_local_gb_usage': 0.0}]})
def get_os_simple_tenant_usage_next_next(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usages': []})
def get_os_simple_tenant_usage_tenantfoo(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usage': {
'total_memory_mb_usage': 25451.762807466665,
'total_vcpus_usage': 49.71047423333333,
'total_hours': 49.71047423333333,
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'stop': '2012-01-22 19:48:41.750722',
'server_usages': [{
'hours': 49.71047423333333,
'uptime': 27035, 'local_gb': 0,
'ended_at': None,
'name': 'f15image1',
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
'vcpus': 1, 'memory_mb': 512,
'state': 'active',
'flavor': 'm1.tiny',
'started_at': '2012-01-20 18:06:06.479998',
}],
'start': '2011-12-25 19:48:41.750687',
'total_local_gb_usage': 0.0}})
def get_os_simple_tenant_usage_test(self, **kw):
return (200, {}, {'tenant_usage': {
'total_memory_mb_usage': 25451.762807466665,
'total_vcpus_usage': 49.71047423333333,
'total_hours': 49.71047423333333,
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'stop': '2012-01-22 19:48:41.750722',
'server_usages': [{
'hours': 49.71047423333333,
'uptime': 27035, 'local_gb': 0,
'ended_at': None,
'name': 'f15image1',
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
'vcpus': 1, 'memory_mb': 512,
'state': 'active',
'flavor': 'm1.tiny',
'started_at': '2012-01-20 18:06:06.479998',
}],
'start': '2011-12-25 19:48:41.750687',
'total_local_gb_usage': 0.0}})
def get_os_simple_tenant_usage_tenant_id(self, **kw):
return (200, {}, {'tenant_usage': {
'total_memory_mb_usage': 25451.762807466665,
'total_vcpus_usage': 49.71047423333333,
'total_hours': 49.71047423333333,
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'stop': '2012-01-22 19:48:41.750722',
'server_usages': [{
'hours': 49.71047423333333,
'uptime': 27035, 'local_gb': 0,
'ended_at': None,
'name': 'f15image1',
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
'vcpus': 1, 'memory_mb': 512,
'state': 'active',
'flavor': 'm1.tiny',
'started_at': '2012-01-20 18:06:06.479998',
}],
'start': '2011-12-25 19:48:41.750687',
'total_local_gb_usage': 0.0}})
def get_os_simple_tenant_usage_tenant_id_next(self, **kw):
return (200, {}, {'tenant_usage': {
'total_memory_mb_usage': 25451.762807466665,
'total_vcpus_usage': 49.71047423333333,
'total_hours': 49.71047423333333,
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'stop': '2012-01-22 19:48:41.750722',
'server_usages': [{
'hours': 49.71047423333333,
'uptime': 27035, 'local_gb': 0,
'ended_at': None,
'name': 'f15image1',
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
'instance_id': 'f079e394-2222-457b-b350-bb5ecc685cdd',
'vcpus': 1, 'memory_mb': 512,
'state': 'active',
'flavor': 'm1.tiny',
'started_at': '2012-01-20 18:06:06.479998',
}],
'start': '2011-12-25 19:48:41.750687',
'total_local_gb_usage': 0.0}})
def get_os_simple_tenant_usage_tenant_id_next_next(self, **kw):
return (200, {}, {'tenant_usage': {}})
#
# Aggregates
#
def get_os_aggregates(self, *kw):
response = (200, {}, {"aggregates": [
{'id': '1',
'name': 'test',
'availability_zone': 'nova1'},
{'id': '2',
'name': 'test2',
'availability_zone': 'nova1'},
{'id': '3',
'name': 'test3',
'metadata': {'test': "dup", "none_key": "Nine"}},
]})
# microversion >= 2.41 returns the uuid in the response
if self.api_version >= api_versions.APIVersion('2.41'):
aggregates = response[2]['aggregates']
aggregates[0]['uuid'] = '80785864-087b-45a5-a433-b20eac9b58aa'
aggregates[1]['uuid'] = '30827713-5957-4b68-8fd3-ccaddb568c24'
aggregates[2]['uuid'] = '9a651b22-ce3f-4a87-acd7-98446ef591c4'
return response
def _return_aggregate(self):
r = {'aggregate': self.get_os_aggregates()[2]['aggregates'][0]}
return (200, {}, r)
def _return_aggregate_3(self):
r = {'aggregate': self.get_os_aggregates()[2]['aggregates'][2]}
return (200, {}, r)
def get_os_aggregates_1(self, **kw):
return self._return_aggregate()
def get_os_aggregates_3(self, **kw):
return self._return_aggregate_3()
def post_os_aggregates(self, body, **kw):
return self._return_aggregate()
def put_os_aggregates_1(self, body, **kw):
return self._return_aggregate()
def post_os_aggregates_1_action(self, body, **kw):
return self._return_aggregate()
def post_os_aggregates_3_action(self, body, **kw):
return self._return_aggregate_3()
def delete_os_aggregates_1(self, **kw):
return (202, {}, None)
def post_os_aggregates_1_images(self, body, **kw):
return (202, {}, None)
#
# Services
#
def get_os_services(self, **kw):
host = kw.get('host', 'host1')
binary = kw.get('binary', 'nova-compute')
if self.api_version >= api_versions.APIVersion('2.53'):
service_id_1 = FAKE_SERVICE_UUID_1
service_id_2 = FAKE_SERVICE_UUID_2
else:
service_id_1 = 1
service_id_2 = 2
services = {
'services': [
{'binary': binary,
'host': host,
'zone': 'nova',
'status': 'enabled',
'state': 'up',
'updated_at': datetime.datetime(
2012, 10, 29, 13, 42, 2),
'id': service_id_1},
{'binary': binary,
'host': host,
'zone': 'nova',
'status': 'disabled',
'state': 'down',
'updated_at': datetime.datetime(
2012, 9, 18, 8, 3, 38),
'id': service_id_2},
]
}
if self.api_version >= api_versions.APIVersion('2.69'):
services['services'].append(
{
"binary": "nova-compute",
"host": "host-down",
"status": "UNKNOWN"
}
)
return (200, FAKE_RESPONSE_HEADERS, services)
def put_os_services_enable(self, body, **kw):
return (200, FAKE_RESPONSE_HEADERS,
{'service': {'host': body['host'],
'binary': body['binary'],
'status': 'enabled'}})
def put_os_services_disable(self, body, **kw):
return (200, FAKE_RESPONSE_HEADERS,
{'service': {'host': body['host'],
'binary': body['binary'],
'status': 'disabled'}})
def put_os_services_disable_log_reason(self, body, **kw):
return (200, FAKE_RESPONSE_HEADERS, {'service': {
'host': body['host'],
'binary': body['binary'],
'status': 'disabled',
'disabled_reason': body['disabled_reason']}})
def put_os_services_75e9eabc_ed3b_4f11_8bba_add1e7e7e2de(
self, body, **kw):
"""This should only be called with microversion >= 2.53."""
return (200, FAKE_RESPONSE_HEADERS, {'service': {
'host': 'host1',
'binary': 'nova-compute',
'status': body.get('status', 'enabled'),
'disabled_reason': body.get('disabled_reason'),
'forced_down': body.get('forced_down', False)}})
def delete_os_services_1(self, **kw):
return (204, FAKE_RESPONSE_HEADERS, None)
def delete_os_services_75e9eabc_ed3b_4f11_8bba_add1e7e7e2de(self, **kwarg):
return (204, FAKE_RESPONSE_HEADERS, None)
def put_os_services_force_down(self, body, **kw):
return (200, FAKE_RESPONSE_HEADERS, {'service': {
'host': body['host'],
'binary': body['binary'],
'forced_down': False}})
#
# Hypervisors
#
def get_os_hypervisors(self, **kw):
return (200, {}, {
"hypervisors": [
{'id': 1234, 'hypervisor_hostname': 'hyper1'},
{'id': 5678, 'hypervisor_hostname': 'hyper2'}]})
def get_os_hypervisors_statistics(self, **kw):
return (200, {}, {
"hypervisor_statistics": {
'count': 2,
'vcpus': 8,
'memory_mb': 20 * 1024,
'local_gb': 500,
'vcpus_used': 4,
'memory_mb_used': 10 * 1024,
'local_gb_used': 250,
'free_ram_mb': 10 * 1024,
'free_disk_gb': 250,
'current_workload': 4,
'running_vms': 4,
'disk_available_least': 200}
})
def get_os_hypervisors_hyper1(self, **kw):
return (200, {}, {
'hypervisor':
{'id': 1234,
'service': {'id': 1, 'host': 'compute1'},
'vcpus': 4,
'memory_mb': 10 * 1024,
'local_gb': 250,
'vcpus_used': 2,
'memory_mb_used': 5 * 1024,
'local_gb_used': 125,
'hypervisor_type': "xen",
'hypervisor_version': 3,
'hypervisor_hostname': "hyper1",
'free_ram_mb': 5 * 1024,
'free_disk_gb': 125,
'current_workload': 2,
'running_vms': 2,
'cpu_info': 'cpu_info',
'disk_available_least': 100}})
def get_os_hypervisors_region_child_1(self, **kw):
return (200, {}, {
'hypervisor':
{'id': 'region!child@1',
'service': {'id': 1, 'host': 'compute1'},
'vcpus': 4,
'memory_mb': 10 * 1024,
'local_gb': 250,
'vcpus_used': 2,
'memory_mb_used': 5 * 1024,
'local_gb_used': 125,
'hypervisor_type': "xen",
'hypervisor_version': 3,
'hypervisor_hostname': "hyper1",
'free_ram_mb': 5 * 1024,
'free_disk_gb': 125,
'current_workload': 2,
'running_vms': 2,
'cpu_info': 'cpu_info',
'disk_available_least': 100}})
def get_os_hypervisors_hyper_search(self, **kw):
return (200, {}, {
'hypervisors': [
{'id': 1234, 'hypervisor_hostname': 'hyper1'},
{'id': 5678, 'hypervisor_hostname': 'hyper2'}]})
def get_os_hypervisors_hyper_servers(self, **kw):
return (200, {}, {
'hypervisors': [
{'id': 1234,
'hypervisor_hostname': 'hyper1',
'servers': [
{'name': 'inst1', 'uuid': 'uuid1'},
{'name': 'inst2', 'uuid': 'uuid2'}]},
{'id': 5678,
'hypervisor_hostname': 'hyper2',
'servers': [
{'name': 'inst3', 'uuid': 'uuid3'},
{'name': 'inst4', 'uuid': 'uuid4'}]}]
})
def get_os_hypervisors_hyper1_servers(self, **kw):
return (200, {}, {
'hypervisors': [
{'id': 1234,
'hypervisor_hostname': 'hyper1',
'servers': [
{'name': 'inst1', 'uuid': 'uuid1'},
{'name': 'inst2', 'uuid': 'uuid2'}]}]
})
def get_os_hypervisors_hyper2_servers(self, **kw):
return (200, {}, {
'hypervisors': [
{'id': 5678,
'hypervisor_hostname': 'hyper2',
'servers': [
{'name': 'inst3', 'uuid': 'uuid3'},
{'name': 'inst4', 'uuid': 'uuid4'}]}]
})
def get_os_hypervisors_hyper_no_servers_servers(self, **kw):
return (200, {}, {'hypervisors':
[{'id': 1234, 'hypervisor_hostname': 'hyper1'}]})
def get_os_hypervisors_1234(self, **kw):
return (200, {}, {
'hypervisor':
{'id': 1234,
'service': {'id': 1, 'host': 'compute1'},
'vcpus': 4,
'memory_mb': 10 * 1024,
'local_gb': 250,
'vcpus_used': 2,
'memory_mb_used': 5 * 1024,
'local_gb_used': 125,
'hypervisor_type': "xen",
'hypervisor_version': 3,
'hypervisor_hostname': "hyper1",
'free_ram_mb': 5 * 1024,
'free_disk_gb': 125,
'current_workload': 2,
'running_vms': 2,
'cpu_info': 'cpu_info',
'disk_available_least': 100}})
def get_os_hypervisors_1234_uptime(self, **kw):
return (200, {}, {
'hypervisor': {'id': 1234,
'hypervisor_hostname': "hyper1",
'uptime': "fake uptime"}})
def get_os_hypervisors_region_child_1_uptime(self, **kw):
return (200, {}, {
'hypervisor': {'id': 'region!child@1',
'hypervisor_hostname': "hyper1",
'uptime': "fake uptime"}})
def get_v2_0_networks(self, **kw):
"""Return neutron proxied networks.
We establish a few different possible networks that we can get
by name, which we can then call in tests. The only usage of
this API should be for name -> id translation, however a full
valid neutron block is provided for the private network to see
the kinds of things that will be in that payload.
"""
name = kw.get('name', "blank")
networks_by_name = {
'private': [
{"status": "ACTIVE",
"router:external": False,
"availability_zone_hints": [],
"availability_zones": ["nova"],
"description": "",
"name": "private",
"subnets": ["64706c26-336c-4048-ab3c-23e3283bca2c",
"18512740-c760-4d5f-921f-668105c9ee44"],
"shared": False,
"tenant_id": "abd42f270bca43ea80fe4a166bc3536c",
"created_at": "2016-08-15T17:34:49",
"tags": [],
"ipv6_address_scope": None,
"updated_at": "2016-08-15T17:34:49",
"admin_state_up": True,
"ipv4_address_scope": None,
"port_security_enabled": True,
"mtu": 1450,
"id": "e43a56c7-11d4-45c9-8681-ddc8171b5850",
"revision": 2}],
'duplicate': [
{"status": "ACTIVE",
"id": "e43a56c7-11d4-45c9-8681-ddc8171b5850"},
{"status": "ACTIVE",
"id": "f43a56c7-11d4-45c9-8681-ddc8171b5850"}],
'blank': []
}
return (200, {}, {"networks": networks_by_name[name]})
def get_os_availability_zone_detail(self, **kw):
return (200, {}, {
"availabilityZoneInfo": [
{"zoneName": "zone-1",
"zoneState": {"available": True},
"hosts": {
"fake_host-1": {
"nova-compute": {
"active": True,
"available": True,
"updated_at": datetime.datetime(
2012, 12, 26, 14, 45, 25, 0)}}}},
{"zoneName": "internal",
"zoneState": {"available": True},
"hosts": {
"fake_host-1": {
"nova-sched": {
"active": True,
"available": True,
"updated_at": datetime.datetime(
2012, 12, 26, 14, 45, 25, 0)}},
"fake_host-2": {
"nova-network": {
"active": True,
"available": False,
"updated_at": datetime.datetime(
2012, 12, 26, 14, 45, 24, 0)}}}},
{"zoneName": "zone-2",
"zoneState": {"available": False},
"hosts": None}]})
def get_servers_1234_os_interface(self, **kw):
attachments = {
"interfaceAttachments": [
{"port_state": "ACTIVE",
"net_id": "net-id-1",
"port_id": "port-id-1",
"mac_address": "aa:bb:cc:dd:ee:ff",
"fixed_ips": [{"ip_address": "1.2.3.4"}],
},
{"port_state": "ACTIVE",
"net_id": "net-id-1",
"port_id": "port-id-1",
"mac_address": "aa:bb:cc:dd:ee:ff",
"fixed_ips": [{"ip_address": "1.2.3.4"}],
}
]
}
if self.api_version >= api_versions.APIVersion('2.70'):
# Include the "tag" field in each attachment.
for attachment in attachments['interfaceAttachments']:
attachment['tag'] = 'test-tag'
return (200, {}, attachments)
def post_servers_1234_os_interface(self, **kw):
attachment = {}
if self.api_version >= api_versions.APIVersion('2.70'):
# Include the "tag" field in the response.
attachment['tag'] = 'test-tag'
return (200, {}, {'interfaceAttachment': attachment})
def delete_servers_1234_os_interface_port_id(self, **kw):
return (200, {}, None)
def post_servers_1234_os_volume_attachments(self, **kw):
attachment = {"device": "/dev/vdb", "volumeId": 2}
if self.api_version >= api_versions.APIVersion('2.70'):
# Include the "tag" field in the response.
attachment['tag'] = 'test-tag'
if self.api_version >= api_versions.APIVersion('2.79'):
# Include the "delete_on_termination" field in the
# response.
attachment['delete_on_termination'] = True
return (200, FAKE_RESPONSE_HEADERS, {"volumeAttachment": attachment})
def put_servers_1234_os_volume_attachments_Work(self, **kw):
return (200, FAKE_RESPONSE_HEADERS,
{"volumeAttachment": {"volumeId": 2}})
def get_servers_1234_os_volume_attachments(self, **kw):
attachments = {
"volumeAttachments": [
{"display_name": "Work",
"display_description": "volume for work",
"status": "ATTACHED",
"id": "15e59938-07d5-11e1-90e3-e3dffe0c5983",
"created_at": "2011-09-09T00:00:00Z",
"attached": "2011-11-11T00:00:00Z",
"size": 1024,
"attachments": [{"id": "3333", "links": ''}],
"metadata": {}}
]
}
if self.api_version >= api_versions.APIVersion('2.70'):
# Include the "tag" field in each attachment.
for attachment in attachments['volumeAttachments']:
attachment['tag'] = 'test-tag'
if self.api_version >= api_versions.APIVersion('2.79'):
# Include the "delete_on_termination" field in each
# attachment.
for attachment in attachments['volumeAttachments']:
attachment['delete_on_termination'] = True
return (200, FAKE_RESPONSE_HEADERS, attachments)
def get_servers_1234_os_volume_attachments_Work(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {
"volumeAttachment":
{"display_name": "Work",
"display_description": "volume for work",
"status": "ATTACHED",
"id": "15e59938-07d5-11e1-90e3-e3dffe0c5983",
"created_at": "2011-09-09T00:00:00Z",
"attached": "2011-11-11T00:00:00Z",
"size": 1024,
"attachments": [{"id": "3333", "links": ''}],
"metadata": {}}})
def delete_servers_1234_os_volume_attachments_Work(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {})
def get_servers_1234_os_instance_actions(self, **kw):
action = {"instance_uuid": "1234",
"user_id": "b968c25e04ab405f9fe4e6ca54cce9a5",
"start_time": "2013-03-25T13:45:09.000000",
"request_id": "req-abcde12345",
"action": "create",
"message": None,
"project_id": "04019601fe3648c0abd4f4abfb9e6106"}
if self.api_version >= api_versions.APIVersion('2.58'):
# This is intentionally different from the start_time.
action['updated_at'] = '2013-03-25T13:50:09.000000'
return (200, FAKE_RESPONSE_HEADERS, {
"instanceActions": [action]})
def get_servers_1234_os_instance_actions_req_abcde12345(self, **kw):
action = {"instance_uuid": "1234",
"user_id": "b968c25e04ab405f9fe4e6ca54cce9a5",
"start_time": "2013-03-25T13:45:09.000000",
"request_id": "req-abcde12345",
"action": "create",
"message": None,
"project_id": "04019601fe3648c0abd4f4abfb9e6106"}
if self.api_version >= api_versions.APIVersion('2.58'):
action['updated_at'] = '2013-03-25T13:45:09.000000'
return (200, FAKE_RESPONSE_HEADERS, {
"instanceAction": action})
def get_os_instance_usage_audit_log(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {
"instance_usage_audit_logs": {
"hosts_not_run": ["samplehost3"],
"log": {
"samplehost0": {
"errors": 1,
"instances": 1,
"message": ("Instance usage audit ran for host "
"samplehost0, 1 instances in 0.01 "
"seconds."),
"state": "DONE"
},
"samplehost1": {
"errors": 1,
"instances": 2,
"message": ("Instance usage audit ran for host "
"samplehost1, 2 instances in 0.01 "
"seconds."),
"state": "DONE"
},
"samplehost2": {
"errors": 1,
"instances": 3,
"message": ("Instance usage audit ran for host "
"samplehost2, 3 instances in 0.01 "
"seconds."),
"state": "DONE"
},
},
"num_hosts": 4,
"num_hosts_done": 3,
"num_hosts_not_run": 1,
"num_hosts_running": 0,
"overall_status": "3 of 4 hosts done. 3 errors.",
"period_beginning": "2012-06-01 00:00:00",
"period_ending": "2012-07-01 00:00:00",
"total_errors": 3,
"total_instances": 6}})
def get_os_instance_usage_audit_log_2016_12_10_13_59_59_999999(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {
"instance_usage_audit_log": {
"hosts_not_run": ["samplehost3"],
"log": {
"samplehost0": {
"errors": 1,
"instances": 1,
"message": ("Instance usage audit ran for host "
"samplehost0, 1 instances in 0.01 "
"seconds."),
"state": "DONE"
},
"samplehost1": {
"errors": 1,
"instances": 2,
"message": ("Instance usage audit ran for host "
"samplehost1, 2 instances in 0.01 "
"seconds."),
"state": "DONE"
},
"samplehost2": {
"errors": 1,
"instances": 3,
"message": ("Instance usage audit ran for host "
"samplehost2, 3 instances in 0.01 "
"seconds."),
"state": "DONE"
},
},
"num_hosts": 4,
"num_hosts_done": 3,
"num_hosts_not_run": 1,
"num_hosts_running": 0,
"overall_status": "3 of 4 hosts done. 3 errors.",
"period_beginning": "2012-06-01 00:00:00",
"period_ending": "2012-07-01 00:00:00",
"total_errors": 3,
"total_instances": 6}})
def get_os_instance_usage_audit_log__5Cu5de5_5Cu4f5c(self, **kw):
return (400, {}, {"Invalid timestamp for date \u6f22\u5b57"})
def post_servers_uuid1_action(self, **kw):
return 202, {}, {}
def post_servers_uuid2_action(self, **kw):
return 202, {}, {}
def post_servers_uuid3_action(self, **kw):
return 202, {}, {}
def post_servers_uuid4_action(self, **kw):
return 202, {}, {}
def post_servers_uuid5_action(self, **kw):
return 202, {}, {}
def post_servers_uuid6_action(self, **kw):
return 202, {}, {}
def get_os_migrations(self, **kw):
migration1 = {
"created_at": "2012-10-29T13:42:02.000000",
"dest_compute": "compute2",
"dest_host": "1.2.3.4",
"dest_node": "node2",
"id": '1234',
"instance_uuid": "instance_id_123",
"new_instance_type_id": 2,
"old_instance_type_id": 1,
"source_compute": "compute1",
"source_node": "node1",
"status": "Done",
"updated_at": "2012-10-29T13:42:02.000000"
}
migration2 = {
"created_at": "2012-10-29T13:42:02.000000",
"dest_compute": "compute2",
"dest_host": "1.2.3.4",
"dest_node": "node2",
"id": '1234',
"instance_uuid": "instance_id_456",
"new_instance_type_id": 2,
"old_instance_type_id": 1,
"source_compute": "compute1",
"source_node": "node1",
"status": "Done",
"updated_at": "2013-11-50T13:42:02.000000"
}
if self.api_version >= api_versions.APIVersion("2.23"):
migration1.update({"migration_type": "live-migration"})
migration2.update({"migration_type": "live-migration"})
if self.api_version >= api_versions.APIVersion("2.59"):
migration1.update({"uuid": "11111111-07d5-11e1-90e3-e3dffe0c5983"})
migration2.update({"uuid": "22222222-07d5-11e1-90e3-e3dffe0c5983"})
if self.api_version >= api_versions.APIVersion("2.80"):
migration1.update({
"project_id": "b59c18e5fa284fd384987c5cb25a1853",
"user_id": "13cc0930d27c4be0acc14d7c47a3e1f7"})
migration2.update({
"project_id": "b59c18e5fa284fd384987c5cb25a1853",
"user_id": "13cc0930d27c4be0acc14d7c47a3e1f7"})
migration_list = []
instance_uuid = kw.get('instance_uuid', None)
if instance_uuid == migration1['instance_uuid']:
migration_list.append(migration1)
elif instance_uuid == migration2['instance_uuid']:
migration_list.append(migration2)
elif instance_uuid is None:
migration_list.extend([migration1, migration2])
migrations = {'migrations': migration_list}
return (200, FAKE_RESPONSE_HEADERS, migrations)
#
# Server Groups
#
def get_os_server_groups(self, **kw):
server_groups = [
{"members": [], "metadata": {},
"id": "2cbd51f4-fafe-4cdb-801b-cf913a6f288b",
"policies": [], "name": "ig1"},
{"members": [], "metadata": {},
"id": "4473bb03-4370-4bfb-80d3-dc8cffc47d94",
"policies": ["anti-affinity"], "name": "ig2"},
{"members": [], "metadata": {"key": "value"},
"id": "31ab9bdb-55e1-4ac3-b094-97eeb1b65cc4",
"policies": [], "name": "ig3"},
{"members": ["2dccb4a1-02b9-482a-aa23-5799490d6f5d"],
"metadata": {},
"id": "4890bb03-7070-45fb-8453-d34556c87d94",
"policies": ["anti-affinity"], "name": "ig2"}]
other_project_server_groups = [
{"members": [], "metadata": {},
"id": "11111111-1111-1111-1111-111111111111",
"policies": [], "name": "ig4"},
{"members": [], "metadata": {},
"id": "22222222-2222-2222-2222-222222222222",
"policies": ["anti-affinity"], "name": "ig5"},
{"members": [], "metadata": {"key": "value"},
"id": "31ab9bdb-55e1-4ac3-b094-97eeb1b65cc4",
"policies": [], "name": "ig6"},
{"members": ["33333333-3333-3333-3333-333333333333"],
"metadata": {},
"id": "44444444-4444-4444-4444-444444444444",
"policies": ["anti-affinity"], "name": "ig5"}]
if kw.get("all_projects", False):
server_groups.extend(other_project_server_groups)
limit = int(kw.get("limit", 1000))
offset = int(kw.get("offset", 0))
server_groups = server_groups[offset:limit + 1]
return (200, {}, {"server_groups": server_groups})
def _return_server_group(self):
if self.api_version < api_versions.APIVersion("2.64"):
r = {'server_group':
self.get_os_server_groups()[2]['server_groups'][0]}
else:
r = {"members": [], "id": "2cbd51f4-fafe-4cdb-801b-cf913a6f288b",
'server_group': {'name': 'ig1', 'policy': 'anti-affinity',
'rules': {'max_server_per_host': 3}}}
return (200, {}, r)
def post_os_server_groups(self, body, **kw):
return self._return_server_group()
def post_servers_1234_migrations_1_action(self, body):
return (202, {}, None)
@api_versions.wraps(start_version="2.23")
def get_servers_1234_migrations_1(self, **kw):
migration = {"migration": {
"created_at": "2016-01-29T13:42:02.000000",
"dest_compute": "compute2",
"dest_host": "1.2.3.4",
"dest_node": "node2",
"id": 1,
"server_uuid": "4cfba335-03d8-49b2-8c52-e69043d1e8fe",
"source_compute": "compute1",
"source_node": "node1",
"status": "running",
"memory_total_bytes": 123456,
"memory_processed_bytes": 12345,
"memory_remaining_bytes": 120000,
"disk_total_bytes": 234567,
"disk_processed_bytes": 23456,
"disk_remaining_bytes": 230000,
"updated_at": "2016-01-29T13:42:02.000000"
}}
if self.api_version >= api_versions.APIVersion("2.80"):
migration['migration'].update({
"project_id": "b59c18e5fa284fd384987c5cb25a1853",
"user_id": "13cc0930d27c4be0acc14d7c47a3e1f7"})
return (200, FAKE_RESPONSE_HEADERS, migration)
@api_versions.wraps(start_version="2.23")
def get_servers_1234_migrations(self, **kw):
migrations = {'migrations': [
{
"created_at": "2016-01-29T13:42:02.000000",
"dest_compute": "compute2",
"dest_host": "1.2.3.4",
"dest_node": "node2",
"id": 1,
"server_uuid": "4cfba335-03d8-49b2-8c52-e69043d1e8fe",
"source_compute": "compute1",
"source_node": "node1",
"status": "running",
"memory_total_bytes": 123456,
"memory_processed_bytes": 12345,
"memory_remaining_bytes": 120000,
"disk_total_bytes": 234567,
"disk_processed_bytes": 23456,
"disk_remaining_bytes": 230000,
"updated_at": "2016-01-29T13:42:02.000000"
}]}
if self.api_version >= api_versions.APIVersion("2.80"):
migrations['migrations'][0].update({
"project_id": "b59c18e5fa284fd384987c5cb25a1853",
"user_id": "13cc0930d27c4be0acc14d7c47a3e1f7"})
return (200, FAKE_RESPONSE_HEADERS, migrations)
def delete_servers_1234_migrations_1(self):
return (202, {}, None)
def put_servers_1234_tags_tag(self, **kw):
return (201, {}, None)
def put_servers_1234_tags_tag1(self, **kw):
return (201, {}, None)
def put_servers_1234_tags_tag2(self, **kw):
return (201, {}, None)
def put_servers_1234_tags_tag3(self, **kw):
return (201, {}, None)
def put_servers_1234_tags(self, **kw):
return (201, {}, None)
def get_servers_1234_tags(self, **kw):
return (200, {}, {'tags': ['tag1', 'tag2']})
def delete_servers_1234_tags_tag(self, **kw):
return (204, {}, None)
def delete_servers_1234_tags_tag1(self, **kw):
return (204, {}, None)
def delete_servers_1234_tags_tag2(self, **kw):
return (204, {}, None)
def delete_servers_1234_tags_tag3(self, **kw):
return (204, {}, None)
def delete_servers_1234_tags(self, **kw):
return (204, {}, None)
def post_os_assisted_volume_snapshots(self, **kw):
return (202, FAKE_RESPONSE_HEADERS,
{'snapshot': {'id': 'blah', 'volumeId': '1'}})
def delete_os_assisted_volume_snapshots_x(self, **kw):
return (202, FAKE_RESPONSE_HEADERS, {})
def post_os_server_external_events(self, **kw):
return (200, FAKE_RESPONSE_HEADERS, {
'events': [
{'name': 'test-event',
'status': 'completed',
'tag': 'tag',
'server_uuid': 'fake-uuid1'},
{'name': 'test-event',
'status': 'completed',
'tag': 'tag',
'server_uuid': 'fake-uuid2'}]})
|