From b95f6bd7c86955ee2a9aa8f06ad605a628e58422 Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Tue, 7 Sep 2021 18:48:58 +0300 Subject: [PATCH] (#111): python virtualenv for users Signed-off-by: anastasia prasolova --- .gitignore | 3 ++- Makefile | 28 ++++++++++++++++++++-------- README.md | 31 +++++++------------------------ build_assets/activate.patch | 26 ++++++++++++++++++++++++++ venv/localtest/environment.sh | 5 +++++ venv/localtest/requirements.txt | 8 ++++++++ venv_template.mk | 20 ++++++++++++++++++++ 7 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 build_assets/activate.patch create mode 100644 venv/localtest/environment.sh create mode 100644 venv/localtest/requirements.txt create mode 100644 venv_template.mk diff --git a/.gitignore b/.gitignore index 82ca115..56c14be 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ **/__pycache__ TemporaryDir/* artifacts/* -docs/* \ No newline at end of file +docs/* +venv.*/* diff --git a/Makefile b/Makefile index c4efce5..8e3cb49 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,30 @@ +#!/usr/bin/make -f + .DEFAULT_GOAL := help -OUTPUT_DIR = artifacts/ -KEYWORDS_PATH = ../neofs-keywords -KEYWORDS_REPO = git@github.com:nspcc-dev/neofs-keywords.git +SHELL = bash -run: deps +OUTPUT_DIR = artifacts/ +KEYWORDS_REPO = git@github.com:nspcc-dev/neofs-keywords.git +VENVS = $(shell ls -1d venv/*/ | sort -u | xargs basename -a) + +.PHONY: all +all: venvs + +include venv_template.mk + +run: venvs @echo "⇒ Test Run" @robot --timestampoutputs --outputdir $(OUTPUT_DIR) robot/testsuites/integration/ -deps: $(KEYWORDS_PATH) +.PHONY: venvs +venvs: + $(foreach venv,$(VENVS),venv.$(venv)) -$(KEYWORDS_PATH): - @echo "Cloning keywords repo" - @git clone $(KEYWORDS_REPO) $(KEYWORDS_PATH) +$(foreach venv,$(VENVS),$(eval $(call VENV_template,$(venv)))) + +clean: + rm -rf venv.* help: @echo "⇒ run Run testcases ${R}" diff --git a/README.md b/README.md index 48d5054..2b027e3 100644 --- a/README.md +++ b/README.md @@ -22,17 +22,7 @@ - `sudo cp bin/neo-go /usr/local/bin/neo-go` or download binary from releases: https://github.com/nspcc-dev/neo-go/releases -4. Install Testcases dependencies - - `pip3.8 install -r requirements.txt` - - `make deps` - -Test cases are designed to run on Python 3.8. - -### Run - -0. Add keywords repo to PYTHONPATH `export PYTHONPATH=${PYTHONPATH}:~/neofs-keywords/lib::~/neofs-keywords/robot` - -1. Clone neofs-dev-env and prepare it +4. Clone neofs-dev-env and prepare it ``` # clean up obsolete volumes @@ -43,25 +33,18 @@ make up # decrease maximum object size to 1000 bytes make update.max_object_size val=1000 ``` -Also disable Storage Nodes Morph cache +5. Build virtual env ``` -export NEOFS_MORPH_DISABLE_CACHE=true +make venv.localtest +. venv.localtest/bin/activate ``` -2. Export neofs-dev-env variables into the shell where you are going to run tests +Test cases are designed to run on Python 3.8. -``` -cd neofs-dev-env -export `make env` -``` +### Run -3. Execute the command `make run` - -4. Logs will be available in the artifacts/ directory after tests with any of the statuses are completed. - - -### Running an arbitrary test case +Execute the command `make run`. Logs will be available in the artifacts/ directory after tests with any of the statuses are completed. To run an arbitrary UserScenario or testcase, you need to run the command: `robot --outputdir artifacts/ robot/testsuites/integration/` or `robot --outputdir artifacts/ robot/testsuites/integration//.robot` diff --git a/build_assets/activate.patch b/build_assets/activate.patch new file mode 100644 index 0000000..e240598 --- /dev/null +++ b/build_assets/activate.patch @@ -0,0 +1,26 @@ +diff -urN bin.orig/activate bin/activate +--- bin.orig/activate 2018-12-27 14:55:13.916461020 +0900 ++++ bin/activate 2018-12-27 20:38:35.223248728 +0900 +@@ -30,6 +30,10 @@ + unset _OLD_VIRTUAL_PS1 + fi + ++ # Uset external env variables ++ declare -f env_deactivate > /dev/null && env_deactivate ++ declare -f venv_deactivate > /dev/null && venv_deactivate ++ + unset VIRTUAL_ENV + if [ ! "${1-}" = "nondestructive" ] ; then + # Self destruct! +@@ -47,6 +51,11 @@ + PATH="$VIRTUAL_ENV/bin:$PATH" + export PATH + ++# Set external variables ++if [ -f ${VIRTUAL_ENV}/bin/environment.sh ] ; then ++ . ${VIRTUAL_ENV}/bin/environment.sh ++fi ++ + # unset PYTHONHOME if set + if ! [ -z "${PYTHONHOME+_}" ] ; then + _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME" diff --git a/venv/localtest/environment.sh b/venv/localtest/environment.sh new file mode 100644 index 0000000..494b1bb --- /dev/null +++ b/venv/localtest/environment.sh @@ -0,0 +1,5 @@ +# DevEnv variables +export NEOFS_MORPH_DISABLE_CACHE=true +pushd ../neofs-dev-env +export `make env` +popd diff --git a/venv/localtest/requirements.txt b/venv/localtest/requirements.txt new file mode 100644 index 0000000..42a31a5 --- /dev/null +++ b/venv/localtest/requirements.txt @@ -0,0 +1,8 @@ +robotframework==3.2.1 +requests==2.25.1 +pexpect==4.8.0 +boto3==1.16.33 +docker==4.4.0 +botocore==1.19.33 +urllib3==1.26.3 +base58==1.0.3 diff --git a/venv_template.mk b/venv_template.mk new file mode 100644 index 0000000..351e32d --- /dev/null +++ b/venv_template.mk @@ -0,0 +1,20 @@ +define VENV_template +venv.$(1): venv.$(1)/bin/activate venv.$(1)/bin/environment.sh + +venv.$(1)/bin/activate: venv/$(1)/requirements.txt + @echo "Creating $(1) venv in $$@ from $$<" + virtualenv --python=python3.8 --prompt="($(1))" venv.$(1) + source venv.$(1)/bin/activate && \ + pip3.8 install -Ur venv/$(1)/requirements.txt + @echo "Cloning keywords repo" + git clone $(KEYWORDS_REPO) venv.$(1)/neofs-keywords + source venv.$(1)/bin/activate && \ + pip3.8 install -Ur venv.$(1)/neofs-keywords/requirements.txt + @echo "Applying activate script patch" + patch -R --dry-run -p1 -s -f -d venv.$(1)/bin/ < build_assets/activate.patch || \ + patch -p1 -d venv.$(1)/bin/ < build_assets/activate.patch + +venv.$(1)/bin/environment.sh: | venv/$(1)/environment.sh + ln -s ../../venv/$(1)/environment.sh venv.$(1)/bin/environment.sh + +endef