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 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084
|
# This file is part of cloud-init. See LICENSE file for license information.
import copy
import os
from collections import namedtuple
from logging import getLogger
from pathlib import Path
from tempfile import mkdtemp
from textwrap import dedent
from uuid import uuid4
import pytest
import yaml
from cloudinit import atomic_helper, subp, util
from cloudinit.sources import DataSourceIBMCloud as ds_ibm
from cloudinit.sources import DataSourceOracle as ds_oracle
from cloudinit.sources import DataSourceSmartOS as ds_smartos
from tests.helpers import cloud_init_project_dir
from tests.unittests.helpers import (
dir2dict,
populate_dir,
populate_dir_with_ts,
)
LOG = getLogger(__name__)
UNAME_MYSYS = "Linux #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64"
UNAME_PPC64EL = (
"Linux #106-Ubuntu SMP mon Jun 26 17:53:54 UTC 2017 "
"ppc64le ppc64le ppc64le"
)
UNAME_FREEBSD = (
"FreeBSD FreeBSD 14.0-RELEASE-p3 releng/14.0-n265398-20fae1e1699"
"GENERIC-MMCCAM amd64"
)
UNAME_OPENBSD = "OpenBSD GENERIC.MP#1397 amd64"
UNAME_WSL = (
"Linux 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 "
"UTC 2023 x86_64"
)
BLKID_EFI_ROOT = """
DEVNAME=/dev/sda1
UUID=8B36-5390
TYPE=vfat
PARTUUID=30d7c715-a6ae-46ee-b050-afc6467fc452
DEVNAME=/dev/sda2
UUID=19ac97d5-6973-4193-9a09-2e6bbfa38262
TYPE=ext4
PARTUUID=30c65c77-e07d-4039-b2fb-88b1fb5fa1fc
"""
# this is a Ubuntu 18.04 disk.img output (dual uefi and bios bootable)
BLKID_UEFI_UBUNTU = [
{"DEVNAME": "vda1", "TYPE": "ext4", "PARTUUID": uuid4(), "UUID": uuid4()},
{"DEVNAME": "vda14", "PARTUUID": uuid4()},
{
"DEVNAME": "vda15",
"TYPE": "vfat",
"LABEL": "UEFI",
"PARTUUID": uuid4(),
"UUID": "5F55-129B",
},
]
DEFAULT_CLOUD_CONFIG = """\
# The top level settings are used as module
# and base configuration.
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
- default
# If this is set, 'root' will not be able to ssh in and they
# will get a message to login instead as the default $user
disable_root: true
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
# If you use datasource_list array, keep array items in a single line.
# If you use multi line array, ds-identify script won't read array items.
# Example datasource config
# datasource:
# Ec2:
# metadata_urls: [ 'blah.com' ]
# timeout: 5 # (defaults to 50 seconds)
# max_wait: 10 # (defaults to 120 seconds)
# The modules that run in the 'init' stage
cloud_init_modules:
- migrator
- seed_random
- bootcmd
- write-files
- growpart
- resizefs
- disk_setup
- mounts
- set_hostname
- update_hostname
- update_etc_hosts
- ca-certs
- rsyslog
- users-groups
- ssh
# The modules that run in the 'config' stage
cloud_config_modules:
- wireguard
- snap
- ubuntu_autoinstall
- ssh-import-id
- keyboard
- locale
- set-passwords
- grub-dpkg
- apt-pipelining
- apt-configure
- ubuntu-advantage
- ntp
- timezone
- disable-ec2-metadata
- runcmd
- byobu
# The modules that run in the 'final' stage
cloud_final_modules:
- package-update-upgrade-install
- fan
- landscape
- lxd
- ubuntu-drivers
- write-files-deferred
- puppet
- chef
- ansible
- mcollective
- salt-minion
- reset_rmc
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- install-hotplug
- phone-home
- final-message
- power-state-change
# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
# This will affect which distro class gets used
distro: ubuntu
# Default user name + that default users groups (if added/used)
default_user:
name: ubuntu
lock_passwd: True
gecos: Ubuntu
groups: [adm, audio, cdrom, floppy, lxd, netdev, plugdev, sudo, video]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
network:
renderers: ['netplan', 'eni', 'sysconfig']
activators: ['netplan', 'eni', 'network-manager', 'networkd']
# Automatically discover the best ntp_client
ntp_client: auto
# Other config here will be given to the distro class and/or path classes
paths:
cloud_dir: /var/lib/cloud/
templates_dir: /etc/cloud/templates/
package_mirrors:
- arches: [i386, amd64]
failsafe:
primary: http://archive.ubuntu.com/ubuntu
security: http://security.ubuntu.com/ubuntu
search:
primary:
- http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
- http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
- http://%(region)s.clouds.archive.ubuntu.com/ubuntu/
security: []
- arches: [arm64, armel, armhf]
failsafe:
primary: http://ports.ubuntu.com/ubuntu-ports
security: http://ports.ubuntu.com/ubuntu-ports
search:
primary:
- http://%(ec2_region)s.ec2.ports.ubuntu.com/ubuntu-ports/
- http://%(availability_zone)s.clouds.ports.ubuntu.com/ubuntu-ports/
- http://%(region)s.clouds.ports.ubuntu.com/ubuntu-ports/
security: []
- arches: [default]
failsafe:
primary: http://ports.ubuntu.com/ubuntu-ports
security: http://ports.ubuntu.com/ubuntu-ports
ssh_svcname: ssh
"""
POLICY_FOUND_ONLY = "search,found=all,maybe=none,notfound=disabled"
POLICY_FOUND_OR_MAYBE = "search,found=all,maybe=none,notfound=disabled"
DI_DEFAULT_POLICY = "search,found=all,maybe=none,notfound=disabled"
DI_DEFAULT_POLICY_NO_DMI = "search,found=all,maybe=none,notfound=disabled"
DI_EC2_STRICT_ID_DEFAULT = "true"
OVF_MATCH_STRING = "http://schemas.dmtf.org/ovf/environment/1"
SHELL_MOCK_TMPL = """\
%(name)s() {
local out='%(out)s' err='%(err)s' r='%(ret)s' RET='%(RET)s'
[ "$out" = "_unset" ] || echo "$out"
[ "$err" = "_unset" ] || echo "$err" 2>&1
[ "$RET" = "_unset" ] || _RET="$RET"
return $r
}
"""
RC_FOUND = 0
RC_NOT_FOUND = 1
DS_NONE = "None"
P_BOARD_NAME = "sys/class/dmi/id/board_name"
P_CHASSIS_ASSET_TAG = "sys/class/dmi/id/chassis_asset_tag"
P_PRODUCT_NAME = "sys/class/dmi/id/product_name"
P_PRODUCT_SERIAL = "sys/class/dmi/id/product_serial"
P_PRODUCT_UUID = "sys/class/dmi/id/product_uuid"
P_SYS_VENDOR = "sys/class/dmi/id/sys_vendor"
P_SEED_DIR = "var/lib/cloud/seed"
P_DSID_CFG = "etc/cloud/ds-identify.cfg"
IBM_CONFIG_UUID = "9796-932E"
MOCK_VIRT_IS_CONTAINER_OTHER = {
"name": "detect_virt",
"RET": "container-other",
"ret": 0,
}
IS_CONTAINER_OTHER_ENV = {"SYSTEMD_VIRTUALIZATION": "vm:kvm"}
MOCK_NOT_LXD_DATASOURCE = {"name": "dscheck_LXD", "ret": 1}
MOCK_VIRT_IS_KVM = {"name": "detect_virt", "RET": "kvm", "ret": 0}
KVM_ENV = {"SYSTEMD_VIRTUALIZATION": "vm:kvm"}
# qemu support for LXD is only for host systems > 5.10 kernel as lxd
# passed `hv_passthrough` which causes systemd < v.251 to misinterpret CPU
# as "qemu" instead of "kvm"
MOCK_VIRT_IS_KVM_QEMU = {"name": "detect_virt", "RET": "qemu", "ret": 0}
IS_KVM_QEMU_ENV = {"SYSTEMD_VIRTUALIZATION": "vm:qemu"}
MOCK_VIRT_IS_VMWARE = {"name": "detect_virt", "RET": "vmware", "ret": 0}
MOCK_VIRT_IS_NOT_VMWARE = {
"name": "detect_virt",
"RET": "not-vmware",
"ret": 0,
}
IS_VMWARE_ENV = {"SYSTEMD_VIRTUALIZATION": "vm:vmware"}
# currenty' SmartOS hypervisor "bhyve" is unknown by systemd-detect-virt.
MOCK_VIRT_IS_VM_OTHER = {"name": "detect_virt", "RET": "vm-other", "ret": 0}
IS_VM_OTHER = {"SYSTEMD_VIRTUALIZATION": "vm:vm-other"}
MOCK_VIRT_IS_XEN = {"name": "detect_virt", "RET": "xen", "ret": 0}
IS_XEN_ENV = {"SYSTEMD_VIRTUALIZATION": "vm:xen"}
MOCK_VIRT_IS_WSL = {"name": "detect_virt", "RET": "wsl", "ret": 0}
MOCK_UNAME_IS_PPC64 = {"name": "uname", "out": UNAME_PPC64EL, "ret": 0}
MOCK_UNAME_IS_FREEBSD = {"name": "uname", "out": UNAME_FREEBSD, "ret": 0}
MOCK_UNAME_IS_OPENBSD = {"name": "uname", "out": UNAME_OPENBSD, "ret": 0}
MOCK_UNAME_IS_WSL = {"name": "uname", "out": UNAME_WSL, "ret": 0}
MOCK_WSL_INSTANCE_DATA = {
"name": "Noble-MLKit",
"distro": "ubuntu",
"version": "24.04",
"os_release": dedent(
"""\
PRETTY_NAME="Ubuntu Noble Numbat (development branch)"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
"""
),
"os_release_no_version_id": dedent(
"""\
PRETTY_NAME="Debian GNU/Linux trixie/sid"
NAME="Debian GNU/Linux"
VERSION_CODENAME="trixie"
ID=debian
"""
),
}
shell_true = 0
shell_false = 1
CallReturn = namedtuple(
"CallReturn", ["rc", "stdout", "stderr", "cfg", "files"]
)
class DsIdentifyBase:
dsid_path = cloud_init_project_dir("tools/ds-identify")
# set to true to write out the mocked ds-identify for inspection
debug_mode = True
def call(
self,
rootd,
mocks=None,
no_mocks=None,
func="main",
args=None,
files=None,
policy_dmi=DI_DEFAULT_POLICY,
policy_no_dmi=DI_DEFAULT_POLICY_NO_DMI,
ec2_strict_id=DI_EC2_STRICT_ID_DEFAULT,
env_vars=None,
):
if args is None:
args = []
if mocks is None:
mocks = []
if files is None:
files = {}
cloudcfg = "etc/cloud/cloud.cfg"
if cloudcfg not in files:
files[cloudcfg] = DEFAULT_CLOUD_CONFIG
unset = "_unset"
wrap = os.path.join(rootd, "_shwrap")
populate_dir(rootd, files)
# DI_DEFAULT_POLICY* are declared always as to not rely
# on the default in the code. This is because SRU releases change
# the value in the code, and thus tests would fail there.
head = [
"DI_MAIN=noop",
"DEBUG_LEVEL=2",
"DI_LOG=stderr",
"PATH_ROOT='%s'" % rootd,
". " + self.dsid_path,
'DI_DEFAULT_POLICY="%s"' % policy_dmi,
'DI_DEFAULT_POLICY_NO_DMI="%s"' % policy_no_dmi,
'DI_EC2_STRICT_ID_DEFAULT="%s"' % ec2_strict_id,
"",
]
def write_mock(data):
ddata = {"out": None, "err": None, "ret": 0, "RET": None}
ddata.update(data)
for k in ddata.keys():
if ddata[k] is None:
ddata[k] = unset
return SHELL_MOCK_TMPL % ddata
mocklines = []
default_mocks = [
MOCK_NOT_LXD_DATASOURCE,
{"name": "detect_virt", "RET": "none", "ret": 1},
{"name": "uname", "out": UNAME_MYSYS},
{"name": "blkid", "out": BLKID_EFI_ROOT},
{
"name": "ovf_vmware_transport_guestinfo",
"out": "No value found",
"ret": 1,
},
{
"name": "dmi_decode",
"ret": 1,
"err": "No dmidecode program. ERROR.",
},
{
"name": "is_disabled",
"ret": 1,
},
{
"name": "get_kenv_field",
"ret": 1,
"err": "No kenv program. ERROR.",
},
]
uname = "Linux"
runpath = "run"
written = []
for d in mocks:
written.append(d["name"])
if d["name"] == "uname":
uname = d["out"].split(" ")[0]
# set runpath so that BSDs use /var/run rather than /run
if uname != "Linux":
runpath = "var/run"
for data in mocks:
mocklines.append(write_mock(data))
for d in default_mocks:
if no_mocks and d["name"] in no_mocks:
continue
if d["name"] not in written:
mocklines.append(write_mock(d))
endlines = [func + " " + " ".join(['"%s"' % s for s in args])]
mocked_ds_identify = "\n".join(head + mocklines + endlines) + "\n"
with open(wrap, "w") as fp:
fp.write(mocked_ds_identify)
# debug_mode force this test to write the mocked ds-identify script to
# a file for inspection
if self.debug_mode:
tempdir = mkdtemp()
dir = f"{tempdir}/ds-identify"
LOG.debug("Writing mocked ds-identify to %s for debugging.", dir)
with open(dir, "w") as fp:
fp.write(mocked_ds_identify)
rc = 0
try:
out, err = subp.subp(
["sh", "-c", ". %s" % wrap],
update_env=env_vars if env_vars else {},
capture=True,
)
except subp.ProcessExecutionError as e:
rc = e.exit_code
out = e.stdout
err = e.stderr
cfg = None
cfg_out = os.path.join(rootd, runpath, "cloud-init/cloud.cfg")
if os.path.exists(cfg_out):
contents = util.load_text_file(cfg_out)
try:
cfg = yaml.safe_load(contents)
except Exception as e:
cfg = {"_INVALID_YAML": contents, "_EXCEPTION": str(e)}
return CallReturn(rc, out, err, cfg, dir2dict(rootd))
def _call_via_dict(self, data, rootd, **kwargs):
# return output of self.call with a dict input like VALID_CFG[item]
xwargs = {"rootd": rootd}
passthrough = (
"no_mocks", # named mocks to ignore
"mocks",
"func",
"args",
"env_vars",
"policy_dmi",
"policy_no_dmi",
"files",
)
for k in passthrough:
if k in data:
xwargs[k] = data[k]
if k in kwargs:
xwargs[k] = kwargs[k]
return self.call(**xwargs)
def _test_ds_found(self, name, rootd):
data = copy.deepcopy(VALID_CFG[name])
dslist = []
for ds in data.pop("ds").split(","):
dslist.append(ds.strip())
dslist.append(DS_NONE)
return self._check_via_dict(data, rootd, RC_FOUND, dslist=dslist)
def _test_ds_not_found(self, name, rootd):
data = copy.deepcopy(VALID_CFG[name])
return self._check_via_dict(data, rootd, RC_NOT_FOUND)
def _check_via_dict(self, data, rootd, rc, dslist=None, **kwargs):
ret = self._call_via_dict(data, rootd, **kwargs)
good = False
try:
assert rc == ret.rc
if dslist is not None:
assert dslist == ret.cfg.get("datasource_list")
good = True
finally:
if not good:
_print_run_output(
ret.rc, ret.stdout, ret.stderr, ret.cfg, ret.files
)
return ret
@pytest.mark.allow_subp_for("sh")
class TestDsIdentify(DsIdentifyBase):
def test_wb_print_variables(self, tmp_path):
"""_print_info reports an array of discovered variables to stderr."""
data = VALID_CFG["Azure-dmi-detection"]
_, _, err, _, _ = self._call_via_dict(data, str(tmp_path))
expected_vars = [
"DMI_PRODUCT_NAME",
"DMI_SYS_VENDOR",
"DMI_PRODUCT_SERIAL",
"DMI_PRODUCT_UUID",
"PID_1_PRODUCT_NAME",
"DMI_CHASSIS_ASSET_TAG",
"FS_LABELS",
"KERNEL_CMDLINE",
"VIRT",
"UNAME_KERNEL_NAME",
"UNAME_KERNEL_VERSION",
"UNAME_MACHINE",
"DSNAME",
"DSLIST",
"MODE",
"ON_FOUND",
"ON_MAYBE",
"ON_NOTFOUND",
]
for var in expected_vars:
assert "{0}=".format(var) in err
@pytest.mark.parametrize(
"config,found",
[
# Don't incorrectly identify maas
#
# The bug reported in 4794 combined with the previously existing
# bug reported in 4796 made for very loose MAAS false-positives.
#
# In ds-identify the function check_config() attempts to parse yaml
# keys in bash, but it sometimes introduces false positives. The
# maas datasource uses check_config() and the existence of a "MAAS"
# key to identify itself (which is a very poor identifier - clouds
# should have stricter identifiers). Since the MAAS datasource is
# at the begining of the list, this is particularly troublesome and
# more concerning than NoCloud false positives, for example.
pytest.param("LXD-kvm-not-MAAS-2", True, id="mass_not_detected_2"),
# Don't detect incorrect config when invalid datasource_list
# provided
#
# If unparsable list is provided we just ignore it. Some users
# might assume that since the rest of the configuration is yaml
# that multi-line yaml lists are valid (they aren't). When this
# happens, just run ds-identify and figure it out for ourselves
# which platform to run.
pytest.param(
"Azure-parse-invalid", True, id="azure_invalid_configuration"
),
# Azure datasource is detected from DMI chassis-asset-tag
pytest.param(
"Azure-dmi-detection",
True,
id="azure_dmi_detection_from_chassis_asset_tag",
),
# Azure datasource is detected due to presence of a seed file.
#
# The seed file tested is /var/lib/cloud/seed/azure/ovf-env.xml.
pytest.param(
"Azure-seed-detection", True, id="azure_seed_file_detection"
),
# EC2: hvm instances use dmi serial and uuid starting with 'ec2'.
pytest.param("Ec2-hvm", True, id="aws_ec2_hvm"),
# EC2: hvm instances use dmi serial and uuid starting with 'ec2'
#
# test using SYSTEMD_VIRTUALIZATION, not systemd-detect-virt
pytest.param("Ec2-hvm-env", True, id="aws_ec2_hvm_env"),
# EC2: hvm instances use system-uuid and may have swapped
# endianness
#
# test using SYSTEMD_VIRTUALIZATION, not systemd-detect-virt
pytest.param(
"Ec2-hvm-swap-endianness", True, id="aws_ec2_hvm_endian"
),
# EC2: sys/hypervisor/uuid starts with ec2.
pytest.param("Ec2-xen", True, id="aws_ec2_xen"),
# EC2: product_serial ends with '.brightbox.com'
pytest.param("Ec2-brightbox", True, id="brightbox_is_ec2"),
# EC2: bobrightbox.com in product_serial is not brightbox
pytest.param(
"Ec2-brightbox-negative",
False,
id="brightbox_is_not_brightbox",
),
# NoCloud identified on FreeBSD via label by geom.
pytest.param("NoCloud-fbsd", True, id="freebsd_nocloud"),
# GCE identifies itself with product_name.
pytest.param("GCE", True, id="gce_by_product_name"),
# GCE identifies itself with product_name.
#
# Uses SYSTEMD_VIRTUALIZATION
pytest.param("GCE_ENV", True, id="gce_by_product_name_env"),
# Older gce compute instances must be identified by serial.
pytest.param("GCE-serial", True, id="gce_by_serial"),
# LXD KVM has race on absent /dev/lxd/socket. Use DMI board_name.
pytest.param("LXD-kvm", True, id="lxd_kvm"),
# LXD KVM on host systems with a kernel > 5.10 need to match "qemu"
#
# LXD provides `hv_passthrough` when launching kvm instances when
# host kernel is > 5.10. This results in systemd being unable to
# detect the virtualized CPUID="Linux KVM Hv" as type "kvm" and
# results in systemd-detect-virt returning "qemu" in this case.
#
# Assert ds-identify can match systemd-detect-virt="qemu" and
# /sys/class/dmi/id/board_name = LXD.
# Once systemd 251 is available on a target distro, the virtualized
# CPUID will be represented properly as "kvm"
pytest.param(
"LXD-kvm-qemu-kernel-gt-5.10", True, id="lxd_kvm_jammy"
),
# LXD KVM on host systems with a kernel > 5.10 need to match "qemu"
#
# LXD provides `hv_passthrough` when launching kvm instances when
# host kernel is > 5.10. This results in systemd being unable to
# detect the virtualized CPUID="Linux KVM Hv" as type "kvm" and
# results in systemd-detect-virt returning "qemu" in this case.
#
# Assert ds-identify can match systemd-detect-virt="qemu" and
# /sys/class/dmi/id/board_name = LXD.
# Once systemd 251 is available on a target distro, the virtualized
# CPUID will be represented properly as "kvm"
pytest.param(
"LXD-kvm-qemu-kernel-gt-5.10-env", True, id="lxd_kvm_jammy_env"
),
# LXD containers will have /dev/lxd/socket at generator time.
pytest.param("LXD", True, id="lxd_containers"),
# ConfigDrive datasource has a disk with LABEL=config-2.
pytest.param("ConfigDrive", True, id="config_drive"),
# Rbx datasource has a disk with LABEL=CLOUDMD.
pytest.param("RbxCloud", True, id="rbx_cloud"),
# Rbx datasource has a disk with LABEL=cloudmd.
pytest.param("RbxCloudLower", True, id="rbx_cloud_lower"),
# ConfigDrive datasource has a disk with LABEL=CONFIG-2.
pytest.param("ConfigDriveUpper", True, id="config_drive_upper"),
# Config Drive seed directory.
pytest.param("ConfigDrive-seed", True, id="config_drive_seed"),
# Multi-line yaml is unsupported
pytest.param(
"LXD-kvm-not-azure",
True,
marks=[
pytest.mark.xfail(
reason=(
"not supported: yaml parser implemented in POSIX"
" shell"
)
)
],
id="multiline_yaml",
),
# Template provisioned with user-data first boot.
#
# Template provisioning with user-data has METADATA disk.
# datasource should return found.
pytest.param(
"IBMCloud-metadata", True, id="ibmcloud_template_userdata"
),
# Launched by os code always has config-2 disk.
pytest.param("IBMCloud-config-2", True, id="ibmcloud_os_code"),
# Test that Aliyun cloud is identified by product id.
pytest.param("AliYun", True, id="ibmcloud_os_code"),
# On Intel, openstack must be identified.
pytest.param(
"OpenStack", True, id="default_openstack_intel_is_found"
),
# Open Telecom identification.
pytest.param(
"OpenStack-OpenTelekom",
True,
id="openstack_open_telekom_cloud",
),
# SAP Converged Cloud identification
pytest.param(
"OpenStack-SAPCCloud", True, id="openstack_sap_ccloud"
),
pytest.param(
"OpenStack-SAPCCloud-env", True, id="openstack_sap_ccloud-env"
),
# Open Huawei Cloud identification.
pytest.param(
"OpenStack-HuaweiCloud", True, id="openstack_huawei_cloud"
),
# Open Samsung Cloud Platform identification.
pytest.param(
"OpenStack-SamsungCloudPlatform",
True,
id="openstack_samsung_cloud_platform",
),
# OpenStack identification via asset tag OpenStack Nova.
pytest.param(
"OpenStack-AssetTag-Nova", True, id="openstack_asset_tag_nova"
),
# OpenStack identification via asset tag OpenStack Compute.
pytest.param(
"OpenStack-AssetTag-Compute",
True,
id="openstack_asset_tag_compute",
),
# OVF is identified found when ovf/ovf-env.xml seed file exists.
pytest.param("OVF-seed", True, id="default_ovf_is_found"),
# OVF is identified when iso9660 cdrom path contains ovf schema.
pytest.param(
"OVF",
True,
id="ovf_on_vmware_iso_found_by_cdrom_with_ovf_schema_match",
),
# OVF guest info is found on vmware.
pytest.param(
"OVF-guestinfo", True, id="ovf_on_vmware_guestinfo_found"
),
# NoCloud is found with iso9660 filesystem on non-cdrom disk.
pytest.param("NoCloud", True, id="default_nocloud_as_vdb_iso9660"),
# NoCloud is found with uppercase filesystem label.
pytest.param("NoCloudUpper", True, id="nocloud_upper"),
# NoCloud seed definition can go in /etc/cloud/cloud.cfg[.d]
pytest.param("NoCloud-cfg", True, id="nocloud_seed_in_cfg"),
# NoCloud fatboot label - LP: #184166.
pytest.param("NoCloud-fatboot", True, id="nocloud_fatboot"),
# Nocloud seed directory.
pytest.param("NoCloud-seed", True, id="nocloud_seed"),
# Nocloud seed directory ubuntu core writable
pytest.param(
"NoCloud-seed-ubuntu-core",
True,
id="nocloud_seed_ubuntu_core_writable",
),
# Hetzner cloud is identified in sys_vendor.
pytest.param("Hetzner", True, id="hetzner_found"),
# CloudCIX cloud is identified in dmi product-name
pytest.param("CloudCIX", True, id="cloudcix_found"),
# NWCS is identified in sys_vendor.
pytest.param("NWCS", True, id="nwcs_found"),
# SmartOS cloud identified by SmartDC in dmi.
pytest.param("SmartOS-bhyve", True, id="smartos_bhyve"),
# SmartOS cloud identified on lxbrand container.
pytest.param("SmartOS-lxbrand", True, id="smartos_lxbrand"),
pytest.param(
"SmartOS-lxbrand-env", True, id="smartos_lxbrand-env"
),
# EC2: chassis asset tag ends with 'zstack.io'
pytest.param("Ec2-ZStack", True, id="zstack_is_ec2"),
# EC2: e24cloud identified by sys_vendor
pytest.param("Ec2-E24Cloud", True, id="e24cloud_is_ec2"),
# EC2: bobrightbox.com in product_serial is not brightbox'
pytest.param(
"Ec2-E24Cloud-negative", False, id="e24cloud_not_active"
),
# EC2: outscale identified by sys_vendor and product_name
pytest.param("Ec2-Outscale", True, id="outscale_is_ec2"),
# EC2: outscale in sys_vendor is not outscale'
pytest.param(
"Ec2-Outscale-negative-sysvendor",
False,
id="outscale_not_active_sysvendor",
),
# EC2: outscale in product_name is not outscale'
pytest.param(
"Ec2-Outscale-negative-productname",
False,
id="outscale_not_active_productname",
),
# VMware: no valid transports
pytest.param(
"VMware-NoValidTransports",
False,
id="vmware_no_valid_transports",
),
# VMware is identified when vmware customization is enabled.
pytest.param(
"VMware-vmware-customization",
True,
id="vmware_on_vmware_when_vmware_customization_is_enabled",
),
# VMware and OVF are identified when:
# 1. On VMware platform.
# 2. VMware customization is enabled.
# 3. iso9660 cdrom path contains ovf schema.
pytest.param(
"VMware-OVF-on-vmware-with-vmware-customization-and-ovf-schema",
True,
id="vmware_ovf_on_vmware_with_vmware_customization_and_ovf_"
"schema",
),
# OVF is identified when:
# 1. Not on VMware platform.
# 2. VMware customization is enabled.
# 3. iso9660 cdrom path contains ovf schema.
pytest.param(
"OVF-not-on-vmware-with-vmware-customization-and-ovf-schema",
True,
id="ovf_not_on_vmware_with_vmware_customization_and_ovf_"
"schema",
),
# VMware: envvar transport no data
pytest.param(
"VMware-EnvVar-NoData", False, id="vmware_envvar_no_data"
),
# VMware: envvar transport success if no virt id
pytest.param(
"VMware-EnvVar-NoVirtID", True, id="vmware_envvar_no_virt_id"
),
# VMware: envvar transport activated by metadata
pytest.param(
"VMware-EnvVar-Metadata",
True,
id="vmware_envvar_activated_by_metadata",
),
# VMware: envvar transport activated by userdata
pytest.param(
"VMware-EnvVar-Userdata",
True,
id="vmware_envvar_activated_by_userdata",
),
# VMware: envvar transport activated by vendordata
pytest.param(
"VMware-EnvVar-Vendordata",
True,
id="vmware_envvar_activated_by_vendordata",
),
# VMware: guestinfo transport no data
pytest.param(
"VMware-GuestInfo-NoData-Rpctool",
False,
id="vmware_guestinfo_no_data_rcptool",
),
pytest.param(
"VMware-GuestInfo-NoData-Vmtoolsd",
False,
id="vmware_guestinfo_no_data_vmtoolsd",
),
# VMware: guestinfo transport fails if no virt id
pytest.param(
"VMware-GuestInfo-NoVirtID",
False,
id="vmware_guestinfo_no_virt_id",
),
# VMware: guestinfo transport activated by metadata
pytest.param(
"VMware-GuestInfo-Metadata",
True,
id="vmware_guestinfo_activated_by_metadata",
),
# VMware: guestinfo transport activated by userdata
pytest.param(
"VMware-GuestInfo-Userdata",
True,
id="vmware_guestinfo_activated_by_userdata",
),
# VMware: guestinfo transport activated by vendordata
pytest.param(
"VMware-GuestInfo-Vendordata",
True,
id="vmware_guestinfo_activated_by_vendordata",
),
# VMware and OVF are identified when:
# 1. On VMware platform.
# 2. guestinfo transport activated by metadata
# 3. iso9660 cdrom path contains ovf schema.
pytest.param(
"VMware-OVF-on-vmware-with-guestinfo-metadata-and-ovf-schema",
True,
id="vmware_ovf_on_vmware_with_guestinfo_metadata_and_ovf_"
"schema",
),
# OVF is identified when:
# 1. Not on VMware platform.
# 2. guestinfo transport activated by metadata
# 3. iso9660 cdrom path contains ovf schema.
pytest.param(
"OVF-not-on-vmware-with-guestinfo-metadata-and-ovf-schema",
True,
id="ovf_not_on_vmware_with_guestinfo_metadata_and_ovf_schema",
),
# ds-identify finds Akamai by system-manufacturer dmi field
pytest.param("Akamai", True, id="akamai_found_by_sys_vendor"),
# Test *BSD code paths
#
# FreeBSD doesn't have /sys so we use kenv(1) here.
# OpenBSD uses sysctl(8).
# Other BSD systems fallback to dmidecode(8).
# BSDs also doesn't have systemd-detect-virt(8), so we use
# sysctl(8) to query kern.vm_guest, and optionally map it:
#
# Test that kenv(1) works on systems which don't have /sys
pytest.param("Hetzner-kenv", True, id="bsd_dmi_kenv"),
# Test that sysctl(8) works on systems which don't have /sys
pytest.param("Hetzner-sysctl", True, id="bsd_dmi_sysctl"),
# Test that dmidecode(8) works on systems which don't have /sys
pytest.param("Hetzner-dmidecode", True, id="bsd_dmi_dmidecode"),
# Simple positive test of Oracle by chassis id.
pytest.param("Oracle", True, id="oracle_found_by_chassis"),
# Simple negative test for WSL due other virt.
pytest.param("Not-WSL", False, id="wsl_not_found_virt"),
# Negative test by lack of host filesystem mount points.
pytest.param("WSL-no-host-mounts", False, id="wsl_no_fs_mounts"),
],
)
def test_ds_found_not_found(self, config, found, tmp_path):
test_func = self._test_ds_found if found else self._test_ds_not_found
test_func(config, str(tmp_path))
def test_flow_sequence_control(self, tmp_path):
"""ensure that an invalid key in the flow_sequence tests produces no
datasource list match
control test: this test serves as a control test for test_flow_sequence
"""
data = copy.deepcopy(VALID_CFG["flow_sequence-control"])
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
def test_flow_sequence(self, tmp_path):
"""correctly identify flow sequences"""
for i in range(1, 10):
data = copy.deepcopy(VALID_CFG[f"flow_sequence-{i}"])
self._check_via_dict(
data, str(tmp_path), RC_FOUND, dslist=[data.get("ds")]
)
def test_config_drive_interacts_with_ibmcloud_config_disk(self, tmp_path):
"""Verify ConfigDrive interaction with IBMCloud.
If ConfigDrive is enabled and not IBMCloud, then ConfigDrive
should claim the ibmcloud 'config-2' disk.
If IBMCloud is enabled, then ConfigDrive should skip."""
data = copy.deepcopy(VALID_CFG["IBMCloud-config-2"])
files = data.get("files", {})
if not files:
data["files"] = files
cfgpath = "etc/cloud/cloud.cfg.d/99_networklayer_common.cfg"
# with list including IBMCloud, config drive should be not found.
files[cfgpath] = "datasource_list: [ ConfigDrive, IBMCloud ]\n"
ret = self._check_via_dict(data, str(tmp_path / "ibm"), shell_true)
assert ret.cfg.get("datasource_list") == ["IBMCloud", "None"]
# But if IBMCloud is not enabled, config drive should claim this.
files[cfgpath] = "datasource_list: [ ConfigDrive, NoCloud ]\n"
ret = self._check_via_dict(data, str(tmp_path), shell_true)
assert ret.cfg.get("datasource_list") == ["ConfigDrive", "None"]
def test_ibmcloud_template_userdata_in_provisioning(self, tmp_path):
"""Template provisioned with user-data during provisioning stage.
Template provisioning with user-data has METADATA disk,
datasource should return not found."""
data = copy.deepcopy(VALID_CFG["IBMCloud-metadata"])
# change the 'is_ibm_provisioning' mock to return 1 (false)
isprov_m = [
m for m in data["mocks"] if m["name"] == "is_ibm_provisioning"
][0]
isprov_m["ret"] = shell_true
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
def test_ibmcloud_template_no_userdata_in_provisioning(self, tmp_path):
"""Template provisioned with no user-data during provisioning.
no disks attached. Datasource should return not found."""
data = copy.deepcopy(VALID_CFG["IBMCloud-nodisks"])
data["mocks"].append(
{"name": "is_ibm_provisioning", "ret": shell_true}
)
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
def test_ibmcloud_template_no_userdata(self, tmp_path):
"""Template provisioned with no user-data first boot.
no disks attached. Datasource should return found."""
self._check_via_dict(
VALID_CFG["IBMCloud-nodisks"], str(tmp_path), RC_NOT_FOUND
)
def test_ibmcloud_os_code_different_uuid(self, tmp_path):
"""IBM cloud config-2 disks must be explicit match on UUID.
If the UUID is not 9796-932E then we actually expect ConfigDrive."""
data = copy.deepcopy(VALID_CFG["IBMCloud-config-2"])
offset = None
for m, d in enumerate(data["mocks"]):
if d.get("name") == "blkid":
offset = m
break
if not offset:
raise ValueError("Expected to find 'blkid' mock, but did not.")
data["mocks"][offset]["out"] = d["out"].replace(
ds_ibm.IBM_CONFIG_UUID, "DEAD-BEEF"
)
self._check_via_dict(
data, str(tmp_path), rc=RC_FOUND, dslist=["ConfigDrive", DS_NONE]
)
def test_ibmcloud_with_nocloud_seed(self, tmp_path):
"""NoCloud seed should be preferred over IBMCloud.
A nocloud seed should be preferred over IBMCloud even if enabled.
Ubuntu 16.04 images have <vlc>/seed/nocloud-net. LP: #1766401."""
data = copy.deepcopy(VALID_CFG["IBMCloud-config-2"])
files = data.get("files", {})
if not files:
data["files"] = files
files.update(VALID_CFG["NoCloud-seed"]["files"])
ret = self._check_via_dict(data, str(tmp_path), shell_true)
assert ["NoCloud", "IBMCloud", "None"] == ret.cfg.get(
"datasource_list"
)
def test_ibmcloud_with_configdrive_seed(self, tmp_path):
"""ConfigDrive seed should be preferred over IBMCloud.
A ConfigDrive seed should be preferred over IBMCloud even if enabled.
Ubuntu 16.04 images have a fstab entry that mounts the
METADATA disk into <vlc>/seed/config_drive. LP: ##1766401."""
data = copy.deepcopy(VALID_CFG["IBMCloud-config-2"])
files = data.get("files", {})
if not files:
data["files"] = files
files.update(VALID_CFG["ConfigDrive-seed"]["files"])
ret = self._check_via_dict(data, str(tmp_path), shell_true)
assert ["ConfigDrive", "IBMCloud", "None"] == ret.cfg.get(
"datasource_list"
)
def test_policy_disabled(self, tmp_path):
"""A Builtin policy of 'disabled' should return not found.
Even though a search would find something, the builtin policy of
disabled should cause the return of not found."""
mydata = copy.deepcopy(VALID_CFG["Ec2-hvm"])
self._check_via_dict(
mydata, str(tmp_path), rc=RC_NOT_FOUND, policy_dmi="disabled"
)
def test_policy_config_disable_overrides_builtin(self, tmp_path):
"""explicit policy: disabled in config file should cause not found."""
mydata = copy.deepcopy(VALID_CFG["Ec2-hvm"])
mydata["files"][P_DSID_CFG] = "\n".join(["policy: disabled", ""])
self._check_via_dict(mydata, str(tmp_path), rc=RC_NOT_FOUND)
def test_single_entry_defines_datasource(self, tmp_path):
"""If config has a single entry in datasource_list, that is used.
Test the valid Ec2-hvm, but provide a config file that specifies
a single entry in datasource_list. The configured value should
be used."""
mydata = copy.deepcopy(VALID_CFG["Ec2-hvm"])
cfgpath = "etc/cloud/cloud.cfg.d/myds.cfg"
mydata["files"][cfgpath] = 'datasource_list: ["NoCloud"]\n'
self._check_via_dict(
mydata, str(tmp_path), rc=RC_FOUND, dslist=["NoCloud"]
)
def test_configured_list_with_none(self, tmp_path):
"""When datasource_list already contains None, None is not added.
The explicitly configured datasource_list has 'None' in it. That
should not have None automatically added."""
mydata = copy.deepcopy(VALID_CFG["GCE"])
cfgpath = "etc/cloud/cloud.cfg.d/myds.cfg"
mydata["files"][cfgpath] = 'datasource_list: ["Ec2", "None"]\n'
self._check_via_dict(
mydata, str(tmp_path), rc=RC_FOUND, dslist=["Ec2", DS_NONE]
)
def test_nocloud_seedfrom(self, tmp_path):
"""Check seedfrom system config detects nocloud.
Verify that a cloud.cfg.d/ that contains more than two datasources in
its datasource_list will positively identify nocloud when a
datasource.NoCloud.seedfrom value exists
"""
self._check_via_dict(
copy.deepcopy(VALID_CFG["NoCloud-seedfrom"]),
str(tmp_path),
rc=RC_FOUND,
dslist=["NoCloud", DS_NONE],
)
def test_nocloud_userdata_and_metadata(self, tmp_path):
"""Check seedfrom system config detects nocloud.
Verify that a cloud.cfg.d/ that contains more than two datasources in
its datasource_list will positively identify nocloud when both
datasource.NoCloud.{user-data,meta-data} value exists
"""
self._check_via_dict(
copy.deepcopy(VALID_CFG["NoCloud-user-data-meta-data"]),
str(tmp_path),
rc=RC_FOUND,
dslist=["NoCloud", DS_NONE],
)
def test_aliyun_over_ec2(self, tmp_path):
"""Even if all other factors identified Ec2, AliYun should be used."""
mydata = copy.deepcopy(VALID_CFG["Ec2-xen"])
self._test_ds_found("AliYun", str(tmp_path))
prod_name = VALID_CFG["AliYun"]["files"][P_PRODUCT_NAME]
mydata["files"][P_PRODUCT_NAME] = prod_name
policy = "search,found=first,maybe=none,notfound=disabled"
self._check_via_dict(
mydata,
str(tmp_path),
rc=RC_FOUND,
dslist=["AliYun", DS_NONE],
policy_dmi=policy,
)
def test_openstack_on_non_intel_is_maybe(self, tmp_path):
"""On non-Intel, openstack without dmi info is none.
nova does not identify itself on platforms other than intel.
https://bugs.launchpad.net/cloud-init/+bugs?field.tag=dsid-nova"""
data = copy.deepcopy(VALID_CFG["OpenStack"])
del data["files"][P_PRODUCT_NAME]
data.update(
{
"policy_dmi": POLICY_FOUND_OR_MAYBE,
"policy_no_dmi": DI_DEFAULT_POLICY_NO_DMI,
}
)
# this should show not found as default uname in tests is intel.
# and intel openstack requires positive identification.
self._check_via_dict(
data, str(tmp_path / "0"), RC_NOT_FOUND, dslist=None
)
# updating the uname to ppc64 though should get a maybe.
data.update({"mocks": [MOCK_VIRT_IS_KVM, MOCK_UNAME_IS_PPC64]})
(_, _, err, _, _) = self._check_via_dict(
data, str(tmp_path / "1"), RC_NOT_FOUND
)
assert "check for 'OpenStack' returned maybe" in err
assert "No ds found" in err
assert "Disabled cloud-init" in err
assert "returning 1" in err
def test_default_ovf_with_detect_virt_none_not_found(self, tmp_path):
"""OVF identifies not found when detect_virt returns "none"."""
self._check_via_dict(
{"ds": "OVF"},
str(tmp_path),
rc=RC_NOT_FOUND,
policy_dmi="disabled",
)
def test_default_ovf_returns_not_found_on_azure(self, tmp_path):
"""OVF datasource won't be found as false positive on Azure."""
ovfonazure = copy.deepcopy(VALID_CFG["OVF"])
# Set azure asset tag to assert OVF content not found
ovfonazure["files"][
P_CHASSIS_ASSET_TAG
] = "7783-7084-3265-9085-8269-3286-77\n"
self._check_via_dict(
ovfonazure, str(tmp_path), RC_FOUND, dslist=["Azure", DS_NONE]
)
def test_ovf_on_vmware_iso_found_by_cdrom_with_matching_fs_label(
self, tmp_path
):
"""OVF is identified by well-known iso9660 labels."""
ovf_cdrom_by_label = copy.deepcopy(VALID_CFG["OVF"])
# Unset matching cdrom ovf schema content
ovf_cdrom_by_label["files"]["dev/sr0"] = "No content match"
self._check_via_dict(
ovf_cdrom_by_label,
str(tmp_path),
rc=RC_NOT_FOUND,
policy_dmi="disabled",
)
# Add recognized labels
valid_ovf_labels = [
"ovf-transport",
"OVF-TRANSPORT",
"OVFENV",
"ovfenv",
"OVF ENV",
"ovf env",
]
for valid_ovf_label in valid_ovf_labels:
ovf_cdrom_by_label["mocks"][0]["out"] = blkid_out(
[
{"DEVNAME": "sda1", "TYPE": "ext4", "LABEL": "rootfs"},
{
"DEVNAME": "sr0",
"TYPE": "iso9660",
"LABEL": valid_ovf_label,
},
{"DEVNAME": "vda1", "TYPE": "ntfs", "LABEL": "data"},
]
)
self._check_via_dict(
ovf_cdrom_by_label,
str(tmp_path),
rc=RC_FOUND,
dslist=["OVF", DS_NONE],
)
def test_ovf_on_vmware_iso_found_by_cdrom_with_different_size(
self, tmp_path
):
"""OVF is identified by well-known iso9660 labels."""
ovf_cdrom_with_size = copy.deepcopy(VALID_CFG["OVF"])
# Set cdrom size to 20480 (10MB in 512 byte units)
ovf_cdrom_with_size["files"]["sys/class/block/sr0/size"] = "20480\n"
self._check_via_dict(
ovf_cdrom_with_size,
str(tmp_path),
rc=RC_NOT_FOUND,
policy_dmi="disabled",
)
# Set cdrom size to 204800 (100MB in 512 byte units)
ovf_cdrom_with_size["files"]["sys/class/block/sr0/size"] = "204800\n"
self._check_via_dict(
ovf_cdrom_with_size,
str(tmp_path),
rc=RC_NOT_FOUND,
policy_dmi="disabled",
)
# Set cdrom size to 18432 (9MB in 512 byte units)
ovf_cdrom_with_size["files"]["sys/class/block/sr0/size"] = "18432\n"
self._check_via_dict(
ovf_cdrom_with_size,
str(tmp_path),
rc=RC_FOUND,
dslist=["OVF", DS_NONE],
)
# Set cdrom size to 2048 (1MB in 512 byte units)
ovf_cdrom_with_size["files"]["sys/class/block/sr0/size"] = "2048\n"
self._check_via_dict(
ovf_cdrom_with_size,
str(tmp_path),
rc=RC_FOUND,
dslist=["OVF", DS_NONE],
)
def test_smartos_lxbrand_requires_socket(self, tmp_path):
"""SmartOS cloud should not be identified if no socket file."""
mycfg = copy.deepcopy(VALID_CFG["SmartOS-lxbrand"])
del mycfg["files"][ds_smartos.METADATA_SOCKFILE]
self._check_via_dict(
mycfg, str(tmp_path), rc=RC_NOT_FOUND, policy_dmi="disabled"
)
def test_smartos_lxbrand_requires_socket_env(self, tmp_path):
"""SmartOS cloud should not be identified if no socket file."""
mycfg = copy.deepcopy(VALID_CFG["SmartOS-lxbrand-env"])
del mycfg["files"][ds_smartos.METADATA_SOCKFILE]
self._check_via_dict(
mycfg, str(tmp_path), rc=RC_NOT_FOUND, policy_dmi="disabled"
)
def test_path_env_gets_set_from_main(self, tmp_path):
"""PATH environment should always have some tokens when main is run.
We explicitly call main as we want to ensure it updates PATH."""
cust = copy.deepcopy(VALID_CFG["NoCloud"])
rootd = str(tmp_path)
mpp = "main-printpath"
pre = "MYPATH="
cust["files"][mpp] = (
'PATH="/mycust/path"; main; r=$?; echo ' + pre + "$PATH; exit $r;"
)
ret = self._check_via_dict(
cust,
rootd,
RC_FOUND,
func=".",
args=[os.path.join(rootd, mpp)],
)
match = [
line for line in ret.stdout.splitlines() if line.startswith(pre)
][0]
toks = match.replace(pre, "").split(":")
expected = ["/sbin", "/bin", "/usr/sbin", "/usr/bin", "/mycust/path"]
assert expected == [
p for p in expected if p in toks
], "path did not have expected tokens"
def test_vmware_on_vmware_open_vm_tools_64(self, tmp_path):
"""VMware is identified when open-vm-tools installed in /usr/lib64."""
cust64 = copy.deepcopy(VALID_CFG["VMware-vmware-customization"])
p32 = "usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so"
open64 = "usr/lib64/open-vm-tools/plugins/vmsvc/libdeployPkgPlugin.so"
cust64["files"][open64] = cust64["files"][p32]
del cust64["files"][p32]
self._check_via_dict(
cust64, str(tmp_path), RC_FOUND, dslist=[cust64.get("ds"), DS_NONE]
)
def test_vmware_on_vmware_open_vm_tools_x86_64_linux_gnu(self, tmp_path):
"""VMware is identified when open-vm-tools installed in
/usr/lib/x86_64-linux-gnu."""
cust64 = copy.deepcopy(VALID_CFG["VMware-vmware-customization"])
p32 = "usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so"
x86 = (
"usr/lib/x86_64-linux-gnu/open-vm-tools/plugins/vmsvc/"
"libdeployPkgPlugin.so"
)
cust64["files"][x86] = cust64["files"][p32]
del cust64["files"][p32]
self._check_via_dict(
cust64, str(tmp_path), RC_FOUND, dslist=[cust64.get("ds"), DS_NONE]
)
def test_vmware_on_vmware_open_vm_tools_aarch64_linux_gnu(self, tmp_path):
"""VMware is identified when open-vm-tools installed in
/usr/lib/aarch64-linux-gnu."""
cust64 = copy.deepcopy(VALID_CFG["VMware-vmware-customization"])
p32 = "usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so"
aarch64 = (
"usr/lib/aarch64-linux-gnu/open-vm-tools/plugins/vmsvc/"
"libdeployPkgPlugin.so"
)
cust64["files"][aarch64] = cust64["files"][p32]
del cust64["files"][p32]
self._check_via_dict(
cust64, str(tmp_path), RC_FOUND, dslist=[cust64.get("ds"), DS_NONE]
)
def test_vmware_on_vmware_open_vm_tools_i386_linux_gnu(self, tmp_path):
"""VMware is identified when open-vm-tools installed in
/usr/lib/i386-linux-gnu."""
cust64 = copy.deepcopy(VALID_CFG["VMware-vmware-customization"])
p32 = "usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so"
i386 = (
"usr/lib/i386-linux-gnu/open-vm-tools/plugins/vmsvc/"
"libdeployPkgPlugin.so"
)
cust64["files"][i386] = cust64["files"][p32]
del cust64["files"][p32]
self._check_via_dict(
cust64, str(tmp_path), RC_FOUND, dslist=[cust64.get("ds"), DS_NONE]
)
@pytest.mark.allow_subp_for("sh")
class TestAkamai(DsIdentifyBase):
def test_found_by_sys_vendor_akamai(self, tmp_path):
"""
ds-identify finds Akamai by system-manufacturer dmi field when set with
name "Akamai" (expected in the future)
"""
cfg = copy.deepcopy(VALID_CFG["Akamai"])
cfg["mocks"][0]["RET"] = "Akamai"
self._check_via_dict(cfg, str(tmp_path), rc=RC_FOUND)
def test_not_found(self, tmp_path):
"""ds-identify does not find Akamai by system-manufacturer field"""
cfg = copy.deepcopy(VALID_CFG["Akamai"])
cfg["mocks"][0]["RET"] = "Other"
self._check_via_dict(cfg, str(tmp_path), rc=RC_NOT_FOUND)
@pytest.mark.allow_subp_for("sh")
class TestIsIBMProvisioning(DsIdentifyBase):
"""Test the is_ibm_provisioning method in ds-identify."""
inst_log = "/root/swinstall.log"
prov_cfg = "/root/provisioningConfiguration.cfg"
boot_ref = "/proc/1/environ"
funcname = "is_ibm_provisioning"
def test_no_config(self, tmp_path):
"""No provisioning config means not provisioning."""
ret = self.call(str(tmp_path), files={}, func=self.funcname)
assert shell_false == ret.rc
def test_config_only(self, tmp_path):
"""A provisioning config without a log means provisioning."""
ret = self.call(
str(tmp_path),
files={self.prov_cfg: "key=value"},
func=self.funcname,
)
assert shell_true == ret.rc
def test_config_with_old_log(self, tmp_path):
"""A config with a log from previous boot is not provisioning."""
rootd = str(tmp_path)
data = {
self.prov_cfg: ("key=value\nkey2=val2\n", -10),
self.inst_log: ("log data\n", -30),
self.boot_ref: ("PWD=/", 0),
}
populate_dir_with_ts(rootd, data)
ret = self.call(rootd=rootd, func=self.funcname)
assert shell_false == ret.rc
assert "from previous boot" in ret.stderr
def test_config_with_new_log(self, tmp_path):
"""A config with a log from this boot is provisioning."""
rootd = str(tmp_path)
data = {
self.prov_cfg: ("key=value\nkey2=val2\n", -10),
self.inst_log: ("log data\n", 30),
self.boot_ref: ("PWD=/", 0),
}
populate_dir_with_ts(rootd, data)
ret = self.call(rootd=rootd, func=self.funcname)
assert shell_true == ret.rc
assert "from current boot" in ret.stderr
class TestOracle(DsIdentifyBase):
@pytest.mark.allow_subp_for("sh")
def test_not_found(self, tmp_path):
"""Simple negative test of Oracle."""
mycfg = copy.deepcopy(VALID_CFG["Oracle"])
mycfg["files"][P_CHASSIS_ASSET_TAG] = "Not Oracle"
self._check_via_dict(mycfg, str(tmp_path), rc=RC_NOT_FOUND)
@pytest.mark.allow_subp_for("sh")
class TestWSL(DsIdentifyBase):
def test_no_userprofile(self, tmp_path):
"""Negative test by failing to read the %USERPROFILE% environment
variable.
"""
data = copy.deepcopy(VALID_CFG["WSL-supported"])
data["mocks"].append(
{
"name": "WSL_run_cmd",
"ret": 0,
"RET": "\r\n",
},
)
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
def test_no_cloudinitdir_in_userprofile(self, tmp_path):
"""Negative test by not finding %USERPROFILE%/.cloud-init."""
data = copy.deepcopy(VALID_CFG["WSL-supported"])
userprofile = str(tmp_path)
data["mocks"].append(
{
"name": "WSL_profile_dir",
"ret": 0,
"RET": userprofile,
},
)
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
def test_empty_cloudinitdir(self, tmp_path):
"""Negative test by lack of host filesystem mount points."""
data = copy.deepcopy(VALID_CFG["WSL-supported"])
userprofile = str(tmp_path)
data["mocks"].append(
{
"name": "WSL_profile_dir",
"ret": 0,
"RET": userprofile,
},
)
cloudinitdir = os.path.join(userprofile, ".cloud-init")
os.mkdir(cloudinitdir)
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
def test_found_fail_due_instance_name_parsing(self, tmp_path):
"""WSL datasource detection fail due parsing error even though the file
exists.
"""
data = copy.deepcopy(VALID_CFG["WSL-supported-debian"])
userprofile = str(tmp_path)
data["mocks"].append(
{
"name": "WSL_profile_dir",
"ret": 0,
"RET": userprofile,
},
)
# Forcing WSL_linux2win_path to return a path we'll fail to parse
# (missing one / in the begining of the path).
for i, m in enumerate(data["mocks"]):
if m["name"] == "WSL_linux2win_path":
data["mocks"][i]["RET"] = "/wsl.localhost/cant-findme"
cloudinitdir = os.path.join(userprofile, ".cloud-init")
os.mkdir(cloudinitdir)
filename = os.path.join(cloudinitdir, "cant-findme.user-data")
Path(filename).touch()
self._check_via_dict(data, str(tmp_path), RC_NOT_FOUND)
Path(filename).unlink()
def test_found_via_userdata_version_codename(self, tmp_path):
"""WSL datasource detected by VERSION_CODENAME when no VERSION_ID"""
data = copy.deepcopy(VALID_CFG["WSL-supported-debian"])
userprofile = str(tmp_path)
data["mocks"].append(
{
"name": "WSL_profile_dir",
"ret": 0,
"RET": userprofile,
},
)
cloudinitdir = os.path.join(userprofile, ".cloud-init")
os.mkdir(cloudinitdir)
filename = os.path.join(cloudinitdir, "debian-trixie.user-data")
Path(filename).touch()
self._check_via_dict(
data, str(tmp_path), RC_FOUND, dslist=[data.get("ds"), DS_NONE]
)
Path(filename).unlink()
def test_found_via_userdata(self, tmp_path):
"""
WSL datasource is found on applicable userdata files in cloudinitdir.
"""
data = copy.deepcopy(VALID_CFG["WSL-supported"])
userprofile = str(tmp_path)
data["mocks"].append(
{
"name": "WSL_profile_dir",
"ret": 0,
"RET": userprofile,
},
)
cloudinitdir = os.path.join(userprofile, ".cloud-init")
os.mkdir(cloudinitdir)
up4wcloudinitdir = os.path.join(userprofile, ".ubuntupro/.cloud-init")
os.makedirs(up4wcloudinitdir, exist_ok=True)
userdata_files = [
os.path.join(
up4wcloudinitdir, MOCK_WSL_INSTANCE_DATA["name"] + ".user-data"
),
os.path.join(up4wcloudinitdir, "agent.yaml"),
os.path.join(
cloudinitdir, MOCK_WSL_INSTANCE_DATA["name"] + ".user-data"
),
os.path.join(
cloudinitdir,
"%s-%s.user-data"
% (
MOCK_WSL_INSTANCE_DATA["distro"],
MOCK_WSL_INSTANCE_DATA["version"],
),
),
os.path.join(
cloudinitdir,
MOCK_WSL_INSTANCE_DATA["distro"] + "-all.user-data",
),
os.path.join(cloudinitdir, "default.user-data"),
]
for i, filename in enumerate(userdata_files):
Path(filename).touch()
self._check_via_dict(
data,
str(tmp_path / str(i)),
RC_FOUND,
dslist=[data.get("ds"), DS_NONE],
)
# Delete one by one
Path(filename).unlink()
# Until there is none, making the datasource no longer viable.
self._check_via_dict(data, str(tmp_path / "-final"), RC_NOT_FOUND)
def blkid_out(disks=None):
"""Convert a list of disk dictionaries into blkid content."""
if disks is None:
disks = []
lines = []
for disk in disks:
if not disk["DEVNAME"].startswith("/dev/"):
disk["DEVNAME"] = "/dev/" + disk["DEVNAME"]
# devname needs to be first.
lines.append("%s=%s" % ("DEVNAME", disk["DEVNAME"]))
for key in [d for d in disk if d != "DEVNAME"]:
lines.append("%s=%s" % (key, disk[key]))
lines.append("")
return "\n".join(lines)
def geom_out(disks=None):
"""Convert a list of disk dictionaries into geom content.
geom called with -a (provider) and -s (script-friendly), will produce the
following output:
gpt/gptboot0 N/A vtbd1p1
gpt/swap0 N/A vtbd1p2
iso9660/cidata N/A vtbd2
"""
if disks is None:
disks = []
lines = []
for disk in disks:
lines.append(
"%s/%s N/A %s" % (disk["TYPE"], disk["LABEL"], disk["DEVNAME"])
)
lines.append("")
return "\n".join(lines)
def _print_run_output(rc, out, err, cfg, files):
"""A helper to print return of TestDsIdentify.
_print_run_output(self.call())"""
print(
"\n".join(
[
"-- rc = %s --" % rc,
"-- out --",
str(out),
"-- err --",
str(err),
"-- cfg --",
atomic_helper.json_dumps(cfg),
]
)
)
print("-- files --")
for k, v in files.items():
if "/_shwrap" in k:
continue
print(" === %s ===" % k)
for line in v.splitlines():
print(" " + line)
VALID_CFG = {
"Akamai": {
"ds": "Akamai",
"mocks": [{"name": "dmi_decode", "ret": 0, "RET": "Linode"}],
},
"AliYun": {
"ds": "AliYun",
"files": {P_PRODUCT_NAME: "Alibaba Cloud ECS\n"},
},
"Azure-dmi-detection": {
"ds": "Azure",
"files": {
P_CHASSIS_ASSET_TAG: "7783-7084-3265-9085-8269-3286-77\n",
},
},
"Azure-seed-detection": {
"ds": "Azure",
"files": {
P_CHASSIS_ASSET_TAG: "No-match\n",
os.path.join(P_SEED_DIR, "azure", "ovf-env.xml"): "present\n",
},
},
"CloudCIX": {
"ds": "CloudCIX",
"files": {P_PRODUCT_NAME: "CloudCIX\n"},
},
"Azure-parse-invalid": {
"ds": "Azure",
"files": {
P_CHASSIS_ASSET_TAG: "7783-7084-3265-9085-8269-3286-77\n",
"etc/cloud/cloud.cfg.d/91-azure_datasource.cfg": (
"datasource_list:\n - Azure"
),
},
},
"Ec2-hvm": {
"ds": "Ec2",
"mocks": [{"name": "detect_virt", "RET": "kvm", "ret": 0}],
"files": {
P_PRODUCT_SERIAL: "ec23aef5-54be-4843-8d24-8c819f88453e\n",
P_PRODUCT_UUID: "EC23AEF5-54BE-4843-8D24-8C819F88453E\n",
},
},
"Ec2-hvm-swap-endianness": {
"ds": "Ec2",
"mocks": [{"name": "detect_virt", "RET": "kvm", "ret": 0}],
"files": {
P_PRODUCT_UUID: "AB232AEC-54BE-4843-8D24-8C819F88453E\n",
},
},
"Ec2-hvm-env": {
"ds": "Ec2",
"mocks": [{"name": "detect_virt_env", "RET": "vm:kvm", "ret": 0}],
"files": {
P_PRODUCT_SERIAL: "ec23aef5-54be-4843-8d24-8c819f88453e\n",
P_PRODUCT_UUID: "EC23AEF5-54BE-4843-8D24-8C819F88453E\n",
},
},
"Ec2-xen": {
"ds": "Ec2",
"mocks": [MOCK_VIRT_IS_XEN],
"files": {
"sys/hypervisor/uuid": "ec2c6e2f-5fac-4fc7-9c82-74127ec14bbb\n"
},
},
"Ec2-brightbox": {
"ds": "Ec2",
"files": {P_PRODUCT_SERIAL: "srv-otuxg.gb1.brightbox.com\n"},
},
"Ec2-brightbox-negative": {
"ds": "Ec2",
"files": {P_PRODUCT_SERIAL: "tricky-host.bobrightbox.com\n"},
},
"GCE": {
"ds": "GCE",
"files": {P_PRODUCT_NAME: "Google Compute Engine\n"},
"mocks": [MOCK_VIRT_IS_KVM],
},
"GCE_ENV": {
"ds": "GCE",
"files": {P_PRODUCT_NAME: "Google Compute Engine\n"},
"env_vars": KVM_ENV,
"no_mocks": ["detect_virt"],
},
"GCE-serial": {
"ds": "GCE",
"files": {P_PRODUCT_SERIAL: "GoogleCloud-8f2e88f\n"},
"mocks": [MOCK_VIRT_IS_KVM],
},
"LXD-kvm": {
"ds": "LXD",
"files": {P_BOARD_NAME: "LXD\n"},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
"LXD-kvm-not-MAAS-1": {
"ds": "LXD",
"files": {
P_BOARD_NAME: "LXD\n",
"etc/cloud/cloud.cfg.d/92-broken-maas.cfg": (
"datasource:\n MAAS:\n metadata_urls: [ 'blah.com' ]"
),
},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
"LXD-kvm-not-MAAS-2": {
"ds": "LXD",
"files": {
P_BOARD_NAME: "LXD\n",
"etc/cloud/cloud.cfg.d/92-broken-maas.cfg": ("#MAAS: None"),
},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
"LXD-kvm-not-MAAS-3": {
"ds": "LXD",
"files": {
P_BOARD_NAME: "LXD\n",
"etc/cloud/cloud.cfg.d/92-broken-maas.cfg": ("MAAS: None\n"),
},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
"flow_sequence-control": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
"""\
"datasource-list": [ None ] \n
"""
)
},
},
# no quotes, whitespace between all chars and at the end of line
"flow_sequence-1": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
"""\
datasource_list : [ None ] \n
"""
)
},
},
# double quotes
"flow_sequence-2": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
"""\
"datasource_list": [None]
"""
)
},
},
# single quotes
"flow_sequence-3": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
"""\
'datasource_list': [None]
"""
)
},
},
# no newlines
"flow_sequence-4": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent("datasource_list: [ None ]")
},
},
# double quoted key, single quoted list member
"flow_sequence-5": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
"\"datasource_list\": [ 'None' ] "
)
},
},
# single quotes, whitespace before colon
"flow_sequence-6": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent("'datasource_list' : [ None ] ")
},
},
"flow_sequence-7": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
'"datasource_list" : [ None ] '
)
},
},
# tabs as part of whitespace between all chars
"flow_sequence-8": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {
"etc/cloud/cloud.cfg": dedent(
'"datasource_list" \t\t : \t\t[\t \tNone \t \t ] \t\t '
)
},
},
# no quotes, no whitespace
"flow_sequence-9": {
"ds": "None",
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
"files": {"etc/cloud/cloud.cfg": dedent("datasource_list: [None]")},
},
"LXD-kvm-not-azure": {
"ds": "Azure",
"files": {
P_BOARD_NAME: "LXD\n",
"etc/cloud/cloud.cfg.d/92-broken-azure.cfg": (
"datasource_list:\n - Azure"
),
},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
"LXD-kvm-qemu-kernel-gt-5.10": { # LXD host > 5.10 kvm launch virt==qemu
"ds": "LXD",
"files": {P_BOARD_NAME: "LXD\n"},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM_QEMU],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
# LXD host > 5.10 kvm launch virt==qemu
"LXD-kvm-qemu-kernel-gt-5.10-env": {
"ds": "LXD",
"files": {
P_BOARD_NAME: "LXD\n",
# this test is systemd-specific, but may run on non-systemd systems
# ensure that /run/systemd/ exists, such that this test will take
# the systemd branch on those systems as well
#
# https://github.com/canonical/cloud-init/issues/5095
"/run/systemd/somefile": "",
},
# /dev/lxd/sock does not exist and KVM virt-type
"mocks": [
{"name": "is_socket_file", "ret": 1},
],
"env_vars": IS_KVM_QEMU_ENV,
"no_mocks": [
"dscheck_LXD",
"detect_virt",
], # Don't default mock dscheck_LXD
},
"LXD": {
"ds": "LXD",
# /dev/lxd/sock exists
"mocks": [{"name": "is_socket_file", "ret": 0}],
"no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD
},
"NoCloud": {
"ds": "NoCloud",
"mocks": [
MOCK_VIRT_IS_KVM,
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
BLKID_UEFI_UBUNTU
+ [
{
"DEVNAME": "vdb",
"TYPE": "iso9660",
"LABEL": "cidata",
}
]
),
},
],
"files": {
"dev/vdb": "pretend iso content for cidata\n",
},
},
"NoCloud-cfg": {
"ds": "NoCloud",
"files": {
# Also include a datasource list of more than just
# [NoCloud, None], because that would automatically select
# NoCloud without checking
"etc/cloud/cloud.cfg": dedent(
"""\
datasource_list: [ Azure, OpenStack, NoCloud, None ]
datasource:
NoCloud:
user-data: |
#cloud-config
hostname: footbar
meta-data: |
instance_id: cloud-image
"""
)
},
},
"NoCloud-fbsd": {
"ds": "NoCloud",
"mocks": [
MOCK_VIRT_IS_KVM,
MOCK_UNAME_IS_FREEBSD,
{
"name": "geom",
"ret": 0,
"out": geom_out(
[{"DEVNAME": "vtbd", "TYPE": "iso9660", "LABEL": "cidata"}]
),
},
],
"files": {
"/dev/vtdb": "pretend iso content for cidata\n",
},
},
"NoCloudUpper": {
"ds": "NoCloud",
"mocks": [
MOCK_VIRT_IS_KVM,
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
BLKID_UEFI_UBUNTU
+ [
{
"DEVNAME": "vdb",
"TYPE": "iso9660",
"LABEL": "CIDATA",
}
]
),
},
],
"files": {
"dev/vdb": "pretend iso content for cidata\n",
},
},
"NoCloud-fatboot": {
"ds": "NoCloud",
"mocks": [
MOCK_VIRT_IS_XEN,
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
BLKID_UEFI_UBUNTU
+ [
{
"DEVNAME": "xvdb",
"TYPE": "vfat",
"SEC_TYPE": "msdos",
"UUID": "355a-4FC2",
"LABEL_FATBOOT": "cidata",
}
]
),
},
],
"files": {
"dev/vdb": "pretend iso content for cidata\n",
},
},
"NoCloud-seed": {
"ds": "NoCloud",
"files": {
os.path.join(P_SEED_DIR, "nocloud", "user-data"): "ud\n",
os.path.join(P_SEED_DIR, "nocloud", "meta-data"): "md\n",
},
},
"NoCloud-seedfrom": {
"ds": "NoCloud",
"files": {
# Also include a datasource list of more than just
# [NoCloud, None], because that would automatically select
# NoCloud without checking
"etc/cloud/cloud.cfg.d/test.cfg": dedent(
"""\
datasource_list: [ Azure, OpenStack, NoCloud, None ]
datasource:
NoCloud:
seedfrom: http://0.0.0.0/test
"""
)
},
},
"NoCloud-user-data-meta-data": {
"ds": "NoCloud",
"files": {
# Also include a datasource list of more than just
# [NoCloud, None], because that would automatically select
# NoCloud without checking
"etc/cloud/cloud.cfg.d/test.cfg": dedent(
"""\
datasource_list: [ Azure, OpenStack, NoCloud, None ]
datasource:
NoCloud:
meta-data: ""
user-data: |
#cloud-config
<some-config>
"""
)
},
},
"NoCloud-seed-ubuntu-core": {
"ds": "NoCloud",
"files": {
os.path.join(
"writable/system-data", P_SEED_DIR, "nocloud-net", "user-data"
): "ud\n",
os.path.join(
"writable/system-data", P_SEED_DIR, "nocloud-net", "meta-data"
): "md\n",
},
},
"OpenStack": {
"ds": "OpenStack",
"files": {P_PRODUCT_NAME: "OpenStack Nova\n"},
"mocks": [MOCK_VIRT_IS_KVM],
"policy_dmi": POLICY_FOUND_ONLY,
"policy_no_dmi": POLICY_FOUND_ONLY,
},
"OpenStack-OpenTelekom": {
# OTC gen1 (Xen) hosts use OpenStack datasource, LP: #1756471
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "OpenTelekomCloud\n"},
"mocks": [MOCK_VIRT_IS_XEN],
},
"OpenStack-SAPCCloud": {
# SAP CCloud hosts use OpenStack on VMware
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "SAP CCloud VM\n"},
"mocks": [MOCK_VIRT_IS_VMWARE],
},
"OpenStack-SAPCCloud-env": {
# SAP CCloud hosts use OpenStack on VMware
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "SAP CCloud VM\n"},
"env_vars": IS_VMWARE_ENV,
"no_mocks": ["detect_virt"],
},
"OpenStack-HuaweiCloud": {
# Huawei Cloud hosts use OpenStack
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "HUAWEICLOUD\n"},
"mocks": [MOCK_VIRT_IS_KVM],
},
"OpenStack-SamsungCloudPlatform": {
# Samsung Cloud Platform hosts use OpenStack
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "Samsung Cloud Platform\n"},
"mocks": [MOCK_VIRT_IS_KVM],
},
"OpenStack-AssetTag-Nova": {
# VMware vSphere can't modify product-name, LP: #1669875
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "OpenStack Nova\n"},
"mocks": [MOCK_VIRT_IS_XEN],
},
"OpenStack-AssetTag-Compute": {
# VMware vSphere can't modify product-name, LP: #1669875
"ds": "OpenStack",
"files": {P_CHASSIS_ASSET_TAG: "OpenStack Compute\n"},
"mocks": [MOCK_VIRT_IS_XEN],
},
"OVF-seed": {
"ds": "OVF",
"files": {
os.path.join(P_SEED_DIR, "ovf", "ovf-env.xml"): "present\n",
},
},
"OVF": {
"ds": "OVF",
"mocks": [
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{"DEVNAME": "sr0", "TYPE": "iso9660", "LABEL": ""},
{
"DEVNAME": "sr1",
"TYPE": "iso9660",
"LABEL": "ignoreme",
},
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
]
),
},
MOCK_VIRT_IS_VMWARE,
],
"files": {
"dev/sr0": "pretend ovf iso has " + OVF_MATCH_STRING + "\n",
"sys/class/block/sr0/size": "2048\n",
},
},
"OVF-guestinfo": {
"ds": "OVF",
"mocks": [
{
"name": "ovf_vmware_transport_guestinfo",
"ret": 0,
"out": '<?xml version="1.0" encoding="UTF-8"?>\n<Environment',
},
MOCK_VIRT_IS_VMWARE,
],
},
"ConfigDrive": {
"ds": "ConfigDrive",
"mocks": [
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "vda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "vdb",
"TYPE": "vfat",
"LABEL": "config-2",
},
]
),
},
],
},
"ConfigDriveUpper": {
"ds": "ConfigDrive",
"mocks": [
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "vda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "vdb",
"TYPE": "vfat",
"LABEL": "CONFIG-2",
},
]
),
},
],
},
"ConfigDrive-seed": {
"ds": "ConfigDrive",
"files": {
os.path.join(
P_SEED_DIR,
"config_drive",
"openstack",
"latest",
"meta_data.json",
): "md\n"
},
},
"RbxCloud": {
"ds": "RbxCloud",
"mocks": [
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "vda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
},
{"DEVNAME": "vdb", "TYPE": "vfat", "LABEL": "CLOUDMD"},
]
),
},
],
},
"RbxCloudLower": {
"ds": "RbxCloud",
"mocks": [
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "vda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
},
{"DEVNAME": "vdb", "TYPE": "vfat", "LABEL": "cloudmd"},
]
),
},
],
},
"Hetzner": {
"ds": "Hetzner",
"files": {P_SYS_VENDOR: "Hetzner\n"},
},
"Hetzner-kenv": {
"ds": "Hetzner",
"mocks": [
MOCK_UNAME_IS_FREEBSD,
{"name": "get_kenv_field", "ret": 0, "RET": "Hetzner"},
],
},
"Hetzner-sysctl": {
"ds": "Hetzner",
"mocks": [
MOCK_UNAME_IS_OPENBSD,
{"name": "get_sysctl_field", "ret": 0, "RET": "Hetzner"},
],
},
"Hetzner-dmidecode": {
"ds": "Hetzner",
"mocks": [{"name": "dmi_decode", "ret": 0, "RET": "Hetzner"}],
},
"NWCS": {
"ds": "NWCS",
"files": {P_SYS_VENDOR: "NWCS\n"},
},
"NWCS-kenv": {
"ds": "NWCS",
"mocks": [
MOCK_UNAME_IS_FREEBSD,
{"name": "get_kenv_field", "ret": 0, "RET": "NWCS"},
],
},
"NWCS-dmidecode": {
"ds": "NWCS",
"mocks": [{"name": "dmi_decode", "ret": 0, "RET": "NWCS"}],
},
"IBMCloud-metadata": {
"ds": "IBMCloud",
"mocks": [
MOCK_VIRT_IS_XEN,
{"name": "is_ibm_provisioning", "ret": shell_false},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "xvda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "xvda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "xvdb",
"TYPE": "vfat",
"LABEL": "METADATA",
},
]
),
},
],
},
"IBMCloud-config-2": {
"ds": "IBMCloud",
"mocks": [
MOCK_VIRT_IS_XEN,
{"name": "is_ibm_provisioning", "ret": shell_false},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "xvda1",
"TYPE": "ext3",
"PARTUUID": uuid4(),
"UUID": uuid4(),
"LABEL": "cloudimg-bootfs",
},
{
"DEVNAME": "xvdb",
"TYPE": "vfat",
"LABEL": "config-2",
"UUID": ds_ibm.IBM_CONFIG_UUID,
},
{
"DEVNAME": "xvda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
"UUID": uuid4(),
},
]
),
},
],
},
"IBMCloud-nodisks": {
"ds": "IBMCloud",
"mocks": [
MOCK_VIRT_IS_XEN,
{"name": "is_ibm_provisioning", "ret": shell_false},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "xvda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
{
"DEVNAME": "xvda2",
"TYPE": "ext4",
"LABEL": "cloudimg-rootfs",
"PARTUUID": uuid4(),
},
]
),
},
],
},
"Oracle": {
"ds": "Oracle",
"files": {
P_CHASSIS_ASSET_TAG: ds_oracle.CHASSIS_ASSET_TAG + "\n",
},
},
"SmartOS-bhyve": {
"ds": "SmartOS",
"mocks": [
MOCK_VIRT_IS_VM_OTHER,
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{
"DEVNAME": "vda1",
"TYPE": "ext4",
"PARTUUID": "49ec635a-01",
},
{
"DEVNAME": "vda2",
"TYPE": "swap",
"LABEL": "cloudimg-swap",
"PARTUUID": "49ec635a-02",
},
]
),
},
],
"files": {P_PRODUCT_NAME: "SmartDC HVM\n"},
},
"SmartOS-lxbrand": {
"ds": "SmartOS",
"mocks": [
MOCK_VIRT_IS_CONTAINER_OTHER,
{
"name": "uname",
"ret": 0,
"out": ("Linux BrandZ virtual linux x86_64"),
},
{"name": "blkid", "ret": 2, "out": ""},
],
"files": {ds_smartos.METADATA_SOCKFILE: "would be a socket\n"},
},
"SmartOS-lxbrand-env": {
"ds": "SmartOS",
"mocks": [
{
"name": "uname",
"ret": 0,
"out": ("Linux BrandZ virtual linux x86_64"),
},
{"name": "blkid", "ret": 2, "out": ""},
],
"no_mocks": ["detect_virt"],
"env_vars": IS_CONTAINER_OTHER_ENV,
"files": {ds_smartos.METADATA_SOCKFILE: "would be a socket\n"},
},
"Ec2-ZStack": {
"ds": "Ec2",
"files": {P_CHASSIS_ASSET_TAG: "123456.zstack.io\n"},
},
"Ec2-E24Cloud": {
"ds": "Ec2",
"files": {P_SYS_VENDOR: "e24cloud\n"},
},
"Ec2-E24Cloud-negative": {
"ds": "Ec2",
"files": {P_SYS_VENDOR: "e24cloudyday\n"},
},
"VMware-NoValidTransports": {
"ds": "VMware",
"mocks": [
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-vmware-customization": {
"ds": "VMware",
"mocks": [
MOCK_VIRT_IS_VMWARE,
{
"name": "vmware_has_rpctool",
"ret": 0,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 1,
"out": "/usr/bin/vmtoolsd",
},
],
"files": {
# Setup vmware customization enabled
"usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so": "here",
"etc/cloud/cloud.cfg": "disable_vmware_customization: false\n",
},
},
"VMware-OVF-on-vmware-with-vmware-customization-and-ovf-schema": {
"ds": "VMware, OVF",
"mocks": [
MOCK_VIRT_IS_VMWARE,
{
"name": "vmware_has_rpctool",
"ret": 0,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 1,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{"DEVNAME": "sr0", "TYPE": "iso9660", "LABEL": ""},
{
"DEVNAME": "sr1",
"TYPE": "iso9660",
"LABEL": "ignoreme",
},
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
]
),
},
],
"files": {
# Setup vmware customization enabled
"usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so": "here",
"etc/cloud/cloud.cfg": "disable_vmware_customization: false\n",
# Setup ovf schema
"dev/sr0": "pretend ovf iso has " + OVF_MATCH_STRING + "\n",
"sys/class/block/sr0/size": "2048\n",
},
},
"OVF-not-on-vmware-with-vmware-customization-and-ovf-schema": {
"ds": "OVF",
"mocks": [
MOCK_VIRT_IS_NOT_VMWARE,
{
"name": "vmware_has_rpctool",
"ret": 0,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 1,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{"DEVNAME": "sr0", "TYPE": "iso9660", "LABEL": ""},
{
"DEVNAME": "sr1",
"TYPE": "iso9660",
"LABEL": "ignoreme",
},
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
]
),
},
],
"files": {
# Setup vmware customization enabled
"usr/lib/vmware-tools/plugins/vmsvc/libdeployPkgPlugin.so": "here",
"etc/cloud/cloud.cfg": "disable_vmware_customization: false\n",
# Setup ovf schema
"dev/sr0": "pretend ovf iso has " + OVF_MATCH_STRING + "\n",
"sys/class/block/sr0/size": "2048\n",
},
},
"VMware-EnvVar-NoData": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_envvar_vmx_guestinfo",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-EnvVar-NoVirtID": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_envvar_vmx_guestinfo",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_metadata",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_vendordata",
"ret": 1,
},
],
},
"VMware-EnvVar-Metadata": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_envvar_vmx_guestinfo",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_metadata",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-EnvVar-Userdata": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_envvar_vmx_guestinfo",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_userdata",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-EnvVar-Vendordata": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_envvar_vmx_guestinfo",
"ret": 0,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_has_envvar_vmx_guestinfo_vendordata",
"ret": 0,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-GuestInfo-NoData-Rpctool": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_rpctool",
"ret": 0,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 1,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-GuestInfo-NoData-Vmtoolsd": {
"ds": "VMware",
"policy_dmi": POLICY_FOUND_ONLY,
"mocks": [
{
"name": "vmware_has_rpctool",
"ret": 1,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 0,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-GuestInfo-NoVirtID": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_rpctool",
"ret": 0,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 0,
"out": "---",
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
],
},
"VMware-GuestInfo-Metadata": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_rpctool",
"ret": 1,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 0,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 0,
"out": "---",
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-GuestInfo-Userdata": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_rpctool",
"ret": 0,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 1,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_guestinfo_userdata",
"ret": 0,
"out": "---",
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-GuestInfo-Vendordata": {
"ds": "VMware",
"mocks": [
{
"name": "vmware_has_rpctool",
"ret": 1,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 0,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 1,
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 0,
"out": "---",
},
MOCK_VIRT_IS_VMWARE,
],
},
"VMware-OVF-on-vmware-with-guestinfo-metadata-and-ovf-schema": {
"ds": "VMware, OVF",
"mocks": [
MOCK_VIRT_IS_VMWARE,
{
"name": "vmware_has_rpctool",
"ret": 1,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 0,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 0,
"out": "---",
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{"DEVNAME": "sr0", "TYPE": "iso9660", "LABEL": ""},
{
"DEVNAME": "sr1",
"TYPE": "iso9660",
"LABEL": "ignoreme",
},
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
]
),
},
],
"files": {
# Setup ovf schema
"dev/sr0": "pretend ovf iso has " + OVF_MATCH_STRING + "\n",
"sys/class/block/sr0/size": "2048\n",
},
},
"OVF-not-on-vmware-with-guestinfo-metadata-and-ovf-schema": {
"ds": "OVF",
"mocks": [
MOCK_VIRT_IS_NOT_VMWARE,
{
"name": "vmware_has_rpctool",
"ret": 1,
"out": "/usr/bin/vmware-rpctool",
},
{
"name": "vmware_has_vmtoolsd",
"ret": 0,
"out": "/usr/bin/vmtoolsd",
},
{
"name": "vmware_guestinfo_metadata",
"ret": 0,
"out": "---",
},
{
"name": "vmware_guestinfo_userdata",
"ret": 1,
},
{
"name": "vmware_guestinfo_vendordata",
"ret": 1,
},
{
"name": "blkid",
"ret": 0,
"out": blkid_out(
[
{"DEVNAME": "sr0", "TYPE": "iso9660", "LABEL": ""},
{
"DEVNAME": "sr1",
"TYPE": "iso9660",
"LABEL": "ignoreme",
},
{
"DEVNAME": "vda1",
"TYPE": "vfat",
"PARTUUID": uuid4(),
},
]
),
},
],
"files": {
# Setup ovf schema
"dev/sr0": "pretend ovf iso has " + OVF_MATCH_STRING + "\n",
"sys/class/block/sr0/size": "2048\n",
},
},
"Ec2-Outscale": {
"ds": "Ec2",
"files": {
P_PRODUCT_NAME: "3DS Outscale VM\n",
P_SYS_VENDOR: "3DS Outscale\n",
},
},
"Ec2-Outscale-negative-sysvendor": {
"ds": "Ec2",
"files": {
P_PRODUCT_NAME: "3DS Outscale VM\n",
P_SYS_VENDOR: "Not 3DS Outscale\n",
},
},
"Ec2-Outscale-negative-productname": {
"ds": "Ec2",
"files": {
P_PRODUCT_NAME: "Not 3DS Outscale VM\n",
P_SYS_VENDOR: "3DS Outscale\n",
},
},
"Not-WSL": {
"ds": "WSL",
"mocks": [
MOCK_VIRT_IS_KVM,
],
},
"WSL-no-host-mounts": {
"ds": "WSL",
"mocks": [
MOCK_VIRT_IS_WSL,
MOCK_UNAME_IS_WSL,
],
"files": {
"proc/mounts": (
"/dev/sdd / ext4 rw,errors=remount-ro,data=ordered 0 0\n"
"cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec0 0\n"
"snapfuse /snap/core22/1033 fuse.snapfuse ro,nodev,user_id=0,"
"group_id=0,allow_other 0 0"
),
},
},
"WSL-supported": {
"ds": "WSL",
"mocks": [
MOCK_VIRT_IS_WSL,
MOCK_UNAME_IS_WSL,
{
"name": "WSL_path",
"ret": 0,
"RET": "//wsl.localhost/%s/" % MOCK_WSL_INSTANCE_DATA["name"],
},
],
"files": {
"proc/mounts": (
"/dev/sdd / ext4 rw,errors=remount-ro,data=ordered 0 0\n"
"cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec0 0\n"
"C:\\134 /mnt/c 9p rw,dirsync,aname=drvfs;path=C:\\;uid=0;"
"gid=0;symlinkroot=/mnt/...\n"
"snapfuse /snap/core22/1033 fuse.snapfuse ro,nodev,user_id=0,"
"group_id=0,allow_other 0 0"
),
"etc/os-release": MOCK_WSL_INSTANCE_DATA["os_release"],
},
},
"WSL-supported-debian": {
"ds": "WSL",
"mocks": [
MOCK_VIRT_IS_WSL,
MOCK_UNAME_IS_WSL,
{
"name": "WSL_path",
"ret": 0,
"RET": "//wsl.localhost/%s/" % MOCK_WSL_INSTANCE_DATA["name"],
},
],
"files": {
"proc/mounts": (
"/dev/sdd / ext4 rw,errors=remount-ro,data=ordered 0 0\n"
"cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec0 0\n"
"C:\\134 /mnt/c 9p rw,dirsync,aname=drvfs;path=C:\\;uid=0;"
"gid=0;symlinkroot=/mnt/...\n"
"snapfuse /snap/core22/1033 fuse.snapfuse ro,nodev,user_id=0,"
"group_id=0,allow_other 0 0"
),
"etc/os-release": MOCK_WSL_INSTANCE_DATA[
"os_release_no_version_id"
],
},
},
}
|