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
|
# Copyright 2019-2022 Hewlett Packard Enterprise Development Company, L.P.
# All Rights Reserved.
#
# 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 builtins
import collections
import io
import json
import os
from unittest import mock
import ddt
import sushy
from sushy.resources.system import system
import testtools
from proliantutils import exception
from proliantutils.ilo import constants as ilo_cons
from proliantutils.redfish import main
from proliantutils.redfish import redfish
from proliantutils.redfish.resources.account_service import account
from proliantutils.redfish.resources.account_service import account_service
from proliantutils.redfish.resources import gpu_common as common_gpu
from proliantutils.redfish.resources.manager import manager
from proliantutils.redfish.resources.manager import virtual_media
from proliantutils.redfish.resources.system import bios
from proliantutils.redfish.resources.system import constants as sys_cons
from proliantutils.redfish.resources.system import iscsi
from proliantutils.redfish.resources.system import memory
from proliantutils.redfish.resources.system import pci_device
from proliantutils.redfish.resources.system.storage import array_controller
from proliantutils.redfish.resources.system.storage \
import common as common_storage
from proliantutils.redfish.resources.system import system as pro_sys
from proliantutils import utils as common_utils
@ddt.ddt
class RedfishOperationsTestCase(testtools.TestCase):
@mock.patch.object(main, 'HPESushy', autospec=True)
def setUp(self, sushy_mock):
super(RedfishOperationsTestCase, self).setUp()
self.sushy = mock.MagicMock()
self.sushy.get_system_collection_path.return_value = (
'/redfish/v1/Systems')
self.sushy.get_manager_collection_path.return_value = (
'/redfish/v1/Managers')
sushy_mock.return_value = self.sushy
with open('proliantutils/tests/redfish/'
'json_samples/root.json', 'r') as f:
self.sushy.json = json.loads(f.read())
self.rf_client = redfish.RedfishOperations(
'1.2.3.4', username='foo', password='bar')
args, kwargs = sushy_mock.call_args
self.assertEqual(('https://1.2.3.4',), args)
self.assertFalse(kwargs.get('verify'))
self.assertEqual('/redfish/v1/', kwargs.get('root_prefix'))
self.assertEqual('foo', kwargs.get('username'))
self.assertEqual('bar', kwargs.get('password'))
@mock.patch.object(main, 'HPESushy', autospec=True)
def test_sushy_init_fail(self, sushy_mock):
sushy_mock.side_effect = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloConnectionError,
'The Redfish controller at "https://1.2.3.4" has thrown error',
redfish.RedfishOperations,
'1.2.3.4', username='foo', password='bar')
def test__get_sushy_system_fail(self):
self.rf_client._sushy.get_system.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish System "apple" was not found.',
self.rf_client._get_sushy_system, 'apple')
def test__get_sushy_manager_fail(self):
self.rf_client._sushy.get_manager.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish Manager "banana" was not found.',
self.rf_client._get_sushy_manager, 'banana')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_product_name(self, get_system_mock):
product_mock = mock.PropertyMock(return_value='ProLiant DL180 Gen10')
type(get_system_mock.return_value).model = product_mock
product_name = self.rf_client.get_product_name()
self.assertEqual('ProLiant DL180 Gen10', product_name)
def test_get_host_power_status(self):
self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_ON
power_state = self.rf_client.get_host_power_status()
self.assertEqual('ON', power_state)
def test_reset_server(self):
self.rf_client.reset_server()
self.sushy.get_system().reset_system.assert_called_once_with(
sushy.RESET_FORCE_RESTART)
def test_reset_server_invalid_value(self):
self.sushy.get_system().reset_system.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to reset server.',
self.rf_client.reset_server)
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
def test_set_host_power_no_change(self, get_host_power_status_mock):
get_host_power_status_mock.return_value = 'ON'
self.rf_client.set_host_power('ON')
self.assertTrue(get_host_power_status_mock.called)
self.assertFalse(self.sushy.get_system().reset_system.called)
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
def test_set_host_power_failure(self, get_host_power_status_mock):
get_host_power_status_mock.return_value = 'OFF'
self.sushy.get_system().reset_system.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to set power state of server to ON',
self.rf_client.set_host_power, 'ON')
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
def test_set_host_power_invalid_input(self, host_power_status_mock):
self.assertRaisesRegex(
exception.InvalidInputError,
'The parameter "target_value" value "Off" is invalid.',
self.rf_client.set_host_power, 'Off')
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
def test_set_host_power_exc(self, host_power_status_mock):
self.assertRaises(exception.InvalidInputError,
self.rf_client.set_host_power, 'invalid')
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
@mock.patch.object(redfish.RedfishOperations, '_retry_until_powered_on')
def test_set_host_power_off(self, retry_mock, host_power_status_mock):
host_power_status_mock.return_value = 'ON'
self.rf_client.set_host_power('OFF')
host_power_status_mock.assert_called_once_with()
self.assertTrue(retry_mock.called)
@mock.patch.object(redfish.RedfishOperations, '_perform_power_op')
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
@mock.patch.object(redfish.RedfishOperations, '_retry_until_powered_on')
def test_set_host_power_on(self, retry_mock, host_power_status_mock,
perform_power_op_mock):
host_power_status_mock.return_value = 'OFF'
self.rf_client.set_host_power('ON')
host_power_status_mock.assert_called_once_with()
self.assertFalse(perform_power_op_mock.called)
self.assertTrue(retry_mock.called)
@mock.patch.object(redfish.RedfishOperations, '_perform_power_op')
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
def test_retry_until_powered_on_3times(self, host_power_status_mock,
perform_power_mock):
host_power_status_mock.side_effect = ['OFF', 'OFF', 'ON']
self.rf_client._retry_until_powered_on('ON')
self.assertEqual(3, host_power_status_mock.call_count)
@mock.patch.object(redfish.RedfishOperations, '_perform_power_op')
@mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
def test_retry_until_powered_on(self, host_power_status_mock,
perform_power_mock):
host_power_status_mock.return_value = 'ON'
self.rf_client._retry_until_powered_on('ON')
self.assertEqual(1, host_power_status_mock.call_count)
def test_perform_power_op(self):
self.rf_client._perform_power_op("ON")
self.sushy.get_system().reset_system.assert_called_once_with(
sushy.RESET_ON)
def test_press_pwr_btn(self):
self.rf_client.press_pwr_btn()
self.sushy.get_system().push_power_button.assert_called_once_with(
sys_cons.PUSH_POWER_BUTTON_PRESS)
def test_press_pwr_btn_fail(self):
self.sushy.get_system().push_power_button.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to press power button',
self.rf_client.press_pwr_btn)
def test_hold_pwr_btn(self):
self.rf_client.hold_pwr_btn()
self.sushy.get_system().push_power_button.assert_called_once_with(
sys_cons.PUSH_POWER_BUTTON_PRESS_AND_HOLD)
def test_hold_pwr_btn_fail(self):
self.sushy.get_system().push_power_button.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to press and hold power button',
self.rf_client.hold_pwr_btn)
def test_get_one_time_boot_not_set(self):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
self.sushy.get_system().json = system_json['default']
boot = self.rf_client.get_one_time_boot()
self.assertEqual('Normal', boot)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_one_time_boot_set_cdrom(self, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.return_value = system_json[
'System_op_for_one_time_boot_cdrom']
self.sys_inst = system.System(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
ret = self.rf_client.get_one_time_boot()
self.assertEqual(ret, 'CDROM')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_pending_boot_mode(self, get_system_mock):
for cons_val in redfish.BOOT_MODE_MAP.keys():
(get_system_mock.return_value.bios_settings.
pending_settings.boot_mode) = cons_val
result = self.rf_client.get_pending_boot_mode()
self.assertEqual(redfish.BOOT_MODE_MAP[cons_val], result)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_pending_boot_mode_fail(self, get_system_mock):
bios_settings_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.bios_settings).pending_settings = (
bios_settings_mock)
self.assertRaisesRegex(
exception.IloError,
'The pending BIOS Settings was not found.',
self.rf_client.get_pending_boot_mode)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_boot_mode(self, get_system_mock):
for cons_val in redfish.BOOT_MODE_MAP.keys():
get_system_mock.return_value.bios_settings.boot_mode = cons_val
result = self.rf_client.get_current_boot_mode()
self.assertEqual(redfish.BOOT_MODE_MAP[cons_val], result)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_boot_mode_fail(self, get_system_mock):
bios_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value).bios_settings = bios_mock
self.assertRaisesRegex(
exception.IloError,
'The current BIOS Settings was not found.',
self.rf_client.get_current_boot_mode)
def test_activate_license(self):
self.rf_client.activate_license('testkey')
(self.sushy.get_manager.return_value.set_license.
assert_called_once_with('testkey'))
def test_activate_license_fail(self):
self.sushy.get_manager.return_value.set_license.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update the license',
self.rf_client.activate_license, 'key')
def _setup_virtual_media(self):
self.conn = mock.Mock()
with open('proliantutils/tests/redfish/'
'json_samples/manager.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
manager_mock = manager.HPEManager(
self.conn, '/redfish/v1/Managers/1',
redfish_version='1.0.2')
with open('proliantutils/tests/redfish/'
'json_samples/vmedia_collection.json', 'r') as f:
vmedia_collection_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/vmedia.json', 'r') as f:
vmedia_json = json.loads(f.read())
return manager_mock, vmedia_collection_json, vmedia_json
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
def test_eject_virtual_media(self, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['vmedia_inserted']]
self.rf_client.eject_virtual_media('CDROM')
eject_mock.assert_called_once_with()
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
def test_eject_virtual_media_invalid_device(self, eject_mock,
manager_mock):
self.assertRaisesRegex(
exception.IloError,
"Invalid device 'XXXXX'. Valid devices: FLOPPY or CDROM.",
self.rf_client.eject_virtual_media,
'XXXXX')
self.assertFalse(eject_mock.called)
self.assertFalse(manager_mock.called)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
def test_eject_virtual_media_not_inserted(self, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['default']]
self.rf_client.eject_virtual_media('CDROM')
self.assertFalse(eject_mock.called)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
def test_eject_virtual_media_floppy(self, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['vmedia_floppy']]
self.rf_client.eject_virtual_media('FLOPPY')
self.assertFalse(eject_mock.called)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
def test_eject_virtual_media_fail(self, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
eject_mock.side_effect = sushy.exceptions.SushyError
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['vmedia_inserted']]
msg = ("The Redfish controller failed to eject the virtual"
" media device 'CDROM'.")
self.assertRaisesRegex(exception.IloError, msg,
self.rf_client.eject_virtual_media,
'CDROM')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
@mock.patch.object(virtual_media.VirtualMedia, 'insert_media')
@mock.patch.object(common_utils, 'validate_href')
def test_insert_virtual_media(
self, validate_href_mock, insert_mock, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['default']]
url = 'http://1.2.3.4:5678/xyz.iso'
self.rf_client.insert_virtual_media(url, 'CDROM')
self.assertFalse(eject_mock.called)
insert_mock.assert_called_once_with(url)
validate_href_mock.assert_called_once_with(url)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
@mock.patch.object(virtual_media.VirtualMedia, 'insert_media')
@mock.patch.object(common_utils, 'validate_href')
def test_insert_virtual_media_floppy(
self, validate_href_mock, insert_mock, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['vmedia_floppy']]
url = 'http://1.2.3.4:5678/xyz.iso'
self.rf_client.insert_virtual_media(url, 'FLOPPY')
self.assertFalse(eject_mock.called)
insert_mock.assert_called_once_with(url)
validate_href_mock.assert_called_once_with(url)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
@mock.patch.object(virtual_media.VirtualMedia, 'insert_media')
@mock.patch.object(common_utils, 'validate_href')
def test_insert_virtual_media_inserted(
self, validate_href_mock, insert_mock, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['vmedia_inserted']]
url = 'http://1.2.3.4:5678/xyz.iso'
self.rf_client.insert_virtual_media(url, 'CDROM')
eject_mock.assert_called_once_with()
insert_mock.assert_called_once_with(url)
validate_href_mock.assert_called_once_with(url)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(virtual_media.VirtualMedia, 'eject_media')
@mock.patch.object(virtual_media.VirtualMedia, 'insert_media')
@mock.patch.object(common_utils, 'validate_href')
def test_insert_virtual_media_fail(
self, validate_href_mock, insert_mock, eject_mock, manager_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
insert_mock.side_effect = sushy.exceptions.SushyError
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['vmedia_inserted']]
url = 'http://1.2.3.4:5678/xyz.iso'
msg = ("The Redfish controller failed to insert the media url "
"%s in the virtual media device 'CDROM'.") % url
self.assertRaisesRegex(exception.IloError, msg,
self.rf_client.insert_virtual_media,
url, 'CDROM')
validate_href_mock.assert_called_once_with(url)
@mock.patch.object(virtual_media.VirtualMedia, 'set_vm_status')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_set_vm_status(self, manager_mock, set_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['default']]
self.rf_client.set_vm_status(device='CDROM')
set_mock.assert_called_once_with(True)
@mock.patch.object(virtual_media.VirtualMedia, 'set_vm_status')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_set_vm_status_fail(self, manager_mock, set_mock):
manager_mock.return_value, vmedia_collection_json, vmedia_json = (
self._setup_virtual_media())
set_mock.side_effect = sushy.exceptions.SushyError
self.conn.get.return_value.json.side_effect = [
vmedia_collection_json, vmedia_json['default']]
msg = ("The Redfish controller failed to set the virtual "
"media status.")
self.assertRaisesRegex(exception.IloError, msg,
self.rf_client.set_vm_status,
'CDROM')
@mock.patch.object(virtual_media.VirtualMedia, 'set_vm_status')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_set_vm_status_not_supported_boot_option(self, manager_mock,
set_mock):
msg = ("Virtual media boot option 'XXXX' is invalid.")
self.assertRaisesRegex(exception.IloInvalidInputError, msg,
self.rf_client.set_vm_status,
device='CDROM', boot_option='XXXX')
self.assertFalse(manager_mock.called)
self.assertFalse(set_mock.called)
@mock.patch.object(virtual_media.VirtualMedia, 'set_vm_status')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_set_vm_status_boot_option_connect(self, manager_mock, set_mock):
self.rf_client.set_vm_status(device='CDROM', boot_option='CONNECT')
self.assertFalse(manager_mock.called)
self.assertFalse(set_mock.called)
def test_update_firmware(self):
self.rf_client.update_firmware('fw_file_url', 'ilo')
(self.sushy.get_update_service.return_value.flash_firmware.
assert_called_once_with(self.rf_client, 'fw_file_url'))
def test_update_firmware_flash_firmware_fail(self):
(self.sushy.get_update_service.return_value.
flash_firmware.side_effect) = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update firmware',
self.rf_client.update_firmware, 'fw_file_url', 'cpld')
def test_update_firmware_get_update_service_fail(self):
self.sushy.get_update_service.side_effect = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update firmware',
self.rf_client.update_firmware, 'fw_file_url', 'cpld')
@mock.patch.object(redfish.RedfishOperations, 'get_current_boot_mode')
def test__is_boot_mode_uefi_uefi(self, get_current_boot_mode_mock):
get_current_boot_mode_mock.return_value = (
redfish.BOOT_MODE_MAP.get(sys_cons.BIOS_BOOT_MODE_UEFI))
result = self.rf_client._is_boot_mode_uefi()
self.assertTrue(result)
@mock.patch.object(redfish.RedfishOperations, 'get_current_boot_mode')
def test__is_boot_mode_uefi_bios(self, get_current_boot_mode_mock):
get_current_boot_mode_mock.return_value = (
redfish.BOOT_MODE_MAP.get(sys_cons.BIOS_BOOT_MODE_LEGACY_BIOS))
result = self.rf_client._is_boot_mode_uefi()
self.assertFalse(result)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_uefi_cdrom(self, get_sushy_system_mock,
_uefi_boot_mode_mock):
(get_sushy_system_mock.return_value.
bios_settings.boot_settings.
get_persistent_boot_device.return_value) = (sushy.
BOOT_SOURCE_TARGET_CD)
_uefi_boot_mode_mock.return_value = True
result = self.rf_client.get_persistent_boot_device()
self.assertEqual(
result,
redfish.DEVICE_REDFISH_TO_COMMON.get(sushy.BOOT_SOURCE_TARGET_CD))
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_bios(self, get_sushy_system_mock,
_uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
result = self.rf_client.get_persistent_boot_device()
self.assertIsNone(result)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_cdrom_continuous(self,
get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.return_value = system_json[
'System_op_for_cdrom_persistent_boot']
self.sys_inst = system.System(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
ret = self.rf_client.get_persistent_boot_device()
self.assertEqual(ret, 'CDROM')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_exp(self, get_system_mock,
_uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = True
boot_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.bios_settings).boot_settings = (
boot_mock)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller is unable to get persistent boot device.',
self.rf_client.get_persistent_boot_device)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_pending_boot_mode(self, get_system_mock):
self.rf_client.set_pending_boot_mode('uefi')
(get_system_mock.return_value.
bios_settings.pending_settings.set_pending_boot_mode.
assert_called_once_with('uefi'))
def test_set_pending_boot_mode_invalid_input(self):
self.assertRaisesRegex(
exception.IloInvalidInputError,
'Invalid Boot mode: "test" specified',
self.rf_client.set_pending_boot_mode, 'test')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_pending_boot_mode_fail(self, get_system_mock):
(get_system_mock.return_value.bios_settings.
pending_settings.set_pending_boot_mode.side_effect) = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to set pending boot mode.',
self.rf_client.set_pending_boot_mode, 'uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_update_persistent_boot(self, get_system_mock):
self.rf_client.update_persistent_boot(['NETWORK'])
(get_system_mock.return_value.update_persistent_boot.
assert_called_once_with(['NETWORK'], persistent=True))
def test_update_persistent_boot_invalid_input(self):
self.assertRaisesRegex(
exception.IloInvalidInputError,
('Invalid input "test". Valid devices: NETWORK, '
'HDD, ISCSI, UEFIHTTP or CDROM.'),
self.rf_client.update_persistent_boot, ['test'])
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_update_persistent_boot_fail(self, get_system_mock):
get_system_mock.return_value.update_persistent_boot.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update persistent boot.',
self.rf_client.update_persistent_boot,
['NETWORK'])
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_one_time_boot(self, get_system_mock):
self.rf_client.set_one_time_boot('CDROM')
(get_system_mock.return_value.update_persistent_boot.
assert_called_once_with(['CDROM'], persistent=False))
def test_set_one_time_boot_invalid_input(self):
self.assertRaisesRegex(
exception.IloInvalidInputError,
('Invalid input "test". Valid devices: NETWORK, '
'HDD, ISCSI, UEFIHTTP or CDROM.'),
self.rf_client.set_one_time_boot, 'test')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_one_time_boot_fail(self, get_system_mock):
get_system_mock.return_value.update_persistent_boot.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to set one time boot.',
self.rf_client.set_one_time_boot,
'CDROM')
def _setup_reset_ilo_credential(self):
self.conn = mock.Mock()
with open('proliantutils/tests/redfish/'
'json_samples/account_service.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
account_mock = account_service.HPEAccountService(
self.conn, '/redfish/v1/AccountService',
redfish_version='1.0.2')
with open('proliantutils/tests/redfish/'
'json_samples/account_collection.json', 'r') as f:
account_collection_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/account.json', 'r') as f:
account_json = json.loads(f.read())
return account_mock, account_collection_json, account_json
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_reset_ilo_credential(self, account_mock):
account_mock.return_value, account_collection_json, account_json = (
self._setup_reset_ilo_credential())
self.conn.get.return_value.json.side_effect = [
account_collection_json, account_json]
self.rf_client.reset_ilo_credential('fake-password')
(self.sushy.get_account_service.return_value.
accounts.get_member_details.return_value.
update_credentials.assert_called_once_with('fake-password'))
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_reset_ilo_credential_fail(self, account_mock):
account_mock.return_value, account_collection_json, account_json = (
self._setup_reset_ilo_credential())
self.conn.get.return_value.json.side_effect = [
account_collection_json, account_json]
(self.sushy.get_account_service.return_value.accounts.
get_member_details.return_value.
update_credentials.side_effect) = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update credentials',
self.rf_client.reset_ilo_credential, 'fake-password')
@mock.patch.object(account.HPEAccount, 'update_credentials')
def test_reset_ilo_credential_get_account_service_fail(self, update_mock):
account_service_not_found_error = sushy.exceptions.SushyError
account_service_not_found_error.message = (
'HPEAccountService not found!!')
self.sushy.get_account_service.side_effect = (
account_service_not_found_error)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update credentials for foo. '
'Error HPEAccountService not found!!',
self.rf_client.reset_ilo_credential, 'fake-password')
self.assertFalse(update_mock.called)
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_reset_ilo_credential_no_member(self, account_mock):
(self.sushy.get_account_service.return_value.accounts.
get_member_details.return_value) = None
self.assertRaisesRegex(
exception.IloError,
'No account found with username: foo',
self.rf_client.reset_ilo_credential, 'fake-password')
@ddt.data((sys_cons.SUPPORTED_LEGACY_BIOS_ONLY,
ilo_cons.SUPPORTED_BOOT_MODE_LEGACY_BIOS_ONLY),
(sys_cons.SUPPORTED_UEFI_ONLY,
ilo_cons.SUPPORTED_BOOT_MODE_UEFI_ONLY),
(sys_cons.SUPPORTED_LEGACY_BIOS_AND_UEFI,
ilo_cons.SUPPORTED_BOOT_MODE_LEGACY_BIOS_AND_UEFI))
@ddt.unpack
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_supported_boot_mode(self, supported_boot,
expected_boot_val,
get_system_mock):
type(get_system_mock.return_value).supported_boot_mode = (
supported_boot)
actual_val = self.rf_client.get_supported_boot_mode()
self.assertEqual(expected_boot_val, actual_val)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_supported_boot_mode_error(self, get_system_mock):
supported_boot_mode_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value).supported_boot_mode = (
supported_boot_mode_mock)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to get the supported boot modes.',
self.rf_client.get_supported_boot_mode)
@mock.patch.object(common_gpu, 'gpu_capabilities')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_chassis')
@mock.patch.object(redfish.RedfishOperations,
'_parse_security_dashboard_values_for_capabilities')
@mock.patch.object(common_storage, 'get_drive_rotational_speed_rpm')
@mock.patch.object(common_storage, 'has_nvme_ssd')
@mock.patch.object(common_storage, 'has_rotational')
@mock.patch.object(common_storage, 'has_ssd')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_get_server_capabilities(self, get_manager_mock, get_system_mock,
ssd_mock, rotational_mock,
nvme_mock, speed_mock, sec_mock,
get_chassis_mock, gpu_cap_mock):
type(get_system_mock.return_value.pci_devices).gpu_devices = (
[mock.MagicMock(spec=pci_device.PCIDevice)])
type(get_system_mock.return_value.bios_settings).sriov = (
sys_cons.SRIOV_ENABLED)
type(get_system_mock.return_value.bios_settings).cpu_vt = (
sys_cons.CPUVT_ENABLED)
type(get_system_mock.return_value).secure_boot = (
mock.MagicMock(spec='Hey I am secure_boot'))
type(get_system_mock.return_value).rom_version = (
'U31 v1.00 (03/11/2017)')
type(get_manager_mock.return_value).firmware_version = 'iLO 5 v1.15'
type(get_system_mock.return_value).model = 'ProLiant DL180 Gen10'
nic_mock = mock.PropertyMock(return_value='1Gb')
type(get_system_mock.return_value.pci_devices).max_nic_capacity = (
nic_mock)
tpm_mock = mock.PropertyMock(return_value=sys_cons.TPM_PRESENT_ENABLED)
type(get_system_mock.return_value.bios_settings).tpm_state = (
tpm_mock)
type(get_system_mock.return_value).supported_boot_mode = (
sys_cons.SUPPORTED_LEGACY_BIOS_AND_UEFI)
iscsi_mock = mock.MagicMock(spec=iscsi.ISCSIResource)
iscsi_mock.is_iscsi_boot_supported = mock.MagicMock(return_value=True)
type(get_system_mock.return_value.bios_settings).iscsi_resource = (
iscsi_mock)
type(get_system_mock.return_value.smart_storage.
array_controllers).members_identities = [
mock.MagicMock(array_controller.HPEArrayController)]
MemoryData = collections.namedtuple(
'MemoryData', ['has_persistent_memory', 'has_nvdimm_n',
'has_logical_nvdimm_n'])
mem = MemoryData(has_persistent_memory=True,
has_nvdimm_n=True,
has_logical_nvdimm_n=False)
memory_mock = mock.MagicMock(spec=memory.MemoryCollection)
memory_mock.details = mock.MagicMock(return_value=mem)
get_system_mock.return_value.memory = memory_mock
ssd_mock.return_value = True
rotational_mock.return_value = True
nvme_mock.return_value = True
raid_mock = mock.PropertyMock(return_value=set(['0', '1']))
type(get_system_mock.return_value.
smart_storage).logical_raid_levels = (raid_mock)
speed_mock.return_value = set(['10000', '15000'])
sec_mock.return_value = {'overall_security_status': 'Risk',
'security_override_switch': 'Ok',
'last_firmware_scan_result': 'Ok'}
gpu_cap_mock.return_value = (
[{'gpu_vendor_count': {'gpu_0x102b_count': 1}},
{'gpu_ven_dev_count': {'gpu_Embedded_Video_Controller_count': 1}},
{'gpu_ven_dev': {'gpu_Embedded_Video_Controller': 'true'}}])
actual = self.rf_client.get_server_capabilities()
expected = {'pci_gpu_devices': 1, 'sriov_enabled': 'true',
'secure_boot': 'true', 'cpu_vt': 'true',
'rom_firmware_version': 'U31 v1.00 (03/11/2017)',
'ilo_firmware_version': 'iLO 5 v1.15',
'nic_capacity': '1Gb',
'trusted_boot': 'true',
'server_model': 'ProLiant DL180 Gen10',
'boot_mode_bios': 'true',
'boot_mode_uefi': 'true', 'iscsi_boot': 'true',
'hardware_supports_raid': 'true',
'persistent_memory': 'true',
'nvdimm_n': 'true',
'logical_nvdimm_n': 'false',
'has_ssd': 'true',
'has_rotational': 'true',
'has_nvme_ssd': 'true',
'logical_raid_level_0': 'true',
'logical_raid_level_1': 'true',
'drive_rotational_10000_rpm': 'true',
'drive_rotational_15000_rpm': 'true',
'overall_security_status': 'Risk',
'security_override_switch': 'Ok',
'last_firmware_scan_result': 'Ok',
'gpu_0x102b_count': 1,
'gpu_Embedded_Video_Controller_count': 1,
'gpu_Embedded_Video_Controller': 'true'}
self.assertEqual(expected, actual)
@mock.patch.object(common_gpu, 'gpu_capabilities')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_chassis')
@mock.patch.object(redfish.RedfishOperations,
'_parse_security_dashboard_values_for_capabilities')
@mock.patch.object(common_storage, 'get_drive_rotational_speed_rpm')
@mock.patch.object(common_storage, 'has_nvme_ssd')
@mock.patch.object(common_storage, 'has_rotational')
@mock.patch.object(common_storage, 'has_ssd')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_get_server_capabilities_optional_capabilities_absent(
self, get_manager_mock, get_system_mock, ssd_mock,
rotational_mock, nvme_mock, speed_mock, sec_mock,
get_chassis_mock, gpu_cap_mock):
type(get_system_mock.return_value.pci_devices).gpu_devices = (
[mock.MagicMock(spec=pci_device.PCIDevice)])
type(get_system_mock.return_value.bios_settings).sriov = (
sys_cons.SRIOV_DISABLED)
type(get_system_mock.return_value.bios_settings).cpu_vt = (
sys_cons.CPUVT_DISABLED)
type(get_system_mock.return_value).secure_boot = (
mock.PropertyMock(side_effect=exception.MissingAttributeError))
type(get_system_mock.return_value).rom_version = (
'U31 v1.00 (03/11/2017)')
type(get_manager_mock.return_value).firmware_version = 'iLO 5 v1.15'
type(get_system_mock.return_value).model = 'ProLiant DL180 Gen10'
nic_mock = mock.PropertyMock(return_value='1Gb')
type(get_system_mock.return_value.pci_devices).max_nic_capacity = (
nic_mock)
type(get_system_mock.return_value.pci_devices).nic_capacity = (
nic_mock)
tpm_mock = mock.PropertyMock(return_value=sys_cons.TPM_NOT_PRESENT)
type(get_system_mock.return_value.bios_settings).tpm_state = (
tpm_mock)
type(get_system_mock.return_value).supported_boot_mode = (
sys_cons.SUPPORTED_UEFI_ONLY)
iscsi_mock = mock.MagicMock(spec=iscsi.ISCSIResource)
iscsi_mock.is_iscsi_boot_supported = mock.MagicMock(return_value=False)
type(get_system_mock.return_value.bios_settings).iscsi_resource = (
iscsi_mock)
type(get_system_mock.return_value.smart_storage.
array_controllers).members_identities = []
MemoryData = collections.namedtuple(
'MemoryData', ['has_persistent_memory', 'has_nvdimm_n',
'has_logical_nvdimm_n'])
mem = MemoryData(has_persistent_memory=False,
has_nvdimm_n=False,
has_logical_nvdimm_n=False)
memory_mock = mock.MagicMock(spec=memory.MemoryCollection)
get_system_mock.return_value.memory = memory_mock
memory_mock.details = mock.MagicMock(return_value=mem)
ssd_mock.return_value = False
rotational_mock.return_value = False
nvme_mock.return_value = False
raid_mock = mock.PropertyMock(return_value=set())
type(get_system_mock.return_value.
smart_storage).logical_raid_levels = (raid_mock)
speed_mock.return_value = set()
sec_mock.return_value = {'overall_security_status': 'Risk',
'security_override_switch': 'Ok',
'last_firmware_scan_result': 'Ok'}
gpu_cap_mock.return_value = (
[{'gpu_vendor_count': {'gpu_0x102b_count': 1}},
{'gpu_ven_dev_count': {'gpu_Embedded_Video_Controller_count': 1}},
{'gpu_ven_dev': {'gpu_Embedded_Video_Controller': 'true'}}])
actual = self.rf_client.get_server_capabilities()
expected = {'pci_gpu_devices': 1,
'rom_firmware_version': 'U31 v1.00 (03/11/2017)',
'ilo_firmware_version': 'iLO 5 v1.15',
'nic_capacity': '1Gb',
'server_model': 'ProLiant DL180 Gen10',
'boot_mode_bios': 'false', 'boot_mode_uefi': 'true',
'overall_security_status': 'Risk',
'security_override_switch': 'Ok',
'last_firmware_scan_result': 'Ok',
'gpu_0x102b_count': 1,
'gpu_Embedded_Video_Controller_count': 1,
'gpu_Embedded_Video_Controller': 'true'}
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_chassis')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_server_capabilities_gpu_fail(self, get_system_mock,
get_chassis_mock):
gpu_mock = mock.PropertyMock(side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.pci_devices).gpu_devices = (
gpu_mock)
type(get_chassis_mock.return_value.devices).vendor_dict = (
gpu_mock)
self.assertRaises(exception.IloError,
self.rf_client.get_server_capabilities)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
@mock.patch.object(bios.BIOSPendingSettings, 'update_bios_data_by_post')
def test_reset_bios_to_default(self, update_bios_mock, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios_base_configs.json', 'r') as f:
bios_default_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
bios_json['BIOS_pending_settings_default'], bios_default_json]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
data = bios_default_json['BaseConfigs'][0]['default']
self.rf_client.reset_bios_to_default()
update_bios_mock.assert_called_once_with(data)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_reset_bios_to_default_fail(self, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios_base_configs.json', 'r') as f:
bios_default_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
bios_json['BIOS_pending_settings_default'], bios_default_json]
(get_system_mock.return_value.bios_settings.
update_bios_to_default.side_effect) = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
"The Redfish controller is unable to update bios settings"
" to default", self.rf_client.reset_bios_to_default)
@mock.patch.object(redfish.LOG, 'debug', autospec=True)
def test_get_secure_boot_mode(self, log_debug_mock):
sushy_system_mock = self.sushy.get_system.return_value
type(sushy_system_mock.secure_boot).current_boot = mock.PropertyMock(
return_value=sys_cons.SECUREBOOT_CURRENT_BOOT_ENABLED)
self.rf_client.get_secure_boot_mode()
log_debug_mock.assert_called_once_with(
'[iLO 1.2.3.4] Secure boot is Enabled')
log_debug_mock.reset_mock()
type(sushy_system_mock.secure_boot).current_boot = mock.PropertyMock(
return_value=sys_cons.SECUREBOOT_CURRENT_BOOT_DISABLED)
self.rf_client.get_secure_boot_mode()
log_debug_mock.assert_called_once_with(
'[iLO 1.2.3.4] Secure boot is Disabled')
def test_get_secure_boot_mode_on_fail(self):
sushy_system_mock = self.sushy.get_system.return_value
type(sushy_system_mock).secure_boot = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloCommandNotSupportedError,
'The Redfish controller failed to provide '
'information about secure boot on the server.',
self.rf_client.get_secure_boot_mode)
def test__has_secure_boot(self):
sushy_system_mock = self.sushy.get_system.return_value
type(sushy_system_mock).secure_boot = mock.PropertyMock(
return_value='Hey I am secure_boot')
self.assertTrue(self.rf_client._has_secure_boot())
def test__has_secure_boot_on_fail(self):
sushy_system_mock = self.sushy.get_system.return_value
type(sushy_system_mock).secure_boot = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
self.assertFalse(self.rf_client._has_secure_boot())
type(sushy_system_mock).secure_boot = mock.PropertyMock(
side_effect=exception.MissingAttributeError)
self.assertFalse(self.rf_client._has_secure_boot())
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_secure_boot_mode(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
self.rf_client.set_secure_boot_mode(True)
secure_boot_mock = self.sushy.get_system.return_value.secure_boot
secure_boot_mock.enable_secure_boot.assert_called_once_with(True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_secure_boot_mode_in_bios(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = False
self.assertRaisesRegex(
exception.IloCommandNotSupportedInBiosError,
'System is not in UEFI boot mode. "SecureBoot" related resources '
'cannot be changed.',
self.rf_client.set_secure_boot_mode, True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_secure_boot_mode_on_fail(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
secure_boot_mock = self.sushy.get_system.return_value.secure_boot
secure_boot_mock.enable_secure_boot.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to set secure boot settings '
'on the server.',
self.rf_client.set_secure_boot_mode, True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_secure_boot_mode_for_invalid_value(
self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
secure_boot_mock = self.sushy.get_system.return_value.secure_boot
secure_boot_mock.enable_secure_boot.side_effect = (
exception.InvalidInputError('Invalid input'))
self.assertRaises(
exception.IloError,
self.rf_client.set_secure_boot_mode, 'some-non-boolean')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_reset_secure_boot_keys(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
self.rf_client.reset_secure_boot_keys()
sushy_system_mock = self.sushy.get_system.return_value
sushy_system_mock.secure_boot.reset_keys.assert_called_once_with(
sys_cons.SECUREBOOT_RESET_KEYS_DEFAULT)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_reset_secure_boot_keys_in_bios(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = False
self.assertRaisesRegex(
exception.IloCommandNotSupportedInBiosError,
'System is not in UEFI boot mode. "SecureBoot" related resources '
'cannot be changed.',
self.rf_client.reset_secure_boot_keys)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_reset_secure_boot_keys_on_fail(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
sushy_system_mock = self.sushy.get_system.return_value
sushy_system_mock.secure_boot.reset_keys.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to reset secure boot keys '
'on the server.',
self.rf_client.reset_secure_boot_keys)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_clear_secure_boot_keys(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
self.rf_client.clear_secure_boot_keys()
sushy_system_mock = self.sushy.get_system.return_value
sushy_system_mock.secure_boot.reset_keys.assert_called_once_with(
sys_cons.SECUREBOOT_RESET_KEYS_DELETE_ALL)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_clear_secure_boot_keys_in_bios(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = False
self.assertRaisesRegex(
exception.IloCommandNotSupportedInBiosError,
'System is not in UEFI boot mode. "SecureBoot" related resources '
'cannot be changed.',
self.rf_client.clear_secure_boot_keys)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_clear_secure_boot_keys_on_fail(self, _is_boot_mode_uefi_mock):
_is_boot_mode_uefi_mock.return_value = True
sushy_system_mock = self.sushy.get_system.return_value
sushy_system_mock.secure_boot.reset_keys.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to clear secure boot keys '
'on the server.',
self.rf_client.clear_secure_boot_keys)
@mock.patch.object(common_storage, 'get_local_gb')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_essential_properties(self, get_system_mock, local_gb_mock):
memory_mock = mock.PropertyMock(return_value=20)
type(get_system_mock.return_value.memory_summary).size_gib = (
memory_mock)
count_mock = mock.PropertyMock(return_value=40)
type(get_system_mock.return_value.processors.summary).count = (
count_mock)
arch_mock = mock.PropertyMock(return_value=sushy.PROCESSOR_ARCH_x86)
type(get_system_mock.return_value.processors.summary).architecture = (
arch_mock)
type(get_system_mock.return_value.ethernet_interfaces).summary = (
{'1': '12:44:6A:3B:04:11'})
local_gb_mock.return_value = 600
actual = self.rf_client.get_essential_properties()
expected = {'properties': {'cpus': 40,
'cpu_arch': 'x86_64',
'memory_mb': 20480,
'local_gb': 600},
'macs': {'1': '12:44:6A:3B:04:11'}}
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_essential_properties_fail(self, get_system_mock):
memory_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.memory_summary).size_gib = (
memory_mock)
self.assertRaisesRegex(
exception.IloError,
"The Redfish controller failed to get the "
"resource data. Error None",
self.rf_client.get_essential_properties)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_iscsi_info_bios(self, _uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
self.assertRaisesRegex(exception.IloCommandNotSupportedInBiosError,
'iSCSI boot is not supported '
'in the BIOS boot mode',
self.rf_client.set_iscsi_info,
'iqn.2011-07.com.example.server:test1',
'1', '10.10.1.30')
@mock.patch.object(redfish.RedfishOperations,
'_change_iscsi_target_settings', autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_iscsi_info_uefi(self, _uefi_boot_mode_mock,
change_iscsi_target_settings_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_variables = {
'iSCSITargetName': 'iqn.2011-07.com.example.server:test1',
'iSCSITargetInfoViaDHCP': False,
'iSCSILUN': '1',
'iSCSIConnection': 'Enabled',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260}
self.rf_client.set_iscsi_info(
'iqn.2011-07.com.example.server:test1',
'1', '10.10.1.30')
change_iscsi_target_settings_mock.assert_called_once_with(
self.rf_client, iscsi_variables, [])
@mock.patch.object(redfish.RedfishOperations,
'_change_iscsi_target_settings', autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_iscsi_info_uefi_with_mac(self, _uefi_boot_mode_mock,
change_iscsi_target_settings_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_variables = {
'iSCSITargetName': 'iqn.2011-07.com.example.server:test1',
'iSCSITargetInfoViaDHCP': False,
'iSCSILUN': '1',
'iSCSIConnection': 'Enabled',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260}
self.rf_client.set_iscsi_info(
'iqn.2011-07.com.example.server:test1',
'1', '10.10.1.30', macs=['98:f2:b3:ee:f4:00'])
change_iscsi_target_settings_mock.assert_called_once_with(
self.rf_client, iscsi_variables, ['98:f2:b3:ee:f4:00'])
@mock.patch.object(redfish.RedfishOperations,
'_change_iscsi_target_settings', autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_iscsi_info_uefi_with_chap(
self, _uefi_boot_mode_mock, change_iscsi_target_settings_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_variables = {
'iSCSITargetName': 'iqn.2011-07.com.example.server:test1',
'iSCSITargetInfoViaDHCP': False,
'iSCSILUN': '1',
'iSCSIConnection': 'Enabled',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSIAuthenticationMethod': 'Chap',
'iSCSIChapUsername': 'admin',
'iSCSIChapSecret': 'password'}
self.rf_client.set_iscsi_info(
'iqn.2011-07.com.example.server:test1',
'1', '10.10.1.30', 3260, 'CHAP', 'admin', 'password')
change_iscsi_target_settings_mock.assert_called_once_with(
self.rf_client, iscsi_variables, [])
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_unset_iscsi_info_bios(self, _uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
self.assertRaisesRegex(exception.IloCommandNotSupportedInBiosError,
"iSCSI boot is not supported "
"in the BIOS boot mode",
self.rf_client.unset_iscsi_info)
@mock.patch.object(redfish.RedfishOperations,
'_change_iscsi_target_settings', autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_unset_iscsi_info_uefi(self, _uefi_boot_mode_mock,
change_iscsi_target_settings_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_variables = {
'iSCSIConnection': 'Disabled'}
self.rf_client.unset_iscsi_info()
change_iscsi_target_settings_mock.assert_called_once_with(
self.rf_client, iscsi_variables, [])
@mock.patch.object(redfish.RedfishOperations,
'_change_iscsi_target_settings', autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_unset_iscsi_info_uefi_with_mac(self, _uefi_boot_mode_mock,
change_iscsi_target_settings_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_variables = {
'iSCSIConnection': 'Disabled'}
self.rf_client.unset_iscsi_info(['98:f2:b3:ee:f4:00'])
change_iscsi_target_settings_mock.assert_called_once_with(
self.rf_client, iscsi_variables, ['98:f2:b3:ee:f4:00'])
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test__change_iscsi_target_settings(
self, get_system_mock, update_iscsi_settings_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios_mappings.json', 'r') as f:
bios_mappings_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi.json', 'r') as f:
iscsi_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi_settings.json', 'r') as f:
iscsi_settings_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
bios_mappings_json['Default'], iscsi_json,
iscsi_settings_json['Default']]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
iscsi_variable = {'iSCSITargetName':
'iqn.2011-07.com.example.server:test1',
'iSCSILUN': '1',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSITargetInfoViaDHCP': False,
'iSCSIConnection': 'Enabled'}
iscsi_data1 = {'iSCSITargetName':
'iqn.2011-07.com.example.server:test1',
'iSCSILUN': '1',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSITargetInfoViaDHCP': False,
'iSCSIConnection': 'Enabled',
'iSCSIAttemptName': 'NicBoot1',
'iSCSINicSource': 'NicBoot1',
'iSCSIAttemptInstance': 1}
iscsi_data2 = {'iSCSITargetName':
'iqn.2011-07.com.example.server:test1',
'iSCSILUN': '1',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSITargetInfoViaDHCP': False,
'iSCSIConnection': 'Enabled',
'iSCSIAttemptName': 'NicBoot2',
'iSCSINicSource': 'NicBoot2',
'iSCSIAttemptInstance': 2}
data = {
'iSCSISources': [iscsi_data1, iscsi_data2]
}
self.rf_client._change_iscsi_target_settings(iscsi_variable, [])
update_iscsi_settings_mock.assert_called_once_with(
data)
@mock.patch.object(pro_sys.HPESystem, 'validate_macs')
@mock.patch.object(pro_sys.HPESystem, 'get_nic_association_name_by_mac')
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test__change_iscsi_target_settings_with_mac(
self, get_system_mock, update_iscsi_settings_mock,
get_nic_association_mock, validate_macs_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi.json', 'r') as f:
iscsi_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi_settings.json', 'r') as f:
iscsi_settings_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
iscsi_json,
iscsi_settings_json['Default']]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
get_nic_association_mock.return_value = 'NicBoot1'
iscsi_variable = {'iSCSITargetName':
'iqn.2011-07.com.example.server:test1',
'iSCSILUN': '1',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSITargetInfoViaDHCP': False,
'iSCSIConnection': 'Enabled'}
iscsi_data = {'iSCSITargetName':
'iqn.2011-07.com.example.server:test1',
'iSCSILUN': '1',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSITargetInfoViaDHCP': False,
'iSCSIConnection': 'Enabled',
'iSCSIAttemptName': 'NicBoot1',
'iSCSINicSource': 'NicBoot1',
'iSCSIAttemptInstance': 1}
data = {
'iSCSISources': [iscsi_data]
}
self.rf_client._change_iscsi_target_settings(
iscsi_variable, ['98:f2:b3:ee:f4:00'])
update_iscsi_settings_mock.assert_called_once_with(
data)
validate_macs_mock.assert_called_once_with(['98:f2:b3:ee:f4:00'])
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test__change_iscsi_target_settings_failed_getting_mappings(
self, get_system_mock):
mapping_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.bios_settings).bios_mappings = (
mapping_mock)
self.assertRaisesRegex(
exception.IloError,
"The Redfish controller failed to get the "
"bios mappings. Error",
self.rf_client._change_iscsi_target_settings, {}, [])
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test__change_iscsi_target_settings_no_macs(
self, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios_mappings.json', 'r') as f:
bios_mappings_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
bios_mappings_json['Mappings_without_nic']]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
self.assertRaisesRegex(
exception.IloError,
"No macs were found on the system",
self.rf_client._change_iscsi_target_settings, {}, [])
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test__change_iscsi_target_settings_mac_invalid(
self, get_system_mock):
msg = ("Given macs: %(macs)s not found in the system"
% {'macs': str(['12:44:6A:3B:04:15'])})
get_system_mock.return_value.validate_macs.side_effect = (
exception.InvalidInputError(msg))
self.assertRaisesRegex(
exception.InvalidInputError,
r"Given macs: \['12:44:6A:3B:04:15'\] not found in the system",
self.rf_client._change_iscsi_target_settings, {},
['12:44:6A:3B:04:15'])
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test__change_iscsi_target_settings_update_failed(
self, get_system_mock, update_iscsi_settings_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios_mappings.json', 'r') as f:
bios_mappings_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi.json', 'r') as f:
iscsi_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi_settings.json', 'r') as f:
iscsi_settings_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
bios_mappings_json['Default'], iscsi_json,
iscsi_settings_json['Default']]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
iscsi_variable = {'iSCSITargetName':
'iqn.2011-07.com.example.server:test1',
'iSCSILUN': '1',
'iSCSITargetIpAddress': '10.10.1.30',
'iSCSITargetTcpPort': 3260,
'iSCSITargetInfoViaDHCP': False,
'iSCSIConnection': 'Enabled'}
update_iscsi_settings_mock.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller is failed to update iSCSI '
'settings.',
self.rf_client._change_iscsi_target_settings, iscsi_variable, [])
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_iscsi_initiator_info(
self, get_system_mock, _uefi_boot_mode_mock,
update_iscsi_settings_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi.json', 'r') as f:
iscsi_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi_settings.json', 'r') as f:
iscsi_settings_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
iscsi_json, iscsi_settings_json['Default']]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
_uefi_boot_mode_mock.return_value = True
initiator = 'iqn.2015-02.com.hpe:uefi-U31'
data = {'iSCSIInitiatorName': initiator}
self.rf_client.set_iscsi_initiator_info(initiator)
update_iscsi_settings_mock.assert_called_once_with(
data)
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_iscsi_initiator_info_update_failed(
self, get_system_mock, _uefi_boot_mode_mock,
update_iscsi_settings_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi.json', 'r') as f:
iscsi_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi_settings.json', 'r') as f:
iscsi_settings_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
iscsi_json, iscsi_settings_json['Default']]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
_uefi_boot_mode_mock.return_value = True
initiator = 'iqn.2015-02.com.hpe:uefi-U31'
update_iscsi_settings_mock.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller has failed to update iSCSI '
'settings.',
self.rf_client.set_iscsi_initiator_info,
initiator)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_set_iscsi_initiator_info_bios(self, _uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
self.assertRaisesRegex(exception.IloCommandNotSupportedInBiosError,
'iSCSI initiator cannot be updated in '
'BIOS boot mode',
self.rf_client.set_iscsi_initiator_info,
'iqn.2015-02.com.hpe:uefi-U31')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_iscsi_initiator_info(
self, get_system_mock, _uefi_boot_mode_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
bios_json = json.loads(f.read())
with open('proliantutils/tests/redfish/'
'json_samples/iscsi.json', 'r') as f:
iscsi_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.side_effect = [
system_json['default'], bios_json['Default'],
iscsi_json]
self.sys_inst = pro_sys.HPESystem(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
_uefi_boot_mode_mock.return_value = True
ret = self.rf_client.get_iscsi_initiator_info()
self.assertEqual('iqn.2015-02.com.hpe:uefi-U31', ret)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_iscsi_initiator_info_failed(
self, get_system_mock, _uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_resource_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.bios_settings).iscsi_resource = (
iscsi_resource_mock)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller has failed to get the '
'iSCSI initiator.',
self.rf_client.get_iscsi_initiator_info)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
autospec=True)
def test_get_iscsi_initiator_info_bios(self, _uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
self.assertRaisesRegex(exception.IloCommandNotSupportedInBiosError,
'iSCSI initiator cannot be retrieved in '
'BIOS boot mode',
self.rf_client.get_iscsi_initiator_info)
def test_inject_nmi(self):
self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_ON
self.rf_client.inject_nmi()
self.sushy.get_system().reset_system.assert_called_once_with(
sushy.RESET_NMI)
def test_inject_nmi_power_off(self):
self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_OFF
self.assertRaisesRegex(
exception.IloError,
'Server is not in powered on state.',
self.rf_client.inject_nmi)
self.assertFalse(self.sushy.get_system().reset_system.called)
def test_inject_nmi_sushy_exc(self):
self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_ON
self.sushy.get_system().reset_system.side_effect = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to inject nmi',
self.rf_client.inject_nmi)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_bios_settings_filter_true(self, get_system_mock):
only_allowed_settings = True
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
type(
get_system_mock.return_value.bios_settings).json = (
mock.PropertyMock(return_value=jsonval))
settings = jsonval.get('Attributes')
expected_value = {k: settings[k] for k in (
ilo_cons.SUPPORTED_REDFISH_BIOS_PROPERTIES) if k in settings}
actual_value = self.rf_client.get_current_bios_settings(
only_allowed_settings)
self.assertEqual(expected_value, actual_value)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_bios_settings_filter_false(self, get_system_mock):
only_allowed_settings = False
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
type(
get_system_mock.return_value.bios_settings).json = (
mock.PropertyMock(return_value=jsonval))
settings = jsonval.get('Attributes')
expected_value = settings
actual_value = self.rf_client.get_current_bios_settings(
only_allowed_settings)
self.assertEqual(expected_value, actual_value)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_bios_settings_raises_exception(self, get_system_mock):
only_allowed_settings = True
bios_mock = mock.PropertyMock()
bios_mock.side_effect = sushy.exceptions.SushyError
type(get_system_mock.return_value.bios_settings).json = bios_mock
self.assertRaisesRegex(
exception.IloError,
'The current BIOS Settings were not found',
self.rf_client.get_current_bios_settings,
only_allowed_settings)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_pending_bios_settings_filter_true(self, system_mock):
only_allowed_settings = True
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("BIOS_pending_settings_default")
type(system_mock.return_value.bios_settings.pending_settings).json = (
mock.PropertyMock(return_value=jsonval))
settings = jsonval.get('Attributes')
expected_value = {k: settings[k] for k in (
ilo_cons.SUPPORTED_REDFISH_BIOS_PROPERTIES) if k in settings}
actual_value = self.rf_client.get_pending_bios_settings(
only_allowed_settings)
self.assertEqual(expected_value, actual_value)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_pending_bios_settings_filter_false(self, system_mock):
only_allowed_settings = False
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("BIOS_pending_settings_default")
type(system_mock.return_value.bios_settings.pending_settings).json = (
mock.PropertyMock(return_value=jsonval))
expected = jsonval.get('Attributes')
actual = self.rf_client.get_pending_bios_settings(
only_allowed_settings)
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_pending_bios_settings_raises_exception(self, system_mock):
only_allowed_settings = True
bios_mock = mock.PropertyMock()
bios_mock.side_effect = sushy.exceptions.SushyError
type(system_mock.return_value.bios_settings.pending_settings).json = (
bios_mock)
self.assertRaisesRegex(
exception.IloError,
'The pending BIOS Settings were not found',
self.rf_client.get_pending_bios_settings,
only_allowed_settings)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_default_bios_settings_filter_true(self, get_system_mock):
only_allowed_settings = True
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
settings = jsonval.get("Attributes")
type(get_system_mock.return_value.bios_settings).default_settings = (
mock.PropertyMock(return_value=settings))
expected = {k: settings[k] for k in (
ilo_cons.SUPPORTED_REDFISH_BIOS_PROPERTIES) if k in settings}
actual = self.rf_client.get_default_bios_settings(
only_allowed_settings)
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_default_bios_settings_filter_false(self, get_system_mock):
only_allowed_settings = False
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
settings = jsonval.get("Attributes")
type(get_system_mock.return_value.bios_settings).default_settings = (
mock.PropertyMock(return_value=settings))
expected = settings
actual = self.rf_client.get_default_bios_settings(
only_allowed_settings)
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_default_bios_settings_raises_exception(self, get_system_mock):
only_allowed_settings = True
bios_mock = mock.PropertyMock(side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.bios_settings).default_settings = (
bios_mock)
self.assertRaisesRegex(
exception.IloError,
'The default BIOS Settings were not found',
self.rf_client.get_default_bios_settings,
only_allowed_settings)
@mock.patch.object(bios.BIOSPendingSettings, 'update_bios_data_by_patch')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_bios_settings_no_data(self, system_mock, update_data_mock):
data = None
apply_filter = True
self.assertRaisesRegex(
exception.IloError,
"Could not apply settings with empty data",
self.rf_client.set_bios_settings,
data, apply_filter)
update_data_mock.assert_not_called()
system_mock.assert_not_called()
@mock.patch.object(bios.BIOSPendingSettings, 'update_bios_data_by_patch')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_bios_settings_no_data_no_filter(self, system_mock,
update_data_mock):
data = None
apply_filter = False
self.assertRaisesRegex(
exception.IloError,
"Could not apply settings with empty data",
self.rf_client.set_bios_settings,
data, apply_filter)
update_data_mock.assert_not_called()
system_mock.assert_not_called()
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_bios_settings_filter_true_valid_data(self, system_mock):
apply_filter = True
data = {
"BootOrderPolicy": "AttemptOnce",
"IntelPerfMonitoring": "Enabled",
"IntelProcVtd": "Disabled",
"UefiOptimizedBoot": "Disabled",
"PowerProfile": "MaxPerf",
}
bios_ps_mock = mock.MagicMock(spec=bios.BIOSPendingSettings)
pending_settings_mock = mock.PropertyMock(return_value=bios_ps_mock)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
self.rf_client.set_bios_settings(data, apply_filter)
bios_ps_mock.update_bios_data_by_patch.assert_called_once_with(data)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_bios_settings_filter_true_invalid_data(self, system_mock):
apply_filter = True
data = {
"AdminName": "Administrator",
"BootOrderPolicy": "AttemptOnce",
"IntelPerfMonitoring": "Enabled",
"IntelProcVtd": "Disabled",
"UefiOptimizedBoot": "Disabled",
"PowerProfile": "MaxPerf",
"TimeZone": "Utc1"
}
self.assertRaisesRegex(
exception.IloError,
"Could not apply settings as one or more settings"
" are not supported",
self.rf_client.set_bios_settings,
data, apply_filter)
system_mock.assert_called_once_with(redfish.PROLIANT_SYSTEM_ID)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_bios_settings_filter_false(self, system_mock):
apply_filter = False
data = {
"BootMode": "LEGACY",
"ServerName": "Gen9 server",
"TimeFormat": "Ist",
"BootOrderPolicy": "RetryIndefinitely",
"ChannelInterleaving": "Enabled",
"CollabPowerControl": "Enabled",
"ConsistentDevNaming": "LomsOnly",
"CustomPostMessage": ""
}
bios_ps_mock = mock.MagicMock(spec=bios.BIOSPendingSettings)
pending_settings_mock = mock.PropertyMock(return_value=bios_ps_mock)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
self.rf_client.set_bios_settings(data, apply_filter)
bios_ps_mock.update_bios_data_by_patch.assert_called_once_with(data)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_bios_settings_raises_exception(self, system_mock):
apply_filter = True
data = {
"BootOrderPolicy": "AttemptOnce",
"IntelPerfMonitoring": "Enabled",
"IntelProcVtd": "Disabled",
"UefiOptimizedBoot": "Disabled",
"PowerProfile": "MaxPerf"
}
pending_settings_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
self.assertRaisesRegex(
exception.IloError,
'The pending BIOS Settings resource not found',
self.rf_client.set_bios_settings,
data,
apply_filter)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_host_post_state(self, get_system_mock):
post_state = mock.PropertyMock(return_value='poweroff')
type(get_system_mock.return_value).post_state = post_state
result = self.rf_client.get_host_post_state()
self.assertEqual('PowerOff', result)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_do_one_button_secure_erase(self, get_system_mock):
self.rf_client.do_one_button_secure_erase()
(get_system_mock.return_value.
do_one_button_secure_erase.assert_called_once())
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_do_disk_erase_hdd(self, get_system_mock):
self.rf_client.do_disk_erase('HDD')
get_system_mock.return_value.do_disk_erase.assert_called_once_with(
'HDD', None)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_do_disk_erase_ssd(self, get_system_mock):
self.rf_client.do_disk_erase('SSD')
get_system_mock.return_value.do_disk_erase.assert_called_once_with(
'SSD', None)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_do_disk_erase_ssd_pattern_zero(self, get_system_mock):
self.rf_client.do_disk_erase('SSD', 'zero')
get_system_mock.return_value.do_disk_erase.assert_called_once_with(
'SSD', 'zero')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_has_disk_erase_completed(self, get_system_mock):
(get_system_mock.return_value.
has_disk_erase_completed.return_value) = True
self.assertEqual(True, self.rf_client.has_disk_erase_completed())
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_delete_raid_configuration(self, get_system_mock):
self.rf_client.delete_raid_configuration()
get_system_mock.return_value.delete_raid.assert_called_once_with()
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_create_raid_configuration(self, get_system_mock):
ld1 = {"size_gb": 150, "raid_level": '0', "is_root_volume": True}
raid_config = {"logical_disks": [ld1]}
self.rf_client.create_raid_configuration(raid_config)
get_system_mock.return_value.create_raid.assert_called_once_with(
raid_config)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_read_raid_configuration(self, get_system_mock):
result_ld1 = [{'size_gb': 149,
'physical_disks': [u'2I:1:1'],
'raid_level': u'0',
'root_device_hint': {'wwn': u'0x600508B'},
'controller': u'Smart Storage Controller in Slot 1',
'volume_name': u'01E6E63APFJHD'}]
config = {'logical_disks': result_ld1}
expected = [('HPE Smart Array P408i-p SR Gen10', config)]
get_system_mock.return_value.read_raid.return_value = expected
self.assertEqual(expected, self.rf_client.read_raid_configuration())
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_bios_settings_result_failed(self, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/bios_failed.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
type(get_system_mock.return_value.bios_settings).messages = (
jsonval['@Redfish.Settings']['Messages'])
expected_settings = [
{
"MessageArgs": [
"MinProcIdlePkgState"
],
"MessageID": "Base.1.0:PropertyNotWritable"
},
{
"MessageArgs": [
"MinProcIdlePower"
],
"MessageID": "Base.1.0:PropertyNotWritable"
},
{
"MessageArgs": [
"EnergyPerfBias"
],
"MessageID": "Base.1.0:PropertyNotWritable"
},
{
"MessageArgs": [
"PowerRegulator"
],
"MessageID": "Base.1.0:PropertyNotWritable"
},
{
"MessageArgs": [],
"MessageID": "Base.1.0:Success"
}
]
expected = {"status": "failed", "results": expected_settings}
actual = self.rf_client.get_bios_settings_result()
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_bios_settings_result_success(self, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
actual_settings = [
{
"MessageId": "Base.1.0.Success"
}
]
type(get_system_mock.return_value.bios_settings).messages = (
jsonval['@Redfish.Settings']['Messages'])
actual = self.rf_client.get_bios_settings_result()
expected = {"status": "success", "results": actual_settings}
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_available_disk_types(self, get_system_mock):
get_system_mock.return_value.get_disk_types.return_value = ['HDD',
'SSD']
self.assertEqual(
['HDD', 'SSD'], self.rf_client.get_available_disk_types())
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_http_boot_url(self, get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
jsonval = json.loads(f.read()).get("Default")
type(
get_system_mock.return_value.bios_settings).json = (
mock.PropertyMock(return_value=jsonval))
settings = jsonval.get('Attributes')
expected_url_boot_file = settings.get('UrlBootFile')
actual_url_boot_file = self.rf_client.get_http_boot_url()
self.assertEqual(expected_url_boot_file, actual_url_boot_file)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_http_boot_url_fail(self, get_system_mock):
bios_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value).bios_settings = bios_mock
self.assertRaisesRegex(
exception.IloError,
'The attribute "UrlBootFile" not found.',
self.rf_client.get_http_boot_url)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_http_boot_url_dhcp_default(self, system_mock):
bios_ps_mock = mock.MagicMock(spec=bios.BIOSPendingSettings)
pending_settings_mock = mock.PropertyMock(return_value=bios_ps_mock)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
url = 'a.b.c'
expected_parameter = {
'PreBootNetwork': 'Auto',
'UrlBootFile': 'a.b.c',
'Dhcpv4': 'Enabled'
}
self.rf_client.set_http_boot_url(url)
bios_ps_mock.update_bios_data_by_post.assert_called_once_with(
expected_parameter)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_http_boot_url_dhcp_enabled(self, system_mock):
bios_ps_mock = mock.MagicMock(spec=bios.BIOSPendingSettings)
pending_settings_mock = mock.PropertyMock(return_value=bios_ps_mock)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
dhcp_enabled = True
url = 'a.b.c'
expected_parameter = {
'PreBootNetwork': 'Auto',
'UrlBootFile': 'a.b.c',
'Dhcpv4': 'Enabled'
}
self.rf_client.set_http_boot_url(url, dhcp_enabled)
bios_ps_mock.update_bios_data_by_post.assert_called_once_with(
expected_parameter)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_http_boot_url_dhcp_disabled(self, system_mock):
bios_ps_mock = mock.MagicMock(spec=bios.BIOSPendingSettings)
pending_settings_mock = mock.PropertyMock(return_value=bios_ps_mock)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
dhcp_enabled = False
url = 'a.b.c'
expected_parameter = {
'PreBootNetwork': 'Auto',
'UrlBootFile': 'a.b.c',
'Dhcpv4': 'Disabled'
}
self.rf_client.set_http_boot_url(url, dhcp_enabled)
bios_ps_mock.update_bios_data_by_post.assert_called_once_with(
expected_parameter)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_set_http_boot_url_raises_exception(self, system_mock):
pending_settings_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(system_mock.return_value.bios_settings).pending_settings = (
pending_settings_mock)
dhcp_enabled = True
url = 'a.b.c'
self.assertRaisesRegex(
exception.IloError,
'Could not set HTTPS URL on the iLO.',
self.rf_client.set_http_boot_url, url, dhcp_enabled)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_add_tls_certificate_bios(self, get_sushy_system_mock,
_uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
data = {
"NewCertificates": [
{
"X509Certificate": "Some data"
}
]
}
self.assertRaisesRegex(
exception.IloCommandNotSupportedInBiosError,
'TLS certificate cannot be upload in BIOS boot mode',
self.rf_client.add_tls_certificate,
data)
@mock.patch.object(builtins, 'open')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_add_tls_certificate(self, get_sushy_system_mock,
_uefi_boot_mode_mock, open_mock):
_uefi_boot_mode_mock.return_value = True
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
c_l = [
"-----BEGIN CERTIFICATE-----\r\nMIID7TC\r\nCF"
"g879\r\n-----END CERTIFICATE-----",
"-----BEGIN CERTIFICATE-----\r\nKHY8UP\r\nGH"
"f792\r\n-----END CERTIFICATE-----"
]
expected_data = {
"NewCertificates": [
{
"X509Certificate": c_l[0],
},
{
"X509Certificate": c_l[1],
}
]
}
cert_file = '/path/to/certfile'
self.rf_client.add_tls_certificate([cert_file])
(get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
add_tls_certificate.assert_called_once_with(expected_data))
@mock.patch.object(builtins, 'open')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_add_tls_certificate_no_certificate(self, get_sushy_system_mock,
_uefi_boot_mode_mock,
open_mock):
_uefi_boot_mode_mock.return_value = True
data = (
"-----UNFORMATED CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----UNFORMATED CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
cert_file = "/path/to/certfile"
self.assertRaisesRegex(
exception.IloError,
"No valid certificate",
self.rf_client.add_tls_certificate, [cert_file])
(get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
add_tls_certificate.assert_not_called())
@mock.patch.object(builtins, 'open')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_add_tls_certificate_raises_ilo_error(self, get_sushy_system_mock,
_uefi_boot_mode_mock,
open_mock):
_uefi_boot_mode_mock.return_value = True
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
cert_file = '/path/to/certfile'
(get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
add_tls_certificate.side_effect) = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller has failed to upload TLS certificate.',
self.rf_client.add_tls_certificate, [cert_file])
@mock.patch.object(redfish, 'load_certificate')
@mock.patch.object(redfish, 'b64decode')
@mock.patch.object(builtins, 'open')
def test__get_fps_from_file(self, open_mock, decode_mock, load_cert_mock):
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
decode_mock.side_effect = ['first decoded data',
'second decoded data']
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
decode_calls = [
mock.call('MIID7TCCFg879'),
mock.call('KHY8UPGHf792')
]
load_cert_calls = [
mock.call(redfish.FILETYPE_ASN1, 'first decoded data'),
mock.call(redfish.FILETYPE_ASN1, 'second decoded data')
]
cert1_mock = mock.MagicMock()
cert2_mock = mock.MagicMock()
load_cert_mock.side_effect = [cert1_mock, cert2_mock]
cert1_mock.digest.return_value.decode.return_value = "hickerydickery"
cert2_mock.digest.return_value.decode.return_value = "humptydumpty"
cert_file = '/path/to/certfile'
expected_fp_list = ["hickerydickery", "humptydumpty"]
actual_fp_list = self.rf_client._get_fps_from_file(cert_file)
decode_mock.assert_has_calls(decode_calls)
load_cert_mock.assert_has_calls(load_cert_calls)
self.assertEqual(expected_fp_list, actual_fp_list)
@mock.patch.object(redfish.RedfishOperations, '_get_fps_from_file')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_remove_tls_certificate_default_exclude_list(
self, get_sushy_system_mock, _uefi_boot_mode_mock,
get_fps_mock):
_uefi_boot_mode_mock.return_value = True
get_fps_calls = [
mock.call('/path/to/certfile1'),
mock.call('/path/to/certfile2')
]
get_fps_mock.side_effect = [
["AA:BB:CC", "DD:EE:FF"],
["XX:YY:ZZ"]
]
expected = ["AA:BB:CC", "DD:EE:FF", "XX:YY:ZZ"]
cert_file_list = ['/path/to/certfile1', '/path/to/certfile2']
remove_tls_mock = (get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
remove_tls_certificate)
self.rf_client.remove_tls_certificate(cert_file_list)
get_fps_mock.assert_has_calls(get_fps_calls)
val_delete_certs = remove_tls_mock.call_args[0][0].get(
"DeleteCertificates")
actual = [item.get("FingerPrint") for item in val_delete_certs]
actual.sort()
get_fps_mock.assert_has_calls(get_fps_calls)
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_fps_from_file')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_remove_tls_certificate_empty_exclude_list(
self, get_sushy_system_mock, _uefi_boot_mode_mock,
get_fps_mock):
_uefi_boot_mode_mock.return_value = True
get_fps_calls = [
mock.call('/path/to/certfile1'),
mock.call('/path/to/certfile2')
]
get_fps_mock.side_effect = [
["AA:BB:CC", "DD:EE:FF"],
["XX:YY:ZZ"]
]
expected = ["AA:BB:CC", "DD:EE:FF", "XX:YY:ZZ"]
cert_file_list = ['/path/to/certfile1', '/path/to/certfile2']
excl_cert_file_list = []
remove_tls_mock = (get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
remove_tls_certificate)
self.rf_client.remove_tls_certificate(cert_file_list,
excl_cert_file_list)
val_delete_certs = remove_tls_mock.call_args[0][0].get(
"DeleteCertificates")
actual = [item.get("FingerPrint") for item in val_delete_certs]
actual.sort()
get_fps_mock.assert_has_calls(get_fps_calls)
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_fps_from_file')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_remove_tls_certificate_valid_exclude_list(
self, get_sushy_system_mock, _uefi_boot_mode_mock,
get_fps_mock):
_uefi_boot_mode_mock.return_value = True
get_fps_calls = [
mock.call('/path/to/certfile1'),
mock.call('/path/to/certfile2')
]
get_fps_mock.side_effect = [
["DD:EE:FF", "KK:LL:MM"],
["AA:BB:CC", "DD:EE:FF"],
["XX:YY:ZZ"]
]
expected = ["AA:BB:CC", "XX:YY:ZZ"]
cert_file_list = ['/path/to/certfile1', '/path/to/certfile2']
excl_cert_file_list = ['/path/to/certfile3']
remove_tls_mock = (get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
remove_tls_certificate)
self.rf_client.remove_tls_certificate(
cert_file_list, excl_cert_file_list)
val_delete_certs = remove_tls_mock.call_args[0][0].get(
"DeleteCertificates")
actual = [item.get("FingerPrint") for item in val_delete_certs]
actual.sort()
get_fps_mock.assert_has_calls(get_fps_calls)
self.assertEqual(expected, actual)
@mock.patch.object(redfish.RedfishOperations, '_get_fps_from_file')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_remove_tls_certificate_no_certificate(
self, get_sushy_system_mock, _uefi_boot_mode_mock, get_fps_mock):
_uefi_boot_mode_mock.return_value = True
cert_file_list = ['/path/to/certfile1', '/path/to/certfile2']
get_fps_calls = [
mock.call('/path/to/certfile1'),
mock.call('/path/to/certfile2')
]
get_fps_mock.return_value = []
self.assertRaisesRegex(
exception.IloError,
"No valid certificate",
self.rf_client.remove_tls_certificate, cert_file_list)
get_fps_mock.assert_has_calls(get_fps_calls)
(get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
remove_tls_certificate.assert_not_called())
@mock.patch.object(redfish.RedfishOperations, '_get_fps_from_file')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_remove_tls_certificate_raises_ilo_error(
self, get_sushy_system_mock, _uefi_boot_mode_mock, get_fps_mock):
_uefi_boot_mode_mock.return_value = True
get_fps_calls = [
mock.call('/path/to/certfile1'),
mock.call('/path/to/certfile2')
]
get_fps_mock.side_effect = [
["AA:BB:CC", "DD:EE:FF"],
["XX:YY:ZZ"]
]
cert_file_list = ['/path/to/certfile1', '/path/to/certfile2']
(get_sushy_system_mock.return_value.
bios_settings.tls_config.tls_config_settings.
remove_tls_certificate.side_effect) = (
sushy.exceptions.SushyError)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller has failed to remove TLS certificate.',
self.rf_client.remove_tls_certificate, cert_file_list)
get_fps_mock.assert_has_calls(get_fps_calls)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_remove_tls_certificate_bios(self, get_sushy_system_mock,
_uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
fp = ('FA:3A:68:C7:7E:ED:90:21:D2:FA:3E:54:6B:0C:14:D3:'
'2F:8D:43:50:F7:05:A7:0F:1C:68:35:DB:5C:D2:53:28')
self.assertRaisesRegex(
exception.IloCommandNotSupportedInBiosError,
'TLS certificates cannot be removed in BIOS boot mode',
self.rf_client.remove_tls_certificate, fp)
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_update_password_complexity(self, account_mock, secure_mock):
self.rf_client.update_password_complexity()
(self.sushy.get_account_service.return_value.
update_enforce_passwd_complexity.assert_called_once_with(True))
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_update_password_complexity_fail(self, account_mock,
secure_mock):
(self.sushy.get_account_service.return_value.
update_enforce_passwd_complexity.
side_effect) = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to update the security dashboard '
'parameter ``Password_Complexity``.',
self.rf_client.update_password_complexity)
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_update_require_login_for_ilo_rbsu(self, manager_mock,
secure_mock):
self.rf_client.update_require_login_for_ilo_rbsu()
(manager_mock.return_value.update_login_for_ilo_rbsu.
assert_called_once_with(True))
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_update_require_login_for_ilo_rbsu_fail(self, manager_mock,
secure_mock):
(manager_mock.return_value.update_login_for_ilo_rbsu.
side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to update the security dashboard"
" parameter ``RequiredLoginForiLORBSU``.")
self.assertRaisesRegex(
exception.IloError, msg,
self.rf_client.update_require_login_for_ilo_rbsu)
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_update_require_host_authentication(self, manager_mock,
secure_mock):
self.rf_client.update_require_host_authentication()
(manager_mock.return_value.update_host_authentication.
assert_called_once_with(True))
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_update_require_host_authentication_fail(self, manager_mock,
secure_mock):
(manager_mock.return_value.update_host_authentication.
side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to update the "
"security dashboard paramater ``RequireHostAuthentication``.")
self.assertRaisesRegex(
exception.IloError, msg,
self.rf_client.update_require_host_authentication)
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_update_minimum_password_length(self, account_mock, secure_mock):
self.rf_client.update_minimum_password_length(passwd_length=10)
(self.sushy.get_account_service.return_value.
update_min_passwd_length.assert_called_once_with(10))
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_update_minimum_password_length_fail(self, account_mock,
secure_mock):
(self.sushy.get_account_service.return_value.
update_min_passwd_length.side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to update the "
"security dashboard paramater ``MinPasswordLength``.")
self.assertRaisesRegex(
exception.IloError, msg,
self.rf_client.update_minimum_password_length)
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_update_ipmi_over_lan(self, manager_mock, secure_mock):
self.rf_client.update_ipmi_over_lan()
(manager_mock.return_value.networkprotocol.return_value.
update_ipmi_enabled(False))
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_update_ipmi_over_lan_fail(self, manager_mock, secure_mock):
(manager_mock.return_value.networkprotocol.
update_ipmi_enabled.side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to update the "
"security dashboard paramater ``IPMI/DCMI_Over_LAN``.")
self.assertRaisesRegex(
exception.IloError, msg, self.rf_client.update_ipmi_over_lan)
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_update_authentication_failure_logging(self, account_mock,
secure_mock):
self.rf_client.update_authentication_failure_logging()
(self.sushy.get_account_service.return_value.
update_auth_failure_logging.assert_called_once_with(None))
@mock.patch.object(redfish.RedfishOperations,
'_update_security_parameter')
@mock.patch.object(main.HPESushy, 'get_account_service')
def test_update_authentication_failure_logging_fail(self, account_mock,
secure_mock):
(self.sushy.get_account_service.return_value.
update_auth_failure_logging.
side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to update the security "
"dashboard paramater ``Authentication_failure_Logging``.")
self.assertRaisesRegex(
exception.IloError, msg,
self.rf_client.update_authentication_failure_logging)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test__create_csr(self, manager_mock):
data = {
"CommonName": '1.1.1.1',
"Country": 'IN',
"State": 'KA',
"City": 'blr',
"OrgName": 'HPE',
"OrgUnit": None
}
(manager_mock.return_value.securityservice.https_certificate_uri.
generate_csr.return_value) = 'certificate'
self.rf_client._create_csr(data)
(manager_mock.return_value.securityservice.https_certificate_uri.
generate_csr.assert_called_once_with(data))
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test__create_csr_fail(self, manager_mock):
data = {
"CommonName": '1.1.1.1',
"Country": 'IN',
"State": 'KA',
"City": 'blr',
"OrgName": 'HPE',
"OrgUnit": None
}
(manager_mock.return_value.securityservice.https_certificate_uri.
generate_csr.side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to create the "
"certificate signing request. ")
self.assertRaisesRegex(
exception.IloError, msg, self.rf_client._create_csr, data)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(os, 'chmod', autospec=True)
@mock.patch.object(os, 'makedirs', autospec=True)
@mock.patch.object(builtins, 'open', autospec=True)
def test_create_csr(self, open_mock, makedirs_mock, chmod_mock,
manager_mock):
data = {
"CommonName": '1.1.1.1',
"Country": 'IN',
"State": 'KA',
"City": 'blr',
"OrgName": 'HPE',
"OrgUnit": None
}
(manager_mock.return_value.securityservice.https_certificate_uri.
generate_csr.return_value) = 'certificate'
self.rf_client.create_csr('/httproot/', data)
(manager_mock.return_value.securityservice.https_certificate_uri.
generate_csr.assert_called_once_with(data))
makedirs_mock.assert_called_once_with('/httproot/', 0o755)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
def test_create_csr_fail(self, manager_mock):
data = {
"CommonName": '1.1.1.1',
"Country": 'IN',
"State": 'KA',
"City": 'blr',
"OrgName": 'HPE',
"OrgUnit": None
}
(manager_mock.return_value.securityservice.https_certificate_uri.
generate_csr.side_effect) = sushy.exceptions.SushyError
msg = ("The Redfish controller failed to create the "
"certificate signing request. ")
self.assertRaisesRegex(
exception.IloError, msg, self.rf_client.create_csr,
'/httproot', data)
@mock.patch.object(redfish.RedfishOperations, '_create_csr')
@mock.patch.object(redfish.RedfishOperations, '_add_https_certificate')
@mock.patch.object(builtins, 'open')
@mock.patch('subprocess.Popen')
def test_add_ssl_certificate(self, subprocess_mock, open_mock,
https_cert_mock, create_mock):
csr_params = {
"CommonName": '1.1.1.1',
"Country": 'IN',
"State": 'KA',
"City": 'blr',
"OrgName": 'HPE',
"OrgUnit": None
}
p_key = '/p_key.key'
create_mock.return_value = '/tmp/csr_file'
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
process_mock = mock.Mock()
attrs = {'communicate.return_value': ('output', 'error')}
process_mock.configure_mock(**attrs)
subprocess_mock.return_value = process_mock
self.rf_client.add_ssl_certificate(csr_params, data, p_key, '1234')
subprocess_mock.assert_called_once()
https_cert_mock.assert_called_once()
create_mock.assert_called_once()
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(builtins, 'open')
def test__add_https_certificate(self, open_mock, manager_mock):
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
c_l = [
"-----BEGIN CERTIFICATE-----\r\nMIID7TC\r\nCF"
"g879\r\n-----END CERTIFICATE-----",
"-----BEGIN CERTIFICATE-----\r\nKHY8UP\r\nGH"
"f792\r\n-----END CERTIFICATE-----"
]
cert_file = '/path/to/certfile'
self.rf_client._add_https_certificate(cert_file)
(manager_mock.return_value.securityservice.https_certificate_uri.
import_certificate.assert_called_once_with(c_l[0]))
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(builtins, 'open')
def test__add_https_certificate_no_certificate(self, open_mock,
manager_mock):
data = (
"-----UNFORMATED CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----UNFORMATED CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
cert_file = "/path/to/certfile"
self.assertRaisesRegex(
exception.IloError,
"No valid certificate",
self.rf_client._add_https_certificate, cert_file)
(manager_mock.return_value.securityservice.https_certificate_uri.
import_certificate.assert_not_called())
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(builtins, 'open')
def test__add_https_certificate_fail(self, open_mock, manager_mock):
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
cert_file = '/path/to/certfile'
(manager_mock.return_value.securityservice.https_certificate_uri.
import_certificate.side_effect) = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to import the given '
'certificate. ', self.rf_client._add_https_certificate, cert_file)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(builtins, 'open')
def test_add_https_certificate(self, open_mock, manager_mock):
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
c_l = [
"-----BEGIN CERTIFICATE-----\r\nMIID7TC\r\nCF"
"g879\r\n-----END CERTIFICATE-----",
"-----BEGIN CERTIFICATE-----\r\nKHY8UP\r\nGH"
"f792\r\n-----END CERTIFICATE-----"
]
cert_file = '/path/to/certfile'
self.rf_client.add_https_certificate(cert_file)
(manager_mock.return_value.securityservice.https_certificate_uri.
import_certificate.assert_called_once_with(c_l[0]))
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(builtins, 'open')
def test_add_https_certificate_no_certificate(self, open_mock,
manager_mock):
data = (
"-----UNFORMATED CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----UNFORMATED CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
cert_file = "/path/to/certfile"
self.assertRaisesRegex(
exception.IloError,
"No valid certificate",
self.rf_client.add_https_certificate, cert_file)
(manager_mock.return_value.securityservice.https_certificate_uri.
import_certificate.assert_not_called())
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_manager')
@mock.patch.object(builtins, 'open')
def test_add_https_certificate_fail(self, open_mock, manager_mock):
data = (
"-----BEGIN CERTIFICATE-----\nMIID7TC\nCF"
"g879\n-----END CERTIFICATE-----\n"
"-----BEGIN CERTIFICATE-----\nKHY8UP\nGH"
"f792\n-----END CERTIFICATE-----\n"
)
fd_mock = mock.MagicMock(spec=io.BytesIO)
open_mock.return_value = fd_mock
fd_mock.__enter__.return_value = fd_mock
fd_mock.read.return_value = data
cert_file = '/path/to/certfile'
(manager_mock.return_value.securityservice.https_certificate_uri.
import_certificate.side_effect) = sushy.exceptions.SushyError
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller failed to import the given '
'certificate. ', self.rf_client.add_https_certificate, cert_file)
@mock.patch.object(redfish.RedfishOperations,
'get_security_dashboard_values')
def test__parse_security_dashboard_values_for_capabilities(self, sec_mock):
desc1 = ('The Require Login for iLO RBSU setting is disabled. '
'This configuration allows unauthenticated iLO access '
'through the UEFI System Utilities.')
act1 = ('Enable the Require Login for iLO RBSU setting.')
desc2 = ('The Password Complexity setting is disabled. This '
'configuration increases system vulnerability to attack.')
act2 = ('Enable the "Password Complexity" setting.')
desc3 = ('The UEFI Secure Boot setting is disabled. In this '
'configuration, the UEFI system firmware does not '
'validate the boot loader, Option ROM firmware, and '
'other system software executables for trusted signatures. '
'This configuration breaks the chain of trust established by '
'iLO from power-on')
act3 = ('Enable the Secure Boot setting in the UEFI System Utilities.')
s = {'server_configuration_lock_status': 'Disabled',
'overall_security_status': 'Risk',
'security_parameters':
{'Require Host Authentication': {'ignore': False,
'security_status': 'Ok',
'state': 'Disabled'},
'Last Firmware Scan Result': {'ignore': False,
'security_status': 'Ok',
'state': 'Ok'},
'Require Login for iLO RBSU': {'ignore': False,
'security_status': 'Risk',
'description': desc1,
'state': 'Disabled',
'recommended_action': act1},
'Authentication Failure Logging': {'ignore': False,
'security_status': 'Ok',
'state': 'Enabled'},
'Password Complexity': {'ignore': False,
'security_status': 'Risk',
'description': desc2,
'state': 'Disabled',
'recommended_action': act2},
'IPMI/DCMI Over LAN': {'ignore': False,
'security_status': 'Ok',
'state': 'Disabled'},
'Security Override Switch': {'ignore': False,
'security_status': 'Ok',
'state': 'Off'},
'Minimum Password Length': {'ignore': False,
'security_status': 'Ok',
'state': 'Ok'},
'Secure Boot': {'ignore': False,
'security_status': 'Risk',
'description': desc3,
'state': 'Disabled',
'recommended_action': act3}}}
sec_mock.return_value = s
expected = {'last_firmware_scan_result': 'Ok',
'overall_security_status': 'Risk',
'security_override_switch': 'Ok'}
actual = (
self.rf_client._parse_security_dashboard_values_for_capabilities())
self.assertEqual(expected, actual)
|