blob: b10a4eae1c387de3e6d968d4b1257a9d865e8815 [file] [log] [blame]
Zack Williams821c5022020-01-15 15:11:46 -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
15# use bash for pushd/popd, and to fail quickly. virtualenv's activate
16# has undefined variables, so no -u
17SHELL := bash -e -o pipefail
18
19WORKSPACE ?= $(HOME)
20VERSION ?= $(shell cat ./VERSION)
21
22# Robot confiig
23ROBOT_FILE ?=
24ROBOT_DIR ?=
25ROBOT_DEBUG_LOG_OPT ?=
26ROBOT_MISC_ARGS ?=
27ROBOT_TEST_TAGS ?= stable
28
29# Robot Job definitions
30siab-robot: ROBOT_FILE := SIAB.robot
31siab-robot: ROBOT_DIR := src/test/cord-api/Tests/WorkflowValidations
32siab-robot: ROBOT_MISC_ARGS += --removekeywords wuks -e notready $(ROBOT_DEBUG_LOG_OPT) -i $(ROBOT_TEST_TAGS) -v VOLTHA_DIR:$(WORKSPACE)/cord/incubator/voltha -v SUBSCRIBER_FILENAME:SIABSubscriberLatest -v WHITELIST_FILENAME:SIABWhitelistLatest -v OLT_DEVICE_FILENAME:SIABOLT0Device
33siab-robot: seba-robot
34
35seba-robot: venv_cord
36 source ./$</bin/activate ; set -u ;\
37 cd $(ROBOT_DIR) ;\
38 robot -V $(ROBOT_FILE) $(ROBOT_MISC_ARGS)
39
40# self-test, lint, and setup targets
41ROBOT_LINT_ARGS ?= --verbose \
Suchitra Vemurieaccb592020-07-15 17:53:48 -070042 --configure LineTooLong:120 \
43 --warning TooManyTestSteps \
44 --warning TooManyTestCases \
Zack Williams821c5022020-01-15 15:11:46 -070045 --configure TooFewTestSteps:1 \
46 --configure TooFewKeywordSteps:1 \
Suchitra Vemurieaccb592020-07-15 17:53:48 -070047 --warning FileTooLong \
48 --warning TrailingWhitespace \
49 --warning RequireKeywordDocumentation \
50 --warning RequireTestDocumentation \
51 --warning DuplicateTestNames
Zack Williams821c5022020-01-15 15:11:46 -070052
53PYTHON_FILES := $(shell find ./src -name *.py -print)
54ROBOT_FILES := $(shell find ./src -name *.robot -print)
55YAML_FILES := $(shell find . -type f \( -name *.yaml -o -name *.yml \) -print)
56JSON_FILES := $(shell find ./src -name *.json -print)
57JENKINSFILES := $(shell find . -type f -name 'Jenkinsfile*' -print)
58
59# virtualenv for the robot tools
60venv_cord:
61 virtualenv -p python3 $@ ;\
62 source ./$@/bin/activate ;\
63 pip install -r requirements.txt ;\
64 pip install -e cord-robot
65
Suchitra Vemurieaccb592020-07-15 17:53:48 -070066# cord-robot is totally deprecated, removing.
67test:
Zack Williams821c5022020-01-15 15:11:46 -070068
Suchitra Vemurieaccb592020-07-15 17:53:48 -070069# virtualenv for the robot tools
70# VOL-2724 Invoke pip via python3 to avoid pathname too long on QA jobs
71vst_venv:
72 virtualenv -p python3 $@ ;\
73 source ./$@/bin/activate ;\
74 python -m pip install -r requirements.txt
Zack Williams821c5022020-01-15 15:11:46 -070075
Suchitra Vemurieaccb592020-07-15 17:53:48 -070076lint: lint-robot lint-python lint-yaml lint-json
Zack Williams821c5022020-01-15 15:11:46 -070077
Suchitra Vemurieaccb592020-07-15 17:53:48 -070078lint-robot: vst_venv
Zack Williams821c5022020-01-15 15:11:46 -070079 source ./$</bin/activate ; set -u ;\
Suchitra Vemurieaccb592020-07-15 17:53:48 -070080 rflint $(ROBOT_LINT_ARGS) $(ROBOT_FILES)
Zack Williams821c5022020-01-15 15:11:46 -070081
82# check deps for format and python3 cleanliness
Suchitra Vemurieaccb592020-07-15 17:53:48 -070083lint-python: vst_venv
Zack Williams821c5022020-01-15 15:11:46 -070084 source ./$</bin/activate ; set -u ;\
Suchitra Vemurieaccb592020-07-15 17:53:48 -070085 pylint --py3k $(PYTHON_FILES) ;\
86 flake8 --max-line-length=119 --count $(PYTHON_FILES)
Zack Williams821c5022020-01-15 15:11:46 -070087
Suchitra Vemurieaccb592020-07-15 17:53:48 -070088lint-yaml: vst_venv
Zack Williams821c5022020-01-15 15:11:46 -070089 source ./$</bin/activate ; set -u ;\
90 yamllint \
Suchitra Vemurieaccb592020-07-15 17:53:48 -070091 -d "{extends: default, rules: {line-length: {max: 119}}}" \
92 -s $(YAML_FILES)
Zack Williams821c5022020-01-15 15:11:46 -070093
Suchitra Vemurieaccb592020-07-15 17:53:48 -070094lint-json: vst_venv
Zack Williams821c5022020-01-15 15:11:46 -070095 source ./$</bin/activate ; set -u ;\
Suchitra Vemurieaccb592020-07-15 17:53:48 -070096 for jsonfile in $(JSON_FILES); do \
97 echo "Validating json file: $$jsonfile" ;\
98 python -m json.tool $$jsonfile > /dev/null ;\
99 done
Zack Williams821c5022020-01-15 15:11:46 -0700100
101# only works on declarative pipeline Jenkinsfiles
102lint-jenkins:
103 ./scripts/jflint.sh $(JENKINSFILES)
104
105# tidy target will be more useful once issue with removing leading comments
106# is resolved: https://github.com/robotframework/robotframework/issues/3263
Suchitra Vemurieaccb592020-07-15 17:53:48 -0700107tidy-robot: vst_venv
Zack Williams821c5022020-01-15 15:11:46 -0700108 source ./$</bin/activate ; set -u ;\
Suchitra Vemurieaccb592020-07-15 17:53:48 -0700109 python -m robot.tidy --inplace $(ROBOT_FILES);
Zack Williams821c5022020-01-15 15:11:46 -0700110
111## Variables for gendocs
Andy Bavierde62ba72020-02-27 14:12:30 -0700112TEST_SOURCE := $(wildcard src/test/cord-api/Tests/*/*.robot)
Zack Williams821c5022020-01-15 15:11:46 -0700113TEST_BASENAME := $(basename $(TEST_SOURCE))
114TEST_DIRS := $(dir $(TEST_SOURCE))
115
Andy Bavierde62ba72020-02-27 14:12:30 -0700116PYLIB_SOURCE := $(filter-out cord-robot/CORDRobot/__init__.py, $(wildcard cord-robot/CORDRobot/*.py))
117PYLIB_BASENAME := $(basename $(PYLIB_SOURCE))
118PYLIB_DIRS := $(dir $(PYLIB_SOURCE))
119
120RESOURCE_SOURCE := $(wildcard cord-robot/CORDRobot/rf-resources/*.resource)
121RESOURCE_BASENAME := $(basename $(RESOURCE_SOURCE))
122RESOURCE_DIRS := $(dir $(RESOURCE_SOURCE))
Zack Williams821c5022020-01-15 15:11:46 -0700123
124.PHONY: gendocs lint test
Zack Williams821c5022020-01-15 15:11:46 -0700125gendocs: venv_cord
126 source ./$</bin/activate ; set -u ;\
127 mkdir -p $@ ;\
Andy Bavierde62ba72020-02-27 14:12:30 -0700128 for dir in ${PYLIB_DIRS}; do mkdir -p $@/$$dir; done;\
129 for dir in ${PYLIB_BASENAME}; do\
130 python -m robot.libdoc --format HTML $$dir.py $@/$$dir.html ;\
131 done ;\
132 for dir in ${RESOURCE_DIRS}; do mkdir -p $@/$$dir; done;\
133 for dir in ${RESOURCE_BASENAME}; do\
134 python -m robot.libdoc --format HTML $$dir.resource $@/$$dir.html ;\
Zack Williams821c5022020-01-15 15:11:46 -0700135 done ;\
136 for dir in ${TEST_DIRS}; do mkdir -p $@/$$dir; done;\
137 for dir in ${TEST_BASENAME}; do\
138 python -m robot.testdoc $$dir.robot $@/$$dir.html ;\
139 done
140
141clean:
142 find . -name output.xml -print
143
144clean-all: clean
Andy Bavier95032202020-02-26 06:25:56 -0700145 rm -rf venv_cord gendocs cord-robot/CORDRobot/VERSION cord-robot/dist/*
Zack Williams821c5022020-01-15 15:11:46 -0700146