-
Notifications
You must be signed in to change notification settings - Fork 21
/
docker_salt.zsh
121 lines (106 loc) · 3.18 KB
/
docker_salt.zsh
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
LOCAL_VOLUME="${HOME}/devel/salt/"
BARNACLE_DIR="${HOME}/devel/barnacle"
LOCAL_FILEROOTS="/srv/salt"
if [[ -e /usr/bin/sw_vers && `/usr/bin/sw_vers -productName` == "Mac OS X" ]]; then
SUDO=""
DOCKER="/usr/local/bin/docker"
else
SUDO="sudo"
DOCKER="/usr/bin/docker"
fi
csalt_func() {
image=$1
shift
$SUDO $DOCKER run --name salt-$image --rm -itv ${LOCAL_VOLUME}:/testing salt-$image ${@:-/bin/bash}
}
cexec_func() {
image=$1
shift
$SUDO $DOCKER exec -ti salt-$image ${@:-/bin/bash}
}
ctest_func() {
#function variables
local no_clean=''
local rm='--rm'
local usage='False'
local image=${1}
local test=${2}
# get all opts
while test $# -gt 0;do
case "$1" in
'--no-clean')
local rm=''
local no_clean='--no-clean'
;;
'--help'|'-h')
local usage='True'
;;
esac
shift
done
# cannot call a usage funciton because it wont exit and will run docker command
# so need to put in if function
if [ ${usage} = 'True' ]; then
echo "usage: cts <os> <testmodule> <options>"
echo "example: cts ubuntu14 integration.modules.test"
echo "options available:"
echo "--no-clean -> will add --no-clean to runner and ensure -rm is not added to docker run cmd"
echo "--help|-h -> will print out usage information"
else
$SUDO $DOCKER run ${rm} -itv ${LOCAL_VOLUME}:/testing salt-${image} python2 /testing/tests/runtests.py "${no_clean}" -n ${test}
fi
}
cbuild_func() {
sudo ${BARNACLE_DIR}/auto_build.sh $1 $2
}
csalt-call_cmd_func() {
local image=$1
local salt_cmd=$2
local salt_args=$3
$SUDO $DOCKER run --name salt-$image --rm -itv ${LOCAL_VOLUME}:/testing -v ${LOCAL_FILEROOTS}:/srv/salt/ salt-$image salt-call --local ${salt_cmd} ${salt_args}
}
cstart-systemd_func() {
local container=$1
local image=$2
if test -z "$container"; then
echo "Missing container name!" 1>&2
exit 1
fi
if test -z "$image"; then
echo "Missing image name!" 1>&2
exit 2
fi
$SUDO $DOCKER run -d --name $container --cap-add SYS_ADMIN -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v ${LOCAL_VOLUME}:/testing salt-$image /usr/lib/systemd/systemd
}
cssh_func() {
local container=$1
if test -z "$container"; then
echo "Missing container name!" 1>&2
exit 1
fi
local ipaddr=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $container)
# Disable strict checking because docker will reuse IP addresses
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "root@$ipaddr"
}
cdshell_func() {
local container=$1
local shell=$2
if test -z "$container"; then
echo "Missing container name!" 1>&2
exit 1
fi
if test -x "$shell"; then
echo "No shell specified, defaulting to bash" 1>&2
shell=/bin/bash
fi
docker exec -ti $container $shell
}
# ALIASES
alias cshell='csalt_func'
alias cexec='cexec_func'
alias cts='ctest_func'
alias cbuild='cbuild_func'
alias csalt-call='csalt-call_cmd_func'
alias cstart-systemd='cstart-systemd_func'
alias cssh='cssh_func'
alias cdshell='cdshell_func()'