Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 1 | # 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 |
| 17 | SHELL := bash -e -o pipefail |
| 18 | |
| 19 | WORKSPACE ?= $(HOME) |
| 20 | VERSION ?= $(shell cat ./VERSION) |
| 21 | |
| 22 | # Robot confiig |
| 23 | ROBOT_FILE ?= |
| 24 | ROBOT_DIR ?= |
| 25 | ROBOT_DEBUG_LOG_OPT ?= |
| 26 | ROBOT_MISC_ARGS ?= |
| 27 | ROBOT_TEST_TAGS ?= stable |
| 28 | |
| 29 | # Robot Job definitions |
| 30 | siab-robot: ROBOT_FILE := SIAB.robot |
| 31 | siab-robot: ROBOT_DIR := src/test/cord-api/Tests/WorkflowValidations |
| 32 | siab-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 |
| 33 | siab-robot: seba-robot |
| 34 | |
| 35 | seba-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 |
| 41 | ROBOT_LINT_ARGS ?= --verbose \ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 42 | --configure LineTooLong:120 \ |
| 43 | --warning TooManyTestSteps \ |
| 44 | --warning TooManyTestCases \ |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 45 | --configure TooFewTestSteps:1 \ |
| 46 | --configure TooFewKeywordSteps:1 \ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 47 | --warning FileTooLong \ |
| 48 | --warning TrailingWhitespace \ |
| 49 | --warning RequireKeywordDocumentation \ |
| 50 | --warning RequireTestDocumentation \ |
| 51 | --warning DuplicateTestNames |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 52 | |
| 53 | PYTHON_FILES := $(shell find ./src -name *.py -print) |
| 54 | ROBOT_FILES := $(shell find ./src -name *.robot -print) |
| 55 | YAML_FILES := $(shell find . -type f \( -name *.yaml -o -name *.yml \) -print) |
| 56 | JSON_FILES := $(shell find ./src -name *.json -print) |
| 57 | JENKINSFILES := $(shell find . -type f -name 'Jenkinsfile*' -print) |
| 58 | |
| 59 | # virtualenv for the robot tools |
| 60 | venv_cord: |
| 61 | virtualenv -p python3 $@ ;\ |
| 62 | source ./$@/bin/activate ;\ |
| 63 | pip install -r requirements.txt ;\ |
| 64 | pip install -e cord-robot |
| 65 | |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 66 | # cord-robot is totally deprecated, removing. |
| 67 | test: |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 68 | |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 69 | # virtualenv for the robot tools |
| 70 | # VOL-2724 Invoke pip via python3 to avoid pathname too long on QA jobs |
| 71 | vst_venv: |
| 72 | virtualenv -p python3 $@ ;\ |
| 73 | source ./$@/bin/activate ;\ |
| 74 | python -m pip install -r requirements.txt |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 75 | |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 76 | lint: lint-robot lint-python lint-yaml lint-json |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 77 | |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 78 | lint-robot: vst_venv |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 79 | source ./$</bin/activate ; set -u ;\ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 80 | rflint $(ROBOT_LINT_ARGS) $(ROBOT_FILES) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 81 | |
| 82 | # check deps for format and python3 cleanliness |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 83 | lint-python: vst_venv |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 84 | source ./$</bin/activate ; set -u ;\ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 85 | pylint --py3k $(PYTHON_FILES) ;\ |
| 86 | flake8 --max-line-length=119 --count $(PYTHON_FILES) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 87 | |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 88 | lint-yaml: vst_venv |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 89 | source ./$</bin/activate ; set -u ;\ |
| 90 | yamllint \ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 91 | -d "{extends: default, rules: {line-length: {max: 119}}}" \ |
| 92 | -s $(YAML_FILES) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 93 | |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 94 | lint-json: vst_venv |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 95 | source ./$</bin/activate ; set -u ;\ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 96 | for jsonfile in $(JSON_FILES); do \ |
| 97 | echo "Validating json file: $$jsonfile" ;\ |
| 98 | python -m json.tool $$jsonfile > /dev/null ;\ |
| 99 | done |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 100 | |
| 101 | # only works on declarative pipeline Jenkinsfiles |
| 102 | lint-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 Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 107 | tidy-robot: vst_venv |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 108 | source ./$</bin/activate ; set -u ;\ |
Suchitra Vemuri | eaccb59 | 2020-07-15 17:53:48 -0700 | [diff] [blame] | 109 | python -m robot.tidy --inplace $(ROBOT_FILES); |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 110 | |
| 111 | ## Variables for gendocs |
Andy Bavier | de62ba7 | 2020-02-27 14:12:30 -0700 | [diff] [blame] | 112 | TEST_SOURCE := $(wildcard src/test/cord-api/Tests/*/*.robot) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 113 | TEST_BASENAME := $(basename $(TEST_SOURCE)) |
| 114 | TEST_DIRS := $(dir $(TEST_SOURCE)) |
| 115 | |
Andy Bavier | de62ba7 | 2020-02-27 14:12:30 -0700 | [diff] [blame] | 116 | PYLIB_SOURCE := $(filter-out cord-robot/CORDRobot/__init__.py, $(wildcard cord-robot/CORDRobot/*.py)) |
| 117 | PYLIB_BASENAME := $(basename $(PYLIB_SOURCE)) |
| 118 | PYLIB_DIRS := $(dir $(PYLIB_SOURCE)) |
| 119 | |
| 120 | RESOURCE_SOURCE := $(wildcard cord-robot/CORDRobot/rf-resources/*.resource) |
| 121 | RESOURCE_BASENAME := $(basename $(RESOURCE_SOURCE)) |
| 122 | RESOURCE_DIRS := $(dir $(RESOURCE_SOURCE)) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 123 | |
| 124 | .PHONY: gendocs lint test |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 125 | gendocs: venv_cord |
| 126 | source ./$</bin/activate ; set -u ;\ |
| 127 | mkdir -p $@ ;\ |
Andy Bavier | de62ba7 | 2020-02-27 14:12:30 -0700 | [diff] [blame] | 128 | 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 Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 135 | 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 | |
| 141 | clean: |
| 142 | find . -name output.xml -print |
| 143 | |
| 144 | clean-all: clean |
Hardik Windlass | 70761af | 2021-10-05 09:25:56 +0000 | [diff] [blame^] | 145 | rm -rf vst_venv venv_cord gendocs cord-robot/CORDRobot/VERSION cord-robot/dist/* |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 146 | |