Configure postgres to run appveyor tests on ssl

This commit is contained in:
Daniele Varrazzo 2019-04-21 13:33:15 +01:00
parent b1078b1b92
commit 9eec303cf7
2 changed files with 59 additions and 7 deletions

View File

@ -31,6 +31,10 @@ environment:
PGUSER: postgres PGUSER: postgres
PGPASSWORD: Password12! PGPASSWORD: Password12!
PGSSLMODE: require
# Select according to the service enabled
POSTGRES_DIR: C:\Program Files\PostgreSQL\9.6\
# The python used in the build process, not the one packages are built for # The python used in the build process, not the one packages are built for
PYEXE: C:\Python36\python.exe PYEXE: C:\Python36\python.exe
@ -39,8 +43,7 @@ matrix:
fast_finish: false fast_finish: false
services: services:
# Note: if you change this service also change the paths to match # Note: if you change this service also change POSTGRES_DIR
# (see where Program Files\Postgres\9.6 is used)
- postgresql96 - postgresql96
cache: cache:

View File

@ -88,7 +88,11 @@ def python_info():
def step_install(): def step_install():
python_info() python_info()
configure_sdk()
configure_postgres()
def configure_sdk():
# The program rc.exe on 64bit with some versions look in the wrong path # The program rc.exe on 64bit with some versions look in the wrong path
# location when building postgresql. This cheats by copying the x64 bit # location when building postgresql. This cheats by copying the x64 bit
# files to that location. # files to that location.
@ -100,11 +104,50 @@ def step_install():
fn, r"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin" fn, r"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin"
) )
def configure_postgres():
# Change PostgreSQL config before service starts # Change PostgreSQL config before service starts
logger.info("Configuring Postgres") logger.info("Configuring Postgres")
with (pg_dir() / 'data' / 'postgresql.conf').open('a') as f: with (pg_data_dir() / 'postgresql.conf').open('a') as f:
# allow > 1 prepared transactions for test cases # allow > 1 prepared transactions for test cases
print("max_prepared_transactions = 10", file=f) print("max_prepared_transactions = 10", file=f)
print("ssl = on", file=f)
# Create openssl certificate to allow ssl connection
cwd = os.getcwd()
os.chdir(pg_data_dir())
run_openssl(
'req -new -x509 -days 365 -nodes -text '
'-out server.crt -keyout server.key -subj /CN=initd.org'.split()
)
run_openssl(
'req -new -nodes -text -out root.csr -keyout root.key '
'-subj /CN=initd.org'.split()
)
run_openssl(
'x509 -req -in root.csr -text -days 3650 -extensions v3_ca '
'-signkey root.key -out root.crt'.split()
)
run_openssl(
'req -new -nodes -text -out server.csr -keyout server.key '
'-subj /CN=initd.org'.split()
)
run_openssl(
'x509 -req -in server.csr -text -days 365 -CA root.crt '
'-CAkey root.key -CAcreateserial -out server.crt'.split()
)
os.chdir(cwd)
def run_openssl(args):
"""Run the appveyor-installed openssl"""
# https://www.appveyor.com/docs/windows-images-software/
openssl = Path(r"C:\OpenSSL-v111-Win64") / 'bin' / 'openssl'
return run_command([openssl] + args)
def step_build_script(): def step_build_script():
@ -283,9 +326,7 @@ def build_psycopg():
def step_before_test(): def step_before_test():
# Add PostgreSQL binaries to the path # Add PostgreSQL binaries to the path
setenv( setenv('PATH', os.pathsep.join([str(pg_bin_dir()), os.environ['PATH']]))
'PATH', os.pathsep.join([str(pg_dir() / 'bin'), os.environ['PATH']])
)
# Create and setup PostgreSQL database for the tests # Create and setup PostgreSQL database for the tests
run_command(['createdb', os.environ['PSYCOPG2_TESTDB']]) run_command(['createdb', os.environ['PSYCOPG2_TESTDB']])
@ -457,7 +498,15 @@ def clone_dir():
def pg_dir(): def pg_dir():
return Path(r"C:\Program Files\PostgreSQL\9.6") return Path(os.environ['POSTGRES_DIR'])
def pg_data_dir():
return pg_dir() / 'data'
def pg_bin_dir():
return pg_dir() / 'bin'
def top_dir(): def top_dir():