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
|
#
# Copyright 2009- ECMWF.
#
# This software is licensed under the terms of the Apache Licence version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
# This test ensures the User API works as expected.
import time
import os
import pwd
import select
import sys
import threading
from datetime import datetime
import shutil # used to remove directory tree
# ecflow_test_util, see File ecflow_test_util.py
import ecflow_test_util as Test
from ecflow import Defs, Suite, Family, Task, Edit, Meter, Clock, DState, Style, State, RepeatDate, RepeatDateTime, \
PrintStyle, File, Client, SState, CheckPt, Cron, Late, debug_build, Flag, FlagType
import re
import platform
def disable_on(regex_platform):
def decorator(func):
def wrapper(*args, **kwargs):
if re.match(regex_platform, platform.platform()):
print(f"Skipping {func.__name__} due to match with {regex_platform}")
else:
return func(*args, **kwargs)
return wrapper
return decorator
def ecf_includes(): return os.getcwd() + "/test/data/includes"
def debugging(): return False # Use to enable auto flush and disable log file tests
def create_defs(name, port, protocol):
defs = Defs()
suite_name = name
if len(suite_name) == 0: suite_name = "s1"
suite = defs.add_suite(suite_name);
ecfhome = Test.ecf_home(port);
suite.add_variable("ECF_HOME", ecfhome);
protocol_option = "--http" if protocol == Test.Protocol.HTTP else ""
suite.add_variable("ECF_CLIENT_EXE_PATH", f"{File.find_client()} {protocol_option}")
suite.add_variable("SLEEP", "1"); # not strictly required since default is 1 second
suite.add_variable("ECF_INCLUDE", ecf_includes());
family = suite.add_family("f1")
family.add_task("t1")
family.add_task("t2")
return defs
def test_host_port(ci, host, port):
try:
ci.set_host_port(host, port)
return True
except RuntimeError:
return False
def test_host_port_(ci, host_port):
try:
ci.set_host_port(host_port)
return True
except RuntimeError:
return False
def test_client_host_port(host, port):
try:
Client(host, port)
return True
except RuntimeError:
return False
def test_client_host_port_(host_port):
try:
Client(host_port)
return True
except RuntimeError:
return False
def sync_local(ci):
if ci.is_auto_sync_enabled():
return
ci.sync_local()
def test_set_host_port():
print("test_set_host_port")
ci = Client()
ci.debug(True)
ci.enable_http()
print(" Client.get_host() = " + ci.get_host())
print(" Client.get_port() = " + ci.get_port())
assert test_host_port(ci, "host", "3141"), "Expected no errors"
assert test_host_port(ci, "host", 4444), "Expected no errors"
assert test_host_port_(ci, "host:4444"), "Expected no errors"
assert test_host_port_(ci, "host@4444"), "Expected no errors"
assert test_host_port(ci, "", "") == False, "Expected errors"
assert test_host_port(ci, "host", "") == False, "Expected errors"
assert test_host_port(ci, "host", "host") == False, "Expected errors"
assert test_host_port_(ci, "host:host") == False, "Expected errors"
assert test_host_port_(ci, "3141:host") == False, "Expected errors"
assert test_host_port_(ci, "3141@host") == False, "Expected errors"
assert test_host_port_(ci, "3141@") == False, "Expected errors"
assert test_client_host_port("host", "3141"), "Expected no errors"
assert test_client_host_port("host", 4444), "Expected no errors"
assert test_client_host_port_("host:4444"), "Expected no errors"
assert test_client_host_port("", "") == False, "Expected errors"
assert test_client_host_port("host", "") == False, "Expected errors"
assert test_client_host_port("host", "host") == False, "Expected errors"
assert test_client_host_port_("host:host") == False, "Expected errors"
assert test_client_host_port_("3141:host") == False, "Expected errors"
def print_test(ci, test_name):
print(test_name, flush=True)
if ci.is_auto_sync_enabled():
ci.log_msg(test_name + " ============= AUTO SYNC ENABLED ================================ ")
else:
ci.log_msg(test_name + " ================================================================ ")
def test_version(ci):
print_test(ci, "test_version")
client_version = ci.version();
server_version = ci.server_version();
print(" client_version: ", client_version)
print(" server_version: ", server_version)
assert client_version == server_version, "Expected client version(" + client_version + ") and server version(" + server_version + ") to match\n";
def test_client_get_server_defs(ci, protocol):
print_test(ci, "test_client_get_server_defs")
ci.delete_all() # start fresh
ci.load(create_defs("", ci.get_port(), protocol))
ci.get_server_defs()
assert ci.get_defs().find_suite("s1") is not None, "Expected to find suite of name s1:\n" + str(ci.get_defs())
ci.delete_all() # start fresh
ci.load(create_defs("", ci.get_port(), protocol))
sync_local(ci)
assert ci.get_defs().find_suite("s1") is not None, "Expected to find suite of name s1:\n" + str(ci.get_defs())
def test_client_new_log(ci):
print_test(ci, "test_client_new_log")
log_path = Test.log_file_path(ci.get_port())
if not os.path.exists(log_path):
print(log_path + " : log does not exist ?")
new_log_file_name = "./test_client_new_log_" + str(os.getpid()) + ".log"
try:
os.remove(new_log_file_name) # delete file if it exists
except:
pass
ci.new_log(new_log_file_name)
ci.flush_log() # close log file and force write to disk
assert os.path.exists(new_log_file_name), new_log_file_name + " : New log does not exist"
try:
os.remove(new_log_file_name)
except:
pass
# reset new log to original
ci.new_log(log_path)
ci.ping()
ci.flush_log() # close log file and force write to disk
log_file = open(log_path)
try:
log_text = log_file.read(); # assume log file not to big
finally:
log_file.close();
assert log_text.find("--ping") != -1, "Expected to find --ping in log file"
if not os.path.exists(log_path):
print(log_path + " : log does not exist ?")
def test_client_clear_log(ci):
if debugging(): return # dont run this test when debugging as log file is lost
print_test(ci, "test_client_clear_log")
log_path = Test.log_file_path(ci.get_port())
# populate log
ci.ping();
ci.ping();
ci.flush_log() # close log file and force write to disk
log_file = open(log_path)
try:
log_text = log_file.read(); # assume log file not to big
finally:
log_file.close();
assert log_text.find("--ping") != -1, "Expected to find --ping in log file"
ci.clear_log()
if not os.path.exists(log_path):
print(log_path + " : log does not exist ?")
log_file = open(log_path)
try:
log_text = log_file.read(); # assume log file not to big
finally:
log_file.close();
assert len(log_text) == 0, "Expected log file to be empty but found " + log_text
if not os.path.exists(log_path):
print(log_path + " : log does not exist ?")
def test_client_log_msg(ci):
if debugging(): return # dont run this test when debugging
print_test(ci, "test_client_log_msg")
log_path = Test.log_file_path(ci.get_port())
if not os.path.exists(log_path):
print(log_path + " : log does not exist ?")
# Send a message to the log file, then make sure it was written
ci.log_msg("Humpty dumpty sat on a wall!")
ci.flush_log(); # flush and close log file, so we can open it
log_file = open(log_path)
try:
log_text = log_file.read(); # assume log file not to big
finally:
log_file.close();
assert log_text.find("Humpty dumpty sat on a wall!") != -1, "Expected to find Humpty dumpty in the log file"
if not os.path.exists(log_path):
print(log_path + " : log does not exist ?")
def test_client_restart_server(ci):
print_test(ci, "test_client_restart_server")
ci.restart_server()
sync_local(ci)
assert ci.get_defs().get_server_state() == SState.RUNNING, "Expected server to be running"
paths = list(ci.changed_node_paths)
assert len(paths) == 1, "expected changed node to be the root node: " + paths
assert paths[0] == "/", "Expected root path but found " + str(paths[0])
def test_client_halt_server(ci):
print_test(ci, "test_client_halt_server")
ci.halt_server()
sync_local(ci)
assert ci.get_defs().get_server_state() == SState.HALTED, "Expected server to be halted"
paths = list(ci.changed_node_paths)
assert len(paths) == 1, "expected changed node to be the root node"
assert paths[0] == "/", "Expected root path but found " + str(paths[0])
ci.restart_server()
def test_client_shutdown_server(ci):
print_test(ci, "test_client_shutdown_server")
ci.shutdown_server()
sync_local(ci)
assert ci.get_defs().get_server_state() == SState.SHUTDOWN, "Expected server to be shutdown"
paths = list(ci.changed_node_paths)
assert len(paths) == 1, "expected changed node to be the root node"
assert paths[0] == "/", "Expected root path but found " + str(paths[0])
def test_client_load_in_memory_defs(ci, protocol):
print_test(ci, "test_client_load_in_memory_defs")
ci.delete_all() # start fresh
ci.load(create_defs("", ci.get_port(), protocol))
sync_local(ci)
assert ci.get_defs().find_suite("s1") is not None, "Expected to find suite of name s1:\n" + str(ci.get_defs())
def test_client_load_from_disk(ci, protocol):
print_test(ci, "test_client_load_from_disk")
ci.delete_all() # start fresh
defs = create_defs("", ci.get_port(), protocol);
defs_file = "test_client_load_from_disk_" + str(os.getpid()) + ".def"
defs.save_as_defs(defs_file)
assert os.path.exists(defs_file), "Expected file " + defs_file + " to exist after defs.save_as_defs()"
ci.load(defs_file) # open and parse defs file, and load into server.\n"
sync_local(ci)
assert ci.get_defs().find_suite("s1") is not None, "Expected to find suite of name s1:\n" + str(ci.get_defs())
os.remove(defs_file)
def test_client_checkpt(ci, protocol):
print_test(ci, "test_client_checkpt")
# start fresh
ci.delete_all()
port = ci.get_port();
try:
os.remove(Test.checkpt_file_path(port))
os.remove(Test.backup_checkpt_file_path(port))
except:
pass
ci.load(create_defs("", ci.get_port(), protocol))
ci.checkpt()
assert os.path.exists(Test.checkpt_file_path(port)), "Expected check pt file to exist after ci.checkpt()"
assert os.path.exists(Test.backup_checkpt_file_path(port)) == False, "Expected back up check pt file to *NOT* exist"
ci.checkpt() # second check pt should cause backup check pt to be written
assert os.path.exists(
Test.backup_checkpt_file_path(port)), "Expected back up check pt file to exist after second ci.checkpt()"
ci.checkpt(CheckPt.NEVER) # switch of check pointing
ci.checkpt(CheckPt.ALWAYS) # always check point, at any state change
ci.checkpt(CheckPt.ON_TIME) # Check point periodically, by interval set in server
ci.checkpt(CheckPt.ON_TIME, 200) # Check point periodically, by interval set in server
ci.checkpt(CheckPt.UNDEFINED, 0, 35) # Change check point save time alarm
os.remove(Test.checkpt_file_path(port))
os.remove(Test.backup_checkpt_file_path(port))
def test_client_restore_from_checkpt(ci, protocol):
print_test(ci, "test_client_restore_from_checkpt")
# start fresh
ci.delete_all()
port = ci.get_port()
try:
os.remove(Test.checkpt_file_path(port))
os.remove(Test.backup_checkpt_file_path(port))
except:
pass
ci.load(create_defs("", ci.get_port(), protocol))
ci.checkpt()
ci.delete_all()
sync_local(ci)
assert ci.get_defs().find_suite("s1") is None, "Expected all suites to be delete:\n"
ci.halt_server() # server must be halted, otherwise restore_from_checkpt will throw
ci.restore_from_checkpt()
sync_local(ci)
assert ci.get_defs().find_suite("s1") is not None, "Expected to find suite s1 after restore from checkpt:\n" + str(
ci.get_defs())
os.remove(Test.checkpt_file_path(port))
ci.restart_server()
def get_username(): return pwd.getpwuid(os.getuid())[0]
def test_client_reload_wl_file(ci):
print_test(ci, "test_client_reload_wl_file")
expected = False
try:
ci.reload_wl_file();
except:
expected = True
assert expected, "Expected reload to fail when no white list specified"
# create a white list file
port = ci.get_port()
wl_file = open(Test.white_list_file_path(port), 'w')
wl_file.write("#\n")
wl_file.write("4.4.14 # comment\n\n")
wl_file.write("# These user have read and write access to the server\n")
wl_file.write(
get_username() + "\n") # add current user otherwise remaining test's, wont have access from server anymore
wl_file.write("axel # admin\n")
wl_file.write("john # admin\n\n")
wl_file.write("# Read only users\n")
wl_file.write("-fred # needs read access only\n")
wl_file.write("-joe90 # needs read access only\n")
wl_file.close();
ci.reload_wl_file();
os.remove(Test.white_list_file_path(port))
def test_client_run(ci, protocol):
print_test(ci, "test_client_run")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_client_run", port, protocol)
suite = defs.find_suite("test_client_run")
suite.add_defstatus(DState.suspended)
defs.generate_scripts();
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
ci.run("/test_client_run", False)
count = 0
while 1:
count += 1
ci.sync_local() # get the changes, synced with local defs
suite = ci.get_defs().find_suite("test_client_run")
assert suite is not None, "Expected to find suite test_client_run:\n" + str(ci.get_defs())
print(f"Suite state: {suite.get_state()}, {count}, at {datetime.now()}")
if suite.get_state() == State.complete:
break;
assert suite.get_state() != State.aborted, "Expected suite to complete, but found it was aborted"
time.sleep(3)
if count > 20:
assert False, "test_client_run aborted after " + str(count) + " loops:\n" + str(ci.get_defs())
ci.log_msg("Looped " + str(count) + " times")
dir_to_remove = Test.ecf_home(port) + "/" + "test_client_run"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_client_run_with_multiple_paths(ci, protocol):
print_test(ci, "test_client_run_with_multiple_paths")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_client_run_with_multiple_paths", port, protocol)
suite = defs.find_suite("test_client_run_with_multiple_paths")
suite.add_defstatus(DState.suspended)
defs.generate_scripts();
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
path_list = ["/test_client_run_with_multiple_paths/f1/t1", "/test_client_run_with_multiple_paths/f1/t2"]
ci.run(path_list, False)
count = 0
while 1:
count += 1
ci.sync_local() # get the changes, synced with local defs
suite = ci.get_defs().find_suite("test_client_run_with_multiple_paths")
assert suite is not None, "Expected to find suite test_client_run_with_multiple_paths:\n" + str(ci.get_defs())
if suite.get_state() == State.complete:
break;
time.sleep(3)
if count > 20:
assert False, "test_client_run_with_multiple_paths aborted after " + str(count) + " loops:\n" + str(
ci.get_defs())
ci.log_msg("Looped " + str(count) + " times")
dir_to_remove = Test.ecf_home(port) + "/" + "test_client_run_with_multiple_paths"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_client_requeue(ci, protocol):
print_test(ci, "test_client_requeue")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_client_requeue", port, protocol)
suite = defs.find_suite("test_client_requeue")
suite.add_defstatus(DState.suspended)
defs.generate_scripts()
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
ci.force_state_recursive("/test_client_requeue", State.unknown)
sync_local(ci)
suite = ci.get_defs().find_suite("test_client_requeue")
assert suite.get_state() == State.unknown, "Expected to find suite with state unknown"
ci.requeue("/test_client_requeue")
sync_local(ci);
suite = ci.get_defs().find_suite("test_client_requeue")
assert suite.get_state() == State.queued, "Expected to find suite with state queued"
dir_to_remove = Test.ecf_home(port) + "/" + "test_client_requeue"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_client_requeue_with_multiple_paths(ci, protocol):
print_test(ci, "test_client_requeue_with_multiple_paths")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_client_requeue_with_multiple_paths", port, protocol)
suite = defs.find_suite("test_client_requeue_with_multiple_paths")
suite.add_defstatus(DState.suspended)
defs.generate_scripts()
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
ci.force_state_recursive("/test_client_requeue_with_multiple_paths", State.unknown)
sync_local(ci);
task1 = ci.get_defs().find_abs_node("/test_client_requeue_with_multiple_paths/f1/t1")
task2 = ci.get_defs().find_abs_node("/test_client_requeue_with_multiple_paths/f1/t2")
assert task1.get_state() == State.unknown, "Expected to find t1 with state unknown"
assert task2.get_state() == State.unknown, "Expected to find t2 with state unknown"
path_list = ["/test_client_requeue_with_multiple_paths/f1/t1", "/test_client_requeue_with_multiple_paths/f1/t2"]
ci.requeue(path_list)
sync_local(ci);
task1 = ci.get_defs().find_abs_node("/test_client_requeue_with_multiple_paths/f1/t1")
task2 = ci.get_defs().find_abs_node("/test_client_requeue_with_multiple_paths/f1/t2")
assert task1.get_state() == State.queued, "Expected to find task t1 with state queued"
assert task2.get_state() == State.queued, "Expected to find task t2 with state queued"
dir_to_remove = Test.ecf_home(port) + "/" + "test_client_requeue_with_multiple_paths"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_client_free_dep(ci, protocol):
print_test(ci, "test_client_free_dep")
ci.delete_all()
# add a real clock, since we are adding date dependencies
# Note: adding a future time dependency on a task, will cause it to requeue, when complete
# Hence even when we free these dependency they get requeued.
# So we use todays date.
ltime = time.localtime();
day = ltime.tm_mday
month = ltime.tm_mon
year = ltime.tm_year
defs = Defs()
suite = defs.add_suite("test_client_free_dep");
suite.add_clock(Clock(False)) # true means hybrid, False means real
ecfhome = Test.ecf_home(ci.get_port());
suite.add_variable("ECF_HOME", ecfhome);
protocol_option = "--http" if protocol == Test.Protocol.HTTP else ""
suite.add_variable("ECF_CLIENT_EXE_PATH", f"{File.find_client()} {protocol_option}")
suite.add_variable("SLEEPTIME", "1");
suite.add_variable("ECF_INCLUDE", ecf_includes());
family = suite.add_family("f1")
family.add_task("t1").add_time("00:01")
family.add_task("t2").add_date(day, month, year)
family.add_task("t3").add_trigger("1 == 0")
t4 = family.add_task("t4")
t4.add_time("00:01")
t4.add_date(day, month, year)
t4.add_trigger("1 == 0")
defs.generate_scripts();
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
t1_path = "/test_client_free_dep/f1/t1"
t2_path = "/test_client_free_dep/f1/t2"
t3_path = "/test_client_free_dep/f1/t3"
t4_path = "/test_client_free_dep/f1/t4"
while 1:
ci.sync_local()
t1 = ci.get_defs().find_abs_node(t1_path)
t2 = ci.get_defs().find_abs_node(t2_path)
t3 = ci.get_defs().find_abs_node(t3_path)
t4 = ci.get_defs().find_abs_node(t4_path)
if t1.get_state() == State.queued: ci.free_time_dep(t1_path)
if t2.get_state() == State.queued: ci.free_date_dep(t2_path)
if t3.get_state() == State.queued: ci.free_trigger_dep(t3_path)
if t4.get_state() == State.queued: ci.free_all_dep(t4_path)
suite = ci.get_defs().find_suite("test_client_free_dep")
if suite.get_state() == State.complete:
break;
time.sleep(3)
dir_to_remove = Test.ecf_home(ci.get_port()) + "/" + "test_client_free_dep"
shutil.rmtree(dir_to_remove, ignore_errors=True)
class CustomStdOut:
def __init__(self, stream=sys.stdout):
self.marker = "<<<OUTPUT CAPTURE END>>>" # marker to indicate end of capture
self.captured = ""
# create a pipe to capture content temporarily
self.o_pipe, self.i_pipe = os.pipe()
# store the stream
self.stream = sys.stdout if stream is None else stream
self.stream_no = self.stream.fileno()
def __enter__(self):
self.captured = ""
# make a copy of the original stdout
self.backup_no = os.dup(self.stream_no)
# redirect stdout into the write pipe
os.dup2(self.i_pipe, self.stream_no)
# start a worker thread to capture the output
self.worker = threading.Thread(target=self._capture_output)
self.worker.start()
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
# write the end marker to indicate the end of capture
self.stream.write(self.marker)
self.stream.flush()
# wait for the worker threadto finish capturing output
self.worker.join()
# close the temporary pipe
os.close(self.i_pipe)
os.close(self.o_pipe)
# restore the original output fd
os.dup2(self.backup_no, self.stream_no)
def _capture_output(self):
while True:
self.captured += os.read(self.o_pipe, 1).decode(self.stream.encoding)
if self.captured.endswith(self.marker):
# we reached the end marker, so we stop capturing and remove the marker
self.captured = self.captured[:-len(self.marker)]
break
def value(self):
return self.captured
@disable_on("macOS-13.*-arm64-.*")
def test_client_stats(ci):
print_test(ci, "test_client_stats")
out = CustomStdOut()
with out:
stats = ci.stats()
assert "statistics" in stats, "Expected 'statistics' in the response"
assert "statistics" in out.value(), "Expected 'statistics' in the captured output"
@disable_on("macOS-13.*-arm64-.*")
def test_client_stats_with_stdout(ci):
print_test(ci, "test_client_stats_with_stdout")
out = CustomStdOut()
with out:
stats = ci.stats(True)
assert "statistics" in stats, "Expected 'statistics' in the response"
assert "statistics" in out.value(), "Expected 'statistics' in the captured output"
@disable_on("macOS-13.*-arm64-.*")
def test_client_stats_without_stdout(ci):
print_test(ci, "test_client_stats_without_stdout")
out = CustomStdOut()
with out:
stats = ci.stats(False)
assert "statistics" in stats, "Expected 'statistics' in the response"
assert not out.value(), "No captured output expected, but found: " + out.value()
def test_client_stats_reset(ci):
print_test(ci, "test_client_stats_reset")
ci.stats_reset()
stats = ci.stats()
assert "statistics" in stats, "Expected 'statistics' in the response"
def test_client_debug_server_on_off(ci):
print_test(ci, "test_client_debug_server_on_off")
ci.debug_server_on() # writes to standard out
ci.debug_server_off()
def test_client_check(ci):
print_test(ci, "test_client_check")
ci.delete_all()
defs = Defs()
defs.add_extern("/a/b/c/d")
defs.add_extern("/a/b/c/d/e:event")
defs.add_extern("/a/b/c/d/e:meter")
defs.add_extern("/made/up/redundant/extren")
defs.add_extern("/made/up/redundant/extren")
defs.add_extern("/limits:c1a")
defs.add_extern("/limits:c1a")
defs.add_extern("fred")
defs.add_extern("limits:hpcd")
defs.add_extern("/suiteName:sg1")
defs.add_extern("/obs/limits:hpcd")
suite = defs.add_suite("extern")
family_f1 = suite.add_family("f1")
family_f1.add_task("p").add_trigger("/a/b/c/d == complete") # extern path
family_f1.add_task("q").add_trigger("/a/b/c/d/e:event == set") # extern event path
family_f1.add_task("r").add_trigger("/a/b/c/d/e:meter le 30") # extern meter path
suite.add_inlimit("c1a", "/limits")
suite.add_inlimit("fred")
family_anon = suite.add_family("anon")
family_anon.add_inlimit("hpcd", "limits")
family_anon.add_task("t1").add_inlimit("sg1", "/suiteName")
family_anon.add_task("t2").add_inlimit("hpcd", "/obs/limits")
family_anon.add_task("t3").add_inlimit("c1a", "/limits")
# CLIENT side check
client_check = defs.check()
assert len(client_check) == 0, "Expected clean defs check due to externs but found:\n" + client_check + "\n" + str(
defs)
# SERVER side check
ci.load(defs)
server_check = ci.check("") # empty string means check the whole defs, otherwise a node path can be specified.
# print(server_check)
assert len(server_check) > 0, "Expected defs to fail, since no externs in server "
def test_client_suites(ci, protocol):
print_test(ci, "test_client_suites")
ci.delete_all()
assert len(ci.suites()) == 0, "expected 0 suite "
defs = create_defs("test_client_suites", ci.get_port(), protocol)
ci.load(defs)
assert len(ci.suites()) == 1, "expected 1 suite "
ci.delete_all()
defs.add_suite("s2")
ci.load(defs)
assert len(ci.suites()) == 2, "expected 2 suite "
def test_client_ch_suites(ci):
print_test(ci, "test_client_ch_suites")
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
ci.delete_all()
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 6, "Expected 6 after load, but found " + str(
len(list((ci.get_defs().suites))))
suite_names = ['s1', 's2', 's3']
ci.ch_register(True, suite_names) # register interest in suites s1,s2,s3 and any new suites
print("ch_handle after register : ", ci.ch_handle())
ci.ch_suites() # writes to standard out, list of suites and handles
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 3, "Expected 3 registered suites but found " + str(
len(list((ci.get_defs().suites))))
ci.ch_register(False, ["s1"]) # register interest in suites s1. ci remembers the last client handle
ci.ch_suites() # writes to standard out, list of suites and handles
sync_local(ci)
ci.ch_suites() # writes to standard out, list of suites and handles
assert len(list(ci.get_defs().suites)) == 1, "Expected 1 registered suites but found " + str(
len(list((ci.get_defs().suites))))
def test_client_ch_register(ci):
print_test(ci, "test_client_ch_register")
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
ci.delete_all()
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
suite_names = ['s1', 's2', 's3']
ci.ch_register(True, suite_names) # register interest in suites s1,s2,s3 and any new suites
ci.ch_register(False, suite_names) # register interest in suites s1,s2,s3 only
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 3, "Expected 3 registered suites but found " + str(
len(list((ci.get_defs().suites))))
def test_client_ch_drop(ci):
print_test(ci, "test_client_ch_drop")
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
ci.delete_all()
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
try:
# register interest in suites s1,s2,s3 and any new suites
suite_names = ['s1', 's2', 's3']
ci.ch_register(True, suite_names)
finally:
ci.ch_drop() # drop using handle stored in ci., from last register
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 6, "Expected 6 suites but found " + str(len(list((ci.get_defs().suites))))
def test_client_ch_drop_user(ci):
print_test(ci, "test_client_ch_drop_user")
ci.delete_all()
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
try:
# register interest in suites s1,s2,s3 and any new suites
suite_names = ['s1', 's2', 's3']
ci.ch_register(True, suite_names)
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 3, "Expected 3 suites but found " + str(
len(list((ci.get_defs().suites))))
except RuntimeError as e:
print(str(e))
ci.ch_drop_user("") # drop all handle associated with current user
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 6, "Expected 6 suites but found " + str(len(list((ci.get_defs().suites))))
def test_client_ch_add(ci):
print_test(ci, "test_client_ch_add")
ci.delete_all()
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
try:
suite_names = []
ci.ch_register(True, suite_names) # register interest in any new suites
suite_names = ['s1', 's2']
ci.ch_add(suite_names) # add suites s1,s2 to the last added handle
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 2, "Expected 2 suites but found " + str(
len(list((ci.get_defs().suites))))
suite_names = ['s3', 's4']
ci.ch_add(ci.ch_handle(), suite_names) # add suites s3,s4 using last handle
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 4, "Expected 4 suites but found " + str(
len(list((ci.get_defs().suites))))
except RuntimeError as e:
print(str(e))
ci.ch_drop_user("") # drop all handle associated with current user
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 6, "Expected 6 suites but found " + str(len(list((ci.get_defs().suites))))
def test_client_ch_auto_add(ci):
print_test(ci, "test_client_ch_auto_add")
ci.delete_all()
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
try:
suite_names = ['s1', 's2', 's3']
ci.ch_register(True, suite_names) # register interest in suites s1,s2,s3 and any new suites
ci.ch_auto_add(False) # disable adding newly created suites to last registered handle\n"
ci.ch_auto_add(True) # enable adding newly created suites to last registered handle\n"
ci.ch_auto_add(ci.ch_handle(), False) # disable adding newly created suites to handle\n"
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 3, "Expected 3 suites but found " + str(
len(list((ci.get_defs().suites))))
except RuntimeError as e:
print(str(e))
ci.ch_drop_user("") # drop all handle associated with current user
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 6, "Expected 6 suites but found " + str(len(list((ci.get_defs().suites))))
def test_client_ch_remove(ci):
print_test(ci, "test_client_ch_remove")
ci.delete_all()
try:
ci.ch_drop_user("") # drop all handle associated with current user
except:
pass # Drop throws if no handle registered
defs = Defs()
for i in range(1, 7): defs.add_suite("s" + str(i))
ci.load(defs)
try:
suite_names = ['s1', 's2', 's3']
ci.ch_register(True, suite_names) # register interest in suites s1,s2,s3 and any new suites
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 3, "Expected 3 suites but found " + str(
len(list((ci.get_defs().suites))))
suite_names = ['s1']
ci.ch_remove(suite_names) # remove suites s1 from the last added handle\n"
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 2, "Expected 2 suites but found " + str(
len(list((ci.get_defs().suites))))
suite_names = ['s2']
ci.ch_remove(ci.ch_handle(), suite_names) # remove suites s2 from the last added handle\n"
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 1, "Expected 1 suites but found " + str(
len(list((ci.get_defs().suites))))
except RuntimeError as e:
print(str(e))
ci.ch_drop_user("") # drop all handle associated with current user
sync_local(ci)
assert len(list(ci.get_defs().suites)) == 6, "Expected 6 suites but found " + str(len(list((ci.get_defs().suites))))
def test_client_get_file(ci):
print_test(ci, "test_client_get_file")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_client_get_file", port, protocol)
# Also test where user has specified his OWN ECF_JOBOUT (rare)
t2 = defs.find_abs_node("/test_client_get_file/f1/t2")
t2_jobout = Test.ecf_home(ci.get_port()) + "/test_client_get_file/t2.xx"
t2.add_variable("ECF_JOBOUT", t2_jobout)
defs.generate_scripts()
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
while 1:
if ci.news_local():
ci.sync_local() # get the changes, synced with local defs
suite = ci.get_defs().find_suite("test_client_get_file")
assert suite is not None, "Expected to find suite"
if suite.get_state() == State.complete:
break
time.sleep(1)
try:
for task in ['/test_client_get_file/f1/t1', '/test_client_get_file/f1/t2']:
result_string = ci.get_file(task)
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}) to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}) to return something"
result_string = ci.get_file(task, as_bytes=False)
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, as_bytes=False) to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, as_bytes=False) to return something"
result_bytes = ci.get_file(task, as_bytes=True)
assert isinstance(result_bytes, bytes), \
f"Expected ci.get_file({task}, as_bytes=True) to return 'bytes'"
assert len(result_bytes) > 0, \
f"Expected ci.get_file({task}, as_bytes=True) to return something"
assert len(result_string) == len(result_bytes), \
f"Expected 'str' result and 'bytes' result to have the same length"
result_string = ci.get_file(task, max_lines='10')
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, max_lines='10') to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, max_lines='10') to return something"
result_string = ci.get_file(task, max_lines='10', as_bytes=False)
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, max_lines='10', as_bytes=False) to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, max_lines='10', as_bytes=False) to return something"
result_bytes = ci.get_file(task, max_lines='10', as_bytes=True)
assert isinstance(result_bytes, bytes), \
f"Expected ci.get_file({task}, max_lines='10', as_bytes=True) to return 'bytes'"
assert len(result_bytes) > 0, \
f"Expected ci.get_file({task}, max_lines='10', as_bytes=True) to return something"
assert len(result_string) == len(result_bytes), \
f"Expected 'str' result and 'bytes' result to have the same length"
for file_type in ['script', 'job', 'jobout', 'manual']:
result_string = ci.get_file(task, file_type)
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, {file_type}) to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, {file_type}) to return something"
result_string = ci.get_file(task, file_type, as_bytes=False)
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, {file_type}, as_bytes=False) to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, {file_type}, as_bytes=False) to return something"
result_bytes = ci.get_file(task, file_type, as_bytes=True)
assert isinstance(result_bytes, bytes), \
f"Expected ci.get_file({task}, {file_type}, as_bytes=True) to return 'bytes'"
assert len(result_bytes) > 0, \
f"Expected ci.get_file({task}, {file_type}, as_bytes=True) to return something"
assert len(result_string) == len(result_bytes), \
f"Expected 'str' result and 'bytes' result to have the same length"
result_string = ci.get_file(task, file_type, '10')
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, {file_type}, '10') to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, {file_type}, '10') to return something"
result_string = ci.get_file(task, file_type, '10', as_bytes=False)
assert isinstance(result_string, str), \
f"Expected ci.get_file({task}, {file_type}, '10', as_bytes=False) to return 'str'"
assert len(result_string) > 0, \
f"Expected ci.get_file({task}, {file_type}, '10', as_bytes=False) to return something"
result_bytes = ci.get_file(task, file_type, '10', as_bytes=True)
assert isinstance(result_bytes, bytes), \
f"Expected ci.get_file({task}, {file_type}, '10', as_bytes=True) to return 'bytes'"
assert len(result_bytes) > 0, \
f"Expected ci.get_file({task}, {file_type}, '10', as_bytes=True) to return something"
assert len(result_string) == len(result_bytes), \
f"Expected 'str' result and 'bytes' result to have the same length"
assert os.path.exists(t2_jobout), f"User specified ECF_JOBOUT file not created {t2_jobout}"
except RuntimeError as e:
print(str(e))
dir_to_remove = Test.ecf_home(port) + "/" + "test_client_get_file"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_client_plug(ci):
pass
def test_client_alter_sort(ci, protocol):
print_test(ci, "test_client_alter_sort")
ci.delete_all()
defs = create_defs("test_client_alter_sort", ci.get_port(), protocol)
t1 = "/test_client_alter_sort/f1/t1"
task_t1 = defs.find_abs_node(t1)
task_t1.add_variable("z", "value").add_variable("y", "value").add_variable("x", "value")
task_t1.add_event("z").add_event("y").add_event("x")
task_t1.add_meter("z", 0, 100, 100).add_meter("y", 0, 100, 100).add_meter("x", 0, 100, 100)
task_t1.add_label("z", "name").add_label("y", "name").add_label("x", "name")
task_t1.add_limit("z", 10).add_limit("y", 10).add_limit("x", 10)
ci.load(defs)
ci.sort_attributes(t1, "variable")
ci.sort_attributes(t1, "event")
ci.sort_attributes(t1, "meter")
ci.sort_attributes(t1, "label")
ci.sort_attributes(t1, "limit")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.variables)) == 3, "Expected 3 variable :\n" + str(ci.get_defs())
assert len(list(task_t1.events)) == 3, "Expected 3 events :\n" + str(ci.get_defs())
assert len(list(task_t1.meters)) == 3, "Expected 3 meters :\n" + str(ci.get_defs())
assert len(list(task_t1.labels)) == 3, "Expected 3 labels :\n" + str(ci.get_defs())
assert len(list(task_t1.limits)) == 3, "Expected 3 limits :\n" + str(ci.get_defs())
expected = ['x', 'y', 'z'];
vactual = [];
eactual = [];
mactual = [];
lactual = [];
liactual = [];
for v in task_t1.variables: vactual.append(v.name())
for v in task_t1.events: eactual.append(v.name())
for v in task_t1.meters: mactual.append(v.name())
for v in task_t1.labels: lactual.append(v.name())
for v in task_t1.limits: liactual.append(v.name())
assert expected == vactual, "variable Attributes not sorted, expected:" + str(expected) + " but found:" + str(
vactual)
assert expected == eactual, "event Attributes not sorted, expected:" + str(expected) + " but found:" + str(eactual)
assert expected == mactual, "meter Attributes not sorted, expected:" + str(expected) + " but found:" + str(mactual)
assert expected == lactual, "label Attributes not sorted, expected:" + str(expected) + " but found:" + str(lactual)
assert expected == liactual, "limit Attributes not sorted, expected:" + str(expected) + " but found:" + str(
liactual)
def test_client_alter_sort_defs(ci, protocol):
print_test(ci, "test_client_alter_sort_defs")
ci.delete_all()
defs = create_defs("test_client_alter_sort_defs", ci.get_port(), protocol)
t1 = "/test_client_alter_sort_defs/f1/t1"
task_t1 = defs.find_abs_node(t1)
task_t1.add_variable("z", "value").add_variable("y", "value").add_variable("x", "value")
task_t1.add_event("z").add_event("y").add_event("x")
task_t1.add_meter("z", 0, 100, 100).add_meter("y", 0, 100, 100).add_meter("x", 0, 100, 100)
task_t1.add_label("z", "name").add_label("y", "name").add_label("x", "name")
task_t1.add_limit("z", 10).add_limit("y", 10).add_limit("x", 10)
ci.load(defs)
ci.sort_attributes("/", "variable", True)
ci.sort_attributes("/", "event", True)
ci.sort_attributes("/", "meter", True)
ci.sort_attributes("/", "label", True)
ci.sort_attributes("/", "limit", True)
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.variables)) == 3, "Expected 3 variable :\n" + str(ci.get_defs())
assert len(list(task_t1.events)) == 3, "Expected 3 events :\n" + str(ci.get_defs())
assert len(list(task_t1.meters)) == 3, "Expected 3 meters :\n" + str(ci.get_defs())
assert len(list(task_t1.labels)) == 3, "Expected 3 labels :\n" + str(ci.get_defs())
assert len(list(task_t1.limits)) == 3, "Expected 3 limits :\n" + str(ci.get_defs())
expected = ['x', 'y', 'z'];
vactual = [];
eactual = [];
mactual = [];
lactual = [];
liactual = [];
for v in task_t1.variables: vactual.append(v.name())
for v in task_t1.events: eactual.append(v.name())
for v in task_t1.meters: mactual.append(v.name())
for v in task_t1.labels: lactual.append(v.name())
for v in task_t1.limits: liactual.append(v.name())
assert expected == vactual, "variable Attributes not sorted, expected:" + str(expected) + " but found:" + str(
vactual)
assert expected == eactual, "event Attributes not sorted, expected:" + str(expected) + " but found:" + str(eactual)
assert expected == mactual, "meter Attributes not sorted, expected:" + str(expected) + " but found:" + str(mactual)
assert expected == lactual, "label Attributes not sorted, expected:" + str(expected) + " but found:" + str(lactual)
assert expected == liactual, "limit Attributes not sorted, expected:" + str(expected) + " but found:" + str(
liactual)
def test_client_alter_add(ci, protocol):
print_test(ci, "test_client_alter_add")
ci.delete_all()
ci.load(create_defs("test_client_alter_add", ci.get_port(), protocol))
t1 = "/test_client_alter_add/f1/t1"
ci.alter(t1, "add", "variable", "var", "var_name")
ci.alter(t1, "add", "variable", "var2", "--")
ci.alter(t1, "add", "variable", "var3", "--fred")
ci.alter(t1, "add", "variable", "var4", " --fred ")
ci.alter(t1, "add", "variable", "var5", "--fred --jake")
ci.alter(t1, "add", "variable", "var6", " --fred --jake ")
ci.alter(t1, "add", "variable", "var7", "")
ci.alter(t1, "add", "time", "+00:30")
ci.alter(t1, "add", "time", "01:30")
ci.alter(t1, "add", "time", "01:30 20:00 00:30")
ci.alter(t1, "add", "today", "+00:30")
ci.alter(t1, "add", "today", "01:30")
ci.alter(t1, "add", "today", "01:30 20:00 00:30")
ci.alter(t1, "add", "date", "01.01.2001")
ci.alter(t1, "add", "date", "*.01.2001")
ci.alter(t1, "add", "date", "*.*.2001")
ci.alter(t1, "add", "date", "*.*.*")
ci.alter(t1, "add", "day", "sunday")
ci.alter(t1, "add", "day", "monday")
ci.alter(t1, "add", "day", "tuesday")
ci.alter(t1, "add", "day", "wednesday")
ci.alter(t1, "add", "day", "thursday")
ci.alter(t1, "add", "day", "friday")
ci.alter(t1, "add", "day", "saturday")
ci.alter(t1, "add", "late", "late -s +00:15 -a 20:00 -c +02:00")
ci.alter(t1, "add", "label", "label_name", "label_value")
ci.alter(t1, "add", "label", "label_name2", "/a/label/with/path/values")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.variables)) == 7, "Expected 7 variable :\n" + str(ci.get_defs())
assert len(list(task_t1.times)) == 3, "Expected 3 time :\n" + str(ci.get_defs())
assert len(list(task_t1.todays)) == 3, "Expected 3 today's :\n" + str(ci.get_defs())
assert len(list(task_t1.dates)) == 4, "Expected 4 dates :\n" + str(ci.get_defs())
assert len(list(task_t1.days)) == 7, "Expected 7 days :\n" + str(ci.get_defs())
assert len(list(task_t1.labels)) == 2, "Expected 2 labels :\n" + str(ci.get_defs())
assert str(
task_t1.get_late()) == "late -s +00:15 -a 20:00 -c +02:00", "Expected late 'late -s +00:15 -a 20:00 -c +02:00'" + str(
ci.get_defs())
def test_client_alter_delete(ci, protocol):
print_test(ci, "test_client_alter_delete")
ci.delete_all()
defs = create_defs("test_client_alter_delete", ci.get_port(), protocol)
suite_with_limits = defs.add_suite("suite_with_limits")
suite_with_limits.add_limit("limitX", 10)
suite_with_limits_X = defs.add_suite("suite_with_limits_X")
suite_with_limits_X.add_limit("limitX", 10)
t1 = "/test_client_alter_delete/f1/t1"
task_t1 = defs.find_abs_node(t1)
task_t1.add_variable("var", "value")
task_t1.add_variable("var1", "value")
task_t1.add_time("00:30")
task_t1.add_time("00:31")
task_t1.add_today("00:30")
task_t1.add_today("00:31")
task_t1.add_date(1, 1, 2001)
task_t1.add_date(1, 1, 2002)
task_t1.add_day("sunday")
task_t1.add_day("monday")
cron = Cron()
cron.set_week_days([0, 1, 2, 3, 4, 5, 6])
cron.set_time_series("+00:30")
task_t1.add_cron(cron)
task_t1.add_cron(cron)
task_t1.add_event("event")
task_t1.add_event("event1")
task_t1.add_meter("meter", 0, 100, 100)
task_t1.add_meter("meter1", 0, 100, 100)
task_t1.add_label("label", "name")
task_t1.add_label("label1", "name")
task_t1.add_limit("limit", 10)
task_t1.add_limit("limit1", 10)
task_t1.add_inlimit("limit", t1, 2)
task_t1.add_inlimit("limit1", t1, 2)
task_t1.add_inlimit("limitX", "/suite_with_limits", 2)
task_t1.add_inlimit("limitX", "/suite_with_limits_X", 2)
task_t1.add_trigger("t2 == active")
task_t1.add_complete("t2 == complete")
assert task_t1.get_late() is None, "expected no late"
late = Late()
late.submitted(20, 10)
late.active(20, 10)
late.complete(20, 10, True)
task_t1.add_late(late)
assert task_t1.get_late() is not None, "expected late"
t2 = "/test_client_alter_delete/f1/t2"
task_t2 = defs.find_abs_node(t2)
task_t2.add_repeat(RepeatDate("date", 20100111, 20100115, 2)) # can't add cron and repeat at the same level
# print(defs)
ci.load(defs)
ci.alter(t1, "delete", "variable", "var")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.variables)) == 1, "Expected 1 variable :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "variable") # delete all veriables
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.variables)) == 0, "Expected 0 variable :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "time", "00:30")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.times)) == 1, "Expected 1 time :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "time")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.times)) == 0, "Expected 0 time :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "today", "00:30")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.todays)) == 1, "Expected 1 today :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "today")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.todays)) == 0, "Expected 0 today :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "date", "01.01.2001")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.dates)) == 1, "Expected 1 date :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "date")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.dates)) == 0, "Expected 0 date :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "day", "sunday")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.days)) == 1, "Expected 1 day :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "day")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.days)) == 0, "Expected 0 day :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "event", "event")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.events)) == 1, "Expected 1 event :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "event")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.events)) == 0, "Expected 0 event :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "meter", "meter")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.meters)) == 1, "Expected 1 meter :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "meter")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.meters)) == 0, "Expected 0 meter :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "label", "label")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.labels)) == 1, "Expected 1 label :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "label")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.labels)) == 0, "Expected 0 label :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "inlimit", "limit")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.inlimits)) == 3, "Expected 3 inlimit :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "inlimit", "/suite_with_limits:limitX")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.inlimits)) == 2, "Expected 2 inlimit :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "inlimit", "/suite_with_limits_X:limitX")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.inlimits)) == 1, "Expected 1 inlimit :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "inlimit")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.inlimits)) == 0, "Expected 0 inlimit :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "limit", "limit")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.limits)) == 1, "Expected 1 limit :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "limit")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.limits)) == 0, "Expected 0 limit :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "cron")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.crons)) == 0, "Expected 0 crons :\n" + str(ci.get_defs())
ci.alter(t1, "delete", "late")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert task_t1.get_late() is None, "expected no late after delete"
task_t1 = ci.get_defs().find_abs_node(t1)
assert task_t1.get_trigger() is not None, "Expected trigger:\n" + str(ci.get_defs())
ci.alter(t1, "delete", "trigger")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert task_t1.get_trigger() is None, "Expected trigger to be deleted:\n" + str(ci.get_defs())
task_t1 = ci.get_defs().find_abs_node(t1)
assert task_t1.get_complete() is not None, "Expected complete:\n" + str(ci.get_defs())
ci.alter(t1, "delete", "complete")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert task_t1.get_complete() is None, "Expected complete to be deleted:\n" + str(ci.get_defs())
ci.alter(t2, "delete", "repeat")
sync_local(ci)
task_t2 = ci.get_defs().find_abs_node(t2)
repeat = task_t2.get_repeat()
assert repeat.empty(), "Expected repeat to be deleted:\n" + str(ci.get_defs())
def test_client_alter_change(ci, protocol):
print_test(ci, "test_client_alter_change")
ci.delete_all()
defs = create_defs("test_client_alter_change", ci.get_port(), protocol)
t1 = "/test_client_alter_change/f1/t1"
repeat_date_path = "/test_client_alter_change/f1/repeat_date"
repeat_datetime_path = "/test_client_alter_change/f1/repeat_datetime"
task_t1 = defs.find_abs_node(t1)
task_t1.add_variable("var", "value")
task_t1.add_variable("var1", "value")
task_t1.add_event("event")
task_t1.add_event("event1")
task_t1.add_meter("meter", 0, 100, 100)
task_t1.add_meter("meter1", 0, 100, 100)
task_t1.add_label("label", "name")
task_t1.add_label("label1", "name1")
task_t1.add_limit("limit", 10)
task_t1.add_limit("limit1", 10)
task_t1.add_inlimit("limit", t1, 2)
task_t1.add_inlimit("limit1", t1, 2)
task_t1.add_trigger("t2 == active")
task_t1.add_complete("t2 == complete")
task_t1.add_time("00:31")
task_t1.add_today("00:30")
late = Late()
late.submitted(20, 10)
late.active(20, 10)
late.complete(20, 10, True)
task_t1.add_late(late)
f1 = defs.find_abs_node("/test_client_alter_change/f1")
# Add a new Repeat (based on date)
repeat_date = f1.add_task("repeat_date")
repeat_date.add_repeat(RepeatDate("date", 20100111, 20100115, 2)) # can't add cron and repeat at the same level
# Add a new Repeat (based on date+time)
repeat_datetime = f1.add_task("repeat_datetime")
repeat_datetime.add_repeat(RepeatDateTime("datetime", "20100111T000000", "20100115T000000", "48:00:00"))
ci.load(defs)
ci.alter(t1, "change", "time", "00:31", "10:10")
ci.alter(t1, "change", "today", "00:30", "10:10")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
assert len(list(task_t1.times)) == 1, "Expected 1 time :\n" + str(ci.get_defs())
assert len(list(task_t1.todays)) == 1, "Expected 1 time :\n" + str(ci.get_defs())
for t in task_t1.times:
assert str(t) == "time 10:10", " expected 'time 10:10' but found:\n" + str(t)
for t in task_t1.todays:
assert str(t) == "today 10:10", " expected 'today 10:10' but found:\n" + str(t)
ci.alter(t1, "change", "late", "-s +10:00")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
variable = task_t1.get_late()
assert str(
task_t1.get_late()) == "late -s +10:00", "Expected alter of late to be 'late -s +10:00' but found " + str(
task_t1.get_late())
ci.alter(t1, "change", "variable", "var", "changed_var")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
variable = task_t1.find_variable("var")
assert variable.value() == "changed_var", "Expected alter of variable to be 'change_var' but found " + variable.value()
res = ci.query('variable', task_t1.get_abs_node_path(), "var")
assert res == 'changed_var', "Expected alter of variable to be 'change_var' but found " + res
ci.alter(t1, "change", "variable", "var", "--")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
variable = task_t1.find_variable("var")
assert variable.value() == "--", "Expected alter of variable to be '--' but found " + variable.value()
res = ci.query('variable', task_t1.get_abs_node_path(), "var")
assert res == '--', "Expected alter of variable to be '--' but found " + res
ci.alter(t1, "change", "variable", "var", "--fred")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
variable = task_t1.find_variable("var")
assert variable.value() == "--fred", "Expected alter of variable to be '--fred' but found " + variable.value()
ci.alter(t1, "change", "variable", "var", "--fred --bill")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
variable = task_t1.find_variable("var")
assert variable.value() == "--fred --bill", "Expected alter of variable to be '--fred --bill' but found " + variable.value()
ci.alter(t1, "change", "meter", "meter", "10")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
meter = task_t1.find_meter("meter")
assert meter.value() == 10, "Expected alter of meter to be 10 but found " + str(meter.value())
res = ci.query('meter', task_t1.get_abs_node_path(), "meter")
assert res == '10', "Expected alter of meter to be 10 but found " + res
ci.alter(t1, "change", "event", "event", "set")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
event = task_t1.find_event("event")
assert event.value() == True, "Expected alter of event to be set but found " + str(event.value())
res = ci.query('event', task_t1.get_abs_node_path(), "event")
assert res == 'set', "Expected alter of event to be 'set' but found " + res
ci.alter(t1, "change", "trigger", "t2 == aborted")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
trigger = task_t1.get_trigger()
assert trigger.get_expression() == "t2 == aborted", "Expected alter of trigger to be 't2 == aborted' but found " + trigger.get_expression()
res = ci.query('trigger', task_t1.get_abs_node_path(), "t2 == aborted")
assert res == 'false', "Expected evaluation of trigger to fail, but found: " + res
ci.alter(t1, "change", "trigger", "/test_client_alter_change/f1/t2 == complete")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
trigger = task_t1.get_trigger()
assert trigger.get_expression() == "/test_client_alter_change/f1/t2 == complete", "Expected alter of trigger to be '/test_client_alter_change/f1/t2 == complete' but found " + trigger.get_expression()
ci.alter(t1, "change", "complete", "t2 == aborted")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
complete = task_t1.get_complete()
assert complete.get_expression() == "t2 == aborted", "Expected alter of complete to be 't2 == aborted' but found " + complete.get_expression()
ci.alter(t1, "change", "complete", "/test_client_alter_change/f1/t2 == active")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
complete = task_t1.get_complete()
assert complete.get_expression() == "/test_client_alter_change/f1/t2 == active", "Expected alter of complete to be '/test_client_alter_change/f1/t2 == active' but found " + complete.get_expression()
ci.alter(t1, "change", "limit_max", "limit", "2")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
limit = task_t1.find_limit("limit")
assert limit is not None, "Expected to find limit"
assert limit.limit() == 2, "Expected alter of limit_max to be 2 but found " + str(limit.limit())
ci.alter(t1, "change", "limit_value", "limit", "2")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
limit = task_t1.find_limit("limit")
assert limit is not None, "Expected to find limit"
assert limit.value() == 2, "Expected alter of limit_value to be 2 but found " + str(limit.value())
ci.alter(t1, "change", "label", "label", "new-value")
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
label = task_t1.find_label("label")
assert label.new_value() == "new-value", "Expected alter of label to be 'new-value' but found " + label.new_value()
ci.alter(repeat_date_path, "change", "repeat", "20100113")
sync_local(ci)
task = ci.get_defs().find_abs_node(repeat_date_path)
repeat = task.get_repeat()
assert repeat.value() == 20100113, "Expected alter of repeat to be 20100113 but found " + str(repeat.value())
res = ci.query('variable', task.get_abs_node_path(), repeat.name())
assert res == "20100113", "Expected alter of repeat to be 20100113 but found " + res
ci.alter(repeat_datetime_path, "change", "repeat", "20100113T000000")
sync_local(ci)
task = ci.get_defs().find_abs_node(repeat_datetime_path)
repeat = task.get_repeat()
assert repeat.value() == 1263340800, "Expected alter of repeat to be 1263340800 (i.e. seconds between 19700101T000000 and 20100113T000000) but found " + str(
repeat.value())
res = ci.query('variable', task.get_abs_node_path(), repeat.name())
assert res == "20100113T000000", "Expected alter of repeat to be 20100113T000000 but found " + res
def test_client_alter_flag(ci, protocol):
print_test(ci, "test_client_alter_flag")
ci.delete_all()
defs = create_defs("test_client_alter_flag", ci.get_port(), protocol)
t1 = "/test_client_alter_flag/f1/t1"
task_t1 = defs.find_abs_node(t1)
ci.load(defs)
flag = Flag()
flag_list = flag.list() # flag_list is of type FlagTypeVec
for flg in flag_list:
ci.alter(t1, "set_flag", flag.type_to_string(flg))
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
task_flag = task_t1.get_flag()
assert task_flag.is_set(flg), "expected flag %r to be set" % task_flag.type_to_string(flg)
# alter itself causes the flag message to be set, and preserved
if flg == FlagType.message: continue
ci.alter(t1, "clear_flag", flag.type_to_string(flg))
sync_local(ci)
task_t1 = ci.get_defs().find_abs_node(t1)
task_flag = task_t1.get_flag()
assert not task_flag.is_set(flg), "expected flag %r NOT to be set" % task_flag.type_to_string(flg)
# ISSUES:
# o Currently we can only change clock attr if we have one.
# o Even when we have a clock attr, it only makes sense to apply clock attr changes
# before begin(), i.e how do we apply change in gain after begin ??
# " change clock-type name # The name must be one of 'hybrid' or 'real'.\n"
# " change clock-gain name # The gain must be convertible to an integer.\n"
# " change label name value # sets the label\n"
# " change repeat value # If the repeat is a date, then the value must be a valid YMD ( ie. yyyymmdd)\n"
# " # and be convertible to an integer, additionally the value must be in range\n"
# " # of the repeat start and end dates. Like wise for repeat integer. For repeat\n"
# " # string and enum, the name must either be an integer, that is a valid index or\n"
# " # if it is a string, it must correspond to one of enum's or strings list\n"
def test_client_force(ci, protocol):
print_test(ci, "test_client_force")
ci.delete_all()
defs = create_defs("test_client_force", ci.get_port(), protocol)
path_list = ["/test_client_force/f1/t1", "/test_client_force/f1/t2"]
t1 = path_list[0]
for path in path_list:
task = defs.find_abs_node(path)
assert task is not None, "Expected to find task at path " + path
task.add_event("event")
ci.load(defs)
state_list = [State.unknown, State.active, State.complete, State.queued, State.submitted, State.aborted]
for state in state_list:
ci.force_state(t1, state)
sync_local(ci)
task = ci.get_defs().find_abs_node(t1)
assert task.get_state() == state, "Expected state " + state + " but found " + str(task.get_state())
for state in state_list:
ci.force_state(path_list, state)
sync_local(ci)
for path in path_list:
task = ci.get_defs().find_abs_node(path)
assert task.get_state() == state, "Expected state " + state + " but found " + str(task.get_state())
for state in state_list:
ci.force_state_recursive("/test_client_force", state)
sync_local(ci)
task = ci.get_defs().find_abs_node(t1)
assert task.get_state() == state, "Expected state " + state + " but found " + str(task.get_state())
suite_paths = ["/test_client_force"]
for state in state_list:
ci.force_state_recursive(suite_paths, state)
sync_local(ci)
task = ci.get_defs().find_abs_node(t1)
assert task.get_state() == state, "Expected state " + state + " but found " + str(task.get_state())
event_states = ["set", "clear"]
for ev_state in event_states:
for path in path_list:
ci.force_event(path + ":event", ev_state)
sync_local(ci)
task = ci.get_defs().find_abs_node(path)
event_fnd = False
for event in task.events:
event_fnd = True
if ev_state == "set":
assert event.value() == True, " Expected event value to be set"
else:
assert event.value() == False, " Expected event value to be clear"
assert event_fnd == True, " Expected event to be found"
event_path_list = ["/test_client_force/f1/t1:event", "/test_client_force/f1/t2:event"]
event_states = ["set", "clear"]
for ev_state in event_states:
ci.force_event(event_path_list, ev_state)
sync_local(ci)
for path in path_list:
task = ci.get_defs().find_abs_node(path)
event_fnd = False
for event in task.events:
event_fnd = True
if ev_state == "set":
assert event.value() == True, " Expected event value to be set"
else:
assert event.value() == False, " Expected event value to be clear"
assert event_fnd == True, " Expected event to be found"
def test_client_replace(ci, on_disk, protocol):
print_test(ci, "test_client_replace client_defs on disk = " + str(on_disk))
# Create and load the following defs
# s1
# f1
# t1
# t2
ci.delete_all()
ci.load(create_defs("s1", ci.get_port(), protocol))
# ===============================================================================
# Example of using replace to ADD a *NEW* node hierarchy to an existing suite
# we should end up with:
# s1
# f1
# t1
# t2
# f2
# t1
# t2
test_client_replace_def_file = "test_client_replace_" + str(os.getpid()) + ".def"
client_def = create_defs("s1", ci.get_port(), protocol)
client_def.find_suite("s1").add_family("f2").add_task("t1")
if on_disk:
client_def.save_as_defs(test_client_replace_def_file)
client_def = test_client_replace_def_file
ci.replace("/s1/f2", client_def, True,
False) # True means create parents as needed, False means don't bypass checks/zombies
ci.get_server_defs()
assert len(list(ci.get_defs().suites)) == 1, "Expected 1 suites:\n" + str(ci.get_defs())
assert ci.get_defs().find_abs_node("/s1/f2/t1") is not None, "Expected to find task /s1/f2/t1\n" + str(
ci.get_defs())
# Example of using replace to *REMOVE* node hierarchy to an existing suite, could have used delete
assert ci.get_defs().find_abs_node("/s1/f1/t1") is not None, "Expected to find task /s1/f1/t1\n" + str(
ci.get_defs())
assert ci.get_defs().find_abs_node("/s1/f2/t1") is not None, "Expected to find task /s1/f2/t1\n" + str(
ci.get_defs())
client_def = Defs()
client_def.add_suite("s1") # should only have the suite
if on_disk:
client_def.save_as_defs(test_client_replace_def_file)
client_def = test_client_replace_def_file
ci.replace("/s1", client_def)
ci.get_server_defs()
assert len(list(ci.get_defs().suites)) == 1, "Expected 1 suites:\n" + str(ci.get_defs())
assert ci.get_defs().find_abs_node("/s1/f1/t1") is None, "Expected NOT to find task /s1/f1/t1\n" + str(
ci.get_defs())
assert ci.get_defs().find_abs_node("/s1/f2/t1") is None, "Expected NOT to find task /s1/f2/t1\n" + str(
ci.get_defs())
# ===============================================================================
# Example of using replace to add a *NEW* suite
client_def = Defs();
client_def.add_suite("s2")
if on_disk:
client_def.save_as_defs(test_client_replace_def_file)
client_def = test_client_replace_def_file
ci.replace("/s2", client_def, True,
False) # True means create parents as needed, False means don't bypass checks/zombies
ci.get_server_defs()
assert len(list(ci.get_defs().suites)) == 2, " Expected two suites:\n" + str(ci.get_defs())
# replace added suite s2 with a new s2 which has a task,
# s2 must exist on the client defs
client_def = Defs();
client_def.add_suite("s2").add_task("t1")
if on_disk:
client_def.save_as_defs(test_client_replace_def_file)
client_def = test_client_replace_def_file
ci.replace("/s2", client_def)
ci.get_server_defs()
assert len(list(ci.get_defs().suites)) == 2, " Expected two suites:\n" + str(ci.get_defs())
assert ci.get_defs().find_abs_node("/s2/t1") is not None, "Expected to find task /s2/t1\n" + str(ci.get_defs())
if on_disk:
os.remove(test_client_replace_def_file)
def test_node_replace(ci):
print_test(ci, "test_node_replace")
PrintStyle.set_style(Style.MIGRATE) # show node state
ci.delete_all()
defs = Defs() + (Suite("s1") + Family('f1').add(Task('t1'), Task('t2')))
ci.load(defs)
# We should have 4 nodes
sync_local(ci)
ci_defs = ci.get_defs()
node_vec = ci_defs.get_all_nodes()
assert len(list(node_vec)) == 4, "Expected two 4 nodes: \n" + str(ci.get_defs())
# replace each node, add variable first, then check, it was added
for node in node_vec:
node += Edit(var="XX", var2="xx")
node.replace_on_server(ci) # default is to suspend server node first, so replaced node is also suspended
sync_local(ci)
replace_node = ci.get_defs().find_abs_node(node.get_abs_node_path())
assert len(list(replace_node.variables)) == 2, "Expected two 2 variable: \n" + str(replace_node) + "\n" + str(
ci.get_defs())
assert replace_node.get_dstate() == DState.suspended, "Expected node to be suspended:\n" + str(
replace_node) + "\n" + str(ci.get_defs())
# resume nodes, test that when False passed in we do not suspend the replaced node
for node in node_vec:
ci.resume(node.get_abs_node_path())
sync_local(ci)
replace_node = ci.get_defs().find_abs_node(node.get_abs_node_path())
assert replace_node.get_dstate() != DState.suspended, "Expected node not to suspended:\n" + str(replace_node)
replace_node += Meter("meter", 0, 100)
# cant use node i.e this is only client side, and is still suspended
# When we replace is server the client defs is sent to server. hence node would be suspended
replace_node.replace_on_server(ci, suspend_node_first=False)
sync_local(ci)
replace_node = ci.get_defs().find_abs_node(node.get_abs_node_path())
assert len(list(replace_node.meters)) == 1, "Expected 1 meter: \n" + str(replace_node)
assert len(list(replace_node.variables)) == 2, "Expected two 2 variable: \n" + str(replace_node)
assert replace_node.get_dstate() != DState.suspended, "Expected node not to suspended:\n" + str(replace_node)
# replace the suite
defs = Defs() + Suite("s1")
host_port = ci.get_host() + ':' + ci.get_port()
defs.s1.replace_on_server(ci)
ci.get_server_defs()
assert len(list(ci.get_defs().s1)) == 0, "Expected 0 family: \n" + str(ci.get_defs())
assert ci.get_defs().s1.get_dstate() == DState.suspended, "Expected node to be suspended:\n" + str(ci.get_defs())
def test_client_kill(ci):
pass
def test_client_status(ci):
pass
def test_client_order(ci):
pass
def test_client_group(ci):
pass
def test_client_suspend(ci, protocol):
print_test(ci, "test_client_suspend")
ci.delete_all()
defs = create_defs("test_client_suspend", ci.get_port(), protocol)
suite = defs.find_suite("test_client_suspend")
suite.add_variable("ECF_DUMMY_TASK", "")
ci.load(defs)
ci.begin_all_suites()
ci.suspend("/test_client_suspend")
sync_local(ci);
suite = ci.get_defs().find_suite("test_client_suspend")
assert suite.is_suspended(), "Expected to find suite suspended"
assert ci.query('dstate',
suite.get_abs_node_path()) == "suspended", "Expected to find suite dstate suspended but found: " + res
assert ci.query('state',
suite.get_abs_node_path()) == "queued", "Expected to find suite state queued but found: " + res
def test_client_suspend_multiple_paths(ci, protocol):
print_test(ci, "test_client_suspend_multiple_paths")
ci.delete_all()
defs = create_defs("test_client_suspend_multiple_paths", ci.get_port(), protocol)
suite = defs.find_suite("test_client_suspend_multiple_paths")
suite.add_variable("ECF_DUMMY_TASK", "")
ci.load(defs)
ci.begin_all_suites()
path_list = ["/test_client_suspend_multiple_paths/f1/t1", "/test_client_suspend_multiple_paths/f1/t2"]
ci.suspend(path_list)
sync_local(ci);
task_t1 = ci.get_defs().find_abs_node("/test_client_suspend_multiple_paths/f1/t1")
task_t2 = ci.get_defs().find_abs_node("/test_client_suspend_multiple_paths/f1/t2")
assert task_t1.is_suspended(), "Expected to find task t1 to be suspended"
assert task_t2.is_suspended(), "Expected to find task t2 to be suspended"
def test_client_resume(ci, protocol):
print_test(ci, "test_client_resume")
ci.delete_all()
defs = create_defs("test_client_resume", ci.get_port(), protocol)
suite = defs.find_suite("test_client_resume")
suite.add_variable("ECF_DUMMY_TASK", "")
ci.load(defs)
ci.begin_all_suites()
ci.suspend("/test_client_resume")
sync_local(ci);
suite = ci.get_defs().find_suite("test_client_resume")
assert suite.is_suspended(), "Expected to find suite suspended"
ci.resume("/test_client_resume")
sync_local(ci);
suite = ci.get_defs().find_suite("test_client_resume")
assert suite.is_suspended() == False, "Expected to find suite resumed"
def test_client_resume_multiple_paths(ci, protocol):
print_test(ci, "test_client_resume_multiple_paths")
ci.delete_all()
defs = create_defs("test_client_resume_multiple_paths", ci.get_port(), protocol)
suite = defs.find_suite("test_client_resume_multiple_paths")
suite.add_variable("ECF_DUMMY_TASK", "")
ci.load(defs)
ci.begin_all_suites()
path_list = ["/test_client_resume_multiple_paths/f1/t1", "/test_client_resume_multiple_paths/f1/t2"]
ci.suspend(path_list)
sync_local(ci);
task_t1 = ci.get_defs().find_abs_node("/test_client_resume_multiple_paths/f1/t1")
task_t2 = ci.get_defs().find_abs_node("/test_client_resume_multiple_paths/f1/t2")
assert task_t1.is_suspended(), "Expected to find task t1 to be suspended"
assert task_t2.is_suspended(), "Expected to find task t2 to be suspended"
ci.resume(path_list)
sync_local(ci);
task_t1 = ci.get_defs().find_abs_node("/test_client_resume_multiple_paths/f1/t1")
task_t2 = ci.get_defs().find_abs_node("/test_client_resume_multiple_paths/f1/t2")
assert task_t1.is_suspended() == False, "Expected to find task t1 to be resumed"
assert task_t2.is_suspended() == False, "Expected to find task t2 to be resumed"
def test_client_delete_node(ci, protocol):
print_test(ci, "test_client_delete_node")
ci.delete_all()
defs = create_defs("test_client_delete_node", ci.get_port(), protocol)
task_vec = defs.get_all_tasks();
assert len(task_vec) > 0, "Expected some tasks but found none:\n" + str(defs)
ci.load(defs)
sync_local(ci);
for task in task_vec:
node = ci.get_defs().find_abs_node(task.get_abs_node_path())
assert node is not None, "Expected to find task " + task.get_abs_node_path() + ":\n" + str(ci.get_defs())
for task in task_vec:
ci.delete(task.get_abs_node_path())
sync_local(ci);
for task in task_vec:
node = ci.get_defs().find_abs_node(task.get_abs_node_path())
assert node is None, "Expected not to find task " + task.get_abs_node_path() + " as it should have been deleted:\n" + str(
ci.get_defs())
def test_client_delete_node_multiple_paths(ci, protocol):
print_test(ci, "test_client_delete_node_multiple_paths")
ci.delete_all()
defs = create_defs("test_client_delete_node_multiple_paths", ci.get_port(), protocol)
task_vec = defs.get_all_tasks();
assert len(task_vec) > 0, "Expected some tasks but found none:\n" + str(defs)
paths = []
for task in task_vec:
paths.append(task.get_abs_node_path())
ci.load(defs)
sync_local(ci);
for task in task_vec:
node = ci.get_defs().find_abs_node(task.get_abs_node_path())
assert node is not None, "Expected to find task " + task.get_abs_node_path() + ":\n" + str(ci.get_defs())
ci.delete(paths)
sync_local(ci);
for task in task_vec:
node = ci.get_defs().find_abs_node(task.get_abs_node_path())
assert node is None, "Expected not to find task " + task.get_abs_node_path() + " as it should have been deleted:\n" + str(
ci.get_defs())
def test_client_archive_and_restore(ci, protocol):
suite_name = "test_client_archive_and_restore"
print_test(ci, suite_name)
ci.delete_all()
defs = create_defs(suite_name, ci.get_port(), protocol)
suite = defs.find_suite(suite_name)
suite_path = suite.get_abs_node_path();
ci.restart_server()
ci.load(defs)
sync_local(ci) # get the changes, synced with local defs
node_vec = ci.get_defs().get_all_nodes()
assert len(node_vec) == 4, "Expected 4 nodes, but found " + str(len(node_vec))
ci.archive(suite_path)
sync_local(ci) # get the changes, synced with local defs
node_vec = ci.get_defs().get_all_nodes()
assert len(node_vec) == 1, "Expected 1 nodes, but found " + str(len(node_vec))
the_suite = ci.get_defs().find_suite(suite_name)
assert the_suite is not None, "Expected to find suite"
assert the_suite.get_flag().is_set(FlagType.archived), " expected archive flag to be set"
ci.restore(suite_path)
sync_local(ci) # get the changes, synced with local defs
node_vec = ci.get_defs().get_all_nodes()
assert len(node_vec) == 4, "Expected 4 nodes, but found " + str(len(node_vec))
the_restored_suite = ci.get_defs().find_suite(suite_name)
assert the_restored_suite is not None, "Expected to find suite"
assert the_restored_suite.get_flag().is_set(FlagType.restored), " expected restored flag to be set"
assert not the_restored_suite.get_flag().is_set(FlagType.archived), "expected archive flag to be cleared"
def test_client_check_defstatus(ci, protocol):
print_test(ci, "test_client_check_defstatus")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_client_check_defstatus", port, protocol)
# stop defs form running when begin is called.
suite = defs.find_suite("test_client_check_defstatus")
suite.add_defstatus(DState.suspended)
t1 = "/test_client_check_defstatus/f1/t1"
t2 = "/test_client_check_defstatus/f1/t2"
task_t1 = defs.find_abs_node(t1)
task_t1.add_defstatus(DState.suspended)
defs.generate_scripts();
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.begin_all_suites()
sync_local(ci) # get the changes, synced with local defs
# print(ci.get_defs())
task_t1 = ci.get_defs().find_abs_node(t1)
task_t2 = ci.get_defs().find_abs_node(t2)
assert task_t1 is not None, "Could not find t1"
assert task_t2 is not None, "Could not find t2"
assert task_t1.get_state() == State.queued, "Expected state queued but found " + str(task_t1.get_state())
assert task_t2.get_state() == State.queued, "Expected state queued " + str(task_t2.get_state())
assert task_t1.get_dstate() == DState.suspended, "Expected state suspended but found " + str(task_t1.get_state())
assert task_t2.get_dstate() == DState.queued, "Expected state queued but found " + str(task_t2.get_state())
dir_to_remove = Test.ecf_home(port) + "/" + "test_client_check_defstatus"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_ECFLOW_189(ci, protocol):
# Bug, when a node is resumed it ignored holding dependencies higher up the tree.
# i.e Previously when we resumed a node, it ignored trigger/time/node state, dependencies higher up the tree
print_test(ci, "test_ECFLOW_189")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_ECFLOW_189", port, protocol)
defs.generate_scripts();
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.suspend("/test_ECFLOW_189")
ci.suspend("/test_ECFLOW_189/f1/t1")
ci.suspend("/test_ECFLOW_189/f1/t2")
ci.begin_all_suites()
sync_local(ci) # get the changes, synced with local defs
# print(ci.get_defs())
task_t1 = ci.get_defs().find_abs_node("/test_ECFLOW_189/f1/t1")
task_t2 = ci.get_defs().find_abs_node("/test_ECFLOW_189/f1/t2")
assert task_t1 is not None, "Could not find /test_ECFLOW_189/f1/t1"
assert task_t2 is not None, "Could not find /test_ECFLOW_189/f1/t2"
assert task_t1.get_state() == State.queued, "Expected state queued but found " + str(task_t1.get_state())
assert task_t2.get_state() == State.queued, "Expected state queued but found " + str(task_t2.get_state())
assert task_t1.get_dstate() == DState.suspended, "Expected state suspended but found " + str(task_t1.get_dstate())
assert task_t2.get_dstate() == DState.suspended, "Expected state suspended but found " + str(task_t2.get_dstate())
# ok now resume t1/t2, they should remain queued, since the Suite is still suspended
ci.resume("/test_ECFLOW_189/f1/t1")
ci.resume("/test_ECFLOW_189/f1/t2")
time.sleep(3)
sync_local(ci) # get the changes, synced with local defs
# print(ci.get_defs())
task_t1 = ci.get_defs().find_abs_node("/test_ECFLOW_189/f1/t1")
task_t2 = ci.get_defs().find_abs_node("/test_ECFLOW_189/f1/t2")
assert task_t1.get_state() == State.queued, "Expected state queued but found " + str(task_t1.get_state())
assert task_t2.get_state() == State.queued, "Expected state queued but found " + str(task_t2.get_state())
assert task_t1.get_dstate() == DState.queued, "Expected state queued but found " + str(task_t1.get_dstate())
assert task_t2.get_dstate() == DState.queued, "Expected state queued but found " + str(task_t2.get_dstate())
dir_to_remove = Test.ecf_home(port) + "/" + "test_ECFLOW_189"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_ECFLOW_1761(ci):
print_test(ci, "test_ECFLOW_1761")
print("# get log: last 10 lines")
ci.get_log(10)
ci_defs = ci.get_defs()
task = ci_defs.get_all_nodes()[0] # take first task
# print(ci.edit_script_edit(task.get_abs_node_path())
# print(ci.edit_script_preprocess(task.get_abs_node_path()))
# ci.edit_script_submit(
# task.get_abs_node_path(),
# [], # name-value variables list
# [], # lines (script)
# False, # True, $ alias
# False) # run
def test_ECFLOW_199(ci, protocol):
# Test ClientInvoker::changed_node_paths
print_test(ci, "test_ECFLOW_199")
ci.delete_all()
port = ci.get_port()
defs = create_defs("test_ECFLOW_199", port, protocol)
defs.generate_scripts();
msg = defs.check_job_creation(verbose=True)
assert len(msg) == 0, msg
ci.restart_server()
ci.load(defs)
ci.suspend("/test_ECFLOW_199")
ci.suspend("/test_ECFLOW_199/f1/t1")
ci.suspend("/test_ECFLOW_199/f1/t2")
ci.begin_all_suites()
sync_local(ci) # get the changes, synced with local defs
# print(ci.get_defs())
assert len(list(
ci.changed_node_paths)) == 0, "Expected first call to sync_local, to have no changed paths but found " + str(
len(list(ci.changed_node_paths)))
# ok now resume t1/t2, they should remain queued, since the Suite is still suspended
# Note: ECFLOW-1512, we may get additional paths.( i.e. suite path) due to changes in suite calendar
ci.resume("/test_ECFLOW_199/f1/t1")
sync_local(ci)
found_path = False
for path in ci.changed_node_paths:
print(" changed node path " + path);
if path == "/test_ECFLOW_199/f1/t1":
found_path = True
assert found_path, "Expected '/test_ECFLOW_199/f1/t1' in list of changed paths"
ci.resume("/test_ECFLOW_199/f1/t2")
sync_local(ci)
found_path = False
for path in ci.changed_node_paths:
print(" changed node path " + path);
if path == "/test_ECFLOW_199/f1/t2":
found_path = True
assert found_path, "Expected '/test_ECFLOW_199/f1/t2' in list of changed paths"
dir_to_remove = Test.ecf_home(port) + "/" + "test_ECFLOW_199"
shutil.rmtree(dir_to_remove, ignore_errors=True)
def test_client_ch_with_drops_handles(ci, protocol):
print_test(ci, "test_client_ch_with_drops_handles")
try:
port = ci.get_port()
print(" test using with but without register, handle should be zero, ie do nothing")
with Client("localhost", port) as local_ci:
local_ci.debug(True)
if protocol == Test.Protocol.HTTP:
local_ci.enable_http()
assert local_ci.ch_handle() == 0, "Expected handle to be zero"
local_ci.ch_suites()
print(" Test Client with register, should drop handle ")
with Client("localhost", port) as local_ci:
local_ci.debug(True)
if protocol == Test.Protocol.HTTP:
local_ci.enable_http()
local_ci.ch_register(True, ['s1', 's2'])
# print("Handle:",local_ci .ch_handle())
local_ci.ch_suites()
# raise RuntimeError("xxx") # check exeption is still caught
except RuntimeError as e:
print("Exception", e)
print("after with:")
# really need a way to get hold of the suites, via python api.
ci.ch_suites() # should be empty
def do_tests(ci, protocol):
test_version(ci)
PrintStyle.set_style(Style.STATE) # show node state
test_client_get_server_defs(ci, protocol)
test_client_new_log(ci)
test_client_clear_log(ci)
test_client_log_msg(ci)
test_client_restart_server(ci)
test_client_halt_server(ci)
test_client_shutdown_server(ci)
test_client_load_in_memory_defs(ci, protocol)
test_client_load_from_disk(ci, protocol)
test_client_checkpt(ci, protocol)
test_client_restore_from_checkpt(ci, protocol)
test_client_reload_wl_file(ci)
test_client_run(ci, protocol)
test_client_run_with_multiple_paths(ci, protocol)
test_client_requeue(ci, protocol)
test_client_requeue_with_multiple_paths(ci, protocol)
test_client_free_dep(ci, protocol)
test_client_suites(ci, protocol)
test_client_ch_with_drops_handles(ci, protocol)
test_client_ch_suites(ci)
test_client_ch_register(ci)
test_client_ch_drop(ci)
test_client_ch_drop_user(ci)
test_client_ch_add(ci)
test_client_ch_auto_add(ci)
test_client_ch_remove(ci)
test_client_get_file(ci)
# test_client_plug(ci)
test_client_alter_sort(ci, protocol)
test_client_alter_sort_defs(ci, protocol)
test_client_alter_add(ci, protocol)
test_client_alter_delete(ci, protocol)
test_client_alter_change(ci, protocol)
test_client_alter_flag(ci, protocol)
test_client_force(ci, protocol)
test_client_replace(ci, False, protocol)
test_client_replace(ci, True, protocol)
test_node_replace(ci)
# test_client_kill(ci)
# test_client_status(ci)
# test_client_order(ci)
# test_client_group(ci)
test_client_suspend(ci, protocol)
test_client_suspend_multiple_paths(ci, protocol)
test_client_resume(ci, protocol)
test_client_resume_multiple_paths(ci, protocol)
test_client_delete_node(ci, protocol)
test_client_delete_node_multiple_paths(ci, protocol)
test_client_archive_and_restore(ci, protocol)
test_client_check(ci)
test_client_check_defstatus(ci, protocol)
test_client_stats(ci)
test_client_stats_with_stdout(ci)
test_client_stats_without_stdout(ci)
test_client_stats_reset(ci)
test_client_debug_server_on_off(ci)
test_ECFLOW_189(ci, protocol)
test_ECFLOW_199(ci, protocol)
test_ECFLOW_1761(ci)
def launch_tests(ci, protocol):
server_version = ci.server_version()
print("Running ecflow server version " + server_version)
print("Running ecflow client version " + ci.version())
assert ci.version() == server_version, " Client version not same as server version"
# test with sync_local
do_tests(ci, protocol)
# test with auto sync
ci.set_auto_sync(True)
do_tests(ci, protocol)
print("All Tests pass ======================================================================")
if __name__ == "__main__":
Test.print_test_start(os.path.basename(__file__))
# server independent tests
test_set_host_port();
# Run tests using ecFlow server (using custom TCP/IP protocol)
with Test.Server(Test.Protocol.CUSTOM) as ctx:
ci = ctx[0]
protocol = ctx[1]
launch_tests(ci, protocol)
# Run tests using ecFlow server (using HTTP protocol)
with Test.Server(Test.Protocol.HTTP) as ctx:
ci = ctx[0]
protocol = ctx[1]
launch_tests(ci, protocol)
|