Update tobiko-deploy and tobiko-ensure-* roles

Change-Id: I1354b356970a7da24679a2cb1e2730d0c59f32e4
This commit is contained in:
Federico Ressi 2020-04-03 11:41:08 +02:00
parent 86441d7aac
commit 672017742a
15 changed files with 278 additions and 120 deletions

View File

@ -29,35 +29,22 @@ subparsers:
- title: Deploy stage
options:
clean-deploy-dir:
clean:
type: Flag
help: Cleanup directory where test cases will be downloaded
ansible_variable: clean_deploy_dir
tobiko-src-dir:
git-base:
type: Value
help: Local directory where tobiko scripts are found
ansible_variable: tobiko_src_dir
tobiko-dir:
type: Value
help: Test host directory where Tobiko has to be deployed to
ansible_variable: tobiko_dir
tobiko-version:
type: Value
help: Git version to be used for checking out Tobiko scripts
ansible_variable: tobiko_git_version
tobiko-refspec:
type: Value
help: Git refspect to be used for checking out Tobiko scripts
ansible_variable: tobiko_git_refspec
test-src-dir:
type: Value
help: Local directory where test cases (and tox.ini file) are found
ansible_variable: test_src_dir
help: Git Url prefix where test projects are fetched from
ansible_variable: git_base
test-dir:
type: Value
help: Test host directory where test cases (and tox.ini file) are found
ansible_variable: test_dir
test-repo:
type: Value
help: Git URL from where to download test files
ansible_variable: test_git_repo
test-version:
type: Value
help: Git version to be used for checking out test scripts
@ -66,6 +53,30 @@ subparsers:
type: Value
help: Git refspect to be used for checking out test scripts
ansible_variable: test_git_refspec
test-src-dir:
type: Value
help: Local directory where test cases (and tox.ini file) are found
ansible_variable: test_src_dir
tobiko-dir:
type: Value
help: Test host directory where Tobiko has to be deployed to
ansible_variable: tobiko_dir
tobiko-repo:
type: Value
help: Git URL from where to download tobiko files
ansible_variable: tobiko_git_repo
tobiko-version:
type: Value
help: Git version to be used for checking out Tobiko scripts
ansible_variable: tobiko_git_version
tobiko-refspec:
type: Value
help: Git refspect to be used for checking out Tobiko scripts
ansible_variable: tobiko_git_refspec
tobiko-src-dir:
type: Value
help: Local directory where tobiko scripts are found
ansible_variable: tobiko_src_dir
- title: Configure stage
options:
@ -123,3 +134,4 @@ subparsers:
type: Value
help: local directory where report files are going to be copied to
ansible_variable: test_collect_dir
default: '{{ inventory_dir }}/{{ test_report_name }}'

View File

@ -7,21 +7,29 @@ test_stage: all
# --- Test deploy options -----------------------------------------------------
test_home: '{{ (ansible_user_dir + "/src") | realpath }}'
test_dir: '{{ tobiko_dir | realpath }}'
test_src_dir: ''
test_git_repo: ''
deploy_home: '{{ ansible_user_dir | realpath }}/src'
git_base: 'https://opendev.org'
test_dir: "{{ deploy_home }}/{{ test_project }}"
test_project:
"{{ test_git_repo | urlsplit('path') | regex_replace('^\\/|\\/$', '') | splitext | first }}"
test_git_repo: '{{ git_base }}/x/tobiko.git'
test_git_refspec: ''
test_git_version: ''
test_git_version: 'master'
test_src_dir: ''
# NOTE: if test_dir and tobiko_dir variables endup being the same actual
# directory then test_src and test_git_* variables will be overriden
# tobiko_src and tobiko_git_* variables
# --- Tobiko deploy options ---------------------------------------------------
tobiko_dir: '{{ test_home | realpath }}/tobiko'
tobiko_src_dir: '{{ role_path | realpath | dirname | dirname }}'
tobiko_git_repo: 'https://opendev.org/x/tobiko.git'
tobiko_dir: "{{ deploy_home }}/{{ tobiko_project }}"
tobiko_project:
"{{ tobiko_git_repo | urlsplit('path') | regex_replace('^\\/|\\/$', '') | splitext | first }}"
tobiko_git_repo: '{{ git_base }}/x/tobiko.git'
tobiko_git_refspec: ''
tobiko_git_version: ''
tobiko_src_dir: ''
# --- Test configuration options ----------------------------------------------

View File

@ -1,11 +1,25 @@
---
# Directory where files has to be deployed to
src_dir: '{{ tobiko_src_dir }}'
dest_dir: '{{ tobiko_dir }}'
git_repo: '{{ tobiko_git_repo }}'
git_refspec: '{{ tobiko_git_refspec }}'
git_version: '{{ tobiko_git_version }}'
# Directoies where files has to be deployed to
clean_deploy_dir: false
test_deploy_dirs:
# test suite directory
- clean_dir: '{{ clean_deploy_dir }}'
dest_dir: '{{ test_dir }}'
git_repo: '{{ test_git_repo }}'
git_refspec: '{{ test_git_refspec }}'
git_version: '{{ test_git_version }}'
src_dir: '{{ test_src_dir }}'
# Tobiko framework directory
- clean_dir: '{{ clean_deploy_dir }}'
dest_dir: '{{ tobiko_dir }}'
git_repo: '{{ tobiko_git_repo }}'
git_refspec: '{{ tobiko_git_refspec }}'
git_version: '{{ tobiko_git_version }}'
src_dir: '{{ tobiko_src_dir }}'
bindep_file: bindep.txt
bindep_profiles: test

View File

@ -2,8 +2,6 @@
dependencies:
- role: tobiko-common
- role: tobiko-ensure-rsync
- role: tobiko-ensure-git
when: >
(tobiko_git_repo is defined) or
(test_git_repo is defined)
- role: tobiko-ensure-bindep

View File

@ -0,0 +1,89 @@
---
- name: "set deploy source variables"
set_fact:
'{{ item.0 }}': '{{ item.1 }}'
loop: '{{ deploy.1 | dictsort }}'
loop_control:
label: '{{ item.0 }}'
- name: "clean directory '{{ dest_dir }}'"
file:
path: "{{ dest_dir | realpath }}"
state: absent
when:
- clean_dir | bool
- |
(src_dir | length) == 0 or
(git_version | length) > 0 or
(git_refspec | length) == 0
- name: "create directory {{ dest_dir }}"
file:
path: "{{ dest_dir | realpath }}"
state: directory
- name: "copy '{{ src_dir }}' to '{{ dest_dir }}'"
synchronize:
src: "{{ src_dir | realpath }}/."
dest: "{{ dest_dir | realpath }}"
use_ssh_args: yes
recursive: yes
delete: "{{ clean_dir | bool }}"
rsync_opts:
- "--exclude-from={{ src_dir | realpath }}/.gitignore"
when:
- (src_dir | length) > 0
- (git_version | length) == 0
- (git_refspec | length) == 0
- name: "checkout test cases from '{{ git_repo }}[{{ git_refspec or git_version }}]' to '{{ dest_dir }}'"
git:
dest: '{{ dest_dir }}'
repo: '{{ git_repo }}'
refspec: '{{ git_refspec }}'
version: '{%if (git_refspec | length) %}FETCH_HEAD{% else %}{{ git_version }}{% endif %}'
force: yes
when: |
(src_dir | length) == 0 or
(git_version | length) > 0 or
(git_refspec | length) > 0
- name: "get last change details for '{{ dest_dir }}'" # noqa 303
command:
chdir: "{{ dest_dir }}"
cmd: git log -n 1
register: get_git_log
- name: "show last change details"
debug: var=get_git_log.stdout_lines
- block:
- name: "check missing binary dependencies from '{{ bindep_file }}'"
command:
cmd: >
'{{ bindep_executable }}' -b -f '{{ bindep_file }}' {{ bindep_profiles }}
chdir: '{{ dest_dir }}'
register: get_bindeps
changed_when: no
rescue:
- name: "install missing dependencies"
become: yes
package:
name: '{{ get_bindeps.stdout_lines }}'
- name: "check missing binary dependencies from '{{ bindep_file }}'"
command:
cmd: >
'{{ bindep_executable }}' -b -f '{{ bindep_file }}' {{ bindep_profiles }}
chdir: '{{ dest_dir }}'
register: get_bindeps
changed_when: no

View File

@ -0,0 +1,21 @@
---
- name: 'combine test_deploy_dirs variables'
set_fact:
_test_deploy_dirs: >
{{ _test_deploy_dirs |
default({}) |
combine({(item.dest_dir | expanduser | realpath): item}) }}
loop: '{{ test_deploy_dirs }}'
loop_control:
label: '{{ item.dest_dir }}'
- name: "show combined deploy variables"
debug: var=_test_deploy_dirs
- name: "deploy test directories'"
include_tasks: deploy-dir.yaml
loop: '{{ _test_deploy_dirs | dictsort }}'
loop_control:
label: '{{ deploy.0 }}'
loop_var: deploy

View File

@ -1,57 +1,6 @@
---
- name: "clean directory {{ dest_dir }}"
file:
path: "{{ dest_dir | realpath }}"
state: absent
- name: "deploy test cases"
include_tasks: deploy.yaml
when:
- clean_deploy_dir | bool
- |
(src_dir | length) == 0 or
(git_version | length) > 0 or
(git_refspec | length) == 0
- name: "create directory {{ dest_dir }}"
file:
path: "{{ dest_dir | realpath }}"
state: directory
- name: "copy '{{ src_dir }}' to '{{ dest_dir }}'"
synchronize:
src: "{{ src_dir | realpath }}/."
dest: "{{ dest_dir | realpath }}"
use_ssh_args: yes
recursive: yes
delete: "{{ clean_deploy_dir | bool }}"
rsync_opts:
- "--exclude-from={{ src_dir | realpath }}/.gitignore"
when:
- (src_dir | length) > 0
- (git_version | length) == 0
- (git_refspec | length) == 0
- name: "checkout test cases from '{{ git_repo }}[{{ git_refspec or git_version }}]' to '{{ dest_dir }}'"
git:
dest: '{{ dest_dir }}'
repo: '{{ git_repo }}'
refspec: '{{ git_refspec }}'
version: '{%if (git_refspec | length) %}FETCH_HEAD{% else %}{{ git_version }}{% endif %}'
force: yes
when: |
(src_dir | length) == 0 or
(git_version | length) > 0 or
(git_refspec | length) > 0
- name: "get last change details" # noqa 303
command:
chdir: "{{ dest_dir }}"
cmd: git log -n 1
register: get_git_log
- name: "show last change details"
debug: var=get_git_log.stdout_lines
- test_stage in ['all', 'pre-run', 'deploy']

View File

@ -1,23 +1,40 @@
---
- name: "ensure Bindep is installed"
command: |
command: >
'{{ python_executable }}' -m pip install --user 'bindep>={{ bindep_min_version }}'
register: result
changed_when: "'Successfully installed' in result.stdout"
register: install_bindep
changed_when: "'Successfully installed' in install_bindep.stdout"
- name: "set bindep_executable fact"
set_fact:
bindep_executable: "{{ ansible_user_dir }}/.local/bin/bindep"
cacheable: true
when: result is changed
- block:
- name: "get '{{ bindep_executable }}' full path"
command: >
which '{{ bindep_executable }}'
register: get_bindep_path
- name: "update bindep_executable fact"
set_fact:
bindep_executable: '{{ get_bindep_path.stdout_lines | first }}'
rescue:
- name: "update bindep_executable fact"
set_fact:
bindep_executable: '{{ ansible_user_dir }}/.local/bin/bindep'
- name: "get installed Bindep version"
command: "{{ bindep_executable }} --version"
register: get_installed_bindep_version
command: "'{{ bindep_executable }}' --version"
register: get_bindep_version
- name: "show Bindep installed version"
debug: var=get_installed_bindep_version.stdout_lines
- name: "update bindep_version fact"
set_fact:
bindep_version: '{{ get_bindep_version.stdout }}'
- name: "show Bindep facts"
debug:
msg:
bindep_executable: '{{ bindep_executable }}'
bindep_version: '{{ bindep_version }}'

View File

@ -3,4 +3,4 @@
- name: "ensures '{{ bindep_executable }}' command is available"
include_tasks: bindep.yaml
when:
- test_stage in ['all', 'pre-run', 'bindep']
- bindep_version is not defined

View File

@ -0,0 +1,4 @@
---
dependencies:
- role: tobiko-common

View File

@ -0,0 +1,6 @@
---
- name: "ensures 'rsync' command is available"
include_tasks: rsync.yaml
when:
- test_stage in ['all', 'pre-run', 'rsync']

View File

@ -0,0 +1,23 @@
---
- block:
- name: "get installed rsync version" # noqa 303
shell: >
rsync --version
register: get_rsync_gersion
rescue:
- name: "install rsync packages"
become: true
package:
name: rsync
- name: "get installed rsync version" # noqa 303
shell: >
rsync --version
register: get_rsync_gersion
- name: "show installed rsync version"
debug:
var: get_rsync_gersion.stdout_lines

View File

@ -3,4 +3,4 @@
- name: "ensures '{{ tox_executable }}' command is available"
include_tasks: tox.yaml
when:
- test_stage in ['all', 'pre-run', 'tox']
- tox_version is not defined

View File

@ -7,17 +7,34 @@
changed_when: "'Successfully installed' in result.stdout"
- name: "set tox_executable fact"
set_fact:
tox_executable: "{{ ansible_user_dir }}/.local/bin/tox"
cacheable: true
when: result is changed
- block:
- name: "get '{{ tox_executable }}' full path"
command: >
which '{{ tox_executable }}'
register: get_tox_path
- name: "update tox_executable fact"
set_fact:
tox_executable: '{{ get_tox_path.stdout_lines | first }}'
rescue:
- name: "update tox_executable fact"
set_fact:
tox_executable: '{{ ansible_user_dir }}/.local/bin/tox'
- name: "get installed Tox version"
command: "{{ tox_executable }} --version"
register: get_installed_tox_version
command: "'{{ tox_executable }}' --version"
register: get_tox_version
- name: "show Tox installed version"
debug: var=get_installed_tox_version.stdout_lines
- name: "update tox_version fact"
set_fact:
tox_version: '{{ get_tox_version.stdout }}'
- name: "show Tox facts"
debug:
msg:
tox_executable: '{{ tox_executable }}'
tox_version: '{{ tox_version }}'

View File

@ -179,7 +179,7 @@ commands = {posargs:bash}
# On RedHat Linux must use the default unversioned python because of dependency on native SELinux
# package available only for /usr/bin/python interpreter
basepython = {env:IR_PYTHON:/usr/bin/python}
basepython = {env:IR_PYTHON:python}
usedevelop = false
skipdist = true
skip_install = true