Browse code

Add full support for Shippable CI.

(cherry picked from commit b0e1efbd62b683cd4ab9620372660ab11f139ce6)

Matt Clay authored on 2016/06/02 13:08:14
Showing 5 changed files
... ...
@@ -61,3 +61,4 @@ venv
61 61
 Vagrantfile
62 62
 .vagrant
63 63
 ansible.egg-info/
64
+/shippable/
... ...
@@ -1,23 +1,33 @@
1 1
 language: python
2 2
 
3
-env: TOXENV=py24
3
+env:
4
+  matrix:
5
+    - TEST=code-smell
4 6
 
5 7
 matrix:
6 8
   include:
7
-    - python: 2.6
8
-      env: TOXENV=py26
9
-    - python: 2.7
10
-      env: TOXENV=py27
11
-    - python: 3.4
12
-      env: TOXENV=py34
13
-    - python: 3.5
14
-      env: TOXENV=py35
9
+    - env: TEST=sanity INSTALL_DEPS=1 TOXENV=py24
10
+      python: 2.7
11
+    - env: TEST=sanity INSTALL_DEPS=1 TOXENV=py26
12
+      python: 2.6
13
+    - env: TEST=sanity INSTALL_DEPS=1 TOXENV=py27
14
+      python: 2.7
15
+    - env: TEST=sanity INSTALL_DEPS=1 TOXENV=py34
16
+      python: 3.4
17
+    - env: TEST=sanity INSTALL_DEPS=1 TOXENV=py35
18
+      python: 3.5
19
+    - env: TEST=integration IMAGE=ansible/ansible:centos6
20
+    - env: TEST=integration IMAGE=ansible/ansible:centos7
21
+    - env: TEST=integration IMAGE=ansible/ansible:fedora-rawhide
22
+    - env: TEST=integration IMAGE=ansible/ansible:fedora23
23
+    - env: TEST=integration IMAGE=ansible/ansible:opensuseleap
24
+    - env: TEST=integration IMAGE=ansible/ansible:ubuntu1204 PRIVILEGED=true
25
+    - env: TEST=integration IMAGE=ansible/ansible:ubuntu1404 PRIVILEGED=true
26
+    - env: TEST=integration IMAGE=ansible/ansible:ubuntu1604
15 27
 
16 28
 build:
17 29
   ci:
18
-    - if [ "${TOXENV}" = "py24" ]; then add-apt-repository ppa:fkrull/deadsnakes && apt-get update -qq && apt-get install python2.4 -qq; fi
19
-    - pip install tox
20
-    - TARGET=sanity ./test/utils/run_tests.sh
30
+    - test/utils/shippable/${TEST}.sh 2>&1 | gawk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'
21 31
 
22 32
 integrations:
23 33
   notifications:
24 34
new file mode 100755
... ...
@@ -0,0 +1,10 @@
0
+#!/bin/bash -eux
1
+
2
+source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
3
+
4
+cd "${source_root}"
5
+
6
+test/code-smell/replace-urlopen.sh .
7
+test/code-smell/use-compat-six.sh lib
8
+test/code-smell/boilerplate.sh
9
+test/code-smell/required-and-default-attributes.sh
0 10
new file mode 100755
... ...
@@ -0,0 +1,91 @@
0
+#!/bin/bash -eux
1
+
2
+source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
3
+
4
+test_image="${IMAGE}"
5
+test_privileged="${PRIVILEGED:-false}"
6
+test_flags="${TEST_FLAGS:-}"
7
+test_target="${TARGET:-}"
8
+test_ansible_dir="${TEST_ANSIBLE_DIR:-/root/ansible}"
9
+
10
+http_image="${HTTP_IMAGE:-ansible/ansible:httptester}"
11
+
12
+keep_containers="${KEEP_CONTAINERS:-}"
13
+copy_source="${COPY_SOURCE:-}"
14
+
15
+if [ "${SHIPPABLE_BUILD_DIR:-}" ]; then
16
+    host_shared_dir="/home/shippable/cache/build-${BUILD_NUMBER}"
17
+    controller_shared_dir="/home/shippable/cache/build-${BUILD_NUMBER}"
18
+else
19
+    host_shared_dir="${source_root}"
20
+    controller_shared_dir=""
21
+fi
22
+
23
+if [ "${copy_source}" ]; then
24
+    test_shared_dir="/tmp/shared-dir"
25
+else
26
+    test_shared_dir="${test_ansible_dir}"
27
+fi
28
+
29
+container_id=
30
+httptester_id=
31
+
32
+function show_environment
33
+{
34
+    docker ps
35
+
36
+    if [ -d /home/shippable/cache ]; then
37
+        ls -l /home/shippable/cache
38
+    fi
39
+}
40
+
41
+function cleanup
42
+{
43
+    if [ "${controller_shared_dir}" ]; then
44
+        cp -av "${controller_shared_dir}/shippable" "${SHIPPABLE_BUILD_DIR}"
45
+        rm -rf "${controller_shared_dir}"
46
+    fi
47
+
48
+    if [ "${keep_containers}" == "" ]; then
49
+        if [ "${container_id}" ]; then
50
+            docker rm -f "${container_id}"
51
+        fi
52
+
53
+        if [ "${httptester_id}" ]; then
54
+            docker rm -f "${httptester_id}"
55
+        fi
56
+    fi
57
+
58
+    show_environment
59
+}
60
+
61
+trap cleanup EXIT INT TERM
62
+show_environment
63
+
64
+if [ "${controller_shared_dir}" ]; then
65
+    cp -a "${SHIPPABLE_BUILD_DIR}" "${controller_shared_dir}"
66
+fi
67
+
68
+httptester_id=$(docker run -d "${http_image}")
69
+container_id=$(docker run -d \
70
+    -v "/sys/fs/cgroup:/sys/fs/cgroup:ro" \
71
+    -v "${host_shared_dir}:${test_shared_dir}" \
72
+    --link="${httptester_id}:ansible.http.tests" \
73
+    --link="${httptester_id}:sni1.ansible.http.tests" \
74
+    --link="${httptester_id}:sni2.ansible.http.tests" \
75
+    --link="${httptester_id}:fail.ansible.http.tests" \
76
+    --privileged="${test_privileged}" \
77
+    "${test_image}")
78
+
79
+show_environment
80
+
81
+docker exec "${container_id}" pip install junit-xml
82
+
83
+if [ "${copy_source}" ]; then
84
+    docker exec "${container_id}" cp -a "${test_shared_dir}" "${test_ansible_dir}"
85
+fi
86
+
87
+docker exec "${container_id}" mkdir -p "${test_shared_dir}/shippable/testresults"
88
+docker exec "${container_id}" /bin/sh -c "cd '${test_ansible_dir}' && . hacking/env-setup && cd test/integration && \
89
+    JUNIT_OUTPUT_DIR='${test_shared_dir}/shippable/testresults' ANSIBLE_CALLBACK_WHITELIST=junit \
90
+    HTTPTESTER=1 TEST_FLAGS='${test_flags}' LC_ALL=en_US.utf-8 make ${test_target}"
0 91
new file mode 100755
... ...
@@ -0,0 +1,31 @@
0
+#!/bin/bash -eux
1
+
2
+source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
3
+
4
+install_deps="${INSTALL_DEPS:-}"
5
+
6
+cd "${source_root}"
7
+
8
+if [ "${TOXENV}" = 'py24' ]; then
9
+    if [ "${install_deps}" != "" ]; then
10
+        add-apt-repository ppa:fkrull/deadsnakes && apt-get update -qq && apt-get install python2.4 -qq
11
+    fi
12
+
13
+    python2.4 -V
14
+    python2.4 -m compileall -fq -x 'module_utils/(a10|rax|openstack|ec2|gce|docker_common|azure_rm_common|vca|vmware).py' lib/ansible/module_utils
15
+else
16
+    if [ "${install_deps}" != "" ]; then
17
+        pip install tox
18
+    fi
19
+
20
+    xunit_dir="${source_root}/shippable/testresults"
21
+    coverage_dir="${source_root}/shippable/codecoverage"
22
+
23
+    mkdir -p "${xunit_dir}"
24
+    mkdir -p "${coverage_dir}"
25
+
26
+    xunit_file="${xunit_dir}/nosetests-xunit.xml"
27
+    coverage_file="${coverage_dir}/nosetests-coverage.xml"
28
+
29
+    TOX_TESTENV_PASSENV=NOSETESTS NOSETESTS="nosetests --with-xunit --xunit-file='${xunit_file}' --cover-xml --cover-xml-file='${coverage_file}'" tox
30
+fi