1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
|
#!/bin/sh
# Copyright (C) 2014-2024 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# shellcheck disable=SC2154
# SC2154: ... is referenced but not assigned.
# Reason: some variables are sourced.
# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu
# Include common test library.
# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
# Include admin utilities
# shellcheck source=src/bin/admin/admin-utils.sh.in
. "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
# Set path to the production schema scripts
db_scripts_dir="@abs_top_srcdir@/src/share/database/scripts"
# Set location of the kea-admin.
kea_admin="@abs_top_builddir@/src/bin/admin/kea-admin"
# Convenience function for running an SQL statement
# param hdr - text message to prepend to any error
# param qry - SQL statement to run
# param exp_value - optional expected value. This can be used IF the SQL statement
# generates a single value, such as a SELECT which returns one column for one row.
# Examples:
#
# qry="insert into lease6 (address, lease_type, subnet_id, state) values ($addr,$ltype,1,0)"
# run_statement "#2" "$qry"
#
# qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0"
# run_statement "#3" "$qry" 1
run_statement() {
hdr="$1";shift
qry="$1";shift
exp_value="${1-}" # Optional value. If not given, replace with empty string.
# Execute the statement
run_command \
mysql_execute "${qry}"
# shellcheck disable=SC2153
# SC2153: Possible misspelling: ... may not be assigned, but ... is.
# Reason for disable: OUTPUT is assigned in run_command.
value="${OUTPUT}"
# Execution should succeed
assert_eq 0 "${EXIT_CODE}" "$hdr: SQL=[$qry] failed: (expected status code %d, returned %d)"
# If there's an expected value, test it
if [ "x$exp_value" != "x" ]
then
assert_str_eq "$exp_value" "$value" "$hdr: SQL=[$qry] wrong: (expected value %s, returned %s)"
fi
}
# Wipe all tables from the DB:
mysql_wipe() {
printf "Wiping whole database %s...\n" "${db_name}"
run_command \
mysql_execute_script "${db_scripts_dir}/mysql/dhcpdb_drop.mysql"
assert_eq 0 "${EXIT_CODE}" "mysql-wipe: drop table sql failed, expected %d, returned %d"
}
# Checks that a column in a table exists.
# param column name of the column to check
# param table name of table containing the column
check_table_column() {
column=$1;shift
table=$1;shift
qry="select $column from $table limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
}
mysql_db_init_test() {
test_start "mysql.db-init"
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql failed, expected %d, returned non-zero status code %d"
# Ok, now let's check if the tables are indeed there.
# First table: schema_version. Should have 2 columns: version and minor.
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT version, minor FROM schema_version'
assert_eq 0 "${EXIT_CODE}" "schema_version table is missing or broken. (expected status code %d, returned %d)"
# Second table: lease4
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname FROM lease4'
assert_eq 0 "${EXIT_CODE}" "lease4 table is missing or broken. (expected status code %d, returned %d)"
# Third table: lease6
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, hwaddr_source FROM lease6'
assert_eq 0 "${EXIT_CODE}" "lease6 table is missing or broken. (expected status code %d, returned %d)"
# Fourth table: lease6_types
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT lease_type, name FROM lease6_types'
assert_eq 0 "${EXIT_CODE}" "lease6_types table is missing or broken. (expected status code %d, returned %d)"
# Fifth table: lease_hwaddr_source
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT hwaddr_source, name FROM lease_hwaddr_source'
assert_eq 0 "${EXIT_CODE}" "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
mysql_db_version_test() {
test_start "mysql.db-version"
# Let's wipe the whole database
mysql_wipe
# Do not create any table so db-version will raise an error
printf 'Checking db-version error case...\n'
run_command \
"${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
assert_eq 1 "${EXIT_CODE}" "schema_version table still exists. (expected %d, exit code %d)"
# Ok, now let's create a version 1.7
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'CREATE TABLE schema_version (
version INT PRIMARY KEY NOT NULL,
minor INT
);
INSERT INTO schema_version VALUES (1, 7)'
assert_eq 0 "${EXIT_CODE}" "schema_version table cannot be created. (expected %d, exit code %d)"
run_command \
"${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
version="${OUTPUT}"
assert_str_eq "1.7" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
mysql_db_version_with_extra_test() {
test_start "mysql.db-version_with_extra"
# Let's wipe the whole database
mysql_wipe
# Do not create any table so db-version will raise an error
printf 'Checking db-version error case...\n'
run_command \
"${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
assert_eq 1 "${EXIT_CODE}" "schema_version table still exists. (expected %d, exit code %d)"
# Ok, now let's create a version 1.7
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'CREATE TABLE schema_version (
version INT PRIMARY KEY NOT NULL,
minor INT
);
INSERT INTO schema_version VALUES (1, 7)'
assert_eq 0 "${EXIT_CODE}" "schema_version table cannot be created. (expected %d, exit code %d)"
# Single -x.
run_command \
"${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -x --protocol=TCP
version="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "kea-admin -x failed. (expected %d, exit code %d)"
assert_str_eq "1.7" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Multiple -x.
run_command \
"${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" \
-x --protocol=TCP -x --hello 2> "@abs_top_builddir@/src/bin/admin/test-data"
assert_eq 2 "${EXIT_CODE}" "kea-admin -x -x succeeded. (expected %d, exit code %d)"
if ! grep -F "unknown option '--hello'" "@abs_top_builddir@/src/bin/admin/test-data"; then
printf 'second parameter --hello was not passed to mysql with -x\n'
test_finish 1
fi
rm -f "@abs_top_builddir@/src/bin/admin/test-data"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
mysql_host_reservation_init_test() {
test_start "mysql.host_reservation-init"
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql failed, expected %d, returned non-zero status code %d"
# Ok, now let's check if the tables are indeed there.
# First table: schema_version. Should have 2 columns: version and minor.
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT version, minor FROM schema_version'
assert_eq 0 "${EXIT_CODE}" "schema_version table is missing or broken. (expected status code %d, returned %d)"
# Second table: hosts
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key FROM hosts'
assert_eq 0 "${EXIT_CODE}" "hosts table is missing or broken. (expected status code %d, returned %d)"
# Third table: ipv6_reservations
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations'
assert_eq 0 "${EXIT_CODE}" "ipv6_reservations table is missing or broken. (expected status code %d, returned %d)"
# Fourth table: dhcp4_options
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id, scope_id FROM dhcp4_options'
assert_eq 0 "${EXIT_CODE}" "dhcp4_options table is missing or broken. (expected status code %d, returned %d)"
# Fifth table: dhcp6_options
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id, scope_id FROM dhcp6_options'
assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)"
# Sixth table: host_identifier_type
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT type, name FROM host_identifier_type'
assert_eq 0 "${EXIT_CODE}" "host_identifier_type table is missing or broken. (expected status code %d, returned %d)"
# Seventh table: dhcp_option_scope
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT scope_id, scope_name FROM dhcp_option_scope'
assert_eq 0 "${EXIT_CODE}" "dhcp_option_scope table is missing or broken. (expected status code %d, returned %d)"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Upgrades an existing schema to a target newer version
# param target_version - desired schema version as "major.minor"
mysql_upgrade_schema_to_version() {
target_version=$1
upgrade_scripts_dir=${db_scripts_dir}/mysql
# Check if the scripts directory exists at all.
if [ ! -d ${upgrade_scripts_dir} ]; then
log_error "Invalid scripts directory: ${upgrade_scripts_dir}"
exit 1
fi
# Check if there are any files in it
num_files=$(find ${upgrade_scripts_dir} -name 'upgrade*.sh' -type f | wc -l)
if [ "${num_files}" -eq 0 ]; then
upgrade_scripts_dir=@abs_top_builddir@/src/share/database/scripts/mysql
# Check if the scripts directory exists at all.
if [ ! -d ${upgrade_scripts_dir} ]; then
log_error "Invalid scripts directory: ${upgrade_scripts_dir}"
exit 1
fi
# Check if there are any files in it
num_files=$(find "${upgrade_scripts_dir}" -name 'upgrade*.sh' -type f | wc -l)
fi
if [ "${num_files}" -eq 0 ]; then
log_error "No scripts in ${upgrade_scripts_dir}?"
exit 1
fi
for script in "${upgrade_scripts_dir}"/upgrade*.sh
do
version=$(mysql_version)
if [ "${version}" = "${target_version}" ]
then
break
fi
echo "Processing $script file..."
"${script}" --user="${db_user}" --password="${db_password}" "${db_name}"
done
echo "Schema upgraded to $version"
}
mysql_upgrade_12_to_13_test() {
# Check the output of colonSeparatedHex().
run_command \
mysql_execute 'SELECT colonSeparatedHex(HEX(0xF123456789))'
assert_eq 0 "${EXIT_CODE}" 'colonSeparatedHex() failed, expected exit code %d, actual %d'
assert_str_eq 'f1:23:45:67:89' "${OUTPUT}"
run_command \
mysql_execute 'SELECT colonSeparatedHex("")'
assert_eq 0 "${EXIT_CODE}" 'colonSeparatedHex() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
run_command \
mysql_execute 'SELECT colonSeparatedHex(HEX(0xF))'
assert_eq 0 "${EXIT_CODE}" 'colonSeparatedHex() failed, expected exit code %d, actual %d'
assert_str_eq '0f' "${OUTPUT}"
run_command \
mysql_execute 'SELECT colonSeparatedHex(HEX(0xF1))'
assert_eq 0 "${EXIT_CODE}" 'colonSeparatedHex() failed, expected exit code %d, actual %d'
assert_str_eq 'f1' "${OUTPUT}"
run_command \
mysql_execute 'SELECT colonSeparatedHex(HEX(0xF12))'
assert_eq 0 "${EXIT_CODE}" 'colonSeparatedHex() failed, expected exit code %d, actual %d'
assert_str_eq '0f:12' "${OUTPUT}"
run_command \
mysql_execute 'SELECT colonSeparatedHex(HEX(458753))'
assert_eq 0 "${EXIT_CODE}" 'colonSeparatedHex() failed, expected exit code %d, actual %d'
assert_str_eq '07:00:01' "${OUTPUT}"
# Check lease4Dump*().
run_command \
mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,(SELECT FROM_UNIXTIME(1678900000)),50,1,1,'one,example,com',0,'{ \"a\": 1, \"b\": 2 }',NULL,NULL,0)"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease4 failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
run_command \
mysql_execute "CALL lease4DumpHeader()"
assert_eq 0 "${EXIT_CODE}" 'lease4DumpHeader() failed, expected exit code %d, actual %d'
assert_str_eq 'address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id' "${OUTPUT}"
run_command \
mysql_execute "CALL lease4DumpData()"
assert_eq 0 "${EXIT_CODE}" 'lease4DumpData() failed, expected exit code %d, actual %d'
output=$(printf '%s' "${OUTPUT}" | sed 's/\t/,/g') # turn tabs into commas
assert_str_eq '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,oneˎxampleˌom,0,{ "a": 1, "b": 2 },0' "${output}"
# Check lease6Dump*().
run_command \
mysql_execute "INSERT INTO lease6 VALUES(inet6_aton('::10'),20,30,(SELECT FROM_UNIXTIME(1678900000)),40,50,1,60,70,1,1,'one,example,com',80,90,16,0,'{ \"a\": 1, \"b\": 2 }',0)"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease6 failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
run_command \
mysql_execute "CALL lease6DumpHeader()"
assert_eq 0 "${EXIT_CODE}" 'lease6DumpHeader() failed, expected exit code %d, actual %d'
assert_str_eq 'address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id' "${OUTPUT}"
run_command \
mysql_execute "CALL lease6DumpData()"
assert_eq 0 "${EXIT_CODE}" 'lease6DumpData() failed, expected exit code %d, actual %d'
output=$(printf '%s' "${OUTPUT}" | sed 's/\t/,/g') # turn tabs into commas
assert_str_eq '::10,32:30,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{ "a": 1, "b": 2 },90,16,0' "${output}"
# Check lease4Upload().
run_command \
mysql_execute "CALL lease4Upload('192.0.0.0','ff0102030405','01ff0102030405',7200,1234567890,1,0,0,'',0,'',0)"
assert_eq 0 "${EXIT_CODE}" 'lease4Upload() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
# Check lease6Upload().
run_command \
mysql_execute "CALL lease6Upload('2001:db8::','000100012955cb80ff0102030407',7200,1234567890,1,3600,0,1,128,0,0,'','ff0102030407',0,'',90,16,0)"
assert_eq 0 "${EXIT_CODE}" 'lease6Upload() failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}"
}
mysql_upgrade_13_to_14_test() {
# Check function source code
run_command \
mysql_execute "select action_statement from information_schema.TRIGGERS where trigger_schema = '${db_name}' and trigger_name = 'dhcp4_shared_network_BDEL'"
assert_eq 0 "${EXIT_CODE}" "function func_dhcp4_shared_network_BDEL() broken or missing. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Eci 'UPDATE dhcp4_subnet SET shared_network_name = NULL') || true
assert_eq 1 "${count}" "function func_dhcp4_shared_network_BDEL() is missing changed line. (expected count %d, returned %d)"
# Check function source code
run_command \
mysql_execute "select action_statement from information_schema.TRIGGERS where trigger_schema = '${db_name}' and trigger_name = 'dhcp6_shared_network_BDEL'"
assert_eq 0 "${EXIT_CODE}" "function func_dhcp6_shared_network_BDEL() broken or missing. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Eci 'UPDATE dhcp6_subnet SET shared_network_name = NULL') || true
assert_eq 1 "${count}" "function func_dhcp6_shared_network_BDEL() is missing changed line. (expected count %d, returned %d)"
# user_context should have been added to dhcp4_client_class
qry="select user_context from dhcp4_client_class limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# user_context should have been added to dhcp6_client_class
qry="select user_context from dhcp6_client_class limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# -- lease counting tests --
# Check that @json_supported is NULL by default.
query="SELECT @json_supported"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "NULL" "${OUTPUT}" "${query}: expected output %s, returned %s"
# Clean up.
query="DELETE FROM lease4; DELETE FROM lease6"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "" "${OUTPUT}" "${query}: expected output %s, returned %s"
# Populate the lease tables. Also check that @json_supported is NULL at
# first, and then it is set after inserting leases.
run_command \
mysql_execute "
SELECT @json_supported;
INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (100,1,0,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
SELECT @json_supported;
INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (101,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (102,1,2,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (103,1,0,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (104,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (105,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (100,0,1,0,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (101,0,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (102,0,1,0,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (103,0,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (104,2,1,0,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (105,2,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (106,2,1,0,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (107,2,1,1,
'{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }');
SELECT @json_supported;
"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO leases when upgrading from 13 to 14 failed. expected %d, returned %d'
one_line=$(printf '%s' "${OUTPUT}" | tr '\n' ' ')
json_supported=$(printf '%s' "${one_line}" | grep -Eo '[0-1]$') || true
if test "${json_supported}" != 0 && test "${json_supported}" != 1; then
assert_str_eq '[01]' "${json_supported}" "INSERT INTO leases when upgrading from 13 to 14 does not set @json_supported. expected '[01]', returned '${json_supported}'"
fi
if ! printf '%s' "${one_line}" | grep -E "NULL ${json_supported} ${json_supported}" > /dev/null; then
assert_str_eq 'NULL [01] [01]' "${one_line}" "INSERT INTO leases when upgrading from 13 to 14 does not set @json_supported. expected 'NULL [01] [01]', returned '${one_line}'"
fi
for v in 4 6; do
# Check that client classes were counted correctly.
query="SELECT leases FROM lease${v}_stat_by_client_class WHERE client_class = 'foo' LIMIT 1"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
if test "${json_supported}" = 1; then
assert_str_eq 2 "${OUTPUT}" "${query}: expected output %s, returned %s"
else
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
# -- Verify some calls to checkLeaseXLimits(). --
query="SELECT checkLease${v}Limits('')"
run_command \
mysql_execute "${query}"
# Should fail with ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract'
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
query="SELECT checkLease${v}Limits('{}')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
fi
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 1 } ] } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 1 for client class \"foo\", current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"subnet\": { \"id\": 1, \"address-limit\": 1 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 1 for subnet ID 1, current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 2 } ] } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 2 for client class \"foo\", current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"subnet\": { \"id\": 1, \"address-limit\": 2 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 2 for subnet ID 1, current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 4 } ] } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
fi
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"subnet\": { \"id\": 1, \"address-limit\": 4 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
fi
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 1 }, { \"name\": \"bar\", \"address-limit\": 1 } ], \"subnet\": { \"id\": 1, \"address-limit\": 1 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 1 for client class \"foo\", current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 2 }, { \"name\": \"bar\", \"address-limit\": 4 } ], \"subnet\": { \"id\": 1, \"address-limit\": 4 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 2 for client class \"foo\", current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 4 }, { \"name\": \"bar\", \"address-limit\": 4 } ], \"subnet\": { \"id\": 1, \"address-limit\": 2 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq "address limit 2 for subnet ID 1, current lease count 2" "${OUTPUT}" "${query}: expected output %s, returned %s"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 4 }, { \"name\": \"bar\", \"address-limit\": 4 } ], \"subnet\": { \"id\": 1, \"address-limit\": 4 } } } }')"
run_command \
mysql_execute "${query}"
if test "${json_supported}" = 1; then
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
else
# Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist
assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d"
fi
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
done
# Check that leases counters cannot go negative.
for v in 4 6; do
query="SELECT leases FROM lease${v}_stat WHERE subnet_id = 1 AND state = 0 LIMIT 1"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '2' "${OUTPUT}" "${query}: expected output %s, returned %s"
# Artificially change the subnet counter from 2 down to 1.
query="UPDATE lease${v}_stat SET leases = 1 WHERE subnet_id = 1 AND state = 0"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
if test "${json_supported}" = 1; then
query="SELECT leases FROM lease${v}_stat_by_client_class WHERE client_class = 'foo' LIMIT 1"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '2' "${OUTPUT}" "${query}: expected output %s, returned %s"
# Artificially change the client class counter from 2 down to 1.
query="UPDATE lease${v}_stat_by_client_class SET leases = 1 WHERE client_class = 'foo'"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
# Clean up.
query="DELETE FROM lease${v}"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s"
# SELECT should finish successfully and the subnet counter should be 0.
query="SELECT leases FROM lease${v}_stat WHERE subnet_id = 1 AND state = 0 LIMIT 1"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '0' "${OUTPUT}" "${query}: expected output %s, returned %s"
if test "${json_supported}" = 1; then
# SELECT should finish successfully and the client class counter should be 0.
query="SELECT leases FROM lease${v}_stat_by_client_class WHERE client_class = 'foo' LIMIT 1"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '0' "${OUTPUT}" "${query}: expected output %s, returned %s"
fi
done
}
mysql_upgrade_14_to_15_test() {
# table: dhcp4_options new cancelled column.
qry="select cancelled from dhcp4_options"
run_statement "dhcp4_options" "$qry"
# table: dhcp6_options new cancelled column.
qry="select cancelled from dhcp6_options"
run_statement "dhcp6_options" "$qry"
# Check if offer_lifetime was added to dhcp4_shared_network table.
qry="SELECT offer_lifetime from dhcp4_shared_network limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if offer_lifetime was added to dhcp4_subnet table.
qry="SELECT offer_lifetime from dhcp4_subnet limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if offer_lifetime was added to dhcp4_client_class table.
qry="SELECT offer_lifetime from dhcp4_client_class limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
}
mysql_upgrade_16_to_17_test() {
# Check if allocator was added to dhcp4_shared_network table.
qry="SELECT allocator from dhcp4_shared_network limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if allocator was added to dhcp6_shared_network table.
qry="SELECT allocator from dhcp6_shared_network limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if pd_allocator was added to dhcp6_shared_network table.
qry="SELECT pd_allocator from dhcp6_shared_network limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if allocator was added to dhcp4_subnet table.
qry="SELECT allocator from dhcp4_subnet limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if allocator was added to dhcp6_subnet table.
qry="SELECT allocator from dhcp6_subnet limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# Check if pd_allocator was added to dhcp6_subnet table.
qry="SELECT pd_allocator from dhcp6_subnet limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
}
mysql_upgrade_17_to_18_test() {
# lease4 client_id should support 255 long strings.
qry="insert into lease4 (address, client_id, subnet_id) values (1, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 1)"
run_statement "lease4_255_long_client_id" "$qry"
# lease4 relay_id should support 255 long strings.
qry="insert into lease4 (address, remote_id, subnet_id) values (2, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 1)"
run_statement "lease4_255_long_relay_id" "$qry"
# lease4 remote_id should support 255 long strings.
qry="insert into lease4 (address, remote_id, subnet_id) values (3, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 1)"
run_statement "lease4_255_long_remote_id" "$qry"
# hosts dhcp_identifier should support 255 long strings.
qry="insert into hosts (dhcp_identifier, dhcp_identifier_type) values ('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 0)"
run_statement "hosts_255_long_dhcp_identifier" "$qry"
#lease6 duid should support 130 long strings.
qry="insert into lease6 values(inet6_aton('::10'),12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,0)"
run_statement "lease6_130_long_duid" "$qry"
#lease4_pool_stat new table.
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT subnet_id, pool_id, state, leases FROM lease4_pool_stat'
assert_eq 0 "${EXIT_CODE}" "lease4_pool_stat table is missing or broken. (expected status code %d, returned %d)"
#lease6_pool_stat new table.
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT subnet_id, pool_id, lease_type, state, leases FROM lease6_pool_stat'
assert_eq 0 "${EXIT_CODE}" "lease6_pool_stat table is missing or broken. (expected status code %d, returned %d)"
#lease6_relay_id new table.
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT extended_info_id, relay_id, lease_addr FROM lease6_relay_id'
assert_eq 0 "${EXIT_CODE}" "lease6_relay_id table is missing or broken. (expected status code %d, returned %d)"
#lease6_remote_id new table.
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT extended_info_id, remote_id, lease_addr FROM lease6_remote_id'
assert_eq 0 "${EXIT_CODE}" "lease6_remote_id table is missing or broken. (expected status code %d, returned %d)"
}
mysql_upgrade_18_to_19_test() {
# Verify that lease6 address is binary. This is sort of overkill as many of
# the prior upgrade tests manipulate lease6 records.
qry="insert into lease6 values(inet6_aton('3001::99'),'18219',30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,0)"
run_statement "lease6_insert" "$qry"
qry="select inet6_ntoa(address) from lease6 where duid = '18219';"
run_statement "lease6_insert" "$qry" "3001::99"
# Verify that ipv6_reservations address is binary.
qry="\
insert into hosts(host_id, dhcp_identifier, dhcp_identifier_type) values (18219, '18219', 1); \
insert into ipv6_reservations (address, prefix_len, type, dhcp6_iaid, host_id) \
values (inet6_aton('3001::99'), 128, 1, 123, 18219); \
select inet6_ntoa(address) from ipv6_reservations where host_id = 18219;"
run_statement "ipv6_reservations_insert" "$qry" "3001::99"
}
mysql_upgrade_22_to_23_test() {
qry="SELECT name FROM lease_state WHERE state = 3"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}: expected %d, returned %d"
assert_str_eq 'released' "${OUTPUT}" "${qry}: expected output %s, returned %s"
}
mysql_upgrade_23_to_24_test() {
query="SELECT COUNT(id) FROM option_def_data_type"
run_command \
mysql_execute "${query}"
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
assert_str_eq '18' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 0"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'empty' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'binary' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 2"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'boolean' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 4"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'int16' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 5"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'int32' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 6"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'uint8' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 7"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'uint16' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 8"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'uint32' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 10"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'ipv4-address' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 11"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'ipv6-address' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 12"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'ipv6-prefix' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 13"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'psid' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 14"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'string' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 15"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'tuple' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 16"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'fqdn' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 17"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'internal' "${OUTPUT}" "${query}: expected output %s, returned %s"
qry="select name from option_def_data_type where id = 254"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
assert_str_eq 'record' "${OUTPUT}" "${query}: expected output %s, returned %s"
}
mysql_upgrade_24_to_25_test() {
# excluded_prefix should have been added to ipv6_reservations
qry="select excluded_prefix from ipv6_reservations limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# excluded_prefix_len should have been added to ipv6_reservations
qry="select excluded_prefix_len from ipv6_reservations limit 1"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
}
mysql_upgrade_25_to_26_test() {
# client_classes been added to dhcp4_options
check_table_column client_classes dhcp4_options
# client_classes been added to dhcp6_options
check_table_column client_classes dhcp6_options
# check rename of require_client_classes to evaluate_additional_classes.
check_table_column evaluate_additional_classes dhcp4_shared_network
check_table_column evaluate_additional_classes dhcp4_subnet
check_table_column evaluate_additional_classes dhcp4_pool
check_table_column evaluate_additional_classes dhcp6_shared_network
check_table_column evaluate_additional_classes dhcp6_subnet
check_table_column evaluate_additional_classes dhcp6_pool
check_table_column evaluate_additional_classes dhcp6_pd_pool
# check rename of only_if_required to only_in_additional_list.
check_table_column only_in_additional_list dhcp4_client_class
check_table_column only_in_additional_list dhcp6_client_class
}
mysql_upgrade_26_to_27_test() {
# check client_class has become client_classes.
check_table_column client_classes dhcp4_shared_network
check_table_column client_classes dhcp4_subnet
check_table_column client_classes dhcp4_pool
check_table_column client_classes dhcp6_shared_network
check_table_column client_classes dhcp6_subnet
check_table_column client_classes dhcp6_pool
check_table_column client_classes dhcp6_pd_pool
}
mysql_upgrade_test() {
test_start "mysql.upgrade"
# Let's wipe the whole database
mysql_wipe
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Sanity check - verify that it reports version 1.0.
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "1.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "kea-admin db-upgrade mysql failed, expected %d, returned non-zero status code %d\n"
# Verify that the upgraded schema reports the latest version.
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "27.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's check that the new tables are indeed there.
#table: lease6 (upgrade 1.0 -> 2.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT hwaddr, hwtype, hwaddr_source FROM lease6'
assert_eq 0 "${EXIT_CODE}" "lease6 table not upgraded to 2.0 (expected status code %d, returned %d)"
#table: lease_hwaddr_source (upgrade 1.0 -> 2.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT hwaddr_source, name FROM lease_hwaddr_source'
assert_eq 0 "${EXIT_CODE}" "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)"
#table: hosts (upgrade 2.0 -> 3.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes FROM hosts'
assert_eq 0 "${EXIT_CODE}" "hosts table is missing or broken. (expected status code %d, returned %d)"
#table: ipv6_reservations (upgrade 2.0 -> 3.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations'
assert_eq 0 "${EXIT_CODE}" "ipv6_reservations table is missing or broken. (expected status code %d, returned %d)"
#table: dhcp4_options (upgrade 2.0 -> 3.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id FROM dhcp4_options'
assert_eq 0 "${EXIT_CODE}" "dhcp4_options table is missing or broken. (expected status code %d, returned %d)"
#table: dhcp6_options (upgrade 2.0 -> 3.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id FROM dhcp6_options'
assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)"
#table: lease_state table added (upgrade 3.0 -> 4.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT state,name from lease_state'
assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)"
#table: state column added to lease4 (upgrade 3.0 -> 4.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT state from lease4'
assert_eq 0 "${EXIT_CODE}" "lease4 is missing state column. (expected status code %d, returned %d)"
#table: state column added to lease6 (upgrade 3.0 -> 4.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT state from lease6'
assert_eq 0 "${EXIT_CODE}" "lease6 is missing state column. (expected status code %d, returned %d)"
#table: stored procedures for lease dumps added (upgrade 3.0 -> 4.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'call lease4DumpHeader(); call lease4DumpData(); call lease6DumpHeader(); call lease6DumpHeader()'
assert_eq 0 "${EXIT_CODE}" "lease dump stored procedures are missing or broken. (expected status code %d, returned %d)"
#lease_hardware_source should have row for source = 0 (upgrade 4.0 -> 4.1)
qry="select count(hwaddr_source) from lease_hwaddr_source where hwaddr_source = 0 and name='HWADDR_SOURCE_UNKNOWN'"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select from lease_hwaddr_source failed. (expected status code %d, returned %d)"
assert_eq 1 "${count}" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)"
# table: stored procedures for lease data dumps were modified (upgrade 4.0 -> 4.1)
# verify lease4DumpData has order by lease address
qry="show create procedure lease4DumpData"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "procedure text fetch for lease4DumpData failed. (returned status code %d, expected %d)"
count=$(echo "${OUTPUT}" | grep -Eci 'order by [a-z]*[\.]?address') || true
assert_eq 1 "${count}" "lease4DumpData is missing order by clause. (expected count %d, returned %d)"
# verify lease6DumpData has order by lease address
qry="show create procedure lease6DumpData"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "procedure text fetch for lease6DumpData failed. (returned status code %d, expected %d)"
count=$(echo "${OUTPUT}" | grep -Eci 'order by [a-z]*[\.]?address') || true
assert_eq 1 "${count}" "lease6DumpData doesn't have order by clause. (returned count %d, expected %d)"
#table: host_identifier_type (upgrade 4.1 -> 5.0)
# verify that host_identifier_type table exists.
qry="select count(*) from host_identifier_type"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select from host_identifier_type failed. (expected status code %d, returned %d)"
assert_eq 5 "${count}" "host_identifier_type does not contain correct number of entries. (expected count %d, returned %d)"
# verify that foreign key fk_host_identifier_type exists
qry="show create table hosts"
run_command \
mysql_execute "${qry}"
count=$(echo "${OUTPUT}" | grep -Fci -m 1 'fk_host_identifier_type') || true
assert_eq 0 "${EXIT_CODE}" "show create table hosts failed. (expected status code %d, returned %d)"
assert_eq 1 "${count}" "show create table hosts did not return correct number of fk_host_identifier_type instances. (expected %d, returned %d)"
#table: dhcp_option_scope (upgrade 4.1 -> 5.0)
# verify that dhcp_option_scope table exists.
qry="select count(*) from dhcp_option_scope"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select from dhcp_option_scope failed. (expected status code %d, returned %d)"
# verify that dhcp_option_scope table contains correct number of entries.
assert_eq 7 "${count}" "dhcp_option_scope does not contain correct number of entries. (expected %d, returned %d)"
#table: scope_id columns to dhcp4_options (upgrade 4.1 -> 5.0)
# verify that dhcp4_options table includes scope_id
qry="select scope_id from dhcp4_options"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select scope_id from dhcp4_options failed. (expected status code %d, returned %d)"
#table: scope_id columns to dhcp6_options (upgrade 4.1 -> 5.0)
# verify that dhcp6_options table includes scope_id
qry="select scope_id from dhcp6_options"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select scope_id from dhcp6_options failed. (expected status code %d, returned %d)"
#table: DHCPv4 fixed field columns (upgrade 4.1 -> 5.0)
# verify that hosts table has columns holding values for DHCPv4 fixed fields
qry="select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key from hosts"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key failed. (expected status code %d, returned %d)"
# verify that dhcp4_subnet_id is unsigned
qry="show columns from hosts like 'dhcp4_subnet_id'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show columns from hosts like 'dhcp4_subnet_id' failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci unsigned) || true
assert_eq 1 "${count}" "dhcp4_subnet_id is not of unsigned type. (returned count %d, expected %d)"
# verify that dhcp6_subnet_id is unsigned
qry="show columns from hosts like 'dhcp6_subnet_id'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show columns from hosts like 'dhcp6_subnet_id' failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci unsigned) || true
assert_eq 1 "${count}" "dhcp6_subnet_id is not of unsigned type. (expected count %d, returned %d)"
#host_identifier_type should have rows for types 3 and 4 (upgrade 5.0 -> 5.1)
qry="select count(*) from host_identifier_type"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select from host_identifier_type failed. (expected status code %d, returned %d)"
assert_eq 5 "${count}" "host_identifier_type does not contain correct number of entries. (expected count %d, returned %d)"
#table: user_context columns to hosts, dhcp4_options and dhcp6_options (upgrade 5.2 -> 6.0)
# verify that hosts table includes user_context
qry="select user_context from hosts"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select user_context from hosts failed. (expected status code %d, returned %d)"
# verify that dhcp4_options table includes user_context
qry="select user_context from dhcp4_options"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select user_context from dhcp4_options failed. (expected status code %d, returned %d)"
# verify that dhcp6_options table includes user_context
qry="select user_context from dhcp6_options"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select user_context from dhcp6_options failed. (expected status code %d, returned %d)"
# lease4/6_stats changes are tested separately
#table: user_context to lease4 and lease6 (upgrade 6.0 -> 7.0)
# verify that lease4 table includes user_context
qry="select user_context from lease4"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select user_context from lease4 failed. (expected status code %d, returned %d)"
# verify that lease6 table includes user_context
qry="select user_context from lease6"
run_command \
mysql_execute "${qry}"
count="${OUTPUT}"
assert_eq 0 "${EXIT_CODE}" "select user_context from lease6 failed. (expected status code %d, returned %d)"
#table: logs (upgrade 6.0 -> 7.0)
run_command \
mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
'SELECT timestamp, address, log FROM logs'
assert_eq 0 "${EXIT_CODE}" "logs table is missing or broken. (expected status code %d, returned %d)"
# table: modification (upgrade 6.0 -> 7.0)
qry="select id, modification_type from modification"
run_statement "modification" "$qry"
# table: modification table should have 3 entries (upgrade 6.0 -> 7.0)
qry="select count(*) from modification"
run_statement "modification count" "$qry" 3
# table: dhcp4_server
qry="select id, tag, description, modification_ts from dhcp4_server"
run_statement "dhcp4_server" "$qry"
# table: dhcp4_server - check if it contains default entry
qry="select count(*) from dhcp4_server"
run_statement "dhcp4_server" "$qry" 1
# table: dhcp4_audit
qry="select id, object_type, object_id, modification_type from dhcp4_audit"
run_statement "dhcp4_audit" "$qry"
# table: dhcp4_global_parameter
qry="select id, name, value, parameter_type, modification_ts from dhcp4_global_parameter"
run_statement "dhcp4_global_parameter" "$qry"
# table: dhcp4_global_parameter_server
qry="select parameter_id, server_id, modification_ts from dhcp4_global_parameter_server"
run_statement "dhcp4_global_parameter_server" "$qry"
# table: dhcp4_option_def
qry="select id, code, name, space, type, modification_ts, is_array, encapsulate, record_types, user_context from dhcp4_option_def"
run_statement "dhcp4_option_def" "$qry"
# table: dhcp4_option_def_server
qry="select option_def_id, server_id, modification_ts from dhcp4_option_def_server"
run_statement "dhcp4_option_def_server" "$qry"
# table: dhcp4_shared_network
qry="select id, name, client_classes, interface, match_client_id, modification_ts, rebind_timer, relay, renew_timer, evaluate_additional_classes, user_context, valid_lifetime, authoritative, calculate_tee_times, t1_percent, t2_percent, boot_file_name, next_server, server_hostname from dhcp4_shared_network"
run_statement "dhcp4_shared_network" "$qry"
# table: dhcp4_shared_network_server
qry="select shared_network_id, server_id, modification_ts from dhcp4_shared_network_server"
run_statement "dhcp4_shared_network_server" "$qry"
# table: dhcp4_subnet
qry="select subnet_prefix, 4o6_interface, 4o6_interface_id, 4o6_subnet, boot_file_name, client_classes, interface, match_client_id, modification_ts, next_server, rebind_timer, relay, renew_timer, evaluate_additional_classes, server_hostname, shared_network_name, subnet_id, user_context, valid_lifetime, authoritative, calculate_tee_times, t1_percent, t2_percent from dhcp4_subnet"
run_statement "dhcp4_subnet" "$qry"
# table: dhcp4_pool
qry="select id, start_address, end_address, subnet_id, modification_ts from dhcp4_pool"
run_statement "dhcp4_pool" "$qry"
# table: dhcp4_subnet_server
qry="select subnet_id, server_id, modification_ts from dhcp4_subnet_server"
run_statement "dhcp4_subnet_server" "$qry"
# table: dhcp4_options (should include three new columns)
qry="select shared_network_name, pool_id, modification_ts from dhcp4_options"
run_statement "dhcp4_options" "$qry"
# table: dhcp4_options_server
qry="select option_id, server_id, modification_ts from dhcp4_options_server"
run_statement "dhcp4_options_server" "$qry"
# table: dhcp6_server
qry="select id, tag, description, modification_ts from dhcp6_server"
run_statement "dhcp6_server" "$qry"
# table: dhcp6_server - check if it contains default entry
qry="select count(*) from dhcp6_server"
run_statement "dhcp6_server" "$qry" 1
# table: dhcp6_audit
qry="select id, object_type, object_id, modification_type from dhcp6_audit"
run_statement "dhcp6_audit" "$qry"
# table: dhcp6_global_parameter
qry="select id, name, value, parameter_type, modification_ts from dhcp6_global_parameter"
run_statement "dhcp6_global_parameter" "$qry"
# table: dhcp6_global_parameter_server
qry="select parameter_id, server_id, modification_ts from dhcp6_global_parameter_server"
run_statement "dhcp6_global_parameter_server" "$qry"
# table: dhcp6_option_def
qry="select id, code, name, space, type, modification_ts, is_array, encapsulate, record_types, user_context from dhcp6_option_def"
run_statement "dhcp6_option_def" "$qry"
# table: dhcp6_option_def_server
qry="select option_def_id, server_id, modification_ts from dhcp6_option_def_server"
run_statement "dhcp6_option_def_server" "$qry"
# table: dhcp6_shared_network
qry="select id, name, client_classes, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, evaluate_additional_classes, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent, interface_id from dhcp6_shared_network"
run_statement "dhcp6_shared_network" "$qry"
# table: dhcp6_shared_network_server
qry="select shared_network_id, server_id, modification_ts from dhcp6_shared_network_server"
run_statement "dhcp6_shared_network" "$qry"
# table: dhcp6_subnet
qry="select subnet_prefix, client_classes, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, evaluate_additional_classes, shared_network_name, subnet_id, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent, interface_id from dhcp6_subnet"
run_statement "dhcp6_subnet" "$qry"
# table: dhcp6_subnet_server
qry="select subnet_id, server_id, modification_ts from dhcp6_subnet_server"
run_statement "dhcp6_subnet_server" "$qry"
# table: dhcp6_pd_pool
qry="select id, prefix_length, delegated_prefix_length, subnet_id, modification_ts from dhcp6_pd_pool"
run_statement "dhcp6_pd_pool" "$qry"
# table: dhcp6_pool
qry="select id, start_address, end_address, subnet_id, modification_ts from dhcp6_pool"
run_statement "dhcp6_pool" "$qry"
# table: dhcp6_options (should include four new columns)
qry="select shared_network_name, pool_id, pd_pool_id, modification_ts from dhcp6_options"
run_statement "dhcp6_options" "$qry"
# table: dhcp6_options_server
qry="select option_id, server_id, modification_ts from dhcp6_options_server"
run_statement "dhcp6_options_server" "$qry"
# Schema upgrade from 7.0 to 8.0
# Test that createAuditRevisionDHCP4 exists and creates entry in
# the dhcp4_audit_revision table.
qry="CALL createAuditRevisionDHCP4('2019-01-28 23:59:11', 'all', 'some log message', 0)"
run_statement "createAuditRevisionDHCP4" "$qry"
qry="SELECT COUNT(*) from dhcp4_audit_revision"
run_statement "dhcp4_audit_revision count" "$qry" 1
qry="SELECT id, modification_ts, server_id, log_message FROM dhcp4_audit_revision"
run_statement "dhcp4_audit_revision" "$qry"
# Test that createAuditEntryDHCP4 exists and creates entry in
# the dhcp4_audit table.
qry="SET @audit_revision_id = (SELECT id FROM dhcp4_audit_revision LIMIT 1); CALL createAuditEntryDHCP4('dhcp4_subnet', 1, 'create')"
run_statement "createAuditEntryDHCP4" "$qry"
qry="SELECT COUNT(*) FROM dhcp4_audit"
run_statement "dhcp4_audit count" "$qry" 1
qry="SELECT id, object_type, object_id, modification_type, revision_id FROM dhcp4_audit"
run_statement "dhcp4_audit" "$qry"
# Test that createOptionAuditDHCP4 exists can create an audit
# entry.
# First set the cascade_transaction session variable to check that
# the procedure won't create the audit entry for the option when
# this flag is set.
qry="SET @audit_revision_id = (SELECT id FROM dhcp4_audit_revision LIMIT 1); SET @cascade_transaction = 1; CALL createOptionAuditDHCP4('create', 0, 1024, NULL, NULL, NULL, NULL, now())"
run_statement "createOptionAuditDHCP4 cascade update" "$qry"
# The number of rows matching the audit entry should be 0.
qry="SELECT COUNT(*) FROM dhcp4_audit WHERE object_type = 'dhcp4_options' AND object_id = 1024"
run_statement "createOptionAuditDHCP4 cascade update, entry not inserted" "$qry" 0;
# This time set the cascade_update to 0 and expect that the
# audit entry will be created for the option.
qry="SET @audit_revision_id = (SELECT id FROM dhcp4_audit_revision LIMIT 1); SET @cascade_transaction = 0; CALL createOptionAuditDHCP4('create', 0, 1024, NULL, NULL, NULL, NULL, now())"
run_statement "createOptionAuditDHCP4 cascade update" "$qry"
qry="SELECT COUNT(*) FROM dhcp4_audit WHERE object_type = 'dhcp4_options' AND object_id = 1024"
run_statement "createOptionAuditDHCP4 cascade update, entry not inserted" "$qry" 1;
# Test that createAuditRevisionDHCP6 exists and creates entry in
# the dhcp6_audit_revision table.
qry="CALL createAuditRevisionDHCP6('2019-01-28 23:59:11', 'all', 'some log message', 0)"
run_statement "createAuditRevisionDHCP6" "$qry"
qry="SELECT COUNT(*) from dhcp6_audit_revision"
run_statement "dhcp6_audit_revision count" "$qry" 1
qry="SELECT id, modification_ts, server_id, log_message FROM dhcp6_audit_revision"
run_statement "dhcp6_audit_revision" "$qry"
# Test that createAuditEntryDHCP6 exists and creates entry in
# the dhcp6_audit table.
qry="SET @audit_revision_id = (SELECT id FROM dhcp6_audit_revision LIMIT 1); CALL createAuditEntryDHCP6('dhcp6_subnet', 1, 'create')"
run_statement "createAuditEntryDHCP6" "$qry"
qry="SELECT COUNT(*) FROM dhcp6_audit"
run_statement "dhcp6_audit count" "$qry" 1
qry="SELECT id, object_type, object_id, modification_type, revision_id FROM dhcp6_audit"
run_statement "dhcp6_audit" "$qry"
# Test that createOptionAuditDHCP6 exists can create an audit
# entry.
# First set the cascade_transaction session variable to check that
# the procedure won't create the audit entry for the option when
# this flag is set.
qry="SET @audit_revision_id = (SELECT id FROM dhcp6_audit_revision LIMIT 1); SET @cascade_transaction = 1; CALL createOptionAuditDHCP6('create', 0, 1024, NULL, NULL, NULL, NULL, NULL, now())"
run_statement "createOptionAuditDHCP6 cascade update" "$qry"
# The number of rows matching the audit entry should be 0.
qry="SELECT COUNT(*) FROM dhcp6_audit WHERE object_type = 'dhcp6_options' AND object_id = 1024"
run_statement "createOptionAuditDHCP6 cascade update, entry not inserted" "$qry" 0;
# This time set the cascade_update to 0 and expect that the
# audit entry will be created for the option.
qry="SET @audit_revision_id = (SELECT id FROM dhcp6_audit_revision LIMIT 1); SET @cascade_transaction = 0; CALL createOptionAuditDHCP6('create', 0, 1024, NULL, NULL, NULL, NULL, NULL,now())"
run_statement "createOptionAuditDHCP6 cascade update" "$qry"
qry="SELECT COUNT(*) FROM dhcp6_audit WHERE object_type = 'dhcp6_options' AND object_id = 1024"
run_statement "createOptionAuditDHCP6 cascade update, entry not inserted" "$qry" 1;
# New triggers aren't tested here because the extensive tests are
# provided with the backend implementations.
# parameter_data_type must exist and must have 4 rows.
qry="SELECT COUNT(*) FROM parameter_data_type"
run_statement "parameter_data_type count" "$qry" 4;
# Schema upgrade from 8.0 to 8.2
# New lifetime bounds.
# table: dhcp4_shared_network
qry="select id, name, client_classes, interface, match_client_id, modification_ts, rebind_timer, relay, renew_timer, evaluate_additional_classes, user_context, valid_lifetime, min_valid_lifetime, max_valid_lifetime, authoritative, calculate_tee_times, t1_percent, t2_percent, boot_file_name, next_server, server_hostname from dhcp4_shared_network"
run_statement "dhcp4_shared_network" "$qry"
# table: dhcp4_subnet
qry="select subnet_prefix, 4o6_interface, 4o6_interface_id, 4o6_subnet, boot_file_name, client_classes, interface, match_client_id, modification_ts, next_server, rebind_timer, relay, renew_timer, evaluate_additional_classes, server_hostname, shared_network_name, subnet_id, user_context, valid_lifetime, min_valid_lifetime, max_valid_lifetime, authoritative, calculate_tee_times, t1_percent, t2_percent from dhcp4_subnet"
run_statement "dhcp4_subnet" "$qry"
# table: dhcp6_shared_network
qry="select id, name, client_classes, interface, modification_ts, preferred_lifetime, min_preferred_lifetime, max_preferred_lifetime,rapid_commit, rebind_timer, relay, renew_timer, evaluate_additional_classes, user_context, valid_lifetime, min_valid_lifetime, max_valid_lifetime, calculate_tee_times, t1_percent, t2_percent from dhcp6_shared_network"
run_statement "dhcp6_shared_network" "$qry"
# table: dhcp6_subnet
qry="select subnet_prefix, client_classes, interface, modification_ts, preferred_lifetime, min_preferred_lifetime, max_preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, evaluate_additional_classes, shared_network_name, subnet_id, user_context, valid_lifetime, min_valid_lifetime, max_valid_lifetime, calculate_tee_times, t1_percent, t2_percent from dhcp6_subnet"
run_statement "dhcp6_subnet" "$qry"
# table: dhcp4_pool (should include three new columns)
qry="select client_classes, evaluate_additional_classes, user_context from dhcp4_pool"
run_statement "dhcp4_pool" "$qry"
# table: dhcp6_pd_pool (should include five new columns)
qry="select excluded_prefix, excluded_prefix_length, client_classes, evaluate_additional_classes, user_context from dhcp6_pd_pool"
run_statement "dhcp6_pd_pool" "$qry"
# table: dhcp6_pool (should include three new columns)
qry="select client_classes, evaluate_additional_classes, user_context from dhcp6_pool"
run_statement "dhcp6_pool" "$qry"
# Verify that dhcp4_option_def column name is is_array
qry="select is_array from dhcp4_option_def"
run_statement "dhcp4_option_def verify is_array column" "$qry"
# Verify that dhcp6_option_def column name is is_array
qry="select is_array from dhcp6_option_def"
run_statement "dhcp6_option_def verify is_array column" "$qry"
# Schema upgrade from 8.2 to 9.3
# New DDNS columns.
# table: dhcp4_shared_network (should include six new columns)
qry="select ddns_send_updates, ddns_override_no_update, ddns_override_client_update, ddns_replace_client_name, ddns_generated_prefix, ddns_qualifying_suffix from dhcp4_shared_network"
run_statement "dhcp4_shared_network" "$qry"
# table: dhcp6_shared_network (should include six new columns)
qry="select ddns_send_updates, ddns_override_no_update, ddns_override_client_update, ddns_replace_client_name, ddns_generated_prefix, ddns_qualifying_suffix from dhcp6_shared_network"
run_statement "dhcp6_shared_network" "$qry"
# table: dhcp4_subnet (should include six new columns)
qry="select ddns_send_updates, ddns_override_no_update, ddns_override_client_update, ddns_replace_client_name, ddns_generated_prefix, ddns_qualifying_suffix from dhcp4_subnet"
run_statement "dhcp4_subnet" "$qry"
# table: dhcp6_subnet (should include six new columns)
qry="select ddns_send_updates, ddns_override_no_update, ddns_override_client_update, ddns_replace_client_name, ddns_generated_prefix, ddns_qualifying_suffix from dhcp6_subnet"
run_statement "dhcp6_subnet" "$qry"
# Schema upgrade from 9.3 to 9.4.
# Non unique indexes on hosts allowing multiple reservation for the same IP.
insert_sql="\
insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (hex('010101010101'), 0, 1, inet_aton('192.0.2.0'));\
insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (hex('010101010102'), 0, 1, inet_aton('192.0.2.0'))"
run_command \
mysql_execute "$insert_sql"
assert_eq 0 "${EXIT_CODE}" "insert into hosts failed, expected exit code %d, actual %d"
# Schema upgrade from 9.4 to 9.5.
# table: dhcp4_shared_network (reservation_mode replaced by reservations flags)
qry="select reservations_global, reservations_in_subnet, reservations_out_of_pool from dhcp4_shared_network"
run_statement "dhcp4_shared_network" "$qry"
qry="show columns from dhcp4_shared_network like 'reservation_mode'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show columns from dhcp4_shared_network like 'reservation_mode' failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci reservation) || true
assert_eq 0 "${count}" "dhcp4_shared_network has still reservation_mode column. (returned count %d, expected %d)"
# table: dhcp4_subnet (reservation_mode replaced by reservations flags)
qry="select reservations_global, reservations_in_subnet, reservations_out_of_pool from dhcp4_subnet"
run_statement "dhcp4_subnet" "$qry"
qry="show columns from dhcp4_subnet like 'reservation_mode'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show columns from dhcp4_subnet like 'reservation_mode' failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci reservation) || true
assert_eq 0 "${count}" "dhcp4_subnet has still reservation_mode column. (returned count %d, expected %d)"
# table: dhcp6_shared_network (reservation_mode replaced by reservations flags)
qry="select reservations_global, reservations_in_subnet, reservations_out_of_pool from dhcp6_shared_network"
run_statement "dhcp6_shared_network" "$qry"
qry="show columns from dhcp6_shared_network like 'reservation_mode'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show columns from dhcp6_shared_network like 'reservation_mode' failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci reservation) || true
assert_eq 0 "${count}" "dhcp6_shared_network has still reservation_mode column. (returned count %d, expected %d)"
# table: dhcp6_subnet (reservation_mode replaced by reservations flags)
qry="select reservations_global, reservations_in_subnet, reservations_out_of_pool from dhcp6_subnet"
run_statement "dhcp6_subnet" "$qry"
qry="show columns from dhcp6_subnet like 'reservation_mode'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show columns from dhcp6_subnet like 'reservation_mode' failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci reservation) || true
assert_eq 0 "${count}" "dhcp6_subnet has still reservation_mode column. (returned count %d, expected %d)"
# Schema upgrade from 9.5 to 9.6.
# table: dhcp4_shared_network new cache_threshold and cache_max_age columns
qry="select cache_threshold, cache_max_age from dhcp4_shared_network"
run_statement "dhcp4_shared_network" "$qry"
# table: dhcp4_subnet new cache_threshold and cache_max_age columns
qry="select cache_threshold, cache_max_age from dhcp4_subnet"
run_statement "dhcp4_shared_network" "$qry"
# table: dhcp6_shared_network new cache_threshold and cache_max_age columns
qry="select cache_threshold, cache_max_age from dhcp6_shared_network"
run_statement "dhcp6_shared_network" "$qry"
# table: dhcp6_subnet new cache_threshold and cache_max_age columns
qry="select cache_threshold, cache_max_age from dhcp6_subnet"
run_statement "dhcp6_shared_network" "$qry"
qry='SELECT id FROM logs'
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry} failed: expected status code %d, returned %d"
# Check upgrade from 10.0 to 11.0.
qry="show indexes from lease4 where key_name = 'lease4_by_expire_state'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show indexes from lease4 failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci lease4_by_expire_state)
assert_eq 2 "${count}" "lease4_by_expire_state wrong or missing. (expected count %d, actual %d)"
qry="show indexes from lease6 where key_name = 'lease6_by_expire_state'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show indexes from lease6 failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci lease6_by_expire_state)
assert_eq 2 "${count}" "lease6_by_expire_state wrong or missing. (expected count %d, actual %d)"
# Verify preferred lifetime columns exist.
qry="select preferred_lifetime,min_preferred_lifetime,max_preferred_lifetime from dhcp6_client_class where name=''"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "$qry failed. dhcp6_client_classes preferred lifetime columns missing?"
# Check upgrade from 11.0 to 12.0.
# Add classes with associated options.
qry="\
SET @disable_audit = 1;\
INSERT INTO dhcp4_client_class(name, modification_ts) VALUES ('foo', now());\
INSERT INTO dhcp4_options(code, scope_id, dhcp_client_class, modification_ts) VALUES (222, 2, 'foo', now());\
INSERT INTO dhcp6_client_class(name, modification_ts) VALUES ('foo', now());\
INSERT INTO dhcp6_options(code, scope_id, dhcp_client_class, modification_ts) VALUES (222, 2, 'foo', now());\
SET @disable_audit = 0"
run_command \
mysql_execute "$qry"
assert_eq 0 "${EXIT_CODE}" "inserting classes and options failed, expected exit code %d, actual %d"
# Delete the classes.
qry="\
SET @disable_audit = 1;\
DELETE FROM dhcp4_client_class;\
DELETE FROM dhcp6_client_class;\
SET @disable_audit = 0"
run_command \
mysql_execute "$qry"
assert_eq 0 "${EXIT_CODE}" "deleting classes failed, expected exit code %d, actual %d"
# Ensure that the DHCPv4 option was deleted.
qry="SELECT COUNT(*) from dhcp4_options"
run_statement "dhcp4_options count" "$qry" 0
# Ensure that the DHCPv6 option was deleted.
qry="SELECT COUNT(*) from dhcp6_options"
run_statement "dhcp6_options count" "$qry" 0
# Check upgrade from 12.0 to 13.0.
mysql_upgrade_12_to_13_test
# Check upgrade from 13.0 to 14.0.
mysql_upgrade_13_to_14_test
# Check upgrade from 14.0 to 15.0.
mysql_upgrade_14_to_15_test
# Check upgrade from 15.0 to 16.0.
# table: lease4 new relay_id remote_id column and index.
qry="select relay_id from lease4"
run_statement "lease4" "$qry"
qry="show indexes from lease4 where key_name = 'lease4_by_relay_id'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show indexes from lease4 failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci lease4_by_relay_id)
assert_eq 1 "${count}" "lease4_by_relay_id wrong or missing. (expected count %d, actual %d)"
# table: lease4 new remote_id column and index.
qry="select remote_id from lease4"
run_statement "lease4" "$qry"
qry="show indexes from lease4 where key_name = 'lease4_by_remote_id'"
run_command \
mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "show indexes from lease4 failed. (expected status code %d, returned %d)"
count=$(echo "${OUTPUT}" | grep -Fci lease4_by_remote_id)
assert_eq 1 "${count}" "lease4_by_remote_id wrong or missing. (expected count %d, actual %d)"
# Check upgrade from 16.0 to 17.0.
mysql_upgrade_16_to_17_test
# Check upgrade from 17.0 to 18.0.
mysql_upgrade_17_to_18_test
# Check upgrade from 18.0 to 19.0.
mysql_upgrade_18_to_19_test
# Check upgrade from 22.0 to 23.0.
mysql_upgrade_22_to_23_test
# Check upgrade from 23.0 to 24.0.
mysql_upgrade_23_to_24_test
# Check upgrade from 24.0 to 25.0.
mysql_upgrade_24_to_25_test
# Check upgrade from 25.0 to 26.0.
mysql_upgrade_25_to_26_test
# Check upgrade from 26.0 to 27.0.
mysql_upgrade_26_to_27_test
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# May accept additional parameters to be passed to lease-dump.
mysql_lease4_dump_test() {
test_start "mysql.lease4_dump_test${1-}"
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
output_file="$output_dir/data/mysql.lease4_dump_test.output.csv"
ref_file="$test_dir/data/lease4_dump_test.reference.csv"
# Clean up any test files left from prior failed runs unless -y was provided in which case
# explicitly create the file to check that it will be automatically deleted.
# files should be removed by kea-admin itself.
for i in "${output_file}" \
"${output_file}.tmp" \
"/tmp/$(basename "${output_file}").tmp" \
; do
if printf '%s' "$@" | grep 'y' > /dev/null; then
touch "${i}"
else
rm -f "${i}"
fi
done
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" \
-d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d"
# Insert the reference record
insert_sql="\
insert into lease4 values(10,20,30,40,(SELECT FROM_UNIXTIME(1642000000)),50,1,1,'one.example.com',0,NULL,NULL,NULL,0);
insert into lease4 values(11,NULL,123,40,(SELECT FROM_UNIXTIME(1643210000)),50,1,1,'',1,'{ }',NULL,NULL,0);\
insert into lease4 values(12,22,NULL,40,(SELECT FROM_UNIXTIME(1643212345)),50,1,1,'three,example,com',2,'{ \"a\": 1, \"b\": \"c\" }',NULL,NULL,0)"
run_command \
mysql_execute "$insert_sql"
assert_eq 0 "${EXIT_CODE}" "insert into lease4 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file
run_command \
"${kea_admin}" lease-dump mysql -4 -u "${db_user}" -p "${db_password}" -n "${db_name}" \
-d "${db_scripts_dir}" -o "${output_file}" "$@"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical
run_command \
cmp -s "${output_file}" "${ref_file}"
assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d, diff:\n$(diff ${ref_file} ${output_file})"
# Remove the files.
rm -f "${output_file}"
rm -f "${output_file}.tmp"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# May accept additional parameters to be passed to lease-dump.
mysql_lease6_dump_test() {
test_start "mysql.lease6_dump_test${1-}"
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
output_file="$output_dir/data/mysql.lease6_dump_test.output.csv"
ref_file="$test_dir/data/lease6_dump_test.reference.csv"
# Clean up any test files left from prior failed runs unless -y was provided in which case
# explicitly create the file to check that it will be automatically deleted.
# files should be removed by kea-admin itself.
for i in "${output_file}" \
"${output_file}.tmp" \
"/tmp/$(basename "${output_file}").tmp" \
; do
if printf '%s' "$@" | grep 'y' > /dev/null; then
touch "${i}"
else
rm -f "${i}"
fi
done
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d"
# Insert the reference record
insert_sql="\
insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,128,1,1,'one.example.com',80,90,16,0,NULL,0);\
insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,128,1,1,'',80,90,1,1,'{ }',0);\
insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,128,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',0)"
run_command \
mysql_execute "$insert_sql"
assert_eq 0 "${EXIT_CODE}" "insert into lease6 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file
run_command \
"${kea_admin}" lease-dump mysql -6 -u "${db_user}" -p "${db_password}" -n "${db_name}" \
-d "${db_scripts_dir}" -o "${output_file}" "$@"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical
run_command \
cmp -s "${output_file}" "${ref_file}"
assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d, diff:\n$(diff ${ref_file} ${output_file})"
# Remove the files.
rm -f "${output_file}"
rm -f "${output_file}.tmp"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# May accept additional parameters to be passed to lease-dump or to lease-upload.
mysql_lease4_upload_test() {
test_start "mysql.lease4_upload_test${1-}"
input_file="@abs_top_srcdir@/src/bin/admin/tests/data/lease4_dump_test.reference.csv"
input_file_cp="@abs_top_builddir@/src/bin/admin/tests/data/lease4_dump_test.reference.csv"
output_file="@abs_top_builddir@/src/bin/admin/tests/data/lease4_dump_test.output.csv"
if [ "${input_file}" != "${input_file_cp}" ]; then
cp -f ${input_file} ${input_file_cp}
input_file=${input_file_cp}
input_file_cp=""
fi
# Wipe the whole database.
mysql_wipe
# Clean up any test files left from prior failed runs unless -y was provided in which case
# explicitly create the file to check that it will be automatically deleted.
# files should be removed by kea-admin itself.
for i in "${input_file}.tmp" \
"${output_file}" \
"${output_file}.tmp" \
"/tmp/$(basename "${input_file}").tmp" \
; do
if printf '%s' "$@" | grep 'y' > /dev/null; then
touch "${i}"
else
rm -f "${i}"
fi
done
# Initialize the database.
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" \
-n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d"
# Upload leases.
run_command \
"${kea_admin}" lease-upload mysql -4 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
-i "${input_file}" "$@"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-upload -4 failed, expected exit code %d, actual %d"
# Dump leases.
run_command \
"${kea_admin}" lease-dump mysql -4 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
-o "${output_file}" "$@"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
# Compare the initial file used for upload to the file retrieved from dump, they should be identical.
run_command \
cmp -s "${input_file}" "${output_file}"
assert_eq 0 "${EXIT_CODE}" "file resulted from dump after upload does not match file used for upload, expected exit code %d, actual %d, diff:\n$(diff ${input_file} ${output_file})"
# Remove the files.
if [ "${input_file}" != "${input_file_cp}" ]; then
rm -f "${input_file}"
fi
rm -f "${input_file}.tmp"
rm -f "${output_file}"
rm -f "${output_file}.tmp"
# Wipe the whole database.
mysql_wipe
test_finish 0
}
# May accept additional parameters to be passed to lease-dump or to lease-upload.
mysql_lease6_upload_test() {
test_start "mysql.lease6_upload_test${1-}"
input_file="@abs_top_srcdir@/src/bin/admin/tests/data/lease6_dump_test.reference.csv"
input_file_cp="@abs_top_builddir@/src/bin/admin/tests/data/lease6_dump_test.reference.csv"
output_file="@abs_top_builddir@/src/bin/admin/tests/data/lease6_dump_test.output.csv"
if [ "${input_file}" != "${input_file_cp}" ]; then
cp -f ${input_file} ${input_file_cp}
input_file=${input_file_cp}
input_file_cp=""
fi
# Wipe the whole database.
mysql_wipe
# Clean up any test files left from prior failed runs unless -y was provided in which case
# explicitly create the file to check that it will be automatically deleted.
# files should be removed by kea-admin itself.
for i in "${input_file}.tmp" \
"${output_file}" \
"${output_file}.tmp" \
"/tmp/$(basename "${input_file}").tmp" \
; do
if printf '%s' "$@" | grep 'y' > /dev/null; then
touch "${i}"
else
rm -f "${i}"
fi
done
# Initialize the database.
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" \
-n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d"
# Upload leases.
run_command \
"${kea_admin}" lease-upload mysql -6 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
-i "${input_file}" "$@"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-upload -6 failed, expected exit code %d, actual %d"
# Dump leases.
run_command \
"${kea_admin}" lease-dump mysql -6 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
-o "${output_file}" "$@"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, expected exit code %d, actual %d"
# Compare the initial file used for upload to the file retrieved from dump, they should be identical.
run_command \
cmp -s "${input_file}" "${output_file}"
assert_eq 0 "${EXIT_CODE}" "file resulted from dump after upload does not match file used for upload, expected exit code %d, actual %d, diff:\n$(diff ${input_file} ${output_file})"
# Remove the files.
if [ "${input_file}" != "${input_file_cp}" ]; then
rm -f "${input_file}"
fi
rm -f "${input_file}.tmp"
rm -f "${output_file}"
rm -f "${output_file}.tmp"
# Wipe the whole database.
mysql_wipe
test_finish 0
}
# Verifies lease4_stat trigger operations on
# an new, empty database. It inserts, updates, and
# deletes various leases, checking lease4_stat
# values along the way.
mysql_lease4_stat_test() {
test_start "mysql.lease4_stat_test"
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql failed, expected %d, returned non-zero status code %d"
# Verify lease4 stat table is present
qry="select count(subnet_id) from lease4_stat"
run_statement "#1" "$qry" 0
# Insert lease4
qry="insert into lease4 (address, subnet_id, state) values (111,1,0)"
run_statement "#2" "$qry"
# Assigned state count should be 1
qry="select leases from lease4_stat where subnet_id = 1 and state = 0"
run_statement "#3" "$qry" 1
# Assigned state count should be 1
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 0 and state = 0"
run_statement "#4" "$qry" 1
# Set lease state to declined
qry="update lease4 set state = 1 where address = 111"
run_statement "#5" "$qry"
# Leases state count for assigned should be 0
qry="select leases from lease4_stat where subnet_id = 1 and state = 0"
run_statement "#6" "$qry" 0
# Leases state count for assigned should be 0
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 0 and state = 0"
run_statement "#7" "$qry" 0
# Leases state count for declined should be 1
qry="select leases from lease4_stat where subnet_id = 1 and state = 1"
run_statement "#8" "$qry" 1
# Leases state count for declined should be 1
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 0 and state = 1"
run_statement "#9" "$qry" 1
# Delete the lease
qry="delete from lease4 where address = 111"
run_statement "#10" "$qry"
# Leases state count for declined should be 0
qry="select leases from lease4_stat where subnet_id = 1 and state = 1"
run_statement "#11" "$qry" 0
# Leases state count for declined should be 0
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 0 and state = 1"
run_statement "#12" "$qry" 0
# Insert lease4
qry="insert into lease4 (address, subnet_id, pool_id, state) values (112,1,1,0)"
run_statement "#13" "$qry"
# Assigned state count should be 1
qry="select leases from lease4_stat where subnet_id = 1 and state = 0"
run_statement "#14" "$qry" 1
# Assigned state count should be 1
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 1 and state = 0"
run_statement "#15" "$qry" 1
# Insert lease4
qry="insert into lease4 (address, subnet_id, pool_id, state) values (113,1,2,0)"
run_statement "#16" "$qry"
# Assigned state count should be 2
qry="select leases from lease4_stat where subnet_id = 1 and state = 0"
run_statement "#17" "$qry" 2
# Assigned state count should be 1
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 1 and state = 0"
run_statement "#18" "$qry" 1
# Assigned state count should be 1
qry="select leases from lease4_pool_stat where subnet_id = 1 and pool_id = 2 and state = 0"
run_statement "#19" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that lease6_stat triggers operate correctly
# for using a given address and lease_type. It will
# insert a lease, update it, and delete checking the
# lease stat counts along the way. It assumes the
# database has been created but is empty.
# param addr - address to use to add to subnet 1
# param ltype - type of lease to create
mysql_lease6_stat_per_type() {
addr=$1;shift
addr1=$1;shift
addr2=$1;shift
ltype=$1
# insert a lease6 for addr and ltype, state assigned
qry="insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('$addr'),$ltype,1,0)"
run_statement "#2" "$qry"
# assigned stat should be 1
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0"
run_statement "#3" "$qry" 1
# assigned stat should be 1
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 0 and state = 0"
run_statement "#4" "$qry" 1
# update the lease, changing state to declined
qry="update lease6 set state = 1 where address = inet6_aton('$addr')"
run_statement "#5" "$qry"
# leases stat for assigned state should be 0
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0"
run_statement "#6" "$qry" 0
# leases stat for assigned state should be 0
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 0 and state = 0"
run_statement "#7" "$qry" 0
# leases count for declined state should be 1
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 1"
run_statement "#8" "$qry" 1
# leases count for declined state should be 1
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 0 and state = 1"
run_statement "#9" "$qry" 1
# delete the lease
qry="delete from lease6 where address = inet6_aton('$addr')"
run_statement "#10" "$qry"
# leases count for declined state should be 0
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0"
run_statement "#11" "$qry" 0
# leases count for declined state should be 0
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 0 and state = 0"
run_statement "#12" "$qry" 0
# insert a lease6 for addr and ltype, state assigned
qry="insert into lease6 (address, lease_type, subnet_id, pool_id, state) values (inet6_aton('$addr1'),$ltype,1,1,0)"
run_statement "#13" "$qry"
# assigned stat should be 1
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0"
run_statement "#14" "$qry" 1
# assigned stat should be 1
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 1 and state = 0"
run_statement "#15" "$qry" 1
# insert a lease6 for addr and ltype, state assigned
qry="insert into lease6 (address, lease_type, subnet_id, pool_id, state) values (inet6_aton('$addr2'),$ltype,1,2,0)"
run_statement "#16" "$qry"
# assigned stat should be 2
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0"
run_statement "#17" "$qry" 2
# assigned stat should be 1
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 1 and state = 0"
run_statement "#18" "$qry" 1
# assigned stat should be 1
qry="select leases from lease6_pool_stat where subnet_id = 1 and lease_type = $ltype and pool_id = 2 and state = 0"
run_statement "#19" "$qry" 1
}
# Verifies that lease6_stat triggers operation correctly
# for both NA and PD lease types, mysql_lease6_stat_per_type()
mysql_lease6_stat_test() {
test_start "mysql.lease6_stat_test"
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql failed, expected %d, returned non-zero status code %d"
# verify lease6 stat table is present
qry="select count(subnet_id) from lease6_stat"
run_statement "#1" "$qry"
# Test for address ::11, NA lease type
mysql_lease6_stat_per_type "::11" "::12" "::13" "0"
# Test for address ::22, PD lease type
mysql_lease6_stat_per_type "::22" "::23" "::24" "1"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that you can upgrade from earlier version and
# lease<4/6>_stat tables will be populated based on existing
# leases and that the stat triggers work properly.
mysql_lease_stat_upgrade_test() {
test_start "mysql.lease_stat_upgrade_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which prepopulate the lease stat
# tables.
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 4.0, this has lease_state in it
mysql_upgrade_schema_to_version 4.0
# Now we need insert some leases to "migrate" for both v4 and v6
qry=\
"insert into lease4 (address, subnet_id, state) values (111,10,0);\
insert into lease4 (address, subnet_id, state) values (222,10,0);\
insert into lease4 (address, subnet_id, state) values (333,10,1);\
insert into lease4 (address, subnet_id, state) values (444,10,2);\
insert into lease4 (address, subnet_id, state) values (555,77,0)"
run_statement "insert v4 leases" "$qry"
qry=\
"insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('::11'),0,40,0);\
insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('::22'),0,40,1);\
insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('::33'),1,40,0);\
insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('::44'),1,50,0);\
insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('::55'),1,50,0);\
insert into lease6 (address, lease_type, subnet_id, state) values (inet6_aton('::66'),1,40,2)"
run_statement "insert v6 leases" "$qry"
# Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
#
# First we'll verify lease4_stats are correct after migration.
#
# Assigned leases for subnet 10 should be 2
qry="select leases from lease4_stat where subnet_id = 10 and state = 0"
run_statement "#4.1" "$qry" 2
# Assigned leases for subnet 10 should be 2
qry="select leases from lease4_pool_stat where subnet_id = 10 and pool_id = 0 and state = 0"
run_statement "#4.2" "$qry" 2
# Assigned leases for subnet 77 should be 1
qry="select leases from lease4_stat where subnet_id = 77 and state = 0"
run_statement "#4.3" "$qry" 1
# Assigned leases for subnet 77 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 0 and state = 0"
run_statement "#4.4" "$qry" 1
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease4_stat where state = 2"
run_statement "#4.5" "$qry" 0
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease4_pool_stat where state = 2"
run_statement "#4.6" "$qry" 0
#
# Now we'll verify v4 trigger operation for insert, update, and delete
#
# Insert a new lease subnet 77
qry="insert into lease4 (address, subnet_id, pool_id, state) values (777,77,1,0)"
run_statement "#4.7" "$qry"
# Assigned count for subnet 77 should be 2
qry="select leases from lease4_stat where subnet_id = 77 and state = 0"
run_statement "#4.8" "$qry" 2
# Assigned count for subnet 77 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 0 and state = 0"
run_statement "#4.9" "$qry" 1
# Assigned count for subnet 77 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 1 and state = 0"
run_statement "#4.10" "$qry" 1
# Update the state of the new lease to declined
qry="update lease4 set state = 1 where address = 777"
run_statement "#4.11" "$qry"
# Assigned count for subnet 77 should be 1 again
qry="select leases from lease4_stat where subnet_id = 77 and state = 0"
run_statement "#4.12" "$qry" 1
# Assigned count for subnet 77 should be 1 again
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 0 and state = 0"
run_statement "#4.13" "$qry" 1
# Assigned count for subnet 77 should be 0 again
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 1 and state = 0"
run_statement "#4.14" "$qry" 0
# Declined count for subnet 77 should be 1
qry="select leases from lease4_stat where subnet_id = 77 and state = 1"
run_statement "#4.15" "$qry" 1
# Declined count for subnet 77 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 1 and state = 1"
run_statement "#4.16" "$qry" 1
# Delete the lease.
qry="delete from lease4 where address = 777"
run_statement "#4.17" "$qry"
# Declined count for subnet 77 should be 0
qry="select leases from lease4_stat where subnet_id = 77 and state = 1"
run_statement "#4.18" "$qry" 0
# Declined count for subnet 77 should be 0
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 1 and state = 1"
run_statement "#4.19" "$qry" 0
#
# Next we'll verify lease6_stats are correct after migration.
#
# Assigned leases for subnet 40 should be 1
qry="select leases from lease6_stat where subnet_id = 40 and lease_type = 0 and state = 0"
run_statement "#6.1" "$qry" 1
# Assigned leases for subnet 40 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 40 and lease_type = 0 and pool_id = 0 and state = 0"
run_statement "#6.2" "$qry" 1
# Assigned (PD) leases for subnet 40 should be 1
qry="select leases from lease6_stat where subnet_id = 40 and lease_type = 1 and state = 0"
run_statement "#6.3" "$qry" 1
# Assigned (PD) leases for subnet 40 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 40 and lease_type = 1 and pool_id = 0 and state = 0"
run_statement "#6.4" "$qry" 1
# Declined leases for subnet 40 should be 1
qry="select leases from lease6_stat where subnet_id = 40 and lease_type = 0 and state = 1"
run_statement "#6.5" "$qry" 1
# Declined leases for subnet 40 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 40 and lease_type = 0 and pool_id = 0 and state = 1"
run_statement "#6.6" "$qry" 1
# Assigned (PD) leases for subnet 50 should be 2
qry="select leases from lease6_stat where subnet_id = 50 and lease_type = 1 and state = 0"
run_statement "#6.7" "$qry" 2
# Assigned (PD) leases for subnet 50 should be 2
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 0 and state = 0"
run_statement "#6.8" "$qry" 2
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease6_stat where state = 2"
run_statement "#6.9" "$qry" 0
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease6_pool_stat where state = 2"
run_statement "#6.10" "$qry" 0
#
# Finally we'll verify v6 trigger operation for insert, update, and delete
#
# Insert a new lease subnet 50
qry="insert into lease6 (address, subnet_id, pool_id, lease_type, state) values (inet6_aton('::77'),50,1,1,0)"
run_statement "#6.11" "$qry"
# Assigned count for subnet 50 should be 3
qry="select leases from lease6_stat where subnet_id = 50 and lease_type = 1 and state = 0"
run_statement "#6.12" "$qry" 3
# Assigned count for subnet 50 should be 2
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 0 and state = 0"
run_statement "#6.13" "$qry" 2
# Assigned count for subnet 50 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 1 and state = 0"
run_statement "#6.14" "$qry" 1
# Update the state of the new lease to expired
qry="update lease6 set state = 2 where address = inet6_aton('::77')"
run_statement "#6.15" "$qry"
# Assigned count for subnet 50 should be 2 again
qry="select leases from lease6_stat where subnet_id = 50 and lease_type = 1 and state = 0"
run_statement "#6.16" "$qry" 2
# Assigned count for subnet 50 should be 0 again
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 1 and state = 0"
run_statement "#6.17" "$qry" 0
# Delete another PD lease.
qry="delete from lease6 where address = inet6_aton('::55')"
run_statement "#6.18" "$qry"
# Assigned leases for subnet 50 should be 1
qry="select leases from lease6_stat where subnet_id = 50 and lease_type = 1 and state = 0"
run_statement "#6.19" "$qry" 1
# Assigned leases for subnet 50 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 0 and state = 0"
run_statement "#6.20" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
mysql_lease_stat_recount_test() {
test_start "mysql.lease_stat_recount_test"
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
"${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql failed, expected %d, returned non-zero status code %d"
# Now we need insert some leases to "recount"
qry=\
"insert into lease4 (address, subnet_id, state) values (111,10,0);\
insert into lease4 (address, subnet_id, pool_id, state) values (222,10,1,0);\
insert into lease4 (address, subnet_id, state) values (333,10,1);\
insert into lease4 (address, subnet_id, state) values (444,10,2);\
insert into lease4 (address, subnet_id, pool_id, state) values (555,77,2,0)"
run_statement "insert v4 leases" "$qry"
qry=\
"insert into lease6 (address, lease_type, subnet_id, state) values ('::111',0,40,0);\
insert into lease6 (address, lease_type, subnet_id, pool_id, state) values ('::222',0,40,1,1);\
insert into lease6 (address, lease_type, subnet_id, state) values ('::333',1,40,0);\
insert into lease6 (address, lease_type, subnet_id, state) values ('::444',1,50,0);\
insert into lease6 (address, lease_type, subnet_id, pool_id, state) values ('::555',1,50,2,0);\
insert into lease6 (address, lease_type, subnet_id, state) values ('::666',1,40,2)"
run_statement "insert v6 leases" "$qry"
# Now we change some counters.
qry=\
"insert into lease4_stat (subnet_id, state, leases) values (20,0,1);\
update lease4_stat set leases = 5 where subnet_id = 10 and state = 0;\
delete from lease4_stat where subnet_id = 10 and state = 2"
run_statement "change v4 stats" "$qry"
qry=\
"insert into lease4_pool_stat (subnet_id, pool_id, state, leases) values (20,3,0,1);\
update lease4_pool_stat set leases = 5 where subnet_id = 10 and pool_id = 0 and state = 0;\
delete from lease4_pool_stat where subnet_id = 10 and pool_id = 0 and state = 2"
run_statement "change v4 stats" "$qry"
qry=\
"insert into lease6_stat (subnet_id, lease_type, state, leases) values (20,1,0,1);\
update lease6_stat set leases = 5 where subnet_id = 40 and lease_type = 0 and state = 0;\
delete from lease6_stat where subnet_id = 40 and lease_type = 1 and state = 2"
run_statement "change v6 stats" "$qry"
qry=\
"insert into lease6_pool_stat (subnet_id, pool_id, lease_type, state, leases) values (20,3,1,0,1);\
update lease6_pool_stat set leases = 5 where subnet_id = 40 and lease_type = 0 and pool_id = 0 and state = 0;\
delete from lease6_pool_stat where subnet_id = 40 and lease_type = 1 and pool_id = 0 and state = 2"
run_statement "change v6 stats" "$qry"
# Recount all statistics from scratch.
run_command \
"${kea_admin}" stats-recount mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
assert_eq 0 "${EXIT_CODE}" "kea-admin stats-recount mysql failed, expected %d, returned non-zero status code %d"
#
# First we'll verify lease4_stats are correct after recount.
#
# Assigned leases for subnet 10 should be 2
qry="select leases from lease4_stat where subnet_id = 10 and state = 0"
run_statement "#4.1" "$qry" 2
# Assigned leases for subnet 10 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 10 and pool_id = 0 and state = 0"
run_statement "#4.2" "$qry" 1
# Assigned leases for subnet 10 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 10 and pool_id = 1 and state = 0"
run_statement "#4.3" "$qry" 1
# Declined leases for subnet 10 should be 1
qry="select leases from lease4_stat where subnet_id = 10 and state = 1"
run_statement "#4.4" "$qry" 1
# Assigned leases for subnet 10 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 10 and pool_id = 0 and state = 1"
run_statement "#4.5" "$qry" 1
# Assigned leases for subnet 77 should be 1
qry="select leases from lease4_stat where subnet_id = 77 and state = 0"
run_statement "#4.6" "$qry" 1
# Assigned leases for subnet 77 should be 1
qry="select leases from lease4_pool_stat where subnet_id = 77 and pool_id = 2 and state = 0"
run_statement "#4.7" "$qry" 1
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease4_stat where state = 2"
run_statement "#4.8" "$qry" 0
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease4_pool_stat where state = 2"
run_statement "#4.9" "$qry" 0
#
# Next we'll verify lease6_stats are correct after recount.
#
# Assigned leases for subnet 40 should be 1
qry="select leases from lease6_stat where subnet_id = 40 and lease_type = 0 and state = 0"
run_statement "#6.1" "$qry" 1
# Assigned leases for subnet 40 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 40 and lease_type = 0 and pool_id = 0 and state = 0"
run_statement "#6.2" "$qry" 1
# Assigned (PD) leases for subnet 40 should be 1
qry="select leases from lease6_stat where subnet_id = 40 and lease_type = 1 and state = 0"
run_statement "#6.3" "$qry" 1
# Assigned (PD) leases for subnet 40 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 40 and lease_type = 1 and pool_id = 0 and state = 0"
run_statement "#6.4" "$qry" 1
# Declined leases for subnet 40 should be 1
qry="select leases from lease6_stat where subnet_id = 40 and lease_type = 0 and state = 1"
run_statement "#6.5" "$qry" 1
# Declined leases for subnet 40 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 40 and lease_type = 0 and pool_id = 1 and state = 1"
run_statement "#6.6" "$qry" 1
# Assigned (PD) leases for subnet 50 should be 2
qry="select leases from lease6_stat where subnet_id = 50 and lease_type = 1 and state = 0"
run_statement "#6.7" "$qry" 2
# Assigned (PD) leases for subnet 50 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 0 and state = 0"
run_statement "#6.8" "$qry" 1
# Assigned (PD) leases for subnet 50 should be 1
qry="select leases from lease6_pool_stat where subnet_id = 50 and lease_type = 1 and pool_id = 2 and state = 0"
run_statement "#6.9" "$qry" 1
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease6_stat where state = 2"
run_statement "#6.10" "$qry" 0
# Should be no records for EXPIRED
qry="select count(subnet_id) from lease6_pool_stat where state = 2"
run_statement "#6.11" "$qry" 0
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that you can upgrade from an earlier version and
# that unused subnet ID values in hosts and options tables are
# converted to NULL.
mysql_unused_subnet_id_test() {
test_start "mysql.unused_subnet_id_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which convert subnet id values
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 6.0, this has lease_state in it
mysql_upgrade_schema_to_version 6.0
# Now we need insert some hosts to "migrate" for both v4 and v6
qry=\
"insert into hosts (dhcp_identifier_type, dhcp_identifier, dhcp4_subnet_id, dhcp6_subnet_id, hostname)\
values (0, '0123456', 0, 0, 'both'); \
insert into hosts (dhcp_identifier_type, dhcp_identifier, dhcp4_subnet_id, dhcp6_subnet_id, hostname)\
values (0, '1123456', 4, 0, 'v4only');
insert into hosts (dhcp_identifier_type, dhcp_identifier, dhcp4_subnet_id, dhcp6_subnet_id, hostname)\
values (0, '2123456', 0, 6, 'v6only');\
insert into hosts (dhcp_identifier_type, dhcp_identifier, dhcp4_subnet_id, dhcp6_subnet_id, hostname) \
values (0, '3123456', 4, 6, 'neither')"
run_statement "insert hosts" "$qry"
# Now we need insert some options to "migrate" for both v4 and v6
qry=\
"insert into dhcp4_options (code, dhcp4_subnet_id, scope_id) values (1, 4, 0);\
insert into dhcp4_options (code, dhcp4_subnet_id, scope_id) values (2, 0, 0);\
insert into dhcp6_options (code, dhcp6_subnet_id, scope_id) values (1, 6, 0);\
insert into dhcp6_options (code, dhcp6_subnet_id, scope_id) values (2, 0, 0)"
run_statement "insert options" "$qry"
# Ok, we have a 6.0 schema with hosts and options. Let's upgrade it to 7.0
# For versions higher than 7.0 some new constraints fail to be added
# with the not empty tables, for instance the 9.1 -> 9.2 upgrade script
# can raise a MySQL error 1452 for fk_dhcp4_options_subnet constraint.
mysql_upgrade_schema_to_version 7.0
# Version should now be 7.0.
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "7.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Two hosts should have null v4 subnet ids
qry="select count(host_id) from hosts where dhcp4_subnet_id is null"
run_statement "#hosts.1" "$qry" 2
# Two hosts should have v4 subnet ids = 4
qry="select count(host_id) from hosts where dhcp4_subnet_id = 4"
run_statement "#hosts.2" "$qry" 2
# Two hosts should have null v6 subnet ids
qry="select count(host_id) from hosts where dhcp6_subnet_id is null"
run_statement "#hosts.3" "$qry" 2
# Two hosts should should have v6 subnet ids = 6
qry="select count(host_id) from hosts where dhcp6_subnet_id = 6"
run_statement "#hosts.4" "$qry" 2
# One option should have null v4 subnet id
qry="select count(option_id) from dhcp4_options where dhcp4_subnet_id is null"
run_statement "#options.1" "$qry" 1
# One option should have v4 subnet id = 4
qry="select count(option_id) from dhcp4_options where dhcp4_subnet_id = 4"
run_statement "#options.2" "$qry" 1
# One option should have null v6 subnet id
qry="select count(option_id) from dhcp6_options where dhcp6_subnet_id is null"
run_statement "#options.3" "$qry" 1
# One option should have v4 subnet id = 6
qry="select count(option_id) from dhcp6_options where dhcp6_subnet_id = 6"
run_statement "#options.4" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that you can upgrade from an earlier version and
# that reservation_mode values in subnet and shared network tables are
# converted to new reservations flags.
mysql_reservation_mode_upgrade_test() {
test_start "mysql.reservation_mode_upgrade_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which convert reservation values
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 9.4, the last version with reservation_mode
mysql_upgrade_schema_to_version 9.4
# Now we need insert some subnets and shared networks.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_shared_network (name, modification_ts, reservation_mode)\
values ('test0', current_timestamp, 0);\
insert into dhcp4_shared_network (name, modification_ts, reservation_mode)\
values ('test1', current_timestamp, 1);\
insert into dhcp4_shared_network (name, modification_ts, reservation_mode)\
values ('test2', current_timestamp, 2);\
insert into dhcp4_shared_network (name, modification_ts, reservation_mode)\
values ('test3', current_timestamp, 3);\
insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (1234, '192.0.0.0/24', current_timestamp, 0);\
insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (2345, '192.0.1.0/24', current_timestamp, 1);\
insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (3456, '192.0.2.0/24', current_timestamp, 2);\
insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (4567, '192.0.3.0/24', current_timestamp, 3);\
insert into dhcp6_shared_network (name, modification_ts, reservation_mode)\
values ('test0', current_timestamp, 0);\
insert into dhcp6_shared_network (name, modification_ts, reservation_mode)\
values ('test1', current_timestamp, 1);\
insert into dhcp6_shared_network (name, modification_ts, reservation_mode)\
values ('test2', current_timestamp, 2);\
insert into dhcp6_shared_network (name, modification_ts, reservation_mode)\
values ('test3', current_timestamp, 3);\
insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (1234, '2001:db8::/64', current_timestamp, 0);\
insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (2345, '2001:db8:1::/64', current_timestamp, 1);\
insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (3456, '2001:db8:2::/64', current_timestamp, 2);\
insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, reservation_mode)\
values (4567, '2001:db8:3::/64', current_timestamp, 3);\
set @disable_audit = 0"
run_statement "insert reservation_mode" "$sql"
qry="select count(*) from dhcp4_shared_network"
run_statement "#get 4_shared count before update" "$qry" 4
qry="select count(*) from dhcp4_subnet"
run_statement "#get 4_subnet count before update" "$qry" 4
qry="select count(*) from dhcp6_shared_network"
run_statement "#get 6_shared count before update" "$qry" 4
qry="select count(*) from dhcp6_subnet"
run_statement "#get 6_subnet count before update" "$qry" 4
# Upgrade to schema 9.5.
mysql_upgrade_schema_to_version 9.5
# Test DISABLED (0) -> false, false, null
qry="select count(id) from dhcp4_shared_network where reservations_global = false and reservations_in_subnet = false and reservations_out_of_pool is null and name = 'test0'"
run_statement "#4_shared_disabled" "$qry" 1
# Test OUT_OF_POOL (1) -> false, true, true
qry="select count(id) from dhcp4_shared_network where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = true and name = 'test1'"
run_statement "#4_shared_out_of_pool" "$qry" 1
# Test GLOBAL (2) -> true, false, null
qry="select count(id) from dhcp4_shared_network where reservations_global = true and reservations_in_subnet = false and reservations_out_of_pool is null and name = 'test2'"
run_statement "#4_shared_global" "$qry" 1
# Test ALL (3) -> false, true, false
qry="select count(id) from dhcp4_shared_network where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = false and name = 'test3'"
run_statement "#4_shared_all" "$qry" 1
# Test DISABLED (0) -> false, false, null
qry="select count(subnet_id) from dhcp4_subnet where reservations_global = false and reservations_in_subnet = false and reservations_out_of_pool is null and subnet_prefix = '192.0.0.0/24'"
run_statement "#4_subnet_disabled" "$qry" 1
# Test OUT_OF_POOL (1) -> false, true, true
qry="select count(subnet_id) from dhcp4_subnet where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = true and subnet_prefix = '192.0.1.0/24'"
run_statement "#4_subnet_out_of_pool" "$qry" 1
# Test GLOBAL (2) -> true, false, null
qry="select count(subnet_id) from dhcp4_subnet where reservations_global = true and reservations_in_subnet = false and reservations_out_of_pool is null and subnet_prefix = '192.0.2.0/24'"
run_statement "#4_subnet_global" "$qry" 1
# Test ALL (3) -> false, true, false
qry="select count(subnet_id) from dhcp4_subnet where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = false and subnet_prefix = '192.0.3.0/24'"
run_statement "#4_subnet_all" "$qry" 1
# Test DISABLED (0) -> false, false, null
qry="select count(id) from dhcp6_shared_network where reservations_global = false and reservations_in_subnet = false and reservations_out_of_pool is null and name = 'test0'"
run_statement "#6_shared_disabled" "$qry" 1
# Test OUT_OF_POOL (1) -> false, true, true
qry="select count(id) from dhcp6_shared_network where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = true and name = 'test1'"
run_statement "#6_shared_out_of_pool" "$qry" 1
# Test GLOBAL (2) -> true, false, null
qry="select count(id) from dhcp6_shared_network where reservations_global = true and reservations_in_subnet = false and reservations_out_of_pool is null and name = 'test2'"
run_statement "#6_shared_global" "$qry" 1
# Test ALL (3) -> false, true, false
qry="select count(id) from dhcp6_shared_network where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = false and name = 'test3'"
run_statement "#6_shared_all" "$qry" 1
# Test DISABLED (0) -> false, false, null
qry="select count(subnet_id) from dhcp6_subnet where reservations_global = false and reservations_in_subnet = false and reservations_out_of_pool is null and subnet_prefix = '2001:db8::/64'"
run_statement "#6_subnet_disabled" "$qry" 1
# Test OUT_OF_POOL (1) -> false, true, true
qry="select count(subnet_id) from dhcp6_subnet where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = true and subnet_prefix = '2001:db8:1::/64'"
run_statement "#6_subnet_out_of_pool" "$qry" 1
# Test GLOBAL (2) -> true, false, null
qry="select count(subnet_id) from dhcp6_subnet where reservations_global = true and reservations_in_subnet = false and reservations_out_of_pool is null and subnet_prefix = '2001:db8:2::/64'"
run_statement "#6_subnet_global" "$qry" 1
# Test ALL (3) -> false, true, false
qry="select count(subnet_id) from dhcp6_subnet where reservations_global = false and reservations_in_subnet = true and reservations_out_of_pool = false and subnet_prefix = '2001:db8:3::/64'"
run_statement "#6_subnet_all" "$qry" 1
qry="select count(*) from dhcp4_shared_network"
run_statement "#get 4_shared count before update" "$qry" 4
qry="select count(*) from dhcp4_subnet"
run_statement "#get 4_subnet count before update" "$qry" 4
qry="select count(*) from dhcp6_shared_network"
run_statement "#get 6_shared count before update" "$qry" 4
qry="select count(*) from dhcp6_subnet"
run_statement "#get 6_subnet count before update" "$qry" 4
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that several tables for holding client classes are created
# and the triggers and stored procedures positioning the client classes
# and validating their dependencies behave correctly.
mysql_client_class_test() {
table_prefix="$1"
test_start "mysql.client_classes_test.${table_prefix}"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which validates client classes and
# dependencies behave correctly
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 10.0 that can contain client classes.
mysql_upgrade_schema_to_version 10.0
# Insert a new server.
sql=\
"SET @disable_audit = 1; \
INSERT INTO ${table_prefix}_server (tag, modification_ts) VALUES ('server1', NOW()); \
SET @disable_audit = 0"
run_statement "insert servers" "$sql"
# Insert client class foo at the top of the hierarchy. It has no dependencies.
sql=\
"START TRANSACTION; \
SET @disable_audit = 1; \
INSERT INTO ${table_prefix}_client_class (name, modification_ts, follow_class_name, depend_on_known_directly) VALUES ('foo', NOW(), NULL, 1); \
SET @last_id = LAST_INSERT_ID(); \
INSERT INTO ${table_prefix}_client_class_server (class_id, server_id) \
VALUES (@last_id, (SELECT id FROM ${table_prefix}_server WHERE tag = 'all')); \
SET @disable_audit = 0; \
COMMIT"
run_statement "insert client class foo" "$sql"
# Insert client class foobar after the foo class.
sql=\
"START TRANSACTION; \
SET @disable_audit = 1; \
INSERT INTO ${table_prefix}_client_class (name, modification_ts, follow_class_name) VALUES ('foobar', NOW(), NULL); \
SET @last_id = LAST_INSERT_ID(); \
INSERT INTO ${table_prefix}_client_class_server (class_id, server_id) \
VALUES (@last_id, (SELECT id FROM ${table_prefix}_server WHERE tag = 'server1')); \
SET @disable_audit = 0; \
COMMIT"
run_statement "insert client class foobar" "$sql"
# Insert the client class bar at the end. This class depends on the client
# class foo.
sql=\
"START TRANSACTION; \
SET @disable_audit = 1; \
INSERT INTO ${table_prefix}_client_class (name, modification_ts, follow_class_name) VALUES ('bar', NOW(), 'foo'); \
SET @last_id = LAST_INSERT_ID(); \
INSERT INTO ${table_prefix}_client_class_server (class_id, server_id) \
VALUES (@last_id, (SELECT id FROM ${table_prefix}_server WHERE tag = 'server1')); \
INSERT INTO ${table_prefix}_client_class_dependency (class_id, dependency_id) \
VALUES (@last_id, (SELECT id FROM ${table_prefix}_client_class WHERE name = 'foo')); \
SET @disable_audit = 0; \
COMMIT"
run_statement "insert client class bar" "$sql"
# Ensure that all three classes have been added in the expected order.
sql="SELECT o.order_index FROM ${table_prefix}_client_class AS c \
INNER JOIN ${table_prefix}_client_class_order AS o \
ON c.id = o.class_id WHERE c.name = 'foo'"
run_statement "#get order index of class foo" "$sql" 1
sql="SELECT o.order_index FROM ${table_prefix}_client_class AS c \
INNER JOIN ${table_prefix}_client_class_order AS o \
ON c.id = o.class_id WHERE c.name = 'bar'"
run_statement "#get order index of class bar" "$sql" 2
sql="SELECT o.order_index FROM ${table_prefix}_client_class AS c \
INNER JOIN ${table_prefix}_client_class_order AS o \
ON c.id = o.class_id WHERE c.name = 'foobar'"
run_statement "#get order index of class foobar" "$sql" 3
# Update the class bar moving behind the foobar class.
sql=\
"START TRANSACTION; \
SET @disable_audit = 1; \
UPDATE ${table_prefix}_client_class SET follow_class_name = 'foobar' WHERE name = 'bar'; \
SET @disable_audit = 0; \
COMMIT"
run_statement "update client class bar with re-positioning" "$sql"
# Check that the order of the last two classes was changed.
sql="SELECT o.order_index FROM ${table_prefix}_client_class AS c \
INNER JOIN ${table_prefix}_client_class_order AS o \
ON c.id = o.class_id WHERE c.name = 'bar'"
run_statement "#get order index of class bar" "$sql" 4
sql="SELECT o.order_index FROM ${table_prefix}_client_class AS c \
INNER JOIN ${table_prefix}_client_class_order AS o \
ON c.id = o.class_id WHERE c.name = 'foobar'"
run_statement "#get order index of class foobar" "$sql" 3
# Check that the first class is still at the first position.
sql="SELECT o.order_index FROM ${table_prefix}_client_class AS c \
INNER JOIN ${table_prefix}_client_class_order AS o \
ON c.id = o.class_id WHERE c.name = 'foo'"
run_statement "#get order index of class foo" "$sql" 1
sql=\
"SET @disable_audit = 1; \
INSERT INTO ${table_prefix}_options(code, scope_id, dhcp_client_class, modification_ts) \
VALUES (222, 0, '', now()); \
SET @disable_audit = 0"
run_statement "add option with an empty dhcp_client class" "$sql"
# Let's make sure that we can upgrade to version 12.0. This version
# introduces a foreign key between dhcpX_client_class and dhcpX_options
# table. The migration should set the dhcp_client_class to NULL.
mysql_upgrade_schema_to_version 12.0
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that the migration 9.6 to 10.0 modifies the length of
# the tag column in the dhcp4_server and dhcp6_server tables.
mysql_shrink_server_tag_test() {
test_start "mysql.shrink_server_tag_test"
mysql_wipe
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 9.6.
mysql_upgrade_schema_to_version 9.6
# Unfortunately, this schema version already contains 64 character
# long server tags. Let's extend it back, but not to 256 characters
# because it is proven to cause errors in some configurations.
sql=\
"ALTER TABLE dhcp4_server MODIFY COLUMN tag VARCHAR(128) NOT NULL"
run_statement "extend server DHCPv4 server tag column", "$sql"
sql=\
"ALTER TABLE dhcp6_server MODIFY COLUMN tag VARCHAR(128) NOT NULL"
run_statement "extend server DHCPv6 server tag column", "$sql"
mysql_upgrade_schema_to_version 10.0
# Ensure that the migration corrected the lengths.
sql=\
"SELECT CHARACTER_MAXIMUM_LENGTH \
FROM INFORMATION_SCHEMA.COLUMNS \
WHERE TABLE_SCHEMA='${db_name}' AND TABLE_NAME='dhcp4_server' AND COLUMN_NAME='tag'"
run_statement "get new tag column length" "$sql" 64
sql=\
"SELECT CHARACTER_MAXIMUM_LENGTH \
FROM INFORMATION_SCHEMA.COLUMNS \
WHERE TABLE_SCHEMA='${db_name}' AND TABLE_NAME='dhcp6_server' AND COLUMN_NAME='tag'"
run_statement "get new tag column length" "$sql" 64
mysql_wipe
test_finish 0
}
# Verifies that you can upgrade from earlier version and that initial EMPTY DUID
# (0x00) value in lease6 table is updated to proper value (0x000000).
mysql_update_empty_duid_test() {
test_start "mysql.update_empty_duid_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which convert empty duid values
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 16.0
mysql_upgrade_schema_to_version 16.0
sql=\
"insert into lease6 values('::10',203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\
insert into lease6 values('::11',UNHEX('00'),30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }')"
run_statement "insert v6 leases" "$sql"
# Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
# leases count for declined state should be 1 with DUID updated (0x000000)
qry="select count(*) from lease6 where address = inet6_aton('::11') and duid = 0x000000 and state = 1"
run_statement "#2" "$qry" 1
# leases count for non declined state should be 1 with DUID unchanged (0x323033)
qry="select count(*) from lease6 where address = inet6_aton('::10') and duid = 0x323033 and state = 0"
run_statement "#3" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that converting from lease6.address to binary column works
# while preserving data.
mysql_update_v6_addresses_to_binary() {
test_start "mysql.update_lease6_address_to_binary"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which convert empty duid values
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 18.0
mysql_upgrade_schema_to_version 18.0
sql=\
"insert into lease6 (address, lease_type, subnet_id) values('2601:19e:8100:1e10:b1b:51a8:f616:cf14', 1, 1);
insert into lease6 (address, lease_type, subnet_id) values('2601:19e:8100:1e10:b1b:51a8:f616:cf15', 1, 1);"
run_statement "insert v6 leases" "$sql"
# Insert ipv6_reservations address is binary.
sql=\
"insert into hosts(host_id, dhcp_identifier, dhcp_identifier_type) values (18219, '18219', 1); \
insert into ipv6_reservations (address, prefix_len, type, dhcp6_iaid, host_id) \
values ('2601:19e:8100:1e10:b1b:51a8:f616:cf16', 128, 1, 123, 18219);"
run_statement "insert an ipv6 reservation" "$sql"
# Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
# leases count for declined state should be 1 with DUID updated (0x000000)
qry="select count(*) from lease6 where address = inet6_aton('2601:19e:8100:1e10:b1b:51a8:f616:cf14');"
run_statement "#2" "$qry" 1
# leases count for non declined state should be 1 with DUID unchanged (0x323033)
qry="select count(*) from lease6 where address = inet6_aton('2601:19e:8100:1e10:b1b:51a8:f616:cf15');"
run_statement "#3" "$qry" 1
# verify the reservation is intact
qry="select inet6_ntoa(address) from ipv6_reservations where host_id = 18219;"
run_statement "ipv6_reservations_insert" "$qry" "2601:19e:8100:1e10:b1b:51a8:f616:cf16"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that you can upgrade from an earlier version and
# that CB global parameter entries for 'ddns-use-conflict-resolution'
# will get translated to 'ddns-conflict-resolution-mode'.
mysql_ddns_conflict_resolution_mode_update_test() {
test_start "mysql.ddns_conflict_resolution_mode_update_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 19.0.
mysql_upgrade_schema_to_version 19.0
# Now insert global parameter instances of ddns-use-conflict-resolution.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution','0',current_time(),2);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution','1',current_time(),2);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution','0',current_time(),2);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution','1',current_time(),2);"
run_statement "insert ddns_conflict_resolution_mode" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name='ddns-use-conflict-resolution';"
run_statement "#get 4_global parameter count before update" "$qry" 2
qry="select count(*) from dhcp6_global_parameter where name='ddns-use-conflict-resolution';"
run_statement "#get 6_global parameter count before update" "$qry" 2
# Upgrade to schema 21.0
mysql_upgrade_schema_to_version 21.0
# Verify we converted parameters correctly.
qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
value='check-with-dhcid'"
run_statement "#get 4_check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
value='no-check-with-dhcid'"
run_statement "#get 4_no-check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
value='check-with-dhcid'"
run_statement "#get 6_check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
value='no-check-with-dhcid'"
run_statement "#get 6_no-check-with-dhcid after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that deprecated dhcp-ddns global map parameters are removed.
mysql_dhcp_ddns_global_parameters_test() {
test_start "mysql.dhcp_ddns_global_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 21.0.
mysql_upgrade_schema_to_version 21.0
# Now insert global parameter instances of dhcp-ddns.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.generated-prefix','my-host',current_time(),4);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.qualifying-suffix','',current_time(),4);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.override-no-update','1',current_time(),2);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.override-client-update','1',current_time(),2);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.replace-client-name','never',current_time(),4);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.hostname-char-replacement','',current_time(),4);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.hostname-char-set','[^A-Za-z0-9.-]',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.generated-prefix','my-host',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.qualifying-suffix','',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.override-no-update','1',current_time(),2);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.override-client-update','1',current_time(),2);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.replace-client-name','never',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.hostname-char-replacement','',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('dhcp-ddns.hostname-char-set','[^A-Za-z0-9.-]',current_time(),4);"
run_statement "insert dhcp-ddns map parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%dhcp-ddns%';"
run_statement "#get 4_global parameter count before update" "$qry" 7
qry="select count(*) from dhcp6_global_parameter where name like '%dhcp-ddns%';"
run_statement "#get 6_global parameter count before update" "$qry" 7
# Upgrade to schema 22.0
mysql_upgrade_schema_to_version 22.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%dhcp-ddns%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%dhcp-ddns%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that deprecated reservation_mode "disabled" is migrated.
mysql_reservation_mode_disabled_parameters_test() {
test_start "mysql.reservation_mode_disabled_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 21.0.
mysql_upgrade_schema_to_version 21.0
# Now insert global parameter instances of reservation_mode.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','disabled',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','disabled',current_time(),4);"
run_statement "insert reservation_mode parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count before update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count before update" "$qry" 0
# Upgrade to schema 22.0
mysql_upgrade_schema_to_version 22.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp4_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that deprecated reservation_mode "off" is migrated.
mysql_reservation_mode_off_parameters_test() {
test_start "mysql.reservation_mode_off_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 21.0.
mysql_upgrade_schema_to_version 21.0
# Now insert global parameter instances of reservation_mode.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','off',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','off',current_time(),4);"
run_statement "insert reservation_mode parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count before update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count before update" "$qry" 0
# Upgrade to schema 22.0
mysql_upgrade_schema_to_version 22.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp4_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='reservations-in-subnet' AND value='0' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that deprecated reservation_mode "all" is migrated.
mysql_reservation_mode_all_parameters_test() {
test_start "mysql.reservation_mode_all_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 21.0.
mysql_upgrade_schema_to_version 21.0
# Now insert global parameter instances of reservation_mode.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','all',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','all',current_time(),4);"
run_statement "insert reservation_mode parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='reservations-in-subnet' AND value='1' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count before update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name='reservations-in-subnet' AND value='1' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count before update" "$qry" 0
# Upgrade to schema 22.0
mysql_upgrade_schema_to_version 22.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp4_global_parameter where name='reservations-in-subnet' AND value='1' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='reservations-in-subnet' AND value='1' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that deprecated reservation_mode "global" is migrated.
mysql_reservation_mode_global_parameters_test() {
test_start "mysql.reservation_mode_global_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 21.0.
mysql_upgrade_schema_to_version 21.0
# Now insert global parameter instances of reservation_mode.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','global',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','global',current_time(),4);"
run_statement "insert reservation_mode parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='reservations-global' AND value='1' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count before update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name='reservations-global' AND value='1' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count before update" "$qry" 0
# Upgrade to schema 22.0
mysql_upgrade_schema_to_version 22.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp4_global_parameter where name='reservations-global' AND value='1' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='reservations-global' AND value='1' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that deprecated reservation_mode "out-of-pool" is migrated.
mysql_reservation_mode_out_of_pool_parameters_test() {
test_start "mysql.reservation_mode_out_of_pool_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 21.0.
mysql_upgrade_schema_to_version 21.0
# Now insert global parameter instances of reservation_mode.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','out-of-pool',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('reservation-mode','out-of-pool',current_time(),4);"
run_statement "insert reservation_mode parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count before update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='reservations-out-of-pool' AND value='1' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count before update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name='reservations-out-of-pool' AND value='1' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count before update" "$qry" 0
# Upgrade to schema 22.0
mysql_upgrade_schema_to_version 22.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%reservation-mode%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%reservation-mode%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp4_global_parameter where name='reservations-out-of-pool' AND value='1' AND parameter_type=2;"
run_statement "#get exact 4_global parameter count after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='reservations-out-of-pool' AND value='1' AND parameter_type=2;"
run_statement "#get exact 6_global parameter count after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that OPT_RECORD_TYPE values are updated
mysql_migrate_opt_record_type() {
test_start "mysql.migrate_opt_record_type"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which prepopulate the lease stat
# tables.
#
# Initialize database to schema 1.0.
mysql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
assert_eq 0 "${EXIT_CODE}" "cannot initialize 1.0 database, expected exit code: %d, actual: %d"
# Now upgrade to schema 23.0
mysql_upgrade_schema_to_version 23.0
# Now insert option definitions.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
values ('222','foo','dhcp4',17,current_timestamp,NULL, false, false);\
insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
values ('223','bar','dhcp4',17,current_timestamp,'10, 7, 2, 14', false, false);\
insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
values ('224','bar2','dhcp4',18,current_timestamp,'10, 7, 2, 14', false, false);
insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
values ('222','foo','dhcp6',17,current_timestamp,NULL, false, false);\
insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
values ('223','bar','dhcp6',17,current_timestamp,'10, 7, 2, 14', false, false);\
insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
values ('224','bar2','dhcp6',18,current_timestamp,'10, 7, 2, 14', false, false);
"
run_statement "insert option definitions" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_option_def;"
run_statement "#get 4_option_def_count before update" "$qry" 3
qry="select count(*) from dhcp6_option_def;"
run_statement "#get 6_option_def_count before update" "$qry" 3
# Upgrade to schema 25.0
mysql_upgrade_schema_to_version 25.0
# Verify the migrated records.
qry="select type from dhcp4_option_def where name = 'foo';"
run_statement "#get 4_option_def_foo after update" "$qry" 17
qry="select type from dhcp4_option_def where name = 'bar';"
run_statement "#get 4_option_def_bar after update" "$qry" 254
qry="select type from dhcp4_option_def where name = 'bar2';"
run_statement "#get 4_option_def_bar2 after update" "$qry" 254
qry="select type from dhcp6_option_def where name = 'foo';"
run_statement "#get 6_option_def_foo after update" "$qry" 17
qry="select type from dhcp6_option_def where name = 'bar';"
run_statement "#get 6_option_def_bar after update" "$qry" 254
qry="select type from dhcp6_option_def where name = 'bar2';"
run_statement "#get 6_option_def_bar2 after update" "$qry" 254
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that control-socket global map parameters are removed.
mysql_remove_control_socket_parameters_test() {
test_start "mysql.mysql_remove_control_socket_parameters_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 23.0.
mysql_upgrade_schema_to_version 23.0
# Now insert global parameter instances of control-socket.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('control-socket.socket-name','/tmp/socket',current_time(),4);
insert into dhcp4_global_parameter (name,value,modification_ts,parameter_type)\
values ('control-socket.socket-type','unix',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('control-socket.socket-name','/tmp/socket',current_time(),4);
insert into dhcp6_global_parameter (name,value,modification_ts,parameter_type)\
values ('control-socket.socket-type','unix',current_time(),4);"
run_statement "insert control-socket map parameters" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name like '%control-socket%';"
run_statement "#get 4_global parameter count before update" "$qry" 2
qry="select count(*) from dhcp6_global_parameter where name like '%control-socket%';"
run_statement "#get 6_global parameter count before update" "$qry" 2
# Upgrade to schema 25.0
mysql_upgrade_schema_to_version 25.0
# Verify the record have been removed.
qry="select count(*) from dhcp4_global_parameter where name like '%control-socket%';"
run_statement "#get 4_global parameter count after update" "$qry" 0
qry="select count(*) from dhcp6_global_parameter where name like '%control-socket%';"
run_statement "#get 6_global parameter count after update" "$qry" 0
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Verifies that client_class to client_classes migrates
# single text entries to JSON list correctly
mysql_migrate_client_class_test() {
test_start "mysql.migrate_client_class_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which prepopulate the lease stat
# tables.
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 4.0, this has lease_state in it
mysql_upgrade_schema_to_version 26.0
# Now we need insert some leases to "migrate" for both v4 and v6
qry=\
"set @disable_audit 1;\
insert into dhcp4_shared_network (name, client_classes) values ('aaa', 'abc');\
insert into dhcp4_shared_network (name, client_classes) values ('bbb', '');\
insert into dhcp4_shared_network (name) values ('ccc');\
set @disable_audit 0;\
run_statement "insert v4 networks" "$qry"
# Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
qry="select client_classes from dhcp4_shared_network where name = 'aaa' and client_classes = '[ \"abc\" ]';
run_statement "#4.1" "$qry" 1
mysql_wipe
test_finish 0
}
# Verifies that client_class to client_classes migrates
# single text entries to JSON list correctly
mysql_migrate_client_class_test() {
test_start "mysql.migrate_client_class_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which prepopulate the lease stat
# tables.
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 4.0, this has lease_state in it
mysql_upgrade_schema_to_version 26.0
# Now we need insert some leases to "migrate" for both v4 and v6
qry="\
set @disable_audit = 1;\
insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net1', 'abc', current_timestamp);\
insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net2', '', current_timestamp);\
insert into dhcp4_shared_network (name, modification_ts) values ('net3', current_timestamp);\
insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
values (1, '192.0.0.0/24', current_timestamp, 'subber');\
insert into dhcp4_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
values (1, INET_ATON('192.0.0.0'), INET_ATON('192.0.0.1'), current_timestamp, 'poolio');\
insert into dhcp6_shared_network (name, client_class, modification_ts) values ('net6', 'xyz', current_timestamp);\
insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
values (6, '2001:db8:1::/64', current_timestamp, 'subber6');\
insert into dhcp6_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
values (6, ('2001:db8:1::1'), ('2001:db8:1::2'), current_timestamp, 'poolio6');\
insert into dhcp6_pd_pool (subnet_id, prefix, prefix_length, delegated_prefix_length, \
excluded_prefix_length, modification_ts, client_class) \
values (6, ('3001::'), 64, 72, 0, current_timestamp, 'pd_poolio');\
set @disable_audit = 0;\
"
run_statement "insert v4 networks" "$qry"
# Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
# Verify dhcp4_shared_network values
qry="select count(name) from dhcp4_shared_network where name = 'net1' and client_classes = '[ \"abc\" ]';"
run_statement "#1" "$qry" 1
qry="select count(name) from dhcp4_shared_network where name = 'net2' and client_classes IS NULL;"
run_statement "#2" "$qry" 1
qry="select count(name) from dhcp4_shared_network where name = 'net3' and client_classes IS NULL;"
run_statement "#3" "$qry" 1
# We don't bother verifying all null and '' handling again, only that the conversion function is
# called for remaining tables.
# Verify dhcp4_subnet.
qry="select count(subnet_id) from dhcp4_subnet where subnet_id = 1 and client_classes = '[ \"subber\" ]';"
run_statement "#4" "$qry" 1
# Verify dhcp4_pool.
qry="select count(subnet_id) from dhcp4_pool where subnet_id = 1 and client_classes = '[ \"poolio\" ]';"
run_statement "#5" "$qry" 1
# Verify dhcp6_shared_network.
qry="select count(name) from dhcp6_shared_network where name = 'net6' and client_classes = '[ \"xyz\" ]';"
run_statement "#6" "$qry" 1
# Verify dhcp6_subnet.
qry="select count(subnet_id) from dhcp6_subnet where subnet_id = 6 and client_classes = '[ \"subber6\" ]';"
run_statement "#7" "$qry" 1
# Verify dhcp6_pool.
qry="select count(subnet_id) from dhcp6_pool where subnet_id = 6 and client_classes = '[ \"poolio6\" ]';"
run_statement "#8" "$qry" 1
# Verify dhcp6_pd_pool.
qry="select count(subnet_id) from dhcp6_pd_pool where subnet_id = 6 and client_classes = '[ \"pd_poolio\" ]';"
run_statement "#9" "$qry" 1
mysql_wipe
test_finish 0
}
# Run tests.
mysql_db_init_test
mysql_host_reservation_init_test
mysql_db_version_test
mysql_db_version_with_extra_test
mysql_upgrade_test
mysql_lease4_dump_test
mysql_lease4_dump_test -y
mysql_lease6_dump_test
mysql_lease6_dump_test -y
mysql_lease4_upload_test
mysql_lease4_upload_test -y
mysql_lease6_upload_test
mysql_lease6_upload_test -y
mysql_lease4_stat_test
mysql_lease6_stat_test
mysql_lease_stat_upgrade_test
mysql_lease_stat_recount_test
mysql_unused_subnet_id_test
mysql_reservation_mode_upgrade_test
mysql_client_class_test dhcp4
mysql_client_class_test dhcp6
mysql_shrink_server_tag_test
mysql_update_empty_duid_test
mysql_update_v6_addresses_to_binary
mysql_ddns_conflict_resolution_mode_update_test
mysql_dhcp_ddns_global_parameters_test
mysql_reservation_mode_disabled_parameters_test
mysql_reservation_mode_off_parameters_test
mysql_reservation_mode_all_parameters_test
mysql_reservation_mode_global_parameters_test
mysql_reservation_mode_out_of_pool_parameters_test
mysql_migrate_opt_record_type
mysql_remove_control_socket_parameters_test
mysql_migrate_client_class_test
|