blob: 0719cdbecba8e6df1d520b2a7c840aa862ac2e72 [file] [log] [blame]
Kailash92764922019-07-25 08:21:39 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Zack Williamsec53a1b2019-09-16 15:50:52 -070015# use bash for pushd/popd, and to fail quickly. virtualenv's activate
16# has undefined variables, so no -u
Zack Williamsa8fe75a2020-01-10 14:25:27 -070017SHELL := bash -e -o pipefail
Kailash92764922019-07-25 08:21:39 -070018
Zack Williamsa8fe75a2020-01-10 14:25:27 -070019ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
Kailash92764922019-07-25 08:21:39 -070020
Zack Williamsa8fe75a2020-01-10 14:25:27 -070021# Configuration and lists of files for linting/testing
22VERSION ?= $(shell cat ./VERSION)
23LINT_ARGS ?= --verbose --configure LineTooLong:120 -e LineTooLong \
24 --configure TooManyTestSteps:30 -e TooManyTestSteps \
25 --configure TooManyTestCases:12 -e TooManyTestCases \
26 --configure TooFewTestSteps:1 \
27 --configure TooFewKeywordSteps:1 \
28 --configure FileTooLong:600 -e FileTooLong \
29 -e TrailingWhitespace
30
31PYTHON_FILES := $(wildcard libraries/*.py)
32ROBOT_FILES := $(shell find . -name *.robot -print)
33YAML_FILES := $(shell find ./tests -type f \( -name *.yaml -o -name *.yml \) -print)
34JSON_FILES := $(shell find ./tests -name *.json -print)
35
36# Robot config
37ROBOT_SANITY_SINGLE_PON_FILE ?= $(ROOT_DIR)/tests/data/bbsim-kind.yaml
38ROBOT_FAIL_SINGLE_PON_FILE ?= $(ROOT_DIR)/tests/data/bbsim-kind.yaml
39ROBOT_SANITY_MULT_PON_FILE ?= $(ROOT_DIR)/tests/data/bbsim-kind-2x2.yaml
40ROBOT_SCALE_SINGLE_PON_FILE ?= $(ROOT_DIR)/tests/data/bbsim-kind-16.yaml
41ROBOT_SCALE_MULT_PON_FILE ?= $(ROOT_DIR)/tests/data/bbsim-kind-8x2.yaml
42ROBOT_DEBUG_LOG_OPT ?=
43ROBOT_MISC_ARGS ?=
44
Gilles Depatie45fbe042019-11-11 17:10:06 -050045# for backwards compatibility
46sanity-kind: sanity-single-kind
47
Andy Bavier33e6dd32020-01-16 13:35:20 -070048functional-single-kind: ROBOT_MISC_ARGS += -i sanity -i functional $(ROBOT_DEBUG_LOG_OPT)
49functional-single-kind: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_SINGLE_PON_FILE)
50functional-single-kind: bbsim-kind
51
David Bainbridgef81cd642019-11-20 00:14:47 +000052sanity-single-kind: ROBOT_MISC_ARGS += -i sanity $(ROBOT_DEBUG_LOG_OPT)
Gilles Depatie45fbe042019-11-11 17:10:06 -050053sanity-single-kind: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_SINGLE_PON_FILE)
54sanity-single-kind: bbsim-kind
55
David Bainbridgef81cd642019-11-20 00:14:47 +000056rwcore-restart-single-kind: ROBOT_MISC_ARGS += -X -i bbsimANDrwcore-restart $(ROBOT_DEBUG_LOG_OPT)
57rwcore-restart-single-kind: ROBOT_CONFIG_FILE := $(ROBOT_FAIL_SINGLE_PON_FILE)
58rwcore-restart-single-kind: ROBOT_FILE := Voltha_PODTests.robot
59rwcore-restart-single-kind: voltha-test
60
David Bainbridge3d6d5d32019-12-17 19:05:35 +000061single-kind: ROBOT_MISC_ARGS += -X -i $(TEST_TAGS) $(ROBOT_DEBUG_LOG_OPT)
62single-kind: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_SINGLE_PON_FILE)
63single-kind: ROBOT_FILE := Voltha_PODTests.robot
64single-kind: voltha-test
65
David Bainbridgef81cd642019-11-20 00:14:47 +000066sanity-multi-kind: ROBOT_MISC_ARGS += -i sanity $(ROBOT_DEBUG_LOG_OPT)
Gilles Depatie45fbe042019-11-11 17:10:06 -050067sanity-multi-kind: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_MULT_PON_FILE)
68sanity-multi-kind: bbsim-kind
Andy Bavierba9866b2019-10-11 07:11:53 -070069
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -070070bbsim-kind: ROBOT_MISC_ARGS += -X
Gilles Depatie45fbe042019-11-11 17:10:06 -050071bbsim-kind: ROBOT_FILE := Voltha_PODTests.robot
72bbsim-kind: voltha-test
73
David Bainbridgef81cd642019-11-20 00:14:47 +000074scale-single-kind: ROBOT_MISC_ARGS += -i active $(ROBOT_DEBUG_LOG_OPT)
Gilles Depatie45fbe042019-11-11 17:10:06 -050075scale-single-kind: ROBOT_CONFIG_FILE := $(ROBOT_SCALE_SINGLE_PON_FILE)
76scale-single-kind: bbsim-scale-kind
77
David Bainbridgef81cd642019-11-20 00:14:47 +000078scale-multi-kind: ROBOT_MISC_ARGS += -i active $(ROBOT_DEBUG_LOG_OPT)
Gilles Depatie45fbe042019-11-11 17:10:06 -050079scale-multi-kind: ROBOT_CONFIG_FILE := $(ROBOT_SCALE_MULT_PON_FILE)
80scale-multi-kind: bbsim-scale-kind
81
David Bainbridgef81cd642019-11-20 00:14:47 +000082bbsim-scale-kind: ROBOT_MISC_ARGS += -X $(ROBOT_DEBUG_LOG_OPT)
Gilles Depatie45fbe042019-11-11 17:10:06 -050083bbsim-scale-kind: ROBOT_FILE := Voltha_ScaleFunctionalTests.robot
84bbsim-scale-kind: voltha-test
Zack Williamsec53a1b2019-09-16 15:50:52 -070085
hwchiuab524f02020-02-03 23:24:19 +000086#Only supported in full mode
87system-scale-test: ROBOT_FILE := K8S_SystemTest.robot
hwchiu56eb85c2020-02-05 01:05:53 +000088system-scale-test: ROBOT_MISC_ARGS += -X -i functional $(ROBOT_DEBUG_LOG_OPT)
hwchiuab524f02020-02-03 23:24:19 +000089system-scale-test: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_MULT_PON_FILE)
90system-scale-test: voltha-test
hwchiu11289122019-11-27 16:20:15 +000091
hwchiu85695932019-12-18 08:05:25 +000092failure-test: ROBOT_MISC_ARGS += -X -i FailureTest $(ROBOT_DEBUG_LOG_OPT)
hwchiu3d9a0982020-02-06 00:19:19 +000093failure-test: ROBOT_FILE := K8S_SystemTest.robot
hwchiu85695932019-12-18 08:05:25 +000094failure-test: ROBOT_CONFIG_FILE := $(ROBOT_FAIL_SINGLE_PON_FILE)
95failure-test: voltha-test
96
Scott Baker60e570d2020-02-02 22:10:13 -080097bbsim-alarms-kind: ROBOT_MISC_ARGS += -X -i active
98bbsim-alarms-kind: ROBOT_FILE := Voltha_AlarmTests.robot
99bbsim-alarms-kind: ROBOT_CONFIG_FILE := $(ROBOT_SCALE_SINGLE_PON_FILE)
100bbsim-alarms-kind: voltctl-docker-image-build voltctl-docker-image-install-kind voltha-test
101
Andy Bavier70eab042019-12-14 14:16:26 -0700102voltha-test: ROBOT_MISC_ARGS += -e notready
hwchiu11289122019-11-27 16:20:15 +0000103
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700104voltha-test: vst_venv
105 source ./$</bin/activate ; set -u ;\
106 cd tests/functional ;\
107 robot -V $(ROBOT_CONFIG_FILE) $(ROBOT_MISC_ARGS) $(ROBOT_FILE)
108
109# self-test, lint, and setup targets
110
111# virtualenv for the robot tools
112vst_venv:
113 virtualenv -p python3 $@ ;\
114 source ./$@/bin/activate ;\
115 pip install -r requirements.txt
116
117test: lint
118
119lint: lint-robot lint-python lint-yaml lint-json
120
121lint-robot: vst_venv
122 source ./$</bin/activate ; set -u ;\
123 rflint $(LINT_ARGS) $(ROBOT_FILES)
124
125# check deps for format and python3 cleanliness
126lint-python: vst_venv
127 source ./$</bin/activate ; set -u ;\
128 pylint --py3k $(PYTHON_FILES) ;\
129 flake8 --max-line-length=99 --count $(PYTHON_FILES)
130
131lint-yaml: vst_venv
132 source ./$</bin/activate ; set -u ;\
133 yamllint -s $(YAML_FILES)
134
135lint-json: vst_venv
136 source ./$</bin/activate ; set -u ;\
137 for jsonfile in $(JSON_FILES); do \
138 echo "Validating json file: $$jsonfile" ;\
139 python -m json.tool $$jsonfile > /dev/null ;\
140 done
141
142# tidy target will be more useful once issue with removing leading comments
143# is resolved: https://github.com/robotframework/robotframework/issues/3263
144tidy-robot: vst_venv
145 source ./$</bin/activate ; set -u ;\
146 python -m robot.tidy --inplace $(ROBOT_FILES);
147
Andy Bavier4a8450e2020-02-04 08:58:37 -0700148# Install the 'kail' tool if needed: https://github.com/boz/kail
149KAIL_PATH ?= /usr/local/bin
150$(KAIL_PATH)/kail:
151 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b /tmp
152 mv /tmp/kail $(KAIL_PATH)
153
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700154## Variables for gendocs
155TEST_SOURCE := $(wildcard tests/*/*.robot)
156TEST_BASENAME := $(basename $(TEST_SOURCE))
157TEST_DIRS := $(dir $(TEST_SOURCE))
158
159LIB_SOURCE := $(wildcard libraries/*.robot)
160LIB_BASENAME := $(basename $(LIB_SOURCE))
161LIB_DIRS := $(dir $(LIB_SOURCE))
162
163.PHONY: gendocs lint test
164# In future explore use of --docformat REST - integration w/Sphinx?
Zack Williamsec53a1b2019-09-16 15:50:52 -0700165gendocs: vst_venv
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700166 source ./$</bin/activate ; set -u ;\
hwchiu0601ec72019-10-08 00:04:43 +0000167 mkdir -p $@ ;\
168 for dir in ${LIB_DIRS}; do mkdir -p $@/$$dir; done;\
169 for dir in ${LIB_BASENAME}; do\
170 python -m robot.libdoc --format HTML $$dir.robot $@/$$dir.html ;\
171 done ;\
172 for dir in ${TEST_DIRS}; do mkdir -p $@/$$dir; done;\
173 for dir in ${TEST_BASENAME}; do\
174 python -m robot.testdoc $$dir.robot $@/$$dir.html ;\
175 done
Zack Williamsec53a1b2019-09-16 15:50:52 -0700176
Zack Williamsec53a1b2019-09-16 15:50:52 -0700177clean:
178 find . -name output.xml -print
179
180clean-all: clean
181 rm -rf vst_venv gendocs
Scott Baker60e570d2020-02-02 22:10:13 -0800182
183voltctl-docker-image-build:
184 cd docker && docker build -t opencord/voltctl:local -f Dockerfile.voltctl .
185
186voltctl-docker-image-install-kind:
187 @if [ "`kind get clusters | grep voltha`" = '' ]; then echo "no voltha cluster found" && exit 1; fi
188 kind load docker-image --name `kind get clusters | grep voltha` opencord/voltctl:local