summaryrefslogtreecommitdiff
path: root/test/utils/shippable/remote-integration.sh
blob: 3f7663029a40c1dae32d1ef1c965c4a31d1c7aa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh

set -eux
env

# TODO: add support for other posix environments
container=freebsd
build_dir="${HOME}/ansible"

test_target="${TARGET:-}"
test_flags="${TEST_FLAGS:-}"

# Force ansible color output by default.
# To disable color force mode use FORCE_COLOR=0
force_color="${FORCE_COLOR:-1}"

# FIXME: these tests fail
skip_tags='test_unarchive,test_service,test_postgresql,test_mysql_db,test_mysql_user,test_mysql_variables,test_uri,test_get_url'

cd ~/

# ssl certificate errors using fetch, so install curl
pkg install -y curl

if [ ! -f bootstrap.sh ]; then
    curl "https://raw.githubusercontent.com/mattclay/ansible-hacking/master/bootstrap.sh" -o bootstrap.sh
fi

chmod +x bootstrap.sh
./bootstrap.sh pip -y -q

# tests require these packages
# TODO: bootstrap.sh should be capable of installing these
pkg install -y \
    bash \
    devel/ruby-gems \
    mercurial \
    rsync \
    ruby \
    subversion \
    sudo \
    zip

# TODO: bootstrap.sh should install these
pip install \
    junit-xml \
    virtualenv

# FIXME: tests assume bash is in /bin/bash
if [ ! -f /bin/bash ]; then
    ln -s /usr/local/bin/bash /bin/bash
fi

# FIXME: tests assume true is in /bin/true
if [ ! -f /bin/true ]; then
    ln -s /usr/bin/true /bin/true
fi

# FIXME: tests assume sha1sum is available (some platforms have shasum instead)
if [ ! -f /usr/local/bin/sha1sum ]; then
    ln -s /usr/local/bin/shasum /usr/local/bin/sha1sum
fi

# FIXME: async doesn't work with ansible_python_interpreter, see: https://github.com/ansible/ansible/issues/14101
if [ ! -f /usr/bin/python ]; then
    ln -s /usr/local/bin/python /usr/bin/python
fi

# Tests assume loopback addresses other than 127.0.0.1 will work.
# Add aliases for loopback addresses used by tests.

for i in 3 4 254; do
    ifconfig lo0 alias "127.0.0.${i}" up
done

ifconfig lo0

# Since tests run as root, we also need to be able to ssh to localhost as root.
sed -i '' 's/^# *PermitRootLogin.*$/PermitRootLogin yes/;' /etc/ssh/sshd_config

# Restart sshd for configuration changes and loopback aliases to work.
service sshd restart

# Generate our ssh key and add it to our authorized_keys file.
# We also need to add localhost's server keys to known_hosts.

if [ ! -f "${HOME}/.ssh/id_rsa.pub" ]; then
    ssh-keygen -q -t rsa -N '' -f "${HOME}/.ssh/id_rsa"
    cp "${HOME}/.ssh/id_rsa.pub" "${HOME}/.ssh/authorized_keys"
    for key in /etc/ssh/ssh_host_*_key.pub; do
        pk=$(cat "${key}")
        echo "localhost ${pk}" >> "${HOME}/.ssh/known_hosts"
    done
fi

repo_name="${REPO_NAME:-ansible}"

if [ -d "${build_dir}" ]; then
    cd "${build_dir}"
elif [ "${repo_name}" = "ansible" ]; then
    git clone "${REPOSITORY_URL:-https://github.com/ansible/ansible.git}" "${build_dir}"
    cd "${build_dir}"

    if [ "${PULL_REQUEST:-false}" = "false" ]; then
        git checkout -f "${BRANCH:-devel}" --
        git reset --hard "${COMMIT:-HEAD}"
    else
        git fetch origin "pull/${PULL_REQUEST}/head"
        git checkout -f FETCH_HEAD
        git merge "origin/${BRANCH}"
    fi

    git submodule init
    git submodule sync
    git submodule update
else
    case "${repo_name}" in
        "ansible-modules-core")
            this_module_group="core"
            ;;
        "ansible-modules-extras")
            this_module_group="extras"
            ;;
        *)
            echo "Unsupported repo name: ${repo_name}"
            exit 1
            ;;
    esac

    git clone "https://github.com/ansible/ansible.git" "${build_dir}"

    cd "${build_dir}"

    git submodule init
    git submodule sync
    git submodule update

    cd "${build_dir}/lib/ansible/modules/${this_module_group}"

    if [ "${PULL_REQUEST:-false}" = "false" ]; then
        echo "Only pull requests are supported for module repositories."
        exit
    else
        git fetch origin "pull/${PULL_REQUEST}/head"
        git checkout -f FETCH_HEAD
        git merge "origin/${BRANCH}"
    fi

    cd "${build_dir}"
fi

set +u
. hacking/env-setup
set -u

cd test/integration

# TODO: support httptester via reverse ssh tunnel

rm -rf "/tmp/shippable"
mkdir -p "/tmp/shippable/testresults"

# TODO: enable jail test
# shellcheck disable=SC2086
JUNIT_OUTPUT_DIR="/tmp/shippable/testresults" \
    ANSIBLE_FORCE_COLOR="${force_color}" \
    ANSIBLE_CALLBACK_WHITELIST=junit \
    TEST_FLAGS="-e ansible_python_interpreter=/usr/local/bin/python2 --skip-tags '${skip_tags}' ${test_flags}" \
    container="${container}" \
    gmake ${test_target}