Allow to specify python interpter used for testing IR plugin
Change-Id: I2ea68efed1fe1c0dc22b3c49118cfc5c93c8a037
This commit is contained in:
parent
b12c5d5d12
commit
e116222308
|
@ -20,6 +20,11 @@ subparsers:
|
||||||
default: localhost
|
default: localhost
|
||||||
help: Target host where test cases are deployed and executed
|
help: Target host where test cases are deployed and executed
|
||||||
ansible_variable: test_host
|
ansible_variable: test_host
|
||||||
|
ansible-python-interpreter:
|
||||||
|
type: Value
|
||||||
|
default: python3
|
||||||
|
help: Python interpreter executed by ansible on target hosts
|
||||||
|
ansible_variable: ansible_python_interpreter
|
||||||
|
|
||||||
- title: Control flow
|
- title: Control flow
|
||||||
options:
|
options:
|
||||||
|
@ -89,14 +94,22 @@ subparsers:
|
||||||
type: Value
|
type: Value
|
||||||
help: command to be executed for tox (typically tox)
|
help: command to be executed for tox (typically tox)
|
||||||
ansible_variable: tox_command
|
ansible_variable: tox_command
|
||||||
|
tox-environment:
|
||||||
|
type: Value
|
||||||
|
help: envitonment variables to be set when running test cases
|
||||||
|
ansible_variable: tox_environment
|
||||||
tox-envlist:
|
tox-envlist:
|
||||||
type: Value
|
type: Value
|
||||||
help: tox environment list to be executed
|
help: Tox environment names to be executed
|
||||||
ansible_variable: tox_envlist
|
ansible_variable: tox_envlist
|
||||||
tox-extra-args:
|
tox-extra-args:
|
||||||
type: Value
|
type: Value
|
||||||
help: extra options to be passed to Tox
|
help: extra options to be passed to Tox
|
||||||
ansible_variable: tox_extra_args
|
ansible_variable: tox_extra_args
|
||||||
|
tox-python:
|
||||||
|
type: Value
|
||||||
|
help: Python interpreter to be used for executing test cases
|
||||||
|
ansible_variable: tox_python
|
||||||
test-report-dir:
|
test-report-dir:
|
||||||
type: Value
|
type: Value
|
||||||
help: directory where to store test report files
|
help: directory where to store test report files
|
||||||
|
|
|
@ -19,7 +19,6 @@ test_git_repo: '{{ tobiko_git_repo | realpath }}'
|
||||||
test_git_refspec: ''
|
test_git_refspec: ''
|
||||||
test_git_version: ''
|
test_git_version: ''
|
||||||
|
|
||||||
|
|
||||||
# --- Test configuration options ----------------------------------------------
|
# --- Test configuration options ----------------------------------------------
|
||||||
|
|
||||||
# Configuration options
|
# Configuration options
|
||||||
|
|
|
@ -4,9 +4,14 @@
|
||||||
tox_dir: '{{ test_dir | realpath }}'
|
tox_dir: '{{ test_dir | realpath }}'
|
||||||
tox_command: tox
|
tox_command: tox
|
||||||
tox_environment: {}
|
tox_environment: {}
|
||||||
tox_envlist: py36
|
tox_envlist:
|
||||||
tox_extra_args: ''
|
tox_extra_args: ''
|
||||||
|
tox_command_line: >
|
||||||
|
{{ tox_command }}
|
||||||
|
{% if tox_envlist %} -e {{ tox_envlist | quote }} {% endif %}
|
||||||
|
{{ tox_extra_args }}
|
||||||
|
|
||||||
|
tox_python: 'python3'
|
||||||
tox_report_dir: '{{ test_report_dir | realpath }}'
|
tox_report_dir: '{{ test_report_dir | realpath }}'
|
||||||
tox_report_name: '{{ test_report_name }}_{{ tox_envlist }}'
|
tox_report_name: '{{ test_report_name }}_{{ tox_envlist }}'
|
||||||
tox_report_env:
|
tox_report_env:
|
||||||
|
|
|
@ -1,10 +1,26 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: "run test Tox envlist '{{ tox_envlist }}' on direcory '{{ tox_dir }}'"
|
- name: "set 'PYTHON={{ tox_python }}' in Tox environment variables"
|
||||||
shell:
|
set_fact:
|
||||||
chdir: "{{ tox_dir }}"
|
tox_environment: >
|
||||||
cmd: |
|
{{ tox_environment | combine({ "PYTHON": (tox_python or "") }) }}
|
||||||
{{ tox_command }} -e "{{ tox_envlist }}" {{ tox_extra_args }}
|
when:
|
||||||
|
- tox_python is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: "show tox environment"
|
||||||
|
debug: var=tox_environment
|
||||||
|
|
||||||
|
|
||||||
|
- name: "normalize white spaces from Tox command line"
|
||||||
|
set_fact:
|
||||||
|
tox_command_line: '{{ tox_command_line.split() | join(" ") }}'
|
||||||
|
|
||||||
|
|
||||||
|
- name: "run Tox on direcory '{{ tox_dir }}': '{{ tox_command_line }}'"
|
||||||
|
command:
|
||||||
|
chdir: '{{ tox_dir }}'
|
||||||
|
cmd: '{{ tox_command_line }}'
|
||||||
register:
|
register:
|
||||||
run_tox
|
run_tox
|
||||||
environment: '{{ tox_environment }}'
|
environment: '{{ tox_environment }}'
|
||||||
|
|
|
@ -14,7 +14,7 @@ function get_realpath {
|
||||||
(
|
(
|
||||||
export PATH=${CI_TOOLS_ORIGINAL_PATH:-${PATH}}
|
export PATH=${CI_TOOLS_ORIGINAL_PATH:-${PATH}}
|
||||||
local tools_dir=$(dirname "${BASH_SOURCE[0]}")
|
local tools_dir=$(dirname "${BASH_SOURCE[0]}")
|
||||||
local python=$(which python3 || which python2 || wich python)
|
local python=$(which python3 || which python2 || which python)
|
||||||
if [ -x "${python}" ] && "${python}" --version > /dev/null; then
|
if [ -x "${python}" ] && "${python}" --version > /dev/null; then
|
||||||
local script="${tools_dir}/realpath.py"
|
local script="${tools_dir}/realpath.py"
|
||||||
local script=$("${python}" "${script}" "${script}")
|
local script=$("${python}" "${script}" "${script}")
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
# Copyright 2018 Red Hat
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
setup_logging()
|
||||||
|
add_plugin('tobiko', os.environ.get('IR_TOBIKO_PLUGIN'))
|
||||||
|
import_workspace(os.environ.get('IR_WORKSPACE_FILE'))
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logging(level=logging.DEBUG):
|
||||||
|
logging.basicConfig(
|
||||||
|
level=level, stream=sys.stderr,
|
||||||
|
format='%(name)-s: %(levelname)-7s %(asctime)-15s | %(message)s')
|
||||||
|
|
||||||
|
|
||||||
|
def add_plugin(name, path):
|
||||||
|
path = path or os.environ.get('IR_TOBIKO_PLUGIN')
|
||||||
|
if path:
|
||||||
|
path = normalize_path(path)
|
||||||
|
if os.path.isdir(path):
|
||||||
|
remove_plugin(name)
|
||||||
|
execute('ir plugin add "{}"', path)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_plugin(name):
|
||||||
|
try:
|
||||||
|
execute('ir plugin remove "{}"', name)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def import_workspace(filename):
|
||||||
|
if filename:
|
||||||
|
filename = normalize_path(filename)
|
||||||
|
if os.path.isfile(filename):
|
||||||
|
try:
|
||||||
|
execute('ir workspace import "{}"', filename)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# If file was already imported before we checkout to its
|
||||||
|
# workspace
|
||||||
|
workspace = name_from_path(filename)
|
||||||
|
execute('ir workspace checkout "{}"', workspace)
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_path(path):
|
||||||
|
return os.path.realpath(os.path.expanduser(path))
|
||||||
|
|
||||||
|
|
||||||
|
def execute(command, *args, **kwargs):
|
||||||
|
if args or kwargs:
|
||||||
|
command = command.format(*args, **kwargs)
|
||||||
|
LOG.info('%s', command)
|
||||||
|
return subprocess.check_output(command, shell=True)
|
||||||
|
|
||||||
|
|
||||||
|
def name_from_path(path):
|
||||||
|
return os.path.splitext(os.path.basename(path))[0]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
LOG = logging.getLogger(name_from_path(__file__))
|
||||||
|
main()
|
33
tox.ini
33
tox.ini
|
@ -1,6 +1,6 @@
|
||||||
[tox]
|
[tox]
|
||||||
|
|
||||||
envlist = linters,py37,docs
|
envlist = bindep,linters,cover
|
||||||
minversion = 3.4.0
|
minversion = 3.4.0
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,11 +177,11 @@ commands = {posargs:bash}
|
||||||
|
|
||||||
[testenv:infrared]
|
[testenv:infrared]
|
||||||
|
|
||||||
# Package libselinux-python3 still not available on centos-7
|
basepython = {env:PYTHON:python3}
|
||||||
basepython = python
|
usedevelop = false
|
||||||
usedevelop = False
|
skipdist = true
|
||||||
skipdist = True
|
skip_install = true
|
||||||
skip_install = True
|
sitepackages = true
|
||||||
deps =
|
deps =
|
||||||
-r infrared-requirements.txt
|
-r infrared-requirements.txt
|
||||||
passenv =
|
passenv =
|
||||||
|
@ -193,15 +193,20 @@ passenv =
|
||||||
|
|
||||||
setenv =
|
setenv =
|
||||||
{[testenv:venv]setenv}
|
{[testenv:venv]setenv}
|
||||||
IR_COMMAND={env:IR_COMMAND:{toxinidir}/tools/ci/ir}
|
|
||||||
IR_HOME={env:IR_HOME:{envdir}/home/infrared}
|
|
||||||
ANSIBLE_CONFIG={env:ANSIBLE_CONFIG:{toxinidir}/ansible.cfg}
|
ANSIBLE_CONFIG={env:ANSIBLE_CONFIG:{toxinidir}/ansible.cfg}
|
||||||
|
ANSIBLE_PYTHON_INTERPRETER={env:ANSIBLE_PYTHON_INTERPRETER:python3}
|
||||||
|
IR_HOME={env:IR_HOME:{envdir}/home/infrared}
|
||||||
|
IR_TOBIKO_PLUGIN={env:IR_TOBIKO_PLUGIN:{toxinidir}/roles}
|
||||||
|
IR_WORKSPACE_FILE={env:IR_WORKSPACE_FILE:{toxinidir}/workspace.tgz}
|
||||||
|
PYTHON={env:PYTHON:python3}
|
||||||
|
|
||||||
commands_pre =
|
commands_pre =
|
||||||
-ir plugin remove tobiko
|
{envpython} {toxinidir}/tools/setup_infrared.py
|
||||||
ir plugin add {toxinidir}/roles
|
|
||||||
-ir workspace import {env:IR_WORKSPACE_FILE:{toxinidir}/workspace.tgz}
|
|
||||||
commands =
|
commands =
|
||||||
ir tobiko --tobiko-src-dir {toxinidir} {posargs}
|
ir tobiko \
|
||||||
|
--ansible-python-interpreter {env:ANSIBLE_PYTHON_INTERPRETER} \
|
||||||
|
--tobiko-src-dir {toxinidir} {posargs}
|
||||||
|
|
||||||
|
|
||||||
# --- documentation environments ----------------------------------------------
|
# --- documentation environments ----------------------------------------------
|
||||||
|
@ -257,10 +262,10 @@ commands =
|
||||||
|
|
||||||
|
|
||||||
[testenv:bindep]
|
[testenv:bindep]
|
||||||
basepython = python3
|
basepython = {env:PYTHON:python3}
|
||||||
# Do not install any requirements. We want this to be fast and work even if
|
# Do not install any requirements. We want this to be fast and work even if
|
||||||
# system dependencies are missing, since it's used to tell you what system
|
# system dependencies are missing, since it's used to tell you what system
|
||||||
# dependencies are missing! This also means that bindep must be installed
|
# dependencies are missing! This also means that bindep must be installed
|
||||||
# separately, outside of the requirements files.
|
# separately, outside of the requirements files.
|
||||||
deps = bindep
|
deps = bindep
|
||||||
commands = bindep test
|
commands = bindep {posargs:test}
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
test_results_dir: '{{ zuul_output_dir }}/logs'
|
test_results_dir: '{{ zuul_output_dir }}/logs'
|
||||||
tox_envlist: infrared
|
tox_envlist: infrared
|
||||||
tox_extra_args: >
|
tox_extra_args: >
|
||||||
-- --collect-dir '{{ test_results_dir }}'
|
--
|
||||||
|
--collect-dir '{{ test_results_dir }}'
|
||||||
pre-run: playbooks/infrared/pre.yaml
|
pre-run: playbooks/infrared/pre.yaml
|
||||||
post-run: playbooks/infrared/post.yaml
|
post-run: playbooks/infrared/post.yaml
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue