-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
118 lines (85 loc) · 3.3 KB
/
Makefile
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
unexport VIRTUAL_ENV
ORG := README.org
YANG := labn-munet-config.yang
YANG_SCHEMA := munet/munet-schema.json
SCHEMA := test-schema.json
LOG_CLI := # --log-cli
TMP := .testtmp
unexport VIRTUAL_ENV
POETRY := env -u VIRTUAL_ENV PATH="$(PATH)" poetry
POETRYRUN := $(POETRY) run
MAKE_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
all: $(TMP) $(YANG) $(YANG_SCHEMA) doc ci-lint test yang-test
.PHONY: doc
doc:
$(POETRYRUN) $(MAKE) -C doc html
doc-start:
sudo podman run -it --rm -p 8088:80 -d --volume $(MAKE_DIR)/doc/build/html:/usr/share/nginx/html --name sphinx docker.io/nginx
doc-stop:
sudo podman stop sphinx
# We hand craft this to keep things cleaner
doc-apidoc:
$(POETRYRUN) sphinx-apidoc -f --module-first --ext-doctest --extensions sphinx-prompt -o doc/source/apidoc munet
prepare-publish: $(YANG_SCHEMA)
lint:
$(POETRYRUN) pydocstyle ./munet
$(POETRYRUN) pylint ./munet $(shell find ./tests/*/* -name '*.py')
ci-lint:
$(POETRYRUN) pydocstyle ./munet
$(POETRYRUN) pylint --disable="fixme" ./munet ./tests
test: test-validate ci-lint
sudo -E $(POETRYRUN) mutest tests
sudo -E $(POETRYRUN) pytest -s -v --cov=munet --cov-report=xml tests
clean:
rm -f *.yang coverage.xml err.out ox-rfc.el
rm -rf .testtmp/schema
run:
sudo -E $(POETRYRUN) python3 -m munet
install:
$(POETRY) install
# ====
# YANG
# ====
# -------------------------
# YANG from source ORG file
# -------------------------
ajv = $(or $(and $(shell which ajv),ajv $(1)),)
y2j = $(POETRYRUN) python -c 'import sys; import json; import yaml; json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=2)' < $(1) > $(2)
$(YANG): $(ORG)
sed -n '/#+begin_src yang :exports code/,/^#+end_src/p' $< | sed '/^#/d' >$@
export DOCKRUN ?= docker run --user $(shell id -u) --network=host -v $$(pwd):/work labn/org-rfc
EMACSCMD := $(DOCKRUN) emacs -Q --batch --eval '(setq-default indent-tabs-mode nil)' --eval '(setq org-confirm-babel-evaluate nil)' -l ./ox-rfc.el
# $(YANG): $(ORG) ox-rfc.el
# $(EMACSCMD) $< --eval '(org-sbe test-validate-module)' 2>&1
run-yang-test: $(ORG) ox-rfc.el
$(EMACSCMD) $< -f ox-rfc-run-test-blocks 2>&1
yang-test: $(ORG) ox-rfc.el
@echo Testing $<
@result="$$($(EMACSCMD) $< -f ox-rfc-run-test-blocks 2>&1)"; \
if [ -n "$$(echo \"$$result\"| grep FAIL)" ]; then \
echo "$$result" | grep RESULT || true; \
exit 1; \
else \
echo "$$result" | grep RESULT || true; \
fi;
ox-rfc.el:
curl -fLO 'https://raw.githubusercontent.com/choppsv1/org-rfc-export/master/ox-rfc.el'
# --------------------
# YANG data validation
# --------------------
$(YANG_SCHEMA): $(YANG)
$(POETRYRUN) pyang --plugindir .venv/src/pyang-json-schema-plugin/jsonschema/jsonschema.py --format jsonschema -o $@ $<
$(TMP):
mkdir -p .testtmp
KINDS_DATA := .testtmp/kinds.json
.testtmp/%.json: munet/%.yaml $(TMP)
$(call y2j,$<,$@)
.testtmp/basic.json: tests/basic/munet.yaml $(TMP)
$(call y2j,$<,$@)
test-validate: $(YANG_SCHEMA) $(KINDS_DATA) .testtmp/basic.json $(TMP)
@echo "testing basic with yang generated schema"
$(call ajv,--spec=draft2020 -d .testtmp/basic.json -s $(YANG_SCHEMA))
$(POETRYRUN) jsonschema --instance .testtmp/basic.json $(YANG_SCHEMA)
@echo "testing kinds with yang generated schema"
$(call ajv,--spec=draft2020 -d .testtmp/kinds.json -s $(YANG_SCHEMA))
$(POETRYRUN) jsonschema --instance .testtmp/kinds.json $(YANG_SCHEMA)