-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a9d8d1
commit 6adf3e0
Showing
12 changed files
with
225 additions
and
90 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,7 @@ | ||
Before running set environment variables, eg.: | ||
|
||
export DOCKER_ACC="percona" | ||
export PS_VERSION="8.0.32-24" | ||
export ROUTER_VERSION="8.0.32" | ||
export TESTING_BRANCH="master" | ||
This is based on: https://testinfra.readthedocs.io/en/latest/examples.html#test-docker-images |
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,5 @@ | ||
#!/usr/bin/env bash | ||
rm -f report.xml | ||
rm -rf .pytest_cache | ||
rm -rf __pycache__ | ||
rm -rf tests/__pycache__ |
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,15 @@ | ||
atomicwrites==1.3.0 | ||
attrs==19.3.0 | ||
importlib-metadata==0.23 | ||
more-itertools==7.2.0 | ||
packaging==19.2 | ||
pluggy==0.13.0 | ||
py==1.10.0 | ||
pyparsing==2.4.2 | ||
pytest==5.2.1 | ||
six==1.12.0 | ||
testinfra==3.2.0 | ||
wcwidth==0.1.7 | ||
zipp==0.6.0 | ||
requests==2.27.1 | ||
docker==5.0.3 |
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,2 @@ | ||
#!/usr/bin/env bash | ||
pytest -v --junit-xml report.xml $@ |
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,14 @@ | ||
import os | ||
|
||
router_version = os.getenv('ROUTER_VERSION') | ||
docker_tag = os.getenv('ROUTER_VERSION') | ||
docker_acc = os.getenv('DOCKER_ACC') | ||
|
||
docker_product = 'percona-mysql-router' | ||
docker_image = docker_acc + "/" + docker_product + ":" + docker_tag | ||
ps_pwd = 'inno' | ||
|
||
RHEL_DISTS = ["redhat", "centos", "rhel", "oracleserver", "ol", "amzn"] | ||
|
||
DEB_DISTS = ["debian", "ubuntu"] | ||
|
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,70 @@ | ||
#!/usr/bin/env python3 | ||
import pytest | ||
import subprocess | ||
import testinfra | ||
import time | ||
from settings import * | ||
|
||
container_name = 'router-docker-test-static' | ||
|
||
@pytest.fixture(scope='module') | ||
def host(): | ||
docker_id = subprocess.check_output( | ||
['docker', 'run', '--name', container_name, '-d', docker_image ], stderr=subprocess.STDOUT ).decode().strip() | ||
time.sleep(20) | ||
subprocess.check_call(['docker','exec','--user','root',container_name,'microdnf','install', '-y', 'net-tools']) | ||
time.sleep(20) | ||
yield testinfra.get_host("docker://root@" + docker_id) | ||
subprocess.check_call(['docker', 'rm', '-f', docker_id]) | ||
|
||
|
||
class TestRouterEnvironment: | ||
def test_packages(self, host): | ||
pkg = host.package("percona-mysql-router") | ||
dist = host.system_info.distribution | ||
assert pkg.is_installed | ||
if dist.lower() in RHEL_DISTS: | ||
assert router_version in pkg.version+'-'+pkg.release, pkg.version+'-'+pkg.release | ||
else: | ||
assert router_version in pkg.version, pkg.version | ||
|
||
def test_binaries_exist(self, host): | ||
router_binary="/tmp/mysqlrouter" | ||
assert host.file(router_binary).exists | ||
assert oct(host.file(router_binary).mode) == '0o755' | ||
|
||
def test_binaries_version(self, host): | ||
assert router_version in host.check_output("/tmp/mysqlrouter --version") | ||
|
||
# def test_process_running(self, host): | ||
# assert host.process.get(user="mysql", comm="orchestrator") | ||
|
||
def test_http_port_6446(self, host): | ||
assert host.socket('tcp://127.0.0.1:6446').is_listening | ||
|
||
def test_raft_port_6447(self, host): | ||
assert host.socket('tcp://127.0.0.1:6447').is_listening | ||
|
||
def test_mysql_user(self, host): | ||
assert host.user('mysql').exists | ||
assert host.user('mysql').uid == 1001 | ||
assert host.user('mysql').gid == 1001 | ||
assert 'mysql' in host.user('mysql').groups | ||
|
||
def test_mysql_group(self, host): | ||
assert host.group('mysql').exists | ||
assert host.group('mysql').gid == 1001 | ||
|
||
def test_router_permissions(self, host): | ||
assert host.file('/var/lib/mysqlrouter').user == 'mysql' | ||
assert host.file('/var/lib/mysqlrouter').group == 'mysql' | ||
assert oct(host.file('/var/lib/mysqlrouter').mode) == '0o755' | ||
|
||
def test_mysqlrouter_version(self, host): | ||
cmd = host.run("mysqlrouter --version") | ||
assert router_version in cmd.stdout | ||
|
||
|
||
def test_mysqlsh_version(self, host): | ||
cmd = host.run("mysqlsh --version") | ||
assert PS_VERSION in cmd.stdout |
Binary file not shown.
Binary file added
BIN
+12 KB
docker-image-tests/percona-mysql-router/tests/.test_router_static.py.swp
Binary file not shown.
Empty file.
38 changes: 38 additions & 0 deletions
38
docker-image-tests/percona-mysql-router/tests/test_router_attr.py
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,38 @@ | ||
#!/usr/bin/env python3 | ||
import pytest | ||
import subprocess | ||
import testinfra | ||
import json | ||
from settings import * | ||
|
||
container_name = 'router-docker-test-inspect' | ||
|
||
@pytest.fixture(scope='module') | ||
def inspect_data(): | ||
docker_id = subprocess.check_output( | ||
['docker', 'run', '--name', container_name, '-d', docker_image], stderr=subprocess.STDOUT ).decode().strip() | ||
inspect_data = json.loads(subprocess.check_output(['docker','inspect',container_name])) | ||
yield inspect_data[0] | ||
subprocess.check_call(['docker', 'rm', '-f', docker_id]) | ||
|
||
|
||
class TestContainerAttributes: | ||
def test_status(self, inspect_data): | ||
assert inspect_data['State']['Status'] == 'running' | ||
assert inspect_data['State']['Running'] == True | ||
|
||
def test_config(self, inspect_data): | ||
assert len(inspect_data['Config']['Cmd']) == 1 | ||
assert inspect_data['Config']['Cmd'][0] == 'mysqlrouter' | ||
|
||
def test_image_name(self, inspect_data): | ||
assert inspect_data['Config']['Image'] == docker_image | ||
|
||
def test_volumes(self, inspect_data): | ||
assert len(inspect_data['Config']['Volumes']) == 1 | ||
assert '/var/lib/mysqlrouter' in inspect_data['Config']['Volumes'] | ||
|
||
def test_entrypoint(self, inspect_data): | ||
assert len(inspect_data['Config']['Entrypoint']) == 1 | ||
assert inspect_data['Config']['Entrypoint'][0] == '/entrypoint.sh' | ||
|
59 changes: 59 additions & 0 deletions
59
docker-image-tests/percona-mysql-router/tests/test_router_static.py
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,59 @@ | ||
#!/usr/bin/env python3 | ||
import pytest | ||
import subprocess | ||
import testinfra | ||
import time | ||
from settings import * | ||
import json | ||
import os | ||
import requests | ||
import docker | ||
|
||
container_name = 'mysql-router-test' | ||
network_name = 'innodbnet1' | ||
|
||
@pytest.fixture(scope='module') | ||
def host(): | ||
docker_client = docker.from_env() | ||
docker_client.networks.create(network_name) | ||
docker_id = subprocess.check_output( | ||
['docker', 'run', '--name', container_name, '--net', network_name, '--MYSQL_PASSWORD', '+ps_pwd+', '--MYSQL_INNODB_CLUSTER_MEMBERS', '4', '-d', docker_image ], stderr=subprocess.STDOUT ).decode().strip() | ||
time.sleep(20) | ||
subprocess.check_call(['docker','exec','--user','root',container_name,'microdnf','install', '-y', 'net-tools']) | ||
time.sleep(20) | ||
yield testinfra.get_host("docker://root@" + docker_id) | ||
subprocess.check_call(['docker', 'rm', '-f', docker_id]) | ||
|
||
|
||
class TestRouterEnvironment: | ||
def test_mysqlsh_version(self, host): | ||
assert host.check_output("mysqlsh --version") == 'mysqlsh Ver '+ROUTER_VERSION+' for Linux on x86_64 - for MySQL '+PS_VERSION+' (Source distribution)' | ||
|
||
def test_mysqlrouter_version(self, host): | ||
assert host.check_output("mysqlrouter --version") == 'MySQL Router Ver '+PS_VERSION+' for Linux on x86_64 (Percona Server (GPL), Release 25, Revision '+Revision+')' | ||
|
||
def test_binaries_exist(self, host): | ||
router_binary="/tmp/mysqlrouter" | ||
assert host.file(router_binary).exists | ||
assert oct(host.file(router_binary).mode) == '0o755' | ||
|
||
def test_http_port_6447(self, host): | ||
assert host.socket('tcp://127.0.0.1:6447').is_listening | ||
|
||
def test_raft_port_6446(self, host): | ||
assert host.socket('tcp://127.0.0.1:6446').is_listening | ||
|
||
def test_mysql_user(self, host): | ||
assert host.user('mysql').exists | ||
assert host.user('mysql').uid == 1001 | ||
assert host.user('mysql').gid == 1001 | ||
assert 'mysql' in host.user('mysql').groups | ||
|
||
def test_mysql_group(self, host): | ||
assert host.group('mysql').exists | ||
assert host.group('mysql').gid == 1001 | ||
|
||
def test_router_permissions(self, host): | ||
assert host.file('/var/lib/mysqlrouter').user == 'mysql' | ||
assert host.file('/var/lib/mysqlrouter').group == 'mysql' | ||
assert oct(host.file('/var/lib/mysqlrouter').mode) == '0o755' |
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