Skip to content

Commit 3afcd19

Browse files
committed
Add more realistic tests and separate test Prefixes
1 parent ba69b2e commit 3afcd19

File tree

7 files changed

+216
-9
lines changed

7 files changed

+216
-9
lines changed

kind/load-data-job/local-demo-data.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ VALUES ('2024-06-14 09:57:11.709344+00', '2024-06-14 09:57:11.709359+00', '{"cus
6363
INSERT INTO public.ipam_prefix (created, last_updated, custom_field_data, prefix, status, is_pool, description, role_id, site_id, tenant_id, vlan_id, vrf_id, _children, _depth, mark_utilized, comments)
6464
VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{}', '2.0.0.0/16', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, '');
6565

66+
-- 2.1.0.0/24
67+
INSERT INTO public.ipam_prefix (created, last_updated, custom_field_data, prefix, status, is_pool, description, role_id, site_id, tenant_id, vlan_id, vrf_id, _children, _depth, mark_utilized, comments)
68+
VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{}', '2.1.0.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, '');
69+
70+
-- 2.2.0.0/24
71+
INSERT INTO public.ipam_prefix (created, last_updated, custom_field_data, prefix, status, is_pool, description, role_id, site_id, tenant_id, vlan_id, vrf_id, _children, _depth, mark_utilized, comments)
72+
VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{}', '2.2.0.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, '');
73+
74+
6675
-- 3.0.0.0/24 - 3.0.8.0/24 (watch out for the upper/lower-case)
6776
-- Pool 1, Production (IPv4)
6877
INSERT INTO public.ipam_prefix (created, last_updated, custom_field_data, prefix, status, is_pool, description, role_id, site_id, tenant_id, vlan_id, vrf_id, _children, _depth, mark_utilized, comments)

tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: chainsaw.kyverno.io/v1alpha1
22
kind: Test
33
metadata:
4-
name: apply-ipv4-prefixclaim-parentprefixselector
4+
name: prefixclaim-parentprefix-succeed
55
spec:
66
steps:
77
- name: Setup
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: prefixclaim-restoration-succeed
5+
spec:
6+
steps:
7+
- name: Install for the first time
8+
description: Apply prefix claim CR 1
9+
try:
10+
- apply:
11+
file: netbox_v1_prefixclaim_1.yaml
12+
- name: Install for the first time
13+
description: Apply prefix claim CR 2
14+
try:
15+
- apply:
16+
file: netbox_v1_prefixclaim_2.yaml
17+
- name: Check
18+
description: Go through each field and check for equality
19+
try:
20+
- assert:
21+
resource:
22+
apiVersion: netbox.dev/v1
23+
kind: PrefixClaim
24+
metadata:
25+
name: prefixclaim-sample-1
26+
spec:
27+
comments: your comments
28+
description: some description
29+
parentPrefix: 2.0.0.0/16
30+
prefixLength: /28
31+
preserveInNetbox: true
32+
site: DM-Akron
33+
tenant: Dunder-Mifflin, Inc.
34+
status:
35+
parentPrefix: 2.0.0.0/16
36+
prefix: 2.0.0.0/28
37+
prefixName: prefixclaim-sample-1
38+
- assert:
39+
resource:
40+
apiVersion: netbox.dev/v1
41+
kind: Prefix
42+
metadata:
43+
name: prefixclaim-sample-1
44+
spec:
45+
comments: your comments
46+
description: some description
47+
prefix: 2.0.0.0/28
48+
preserveInNetbox: true
49+
site: DM-Akron
50+
tenant: Dunder-Mifflin, Inc.
51+
customFields:
52+
netboxOperatorRestorationHash: 41d26b0c31287c0ad278d8e1f7e0262e6b660401
53+
- assert:
54+
resource:
55+
apiVersion: netbox.dev/v1
56+
kind: PrefixClaim
57+
metadata:
58+
name: prefixclaim-sample-2
59+
spec:
60+
comments: your comments
61+
description: some description
62+
parentPrefix: 2.0.0.0/16
63+
prefixLength: /28
64+
preserveInNetbox: true
65+
site: DM-Akron
66+
tenant: Dunder-Mifflin, Inc.
67+
status:
68+
parentPrefix: 2.0.0.0/16
69+
prefix: 2.0.0.16/28
70+
prefixName: prefixclaim-sample-2
71+
- assert:
72+
resource:
73+
apiVersion: netbox.dev/v1
74+
kind: Prefix
75+
metadata:
76+
name: prefixclaim-sample-2
77+
spec:
78+
comments: your comments
79+
description: some description
80+
prefix: 2.0.0.16/28
81+
preserveInNetbox: true
82+
site: DM-Akron
83+
tenant: Dunder-Mifflin, Inc.
84+
customFields:
85+
netboxOperatorRestorationHash: adb20d7607542cf106f7d5fcc12985c41adca0c5
86+
- name: Delete the applied CR 1
87+
description: delete prefix claim CR 1 (we only delete CR1, so if the restoration failed to claim, it will take the next available prefix which will be wrong)
88+
try:
89+
- delete:
90+
ref:
91+
apiVersion: netbox.dev/v1
92+
kind: PrefixClaim
93+
name: prefixclaim-sample-1
94+
- name: Install for the second time
95+
description: Apply prefix claim CR 1
96+
try:
97+
- apply:
98+
file: netbox_v1_prefixclaim-1.yaml
99+
- name: Check
100+
description: Go through each field and check for equality
101+
try:
102+
- assert:
103+
resource:
104+
apiVersion: netbox.dev/v1
105+
kind: PrefixClaim
106+
metadata:
107+
name: prefixclaim-sample-1
108+
spec:
109+
comments: your comments
110+
description: some description
111+
parentPrefix: 2.0.0.0/16
112+
prefixLength: /28
113+
preserveInNetbox: true
114+
site: DM-Akron
115+
tenant: Dunder-Mifflin, Inc.
116+
status:
117+
parentPrefix: 2.0.0.0/16
118+
prefix: 2.0.0.0/28
119+
prefixName: prefixclaim-sample-1
120+
- assert:
121+
resource:
122+
apiVersion: netbox.dev/v1
123+
kind: Prefix
124+
metadata:
125+
name: prefixclaim-sample-1
126+
spec:
127+
comments: your comments
128+
description: some description
129+
prefix: 2.0.0.0/28
130+
preserveInNetbox: true
131+
site: DM-Akron
132+
tenant: Dunder-Mifflin, Inc.
133+
customFields:
134+
netboxOperatorRestorationHash: 41d26b0c31287c0ad278d8e1f7e0262e6b660401
135+
- assert:
136+
resource:
137+
apiVersion: netbox.dev/v1
138+
kind: PrefixClaim
139+
metadata:
140+
name: prefixclaim-sample-2
141+
spec:
142+
comments: your comments
143+
description: some description
144+
parentPrefix: 2.0.0.0/16
145+
prefixLength: /28
146+
preserveInNetbox: true
147+
site: DM-Akron
148+
tenant: Dunder-Mifflin, Inc.
149+
status:
150+
parentPrefix: 2.0.0.0/16
151+
prefix: 2.0.0.16/28
152+
prefixName: prefixclaim-sample-2
153+
- assert:
154+
resource:
155+
apiVersion: netbox.dev/v1
156+
kind: Prefix
157+
metadata:
158+
name: prefixclaim-sample-2
159+
spec:
160+
comments: your comments
161+
description: some description
162+
prefix: 2.0.0.16/28
163+
preserveInNetbox: true
164+
site: DM-Akron
165+
tenant: Dunder-Mifflin, Inc.
166+
customFields:
167+
netboxOperatorRestorationHash: adb20d7607542cf106f7d5fcc12985c41adca0c5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: netbox.dev/v1
2+
kind: PrefixClaim
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: netbox-operator
6+
app.kubernetes.io/managed-by: kustomize
7+
name: prefixclaim-sample-1
8+
spec:
9+
tenant: "Dunder-Mifflin, Inc."
10+
site: "DM-Akron"
11+
description: "some description"
12+
comments: "your comments"
13+
preserveInNetbox: true
14+
parentPrefix: "2.0.0.0/16"
15+
prefixLength: "/28"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: netbox.dev/v1
2+
kind: PrefixClaim
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: netbox-operator
6+
app.kubernetes.io/managed-by: kustomize
7+
name: prefixclaim-sample-2
8+
spec:
9+
tenant: "Dunder-Mifflin, Inc."
10+
site: "DM-Akron"
11+
description: "some description"
12+
comments: "your comments"
13+
preserveInNetbox: true
14+
parentPrefix: "2.0.0.0/16"
15+
prefixLength: "/28"

tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenSucceed/chainsaw-test.yaml renamed to tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/chainsaw-test.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
apiVersion: chainsaw.kyverno.io/v1alpha1
22
kind: Test
33
metadata:
4-
name: apply-prefixclaim
4+
name: prefixclaim-apply-succeed
55
spec:
66
steps:
7-
- name: Setup
7+
- name: Install
88
description: Apply prefix claim CR
99
try:
1010
- apply:
@@ -21,14 +21,14 @@ spec:
2121
spec:
2222
comments: your comments
2323
description: some description
24-
parentPrefix: 2.0.0.0/16
24+
parentPrefix: 2.2.0.0/24
2525
prefixLength: /28
2626
preserveInNetbox: true
2727
site: DM-Akron
2828
tenant: Dunder-Mifflin, Inc.
2929
status:
30-
parentPrefix: 2.0.0.0/16
31-
prefix: 2.0.0.0/28
30+
parentPrefix: 2.2.0.0/24
31+
prefix: 2.2.0.0/28
3232
prefixName: prefixclaim-sample
3333
- assert:
3434
resource:
@@ -39,9 +39,10 @@ spec:
3939
spec:
4040
comments: your comments
4141
description: some description
42-
prefix: 2.0.0.0/28
42+
prefix: 2.2.0.0/28
4343
preserveInNetbox: true
4444
site: DM-Akron
4545
tenant: Dunder-Mifflin, Inc.
4646
customFields:
47-
netboxOperatorRestorationHash: d474bdd0899b4360b7c95c98da2ca90324cd932d
47+
netboxOperatorRestorationHash: b7eb93289c22df04284ec5d15d53ddf5ef87c82f
48+

tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml renamed to tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ spec:
1111
description: "some description"
1212
comments: "your comments"
1313
preserveInNetbox: true
14-
parentPrefix: "2.0.0.0/16"
14+
parentPrefix: "2.2.0.0/24"
1515
prefixLength: "/28"

0 commit comments

Comments
 (0)