From 327b3a12f18688e07af28f27cb1ba8e9d9817b03 Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Wed, 18 Dec 2024 11:52:47 +0100 Subject: [PATCH] Migrate populating local demo data through database.sql to using NetBox API (#177) --- kind/load-data-job/dockerfile | 4 + kind/load-data-job/load-data.sh | 2 +- kind/load-data-job/local-data-setup.sql | 3 + kind/load-data-job/local-demo-data.sql | 117 ----- kind/load-data-job/main.py | 465 ++++++++++++++++++ kind/local-env.sh | 20 +- .../chainsaw-test.yaml | 32 +- .../netbox_v1_prefixclaim_1.yaml | 6 +- .../netbox_v1_prefixclaim_2.yaml | 6 +- .../netbox_v1_prefixclaim_3.yaml | 6 +- .../chainsaw-test.yaml | 10 +- .../netbox_v1_prefixclaim.yaml | 6 +- .../chainsaw-test.yaml | 72 +-- .../netbox_v1_prefixclaim_1.yaml | 6 +- .../netbox_v1_prefixclaim_2.yaml | 6 +- .../chainsaw-test.yaml | 18 +- .../netbox_v1_prefixclaim.yaml | 6 +- .../chainsaw-test.yaml | 48 +- .../netbox_v1_prefixclaim_1.yaml | 6 +- .../netbox_v1_prefixclaim_2.yaml | 6 +- .../chainsaw-test.yaml | 8 +- .../netbox_v1_prefixclaim.yaml | 4 +- 22 files changed, 613 insertions(+), 244 deletions(-) create mode 100644 kind/load-data-job/dockerfile create mode 100644 kind/load-data-job/local-data-setup.sql delete mode 100644 kind/load-data-job/local-demo-data.sql create mode 100644 kind/load-data-job/main.py diff --git a/kind/load-data-job/dockerfile b/kind/load-data-job/dockerfile new file mode 100644 index 00000000..7435f45c --- /dev/null +++ b/kind/load-data-job/dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12 +ADD main.py . +RUN pip install pynetbox +CMD ["python", "./main.py"] diff --git a/kind/load-data-job/load-data.sh b/kind/load-data-job/load-data.sh index a98ca9ff..72d1ef40 100755 --- a/kind/load-data-job/load-data.sh +++ b/kind/load-data-job/load-data.sh @@ -4,4 +4,4 @@ TMP_SQL_FILE=$(mktemp /tmp/netbox-data-dump.XXXXXXX.sql) || exit 1 curl -k https://raw.githubusercontent.com/netbox-community/netbox-demo-data/master/sql/netbox-demo-v4.1.sql > "${TMP_SQL_FILE}" psql "user=netbox host=netbox-db.${NAMESPACE}.svc.cluster.local" netbox -q -f "${TMP_SQL_FILE}" rm "${TMP_SQL_FILE}" -psql "user=netbox host=netbox-db.${NAMESPACE}.svc.cluster.local" netbox -q -f /load-data-job/local-demo-data.sql +psql "user=netbox host=netbox-db.${NAMESPACE}.svc.cluster.local" netbox -q -f /load-data-job/local-data-setup.sql diff --git a/kind/load-data-job/local-data-setup.sql b/kind/load-data-job/local-data-setup.sql new file mode 100644 index 00000000..ee80ad8d --- /dev/null +++ b/kind/load-data-job/local-data-setup.sql @@ -0,0 +1,3 @@ +-- insert User Token +INSERT INTO public.users_token (id, created, expires, key, write_enabled, description, user_id, allowed_ips, last_used) +VALUES (1, '2024-06-14 12:20:13.317942+00', NULL, '0123456789abcdef0123456789abcdef01234567', true, 'test-token', 1, '{}', NULL); diff --git a/kind/load-data-job/local-demo-data.sql b/kind/load-data-job/local-demo-data.sql deleted file mode 100644 index 21bbeca4..00000000 --- a/kind/load-data-job/local-demo-data.sql +++ /dev/null @@ -1,117 +0,0 @@ --- create Custom Fields -INSERT INTO public.extras_customfield (id, type, name, label, description, required, filter_logic, "default", weight, validation_minimum, validation_maximum, validation_regex, created, last_updated, related_object_type_id, group_name, search_weight, is_cloneable, choice_set_id, ui_editable, ui_visible, comments, "unique", related_object_filter) -VALUES (2, 'text', 'netboxOperatorRestorationHash', 'Netbox Restoration Hash', 'Used to rediscover previously claimed IP Addresses', false, 'exact', NULL, 100, NULL, NULL, '', '2024-06-13 15:17:08.65334+00', '2024-06-13 15:17:08.653359+00', NULL, 'netbox-operator', 100, false, NULL, 'hidden', 'always', '', false, NULL); - -INSERT INTO public.extras_customfield (id, type, name, label, description, required, filter_logic, "default", weight, validation_minimum, validation_maximum, validation_regex, created, last_updated, related_object_type_id, group_name, search_weight, is_cloneable, choice_set_id, ui_editable, ui_visible, comments, "unique", related_object_filter) -VALUES (3, 'text', 'example_field', 'Example Field', 'example description', false, 'exact', NULL, 100, NULL, NULL, '', '2024-06-13 15:17:08.65334+00', '2024-06-13 15:17:08.653359+00', NULL, 'netbox-operator', 100, false, NULL, 'hidden', 'always', '', false, NULL); - -INSERT INTO public.extras_customfield (id, type, name, label, description, required, filter_logic, "default", weight, validation_minimum, validation_maximum, validation_regex, created, last_updated, related_object_type_id, group_name, search_weight, is_cloneable, choice_set_id, ui_editable, ui_visible, comments, "unique", related_object_filter) -VALUES (4, 'text', 'environment', 'Environment', 'Custom field 1 for ParentPrefixSelector', false, 'exact', NULL, 100, NULL, NULL, '', '2024-06-13 15:17:08.65334+00', '2024-06-13 15:17:08.653359+00', NULL, 'netbox-operator', 100, false, NULL, 'hidden', 'always', '', false, NULL); - -INSERT INTO public.extras_customfield (id, type, name, label, description, required, filter_logic, "default", weight, validation_minimum, validation_maximum, validation_regex, created, last_updated, related_object_type_id, group_name, search_weight, is_cloneable, choice_set_id, ui_editable, ui_visible, comments, "unique", related_object_filter) -VALUES (5, 'text', 'poolName', 'Pool Name', 'Custom field 2 for ParentPrefixSelector', false, 'exact', NULL, 100, NULL, NULL, '', '2024-06-13 15:17:08.65334+00', '2024-06-13 15:17:08.653359+00', NULL, 'netbox-operator', 100, false, NULL, 'hidden', 'always', '', false, NULL); - -INSERT INTO public.extras_customfield (id, type, name, label, description, required, filter_logic, "default", weight, validation_minimum, validation_maximum, validation_regex, created, last_updated, related_object_type_id, group_name, search_weight, is_cloneable, choice_set_id, ui_editable, ui_visible, comments, "unique", related_object_filter) -VALUES (6, 'boolean', 'cfDataTypeBool', 'cf Data Type Bool', 'Custom field 3 for ParentPrefixSelector', false, 'exact', NULL, 100, NULL, NULL, '', '2024-06-13 15:17:08.65334+00', '2024-06-13 15:17:08.653359+00', NULL, 'netbox-operator', 100, false, NULL, 'hidden', 'always', '', false, NULL); - -INSERT INTO public.extras_customfield (id, type, name, label, description, required, filter_logic, "default", weight, validation_minimum, validation_maximum, validation_regex, created, last_updated, related_object_type_id, group_name, search_weight, is_cloneable, choice_set_id, ui_editable, ui_visible, comments, "unique", related_object_filter) -VALUES (7, 'integer', 'cfDataTypeInteger', 'cf Data Type Integer', 'Custom field 4 for ParentPrefixSelector', false, 'exact', NULL, 100, NULL, NULL, '', '2024-06-13 15:17:08.65334+00', '2024-06-13 15:17:08.653359+00', NULL, 'netbox-operator', 100, false, NULL, 'hidden', 'always', '', false, NULL); - --- associate custom fields with IP -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (2, 2, 69); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (3, 3, 69); - --- associate custom fields with Prefix -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (4, 2, 70); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (5, 3, 70); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (6, 4, 70); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (7, 5, 70); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (8, 6, 70); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (9, 7, 70); - --- associate custom fields with IP Range -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (10, 2, 78); - -INSERT INTO public.extras_customfield_object_types (id, customfield_id, objecttype_id) -VALUES (11, 3, 78); - --- insert User Token -INSERT INTO public.users_token (id, created, expires, key, write_enabled, description, user_id, allowed_ips, last_used) -VALUES (1, '2024-06-14 12:20:13.317942+00', NULL, '0123456789abcdef0123456789abcdef01234567', true, 'test-token', 1, '{}', NULL); - --- insert Tenant -INSERT INTO public.tenancy_tenant (created, last_updated, custom_field_data, id, name, slug, description, comments, group_id) -VALUES ('2024-06-14 09:57:11.709344+00', '2024-06-14 09:57:11.709359+00', '{"cust_id": null}', 100, 'MY_TENANT', 'my_tenant', '', '', NULL); - --- insert Prefix --- 2.0.0.0/16 -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) -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, ''); - --- 2.1.0.0/24 -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) -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, ''); - --- 2.2.0.0/24 -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) -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, ''); - --- 3.0.0.0/24 - 3.0.8.0/24 (watch out for the upper/lower-case) --- Pool 1, Production (IPv4) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "Production", "poolName": "Pool 1", "cfDataTypeBool": true, "cfDataTypeInteger": 1}', '3.0.0.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, ''); - -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "Production", "poolName": "Pool 1", "cfDataTypeBool": true, "cfDataTypeInteger": 1}', '3.0.1.0/24', 'active', false, '', NULL, 5, 100, NULL, NULL, 0, 0, false, ''); - --- Pool 1, Development (IPv4) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "Development", "poolName": "Pool 1", "cfDataTypeBool": false, "cfDataTypeInteger": 2}', '3.0.2.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, ''); - --- Pool 2, Production (IPv4) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "Production", "poolName": "Pool 2", "cfDataTypeBool": true, "cfDataTypeInteger": 3}', '3.0.3.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, ''); - -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "Production", "poolName": "Pool 2", "cfDataTypeBool": true, "cfDataTypeInteger": 3}', '3.0.4.0/24', 'active', false, '', NULL, 5, 100, NULL, NULL, 0, 0, false, ''); - --- Pool 2, Development (IPv4) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "Development", "poolName": "Pool 2", "cfDataTypeBool": false, "cfDataTypeInteger": 4}', '3.0.5.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, ''); - --- pool 3, production (IPv4) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "production", "poolName": "pool 3", "cfDataTypeBool": true, "cfDataTypeInteger": 5}', '3.0.6.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, ''); - -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "production", "poolName": "pool 3", "cfDataTypeBool": true, "cfDataTypeInteger": 5}', '3.0.7.0/24', 'active', false, '', NULL, 5, 100, NULL, NULL, 0, 0, false, ''); - --- pool 3, development (IPv4) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "development", "poolName": "pool 3", "cfDataTypeBool": false, "cfDataTypeInteger": 6}', '3.0.8.0/24', 'active', false, '', NULL, NULL, 100, NULL, NULL, 0, 0, false, ''); - --- pool 4, production (IPv6) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "production", "poolName": "pool 4", "cfDataTypeBool": true, "cfDataTypeInteger": 7}', '2::/64', 'active', false, '', NULL, NULL, 5, NULL, NULL, 0, 0, false, ''); - -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "production", "poolName": "pool 4", "cfDataTypeBool": true, "cfDataTypeInteger": 7}', '2:0:0:1::/64', 'active', false, '', NULL, 5, 5, NULL, NULL, 0, 0, false, ''); - --- pool 4, development (IPv6) -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) -VALUES ('2024-06-14 10:01:10.094083+00', '2024-06-14 10:01:10.094095+00', '{"environment": "development", "poolName": "pool 4", "cfDataTypeBool": false, "cfDataTypeInteger": 8}', '2:0:0:2::/64', 'active', false, '', NULL, NULL, 5, NULL, NULL, 0, 0, false, ''); diff --git a/kind/load-data-job/main.py b/kind/load-data-job/main.py new file mode 100644 index 00000000..d9b99a1f --- /dev/null +++ b/kind/load-data-job/main.py @@ -0,0 +1,465 @@ +import pynetbox +from pprint import pprint +from dataclasses import dataclass +import sys + +print("Starting to load data onto NetBox through API") +try: + nb = pynetbox.api( + 'http://netbox', + token='0123456789abcdef0123456789abcdef01234567' + ) +except pynetbox.RequestError as e: + pprint(e.error) + sys.exit(1) +print("Connected to NetBoxAPI") + +# insert Tenants +@dataclass +class Tenant: + name: str + slug: str + custom_fields: dict + +tenants = [ + Tenant( + name="MY_TENANT", + slug="my_tenant", + custom_fields={ + "cust_id": None, + }, + ), + Tenant( + name="MY_TENANT_2", + slug="my_tenant_2", + custom_fields={ + "cust_id": None, + }, + ), +] + +for tenant in tenants: + try: + nb.tenancy.tenants.create( + name=tenant.name, + slug=tenant.slug, + custom_fields=tenant.custom_fields, + ) + except pynetbox.RequestError as e: + pprint(e.error) + sys.exit(1) +print("Tenants loaded") + +# insert Sites +@dataclass +class Site: + name: str + slug: str + status: str + tenant: dict + +sites = [ + Site( + name="MY_SITE", + slug="my_site", + status="active", + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + ), + Site( + name="MY_SITE_2", + slug="my_site_2", + status="active", + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + ), +] + +for site in sites: + try: + nb.dcim.sites.create( + name=site.name, + slug=site.slug, + tenant=site.tenant, + ) + except pynetbox.RequestError as e: + pprint(e.error) + sys.exit(1) +print("Sites loaded") + +# create custom fields and associate custom fields with IP/IPRange/Prefix +@dataclass +class CustomField: + object_types: list[str] + type: str + name: str + label: str + description: str + required: bool + filter_logic: str + +custom_fields = [ + CustomField( + object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"], + type="text", + name="netboxOperatorRestorationHash", + label="Netbox Restoration Hash", + description="Used to rediscover previously claimed IP Addresses", + required=False, + filter_logic="exact" + ), + CustomField( + object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"], + type="text", + name="example_field", + label="Example Field", + description="example description", + required=False, + filter_logic="exact" + ), + CustomField( + object_types=["ipam.prefix"], + type="text", + name="environment", + label="Environment", + description="Custom field 1 for ParentPrefixSelector", + required=False, + filter_logic="exact" + ), + CustomField( + object_types=["ipam.prefix"], + type="text", + name="poolName", + label="Pool Name", + description="Custom field 2 for ParentPrefixSelector", + required=False, + filter_logic="exact" + ), + CustomField( + object_types=["ipam.prefix"], + type="boolean", + name="cfDataTypeBool", + label="cf Data Type Bool", + description="Custom field 3 for ParentPrefixSelector", + required=False, + filter_logic="exact" + ), + CustomField( + object_types=["ipam.prefix"], + type="integer", + name="cfDataTypeInteger", + label="cf Data Type Integer", + description="Custom field 4 for ParentPrefixSelector", + required=False, + filter_logic="exact" + ), +] + +for custom_field in custom_fields: + try: + nb.extras.custom_fields.create( + object_types=custom_field.object_types, + type=custom_field.type, + name=custom_field.name, + label=custom_field.label, + description=custom_field.description, + required=custom_field.required, + filter_logic=custom_field.filter_logic, + default=None + ) + except pynetbox.RequestError as e: + pprint(e.error) + sys.exit(1) +print("Custom fields loaded") + +# for debugging +# custom_fields = list(nb.extras.custom_fields.all()) +# for custom_field in custom_fields: +# pprint(custom_field) + +# insert Prefixes +@dataclass +class Prefix: + prefix: str + site: dict + tenant: dict + status: str + custom_fields: dict + +prefixes = [ + Prefix( + prefix="2.0.0.0/16", + site=None, + tenant={ + "name": "Dunder-Mifflin, Inc.", + "slug": "dunder-mifflin", + }, + status="active", + custom_fields={}, + ), + + ### START ### + ### Used by e2e tests ### + ### Modifying entries might cause tests to fail ### + Prefix( # Used by prefixclaim-ipv4-apply-exhausted + prefix="2.0.1.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={}, + ), + Prefix( # Used by prefixclaim-ipv4-apply-succeed + prefix="2.0.2.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={}, + ), + Prefix( # Used by prefixclaim-ipv4-restoration-succeed + prefix="2.0.3.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={}, + ), + + Prefix( # TODO(henrybear327): debug why prefixclaim-ipv4-parentprefixselector-apply-succeed isn't using this prefix + prefix="3.0.0.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "Production", + "poolName": "Pool 1", + "cfDataTypeBool": True, + "cfDataTypeInteger": 1, + }, + ), + Prefix( # Used by prefixclaim-ipv4-parentprefixselector-apply-succeed + prefix="3.0.1.0/24", + site={ + "name": "MY_SITE", + "slug": "my_site", + "tenant": { + "name": "MY_TENANT", + "slug": "my_tenant", + }, + }, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "Production", + "poolName": "Pool 1", + "cfDataTypeBool": True, + "cfDataTypeInteger": 1, + }, + ), + Prefix( + prefix="3.0.2.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "Development", + "poolName": "Pool 1", + "cfDataTypeBool": False, + "cfDataTypeInteger": 2, + }, + ), + Prefix( # TODO(henrybear327): debug why prefixclaim-ipv4-parentprefixselector-restoration-succeed isn't using this prefix + prefix="3.0.3.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "Production", + "poolName": "Pool 2", + "cfDataTypeBool": True, + "cfDataTypeInteger": 3, + }, + ), + Prefix( # Used by prefixclaim-ipv4-parentprefixselector-restoration-succeed + prefix="3.0.4.0/24", + site={ + "name": "MY_SITE", + "slug": "my_site", + "tenant": { + "name": "MY_TENANT", + "slug": "my_tenant", + }, + }, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "Production", + "poolName": "Pool 2", + "cfDataTypeBool": True, + "cfDataTypeInteger": 3, + }, + ), + Prefix( + prefix="3.0.5.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "Development", + "poolName": "Pool 2", + "cfDataTypeBool": False, + "cfDataTypeInteger": 4, + }, + ), + Prefix( + prefix="3.0.6.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "production", + "poolName": "pool 3", + "cfDataTypeBool": True, + "cfDataTypeInteger": 5, + }, + ), + Prefix( + prefix="3.0.7.0/24", + site={ + "name": "MY_SITE", + "slug": "my_site", + "tenant": { + "name": "MY_TENANT", + "slug": "my_tenant", + }, + }, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "production", + "poolName": "pool 3", + "cfDataTypeBool": True, + "cfDataTypeInteger": 5, + }, + ), + Prefix( + prefix="3.0.8.0/24", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "development", + "poolName": "pool 3", + "cfDataTypeBool": False, + "cfDataTypeInteger": 6, + }, + ), + + Prefix( # Used by prefixclaim-ipv6-parentprefixselector-apply-succeed + prefix="2::/64", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "production", + "poolName": "pool 4", + "cfDataTypeBool": True, + "cfDataTypeInteger": 7, + }, + ), + Prefix( # TODO(henrybear327): debug why this entry is missing from NetBox after e2e test execution + prefix="2:0:0:1::/64", + site={ + "name": "MY_SITE", + "slug": "my_site", + "tenant": { + "name": "MY_TENANT", + "slug": "my_tenant", + }, + }, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "production", + "poolName": "pool 4", + "cfDataTypeBool": True, + "cfDataTypeInteger": 7, + }, + ), + Prefix( + prefix="2:0:0:2::/64", + site=None, + tenant={ + "name": "MY_TENANT", + "slug": "my_tenant", + }, + status="active", + custom_fields={ + "environment": "development", + "poolName": "pool 4", + "cfDataTypeBool": False, + "cfDataTypeInteger": 8, + }, + ), + ### END ### + ### Used by e2e tests ### + ### Modifying entries might cause tests to fail ### +] + +for prefix in prefixes: + try: + nb.ipam.prefixes.create( + prefix=prefix.prefix, + site=prefix.site, + tenant=prefix.tenant, + status=prefix.status, + custom_fields=prefix.custom_fields, + ) + except pynetbox.RequestError as e: + pprint(e.error) + sys.exit(1) +print("Prefixes loaded") diff --git a/kind/local-env.sh b/kind/local-env.sh index cf60de6a..0aa6f80b 100755 --- a/kind/local-env.sh +++ b/kind/local-env.sh @@ -15,8 +15,18 @@ if ! kubectl get namespaces | grep -q "^${NAMESPACE} "; then exit 1 fi +# build image for loading local data via NetBox API +cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --no-cache --progress=plain -f ./dockerfile . && cd - + # need to align with netbox-chart otherwise the creation of the cluster will hang -declare -a Images=( \ +declare -a Local_Images=( \ +"netbox-load-local-data:1.0" \ +) +for img in "${Local_Images[@]}"; do + kind load docker-image "$img" +done + +declare -a Remote_Images=( \ "gcr.io/kubebuilder/kube-rbac-proxy:v0.14.1" \ "busybox:1.37.0" \ "docker.io/bitnami/redis:7.4.1-debian-12-r2" \ @@ -24,8 +34,7 @@ declare -a Images=( \ "ghcr.io/zalando/postgres-operator:v1.12.2" \ "ghcr.io/zalando/spilo-16:3.2-p3" \ ) - -for img in "${Images[@]}"; do +for img in "${Remote_Images[@]}"; do docker pull "$img" kind load docker-image "$img" done @@ -50,3 +59,8 @@ helm upgrade --install --namespace="${NAMESPACE}" netbox \ https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta.163/netbox-5.0.0-beta.163.tgz kubectl rollout status --namespace="${NAMESPACE}" deployment netbox + +# load local data +kubectl create job netbox-load-local-data --image=netbox-load-local-data:1.0 +kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-load-local-data +docker rmi netbox-load-local-data:1.0 diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/chainsaw-test.yaml index f015148e..71231821 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/chainsaw-test.yaml @@ -18,14 +18,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.1.0.0/24 + parentPrefix: 2.0.1.0/24 prefixLength: /25 preserveInNetbox: false - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.1.0.0/24 - prefix: 2.1.0.0/25 + parentPrefix: 2.0.1.0/24 + prefix: 2.0.1.0/25 prefixName: prefixclaim-ipv4-apply-prefixexhausted-1 - assert: resource: @@ -36,9 +36,9 @@ spec: spec: comments: your comments description: some description - prefix: 2.1.0.0/25 - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + prefix: 2.0.1.0/25 + site: MY_SITE + tenant: MY_TENANT - name: Install CR 2 description: Apply prefix claim CR 2 try: @@ -53,14 +53,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.1.0.0/24 + parentPrefix: 2.0.1.0/24 prefixLength: /25 preserveInNetbox: false - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.1.0.0/24 - prefix: 2.1.0.128/25 + parentPrefix: 2.0.1.0/24 + prefix: 2.0.1.128/25 prefixName: prefixclaim-ipv4-apply-prefixexhausted-2 - assert: resource: @@ -71,9 +71,9 @@ spec: spec: comments: your comments description: some description - prefix: 2.1.0.128/25 - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + prefix: 2.0.1.128/25 + site: MY_SITE + tenant: MY_TENANT - name: Install CR 3 description: Apply prefix claim CR 3 try: diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_1.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_1.yaml index 3df56390..1976d2d1 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_1.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_1.yaml @@ -6,10 +6,10 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-apply-prefixexhausted-1 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT" + site: "MY_SITE" description: "some description" comments: "your comments" preserveInNetbox: false - parentPrefix: "2.1.0.0/24" + parentPrefix: "2.0.1.0/24" prefixLength: "/25" diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_2.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_2.yaml index 6d845454..8da8fea1 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_2.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_2.yaml @@ -6,10 +6,10 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-apply-prefixexhausted-2 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT" + site: "MY_SITE" description: "some description" comments: "your comments" preserveInNetbox: false - parentPrefix: "2.1.0.0/24" + parentPrefix: "2.0.1.0/24" prefixLength: "/25" diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_3.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_3.yaml index 25e28979..333ed36d 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_3.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWhenAppliedThenFailedPrefixExhausted/netbox_v1_prefixclaim_3.yaml @@ -6,10 +6,10 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-apply-prefixexhausted-3 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT" + site: "MY_SITE" description: "some description" comments: "your comments" preserveInNetbox: false - parentPrefix: "2.1.0.0/24" + parentPrefix: "2.0.1.0/24" prefixLength: "/25" diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml index d74dcc4d..52876cb0 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml @@ -21,12 +21,12 @@ spec: environment: Production family: IPv4 poolName: Pool 1 - site: DM-Buffalo + site: MY_SITE tenant: MY_TENANT prefixLength: /31 preserveInNetbox: true - site: DM-Akron - tenant: MY_TENANT + site: MY_SITE_2 + tenant: MY_TENANT_2 status: parentPrefix: 3.0.1.0/24 prefix: 3.0.1.0/31 @@ -42,6 +42,6 @@ spec: description: some description prefix: 3.0.1.0/31 preserveInNetbox: true - tenant: MY_TENANT + tenant: MY_TENANT_2 customFields: - netboxOperatorRestorationHash: b0d7d37281d2f2735ff188bdfa4eda469e55b684 + netboxOperatorRestorationHash: e3ea4eebe4ab49cc7c91dc9f96007965ede43338 diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml index ce896811..ce55667e 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithIPv4ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml @@ -6,15 +6,15 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-parentprefixselector-sample spec: - tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value - site: "DM-Akron" # Use the `name` value instead of the `slug` value + tenant: "MY_TENANT_2" # Use the `name` value instead of the `slug` value + site: "MY_SITE_2" # Use the `name` value instead of the `slug` value description: "some description" comments: "your comments" preserveInNetbox: true prefixLength: "/31" parentPrefixSelector: # The keys and values are case-sensitive tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value - site: "DM-Buffalo" # Use the `name` value instead of the `slug` value + site: "MY_SITE" # Use the `name` value instead of the `slug` value family: "IPv4" # Can only be either IPv4 or IPv6" # custom fields of your interest diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml index 202f1130..0301a1e6 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml @@ -17,14 +17,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.0.0.0/16 + parentPrefix: 2.0.3.0/24 prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.0.0.0/16 - prefix: 2.0.0.0/28 + parentPrefix: 2.0.3.0/24 + prefix: 2.0.3.0/28 prefixName: prefixclaim-ipv4-apply-delete-apply-restored-1 - assert: resource: @@ -35,12 +35,12 @@ spec: spec: comments: your comments description: some description - prefix: 2.0.0.0/28 + prefix: 2.0.3.0/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT customFields: - netboxOperatorRestorationHash: 8beafa710a38be8c61ce9c9e85bd734801ae2464 + netboxOperatorRestorationHash: 87e92d92a73dff00bb78280b57bdfa31a91f4780 - name: Apply prefix claim CR 2 for the first time and go through each field and check for equality try: - apply: @@ -54,14 +54,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.0.0.0/16 + parentPrefix: 2.0.3.0/24 prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.0.0.0/16 - prefix: 2.0.0.16/28 + parentPrefix: 2.0.3.0/24 + prefix: 2.0.3.16/28 prefixName: prefixclaim-ipv4-apply-delete-apply-restored-2 - assert: resource: @@ -72,12 +72,12 @@ spec: spec: comments: your comments description: some description - prefix: 2.0.0.16/28 + prefix: 2.0.3.16/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT customFields: - netboxOperatorRestorationHash: ac35098e1a755678ced699b581c5615acbb0ed94 + netboxOperatorRestorationHash: 0265a1eec7bba9748f9542476fe3dccb46cceb5a - name: Delete the applied CR 1 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) try: @@ -100,14 +100,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.0.0.0/16 + parentPrefix: 2.0.3.0/24 prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.0.0.0/16 - prefix: 2.0.0.0/28 + parentPrefix: 2.0.3.0/24 + prefix: 2.0.3.0/28 prefixName: prefixclaim-ipv4-apply-delete-apply-restored-1 - assert: resource: @@ -118,12 +118,12 @@ spec: spec: comments: your comments description: some description - prefix: 2.0.0.0/28 + prefix: 2.0.3.0/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT customFields: - netboxOperatorRestorationHash: 8beafa710a38be8c61ce9c9e85bd734801ae2464 + netboxOperatorRestorationHash: 87e92d92a73dff00bb78280b57bdfa31a91f4780 - assert: resource: apiVersion: netbox.dev/v1 @@ -133,14 +133,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.0.0.0/16 + parentPrefix: 2.0.3.0/24 prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.0.0.0/16 - prefix: 2.0.0.16/28 + parentPrefix: 2.0.3.0/24 + prefix: 2.0.3.16/28 prefixName: prefixclaim-ipv4-apply-delete-apply-restored-2 - assert: resource: @@ -151,9 +151,9 @@ spec: spec: comments: your comments description: some description - prefix: 2.0.0.16/28 + prefix: 2.0.3.16/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT customFields: - netboxOperatorRestorationHash: ac35098e1a755678ced699b581c5615acbb0ed94 + netboxOperatorRestorationHash: 0265a1eec7bba9748f9542476fe3dccb46cceb5a diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml index 935ab0ec..f084895e 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml @@ -6,10 +6,10 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-apply-delete-apply-restored-1 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT" + site: "MY_SITE" description: "some description" comments: "your comments" preserveInNetbox: true - parentPrefix: "2.0.0.0/16" + parentPrefix: "2.0.3.0/24" prefixLength: "/28" diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml index a7a498cd..3471d5ab 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml @@ -6,10 +6,10 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-apply-delete-apply-restored-2 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT" + site: "MY_SITE" description: "some description" comments: "your comments" preserveInNetbox: true - parentPrefix: "2.0.0.0/16" + parentPrefix: "2.0.3.0/24" prefixLength: "/28" diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/chainsaw-test.yaml index a4e32d64..354e3dcd 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/chainsaw-test.yaml @@ -17,14 +17,14 @@ spec: spec: comments: your comments description: some description - parentPrefix: 2.2.0.0/24 + parentPrefix: 2.0.2.0/24 prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT status: - parentPrefix: 2.2.0.0/24 - prefix: 2.2.0.0/28 + parentPrefix: 2.0.2.0/24 + prefix: 2.0.2.0/28 prefixName: prefixclaim-ipv4-apply - assert: resource: @@ -35,9 +35,9 @@ spec: spec: comments: your comments description: some description - prefix: 2.2.0.0/28 + prefix: 2.0.2.0/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE + tenant: MY_TENANT customFields: - netboxOperatorRestorationHash: 7a4827d80057860f6e6ab58c317323d1a82431cf + netboxOperatorRestorationHash: f773cf04f71c017931716e125a8520d70f4c7f83 diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml index 6de1c704..cd6f3828 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml @@ -6,10 +6,10 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-apply spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT" + site: "MY_SITE" description: "some description" comments: "your comments" preserveInNetbox: true - parentPrefix: "2.2.0.0/24" + parentPrefix: "2.0.2.0/24" prefixLength: "/28" diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml index 8b3e1645..be5473d1 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/chainsaw-test.yaml @@ -21,12 +21,12 @@ spec: environment: Production family: IPv4 poolName: Pool 2 - site: DM-Buffalo + site: MY_SITE tenant: MY_TENANT prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 status: parentPrefix: 3.0.4.0/24 prefix: 3.0.4.0/28 @@ -42,10 +42,10 @@ spec: description: some description prefix: 3.0.4.0/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 customFields: - netboxOperatorRestorationHash: 55499191b81d9f57f22173fb8004506946fe3e4d + netboxOperatorRestorationHash: d571cb2311db97e7564f32cf3543ac0e3526e362 - name: Apply prefix claim CR 2 for the first time and go through each field and check for equality try: - apply: @@ -63,12 +63,12 @@ spec: environment: Production family: IPv4 poolName: Pool 2 - site: DM-Buffalo + site: MY_SITE tenant: MY_TENANT prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 status: parentPrefix: 3.0.4.0/24 prefix: 3.0.4.16/28 @@ -84,10 +84,10 @@ spec: description: some description prefix: 3.0.4.16/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 customFields: - netboxOperatorRestorationHash: 53225105de94363de30c46e0c56cac938bdf35ba + netboxOperatorRestorationHash: 2fecef786a6c3590bc219c540d2a142f9e2ad907 - name: Delete the applied CR 1 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) try: @@ -114,12 +114,12 @@ spec: environment: Production family: IPv4 poolName: Pool 2 - site: DM-Buffalo + site: MY_SITE tenant: MY_TENANT prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 status: parentPrefix: Prefix restored from hash, cannot infer the parent prefix prefix: 3.0.4.0/28 @@ -135,10 +135,10 @@ spec: description: some description prefix: 3.0.4.0/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 customFields: - netboxOperatorRestorationHash: 55499191b81d9f57f22173fb8004506946fe3e4d + netboxOperatorRestorationHash: d571cb2311db97e7564f32cf3543ac0e3526e362 - assert: resource: apiVersion: netbox.dev/v1 @@ -152,12 +152,12 @@ spec: environment: Production family: IPv4 poolName: Pool 2 - site: DM-Buffalo + site: MY_SITE tenant: MY_TENANT prefixLength: /28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 status: parentPrefix: 3.0.4.0/24 prefix: 3.0.4.16/28 @@ -173,7 +173,7 @@ spec: description: some description prefix: 3.0.4.16/28 preserveInNetbox: true - site: DM-Akron - tenant: Dunder-Mifflin, Inc. + site: MY_SITE_2 + tenant: MY_TENANT_2 customFields: - netboxOperatorRestorationHash: 53225105de94363de30c46e0c56cac938bdf35ba + netboxOperatorRestorationHash: 2fecef786a6c3590bc219c540d2a142f9e2ad907 diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml index b7facc5b..9667b3dc 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_1.yaml @@ -6,15 +6,15 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-parentprefixselector-apply-delete-apply-restored-1 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT_2" + site: "MY_SITE_2" description: "some description" comments: "your comments" preserveInNetbox: true prefixLength: "/28" parentPrefixSelector: # The keys and values are case-sensitive tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value - site: "DM-Buffalo" # Use the `name` value instead of the `slug` value + site: "MY_SITE" # Use the `name` value instead of the `slug` value family: "IPv4" # Can only be either IPv4 or IPv6" # custom fields of your interest diff --git a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml index 46dc6b03..4310742d 100644 --- a/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml +++ b/tests/e2e/Prefix/IPv4/GivenPrefixClaimWithPreserveWhenParentPrefixSelectorAppliedDeletedAppliedThenRestorationSucceed/netbox_v1_prefixclaim_2.yaml @@ -6,15 +6,15 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv4-parentprefixselector-apply-delete-apply-restored-2 spec: - tenant: "Dunder-Mifflin, Inc." - site: "DM-Akron" + tenant: "MY_TENANT_2" + site: "MY_SITE_2" description: "some description" comments: "your comments" preserveInNetbox: true prefixLength: "/28" parentPrefixSelector: # The keys and values are case-sensitive tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value - site: "DM-Buffalo" # Use the `name` value instead of the `slug` value + site: "MY_SITE" # Use the `name` value instead of the `slug` value family: "IPv4" # Can only be either IPv4 or IPv6" # custom fields of your interest diff --git a/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml b/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml index eec6901c..ca29d522 100644 --- a/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/chainsaw-test.yaml @@ -25,10 +25,10 @@ spec: environment: production family: IPv6 poolName: pool 4 - tenant: Dunder-Mifflin, Inc. + tenant: MY_TENANT prefixLength: /124 preserveInNetbox: true - tenant: Dunder-Mifflin, Inc. + tenant: MY_TENANT_2 status: parentPrefix: 2::/64 prefix: 2::/124 @@ -44,6 +44,6 @@ spec: description: some description prefix: 2::/124 preserveInNetbox: true - tenant: Dunder-Mifflin, Inc. + tenant: MY_TENANT_2 customFields: - netboxOperatorRestorationHash: a7fbe45766da6a472a3b3d4d7f7070622feb555d + netboxOperatorRestorationHash: 92913dac42ca35232682325c7f04639959d3a3cf diff --git a/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml b/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml index fea0526d..52ebe79a 100644 --- a/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml +++ b/tests/e2e/Prefix/IPv6/GivenPrefixClaimWithIPv6ParentPrefixSelectorWhenAppliedThenSucceed/netbox_v1_prefixclaim.yaml @@ -6,14 +6,14 @@ metadata: app.kubernetes.io/managed-by: kustomize name: prefixclaim-ipv6-parentprefixselector-apply-succeed spec: - tenant: "Dunder-Mifflin, Inc." # Use the `name` value instead of the `slug` value + tenant: "MY_TENANT_2" # Use the `name` value instead of the `slug` value description: "some description" comments: "your comments" preserveInNetbox: true prefixLength: "/124" parentPrefixSelector: # The keys and values are case-sensitive # if the entry for tenant or site is missing, it will *not* inherit from the tenant and site from the Spec - tenant: "Dunder-Mifflin, Inc." # Use the `name` value instead of the `slug` value + tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value family: "IPv6" # Can only be either IPv4 or IPv6" environment: "production"