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 \ |
| 42 | --configure LineTooLong:120 -e LineTooLong \ |
| 43 | -e TooManyTestSteps \ |
| 44 | -e TooManyTestCases \ |
| 45 | --configure TooFewTestSteps:1 \ |
| 46 | --configure TooFewKeywordSteps:1 \ |
| 47 | -e FileTooLong \ |
| 48 | -e TrailingWhitespace |
| 49 | |
| 50 | PYTHON_FILES := $(shell find ./src -name *.py -print) |
| 51 | ROBOT_FILES := $(shell find ./src -name *.robot -print) |
| 52 | YAML_FILES := $(shell find . -type f \( -name *.yaml -o -name *.yml \) -print) |
| 53 | JSON_FILES := $(shell find ./src -name *.json -print) |
| 54 | JENKINSFILES := $(shell find . -type f -name 'Jenkinsfile*' -print) |
| 55 | |
| 56 | # virtualenv for the robot tools |
| 57 | venv_cord: |
| 58 | virtualenv -p python3 $@ ;\ |
| 59 | source ./$@/bin/activate ;\ |
| 60 | pip install -r requirements.txt ;\ |
| 61 | pip install -e cord-robot |
| 62 | |
| 63 | test: cord-robot-test |
| 64 | |
| 65 | cord-robot-test: |
| 66 | cd cord-robot; tox |
| 67 | |
| 68 | lint: lint-python lint-json lint-yaml # lint-robot lint-jenkins |
| 69 | |
| 70 | lint-robot: venv_cord |
| 71 | source ./$</bin/activate ; set -u ;\ |
| 72 | rflint $(ROBOT_LINT_ARGS) $(ROBOT_FILES) |
| 73 | |
| 74 | # check deps for format and python3 cleanliness |
| 75 | lint-python: venv_cord |
| 76 | source ./$</bin/activate ; set -u ;\ |
| 77 | pylint --py3k $(PYTHON_FILES) ;\ |
| 78 | flake8 --max-line-length=119 --count $(PYTHON_FILES) |
| 79 | |
| 80 | lint-yaml: venv_cord |
| 81 | source ./$</bin/activate ; set -u ;\ |
| 82 | yamllint \ |
| 83 | -d "{extends: default, rules: {line-length: {max: 119}}}" \ |
| 84 | -s $(YAML_FILES) |
| 85 | |
| 86 | lint-json: venv_cord |
| 87 | source ./$</bin/activate ; set -u ;\ |
| 88 | for jsonfile in $(JSON_FILES); do \ |
| 89 | echo "Validating json file: $$jsonfile" ;\ |
| 90 | python -m json.tool $$jsonfile > /dev/null ;\ |
| 91 | done |
| 92 | |
| 93 | # only works on declarative pipeline Jenkinsfiles |
| 94 | lint-jenkins: |
| 95 | ./scripts/jflint.sh $(JENKINSFILES) |
| 96 | |
| 97 | # tidy target will be more useful once issue with removing leading comments |
| 98 | # is resolved: https://github.com/robotframework/robotframework/issues/3263 |
| 99 | tidy-robot: venv_cord |
| 100 | source ./$</bin/activate ; set -u ;\ |
| 101 | python -m robot.tidy --inplace $(ROBOT_FILES); |
| 102 | |
| 103 | ## Variables for gendocs |
Andy Bavier | de62ba7 | 2020-02-27 14:12:30 -0700 | [diff] [blame^] | 104 | TEST_SOURCE := $(wildcard src/test/cord-api/Tests/*/*.robot) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 105 | TEST_BASENAME := $(basename $(TEST_SOURCE)) |
| 106 | TEST_DIRS := $(dir $(TEST_SOURCE)) |
| 107 | |
Andy Bavier | de62ba7 | 2020-02-27 14:12:30 -0700 | [diff] [blame^] | 108 | PYLIB_SOURCE := $(filter-out cord-robot/CORDRobot/__init__.py, $(wildcard cord-robot/CORDRobot/*.py)) |
| 109 | PYLIB_BASENAME := $(basename $(PYLIB_SOURCE)) |
| 110 | PYLIB_DIRS := $(dir $(PYLIB_SOURCE)) |
| 111 | |
| 112 | RESOURCE_SOURCE := $(wildcard cord-robot/CORDRobot/rf-resources/*.resource) |
| 113 | RESOURCE_BASENAME := $(basename $(RESOURCE_SOURCE)) |
| 114 | RESOURCE_DIRS := $(dir $(RESOURCE_SOURCE)) |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 115 | |
| 116 | .PHONY: gendocs lint test |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 117 | gendocs: venv_cord |
| 118 | source ./$</bin/activate ; set -u ;\ |
| 119 | mkdir -p $@ ;\ |
Andy Bavier | de62ba7 | 2020-02-27 14:12:30 -0700 | [diff] [blame^] | 120 | for dir in ${PYLIB_DIRS}; do mkdir -p $@/$$dir; done;\ |
| 121 | for dir in ${PYLIB_BASENAME}; do\ |
| 122 | python -m robot.libdoc --format HTML $$dir.py $@/$$dir.html ;\ |
| 123 | done ;\ |
| 124 | for dir in ${RESOURCE_DIRS}; do mkdir -p $@/$$dir; done;\ |
| 125 | for dir in ${RESOURCE_BASENAME}; do\ |
| 126 | python -m robot.libdoc --format HTML $$dir.resource $@/$$dir.html ;\ |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 127 | done ;\ |
| 128 | for dir in ${TEST_DIRS}; do mkdir -p $@/$$dir; done;\ |
| 129 | for dir in ${TEST_BASENAME}; do\ |
| 130 | python -m robot.testdoc $$dir.robot $@/$$dir.html ;\ |
| 131 | done |
| 132 | |
| 133 | clean: |
| 134 | find . -name output.xml -print |
| 135 | |
| 136 | clean-all: clean |
Andy Bavier | 9503220 | 2020-02-26 06:25:56 -0700 | [diff] [blame] | 137 | rm -rf venv_cord gendocs cord-robot/CORDRobot/VERSION cord-robot/dist/* |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 138 | |