forked from cloudera/impyla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-dbapi.sh
executable file
·136 lines (115 loc) · 3.99 KB
/
run-dbapi.sh
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
#! /usr/bin/env bash
# Copyright 2014 Cloudera Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -x
# Check for necessary environment variables
: ${IMPYLA_TEST_HOST:?"IMPYLA_TEST_HOST is unset"}
: ${IMPYLA_TEST_PORT:?"IMPYLA_TEST_PORT is unset"}
: ${IMPYLA_TEST_AUTH_MECH:?"IMPYLA_TEST_AUTH_MECH is unset"}
: ${PYTHON_VERSION:?"PYTHON_VERSION is unset"}
# the following are set by jenkins and are only needed if WORKSPACE not set
# GIT_URL
# GIT_BRANCH
# and for pulling in a pull request
# GITHUB_PR
# For reporting to codecov.io, set
# CODECOV_TOKEN
#
# If testing against Hive, make sure that the HDFS dir /user/<username> exists
# for whichever user is running the Hive queries. Otherwise, the MapReduce
# jobs will fail.
printenv
mkdir -p /tmp/impyla-dbapi
TMP_DIR=$(mktemp -d -p /tmp/impyla-dbapi tmpXXXX)
function cleanup_tmp_dir {
cd ~
rm -rf $TMP_DIR
}
trap cleanup_tmp_dir EXIT
cd $TMP_DIR
# checkout impyla if necessary
# this is necessary when run via SSH on a kerberized node
if [ -z "$WORKSPACE" ]; then
: ${GIT_URL:?"GIT_URL is unset"}
: ${GIT_BRANCH:?"GIT_BRANCH is unset"}
git clone $GIT_URL
pushd impyla && git checkout origin/$GIT_BRANCH && popd
IMPYLA_HOME=$TMP_DIR/impyla
else
# WORKSPACE is set, so I must be on a Jenkins slave
IMPYLA_HOME=$WORKSPACE
fi
# pull in PR if necessary
if [ -z "$WORKSPACE" -a -n "$GITHUB_PR" ]; then
pushd $IMPYLA_HOME
git clean -d -f
git fetch origin pull/$GITHUB_PR/head:pr_$GITHUB_PR
git checkout pr_$GITHUB_PR
popd
fi
# Setup Python
curl https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh > miniconda.sh
bash miniconda.sh -b -p $TMP_DIR/miniconda
export PATH="$TMP_DIR/miniconda/bin:$PATH"
conda update -y -q conda
conda info -a
# Install impyla and deps into new environment
CONDA_ENV_NAME=pyenv-impyla-dbapi-test
conda create -y -q -n $CONDA_ENV_NAME python=$PYTHON_VERSION pip
source activate $CONDA_ENV_NAME
pip install thriftpy sqlalchemy
pip install unittest2 pytest-cov
# build impyla
pip install $IMPYLA_HOME
python --version
which python
if [ $IMPYLA_TEST_AUTH_MECH != "NOSASL" ]; then
# Hive and Kerberos all need sasl installed
sudo yum install -y cyrus-sasl-devel
pip install sasl
fi
if [ $IMPYLA_TEST_AUTH_MECH = "GSSAPI" -o $IMPYLA_TEST_AUTH_MECH = "LDAP" ]; then
# CLOUDERA INTERNAL JENKINS/KERBEROS CONFIG
# impyla tests create databases, so we need to give systest the requisite
# privileges
kinit -l 4h -kt /cdep/keytabs/hive.keytab hive
sudo -u hive PYTHON_EGG_CACHE=/dev/null impala-shell -k -q "GRANT ALL ON SERVER TO ROLE cdep_default_admin WITH GRANT OPTION"
kdestroy
function cleanup_sentry_roles {
cleanup_tmp_dir # only one command per trapped signal
kinit -l 4h -kt /cdep/keytabs/hive.keytab hive
sudo -u hive PYTHON_EGG_CACHE=/dev/null impala-shell -k -q "REVOKE ALL ON SERVER FROM ROLE cdep_default_admin"
kdestroy
}
trap cleanup_sentry_roles EXIT
kinit -l 4h -kt /cdep/keytabs/systest.keytab systest
fi
python -c "from impala.tests.util import ImpylaTestEnv; print(ImpylaTestEnv())"
cd $IMPYLA_HOME
# Run PEP 249 testing suite
py.test --connect \
--cov impala \
--cov-report xml --cov-report term \
--cov-config .coveragerc \
impala
# Enforce PEP 8 etc
if [ $PYTHON_VERSION != "2.6" ]; then
pip install prospector[with_pyroma]
prospector
fi
# Report code coverage to codecov.io
if [ -n $CODECOV_TOKEN ]; then
bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
fi