Rename functest-prepare role to prepare-tests 39/61639/4
authorFatih Degirmenci <fdegir@gmail.com>
Fri, 31 Aug 2018 08:52:00 +0000 (10:52 +0200)
committerFatih Degirmenci <fdegir@gmail.com>
Mon, 3 Sep 2018 09:42:25 +0000 (09:42 +0000)
This change renames functest prepare-tole to prepare tests and makes other
adjustments to the role to move common test preparation steps to its own
script so we can prepare for Functest and Yardstick at one go.

Similar things are required to be prepared for running Functest and Yardstick
such as
- installed packages
- external network creation
- creation of run-functest.sh and run-yardstick scripts from templates
- preparation of environment variables

This change will fail verification until the changes below is submitted.
    https://gerrit.opnfv.org/gerrit/#/c/61645/

Change-Id: Id1020d3e61abd3f087863c06a132c5021339d655
Signed-off-by: Fatih Degirmenci <fdegir@gmail.com>
xci/playbooks/prepare-tests.yml [moved from xci/playbooks/prepare-functest.yml with 90% similarity]
xci/playbooks/roles/prepare-tests/defaults/main.yml [moved from xci/playbooks/roles/prepare-functest/defaults/main.yml with 100% similarity]
xci/playbooks/roles/prepare-tests/tasks/main.yml [moved from xci/playbooks/roles/prepare-functest/tasks/main.yml with 74% similarity]
xci/playbooks/roles/prepare-tests/templates/env.j2 [moved from xci/playbooks/roles/prepare-functest/templates/env.j2 with 100% similarity]
xci/playbooks/roles/prepare-tests/templates/prepare-tests.sh.j2 [new file with mode: 0644]
xci/playbooks/roles/prepare-tests/templates/run-functest.sh.j2 [moved from xci/playbooks/roles/prepare-functest/templates/run-functest.sh.j2 with 54% similarity]
xci/playbooks/roles/prepare-tests/vars/main.yml [moved from xci/playbooks/roles/prepare-functest/vars/main.yml with 74% similarity]

similarity index 90%
rename from xci/playbooks/prepare-functest.yml
rename to xci/playbooks/prepare-tests.yml
index a4cb664..1a1935a 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-- name: Prepare the environment for functest
+- name: Prepare the environment for testing
   hosts: opnfv
   user: root
   vars_files:
     - ../var/opnfv.yml
     - ../installer/osa/files/openstack_services.yml
   roles:
-    - role: "prepare-functest"
+    - role: "prepare-tests"
@@ -8,25 +8,25 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-- name: install functest required packages
+- name: install required packages
   package:
-    name: "{{ functest_required_packages[ansible_pkg_mgr] }}"
+    name: "{{ required_packages[ansible_pkg_mgr] }}"
     state: present
 
-# Docker is needed for functest
+# Docker is needed for test frameworks
 - name: Ensure Docker service is started and enabled
   service:
     name: docker
     state: started
     enabled: yes
 
-- name: install functest required pip packages
+- name: install required pip packages
   pip:
-   name: "{{ functest_required_pip }}"
+   name: "{{ required_pip }}"
    state: present
    extra_args: '-c https://raw.githubusercontent.com/openstack/requirements/{{ requirements_git_install_branch }}/upper-constraints.txt'
 
-- name: create public network gateway for functest
+- name: create public network gateway for testing
   block:
     - name: check if the gateway was already set
       shell: "ip a | grep {{ gateway_ip }}"
       when: gateway_ip_result|failed
   when: deploy_scenario is match("os-.*")
 
-- name: prepare environment file for functest
+- name: prepare environment file for tests
   template:
     src: env.j2
     dest: /root/env
     mode: 0755
 
-- name: prepare the script to create networks and run functest
+- name: create the script to prepare for testing
+  template:
+    src: prepare-tests.sh.j2
+    dest: /root/prepare-tests.sh
+    mode: 0755
+
+- name: create the script to run functest
   template:
     src: run-functest.sh.j2
     dest: /root/run-functest.sh
diff --git a/xci/playbooks/roles/prepare-tests/templates/prepare-tests.sh.j2 b/xci/playbooks/roles/prepare-tests/templates/prepare-tests.sh.j2
new file mode 100644 (file)
index 0000000..afc1cbb
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+# Variables that we need to pass from XCI to testing
+XCI_ENV=(INSTALLER_TYPE XCI_FLAVOR OPENSTACK_OSA_VERSION CI_LOOP BUILD_TAG NODE_NAME FUNCTEST_MODE FUNCTEST_SUITE_NAME)
+
+# Extract variables from xci.env file
+if [[ -e /root/xci.env ]]; then
+    for x in ${XCI_ENV[@]}; do
+        grep "^${x}=" /root/xci.env >> /root/env
+    done
+    # Parse the XCI's DEPLOY_SCENARIO and XCI_FLAVOR variables and
+    # set the functest container's DEPLOY_SCENARIO variable in the
+    # following format <scenario>-<flavor>. But the XCI's mini flavor
+    # is converted into noha.
+    DEPLOY_SCENARIO=`grep -Po '(?<=DEPLOY_SCENARIO=).*' /root/xci.env`
+    XCI_FLAVOR=`grep -Po '(?<=XCI_FLAVOR=).*' /root/xci.env`
+    XCI_FLAVOR=${XCI_FLAVOR/mini/noha}
+    echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO-$XCI_FLAVOR" >> /root/env
+fi
+
+# we need to ensure the necessary environment variables are sourced
+source /root/env
+
+{% if 'os-' in deploy_scenario %}
+{# stuff needed for OpenStack based scenarios #}
+source /root/openrc
+
+openstack --insecure network create --external \
+  --provider-physical-network flat \
+  --provider-network-type flat {{ external_network }}
+
+openstack --insecure subnet create --network {{ external_network }} \
+  --allocation-pool {{ allocation_pool }} \
+  --subnet-range {{ subnet_cidr }} --gateway {{ gateway_ip }} \
+  --no-dhcp {{ subnet_name }}
+{% else %}
+{# stuff needed for Kubernetes based scenarios #}
+# Create k8s.creds file for testing
+KUBE_MASTER_URL=$(grep -r server ~/.kube/config | awk '{print $2}')
+KUBE_MASTER_IP=$(echo $KUBE_MASTER_URL | awk -F "[:/]" '{print $4}')
+cat << EOF > ~/k8s.creds
+KUBERNETES_PROVIDER=local
+KUBE_MASTER_URL=$KUBE_MASTER_URL
+KUBE_MASTER_IP=$KUBE_MASTER_IP
+EOF
+{% endif %}
@@ -1,25 +1,7 @@
 #!/bin/bash
 
-# Variables that we need to pass from XCI to functest
-XCI_ENV=(INSTALLER_TYPE XCI_FLAVOR OPENSTACK_OSA_VERSION CI_LOOP BUILD_TAG NODE_NAME FUNCTEST_MODE FUNCTEST_SUITE_NAME OPNFV_FUNCTEST_HEALTHCHECK_DOCKER_IMAGE_DIGEST)
-
 # Create directory to store functest logs
-mkdir -p ~/results/
-
-# Extract variables from xci.env file
-if [[ -e /root/xci.env ]]; then
-    for x in ${XCI_ENV[@]}; do
-        grep "^${x}=" /root/xci.env >> /root/env
-    done
-    # Parse the XCI's DEPLOY_SCENARIO and XCI_FLAVOR variables and
-    # set the functest container's DEPLOY_SCENARIO variable in the
-    # following format <scenario>-<flavor>. But the XCI's mini flavor
-    # is converted into noha.
-    DEPLOY_SCENARIO=`grep -Po '(?<=DEPLOY_SCENARIO=).*' /root/xci.env`
-    XCI_FLAVOR=`grep -Po '(?<=XCI_FLAVOR=).*' /root/xci.env`
-    XCI_FLAVOR=${XCI_FLAVOR/mini/noha}
-    echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO-$XCI_FLAVOR" >> /root/env
-fi
+mkdir -p /root/functest-results/
 
 # Dump the env file
 echo "------------------------------------------------------"
@@ -32,17 +14,6 @@ source /root/env
 
 {% if 'os-' in deploy_scenario %}
 {# stuff needed for OpenStack based scenarios #}
-source /root/openrc
-
-openstack --insecure network create --external \
-  --provider-physical-network flat \
-  --provider-network-type flat {{ external_network }}
-
-openstack --insecure subnet create --network {{ external_network }} \
-  --allocation-pool {{ allocation_pool }} \
-  --subnet-range {{ subnet_cidr }} --gateway {{ gateway_ip }} \
-  --no-dhcp {{ subnet_name }}
-
 # the needed images differ between the suites so avoid downloading unnecessary images
 echo "Downloading the images needed for functest-$FUNCTEST_SUITE_NAME"
 mkdir ~/images && cd ~/images
@@ -66,26 +37,16 @@ DOCKER_IMAGE_NAME="ollivier/functest-${FUNCTEST_SUITE_NAME}"
 sudo docker run --env-file env \
     -v $(pwd)/openrc:/home/opnfv/functest/conf/env_file  \
     -v $(pwd)/images:/home/opnfv/functest/images  \
-    -v $(pwd)/results:/home/opnfv/functest/results \
+    -v $(pwd)/functest-results:/home/opnfv/functest/results \
     ${DOCKER_IMAGE_NAME}
 {% else %}
 {# stuff needed for Kubernetes based scenarios #}
-# Create k8s.creds file for functest
-KUBE_MASTER_URL=$(grep -r server ~/.kube/config | awk '{print $2}')
-KUBE_MASTER_IP=$(echo $KUBE_MASTER_URL | awk -F "[:/]" '{print $4}')
-cat << EOF > ~/k8s.creds
-KUBERNETES_PROVIDER=local
-KUBE_MASTER_URL=$KUBE_MASTER_URL
-KUBE_MASTER_IP=$KUBE_MASTER_IP
-EOF
-
 # docker image to use will be different for healthcheck and smoke test
 DOCKER_IMAGE_NAME="opnfv/functest-kubernetes-${FUNCTEST_SUITE_NAME}"
 
 sudo docker run --env-file env \
     -v $(pwd)/k8s.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/.kube/config:/root/.kube/config \
-    -v $(pwd)/results:/home/opnfv/functest/results \
+    -v $(pwd)/functest-results:/home/opnfv/functest/results \
     $DOCKER_IMAGE_NAME
 {% endif %}
-
@@ -1,5 +1,5 @@
 ---
-functest_required_packages:
+required_packages:
   apt:
     - docker.io
     - wget
@@ -13,5 +13,5 @@ functest_required_packages:
     - wget
     - xz
 
-functest_required_pip:
+required_pip:
   - docker-py