This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sync charm-helpers for tests * Add Travis CI configuration * Add yakkety support * Clean up pre-existing PEP8 sins * Fix functional tests
- Loading branch information
1 parent
1a82778
commit cefb77f
Showing
19 changed files
with
1,260 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
sudo: required | ||
dist: trusty | ||
language: python | ||
env: | ||
- UNIT_TEST=1 | ||
- AMULET_TEST=gate-basic-precise | ||
- AMULET_TEST=gate-basic-trusty | ||
- AMULET_TEST=gate-basic-xenial | ||
- AMULET_TEST=gate-basic-yakkety | ||
script: | ||
- if [ ! -z ${UNIT_TEST} ]; then make lint; fi | ||
- if [ ! -z ${UNIT_TEST} ]; then make test; fi | ||
# setup dependencies here to save time on simpler test envs | ||
# upgrade python 2.7 to mitigate juju-deployer ssl.SSLError | ||
# sudo back to ourself to activate lxd group membership | ||
- if [ ! -z ${AMULET_TEST} ]; then | ||
sudo add-apt-repository -y ppa:ubuntu-lxc/lxd-stable; | ||
sudo add-apt-repository -y ppa:juju/stable; | ||
sudo add-apt-repository -y ppa:fkrull/deadsnakes-python2.7; | ||
sudo apt-get -qq update; | ||
sudo apt-get -y install lxd juju python-tox libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib python-crypto python-pkg-resources python-yaml python2.7 python2.7-dev python2.7-minimal; | ||
sudo lxd init --auto; | ||
sudo usermod -a -G lxd travis; | ||
sudo su travis -c 'lxc network create lxdbr0'; | ||
sudo su travis -c 'lxc network attach-profile lxdbr0 default eth0'; | ||
sudo su travis -c 'juju bootstrap localhost'; | ||
make virtualenv; | ||
fi | ||
- if [ ! -z ${AMULET_TEST} ]; then | ||
sudo su travis -c '. .venv/bin/activate && bundletester -vl DEBUG | ||
--test-pattern "${AMULET_TEST}*"'; | ||
fi | ||
- if [ ! -z ${AMULET_TEST} ]; then sudo su travis -c 'juju status'; fi | ||
- if [ ! -z ${AMULET_TEST} ]; then | ||
sudo su travis -c \ | ||
'juju ssh mysql/0 sudo cat /var/log/juju/unit-mysql-0.log'; | ||
fi | ||
- if [ ! -z ${AMULET_TEST} ]; then | ||
sudo su travis -c 'juju ssh mysql/0 sudo cat /var/log/mysql/error.log'; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ branch: lp:charm-helpers | |
destination: tests/charmhelpers | ||
include: | ||
- contrib.amulet | ||
- contrib.openstack.amulet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ tags: | |
- databases | ||
- openstack | ||
series: | ||
- yakkety | ||
- xenial | ||
- trusty | ||
- precise | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
path.py<=8.1.2 | ||
PyYAML<=3.11 | ||
flake8 | ||
nose | ||
coverage | ||
mock | ||
six | ||
netifaces | ||
netaddr | ||
pymysql | ||
bundletester | ||
amulet | ||
charm-tools |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/python3 | ||
|
||
import amulet | ||
from charmhelpers.contrib.amulet.deployment import ( | ||
AmuletDeployment | ||
) | ||
import logging | ||
import sys | ||
|
||
try: | ||
import pymysql | ||
except ImportError: | ||
import pymysql3 # noqa | ||
|
||
|
||
class MySQLBasicDeployment(AmuletDeployment): | ||
def __init__(self, series=None): | ||
self.log = self._get_logger() | ||
self.max_connections = '30' | ||
# the default of 80% eats too much resources in a CI environment | ||
self.dataset_size = '25%' | ||
|
||
self.d = amulet.Deployment(series=series) | ||
|
||
self.d.add('mysql') | ||
self.d.configure( | ||
'mysql', { | ||
'max-connections': self.max_connections, | ||
'dataset-size': self.dataset_size, | ||
}, | ||
) | ||
self.d.expose('mysql') | ||
|
||
try: | ||
self.d.setup(timeout=900) | ||
self.d.sentry.wait() | ||
except amulet.helpers.TimeoutError: | ||
amulet.raise_status(amulet.SKIP, | ||
msg="Environment wasn't stood up in time") | ||
|
||
# Allow connections from outside | ||
mysqlmaster = self.d.sentry['mysql'][0] | ||
mysqlmaster.run( | ||
"echo 'GRANT ALL ON *.* to root@\"%\"'\"" | ||
" IDENTIFIED BY '`cat /var/lib/mysql/mysql.passwd`'\"|" | ||
"mysql -u root --password=`cat /var/lib/mysql/mysql.passwd`" | ||
) | ||
|
||
def _get_logger(self, name="deployment-logger", level=logging.DEBUG): | ||
"""Get a logger object that will log to stdout.""" | ||
log = logging | ||
logger = log.getLogger(name) | ||
fmt = log.Formatter("%(asctime)s %(funcName)s " | ||
"%(levelname)s: %(message)s") | ||
|
||
handler = log.StreamHandler(stream=sys.stdout) | ||
handler.setLevel(level) | ||
handler.setFormatter(fmt) | ||
|
||
logger.addHandler(handler) | ||
logger.setLevel(level) | ||
|
||
return logger | ||
|
||
def test_100_connect(self): | ||
"""Verify that we can connect to the deployed MySQL instance""" | ||
self.log.info('Verify that we can connect to the deployed MySQL ' | ||
'instance') | ||
mysql_server = self.d.sentry['mysql'][0] | ||
mysql_password = mysql_server.file_contents( | ||
'/var/lib/mysql/mysql.passwd') | ||
try: | ||
self.mysql_conn = pymysql.connect( | ||
user='root', | ||
password=mysql_password, | ||
host=mysql_server.info['public-address'], | ||
database='mysql') | ||
except: | ||
amulet.raise_status(amulet.FAIL, msg='Unable to connect to MySQL') | ||
self.log.info('OK') | ||
|
||
def test_110_check_variables(self): | ||
"""Verify that configured variables are reflected back to us when | ||
asking MySQL server about them.""" | ||
self.log.info('Verify that configured variables are reflected back to ' | ||
'us when asking MySQL server about them.') | ||
cur = self.mysql_conn.cursor() | ||
cur.execute("SHOW VARIABLES LIKE 'max_connections'") | ||
for row in cur: | ||
if row[0] == 'max_connections': | ||
if row[1] == self.max_connections: | ||
self.log.info('OK') | ||
return | ||
else: | ||
amulet.raise_status( | ||
amulet.FAIL, | ||
msg="max_connections='{}', expected '{}'" | ||
"".format(row[1], self.max_connections)) | ||
amulet.raise_status( | ||
amulet.FAIL, | ||
msg='Unable to retrieve value for max_connections from server') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2014-2015 Canonical Limited. | ||
# | ||
# 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. | ||
|
||
# Bootstrap charm-helpers, installing its dependencies if necessary using | ||
# only standard libraries. | ||
import subprocess | ||
import sys | ||
|
||
try: | ||
import six # flake8: noqa | ||
except ImportError: | ||
if sys.version_info.major == 2: | ||
subprocess.check_call(['apt-get', 'install', '-y', 'python-six']) | ||
else: | ||
subprocess.check_call(['apt-get', 'install', '-y', 'python3-six']) | ||
import six # flake8: noqa | ||
|
||
try: | ||
import yaml # flake8: noqa | ||
except ImportError: | ||
if sys.version_info.major == 2: | ||
subprocess.check_call(['apt-get', 'install', '-y', 'python-yaml']) | ||
else: | ||
subprocess.check_call(['apt-get', 'install', '-y', 'python3-yaml']) | ||
import yaml # flake8: noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2014-2015 Canonical Limited. | ||
# | ||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2014-2015 Canonical Limited. | ||
# | ||
# 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. |
Oops, something went wrong.