From 447241e6c3bd05cf186af0e1c701a7314e62bd9b Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 26 Nov 2017 15:14:49 +0000 Subject: [PATCH] tests: improve coverage Add error condition checks. Add lease file binding states. Check all output formats. Check leases file that is in mad order, cse all sorting methods when checking this. Use json output to check status classfications. Add cidr range checks. Add conf include and comment parsing input checks. Signed-off-by: Sami Kerola --- tests/Makemodule.am | 8 + tests/binding-states | 14 ++ tests/cidr-v4 | 1 + tests/cidr-v6 | 1 + tests/confs/binding-states | 1 + tests/confs/cidr-v4 | 31 ++++ tests/confs/cidr-v6 | 10 ++ tests/confs/formats | 1 + tests/confs/shnet-alarm | 32 +--- tests/confs/shufled | 1 + tests/confs/statuses | 1 + tests/errors | 48 ++++++ tests/expected/big-small | 11 +- tests/expected/binding-states | 16 ++ tests/expected/bootp | 11 +- tests/expected/cidr-v4 | 16 ++ tests/expected/cidr-v6 | 11 ++ tests/expected/errors | 18 +++ tests/expected/formats | 284 ++++++++++++++++++++++++++++++++++ tests/expected/parser | 1 + tests/expected/shufled | 16 ++ tests/expected/statuses | 29 ++++ tests/formats | 37 +++++ tests/leases/binding-states | 241 +++++++++++++++++++++++++++++ tests/leases/cidr-v4 | 1 + tests/leases/cidr-v6 | 1 + tests/leases/formats | 1 + tests/leases/parser | 1 + tests/leases/shufled | 198 ++++++++++++++++++++++++ tests/leases/statuses | 1 + tests/parser | 30 ++++ tests/shufled | 15 ++ tests/statuses | 22 +++ 33 files changed, 1059 insertions(+), 51 deletions(-) create mode 100755 tests/binding-states create mode 120000 tests/cidr-v4 create mode 120000 tests/cidr-v6 create mode 120000 tests/confs/binding-states create mode 100644 tests/confs/cidr-v4 create mode 100644 tests/confs/cidr-v6 create mode 120000 tests/confs/formats mode change 100644 => 120000 tests/confs/shnet-alarm create mode 120000 tests/confs/shufled create mode 120000 tests/confs/statuses create mode 100755 tests/errors mode change 100644 => 120000 tests/expected/big-small create mode 100644 tests/expected/binding-states mode change 100644 => 120000 tests/expected/bootp create mode 100644 tests/expected/cidr-v4 create mode 100644 tests/expected/cidr-v6 create mode 100644 tests/expected/errors create mode 100644 tests/expected/formats create mode 120000 tests/expected/parser create mode 100644 tests/expected/shufled create mode 100644 tests/expected/statuses create mode 100755 tests/formats create mode 100644 tests/leases/binding-states create mode 120000 tests/leases/cidr-v4 create mode 120000 tests/leases/cidr-v6 create mode 120000 tests/leases/formats create mode 120000 tests/leases/parser create mode 100644 tests/leases/shufled create mode 120000 tests/leases/statuses create mode 100755 tests/parser create mode 100755 tests/shufled create mode 100755 tests/statuses diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 1372324..8e31e8e 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -11,21 +11,29 @@ TESTS = \ tests/alarm-warning-snets \ tests/shnet-alarm \ tests/big-small \ + tests/binding-states \ tests/bootp \ + tests/cidr-v4 \ + tests/cidr-v6 \ tests/complete \ tests/complete-perfdata \ tests/empty \ + tests/errors \ tests/full-json \ tests/full-xml \ + tests/formats \ tests/leading0 \ tests/one-ip \ tests/one-line \ + tests/parser \ tests/range4 \ tests/range6 \ tests/same-twice \ + tests/shufled \ tests/simple \ tests/skip \ tests/sorts \ + tests/statuses \ tests/v6 \ tests/v6-perfdata diff --git a/tests/binding-states b/tests/binding-states new file mode 100755 index 0000000..a5e98d0 --- /dev/null +++ b/tests/binding-states @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Minimal regression test suite. + +IAM=$(basename $0) + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=never \ + -l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $? diff --git a/tests/cidr-v4 b/tests/cidr-v4 new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/tests/cidr-v4 @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/tests/cidr-v6 b/tests/cidr-v6 new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/tests/cidr-v6 @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/tests/confs/binding-states b/tests/confs/binding-states new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/confs/binding-states @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/confs/cidr-v4 b/tests/confs/cidr-v4 new file mode 100644 index 0000000..18ba31c --- /dev/null +++ b/tests/confs/cidr-v4 @@ -0,0 +1,31 @@ +shared-network example1 { + subnet 10.0.0.0 netmask 255.255.255.0 { + pool { + range 10.0.0.1/27; + } + } + subnet 10.1.0.0 netmask 255.255.255.0 { + pool { + range 10.1.0.1/27; + } + } +} + +shared-network example2 { + subnet 10.2.0.0 netmask 255.255.255.0 { + pool { + range 10.2.0.1/27; + } + } + subnet 10.3.0.0 netmask 255.255.255.0 { + pool { + range 10.3.0.1/27; + } + } +} + +subnet 10.4.0.0 netmask 255.255.255.0 { + pool { + range 10.4.0.1/28; + } +} diff --git a/tests/confs/cidr-v6 b/tests/confs/cidr-v6 new file mode 100644 index 0000000..a57036c --- /dev/null +++ b/tests/confs/cidr-v6 @@ -0,0 +1,10 @@ +subnet6 dead:abba:1000::/56 { + range6 dead:abba:1000::2/120; + prefix6 dead:abba:1000:0100:: dead:abba:1000:ff00::/56; +} + +subnet6 dead:abba:40ff::/56 { + range6 dead:abba:4000::2/120; + prefix6 dead:abba:4000:0100:: dead:abba:4000:ff00::/56; +} + diff --git a/tests/confs/formats b/tests/confs/formats new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/confs/formats @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/confs/shnet-alarm b/tests/confs/shnet-alarm deleted file mode 100644 index 0ef9eb0..0000000 --- a/tests/confs/shnet-alarm +++ /dev/null @@ -1,31 +0,0 @@ -shared-network example1 { - subnet 10.0.0.0 netmask 255.255.255.0 { - pool { - range 10.0.0.1 10.0.0.20; - } - } - subnet 10.1.0.0 netmask 255.255.255.0 { - pool { - range 10.1.0.1 10.1.0.20; - } - } -} - -shared-network example2 { - subnet 10.2.0.0 netmask 255.255.255.0 { - pool { - range 10.2.0.1 10.2.0.20; - } - } - subnet 10.3.0.0 netmask 255.255.255.0 { - pool { - range 10.3.0.1 10.3.0.20; - } - } -} - -subnet 10.4.0.0 netmask 255.255.255.0 { - pool { - range 10.4.0.1 10.4.0.20; - } -} diff --git a/tests/confs/shnet-alarm b/tests/confs/shnet-alarm new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/confs/shnet-alarm @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/confs/shufled b/tests/confs/shufled new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/confs/shufled @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/confs/statuses b/tests/confs/statuses new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/confs/statuses @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/errors b/tests/errors new file mode 100755 index 0000000..49a4f11 --- /dev/null +++ b/tests/errors @@ -0,0 +1,48 @@ +#!/bin/sh +# +# Test error inputs. + +IAM=$(basename $0) + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +echo '=== output mask' >| tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + -L 88 >> tests/outputs/$IAM 2>&1 + +echo '=== unknown specifier' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + --skip=okish >> tests/outputs/$IAM 2>&1 + +echo '=== color mode' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + --color=sometimes >> tests/outputs/$IAM 2>&1 + +echo '=== IPv5' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + --ip-version=5 >> tests/outputs/$IAM 2>&1 + +echo '=== missing conf' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete_NXFILE -l $top_srcdir/tests/leases/complete 2>&1 | \ + sed 's/: ..\/..\/tests/: .\/tests/'>> tests/outputs/$IAM + +echo '=== missing leases' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete_NXFILE 2>&1 | \ + sed 's/: ..\/..\/tests/: .\/tests/' >> tests/outputs/$IAM + +echo '=== html table' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + --format=html >> tests/outputs/$IAM 2>&1 + +echo '=== none existing format' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + -fz >> tests/outputs/$IAM 2>&1 + +echo '=== broken percent input' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \ + --warning=eighty >> tests/outputs/$IAM 2>&1 + +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $? diff --git a/tests/expected/big-small b/tests/expected/big-small deleted file mode 100644 index da14b05..0000000 --- a/tests/expected/big-small +++ /dev/null @@ -1,10 +0,0 @@ -Ranges: -shared net name first ip last ip max cur percent touch t+c t+c perc -All networks 10.0.0.1 - 10.0.0.10 10 10 100.000 0 10 100.000 - -Shared networks: -name max cur percent touch t+c t+c perc - -Sum of all ranges: -name max cur percent touch t+c t+c perc -All networks 10 10 100.000 0 10 100.000 diff --git a/tests/expected/big-small b/tests/expected/big-small new file mode 120000 index 0000000..8fd3246 --- /dev/null +++ b/tests/expected/big-small @@ -0,0 +1 @@ +simple \ No newline at end of file diff --git a/tests/expected/binding-states b/tests/expected/binding-states new file mode 100644 index 0000000..840db2c --- /dev/null +++ b/tests/expected/binding-states @@ -0,0 +1,16 @@ +Ranges: +shared net name first ip last ip max cur percent touch t+c t+c perc bu bu perc +example1 10.0.0.1 - 10.0.0.20 20 4 20.000 3 7 35.000 2 10.000 +example1 10.1.0.1 - 10.1.0.20 20 10 50.000 0 10 50.000 0 0.000 +example2 10.2.0.1 - 10.2.0.20 20 8 40.000 0 8 40.000 0 0.000 +example2 10.3.0.1 - 10.3.0.20 20 9 45.000 0 9 45.000 0 0.000 +All networks 10.4.0.1 - 10.4.0.20 20 5 25.000 0 5 25.000 0 0.000 + +Shared networks: +name max cur percent touch t+c t+c perc bu bu perc +example1 40 14 35.000 3 17 42.500 2 5.000 +example2 40 17 42.500 0 17 42.500 0 0.000 + +Sum of all ranges: +name max cur percent touch t+c t+c perc bu bu perc +All networks 100 36 36.000 3 39 39.000 2 2.000 diff --git a/tests/expected/bootp b/tests/expected/bootp deleted file mode 100644 index da14b05..0000000 --- a/tests/expected/bootp +++ /dev/null @@ -1,10 +0,0 @@ -Ranges: -shared net name first ip last ip max cur percent touch t+c t+c perc -All networks 10.0.0.1 - 10.0.0.10 10 10 100.000 0 10 100.000 - -Shared networks: -name max cur percent touch t+c t+c perc - -Sum of all ranges: -name max cur percent touch t+c t+c perc -All networks 10 10 100.000 0 10 100.000 diff --git a/tests/expected/bootp b/tests/expected/bootp new file mode 120000 index 0000000..8fd3246 --- /dev/null +++ b/tests/expected/bootp @@ -0,0 +1 @@ +simple \ No newline at end of file diff --git a/tests/expected/cidr-v4 b/tests/expected/cidr-v4 new file mode 100644 index 0000000..db0e50e --- /dev/null +++ b/tests/expected/cidr-v4 @@ -0,0 +1,16 @@ +Ranges: +shared net name first ip last ip max cur percent touch t+c t+c perc +example1 10.0.0.1 - 10.0.0.31 31 11 35.484 0 11 35.484 +example1 10.1.0.1 - 10.1.0.31 31 10 32.258 0 10 32.258 +example2 10.2.0.1 - 10.2.0.31 31 8 25.806 0 8 25.806 +example2 10.3.0.1 - 10.3.0.31 31 9 29.032 0 9 29.032 +All networks 10.4.0.1 - 10.4.0.15 15 5 33.333 0 5 33.333 + +Shared networks: +name max cur percent touch t+c t+c perc +example1 62 21 33.871 0 21 33.871 +example2 62 17 27.419 0 17 27.419 + +Sum of all ranges: +name max cur percent touch t+c t+c perc +All networks 139 43 30.935 0 43 30.935 diff --git a/tests/expected/cidr-v6 b/tests/expected/cidr-v6 new file mode 100644 index 0000000..04a2462 --- /dev/null +++ b/tests/expected/cidr-v6 @@ -0,0 +1,11 @@ +Ranges: +shared net name first ip last ip max cur percent touch t+c t+c perc +All networks dead:abba:1000::2 - dead:abba:1000::ff 254 0 0.000 0 0 0.000 +All networks dead:abba:4000::2 - dead:abba:4000::ff 254 1 0.394 0 1 0.394 + +Shared networks: +name max cur percent touch t+c t+c perc + +Sum of all ranges: +name max cur percent touch t+c t+c perc +All networks 508 1 0.197 0 1 0.197 diff --git a/tests/expected/errors b/tests/expected/errors new file mode 100644 index 0000000..b85e282 --- /dev/null +++ b/tests/expected/errors @@ -0,0 +1,18 @@ +=== output mask +dhcpd-pools: return_limit: output mask '88' is illegal +=== unknown specifier +dhcpd-pools: unknown --skip specifier: okish +=== color mode +dhcpd-pools: unknown color mode: 'sometimes' +=== IPv5 +dhcpd-pools: unknown --ip-version argument: 5 +=== missing conf +dhcpd-pools: parse_config: ./tests/confs/complete_NXFILE: No such file or directory +=== missing leases +dhcpd-pools: parse_leases: ./tests/leases/complete_NXFILE: No such file or directory +=== html table +dhcpd-pools: html table only output format is deprecated +=== none existing format +dhcpd-pools: unknown output format: 'z' +=== broken percent input +dhcpd-pools: illegal argument: 'eighty' diff --git a/tests/expected/formats b/tests/expected/formats new file mode 100644 index 0000000..6aa6432 --- /dev/null +++ b/tests/expected/formats @@ -0,0 +1,284 @@ +=== color text +Ranges: +shared net name first ip last ip max cur percent touch t+c t+c perc +example1 10.0.0.1 - 10.0.0.20 20 11 55.000 0 11 55.000 +example1 10.1.0.1 - 10.1.0.20 20 10 50.000 0 10 50.000 +example2 10.2.0.1 - 10.2.0.20 20 8 40.000 0 8 40.000 +example2 10.3.0.1 - 10.3.0.20 20 9 45.000 0 9 45.000 +All networks 10.4.0.1 - 10.4.0.20 20 5 25.000 0 5 25.000 + +Shared networks: +name max cur percent touch t+c t+c perc +example1 40 21 52.500 0 21 52.500 +example2 40 17 42.500 0 17 42.500 + +Sum of all ranges: +name max cur percent touch t+c t+c perc +All networks 100 43 43.000 0 43 43.000 +=== html + + + +ISC dhcpd dhcpd-pools output + + + + + + + + +
+

ISC DHCPD status

+

Sum of all

+ + + + + + + + + + + + + + + + + + + + + + + + + +
namemaxcurfreepercenttoucht+ct+c perc
All networks100435743.00004343.000
+

Shared networks

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namemaxcurfreepercenttoucht+ct+c perc
example140211952.502152.500
example240172342.501742.500
+

Ranges

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
shared net namefirst iplast ipmaxcurfreepercenttoucht+ct+c perc
example110.0.0.110.0.0.20201195501155.000
example110.1.0.110.1.0.202010105001050.000
example210.2.0.110.2.0.2020812400840.000
example210.3.0.110.3.0.2020911450945.000
All networks10.4.0.110.4.0.2020515250525.000
+
+ + + + + +=== xml + + + example1 + 10.0.0.1 - 10.0.0.20 + 20 + 11 + 0 + 9 + + + example1 + 10.1.0.1 - 10.1.0.20 + 20 + 10 + 0 + 10 + + + example2 + 10.2.0.1 - 10.2.0.20 + 20 + 8 + 0 + 12 + + + example2 + 10.3.0.1 - 10.3.0.20 + 20 + 9 + 0 + 11 + + + All networks + 10.4.0.1 - 10.4.0.20 + 20 + 5 + 0 + 15 + + + example1 + 40 + 21 + 0 + 19 + + + example2 + 40 + 17 + 0 + 23 + + + All networks + 100 + 43 + 0 + 57 + + +=== csv +"Ranges:" +"shared net name","first ip","last ip","max","cur","percent","touch","t+c","t+c perc" +"example1","10.0.0.1","10.0.0.20","20","11","55.000","0","11","55.000" +"example1","10.1.0.1","10.1.0.20","20","10","50.000","0","10","50.000" +"example2","10.2.0.1","10.2.0.20","20","8","40.000","0","8","40.000" +"example2","10.3.0.1","10.3.0.20","20","9","45.000","0","9","45.000" +"All networks","10.4.0.1","10.4.0.20","20","5","25.000","0","5","25.000" + +"Shared networks:" +"name","max","cur","percent","touch","t+c","t+c perc" +"example1","40","21","52.500","0","21","52.500" +"example2","40","17","42.500","0","17","42.500" + +"Sum of all ranges:" +"name","max","cur","percent","touch","t+c","t+c perc" +"All networks","100","43","43.000","0","43","43.000" +=== json +{ + "subnets": [ + { "location":"example1", "range":"10.0.0.1 - 10.0.0.20", "first_ip":"10.0.0.1", "last_ip":"10.0.0.20", "defined":20, "used":11, "touched":0, "free":9, "percent":55, "touch_count":11, "touch_percent":55, "status":0 }, + { "location":"example1", "range":"10.1.0.1 - 10.1.0.20", "first_ip":"10.1.0.1", "last_ip":"10.1.0.20", "defined":20, "used":10, "touched":0, "free":10, "percent":50, "touch_count":10, "touch_percent":50, "status":0 }, + { "location":"example2", "range":"10.2.0.1 - 10.2.0.20", "first_ip":"10.2.0.1", "last_ip":"10.2.0.20", "defined":20, "used":8, "touched":0, "free":12, "percent":40, "touch_count":8, "touch_percent":40, "status":0 }, + { "location":"example2", "range":"10.3.0.1 - 10.3.0.20", "first_ip":"10.3.0.1", "last_ip":"10.3.0.20", "defined":20, "used":9, "touched":0, "free":11, "percent":45, "touch_count":9, "touch_percent":45, "status":0 }, + { "location":"All networks", "range":"10.4.0.1 - 10.4.0.20", "first_ip":"10.4.0.1", "last_ip":"10.4.0.20", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":0 } + ], + "shared-networks": [ + { "location":"example1", "defined":40, "used":21, "touched":0, "free":19, "percent":52.5, "touch_count":21, "touch_percent":52.5, "status":0 }, + { "location":"example2", "defined":40, "used":17, "touched":0, "free":23, "percent":42.5, "touch_count":17, "touch_percent":42.5, "status":0 } + ] +} +=== perfdata +CRITICAL: dhcpd-pools: Ranges - crit: 3 warn: 2 ok: 0; | range_crit=3 range_warn=2 range_ok=0 10.4.0.1_r=5;4;8;0;20 10.4.0.1_rt=0 10.3.0.1_r=9;4;8;0;20 10.3.0.1_rt=0 10.2.0.1_r=8;4;8;0;20 10.2.0.1_rt=0 10.1.0.1_r=10;4;8;0;20 10.1.0.1_rt=0 10.0.0.1_r=11;4;8;0;20 10.0.0.1_rt=0 +Shared nets - crit: 2 warn: 0 ok: 0; | snet_crit=2 snet_warn=0 snet_ok=0 'example1_s'=21;8;16;0;40 'example1_st'=0 'example2_s'=17;8;16;0;40 'example2_st'=0 + diff --git a/tests/expected/parser b/tests/expected/parser new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/expected/parser @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/expected/shufled b/tests/expected/shufled new file mode 100644 index 0000000..ed34a85 --- /dev/null +++ b/tests/expected/shufled @@ -0,0 +1,16 @@ +Ranges: +shared net name first ip last ip max cur percent touch t+c t+c perc +All networks 10.4.0.1 - 10.4.0.20 20 3 15.000 0 3 15.000 +example1 10.0.0.1 - 10.0.0.20 20 9 45.000 0 9 45.000 +example1 10.1.0.1 - 10.1.0.20 20 4 20.000 0 4 20.000 +example2 10.2.0.1 - 10.2.0.20 20 4 20.000 0 4 20.000 +example2 10.3.0.1 - 10.3.0.20 20 3 15.000 0 3 15.000 + +Shared networks: +name max cur percent touch t+c t+c perc +example1 40 13 32.500 0 13 32.500 +example2 40 7 17.500 0 7 17.500 + +Sum of all ranges: +name max cur percent touch t+c t+c perc +All networks 100 23 23.000 0 23 23.000 diff --git a/tests/expected/statuses b/tests/expected/statuses new file mode 100644 index 0000000..908b5a2 --- /dev/null +++ b/tests/expected/statuses @@ -0,0 +1,29 @@ +{ + "subnets": [ + { "location":"example1", "range":"10.0.0.1 - 10.0.0.20", "first_ip":"10.0.0.1", "last_ip":"10.0.0.20", "defined":20, "used":11, "touched":0, "free":9, "percent":55, "touch_count":11, "touch_percent":55, "status":4 }, + { "location":"example1", "range":"10.1.0.1 - 10.1.0.20", "first_ip":"10.1.0.1", "last_ip":"10.1.0.20", "defined":20, "used":10, "touched":0, "free":10, "percent":50, "touch_count":10, "touch_percent":50, "status":4 }, + { "location":"example2", "range":"10.2.0.1 - 10.2.0.20", "first_ip":"10.2.0.1", "last_ip":"10.2.0.20", "defined":20, "used":8, "touched":0, "free":12, "percent":40, "touch_count":8, "touch_percent":40, "status":4 }, + { "location":"example2", "range":"10.3.0.1 - 10.3.0.20", "first_ip":"10.3.0.1", "last_ip":"10.3.0.20", "defined":20, "used":9, "touched":0, "free":11, "percent":45, "touch_count":9, "touch_percent":45, "status":4 }, + { "location":"10.4.0.0/24", "range":"10.4.0.1 - 10.4.0.20", "first_ip":"10.4.0.1", "last_ip":"10.4.0.20", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":4 } + ], + "shared-networks": [ + { "location":"example1", "defined":40, "used":21, "touched":0, "free":19, "percent":52.5, "touch_count":21, "touch_percent":52.5, "status":2 }, + { "location":"example2", "defined":40, "used":17, "touched":0, "free":23, "percent":42.5, "touch_count":17, "touch_percent":42.5, "status":2 }, + { "location":"10.4.0.0/24", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":1 } + ] +} +== minsize +{ + "subnets": [ + { "location":"example1", "range":"10.0.0.1 - 10.0.0.20", "first_ip":"10.0.0.1", "last_ip":"10.0.0.20", "defined":20, "used":11, "touched":0, "free":9, "percent":55, "touch_count":11, "touch_percent":55, "status":3 }, + { "location":"example1", "range":"10.1.0.1 - 10.1.0.20", "first_ip":"10.1.0.1", "last_ip":"10.1.0.20", "defined":20, "used":10, "touched":0, "free":10, "percent":50, "touch_count":10, "touch_percent":50, "status":3 }, + { "location":"example2", "range":"10.2.0.1 - 10.2.0.20", "first_ip":"10.2.0.1", "last_ip":"10.2.0.20", "defined":20, "used":8, "touched":0, "free":12, "percent":40, "touch_count":8, "touch_percent":40, "status":3 }, + { "location":"example2", "range":"10.3.0.1 - 10.3.0.20", "first_ip":"10.3.0.1", "last_ip":"10.3.0.20", "defined":20, "used":9, "touched":0, "free":11, "percent":45, "touch_count":9, "touch_percent":45, "status":3 }, + { "location":"10.4.0.0/24", "range":"10.4.0.1 - 10.4.0.20", "first_ip":"10.4.0.1", "last_ip":"10.4.0.20", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":3 } + ], + "shared-networks": [ + { "location":"example1", "defined":40, "used":21, "touched":0, "free":19, "percent":52.5, "touch_count":21, "touch_percent":52.5, "status":2 }, + { "location":"example2", "defined":40, "used":17, "touched":0, "free":23, "percent":42.5, "touch_count":17, "touch_percent":42.5, "status":2 }, + { "location":"10.4.0.0/24", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":3 } + ] +} diff --git a/tests/formats b/tests/formats new file mode 100755 index 0000000..254a37b --- /dev/null +++ b/tests/formats @@ -0,0 +1,37 @@ +#!/bin/sh +# +# Minimal regression test suite. + +IAM=$(basename $0) + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +echo '=== color text' > tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=always \ + -l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM + +echo '=== html' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=always --format=H \ + -l $top_srcdir/tests/leases/$IAM | + sed '/was last modified at/d; /Generated using/d' >> tests/outputs/$IAM + +echo '=== xml' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM -fx \ + -l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM + +echo '=== csv' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM -fc \ + -l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM + +echo '=== json' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM -fj --limit=33 \ + -l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM + +echo '=== perfdata' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --perfdata --warning=20 --critical=40 \ + -l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM + +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $? diff --git a/tests/leases/binding-states b/tests/leases/binding-states new file mode 100644 index 0000000..0d9929f --- /dev/null +++ b/tests/leases/binding-states @@ -0,0 +1,241 @@ +lease 10.0.0.0 { + binding state active; + hardware ethernet 00:00:00:00:00:00; +} + +lease 10.0.0.1 { + binding state free; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.0.0.1 { + binding state active; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.0.0.1 { + binding state abandoned; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.0.0.1 { + binding state expired; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.0.0.1 { + binding state released; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.0.0.1 { + binding state backup; + hardware ethernet 00:00:00:00:00:01; +} + +lease 10.0.0.2 { + binding state free; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.0.0.2 { + binding state abandoned; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.0.0.2 { + binding state expired; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.0.0.2 { + binding state released; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.0.0.2 { + binding state backup; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.0.0.2 { + binding state active; + hardware ethernet 00:00:00:00:00:02; +} + +lease 10.0.0.3 { + binding state free; + hardware ethernet 00:00:00:00:00:03; +} +lease 10.0.0.4 { + binding state active; + hardware ethernet 00:00:00:00:00:04; +} +lease 10.0.0.5 { + binding state expired; + hardware ethernet 00:00:00:00:00:05; +} +lease 10.0.0.6 { + binding state released; + hardware ethernet 00:00:00:00:00:06; +} +lease 10.0.0.7 { + binding state backup; + hardware ethernet 00:00:00:00:00:07; +} +lease 10.0.0.8 { + binding state none-existing-state; + hardware ethernet 00:00:00:00:00:08; +} +lease 10.0.0.9 { + binding state active; + hardware ethernet 00:00:00:00:00:09; +} +lease 10.0.0.20 { + binding state active; + hardware ethernet 00:00:00:00:00:10; +} +lease 10.0.0.21 { + binding state active; + hardware ethernet 00:00:00:00:00:11; +} + + +lease 10.1.0.0 { + binding state active; + hardware ethernet 00:00:00:00:00:00; +} +lease 10.1.0.1 { + binding state active; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.1.0.2 { + binding state active; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.1.0.3 { + binding state active; + hardware ethernet 00:00:00:00:00:03; +} +lease 10.1.0.4 { + binding state active; + hardware ethernet 00:00:00:00:00:04; +} +lease 10.1.0.5 { + binding state active; + hardware ethernet 00:00:00:00:00:05; +} +lease 10.1.0.6 { + binding state active; + hardware ethernet 00:00:00:00:00:06; +} +lease 10.1.0.7 { + binding state active; + hardware ethernet 00:00:00:00:00:07; +} +lease 10.1.0.8 { + binding state active; + hardware ethernet 00:00:00:00:00:08; +} +lease 10.1.0.9 { + binding state active; + hardware ethernet 00:00:00:00:00:09; +} +lease 10.1.0.10 { + binding state active; + hardware ethernet 00:00:00:00:00:10; +} + + +lease 10.2.0.0 { + binding state active; + hardware ethernet 00:00:00:00:00:00; +} +lease 10.2.0.1 { + binding state active; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.2.0.2 { + binding state active; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.2.0.3 { + binding state active; + hardware ethernet 00:00:00:00:00:03; +} +lease 10.2.0.4 { + binding state active; + hardware ethernet 00:00:00:00:00:04; +} +lease 10.2.0.5 { + binding state active; + hardware ethernet 00:00:00:00:00:05; +} +lease 10.2.0.6 { + binding state active; + hardware ethernet 00:00:00:00:00:06; +} +lease 10.2.0.7 { + binding state active; + hardware ethernet 00:00:00:00:00:07; +} +lease 10.2.0.8 { + binding state active; + hardware ethernet 00:00:00:00:00:08; +} + +lease 10.3.0.0 { + binding state active; + hardware ethernet 00:00:00:00:00:00; +} +lease 10.3.0.1 { + binding state active; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.3.0.2 { + binding state active; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.3.0.3 { + binding state active; + hardware ethernet 00:00:00:00:00:03; +} +lease 10.3.0.4 { + binding state active; + hardware ethernet 00:00:00:00:00:04; +} +lease 10.3.0.5 { + binding state active; + hardware ethernet 00:00:00:00:00:05; +} +lease 10.3.0.6 { + binding state active; + hardware ethernet 00:00:00:00:00:06; +} +lease 10.3.0.7 { + binding state active; + hardware ethernet 00:00:00:00:00:07; +} +lease 10.3.0.8 { + binding state active; + hardware ethernet 00:00:00:00:00:08; +} +lease 10.3.0.9 { + binding state active; + hardware ethernet 00:00:00:00:00:09; +} + +lease 10.4.0.0 { + binding state active; + hardware ethernet 00:00:00:00:00:00; +} +lease 10.4.0.1 { + binding state active; + hardware ethernet 00:00:00:00:00:01; +} +lease 10.4.0.2 { + binding state active; + hardware ethernet 00:00:00:00:00:02; +} +lease 10.4.0.3 { + binding state active; + hardware ethernet 00:00:00:00:00:03; +} +lease 10.4.0.4 { + binding state active; + hardware ethernet 00:00:00:00:00:04; +} +lease 10.4.0.5 { + binding state active; + hardware ethernet 00:00:00:00:00:05; +} diff --git a/tests/leases/cidr-v4 b/tests/leases/cidr-v4 new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/leases/cidr-v4 @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/leases/cidr-v6 b/tests/leases/cidr-v6 new file mode 120000 index 0000000..82e3978 --- /dev/null +++ b/tests/leases/cidr-v6 @@ -0,0 +1 @@ +v6 \ No newline at end of file diff --git a/tests/leases/formats b/tests/leases/formats new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/leases/formats @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/leases/parser b/tests/leases/parser new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/leases/parser @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/leases/shufled b/tests/leases/shufled new file mode 100644 index 0000000..723c6ec --- /dev/null +++ b/tests/leases/shufled @@ -0,0 +1,198 @@ +lease 10.0.0.7 { +} + binding state active; + hardware ethernet 00:00:00:00:00:07; + hardware ethernet 00:00:00:00:00:10; +lease 10.2.0.4 { +lease 10.2.0.6 { +lease 10.0.0.11 { + binding state active; +} + hardware ethernet 00:00:00:00:00:03; +lease 10.3.0.9 { +} + hardware ethernet 00:00:00:00:00:04; +} + binding state active; +lease 10.1.0.7 { +} +} +lease 10.1.0.9 { + + hardware ethernet 00:00:00:00:00:07; + hardware ethernet 00:00:00:00:00:01; + binding state active; + binding state active; +} +} +} + binding state active; +lease 10.4.0.1 { +} +lease 10.0.0.0 { +} + hardware ethernet 00:00:00:00:00:10; +} +} + binding state active; + hardware ethernet 00:00:00:00:00:00; +} +} + binding state active; +} +lease 10.3.0.2 { + hardware ethernet 00:00:00:00:00:01; + binding state active; + hardware ethernet 00:00:00:00:00:02; + binding state active; +lease 10.1.0.3 { + binding state active; +} + binding state active; +} +lease 10.1.0.1 { +lease 10.3.0.8 { +lease 10.2.0.1 { + hardware ethernet 00:00:00:00:00:07; +} +} +lease 10.4.0.0 { + hardware ethernet 00:00:00:00:00:01; +} + binding state active; + hardware ethernet 00:00:00:00:00:02; +lease 10.0.0.10 { + binding state active; +} + hardware ethernet 00:00:00:00:00:04; + hardware ethernet 00:00:00:00:00:11; + hardware ethernet 00:00:00:00:00:08; + binding state active; + hardware ethernet 00:00:00:00:00:08; + binding state active; +lease 10.2.0.5 { + hardware ethernet 00:00:00:00:00:01; +lease 10.1.0.8 { + +lease 10.0.0.3 { + binding state active; + binding state active; +lease 10.0.0.1 { +lease 10.4.0.5 { + hardware ethernet 00:00:00:00:00:06; + + hardware ethernet 00:00:00:00:00:06; + hardware ethernet 00:00:00:00:00:02; +lease 10.2.0.3 { + binding state active; +lease 10.1.0.10 { + binding state active; +} +} + binding state active; + hardware ethernet 00:00:00:00:00:03; +} +} + hardware ethernet 00:00:00:00:00:05; +lease 10.0.0.2 { +} + binding state active; +} + hardware ethernet 00:00:00:00:00:06; +lease 10.3.0.6 { +lease 10.0.0.8 { + hardware ethernet 00:00:00:00:00:01; +lease 10.4.0.3 { +} +} +} + binding state active; + binding state active; +lease 10.1.0.6 { +lease 10.1.0.2 { + hardware ethernet 00:00:00:00:00:05; + binding state active; +} +} +lease 10.2.0.7 { +} +} + hardware ethernet 00:00:00:00:00:03; + binding state active; + +} + binding state active; + hardware ethernet 00:00:00:00:00:03; +} +lease 10.1.0.0 { + hardware ethernet 00:00:00:00:00:04; + binding state active; +} +lease 10.3.0.1 { +lease 10.2.0.2 { + binding state active; + hardware ethernet 00:00:00:00:00:09; +} + binding state active; + hardware ethernet 00:00:00:00:00:00; + binding state active; +lease 10.0.0.6 { + hardware ethernet 00:00:00:00:00:02; + binding state active; +} + binding state active; +} +lease 10.3.0.0 { +lease 10.0.0.9 { + binding state active; +lease 10.0.0.4 { + hardware ethernet 00:00:00:00:00:08; + binding state active; + hardware ethernet 00:00:00:00:00:07; + hardware ethernet 00:00:00:00:00:00; + binding state active; +lease 10.1.0.4 { +lease 10.4.0.2 { + binding state active; +} +} +lease 10.3.0.4 { + hardware ethernet 00:00:00:00:00:05; + hardware ethernet 00:00:00:00:00:05; + binding state active; + binding state active; +lease 10.0.0.5 { + hardware ethernet 00:00:00:00:00:04; + binding state active; + hardware ethernet 00:00:00:00:00:02; + binding state active; + hardware ethernet 00:00:00:00:00:09; + hardware ethernet 00:00:00:00:00:08; +lease 10.2.0.8 { +} + binding state active; + binding state active; + hardware ethernet 00:00:00:00:00:06; + hardware ethernet 00:00:00:00:00:00; +lease 10.3.0.7 { +lease 10.4.0.4 { +} + hardware ethernet 00:00:00:00:00:04; +} + binding state active; +lease 10.3.0.3 { + hardware ethernet 00:00:00:00:00:03; +lease 10.2.0.0 { + binding state active; + binding state active; + hardware ethernet 00:00:00:00:00:05; + + binding state active; +} + hardware ethernet 00:00:00:00:00:00; + binding state active; +lease 10.1.0.5 { + hardware ethernet 00:00:00:00:00:09; +lease 10.3.0.5 { +} + diff --git a/tests/leases/statuses b/tests/leases/statuses new file mode 120000 index 0000000..ceb7cbb --- /dev/null +++ b/tests/leases/statuses @@ -0,0 +1 @@ +complete \ No newline at end of file diff --git a/tests/parser b/tests/parser new file mode 100755 index 0000000..94b4e7d --- /dev/null +++ b/tests/parser @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Minimal regression test suite. + +IAM=$(basename $0) + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi +cat <"./${IAM}-conf" +#shared-network "example3 " { +# subnet 10.0.6.0 netmask 255.255.255.0 { +# pool { +# range 10.0.6.1 10.0.6.20; +# } +# } +# subnet 10.1.7.0 netmask 255.255.255.0 { +# pool { +# range 10.1.7.1 10.1.7.20; +# } +# } +#} + +include "tests/confs/complete"; +EOF +dhcpd-pools -c "./${IAM}-conf" --color=never \ + -l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +rm -f "./${IAM}-conf" +exit $? diff --git a/tests/shufled b/tests/shufled new file mode 100755 index 0000000..4f38984 --- /dev/null +++ b/tests/shufled @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Minimal regression test suite. + +IAM=$(basename $0) + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=never \ + --sort nimcptTenimcptTe --sort nimcptTe \ + -l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $? diff --git a/tests/statuses b/tests/statuses new file mode 100755 index 0000000..e603b8a --- /dev/null +++ b/tests/statuses @@ -0,0 +1,22 @@ +#!/bin/sh +# +# Test json status field values. + +IAM=$(basename $0) + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --format=json -L33 \ + -l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM \ + --warning=20 --critical=41 --all-as-shared --snet-alarms --all-as-shared + +echo '== minsize' >> tests/outputs/$IAM +dhcpd-pools -c $top_srcdir/tests/confs/$IAM --format=json --limit 33 \ + -l $top_srcdir/tests/leases/$IAM --minsize=20 \ + --warning=20 --critical=41 --all-as-shared --snet-alarms --all-as-shared \ + >> tests/outputs/$IAM + +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $?