Skip to content

Commit 769a527

Browse files
committed
Add IpRange IPv4 tests
1 parent 447f069 commit 769a527

10 files changed

+542
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: iprangeclaim-ipv4-apply-update
6+
annotations:
7+
description: Tests if creation and update is successful
8+
# TODO(jstudler): Add update of custom fields
9+
spec:
10+
steps:
11+
- name: Apply CR
12+
try:
13+
- apply:
14+
file: netbox_v1_iprangeclaim.yaml
15+
- name: Check CR spec and status
16+
try:
17+
- assert:
18+
resource:
19+
apiVersion: netbox.dev/v1
20+
kind: IpRangeClaim
21+
metadata:
22+
labels:
23+
app.kubernetes.io/name: netbox-operator
24+
app.kubernetes.io/managed-by: kustomize
25+
name: iprangeclaim-ipv4-apply-update
26+
spec:
27+
tenant: "MY_TENANT"
28+
description: "some description"
29+
comments: "your comments"
30+
parentPrefix: "3.2.0.0/24"
31+
size: 30
32+
status:
33+
(conditions[?type == 'Ready']):
34+
- status: 'True'
35+
endAddress: 3.2.0.30/32
36+
endAddressDotDecimal: 3.2.0.30
37+
ipAddressName: iprangeclaim-ipv4-apply-update
38+
ipRange: 3.2.0.1/32-3.2.0.30/32
39+
ipRangeDotDecimal: 3.2.0.1-3.2.0.30
40+
startAddress: 3.2.0.1/32
41+
startAddressDotDecimal: 3.2.0.1
42+
- assert:
43+
resource:
44+
apiVersion: netbox.dev/v1
45+
kind: IpRange
46+
metadata:
47+
name: iprangeclaim-ipv4-apply-update
48+
finalizers:
49+
- iprange.netbox.dev/finalizer
50+
ownerReferences:
51+
- apiVersion: netbox.dev/v1
52+
blockOwnerDeletion: true
53+
controller: true
54+
kind: IpRangeClaim
55+
name: iprangeclaim-ipv4-apply-update
56+
spec:
57+
comments: your comments
58+
description: some description
59+
startAddress: 3.2.0.1/32
60+
endAddress: 3.2.0.30/32
61+
tenant: MY_TENANT
62+
status:
63+
(conditions[?type == 'Ready']):
64+
- status: 'True'
65+
- name: Update CR
66+
try:
67+
- apply:
68+
file: netbox_v1_iprangeclaim-update.yaml
69+
- name: Check CR spec and status
70+
try:
71+
- assert:
72+
resource:
73+
apiVersion: netbox.dev/v1
74+
kind: IpRangeClaim
75+
metadata:
76+
labels:
77+
app.kubernetes.io/name: netbox-operator
78+
app.kubernetes.io/managed-by: kustomize
79+
name: iprangeclaim-ipv4-apply-update
80+
spec:
81+
tenant: "MY_TENANT"
82+
description: "new description"
83+
comments: "new comments"
84+
parentPrefix: "3.2.0.0/24"
85+
size: 30
86+
status:
87+
(conditions[?type == 'Ready']):
88+
- status: 'True'
89+
endAddress: 3.2.0.30/32
90+
endAddressDotDecimal: 3.2.0.30
91+
ipAddressName: iprangeclaim-ipv4-apply-update
92+
ipRange: 3.2.0.1/32-3.2.0.30/32
93+
ipRangeDotDecimal: 3.2.0.1-3.2.0.30
94+
startAddress: 3.2.0.1/32
95+
startAddressDotDecimal: 3.2.0.1
96+
- assert:
97+
resource:
98+
apiVersion: netbox.dev/v1
99+
kind: IpRange
100+
metadata:
101+
name: iprangeclaim-ipv4-apply-update
102+
finalizers:
103+
- iprange.netbox.dev/finalizer
104+
ownerReferences:
105+
- apiVersion: netbox.dev/v1
106+
blockOwnerDeletion: true
107+
controller: true
108+
kind: IpRangeClaim
109+
name: iprangeclaim-ipv4-apply-update
110+
spec:
111+
comments: new comments
112+
description: new description
113+
startAddress: 3.2.0.1/32
114+
endAddress: 3.2.0.30/32
115+
tenant: MY_TENANT
116+
status:
117+
(conditions[?type == 'Ready']):
118+
- status: 'True'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: netbox.dev/v1
3+
kind: IpRangeClaim
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: netbox-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: iprangeclaim-ipv4-apply-update
9+
spec:
10+
tenant: "MY_TENANT"
11+
description: "new description"
12+
comments: "new comments"
13+
preserveInNetbox: false
14+
parentPrefix: "3.2.0.0/24"
15+
size: 30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: netbox.dev/v1
3+
kind: IpRangeClaim
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: netbox-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: iprangeclaim-ipv4-apply-update
9+
spec:
10+
tenant: "MY_TENANT"
11+
description: "some description"
12+
comments: "your comments"
13+
preserveInNetbox: false
14+
parentPrefix: "3.2.0.0/24"
15+
size: 30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: iprangeclaim-ipv4-prefixexhausted
6+
annotations:
7+
description: Tests if creation fails in case the ParentPrefix is exhausted
8+
spec:
9+
steps:
10+
- name: Apply CR 1
11+
try:
12+
- apply:
13+
file: netbox_v1_iprangeclaim_1.yaml
14+
- name: Check CR 1 spec and status
15+
try:
16+
- assert:
17+
resource:
18+
apiVersion: netbox.dev/v1
19+
kind: IpRangeClaim
20+
metadata:
21+
name: iprangeclaim-ipv4-prefixexhausted-1
22+
spec:
23+
comments: your comments
24+
description: some description
25+
parentPrefix: 3.2.1.0/26
26+
size: 30
27+
tenant: MY_TENANT
28+
status:
29+
(conditions[?type == 'Ready']):
30+
- status: 'True'
31+
endAddress: 3.2.1.30/32
32+
endAddressDotDecimal: 3.2.1.30
33+
ipAddressName: iprangeclaim-ipv4-prefixexhausted-1
34+
ipRange: 3.2.1.1/32-3.2.1.30/32
35+
ipRangeDotDecimal: 3.2.1.1-3.2.1.30
36+
startAddress: 3.2.1.1/32
37+
startAddressDotDecimal: 3.2.1.1
38+
- assert:
39+
resource:
40+
apiVersion: netbox.dev/v1
41+
kind: IpRange
42+
metadata:
43+
name: iprangeclaim-ipv4-prefixexhausted-1
44+
finalizers:
45+
- iprange.netbox.dev/finalizer
46+
ownerReferences:
47+
- apiVersion: netbox.dev/v1
48+
blockOwnerDeletion: true
49+
controller: true
50+
kind: IpRangeClaim
51+
name: iprangeclaim-ipv4-prefixexhausted-1
52+
spec:
53+
comments: your comments
54+
description: some description
55+
startAddress: 3.2.1.1/32
56+
tenant: MY_TENANT
57+
status:
58+
(conditions[?type == 'Ready']):
59+
- status: 'True'
60+
- name: Apply CR 2
61+
try:
62+
- apply:
63+
file: netbox_v1_iprangeclaim_2.yaml
64+
- name: Check CR 2 spec and status
65+
try:
66+
- assert:
67+
resource:
68+
apiVersion: netbox.dev/v1
69+
kind: IpRangeClaim
70+
metadata:
71+
name: iprangeclaim-ipv4-prefixexhausted-2
72+
spec:
73+
comments: your comments
74+
description: some description
75+
parentPrefix: 3.2.1.0/26
76+
size: 30
77+
tenant: MY_TENANT
78+
status:
79+
(conditions[?type == 'Ready']):
80+
- status: 'True'
81+
endAddress: 3.2.1.60/32
82+
endAddressDotDecimal: 3.2.1.60
83+
ipAddressName: iprangeclaim-ipv4-prefixexhausted-2
84+
ipRange: 3.2.1.31/32-3.2.1.60/32
85+
ipRangeDotDecimal: 3.2.1.31-3.2.1.60
86+
startAddress: 3.2.1.31/32
87+
startAddressDotDecimal: 3.2.1.31
88+
- assert:
89+
resource:
90+
apiVersion: netbox.dev/v1
91+
kind: IpRange
92+
metadata:
93+
name: iprangeclaim-ipv4-prefixexhausted-2
94+
finalizers:
95+
- iprange.netbox.dev/finalizer
96+
ownerReferences:
97+
- apiVersion: netbox.dev/v1
98+
blockOwnerDeletion: true
99+
controller: true
100+
kind: IpRangeClaim
101+
name: iprangeclaim-ipv4-prefixexhausted-2
102+
spec:
103+
comments: your comments
104+
description: some description
105+
startAddress: 3.2.1.31/32
106+
endAddress: 3.2.1.60/32
107+
tenant: MY_TENANT
108+
status:
109+
(conditions[?type == 'Ready']):
110+
- status: 'True'
111+
- name: Apply CR 3
112+
try:
113+
- apply:
114+
file: netbox_v1_iprangeclaim_3.yaml
115+
- name: Check CR 3 spec and status and verify it fails
116+
try:
117+
- assert:
118+
resource:
119+
apiVersion: netbox.dev/v1
120+
kind: IpRangeClaim
121+
metadata:
122+
name: iprangeclaim-ipv4-prefixexhausted-3
123+
spec:
124+
comments: your comments
125+
description: some description
126+
parentPrefix: 3.2.1.0/26
127+
size: 30
128+
tenant: MY_TENANT
129+
status:
130+
(conditions[?type == 'IPRangeAssigned']): # TODO(jstudler): Change this to Ready, will need change in SetConditionAndCreateEvent to also update Ready condition
131+
- status: 'False'
132+
- assert:
133+
resource:
134+
apiVersion: v1
135+
count: 1
136+
kind: Event
137+
type: Warning
138+
reason: IPRangeCRNotCreated
139+
source:
140+
component: ip-range-claim-controller
141+
message: Failed to fetch new IP Range from NetBox. Check the logs for more information.
142+
involvedObject:
143+
apiVersion: netbox.dev/v1
144+
kind: IpRangeClaim
145+
name: iprangeclaim-ipv4-prefixexhausted-3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: netbox.dev/v1
3+
kind: IpRangeClaim
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: netbox-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: iprangeclaim-ipv4-prefixexhausted-1
9+
spec:
10+
tenant: "MY_TENANT"
11+
description: "some description"
12+
comments: "your comments"
13+
preserveInNetbox: false
14+
parentPrefix: "3.2.1.0/26"
15+
size: 30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: netbox.dev/v1
3+
kind: IpRangeClaim
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: netbox-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: iprangeclaim-ipv4-prefixexhausted-2
9+
spec:
10+
tenant: "MY_TENANT"
11+
description: "some description"
12+
comments: "your comments"
13+
preserveInNetbox: false
14+
parentPrefix: "3.2.1.0/26"
15+
size: 30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: netbox.dev/v1
3+
kind: IpRangeClaim
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: netbox-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: iprangeclaim-ipv4-prefixexhausted-3
9+
spec:
10+
tenant: "MY_TENANT"
11+
description: "some description"
12+
comments: "your comments"
13+
preserveInNetbox: false
14+
parentPrefix: "3.2.1.0/26"
15+
size: 30

0 commit comments

Comments
 (0)