-
Notifications
You must be signed in to change notification settings - Fork 1
/
vertica_testenv
executable file
·158 lines (139 loc) · 4.61 KB
/
vertica_testenv
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
#!/bin/bash
create_kdc(){
echo "Setting up KDC"
docker network create $NETWORK_NAME
docker build -t vertica/kdc $SRC/docker/kdc
docker run -d --privileged --name=$KDC_NAME --network=$NETWORK_NAME vertica/kdc
docker exec $KDC_NAME /kdc/install_kdc.sh
}
create_db(){
echo "Creating database"
if [ ! -f "$SRC/docker-vertica/packages/vertica-ce.latest.rpm" ]; then
export VERTICA_CE_URL="https://s3.amazonaws.com/vertica-community-edition-for-testing/XCz9cp7m/vertica-9.1.1-0.x86_64.RHEL6.rpm"
git clone https://github.com/jbfavre/docker-vertica.git
curl $VERTICA_CE_URL --create-dirs -o $SRC/docker-vertica/packages/vertica-ce.latest.rpm
fi
docker build -f $SRC/docker-vertica/Dockerfile.centos.7_9.x --build-arg VERTICA_PACKAGE=vertica-ce.latest.rpm -t jbfavre/vertica $SRC/docker-vertica
docker run -d -p 5433:5433 --name=$DB_NAME --network=$NETWORK_NAME jbfavre/vertica
echo "Making service keytab"
export V_PRINC=vertica/[email protected]
docker exec $KDC_NAME kadmin.local -q "addprinc -randkey $V_PRINC"
docker exec $KDC_NAME kadmin.local -q "ktadd -norandkey -k vertica.keytab $V_PRINC"
docker cp $KDC_NAME:vertica.keytab $SRC
docker cp $SRC/vertica.keytab $DB_NAME:/
rm $SRC/vertica.keytab
echo "Waiting for db to start"
sleep 60
echo "Kerberize db"
docker cp $SRC/docker/kerberize_db.sh $DB_NAME:/
docker exec $DB_NAME yum install -y krb5-workstation
docker exec $DB_NAME /bin/sh -c "echo $(docker inspect -f "{{.NetworkSettings.Networks.$NETWORK_NAME.IPAddress }}" $KDC_NAME) kerberos.example.com >> /etc/hosts"
docker exec $DB_NAME /kerberize_db.sh
}
create_sandbox(){
docker build -t vertica/sandbox $SRC/docker/sandbox
docker run --network=$NETWORK_NAME -t -d --name=$SANDBOX_NAME vertica/sandbox
docker exec $SANDBOX_NAME /bin/sh -c "echo $(docker inspect -f "{{.NetworkSettings.Networks.$NETWORK_NAME.IPAddress }}" $KDC_NAME) kerberos.example.com >> /etc/hosts"
docker exec $SANDBOX_NAME /bin/sh -c "echo $(docker inspect -f "{{.NetworkSettings.Networks.$NETWORK_NAME.IPAddress }}" $DB_NAME) vertica.example.com vertica >> /etc/hosts"
docker exec -it $SANDBOX_NAME /bin/bash
}
create_test(){
# Process python version
if [[ $PYENV =~ ^py[0-9][0-9]$ ]]; then
VER=${PYENV:2:1}.${PYENV:3}
cp $SRC/docker/test/Dockerfile $SRC/docker/test/Dockerfile.backup
sed -i "s/<ver>/$VER/g" $SRC/docker/test/Dockerfile
KDC_ADDR=$(docker inspect -f "{{.NetworkSettings.Networks.$NETWORK_NAME.IPAddress }}" $KDC_NAME)
DB_ADDR=$(docker inspect -f "{{.NetworkSettings.Networks.$NETWORK_NAME.IPAddress }}" $DB_NAME)
# Set up testing
docker build -f $SRC/docker/test/Dockerfile -t vertica/test --build-arg KDC_ADDR=$KDC_ADDR --build-arg DB_ADDR=$DB_ADDR $SRC/..
docker run --network=$NETWORK_NAME --rm --name=$TESTER_NAME vertica/test "-e $PYENV"
RESULT=$?
# cleanup
mv docker/test/Dockerfile.backup docker/test/Dockerfile
docker image rm vertica/test
exit $RESULT
else echo "Invalid python environment."
fi
}
stop_containers(){
echo "Stopping containers"
docker container stop $KDC_NAME
docker container stop $DB_NAME
docker container stop $SANDBOX_NAME > /dev/null 2>&1
}
clean_system(){
echo "Cleaning up"
docker container rm $KDC_NAME
docker container rm $DB_NAME
docker container rm $SANDBOX_NAME > /dev/null 2>&1
docker image rm jbfavre/vertica
docker image rm vertica/kdc
docker image rm vertica/sandbox > /dev/null 2>&1
docker network remove $NETWORK_NAME
}
echo_use(){
echo "Usage: $0 command [args]"
}
echo_help(){
echo -e '''
vertica_testenv sets up a kerberos-enabled vertica database to facilitate testing.
Usage: vertica_testenv command [args]
Commands: [start|test|stop|clean]
Start \t Build vertica and kerberos.
Test \t Build and run the vertica-python test suite.
Stop \t Stop the containers.
Clean \t Remove the containers and the images.
Options: --kdc, --db, --py
--kdc \t Name of the kdc container (default: vp.kdc)
--db \t Name of the database container (default: vp.db)
--py \t Python version. Options: py37 (default),py27,py34,py35,py36.
'''
}
if [ $# -eq 0 ]; then
echo_use
exit 0
fi
KDC_NAME=$USER.kdc
DB_NAME=$USER.db
TESTER_NAME=$USER.test
NETWORK_NAME=${USER}test
SANDBOX_NAME=${USER}.sandbox
PYENV=py37
SRC=$(dirname "$BASH_SOURCE")
op=$1
shift
while [ -n "$1" ]; do
case "$1" in
--help) echo_help
exit 0
;;
--kdc) KDC_NAME=$2
shift
;;
--db) DB_NAME=$2
shift
;;
--py) PYENV=$2
shift
;;
--) shift
break ;;
*) break ;;
esac
shift
done
if [ $op = 'start' ]; then
create_kdc
create_db
elif [ $op = 'sandbox' ]; then
create_sandbox
elif [ $op = 'test' ]; then
create_test
elif [ $op = 'stop' ]; then
stop_containers
elif [ $op = 'clean' ]; then
clean_system
else
echo_use
fi