Skip to content

Commit 7b84b80

Browse files
Isidore Reinhardtstgraber
authored andcommitted
tests: Add tests for address sets
Signed-off-by: Isidore Reinhardt <[email protected]>
1 parent 57ada97 commit 7b84b80

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

test/main.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ if [ "${1:-"all"}" != "cluster" ]; then
320320
run_test test_network "network management"
321321
run_test test_network_dhcp_routes "network dhcp routes"
322322
run_test test_network_acl "network ACL management"
323+
run_test test_address_set "network address set"
323324
run_test test_network_forward "network address forwards"
324325
run_test test_network_zone "network DNS zones"
325326
run_test test_idmap "id mapping"

test/suites/network_address_set.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# shellcheck disable=2148
2+
test_address_set() {
3+
ensure_import_testimage
4+
ensure_has_localhost_remote "${INCUS_ADDR}"
5+
6+
! incus network address-set create 2432 || false
7+
incus network address-set create testAS
8+
incus network address-set delete testAS
9+
10+
incus project create testproj -c features.networks=true
11+
incus network address-set create testAS --project testproj
12+
incus network address-set ls --project testproj | grep -q "testAS"
13+
incus network address-set delete testAS --project testproj
14+
incus project delete testproj
15+
16+
cat <<EOF | incus network address-set create testAS
17+
description: Test Address set from STDIN
18+
addresses:
19+
- 192.168.0.1
20+
- 192.168.0.254
21+
external_ids:
22+
user.mykey: foo
23+
EOF
24+
incus network address-set show testAS | grep -q "description: Test Address set from STDIN"
25+
incus network address-set delete testAS
26+
27+
incus network address-set create testAS --description "Listing test"
28+
incus network address-set ls | grep -q "testAS"
29+
incus network address-set delete testAS
30+
31+
incus network address-set create testAS --description "Initial description"
32+
cat <<EOF | incus network address-set edit testAS
33+
description: Updated address set
34+
addresses:
35+
- 10.0.0.1
36+
- 10.0.0.2
37+
external_ids:
38+
user.mykey: bar
39+
EOF
40+
incus network address-set show testAS | grep -q "Updated address set"
41+
incus network address-set delete testAS
42+
43+
incus network address-set create testAS --description "Patch test"
44+
incus query -X PATCH -d "{\"config\": {\"user.myotherkey\": \"bah\"}}" /1.0/network-address-sets/testAS
45+
incus network address-set show testAS | grep -q "user.myotherkey: bah"
46+
incus network address-set delete testAS
47+
48+
incus network address-set create testAS --description "Address add/remove test"
49+
incus network address-set add-addr testAS 192.168.1.100
50+
incus network address-set show testAS | grep -q "192.168.1.100"
51+
incus network address-set del-addr testAS 192.168.1.100
52+
! incus network address-set show testAS | grep -q "192.168.1.100" || false
53+
incus network address-set delete testAS
54+
55+
incus network address-set create testAS --description "Rename test"
56+
incus network address-set rename testAS testAS-renamed
57+
incus network address-set ls | grep -q "testAS-renamed"
58+
incus network address-set delete testAS-renamed
59+
60+
incus network address-set create testAS --description "Custom keys test"
61+
incus network address-set set testAS user.somekey foo
62+
incus network address-set show testAS | grep -q "foo"
63+
incus network address-set delete testAS
64+
65+
! incus network address-set ls | grep -q "testAS" || false
66+
67+
brName="inct$$"
68+
incus network create "${brName}" \
69+
ipv6.dhcp.stateful=true \
70+
ipv4.address=192.0.2.1/24 \
71+
ipv6.address=2001:db8::1/64
72+
73+
incus init testimage testct --network "${brName}"
74+
incus start testct
75+
incus exec testct -- ip a add 192.0.2.2/24 dev eth0
76+
incus exec testct -- ip a add 2001:db8::2/64 dev eth0
77+
78+
incus network address-set create testAS
79+
incus network address-set add-addr testAS 192.0.2.2
80+
81+
incus network acl create allowping
82+
# shellcheck disable=2016
83+
incus network acl rule add allowping ingress action=allow protocol=icmp4 destination='\$testAS' # single quote to avoid expansion
84+
incus network set "${brName}" security.acls="allowping"
85+
ping -c2 192.0.2.2 > /dev/null
86+
incus network address-set del-addr testAS 192.0.2.2
87+
incus network set "${brName}" security.acls=""
88+
incus network acl delete allowping
89+
incus network address-set delete testAS
90+
91+
incus network address-set create testAS
92+
incus network address-set add-addr testAS 192.0.2.2
93+
incus launch testimage testct2
94+
incus exec testct -- ip a add 192.0.2.3/24 dev eth0
95+
incus exec testct -- ip a add 2001:db8::3/64 dev eth0
96+
incus network acl create mixedACL
97+
# shellcheck disable=2016
98+
incus network acl rule add mixedACL ingress action=allow protocol=icmp4 destination='192.0.2.3,\$testAS'
99+
incus network set "${brName}" security.acls="mixedACL"
100+
ping -c2 192.0.2.2 > /dev/null
101+
ping -c2 192.0.2.3 > /dev/null
102+
incus network set "${brName}" security.acls=""
103+
incus network acl delete mixedACL
104+
incus network address-set rm testAS
105+
incus delete testct2 --force
106+
107+
subnet=$(echo 192.0.2.2 | awk -F. '{print $1"."$2"."$3".0/24"}')
108+
incus network address-set create testAS
109+
incus network address-set add-addr testAS "$subnet"
110+
incus network acl create cidrACL
111+
# shellcheck disable=2016
112+
incus network acl rule add cidrACL ingress action=allow protocol=icmp4 destination='\$testAS'
113+
incus network set "${brName}" security.acls="cidrACL"
114+
ping -c2 192.0.2.2 > /dev/null
115+
incus network set "${brName}" security.acls=""
116+
incus network acl delete cidrACL
117+
incus network address-set rm testAS
118+
119+
incus network address-set create testAS
120+
incus network address-set add-addr testAS 192.0.2.1
121+
incus network acl create allowtcp8080
122+
# shellcheck disable=2016
123+
incus network acl rule add allowtcp8080 egress action=allow protocol=tcp destination_port="8080" destination='\$testAS'
124+
incus network set "${brName}" security.acls="allowtcp8080"
125+
nc -l -p 8080 -q0 -s 192.0.2.1 </dev/null >/dev/null &
126+
nc -l -p 8080 -q0 -s 2001:db8::1 </dev/null >/dev/null &
127+
incus exec testct --disable-stdin -- nc -w2 192.0.2.1 8080
128+
incus network address-set add-addr testAS 2001:db8::1
129+
incus exec testct --disable-stdin -- nc -w2 2001:db8::1 8080
130+
incus network address-set del-addr testAS 2001:db8::1
131+
! incus exec testct --disable-stdin -- nc -w2 2001:db8::1 8080 || false
132+
incus network set "${brName}" security.acls=""
133+
incus network acl delete allowtcp8080
134+
incus network address-set rm testAS
135+
incus rm --force testct
136+
137+
incus network delete "${brName}"
138+
}

0 commit comments

Comments
 (0)