Browse Source

Add podman support to validate-tempest role

* https://review.openstack.org/#/c/600517 introduces undercloud_container_cli
  to choose docker/podman container runtime. This changes introduces to use
  both docker/podman for running tempest tests.
* Tempest user does not have permission to create tempest workspace let's
  create the tempest workspace and own it with the tempest user.
* Introducing tempest_data directory to keep tempest related data
  which can be used by tempestconf and tempest run to tests
* Cleaned up stuff which is not necessary for tempest container.

Depends-On: https://review.openstack.org/#/c/614664/

Change-Id: I1b19b2580d1d4c9844e9221f18b23655b36b5a23
Chandan Kumar 6 months ago
parent
commit
2d255d14f8

+ 1
- 0
roles/validate-tempest/README.md View File

@@ -46,6 +46,7 @@ Role Variables
46 46
 * `tempest_container_namespace`: <string> The name of tempest container image to use (default: centos-binary-tempest)
47 47
 * `tempest_container_tag`: <string> The tag of the tempest container image to use (default: current-tripleo)
48 48
 * `tempest_dir`: <string> The path to tempest workspace directory (default: /home/stack/tempest)
49
+* `tempest_data`: <string> The path to keep tempest related files used for running tempest (default: /home/stack)
49 50
 * `test_black_regex`: <list> A set of tempest tests to skip (default: [])
50 51
 * `tempest_version_dict`: <dict> A dict with release name as key and tempest tag version for that release as value
51 52
 * `tempest_version`: <string> The tempest version to use for running tempest

+ 12
- 1
roles/validate-tempest/defaults/main.yml View File

@@ -36,7 +36,18 @@ tempest_container_tag: >-
36 36
   {%- else -%}
37 37
   {{ docker_image_tag }}
38 38
   {%- endif %}
39
-tempest_dir: "{{ working_dir }}/tempest"
39
+tempest_dir: >-
40
+  {% if tempest_format in ['container'] -%}
41
+  /var/lib/tempest/tempest
42
+  {%- else -%}
43
+  {{ working_dir }}/tempest
44
+  {%- endif %}
45
+tempest_data: >-
46
+  {% if tempest_format in ['container'] -%}
47
+  /var/lib/tempest
48
+  {%- else -%}
49
+  {{ working_dir }}
50
+  {%- endif %}
40 51
 tempest_whitelist_file_src: "whitelist_file.j2"
41 52
 tempest_whitelist_file: "whitelist_file.conf"
42 53
 tempest_whitelist: []

+ 5
- 0
roles/validate-tempest/tasks/pre-tempest.yml View File

@@ -8,6 +8,11 @@
8 8
   set_fact:
9 9
       rc_file: "{{ working_dir }}/{% if tempest_undercloud %}stackrc{% else %}overcloudrc{% endif %}"
10 10
 
11
+- name: Set rc file to be sourced to run tempest with in container
12
+  set_fact:
13
+      rc_file_container: "{{ tempest_data }}/{% if tempest_undercloud %}stackrc{% else %}overcloudrc{% endif %}"
14
+  when: tempest_format == 'container'
15
+
11 16
 - name: Create overcloud tempest setup script
12 17
   template:
13 18
     src: tempest-setup.j2

+ 2
- 2
roles/validate-tempest/tasks/tempest-containers.yml View File

@@ -1,8 +1,8 @@
1 1
 ---
2 2
 - name: Set tempest init command
3 3
   set_fact:
4
-      tempest_init: "{% if release == 'newton' %}/usr/share/openstack-tempest-*/tools/configure-tempest-directory{% else %}tempest init {{ tempest_dir }}{% endif %}"
4
+      tempest_init: "tempest init {{ tempest_dir }}"
5 5
 
6 6
 - name: Set tempestconf call
7 7
   set_fact:
8
-      tempestconf: "{% if release == 'newton' %}{{ working_dir }}/tools/config_tempest.py{% else %}/usr/bin/discover-tempest-config{% endif %}"
8
+      tempestconf: "/usr/bin/discover-tempest-config"

+ 11
- 4
roles/validate-tempest/templates/configure-tempest.sh.j2 View File

@@ -10,10 +10,10 @@
10 10
 # to create tempest directory.
11 11
 # We are doing this as sudo because tempest in containers create the files as
12 12
 # root.
13
+{% if tempest_format in ["venv", "packages"] %}
13 14
 sudo rm -rf {{ working_dir }}/.tempest
14 15
 sudo rm -rf {{ tempest_dir }}
15
-# Remove tempest_data directory created before running tempest container
16
-sudo rm -rf {{ working_dir }}/tempest_data
16
+{% endif %}
17 17
 
18 18
 
19 19
 # Cloud Credentials
@@ -75,12 +75,17 @@ set -e
75 75
 
76 76
 rpm -qa | grep tempest
77 77
 
78
+# Remove the existing tempest workspace
79
+if [ -d {{ tempest_dir }}/etc ]; then
80
+tempest workspace remove --name {{ tempest_dir | basename }} --rmdir
81
+fi
78 82
 {% endif %}
79 83
 
80 84
 ## Create Tempest Workspace
81 85
 ## ------------------------
82 86
 ## ::
83 87
 
88
+
84 89
 # Create Tempest directory
85 90
 
86 91
 mkdir {{ tempest_dir }}
@@ -95,7 +100,9 @@ popd
95 100
 ## ::
96 101
 export TEMPESTCONF="{{ tempestconf }}"
97 102
 
98
-{% if tempest_os_cloud == '' %}
103
+{% if tempest_format == 'container' %}
104
+source {{ rc_file_container }}
105
+{% elif tempest_os_cloud == '' %}
99 106
 source {{ rc_file }}
100 107
 {% endif %}
101 108
 
@@ -128,7 +135,7 @@ export OS_AUTH_URL="$OS_AUTH_URL/v2.0"
128 135
 cd {{ tempest_dir }}
129 136
 $TEMPESTCONF --out etc/tempest.conf \
130 137
   {% if tempest_overcloud|bool %}
131
-  --deployer-input {{ working_dir }}/{{ tempest_deployer_input_file }} \
138
+  --deployer-input {{ tempest_dir }}/{{ tempest_deployer_input_file }} \
132 139
   --network-id $public_net_id \
133 140
   {% endif %}
134 141
   {% if tempest_os_cloud != '' %}

+ 25
- 32
roles/validate-tempest/templates/run-tempest.sh.j2 View File

@@ -10,6 +10,7 @@ export OSTESTR='{{ working_dir }}/tempest_git/tools/with_venv.sh ostestr'
10 10
 export OSTESTR='ostestr'
11 11
 export TEMPESTCLI='/usr/bin/tempest'
12 12
 {% endif %}
13
+export TEMPESTDATA={{ tempest_data }}
13 14
 
14 15
 ## List tempest plugins
15 16
 
@@ -26,9 +27,9 @@ $TEMPESTCLI cleanup --init-saved-state
26 27
 {% endif %}
27 28
 
28 29
 {% if release in ["newton", "ocata", "pike"] %} $OSTESTR {% else %} $TEMPESTCLI run {% endif %}{% if test_white_regex != '' %} --regex '({{ test_white_regex }})' {% endif %}
29
-{% if tempest_whitelist|length > 0 %} --whitelist_file={{ working_dir }}/{{ tempest_whitelist_file }} {% endif %}
30
-{% if release not in ["newton", "ocata", "pike"] %} {% if test_black_regex|length > 0 %} --black-regex='{{ test_black_regex|join('|') }}' {% endif %} {% endif %}
31
-{% if skip_file_src != '' %} --blacklist_file={{ working_dir }}/{{ skip_file }} {% endif %}
30
+{% if tempest_whitelist|length > 0 %} --whitelist_file=$TEMPESTDATA/{{ tempest_whitelist_file }} {% endif %}
31
+{% if release not in ["newton", "ocata", "pike"] %} {% if test_black_regex|length > 0 %} --black-regex='{{ test_black_regex|join('|') }}'{% endif %} {% endif %}
32
+{% if skip_file_src != '' %} --blacklist_file=$TEMPESTDATA/{{ skip_file }} {% endif %}
32 33
 {% if tempest_workers is defined %} --concurrency {{ tempest_workers }} {% endif %}
33 34
 {% if tempest_until_failure|bool %} --until-failure {% endif %}
34 35
 
@@ -44,9 +45,14 @@ $TEMPESTCLI cleanup --dry-run
44 45
 EOF
45 46
 chmod +x {{ working_dir }}/tempest_container.sh
46 47
 # Copy all the required files in a temprory directory
47
-mkdir {{ working_dir }}/tempest_data
48
+export TEMPEST_HOST_DATA='/var/lib/tempestdata'
48 49
 
49
-cp $RCFILE \
50
+if [ ! -d $TEMPEST_HOST_DATA ]
51
+then
52
+    mkdir -p $TEMPEST_HOST_DATA
53
+fi
54
+
55
+sudo cp $RCFILE \
50 56
     {% if skip_file_src != '' %}
51 57
     {{ working_dir }}/{{ skip_file }} \
52 58
     {% endif %}
@@ -57,46 +63,33 @@ cp $RCFILE \
57 63
     {{ working_dir }}/{{ tempest_deployer_input_file }} \
58 64
     {% endif %}
59 65
     {{ working_dir }}/tempest_container.sh \
60
-    {{ working_dir }}/tempest_data
61
-
62
-# TODO(chkumar246): https://review.openstack.org/#/c/583940/ added tempest user to
63
-# tempest container, The file getting mounted from host to tempest container have
64
-# different permission as tempest user does not own those folders which will give
65
-# permission denied So first check whether tempest user is there or not if present
66
-# run the docker command to change the dir permission and if not found the usual
67
-# command, Once new container image is available after promotion, we will the add
68
-# the volume in THT itself and fix other stuffs. Also pull docker image locally
69
-# as docker inspect needs the image to exist.
70
-sudo docker pull {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }}
71
-if [ x$(sudo docker inspect --format "{{ '{{' }} .Config.User {{ '}}' }}" {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }}) == 'xtempest' ]; then
72
-    sudo docker run --net=host -u root -v {{ working_dir }}/tempest_data:{{ working_dir }} \
73
-    {% if not 'http' in tempest_test_image_path %}
74
-        -v {{ tempest_test_image_path }}:{{ tempest_test_image_path }} \
75
-    {% endif %}
76
-        {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }} \
77
-        chown -R tempest:tempest \
78
-        {% if not 'http' in tempest_test_image_path %}
79
-        {{ tempest_test_image_path }} \
80
-        {% endif %}
81
-        {{ working_dir }}
82
-fi
66
+    $TEMPEST_HOST_DATA
67
+
68
+{% if undercloud_container_cli is defined %}
69
+export CONTAINER_BINARY={{ undercloud_container_cli }}
70
+{% else %}
71
+export CONTAINER_BINARY='docker'
72
+{% endif %}
73
+
74
+sudo $CONTAINER_BINARY pull {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }}
83 75
 
84 76
 # Run tempest container using docker mouting required files
85
-sudo docker run --net=host -i -v {{ working_dir }}/tempest_data/:{{ working_dir }} \
77
+sudo $CONTAINER_BINARY run --net=host -i -v $TEMPEST_HOST_DATA:{{ tempest_data }} \
86 78
     -e PYTHONWARNINGS="${PYTHONWARNINGS:-}" \
87 79
     -e CURL_CA_BUNDLE="" \
80
+    --user=root \
88 81
     -v /var/log/containers/tempest:{{ tempest_log_dir }} \
89 82
     {% if not 'http' in tempest_test_image_path %}
90 83
     -v {{ tempest_test_image_path }}:{{ tempest_test_image_path }} \
91 84
     {% endif %}
92 85
     {{ tempest_container_registry }}/{{ tempest_container_namespace }}:{{ tempest_container_tag }} \
93
-    /usr/bin/bash -c 'set -e; {{ working_dir }}/tempest_container.sh'
86
+    /usr/bin/bash -c 'set -e; {{ tempest_data }}/tempest_container.sh'
94 87
 
95 88
 # Change permission of tempest workspace directory
96
-sudo chmod -R 777 {{ working_dir }}/tempest_data
89
+sudo chmod -R 777 $TEMPEST_HOST_DATA
97 90
 
98 91
 # Copy tempest related data to tempest folder so that stackviz can use it
99
-cp -R {{ working_dir }}/tempest_data/tempest {{ working_dir }}
92
+cp -R $TEMPEST_HOST_DATA/tempest {{ working_dir }}
100 93
 
101 94
 {% endif %}
102 95
 ### --stop_docs

Loading…
Cancel
Save