From 3eadbe21f943708e7c77f8d83a50341cbdfb1a5e Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Tue, 21 Apr 2020 14:49:12 +0200 Subject: [PATCH] Set remote test directories owner user Change-Id: I007b5f88a72f4c3a821466358d0c3793008354cf --- infrared_plugin/plugin.spec | 23 +++++++++++++++++++++++ roles/tobiko-common/defaults/main.yaml | 11 ++++++++--- roles/tobiko-deploy/defaults/main.yaml | 4 ++++ roles/tobiko-deploy/tasks/deploy-dir.yaml | 16 ++++++++++++---- roles/tobiko-deploy/tasks/deploy.yaml | 2 ++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/infrared_plugin/plugin.spec b/infrared_plugin/plugin.spec index 7470aabe4..88308f5a6 100644 --- a/infrared_plugin/plugin.spec +++ b/infrared_plugin/plugin.spec @@ -12,6 +12,13 @@ subparsers: include_groups: ["Ansible options", "Inventory", "Common options", "Answers file"] groups: + - title: Common options + options: + no-become: + type: Flag + help: Forbid roles from escalate tasks execution as superuser + ansible_variable: test_no_become + - title: Topology options options: host: @@ -39,6 +46,14 @@ subparsers: type: Value help: Test host directory where test cases (and tox.ini file) are found ansible_variable: test_dir + test-user: + type: Value + help: Test host user that should own tests directory + ansible_variable: test_user + test-group: + type: Value + help: Test host user group that should own tests directory + ansible_variable: test_group test-repo: type: Value help: Git URL from where to download test files @@ -63,6 +78,14 @@ subparsers: type: Value help: Test host directory where Tobiko has to be deployed to ansible_variable: tobiko_dir + tobiko-user: + type: Value + help: Test host user that should own Tobiko directory + ansible_variable: tobiko_user + tobiko-group: + type: Value + help: Test host user group that should own Tobiko directory + ansible_variable: tobiko_group tobiko-repo: type: Value help: Git URL from where to download tobiko files diff --git a/roles/tobiko-common/defaults/main.yaml b/roles/tobiko-common/defaults/main.yaml index a6f5af050..3ef4b2285 100644 --- a/roles/tobiko-common/defaults/main.yaml +++ b/roles/tobiko-common/defaults/main.yaml @@ -3,7 +3,8 @@ # --- Tobiko workflow stages test_stage: all - +test_no_become: false +test_become: '{{ not (test_no_become | bool) }}' # --- Test deploy options ----------------------------------------------------- @@ -16,9 +17,11 @@ test_project: "{{ test_git_repo | urlsplit('path') | regex_replace('^\\/|\\/$', '') | splitext | first }}" test_git_repo: '{{ git_base }}/x/tobiko.git' test_git_refspec: '' -test_git_remote: 'origin' +test_git_remote: '{{ omit }}' test_git_version: 'master' test_src_dir: '' +test_user: '{{ ansible_user | default(omit) }}' +test_group: '{{ test_user }}' # NOTE: if test_dir and tobiko_dir variables endup being the same actual @@ -30,9 +33,11 @@ tobiko_project: "{{ tobiko_git_repo | urlsplit('path') | regex_replace('^\\/|\\/$', '') | splitext | first }}" tobiko_git_repo: '{{ git_base }}/x/tobiko.git' tobiko_git_refspec: '' -tobiko_git_remote: 'origin' +tobiko_git_remote: '{{ omit }}' tobiko_git_version: 'master' tobiko_src_dir: '' +tobiko_user: '{{ ansible_user | default(omit) }}' +tobiko_group: '{{ tobiko_user }}' # --- Test configuration options ---------------------------------------------- diff --git a/roles/tobiko-deploy/defaults/main.yaml b/roles/tobiko-deploy/defaults/main.yaml index 958ccfbc7..ce1f04ebd 100644 --- a/roles/tobiko-deploy/defaults/main.yaml +++ b/roles/tobiko-deploy/defaults/main.yaml @@ -8,6 +8,8 @@ test_deploy_dirs: # test suite directory - clean_dir: '{{ clean_deploy_dir }}' dest_dir: '{{ test_dir }}' + dest_user: '{{ test_user }}' + dest_group: '{{ test_group }}' git_repo: '{{ test_git_repo }}' git_refspec: '{{ test_git_refspec }}' git_remote: '{{ test_git_remote }}' @@ -17,6 +19,8 @@ test_deploy_dirs: # Tobiko framework directory - clean_dir: '{{ clean_deploy_dir }}' dest_dir: '{{ tobiko_dir }}' + dest_user: '{{ tobiko_user }}' + dest_group: '{{ tobiko_group }}' git_repo: '{{ tobiko_git_repo }}' git_refspec: '{{ tobiko_git_refspec }}' git_remote: '{{ tobiko_git_remote }}' diff --git a/roles/tobiko-deploy/tasks/deploy-dir.yaml b/roles/tobiko-deploy/tasks/deploy-dir.yaml index d9f5f7041..1d38b3ff2 100644 --- a/roles/tobiko-deploy/tasks/deploy-dir.yaml +++ b/roles/tobiko-deploy/tasks/deploy-dir.yaml @@ -16,13 +16,21 @@ - clean_dir | bool -- name: "create directory '{{ dest_dir }}'" +- name: "setup directory '{{ dest_dir }}'" file: path: "{{ dest_dir | realpath }}" state: directory + owner: '{{ dest_user | default(omit) }}' + group: '{{ dest_group | default(omit) }}' + mode: '0755' + recurse: yes + become: '{{ test_become | bool }}' register: create_dest_dir +- debug: var=create_dest_dir + + - name: "override git_version and src_dir because git_refspec is '{{ git_refspec }}'" set_fact: git_version: 'FETCH_HEAD' @@ -30,13 +38,13 @@ when: '(git_refspec | length) > 0' -- name: "checkout files from '{{ git_repo }}[{{ git_refspec or git_version }}]' to '{{ dest_dir }}'" +- name: "checkout files from '{{ git_repo }}[{{ git_refspec | default(git_version) }}]' to '{{ dest_dir }}'" git: dest: '{{ dest_dir }}' repo: '{{ git_repo }}' - refspec: '{{ git_refspec }}' + refspec: '{{ git_refspec | default(omit) }}' version: '{{ git_version }}' - remote: '{{ git_remote }}' + remote: '{{ git_remote | default(omit) }}' force: yes register: checkout_files when: '((src_dir | length) == 0) or (create_dest_dir is changed)' diff --git a/roles/tobiko-deploy/tasks/deploy.yaml b/roles/tobiko-deploy/tasks/deploy.yaml index 74e1c0375..4d6f518dc 100644 --- a/roles/tobiko-deploy/tasks/deploy.yaml +++ b/roles/tobiko-deploy/tasks/deploy.yaml @@ -10,9 +10,11 @@ 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 }}'