From d9b045050c857b51ad84c287fd543ead91270b10 Mon Sep 17 00:00:00 2001
From: Hongbin Lu <hongbin034@gmail.com>
Date: Sun, 9 Jun 2019 20:14:53 +0000
Subject: [PATCH] Convert legacy job to zuul v3 native

The CI job configuration was auto-converted from legacy job in before.
This commit convert the job to zuul v3 native format.

Change-Id: I591ca197b6860db31e76fc7af3547ff4a92b2a55
---
 .zuul.yaml                                    |  8 +-
 contrib/gate_hook.sh                          | 21 -----
 contrib/post_test_hook.sh                     | 48 -----------
 .../devstack-plugin-container-dsvm/post.yaml  | 83 +------------------
 .../devstack-plugin-container-dsvm/pre.yaml   |  3 +
 .../devstack-plugin-container-dsvm/run.yaml   | 65 +--------------
 roles/fetch_docker_log/README.rst             |  1 +
 roles/fetch_docker_log/tasks/main.yaml        | 22 +++++
 8 files changed, 38 insertions(+), 213 deletions(-)
 delete mode 100644 contrib/gate_hook.sh
 delete mode 100644 contrib/post_test_hook.sh
 create mode 100644 playbooks/devstack-plugin-container-dsvm/pre.yaml
 create mode 100644 roles/fetch_docker_log/README.rst
 create mode 100644 roles/fetch_docker_log/tasks/main.yaml

diff --git a/.zuul.yaml b/.zuul.yaml
index ab84995..0158d9b 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -1,6 +1,7 @@
 - job:
     name: devstack-plugin-container-dsvm
-    parent: legacy-dsvm-base
+    parent: devstack
+    pre-run: playbooks/devstack-plugin-container-dsvm/pre.yaml
     run: playbooks/devstack-plugin-container-dsvm/run.yaml
     post-run: playbooks/devstack-plugin-container-dsvm/post.yaml
     timeout: 4200
@@ -8,6 +9,11 @@
       - openstack/devstack
       - openstack/devstack-gate
       - openstack/devstack-plugin-container
+    vars:
+      devstack_localrc:
+        USE_PYTHON3: true
+      devstack_plugins:
+        devstack-plugin-container: https://opendev.org/openstack/devstack-plugin-container
 
 - project:
     check:
diff --git a/contrib/gate_hook.sh b/contrib/gate_hook.sh
deleted file mode 100644
index b2ba473..0000000
--- a/contrib/gate_hook.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash -x
-#
-# 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.
-#
-# This script is executed inside gate_hook function in devstack gate.
-
-
-# Keep all devstack settings here instead of project-config for easy
-# maintain if we want to change devstack config settings in future.
-
-$BASE/new/devstack-gate/devstack-vm-gate.sh
diff --git a/contrib/post_test_hook.sh b/contrib/post_test_hook.sh
deleted file mode 100644
index a613752..0000000
--- a/contrib/post_test_hook.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash -x
-#
-# 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.
-
-# This script is executed inside post_test_hook function in devstack gate.
-
-# Sleep some time until all services are starting
-sleep 5
-
-# Check if a function already exists
-function function_exists {
-    declare -f -F $1 > /dev/null
-}
-
-if ! function_exists echo_summary; then
-    function echo_summary {
-        echo $@
-    }
-fi
-
-# Save trace setting
-XTRACE=$(set +o | grep xtrace)
-set -o xtrace
-
-echo_summary "Devstack-plugin-container's post_test_hook.sh was called..."
-(set -o posix; set)
-
-# Verify that Docker is installed correctly by running the hello-world image
-sudo -H -u stack docker run hello-world
-
-EXIT_CODE=$?
-
-# Copy over docker systemd unit journals.
-mkdir -p $WORKSPACE/logs
-sudo journalctl -o short-precise --unit docker | sudo tee $WORKSPACE/logs/docker.txt > /dev/null
-
-$XTRACE
-exit $EXIT_CODE
diff --git a/playbooks/devstack-plugin-container-dsvm/post.yaml b/playbooks/devstack-plugin-container-dsvm/post.yaml
index dac8753..f36f945 100644
--- a/playbooks/devstack-plugin-container-dsvm/post.yaml
+++ b/playbooks/devstack-plugin-container-dsvm/post.yaml
@@ -1,80 +1,3 @@
-- hosts: primary
-  tasks:
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=**/*nose_results.html
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=**/*testr_results.html.gz
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=/.testrepository/tmp*
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=**/*testrepository.subunit.gz
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}/tox'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=/.tox/*/log/*
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=/logs/**
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
+- hosts: all
+  roles:
+    - fetch_docker_log
diff --git a/playbooks/devstack-plugin-container-dsvm/pre.yaml b/playbooks/devstack-plugin-container-dsvm/pre.yaml
new file mode 100644
index 0000000..ede8382
--- /dev/null
+++ b/playbooks/devstack-plugin-container-dsvm/pre.yaml
@@ -0,0 +1,3 @@
+- hosts: all
+  roles:
+    - run-devstack
diff --git a/playbooks/devstack-plugin-container-dsvm/run.yaml b/playbooks/devstack-plugin-container-dsvm/run.yaml
index bfed441..f30560e 100644
--- a/playbooks/devstack-plugin-container-dsvm/run.yaml
+++ b/playbooks/devstack-plugin-container-dsvm/run.yaml
@@ -1,69 +1,8 @@
 - hosts: all
-  name: Autoconverted job legacy-devstack-plugin-container-dsvm from old job gate-devstack-plugin-container-dsvm-nv
+  name: Verify that Docker is installed correctly by running the hello-world image
   tasks:
-
-    - name: Ensure legacy workspace directory
-      file:
-        path: '{{ ansible_user_dir }}/workspace'
-        state: directory
-
     - shell:
         cmd: |
           set -e
           set -x
-          cat > clonemap.yaml << EOF
-          clonemap:
-            - name: openstack/devstack-gate
-              dest: devstack-gate
-          EOF
-          /usr/zuul-env/bin/zuul-cloner -m clonemap.yaml --cache-dir /opt/git \
-              https://opendev.org \
-              openstack/devstack-gate
-        executable: /bin/bash
-        chdir: '{{ ansible_user_dir }}/workspace'
-      environment: '{{ zuul | zuul_legacy_vars }}'
-
-    - shell:
-        cmd: |
-          set -e
-          set -x
-          cat << 'EOF' >>"/tmp/dg-local.conf"
-          [[local|localrc]]
-          enable_plugin devstack-plugin-container https://opendev.org/openstack/devstack-plugin-container
-
-          EOF
-        executable: /bin/bash
-        chdir: '{{ ansible_user_dir }}/workspace'
-      environment: '{{ zuul | zuul_legacy_vars }}'
-
-    - shell:
-        cmd: |
-          set -e
-          set -x
-          export PYTHONUNBUFFERED=true
-          export DEVSTACK_GATE_TEMPEST=0
-
-          export BRANCH_OVERRIDE=default
-          if [ "$BRANCH_OVERRIDE" != "default" ] ; then
-              export OVERRIDE_ZUUL_BRANCH=$BRANCH_OVERRIDE
-          fi
-
-          export PROJECTS="openstack/devstack-plugin-container $PROJECTS"
-          # Keep localrc to be able to set some vars in post_test_hook
-          export KEEP_LOCALRC=1
-
-          function gate_hook {
-              bash -xe $BASE/new/devstack-plugin-container/contrib/gate_hook.sh
-          }
-          export -f gate_hook
-
-          function post_test_hook {
-              bash -xe $BASE/new/devstack-plugin-container/contrib/post_test_hook.sh fullstack
-          }
-          export -f post_test_hook
-
-          cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh
-          ./safe-devstack-vm-gate-wrap.sh
-        executable: /bin/bash
-        chdir: '{{ ansible_user_dir }}/workspace'
-      environment: '{{ zuul | zuul_legacy_vars }}'
+          sudo -H -u stack docker run hello-world
diff --git a/roles/fetch_docker_log/README.rst b/roles/fetch_docker_log/README.rst
new file mode 100644
index 0000000..7909c1f
--- /dev/null
+++ b/roles/fetch_docker_log/README.rst
@@ -0,0 +1 @@
+Collect docker log from test run
diff --git a/roles/fetch_docker_log/tasks/main.yaml b/roles/fetch_docker_log/tasks/main.yaml
new file mode 100644
index 0000000..6aa8ef1
--- /dev/null
+++ b/roles/fetch_docker_log/tasks/main.yaml
@@ -0,0 +1,22 @@
+- name: Ensure log path exists
+  become: yes
+  file:
+    path: "{{ ansible_user_dir }}/logs"
+    state: directory
+    owner: "{{ ansible_user }}"
+    group: "{{ ansible_user }}"
+    mode: 0775
+
+- name: Store docker log in {{ ansible_user_dir }}/logs
+  become: yes
+  shell:
+    cmd: |
+      sudo journalctl -o short-precise --unit docker | sudo tee {{ ansible_user_dir }}/logs/docker.log > /dev/null
+
+- name: Set docker.log file permissions
+  become: yes
+  file:
+    path: '{{ ansible_user_dir }}/logs/docker.log'
+    owner: '{{ ansible_user }}'
+    group: '{{ ansible_user }}'
+    mode: 0644