Skip to content

Commit b8dba4b

Browse files
committed
circle: Use the latest NuoDB release Docker image
Change the hardcoded 5.1.2 release to use "latest". Add support for the common-config context, which is needed to obtain the license info needed for newer instances of NuoDB. Modify the test configuration to install a license if (a) there is not already one available in the domain, and (b) we have one provided in the environment (from the common-config context).
1 parent 9e29969 commit b8dba4b

File tree

4 files changed

+80
-41
lines changed

4 files changed

+80
-41
lines changed

.circleci/config.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ version: 2.1
22

33
commands:
44
after_failure:
5+
description: "Steps to be run after build or test failure"
56
parameters:
67
when:
78
type: string
89
steps:
910
- run:
1011
name: On failure action
1112
command: |
12-
env | sort
13-
echo ------
14-
cat $HOME/.bashrc $HOME/.profile $HOME/.bash_profile || true
15-
echo ------
16-
cat $HOME/.nuocmdrc || true
17-
echo ------
18-
cat /var/log/nuodb/nuoadmin.log* || true
19-
echo ------
20-
cat /tmp/nuotest.log || true
21-
echo ------
22-
grep ssl /etc/nuodb/nuoadmin.conf || true
13+
env | sort > artifacts/env.out
14+
cp -a $HOME/.bashrc artifacts || true
15+
cp -a $HOME/.profile artifacts || true
16+
cp -a $HOME/.bash_profile artifacts ||
17+
cp -a $HOME/.nuocmdrc artifacts || true
18+
cp -a /etc/nuodb/nuoadmin.conf artifacts || true
19+
cp -a /var/log/nuodb/nuoadmin.log* artifacts || true
2320
when: <<parameters.when>>
2421

2522
- when:
@@ -30,8 +27,9 @@ commands:
3027

3128
jobs:
3229
build_n_run:
30+
description: "Build the nuodb-python module and run the test suite"
3331
docker:
34-
- image: nuodb/nuodb:5.1.2
32+
- image: nuodb/nuodb:latest
3533
user: root
3634
resource_class: small
3735
environment:
@@ -43,31 +41,35 @@ jobs:
4341
steps:
4442
- checkout
4543
- run:
46-
command: dnf install make -y
44+
name: Make test directories
45+
command: mkdir -p artifacts results
46+
- run:
4747
name: Install make
48+
command: dnf install make -y
4849
- run:
49-
name : Install python dependencies
50+
name: Install Python dependencies
5051
command: make install
5152
- run:
52-
name : Create test result folder
53-
command: mkdir test_results
54-
- run:
55-
name : Configure and run NuoDB Admin
53+
name: Start NuoDB Admin
5654
command: |
57-
sudo -u nuodb "/opt/nuodb/etc/nuoadmin" tls $NUO_SET_TLS
58-
sudo -u nuodb "/opt/nuodb/etc/nuoadmin" tls status
59-
sudo -u nuodb "/opt/nuodb/etc/nuoadmin" start
55+
sudo -u nuodb /opt/nuodb/etc/nuoadmin tls $NUO_SET_TLS
56+
sudo -u nuodb /opt/nuodb/etc/nuoadmin tls status
57+
sudo -u nuodb /opt/nuodb/etc/nuoadmin start
58+
sudo -u nuodb /opt/nuodb/bin/nuocmd --show-json get effective-license
6059
- run:
6160
name: Run test
62-
command: make fulltest "PYTEST_ARGS=--log-file-level=10 --log-file=/tmp/nuotest.log"
61+
command: make fulltest
6362
- store_artifacts:
64-
path: htmlcov
63+
path: artifacts
6564
- store_test_results:
66-
path: test_results
65+
path: results
6766
- after_failure:
6867
when : "on_fail"
6968

7069
workflows:
7170
build-project:
7271
jobs:
73-
- build_n_run
72+
- build_n_run:
73+
name: "Build and run regression tests"
74+
context:
75+
- common-config

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ pip-log.txt
3535
.tox
3636
.testtemp
3737
nosetests.xml
38-
htmlcov/
39-
test_results/
38+
.mypy_cache/
39+
artifacts/
40+
results/
4041

4142
# Translations
4243
*.mo

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
from setuptools import setup
2626

2727
with open(os.path.join(os.path.dirname(__file__), 'pynuodb', '__init__.py')) as v:
28-
VERSION = re.compile(r"^ *__version__ *= *'(.*?)'", re.M).search(v.read()).group(1)
28+
m = re.search(r"^ *__version__ *= *'(.*?)'", v.read(), re.M)
29+
if m is None:
30+
raise RuntimeError("Cannot detect version in pynuodb/__init__.py")
31+
VERSION = m.group(1)
2932

3033
readme = os.path.join(os.path.dirname(__file__), 'README.rst')
3134

tests/conftest.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import time
1414
import socket
1515
import logging
16+
import base64
17+
import shutil
1618

1719
try:
1820
from typing import Any, Generator, List # pylint: disable=unused-import
@@ -36,6 +38,8 @@
3638
DBA_USER = 'dba'
3739
DBA_PASSWORD = 'dba_password'
3840

41+
_CHARS = string.ascii_lowercase + string.digits
42+
3943
# Unfortunately purging the DB also purges the archive so we have to remember
4044
# this externally from the archive fixture.
4145
__archive_created = False
@@ -89,24 +93,50 @@ def ap():
8993
cfg = cvtjson(out)[0]
9094
localaddr = '%s:%s' % (cfg['properties']['altAddr'], cfg['properties']['agentPort'])
9195

92-
_log.info("Checking licensing")
93-
(ret, out) = nuocmd(['--show-json', 'get', 'effective-license'])
94-
if ret != 0:
95-
__fatal("Cannot retrieve NuoDB domain license: %s" % (out))
96-
lic = cvtjson(out)[0]
9796
# We'll assume that any license at all is enough to run the minimum
9897
# database needed by the tests.
99-
if not lic or 'decodedLicense' not in lic or 'type' not in lic['decodedLicense']:
100-
__fatal("Invalid license: %s" % (out))
101-
if lic['decodedLicense']['type'] == 'UNLICENSED':
102-
__fatal("NuoDB domain is UNLICENSED")
98+
def check_license():
99+
# type: () -> Optional[str]
100+
(ret, out) = nuocmd(['--show-json', 'get', 'effective-license'])
101+
if ret != 0:
102+
return "Cannot retrieve NuoDB domain license: %s" % (out)
103+
lic = cvtjson(out)[0]
104+
if not lic or 'decodedLicense' not in lic or 'type' not in lic['decodedLicense']:
105+
return "Invalid license: %s" % (out)
106+
if lic['decodedLicense']['type'] == 'UNLICENSED':
107+
return "NuoDB domain is UNLICENSED"
108+
109+
return None
110+
111+
_log.info("Checking licensing")
112+
err = check_license()
113+
114+
# If we need a license and one exists in the environment, install it
115+
if err and os.environ.get('NUODB_LIMITED_LICENSE_CONTENT'):
116+
licfile = 'nuodb%s.lic' % (''.join(random.choice(_CHARS) for x in range(10)))
117+
licpath = os.path.join(tempfile.gettempdir(), licfile)
118+
_log.info("Adding a license provided by the environment")
119+
with open(licpath, 'wb') as f:
120+
f.write(base64.b64decode(os.environ['NUODB_LIMITED_LICENSE_CONTENT']))
121+
(ret, out) = nuocmd(['set', 'license', '--license-file', licpath])
122+
try:
123+
os.remove(licpath)
124+
except Exception:
125+
pass
126+
if ret != 0:
127+
__fatal("Failed to set a license: %s" % (out))
128+
129+
err = check_license()
130+
131+
if err:
132+
__fatal(err)
103133

104134
yield localap, localaddr
105135

106136

107137
@pytest.fixture(scope="session")
108-
def archive(ap):
109-
# type: (AP_FIXTURE) -> Generator[ARCHIVE_FIXTURE, None, None]
138+
def archive(request, ap):
139+
# type: (pytest.FixtureRequest, AP_FIXTURE) -> Generator[ARCHIVE_FIXTURE, None, None]
110140
"""Find or create an archive.
111141
112142
:return path, id
@@ -126,8 +156,7 @@ def archive(ap):
126156
_log.info("Using existing archive %s: %s" % (ar_id, ar_path))
127157

128158
if not ar_id:
129-
ardir = DATABASE_NAME + '-' + ''.join(random.choice(string.ascii_uppercase + string.digits)
130-
for x in range(20))
159+
ardir = DATABASE_NAME + '-' + ''.join(random.choice(_CHARS) for x in range(20))
131160
ar_path = os.path.join(tempfile.gettempdir(), ardir)
132161
_log.info("Creating archive %s" % (ar_path))
133162
(ret, out) = nuocmd(['--show-json', 'create', 'archive',
@@ -146,6 +175,10 @@ def archive(ap):
146175
(ret, out) = nuocmd(['delete', 'archive', '--archive-id', str(ar_id)])
147176
assert ret == 0, "Failed to delete archive %s: %s" % (ar_id, out)
148177

178+
# If nothing failed then delete the archive, else leave it for forensics
179+
if request.session.testsfailed == 0:
180+
shutil.rmtree(ar_path, ignore_errors=True)
181+
149182

150183
@pytest.fixture(scope="session")
151184
def get_db(archive):

0 commit comments

Comments
 (0)