tests: add support for pg_virtualenv
This commit is contained in:
parent
8e60ac10d1
commit
6dd398b693
|
@ -2,10 +2,19 @@
|
|||
|
||||
pipeline {
|
||||
agent any
|
||||
options { disableConcurrentBuilds() }
|
||||
environment {
|
||||
TMPDIR = "/tmp/$BUILD_TAG"
|
||||
}
|
||||
stages {
|
||||
stage('Unit Tests') {
|
||||
steps {
|
||||
sh 'tox -rv'
|
||||
sh """
|
||||
mkdir ${env.TMPDIR}
|
||||
virtualenv venv
|
||||
./venv/bin/pip install tox
|
||||
PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ./venv/bin/tox -rv
|
||||
"""
|
||||
}
|
||||
post {
|
||||
always {
|
||||
|
@ -35,7 +44,8 @@ pipeline {
|
|||
utils.mail_notify(currentBuild, env, 'admin+jenkins-wcs-olap@entrouvert.com')
|
||||
}
|
||||
}
|
||||
success {
|
||||
cleanup {
|
||||
sh "rm -rf ${env.TMPDIR}"
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,18 @@ class Database(object):
|
|||
def __init__(self):
|
||||
self.db_name = 'db%s' % random.getrandbits(20)
|
||||
self.dsn = 'dbname=%s' % self.db_name
|
||||
with closing(psycopg2.connect('')) as conn:
|
||||
self.connect_kwargs = {
|
||||
'dbname': 'postgres'
|
||||
}
|
||||
for variable, key in [
|
||||
('PGHOST', 'host'),
|
||||
('PGUSER', 'user'),
|
||||
('PGPASSWORD', 'password'),
|
||||
('PGPORT', 'port'),
|
||||
('PGDATABASE', 'dbname')]:
|
||||
if variable in os.environ:
|
||||
self.connect_kwargs[key] = os.environ[variable]
|
||||
with closing(psycopg2.connect(**self.connect_kwargs)) as conn:
|
||||
conn.set_isolation_level(0)
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute('CREATE DATABASE %s' % self.db_name)
|
||||
|
@ -31,7 +42,7 @@ class Database(object):
|
|||
return closing(psycopg2.connect(self.dsn))
|
||||
|
||||
def delete(self):
|
||||
with closing(psycopg2.connect('')) as conn:
|
||||
with closing(psycopg2.connect(**self.connect_kwargs)) as conn:
|
||||
conn.set_isolation_level(0)
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute('DROP DATABASE IF EXISTS %s' % self.db_name)
|
||||
|
|
Loading…
Reference in New Issue