diff --git a/Vagrantfile b/Vagrantfile index 2f965ac..ce68f20 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -32,6 +32,9 @@ PROJECTS_DIR = File.dirname(ENV.fetch('PROJECTS_DIR', VAGRANTFILE_DIR)) GIT_BASE = ENV.fetch('GIT_BASE', 'https://opendev.org') +TOX_ENVLIST = ENV.fetch('TOX_ENVLIST', '') +TOX_EXTRA_ARGS = ENV.fetch('TOX_EXTRA_ARGS', '--notest') + # Local project directories to be copied DEVSTACK_PROJECTS = { # Local directory from where look for devstack project files @@ -120,6 +123,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ansible.playbook = PROVISION_PLAYBOOK ansible.extra_vars = ansible.extra_vars = { 'devstack_projects' => DEVSTACK_PROJECTS, + 'tox_envlist' => TOX_ENVLIST, + 'tox_extra_args' => TOX_EXTRA_ARGS, } end diff --git a/playbooks/vagrant/provision.yaml b/playbooks/vagrant/provision.yaml index 90c1801..6997739 100644 --- a/playbooks/vagrant/provision.yaml +++ b/playbooks/vagrant/provision.yaml @@ -4,7 +4,6 @@ vars: resolv_conf_file: /etc/resolv.conf dest_dir: /opt/stack - tox_extra_args: --notest pre_tasks: diff --git a/roles/devstack-tobiko-deploy/defaults/main.yaml b/roles/devstack-tobiko-deploy/defaults/main.yaml new file mode 100644 index 0000000..2997e9f --- /dev/null +++ b/roles/devstack-tobiko-deploy/defaults/main.yaml @@ -0,0 +1,5 @@ +--- + +force_restack: false +stack_succeeded_file: '{{ devstack_dir }}/SUCCEEDED' +swap_file_size: 8192 diff --git a/roles/devstack-tobiko-deploy/tasks/add-swap-file.yaml b/roles/devstack-tobiko-deploy/tasks/add-swap-file.yaml new file mode 100644 index 0000000..ac7015f --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/add-swap-file.yaml @@ -0,0 +1,27 @@ +--- + +- name: "Add a swap file of {{ swap_file_size }} MBytes" + become: true + become_user: root + shell: + cmd: | + # does the swap file already exist? + if grep -q "swapfile" /etc/fstab; then + echo 'swapfile found. No changes made.' + exit 0 + fi + + echo 'swapfile not found. Adding swapfile...' + set -ex + + fallocate -l '{{ swap_file_size }}M' /swapfile + chmod 600 /swapfile + mkswap /swapfile + swapon /swapfile + echo '/swapfile none swap defaults 0 0' >> /etc/fstab + echo 'swapfile added.' + exit 0 + + register: add_swap_file + changed_when: >- + 'swapfile added' in add_swap_file.stdout diff --git a/roles/devstack-tobiko-deploy/tasks/check_restack.yaml b/roles/devstack-tobiko-deploy/tasks/check_restack.yaml new file mode 100644 index 0000000..cf43b88 --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/check_restack.yaml @@ -0,0 +1,38 @@ +--- + +- when: not (force_restack | bool) + block: + - name: check file '{{ stack_succeeded_file }}' exists + stat: + path: '{{ stack_succeeded_file }}' + register: check_devstack_succeeded_file_exists + failed_when: no + + - debug: var=check_devstack_succeeded_file_exists + + - set_fact: + force_restack: >- + {{ not check_devstack_succeeded_file_exists.stat.exists | + default(true) | + bool }} + + - debug: var=force_restack + + +- when: force_restack | bool + block: + - name: check file '{{ devstack_dir }}/local.conf' exists + stat: + path: '{{ devstack_dir }}/local.conf' + register: check_devstack_local_conf_file_exists + failed_when: no + + - debug: var=check_devstack_local_conf_file_exists + + - set_fact: + force_restack: >- + {{ check_devstack_local_conf_file_exists.stat.exists | + default(false) | + bool }} + + - debug: var=force_restack diff --git a/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml b/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml index 707259e..708343c 100644 --- a/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml +++ b/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml @@ -9,7 +9,6 @@ mode: '0755' owner: stack group: stack - recurse: yes when: >- ( project_src_dir | length) > 0 or ( project_git_repo | length) > 0 diff --git a/roles/devstack-tobiko-deploy/tasks/main.yaml b/roles/devstack-tobiko-deploy/tasks/main.yaml index 7edcebc..4a67716 100644 --- a/roles/devstack-tobiko-deploy/tasks/main.yaml +++ b/roles/devstack-tobiko-deploy/tasks/main.yaml @@ -1,5 +1,6 @@ --- +- include_tasks: add-swap-file.yaml - include_tasks: install-bindeps.yaml - include_tasks: ensure-stack-user.yaml - include_tasks: run-unstack.yaml diff --git a/roles/devstack-tobiko-deploy/tasks/run-stack.yaml b/roles/devstack-tobiko-deploy/tasks/run-stack.yaml index bedc211..184bba2 100644 --- a/roles/devstack-tobiko-deploy/tasks/run-stack.yaml +++ b/roles/devstack-tobiko-deploy/tasks/run-stack.yaml @@ -1,17 +1,24 @@ --- +- include_tasks: check_restack.yaml + - name: run stack.sh become: true become_user: stack shell: cmd: | - sudo su -l stack -c "cd '{{ devstack_dir }}' && ./stack.sh" 2>&1 + sudo su -l stack -c " + cd '{{ devstack_dir }}' && + ./stack.sh && + touch '{{ stack_succeeded_file }}' + " 2>&1 rc=$? echo "*** FINISHED ***" exit $rc chdir: '{{ devstack_dir }}' register: run_stack ignore_errors: true + when: force_restack | bool - name: show stack.sh output diff --git a/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml b/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml index 9a775a5..a2f8d38 100644 --- a/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml +++ b/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml @@ -1,25 +1,23 @@ --- -- name: check '{{ devstack_dir }}/local.conf' exists - stat: - path: '{{ devstack_dir }}/local.conf' - register: check_devstack_local_conf_file_exists - failed_when: no - +- include_tasks: check_restack.yaml - name: run unstack.sh become: yes become_user: stack shell: cmd: | - sudo su -l stack -c "cd '{{ devstack_dir }}' && ./unstack.sh" 2>&1 + sudo su -l stack -c " + rm -f '{{ stack_succeeded_file }}'; + cd '{{ devstack_dir }}' && + ./unstack.sh + " 2>&1 rc=$? echo "*** FINISHED ***" exit $rc register: run_unstack ignore_errors: yes - when: - check_devstack_local_conf_file_exists.stat.exists | default(False) + when: force_restack | bool - debug: var=run_unstack.stdout_lines diff --git a/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml b/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml index 2b02852..bf64b94 100644 --- a/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml +++ b/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml @@ -1,6 +1,13 @@ --- -- name: 'Run test cases: {{ tox_command_line }}' +- set_fact: + tox_command_line: "{{ tox_command_line | replace('\n', '') }}" + + +- debug: var=tox_command_line + + +- name: "Run test cases: {{ tox_command_line }}" become: true become_user: stack shell: