Browse code

Add support for OS X CI on Shippable. (#17160)

Matt Clay authored on 2016/08/24 02:49:46
Showing 5 changed files
... ...
@@ -8,6 +8,8 @@ matrix:
8 8
   exclude:
9 9
     - env: TEST=none
10 10
   include:
11
+    - env: TEST=remote TARGET=all PLATFORM=osx VERSION=10.11
12
+
11 13
     - env: TEST=remote TARGET=all PLATFORM=freebsd VERSION=10.3-STABLE
12 14
 
13 15
     - env: TEST=remote TARGET=ci_win1 PLATFORM=windows VERSION=2012-R2_RTM
... ...
@@ -4,5 +4,6 @@ remote
4 4
 [posix:vars]
5 5
 ansible_connection=ssh
6 6
 ansible_host=@ansible_host
7
+ansible_port=@ansible_port
7 8
 ansible_user=@ansible_user
8 9
 ansible_python_interpreter=/usr/local/bin/python2
... ...
@@ -285,6 +285,7 @@ def make_inventory(inventory_template, connection, instance_id):
285 285
     inventory = template\
286 286
         .replace('@instance_id', instance_id)\
287 287
         .replace('@ansible_host', connection['hostname'])\
288
+        .replace('@ansible_port', str(connection.get('port', 22)))\
288 289
         .replace('@ansible_user', connection['username'])\
289 290
         .replace('@ansible_password', connection.get('password', ''))
290 291
 
... ...
@@ -331,7 +332,7 @@ class HttpRequest:
331 331
         return self.request('PUT', url, data, headers)
332 332
 
333 333
     def request(self, method, url, data=None, headers=None):
334
-        args = ['/usr/bin/curl', '-s', '-i', '-X', method]
334
+        args = ['/usr/bin/curl', '-s', '-S', '-i', '-X', method]
335 335
 
336 336
         if headers is not None:
337 337
             for header in headers:
... ...
@@ -3,8 +3,7 @@
3 3
 set -eux
4 4
 env
5 5
 
6
-# TODO: add support for other posix environments
7
-container=freebsd
6
+container="${PLATFORM}"
8 7
 build_dir="${HOME}/ansible"
9 8
 
10 9
 test_target="${TARGET:-}"
... ...
@@ -19,27 +18,32 @@ skip_tags='test_unarchive,test_service,test_postgresql,test_mysql_db,test_mysql_
19 19
 
20 20
 cd ~/
21 21
 
22
-# ssl certificate errors using fetch, so install curl
23
-pkg install -y curl
22
+make="make"
24 23
 
25
-if [ ! -f bootstrap.sh ]; then
26
-    curl "https://raw.githubusercontent.com/mattclay/ansible-hacking/master/bootstrap.sh" -o bootstrap.sh
27
-fi
24
+if [ "${container}" = "freebsd" ]; then
25
+    make="gmake"
26
+
27
+    pkg install -y curl
28 28
 
29
-chmod +x bootstrap.sh
30
-./bootstrap.sh pip -y -q
31
-
32
-# tests require these packages
33
-# TODO: bootstrap.sh should be capable of installing these
34
-pkg install -y \
35
-    bash \
36
-    devel/ruby-gems \
37
-    mercurial \
38
-    rsync \
39
-    ruby \
40
-    subversion \
41
-    sudo \
42
-    zip
29
+    if [ ! -f bootstrap.sh ]; then
30
+        curl "https://raw.githubusercontent.com/mattclay/ansible-hacking/master/bootstrap.sh" -o bootstrap.sh
31
+    fi
32
+
33
+    chmod +x bootstrap.sh
34
+    ./bootstrap.sh pip -y -q
35
+
36
+    # tests require these packages
37
+    # TODO: bootstrap.sh should be capable of installing these
38
+    pkg install -y \
39
+        bash \
40
+        devel/ruby-gems \
41
+        mercurial \
42
+        rsync \
43
+        ruby \
44
+        subversion \
45
+        sudo \
46
+        zip
47
+fi
43 48
 
44 49
 # TODO: bootstrap.sh should install these
45 50
 pip install \
... ...
@@ -59,8 +63,10 @@ ifconfig lo0
59 59
 # Since tests run as root, we also need to be able to ssh to localhost as root.
60 60
 sed -i '' 's/^# *PermitRootLogin.*$/PermitRootLogin yes/;' /etc/ssh/sshd_config
61 61
 
62
-# Restart sshd for configuration changes and loopback aliases to work.
63
-service sshd restart
62
+if [ "${container}" = "freebsd" ]; then
63
+    # Restart sshd for configuration changes and loopback aliases to work.
64
+    service sshd restart
65
+fi
64 66
 
65 67
 # Generate our ssh key and add it to our authorized_keys file.
66 68
 # We also need to add localhost's server keys to known_hosts.
... ...
@@ -136,6 +142,14 @@ set -u
136 136
 
137 137
 cd test/integration
138 138
 
139
+if [ "${container}" = "osx" ]; then
140
+    # FIXME: these test targets fail
141
+    sed -i '' 's/ test_gathering_facts / /;' Makefile
142
+
143
+    # FIXME: these tests fail
144
+    skip_tags="${skip_tags},test_iterators,test_template,test_git"
145
+fi
146
+
139 147
 # TODO: support httptester via reverse ssh tunnel
140 148
 
141 149
 rm -rf "/tmp/shippable"
... ...
@@ -148,4 +162,4 @@ JUNIT_OUTPUT_DIR="/tmp/shippable/testresults" \
148 148
     ANSIBLE_CALLBACK_WHITELIST=junit \
149 149
     TEST_FLAGS="-e ansible_python_interpreter=/usr/local/bin/python2 --skip-tags '${skip_tags}' ${test_flags}" \
150 150
     container="${container}" \
151
-    gmake ${test_target}
151
+    ${make} ${test_target}
... ...
@@ -32,6 +32,22 @@ else
32 32
     test_auth="remote"
33 33
 fi
34 34
 
35
+case "${test_platform}" in
36
+    "windows")
37
+        ci_endpoint="https://14blg63h2i.execute-api.us-east-1.amazonaws.com"
38
+        ;;
39
+    "freebsd")
40
+        ci_endpoint="https://14blg63h2i.execute-api.us-east-1.amazonaws.com"
41
+        ;;
42
+    "osx")
43
+        ci_endpoint="https://osx.testing.ansible.com"
44
+        ;;
45
+    *)
46
+        echo "unsupported platform: ${test_platform}"
47
+        exit 1
48
+        ;;
49
+esac
50
+
35 51
 env
36 52
 
37 53
 case "${test_platform}" in
... ...
@@ -56,7 +72,7 @@ function cleanup
56 56
     fi
57 57
 
58 58
     if [ "${keep_instance}" = '' ]; then
59
-        "${source_root}/test/utils/shippable/ansible-core-ci" -v stop "${instance_id}"
59
+        "${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" -v stop "${instance_id}"
60 60
     fi
61 61
 
62 62
     echo "instance_id: ${instance_id}"
... ...
@@ -66,7 +82,7 @@ trap cleanup EXIT INT TERM
66 66
 
67 67
 if [ ${start_instance} ]; then
68 68
     # shellcheck disable=SC2086
69
-    "${source_root}/test/utils/shippable/ansible-core-ci" -v \
69
+    "${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" -v \
70 70
         start --id "${instance_id}" "${test_auth}" "${test_platform}" "${test_version}" ${args}
71 71
 fi
72 72
 
... ...
@@ -94,7 +110,7 @@ case "${test_platform}" in
94 94
         ;;
95 95
 esac
96 96
 
97
-"${source_root}/test/utils/shippable/ansible-core-ci" -v \
97
+"${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" -v \
98 98
     get "${instance_id}" \
99 99
     --template "${inventory_template}" \
100 100
     > "${inventory_file}" \
... ...
@@ -123,13 +139,17 @@ test_windows() {
123 123
 }
124 124
 
125 125
 test_remote() {
126
-    endpoint=$("${source_root}/test/utils/shippable/ansible-core-ci" get \
126
+    endpoint=$("${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" get \
127 127
         "${instance_id}" \
128 128
         --template <(echo "@ansible_user@@ansible_host"))
129
+    ssh_port=$("${source_root}/test/utils/shippable/ansible-core-ci" --endpoint "${ci_endpoint}" get \
130
+        "${instance_id}" \
131
+        --template <(echo "@ansible_port"))
129 132
 
130 133
 (
131 134
 cat <<EOF
132 135
 env \
136
+PLATFORM='${test_platform}' \
133 137
 REPOSITORY_URL='${REPOSITORY_URL:-}' \
134 138
 REPO_NAME='${REPO_NAME:-}' \
135 139
 PULL_REQUEST='${PULL_REQUEST:-}' \
... ...
@@ -147,16 +167,24 @@ cat <<EOF
147 147
 put "${source_root}/test/utils/shippable/remote-integration.sh" "/tmp/remote-integration.sh"
148 148
 put "/tmp/remote-script.sh" "/tmp/remote-script.sh"
149 149
 EOF
150
-) | sftp -b - -o StrictHostKeyChecking=no "${endpoint}"
150
+) | sftp -b - -o StrictHostKeyChecking=no -P "${ssh_port}" "${endpoint}"
151 151
 
152 152
     pre_cleanup=test_remote_cleanup
153 153
 
154
-    ssh "${endpoint}" \
155
-        "su -l root -c 'chmod +x /tmp/remote-script.sh; /tmp/remote-script.sh'"
154
+    case "${test_platform}" in
155
+        "osx")
156
+            become="sudo -i PATH=/usr/local/bin:\$PATH"
157
+            ;;
158
+        *)
159
+            become="su -l root -c"
160
+            ;;
161
+    esac
162
+
163
+    ssh -p "${ssh_port}" "${endpoint}" "${become}" "'chmod +x /tmp/remote-script.sh; /tmp/remote-script.sh'"
156 164
 }
157 165
 
158 166
 test_remote_cleanup() {
159
-    scp -r "${endpoint}:/tmp/shippable" "${source_root}"
167
+    scp -r -P "${ssh_port}" "${endpoint}:/tmp/shippable" "${source_root}"
160 168
 }
161 169
 
162 170
 "${test_function}"