-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
310 lines (239 loc) · 12.6 KB
/
Makefile
File metadata and controls
310 lines (239 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
REMOTE ?= origin
APSTRA_COLLECTION_ROOT := ansible_collections/juniper/apstra
VERSION := $(shell sed -n '/^version: / s,.*"\(.*\)"$$,\1,p' $(APSTRA_COLLECTION_ROOT)/galaxy.yml)
APSTRA_COLLECTION := $(APSTRA_COLLECTION_ROOT)/juniper-apstra-$(VERSION).tar.gz
# Get all .py files in the APSTRA_COLLECTION_ROOT directory
PY_FILES := $(shell find $(APSTRA_COLLECTION_ROOT) -name *.py)
PY_VERSION := $(shell cat .python-version)
APSTRA_COLLECTION = juniper-apstra-$(VERSION).tar.gz
.PHONY: setup build release-build install clean clean-pipenv pipenv docs tag image
# OS-specific settings
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
PYENV_INSTALL_PREFIX := PYTHON_CONFIGURE_OPTS=--enable-framework
endif
# By default use .venv in the current directory
export PIPENV_VENV_IN_PROJECT=1
# Needed for antsi-build doc build
CERT_PATH = $(shell python -m certifi 2>/dev/null)
export SSL_CERT_FILE=$(CERT_PATH)
export REQUESTS_CA_BUNDLE=$(CERT_PATH)
setup: clean-pipenv
pyenv uninstall --force $(PY_VERSION)
rm -rf $(HOME)/.pyenv/versions/$(PY_VERSION)
$(PYENV_INSTALL_PREFIX) pyenv install --force $(PY_VERSION)
$(MAKE) pipenv
# Needed for tests
pipenv run ansible-galaxy collection install --ignore-certs --force community.general
define install_collection_if_missing
pipenv run ansible-doc $(1) &>/dev/null || pipenv run ansible-galaxy collection install --ignore-certs --force $(1)
endef
AOS_SDK_DEFAULT_WHL := aos_sdk-0.1.0-py3-none-any.whl
AOS_SDK_DEFAULT_URL := https://s-artifactory.juniper.net:443/artifactory/atom-generic/aos_sdk_5.1.0/$(AOS_SDK_DEFAULT_WHL)
pipenv: build/wheels
@# Pick the highest-versioned aos_sdk wheel; fall back to downloading the default
@AOS_SDK_WHL=$$(ls build/wheels/aos_sdk-*.whl 2>/dev/null | grep -v '$(AOS_SDK_DEFAULT_WHL)' | sort -V | tail -1); \
if [ -z "$$AOS_SDK_WHL" ]; then \
AOS_SDK_WHL=$$(ls build/wheels/$(AOS_SDK_DEFAULT_WHL) 2>/dev/null); \
fi; \
if [ -z "$$AOS_SDK_WHL" ]; then \
echo "No aos_sdk wheel found in build/wheels/, downloading default $(AOS_SDK_DEFAULT_WHL)..."; \
curl -fso "build/wheels/$(AOS_SDK_DEFAULT_WHL)" "$(AOS_SDK_DEFAULT_URL)"; \
AOS_SDK_WHL="build/wheels/$(AOS_SDK_DEFAULT_WHL)"; \
fi; \
AOS_SDK_BASENAME=$$(basename $$AOS_SDK_WHL); \
echo "Using aos_sdk wheel: $$AOS_SDK_BASENAME"; \
CURRENT=$$(sed -n 's/.*aos-sdk = {file = "build\/wheels\/\(aos_sdk-[^"]*\.whl\)".*/\1/p' Pipfile); \
if [ "$$CURRENT" != "$$AOS_SDK_BASENAME" ]; then \
echo "Updating Pipfile: $$CURRENT -> $$AOS_SDK_BASENAME"; \
sed -i "s|aos-sdk = {file = \"build/wheels/aos_sdk-[^\"]*\.whl\"}|aos-sdk = {file = \"build/wheels/$$AOS_SDK_BASENAME\"}|" Pipfile; \
rm -f Pipfile.lock; \
fi
(pip install pipenv pre-commit && \
pre-commit install && \
pipenv install --dev)
build/wheels:
mkdir -p build/wheels
tag:
git tag -a $(VERSION) -m "Release $(VERSION)"
git push $(REMOTE) $(VERSION)
git push --tags
image: build
mkdir -p build/collections
rm -f build/collections/juniper-apstra.tar.gz
cp "$(APSTRA_COLLECTION)" build/collections/juniper-apstra.tar.gz
TAG=$(VERSION) pipenv run build/build_image.sh
release-build: docs
make build
build: $(APSTRA_COLLECTION_ROOT)/.apstra-collection
NEWVER := $(shell sed -n '/^version: / s,.*"\(.*\)"$$,\1,p' $(APSTRA_COLLECTION_ROOT)/galaxy.yml)-$(SHORT_COMMIT)
update-version:
sed -i "s/^version: \".*\"/version: \"$(NEWVER)\"/" $(APSTRA_COLLECTION_ROOT)/galaxy.yml
APSTRA_COLLECTION_DOCS_BUILD := ansible_collections/juniper/apstra/_build
docs: pipenv install
rm -rf "$(APSTRA_COLLECTION_DOCS_BUILD)" "$(APSTRA_COLLECTION_ROOT)/.apstra-collection"
mkdir -p $(APSTRA_COLLECTION_ROOT)/_build
chmod og-rwx $(APSTRA_COLLECTION_ROOT)/_build
pipenv run antsibull-docs sphinx-init \
--dest-dir $(APSTRA_COLLECTION_DOCS_BUILD) \
--no-indexes \
--no-add-antsibull-docs-version \
--output-format simplified-rst \
--use-current \
--squash-hierarchy \
--lenient \
--project "Juniper Network Apstra Ansible Collection" \
--copyright "Juniper Networks, Inc." \
--title "Apstra Ansible Collection" \
--title "Apstra Ansible Collection" \
juniper.apstra
pipenv run $(APSTRA_COLLECTION_DOCS_BUILD)/build.sh
cp $(APSTRA_COLLECTION_DOCS_BUILD)/rst/*.rst $(APSTRA_COLLECTION_ROOT)/docs/
$(APSTRA_COLLECTION_ROOT)/.apstra-collection: $(APSTRA_COLLECTION_ROOT)/requirements.txt $(APSTRA_COLLECTION_ROOT)/galaxy.yml $(PY_FILES)
rm -f juniper-apstra-*.tar.gz
pipenv run ansible-galaxy collection build $(APSTRA_COLLECTION_ROOT)
touch "$@"
$(APSTRA_COLLECTION_ROOT)/requirements.txt: Pipfile Makefile pipenv
pipenv clean && pipenv requirements --from-pipfile --exclude-markers | sed -e 's:==:>=:' | sed -e '\:build/wheels/aos_sdk:d' > "$@"
install: build
pipenv run ansible-galaxy collection install --ignore-certs --force $(APSTRA_COLLECTION)
.PHONY: test \
test-apstra_facts \
test-blueprint \
test-virtual_network \
test-routing_policy \
test-security_zone \
test-endpoint_policy \
test-tag \
test-resource_group \
test-resource_pools \
test-property_set \
test-external_gateway \
test-customize_external_gateway \
test-connectivity_template \
test-configlets \
test-generic_systems \
test-customize_generic_systems \
test-system_agents \
test-interface_map \
test-fabric_settings \
test-ztp_device
# Ignore warnings about localhost from ansible-playbook
export ANSIBLE_LOCALHOST_WARNING=False
export ANSIBLE_INVENTORY_UNPARSED_WARNING=False
ANSIBLE_FLAGS ?= -v
test-apstra_facts: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/apstra_facts.yml
test-blueprint: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/blueprint.yml
test-virtual_network: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/virtual_network.yml
test-routing_policy: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/routing_policy.yml
test-security_zone: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/security_zone.yml
test-endpoint_policy: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/endpoint_policy.yml
test-tag: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/tag.yml
test-resource_group: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/resource_group.yml
test-resource_pools: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/resource_pools.yml
test-property_set: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/property_set.yml
test-external_gateway: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/external_gateway.yml
BLUEPRINT_ID ?=
test-customize_external_gateway: install
@if [ -z "$(BLUEPRINT_ID)" ]; then echo "ERROR: BLUEPRINT_ID is required. Usage: make test-customize_external_gateway BLUEPRINT_ID=<id>"; exit 1; fi
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/customize_external_gateway.yml -e blueprint_id=$(BLUEPRINT_ID)
test-customize_connectivity_template: install
@if [ -z "$(BLUEPRINT_ID)" ]; then echo "ERROR: BLUEPRINT_ID is required. Usage: make test-customize_connectivity_template BLUEPRINT_ID=<id>"; exit 1; fi
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/customize_connectivity_template.yml -e blueprint_id=$(BLUEPRINT_ID)
test-connectivity_template: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/connectivity_template.yml
test-configlets: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/configlets.yml
test-generic_systems: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/generic_systems.yml
test-customize_generic_systems: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/customize_generic_systems.yml
test-system_agents: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/system_agents.yml
test-interface_map: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/interface_map.yml
test-fabric_settings: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/fabric_settings.yml
test-rollback: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/rollback.yml $(if $(BLUEPRINT_ID),-e blueprint_id=$(BLUEPRINT_ID),)
test-ztp_device: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/ztp_device.yml
test-name_resolution: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/name_resolution.yml
TESTBED_FILE ?=
# ── ConnectorOps full run (all phases) ────────────────────────────────────────
create-connectorops-blueprint: install
@if [ -z "$(TESTBED_FILE)" ]; then echo "ERROR: TESTBED_FILE is required. Usage: make create-connectorops-blueprint TESTBED_FILE=/path/to/testbed.yaml"; exit 1; fi
pipenv run ansible-playbook $(ANSIBLE_FLAGS) \
$(APSTRA_COLLECTION_ROOT)/tests/create_connectorops_blueprint.yml \
-e @$(APSTRA_COLLECTION_ROOT)/tests/vars/connectorops_blueprint.yml \
-e testbed_file=$(TESTBED_FILE)
# ── ConnectorOps demo targets (cumulative — each includes all prerequisites) ─
# make demo-auth → Phase 1 only
# make demo-onboard → Phases 1-2
# make demo-design → Phases 1-3
# make demo-interface-maps → Phases 1-4
# make demo-blueprint → Phases 1-5
# make demo-external-gateway → Phases 1-6
# make demo-connectivity-template → Phases 1-7
_DEMO_BASE = pipenv run ansible-playbook $(ANSIBLE_FLAGS) \
$(APSTRA_COLLECTION_ROOT)/tests/create_connectorops_blueprint.yml \
-e @$(APSTRA_COLLECTION_ROOT)/tests/vars/connectorops_blueprint.yml \
-e testbed_file=$(TESTBED_FILE)
_DEMO_CHECK = @if [ -z "$(TESTBED_FILE)" ]; then echo "ERROR: TESTBED_FILE is required. Usage: make $@ TESTBED_FILE=/path/to/testbed.yaml"; exit 1; fi
demo-auth: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth"
demo-onboard: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth,phase2_onboard"
demo-design: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth,phase2_onboard,phase3_design"
demo-interface-maps: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth,phase2_onboard,phase3_design,phase4_interface_maps"
demo-blueprint: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth,phase2_onboard,phase3_design,phase4_interface_maps,phase5_blueprint"
demo-external-gateway: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth,phase2_onboard,phase3_design,phase4_interface_maps,phase5_blueprint,phase6_external_gateway"
demo-connectivity-template: install
$(_DEMO_CHECK)
$(_DEMO_BASE) --tags "phase1_auth,phase2_onboard,phase3_design,phase4_interface_maps,phase5_blueprint,phase6_external_gateway,phase7_connectivity_template"
delete-connectorops-blueprint: install
@if [ -z "$(TESTBED_FILE)" ]; then echo "ERROR: TESTBED_FILE is required. Usage: make delete-connectorops-blueprint TESTBED_FILE=/path/to/testbed.yaml"; exit 1; fi
pipenv run ansible-playbook $(ANSIBLE_FLAGS) \
$(APSTRA_COLLECTION_ROOT)/tests/delete_connectorops_blueprint.yml \
-e @$(APSTRA_COLLECTION_ROOT)/tests/vars/connectorops_blueprint.yml \
-e testbed_file=$(TESTBED_FILE)
test: test-apstra_facts test-blueprint test-virtual_network test-routing_policy test-security_zone test-endpoint_policy test-tag test-resource_group test-configlets test-property_set test-resource_pools test-external_gateway test-connectivity_template test-generic_systems test-system_agents test-interface_map test-fabric_settings test-ztp_device
# Integration Tests
.PHONY: test-integration-property_set
.PHONY: test-integration-resource_pools
.PHONY: test-integration-configlets
test-integration-property_set: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/integration/property_set.yml
test-integration-resource_pools: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/integration/resource_pools.yml
test-integration-configlets: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/integration/configlets.yml
clean-pipenv:
PIPENV_VENV_IN_PROJECT= pipenv --rm 2>/dev/null || true
rm -rf .venv
clean: clean-pipenv
rm -rf $(APSTRA_COLLECTION_ROOT)/.apstra-collection $(APSTRA_COLLECTION_ROOT)/requirements.txt juniper-apstra-*.tar.gz
demo: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) demo/security_zone.yml