From 55f229b7101d763255d496e123b8cf361a34496e Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 8 Sep 2023 15:37:53 +0530 Subject: [PATCH 01/19] MySQL Router Docker --- .../percona-mysql-router/README.md | 7 ++ .../percona-mysql-router/cleanup.sh | 5 + .../percona-mysql-router/requirements.txt | 15 +++ .../percona-mysql-router/run.sh | 2 + .../percona-mysql-router/settings.py | 14 +++ docker-image-tests/percona-mysql-router/test | 70 ++++++++++++ .../tests/.test_router_attr.py.swp | Bin 0 -> 12288 bytes .../tests/.test_router_static.py.swp | Bin 0 -> 12288 bytes .../percona-mysql-router/tests/__init__.py | 0 .../tests/test_router_attr.py | 38 +++++++ .../tests/test_router_static.py | 59 ++++++++++ router-docker_test.sh | 105 +++--------------- 12 files changed, 225 insertions(+), 90 deletions(-) create mode 100644 docker-image-tests/percona-mysql-router/README.md create mode 100755 docker-image-tests/percona-mysql-router/cleanup.sh create mode 100644 docker-image-tests/percona-mysql-router/requirements.txt create mode 100755 docker-image-tests/percona-mysql-router/run.sh create mode 100644 docker-image-tests/percona-mysql-router/settings.py create mode 100644 docker-image-tests/percona-mysql-router/test create mode 100644 docker-image-tests/percona-mysql-router/tests/.test_router_attr.py.swp create mode 100644 docker-image-tests/percona-mysql-router/tests/.test_router_static.py.swp create mode 100644 docker-image-tests/percona-mysql-router/tests/__init__.py create mode 100644 docker-image-tests/percona-mysql-router/tests/test_router_attr.py create mode 100644 docker-image-tests/percona-mysql-router/tests/test_router_static.py diff --git a/docker-image-tests/percona-mysql-router/README.md b/docker-image-tests/percona-mysql-router/README.md new file mode 100644 index 000000000..7bd652f9e --- /dev/null +++ b/docker-image-tests/percona-mysql-router/README.md @@ -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 diff --git a/docker-image-tests/percona-mysql-router/cleanup.sh b/docker-image-tests/percona-mysql-router/cleanup.sh new file mode 100755 index 000000000..3cdc4f0ec --- /dev/null +++ b/docker-image-tests/percona-mysql-router/cleanup.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +rm -f report.xml +rm -rf .pytest_cache +rm -rf __pycache__ +rm -rf tests/__pycache__ diff --git a/docker-image-tests/percona-mysql-router/requirements.txt b/docker-image-tests/percona-mysql-router/requirements.txt new file mode 100644 index 000000000..8a28056d0 --- /dev/null +++ b/docker-image-tests/percona-mysql-router/requirements.txt @@ -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 diff --git a/docker-image-tests/percona-mysql-router/run.sh b/docker-image-tests/percona-mysql-router/run.sh new file mode 100755 index 000000000..8ba9b8684 --- /dev/null +++ b/docker-image-tests/percona-mysql-router/run.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +pytest -v --junit-xml report.xml $@ diff --git a/docker-image-tests/percona-mysql-router/settings.py b/docker-image-tests/percona-mysql-router/settings.py new file mode 100644 index 000000000..095ad5237 --- /dev/null +++ b/docker-image-tests/percona-mysql-router/settings.py @@ -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"] + diff --git a/docker-image-tests/percona-mysql-router/test b/docker-image-tests/percona-mysql-router/test new file mode 100644 index 000000000..29e2c5342 --- /dev/null +++ b/docker-image-tests/percona-mysql-router/test @@ -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 diff --git a/docker-image-tests/percona-mysql-router/tests/.test_router_attr.py.swp b/docker-image-tests/percona-mysql-router/tests/.test_router_attr.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..48502ade281d5aa4a9e01cd4b7fbcd9a2c3598fe GIT binary patch literal 12288 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 VK2hrlUc=L^1|1BvuCsWG`~indR_g!& literal 0 HcmV?d00001 diff --git a/docker-image-tests/percona-mysql-router/tests/__init__.py b/docker-image-tests/percona-mysql-router/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_attr.py b/docker-image-tests/percona-mysql-router/tests/test_router_attr.py new file mode 100644 index 000000000..1499d176c --- /dev/null +++ b/docker-image-tests/percona-mysql-router/tests/test_router_attr.py @@ -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' + diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py new file mode 100644 index 000000000..86856d673 --- /dev/null +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -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, '-e', '--net', network_name, '-e', 'MYSQL_ROOT_PASSWORD='+ps_pwd, '-e', '--MYSQL_INNODB_CLUSTER_MEMBERS', '4', 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' diff --git a/router-docker_test.sh b/router-docker_test.sh index b453b86ab..9eae67318 100755 --- a/router-docker_test.sh +++ b/router-docker_test.sh @@ -1,31 +1,4 @@ -#!/bin/bash - -if [ $# -eq 0 ]; -then - echo "$0: Missing arguments" - exit 1 -elif [ $# -gt 2 ]; -then - echo "$0: Too many arguments: $@" - exit 1 -else - echo "We got some argument(s)" - - echo "===========================" - - echo "Number of arguments.: $#" - - echo "List of arguments...: $@" - - echo "Arg #1..............: $1" - - echo "Arg #2..............: $2" - - echo "===========================" -fi - - -set -xe +#!/usr/bin/env bash cleanup(){ @@ -78,7 +51,7 @@ start_mysql_containers(){ create_new_user(){ for N in 1 2 3 4 - do sudo docker exec -it mysql$N mysql -uroot -proot \ + do sudo docker exec mysql$N mysql -uroot -proot \ -e "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno';" \ -e "GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option;" \ -e "reset master;" @@ -88,7 +61,7 @@ create_new_user(){ verify_new_user(){ for N in 1 2 3 4 - do sudo docker exec -it mysql$N mysql -uinno -pinno \ + do sudo docker exec mysql$N mysql -uinno -pinno \ -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" \ -e "SELECT user FROM mysql.user where user = 'inno';" done @@ -104,19 +77,19 @@ docker_restart(){ create_cluster(){ - sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster + sudo docker exec mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster } add_slave(){ - sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental + sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental sleep 10 - sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental + sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental sleep 10 - sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental + sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental sleep 10 } @@ -131,69 +104,24 @@ Router_Bootstrap(){ data_add(){ sudo docker run -d --name=mysql-client --hostname=mysql-client --net=innodbnet -e MYSQL_ROOT_PASSWORD=root $1 - + sleep 10 - + echo "Adding sbtest user" - sudo docker exec -it mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \ + sudo docker exec mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \ -e "CREATE SCHEMA sbtest; CREATE USER sbtest@'%' IDENTIFIED with mysql_native_password by 'password';" \ -e "GRANT ALL PRIVILEGES ON sbtest.* to sbtest@'%';" echo "Verify sbtest user" - - sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';" - - sleep 5 - - echo "sysbench run" - - sudo docker run --rm=true --net=innodbnet --name=sb-prepare severalnines/sysbench sysbench --db-driver=mysql --table-size=10000 --tables=1 --threads=1 --mysql-host=mysql-router --mysql-port=6446--mysql-user=sbtest --mysql-password=password /usr/share/sysbench/oltp_insert.lua prepare - - sleep 20 - - echo "verify if data is inserted or not" - - sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "SELECT count(*) from sbtest.sbtest1;" -} - -verify_replication(){ - - for N in 1 2 3 4; - do - sudo docker exec -it mysql$N mysql -uinno -pinno -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" -e "SELECT count(*) from sbtest.sbtest1;"; - done -} -Fault_tolerance(){ + sudo docker exec mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';" - echo "Stop One node" - - sudo docker stop mysql1 - - sleep 10 - - echo "check status" - - sudo docker exec -it mysql-client mysqlsh -h mysql-router -P 6446 -uinno -pinno -- cluster status >> cluster1.json - - sed '1d' cluster1.json >> cluster.json - - status=$(jq -r '.defaultReplicaSet.status' cluster.json) - - echo $status -} - -verify_status(){ + sleep 5 - if [[ "${status}" = "OK_PARTIAL" ]]; then - echo "Innodb cluster looks good" - exit 0 - else - echo "Issue in Innodb Cluster" - exit 1 - fi + echo "sysbench run" + sudo docker run --rm=true --net=innodbnet --name=sb-prepare severalnines/sysbench sysbench --db-driver=mysql --table-size=10000 --tables=1 --threads=1 --mysql-host=mysql-router --mysql-port=6446--mysql-user=sbtest --mysql-password=password /usr/share/sysbench/oltp_insert.lua prepare } cleanup @@ -206,7 +134,4 @@ docker_restart create_cluster add_slave Router_Bootstrap $2 -data_add $1 -verify_replication -Fault_tolerance -verify_status +data_add $1 From d56d4eff472c1a2d4636b3a247f9760d181d22b6 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Sun, 10 Sep 2023 12:41:44 +0530 Subject: [PATCH 02/19] debug --- .../tests/test_router_static.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 86856d673..7f7782b46 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -12,6 +12,38 @@ container_name = 'mysql-router-test' network_name = 'innodbnet1' +def get_running_containers(): + try: + # Run the docker ps command and capture the output + output = subprocess.check_output(['docker', 'ps'], universal_newlines=True) + + # Split the output into lines + lines = output.strip().split('\n') + + # Skip the header line (which contains column names) + containers = lines[1:] + + # Extract container IDs and names + container_info = [line.split()[:2] for line in containers] + + return container_info + + except subprocess.CalledProcessError as e: + print(f"Error: {e}") + return None + +# Get the list of running containers +running_containers = get_running_containers() + +# Print the container IDs and names +if running_containers: + print("Running Docker Containers:") + for container in running_containers: + print(f"ID: {container[0]}, Name: {container[1]}") +else: + print("Failed to retrieve running containers.") + + @pytest.fixture(scope='module') def host(): docker_client = docker.from_env() @@ -25,6 +57,38 @@ def host(): subprocess.check_call(['docker', 'rm', '-f', docker_id]) +def get_running_containers(): + try: + # Run the docker ps command and capture the output + output = subprocess.check_output(['docker', 'ps'], universal_newlines=True) + + # Split the output into lines + lines = output.strip().split('\n') + + # Skip the header line (which contains column names) + containers = lines[1:] + + # Extract container IDs and names + container_info = [line.split()[:2] for line in containers] + + return container_info + + except subprocess.CalledProcessError as e: + print(f"Error: {e}") + return None + +# Get the list of running containers +running_containers = get_running_containers() + +# Print the container IDs and names +if running_containers: + print("Running Docker Containers:") + for container in running_containers: + print(f"ID: {container[0]}, Name: {container[1]}") +else: + print("Failed to retrieve running containers.") + + 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)' From 38480ff7a4bf96eeca9992f7c0b5a394de876b5d Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Mon, 11 Sep 2023 16:25:50 +0530 Subject: [PATCH 03/19] Remove .swp files --- .../tests/.test_router_attr.py.swp | Bin 12288 -> 0 bytes .../tests/.test_router_static.py.swp | Bin 12288 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 docker-image-tests/percona-mysql-router/tests/.test_router_attr.py.swp delete mode 100644 docker-image-tests/percona-mysql-router/tests/.test_router_static.py.swp diff --git a/docker-image-tests/percona-mysql-router/tests/.test_router_attr.py.swp b/docker-image-tests/percona-mysql-router/tests/.test_router_attr.py.swp deleted file mode 100644 index 48502ade281d5aa4a9e01cd4b7fbcd9a2c3598fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 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 VK2hrlUc=L^1|1BvuCsWG`~indR_g!& From 0ddf34317ce6a1b7fe408a2bc88eec424225ac17 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Mon, 11 Sep 2023 16:55:15 +0530 Subject: [PATCH 04/19] UPdate env variables --- .../tests/test_router_static.py | 68 +------------------ 1 file changed, 3 insertions(+), 65 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 7f7782b46..02e10abca 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -11,38 +11,9 @@ container_name = 'mysql-router-test' network_name = 'innodbnet1' - -def get_running_containers(): - try: - # Run the docker ps command and capture the output - output = subprocess.check_output(['docker', 'ps'], universal_newlines=True) - - # Split the output into lines - lines = output.strip().split('\n') - - # Skip the header line (which contains column names) - containers = lines[1:] - - # Extract container IDs and names - container_info = [line.split()[:2] for line in containers] - - return container_info - - except subprocess.CalledProcessError as e: - print(f"Error: {e}") - return None - -# Get the list of running containers -running_containers = get_running_containers() - -# Print the container IDs and names -if running_containers: - print("Running Docker Containers:") - for container in running_containers: - print(f"ID: {container[0]}, Name: {container[1]}") -else: - print("Failed to retrieve running containers.") - +docker_tag = os.getenv('ROUTER_VERSION') +docker_acc = os.getenv('DOCKER_ACC') +docker_image = docker_acc + "/" + "percona-mysql-router" + ":" + docker_tag @pytest.fixture(scope='module') def host(): @@ -56,39 +27,6 @@ def host(): yield testinfra.get_host("docker://root@" + docker_id) subprocess.check_call(['docker', 'rm', '-f', docker_id]) - -def get_running_containers(): - try: - # Run the docker ps command and capture the output - output = subprocess.check_output(['docker', 'ps'], universal_newlines=True) - - # Split the output into lines - lines = output.strip().split('\n') - - # Skip the header line (which contains column names) - containers = lines[1:] - - # Extract container IDs and names - container_info = [line.split()[:2] for line in containers] - - return container_info - - except subprocess.CalledProcessError as e: - print(f"Error: {e}") - return None - -# Get the list of running containers -running_containers = get_running_containers() - -# Print the container IDs and names -if running_containers: - print("Running Docker Containers:") - for container in running_containers: - print(f"ID: {container[0]}, Name: {container[1]}") -else: - print("Failed to retrieve running containers.") - - 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)' From 94b07ca2d552b48c5435d7f1302bb1fd9ea0c923 Mon Sep 17 00:00:00 2001 From: Yash Panchal <46398416+panchal-yash@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:23:44 +0530 Subject: [PATCH 05/19] Update test_router_static.py Remove '-e' before '--net' --- .../percona-mysql-router/tests/test_router_static.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 02e10abca..9d0152b89 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -20,7 +20,7 @@ def host(): docker_client = docker.from_env() docker_client.networks.create(network_name) docker_id = subprocess.check_output( - ['docker', 'run', '--name', container_name, '-e', '--net', network_name, '-e', 'MYSQL_ROOT_PASSWORD='+ps_pwd, '-e', '--MYSQL_INNODB_CLUSTER_MEMBERS', '4', docker_image ], stderr=subprocess.STDOUT ).decode().strip() + ['docker', 'run', '--name', container_name, '--net', network_name, '-e', 'MYSQL_ROOT_PASSWORD='+ps_pwd, '-e', '--MYSQL_INNODB_CLUSTER_MEMBERS', '4', 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) From 9039f6a67e87409ada1887587b1fd903e60523b3 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Thu, 28 Sep 2023 16:11:16 +0530 Subject: [PATCH 06/19] Updates --- .../tests/test_router_static.py | 153 ++++++++++++++---- 1 file changed, 121 insertions(+), 32 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 9d0152b89..3efa1a15c 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -13,49 +13,138 @@ network_name = 'innodbnet1' docker_tag = os.getenv('ROUTER_VERSION') docker_acc = os.getenv('DOCKER_ACC') -docker_image = docker_acc + "/" + "percona-mysql-router" + ":" + docker_tag +ps_version = os.getenv('PS_VERSION') +router_docker_image = docker_acc + "/" + "percona-mysql-router" + ":" + docker_tag +percona_docker_image = docker_acc + "/" + "percona-server" + ":" + ps_version +def create_network(): + subprocess.run(['sudo', 'docker', 'network', 'create', 'innodbnet']) + +def create_mysql_config(): + for N in range(1, 5): + with open(f'my{N}.cnf', 'w') as file: + file.write( + f"[mysqld]\n" + f"plugin_load_add='group_replication.so'\n" + f"server_id={(hash(str(time.time()) + str(N))) % 40 + 10}\n" + f"binlog_checksum=NONE\n" + f"enforce_gtid_consistency=ON\n" + f"gtid_mode=ON\n" + f"relay_log=mysql{N}-relay-bin\n" + f"innodb_dedicated_server=ON\n" + f"binlog_transaction_dependency_tracking=WRITESET\n" + f"slave_preserve_commit_order=ON\n" + f"slave_parallel_type=LOGICAL_CLOCK\n" + f"transaction_write_set_extraction=XXHASH64\n" + ) + +def start_mysql_containers(): + for N in range(1, 5): + subprocess.run([ + 'sudo', 'docker', 'run', '-d', + f'--name=mysql{N}', + f'--hostname=mysql{N}', + '--net=innodbnet', + '-v', f'/home/puneet/my{N}.cnf:/etc/my.cnf', + '-e', 'MYSQL_ROOT_PASSWORD=root', percona_docker_image + ]) + time.sleep(60) + +def create_new_user(): + for N in range(1, 5): + subprocess.run([ + 'sudo', 'docker', 'exec', f'mysql{N}', + 'mysql', '-uroot', '-proot', + '-e', "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno'; GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option; FLUSH PRIVILEGES;" + ]) + +def verify_new_user(): + for N in range(1, 5): + subprocess.run([ + 'sudo', 'docker', 'exec', f'mysql{N}', + 'mysql', '-uinno', '-pinno', + '-e', "SHOW VARIABLES WHERE Variable_name = 'hostname';" + '-e', "SELECT user FROM mysql.user where user = 'inno';" + ]) + time.sleep(30) + +def docker_restart(): + subprocess.run(['sudo', 'docker', 'restart', 'mysql1', 'mysql2', 'mysql3', 'mysql4']) + time.sleep(10) + +def create_cluster(): + subprocess.run([ + 'sudo', 'docker', 'exec', 'mysql1', + 'mysqlsh', '-uinno', '-pinno', '--', 'dba', 'create-cluster', 'testCluster' + ]) + +def add_slave(): + subprocess.run([ + 'sudo', 'docker', 'exec', 'mysql1', + 'mysqlsh', '-uinno', '-pinno', '--', + 'cluster', 'add-instance', '--uri=inno@mysql3', '--recoveryMethod=incremental' + ]) + time.sleep(10) + subprocess.run([ + 'sudo', 'docker', 'exec', 'mysql1', + 'mysqlsh', '-uinno', '-pinno', '--', + 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=incremental' + ]) + +def router_bootstrap(): + subprocess.run([ + 'sudo', 'docker', 'run', '-d', + '--name', 'mysql-router', + '--net=innodbnet', + '-e', 'MYSQL_HOST=mysql1', + '-e', 'MYSQL_PORT=3306', + '-e', 'MYSQL_USER=inno', + '-e', 'MYSQL_PASSWORD=inno', + '-e', 'MYSQL_INNODB_CLUSTER_MEMBERS=4', + router_docker_image + ]) + +# Get the Docker ID of the running container +docker_id = subprocess.check_output(['sudo', 'docker', 'ps', '-q', '--filter', f'name={container_name}']).decode().strip() + +# Define the pytest fixture to provide the host identifier @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, '-e', 'MYSQL_ROOT_PASSWORD='+ps_pwd, '-e', '--MYSQL_INNODB_CLUSTER_MEMBERS', '4', 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]) + yield 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)' +# Create an instance of the Host class +class Host: + def check_output(self, command): + result = subprocess.run(['docker', 'exec', docker_id, 'bash', '-c', command], capture_output=True, text=True) + return result.stdout.strip() - 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+')' +# Instantiate an instance of the Host class +host = Host() - def test_binaries_exist(self, host): - router_binary="/tmp/mysqlrouter" - assert host.file(router_binary).exists - assert oct(host.file(router_binary).mode) == '0o755' +class TestRouterEnvironment: + def test_mysqlrouter_version(self, host): + command = "mysqlrouter --version" + output = host.check_output(command) + assert "8.0.33" in output - def test_http_port_6447(self, host): - assert host.socket('tcp://127.0.0.1:6447').is_listening + def test_mysqlsh_version(self, host): + command = "mysqlsh --version" + output = host.check_output(command) + assert "8.0.33-25" in output - def test_raft_port_6446(self, host): - assert host.socket('tcp://127.0.0.1:6446').is_listening + def test_mysqlrouter_directory_permissions(self, host): + assert host.file('/var/lib/mysqlrouter').user == 'mysqlrouter' + assert host.file('/var/lib/mysqlrouter').group == 'mysqlrouter' + assert oct(host.file('/var/lib/mysqlrouter').mode) == '0o755' 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_mysql_user(self, host): + mysql_user = host.user('mysql') + print(f"Username: {mysql_user.name}, UID: {mysql_user.uid}") + assert mysql_user.exists + assert mysql_user.uid == 1001 From d09bdc397b4b4b55a05b816c98f17d120f7b09d3 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Thu, 28 Sep 2023 16:43:52 +0530 Subject: [PATCH 07/19] Remove unnecessary files --- docker-image-tests/percona-mysql-router/test | 70 -------------------- 1 file changed, 70 deletions(-) delete mode 100644 docker-image-tests/percona-mysql-router/test diff --git a/docker-image-tests/percona-mysql-router/test b/docker-image-tests/percona-mysql-router/test deleted file mode 100644 index 29e2c5342..000000000 --- a/docker-image-tests/percona-mysql-router/test +++ /dev/null @@ -1,70 +0,0 @@ -#!/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 From e6c64cd620aa9d3052e7b01492d9343ab9334d65 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Thu, 28 Sep 2023 16:52:19 +0530 Subject: [PATCH 08/19] removing files --- router-docker_test.sh | 105 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 15 deletions(-) diff --git a/router-docker_test.sh b/router-docker_test.sh index 9eae67318..b453b86ab 100755 --- a/router-docker_test.sh +++ b/router-docker_test.sh @@ -1,4 +1,31 @@ -#!/usr/bin/env bash +#!/bin/bash + +if [ $# -eq 0 ]; +then + echo "$0: Missing arguments" + exit 1 +elif [ $# -gt 2 ]; +then + echo "$0: Too many arguments: $@" + exit 1 +else + echo "We got some argument(s)" + + echo "===========================" + + echo "Number of arguments.: $#" + + echo "List of arguments...: $@" + + echo "Arg #1..............: $1" + + echo "Arg #2..............: $2" + + echo "===========================" +fi + + +set -xe cleanup(){ @@ -51,7 +78,7 @@ start_mysql_containers(){ create_new_user(){ for N in 1 2 3 4 - do sudo docker exec mysql$N mysql -uroot -proot \ + do sudo docker exec -it mysql$N mysql -uroot -proot \ -e "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno';" \ -e "GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option;" \ -e "reset master;" @@ -61,7 +88,7 @@ create_new_user(){ verify_new_user(){ for N in 1 2 3 4 - do sudo docker exec mysql$N mysql -uinno -pinno \ + do sudo docker exec -it mysql$N mysql -uinno -pinno \ -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" \ -e "SELECT user FROM mysql.user where user = 'inno';" done @@ -77,19 +104,19 @@ docker_restart(){ create_cluster(){ - sudo docker exec mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster } add_slave(){ - sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental sleep 10 - sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental sleep 10 - sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental sleep 10 } @@ -104,24 +131,69 @@ Router_Bootstrap(){ data_add(){ sudo docker run -d --name=mysql-client --hostname=mysql-client --net=innodbnet -e MYSQL_ROOT_PASSWORD=root $1 - + sleep 10 - + echo "Adding sbtest user" - sudo docker exec mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \ + sudo docker exec -it mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \ -e "CREATE SCHEMA sbtest; CREATE USER sbtest@'%' IDENTIFIED with mysql_native_password by 'password';" \ -e "GRANT ALL PRIVILEGES ON sbtest.* to sbtest@'%';" echo "Verify sbtest user" - - sudo docker exec mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';" - + + sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';" + sleep 5 - + echo "sysbench run" sudo docker run --rm=true --net=innodbnet --name=sb-prepare severalnines/sysbench sysbench --db-driver=mysql --table-size=10000 --tables=1 --threads=1 --mysql-host=mysql-router --mysql-port=6446--mysql-user=sbtest --mysql-password=password /usr/share/sysbench/oltp_insert.lua prepare + + sleep 20 + + echo "verify if data is inserted or not" + + sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "SELECT count(*) from sbtest.sbtest1;" +} + +verify_replication(){ + + for N in 1 2 3 4; + do + sudo docker exec -it mysql$N mysql -uinno -pinno -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" -e "SELECT count(*) from sbtest.sbtest1;"; + done +} + +Fault_tolerance(){ + + echo "Stop One node" + + sudo docker stop mysql1 + + sleep 10 + + echo "check status" + + sudo docker exec -it mysql-client mysqlsh -h mysql-router -P 6446 -uinno -pinno -- cluster status >> cluster1.json + + sed '1d' cluster1.json >> cluster.json + + status=$(jq -r '.defaultReplicaSet.status' cluster.json) + + echo $status +} + +verify_status(){ + + if [[ "${status}" = "OK_PARTIAL" ]]; then + echo "Innodb cluster looks good" + exit 0 + else + echo "Issue in Innodb Cluster" + exit 1 + fi + } cleanup @@ -134,4 +206,7 @@ docker_restart create_cluster add_slave Router_Bootstrap $2 -data_add $1 +data_add $1 +verify_replication +Fault_tolerance +verify_status From e607434c6972bc731d40b9dbf27208a465fa5883 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Thu, 28 Sep 2023 16:55:50 +0530 Subject: [PATCH 09/19] Syntax error --- .../percona-mysql-router/tests/test_router_static.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 3efa1a15c..b8b6363df 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -45,7 +45,7 @@ def start_mysql_containers(): f'--name=mysql{N}', f'--hostname=mysql{N}', '--net=innodbnet', - '-v', f'/home/puneet/my{N}.cnf:/etc/my.cnf', + '-v', f'my{N}.cnf:/etc/my.cnf', '-e', 'MYSQL_ROOT_PASSWORD=root', percona_docker_image ]) time.sleep(60) From c7a11d96011e3de1908497a59cc8e0c7c9e54300 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 29 Sep 2023 10:50:16 +0530 Subject: [PATCH 10/19] Adding functions --- .../tests/test_router_static.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index b8b6363df..d34a472ca 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -104,6 +104,16 @@ def router_bootstrap(): router_docker_image ]) +create_network() +create_mysql_config() +start_mysql_containers() +create_new_user() +verify_new_user() +docker_restart() +create_cluster() +add_slave() +router_bootstrap() + # Get the Docker ID of the running container docker_id = subprocess.check_output(['sudo', 'docker', 'ps', '-q', '--filter', f'name={container_name}']).decode().strip() @@ -125,16 +135,16 @@ class TestRouterEnvironment: def test_mysqlrouter_version(self, host): command = "mysqlrouter --version" output = host.check_output(command) - assert "8.0.33" in output + assert ROUTER_VERSION in output def test_mysqlsh_version(self, host): command = "mysqlsh --version" output = host.check_output(command) - assert "8.0.33-25" in output + assert PS_VERSION in output def test_mysqlrouter_directory_permissions(self, host): - assert host.file('/var/lib/mysqlrouter').user == 'mysqlrouter' - assert host.file('/var/lib/mysqlrouter').group == 'mysqlrouter' + 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_mysql_user(self, host): From a4a8d361111495716022eebb5ba429f079d205a1 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 29 Sep 2023 12:12:58 +0530 Subject: [PATCH 11/19] Updating Host configuration --- .../tests/test_router_static.py | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index d34a472ca..a45b411cf 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -10,6 +10,7 @@ import docker container_name = 'mysql-router-test' +container_name_mysql_router = 'mysql-router' network_name = 'innodbnet1' docker_tag = os.getenv('ROUTER_VERSION') docker_acc = os.getenv('DOCKER_ACC') @@ -112,24 +113,16 @@ def router_bootstrap(): docker_restart() create_cluster() add_slave() -router_bootstrap() +router_bootstrap() -# Get the Docker ID of the running container -docker_id = subprocess.check_output(['sudo', 'docker', 'ps', '-q', '--filter', f'name={container_name}']).decode().strip() - -# Define the pytest fixture to provide the host identifier -@pytest.fixture(scope='module') -def host(): - yield docker_id - -# Create an instance of the Host class -class Host: - def check_output(self, command): - result = subprocess.run(['docker', 'exec', docker_id, 'bash', '-c', command], capture_output=True, text=True) - return result.stdout.strip() - -# Instantiate an instance of the Host class -host = Host() +def get_docker_id(container_name_mysql_router): + try: + command = f'docker ps --filter "name={container_name_mysql_router}" --format "{{.ID}}"' + docker_id = subprocess.check_output(command, shell=True).decode().strip() + return docker_id + except subprocess.CalledProcessError as e: + print(f"Error: {e}") + return None class TestRouterEnvironment: def test_mysqlrouter_version(self, host): @@ -158,3 +151,15 @@ def test_mysql_user(self, host): print(f"Username: {mysql_user.name}, UID: {mysql_user.uid}") assert mysql_user.exists assert mysql_user.uid == 1001 + + def test_mysqlrouter_ports(self, host): + host.socket("tcp://6446").is_listening + host.socket("tcp://6447").is_listening + host.socket("tcp://64460").is_listening + host.socket("tcp://64470").is_listening + + def test_mysqlrouter_config(self, host): + assert host.file("/etc/mysqlrouter/mysqlrouter.conf").exists + assert host.file("/etc/mysqlrouter/mysqlrouter.conf").user == "root" + assert host.file("/etc/mysqlrouter/mysqlrouter.conf").group == "root" + assert oct(host.file("/etc/mysqlrouter/mysqlrouter.conf").mode) == "0o644" From 2df0e799f0c8c0811007fa6d34b594a90ec5cb1d Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 29 Sep 2023 13:31:37 +0530 Subject: [PATCH 12/19] remove sudo --- .../tests/test_router_static.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index a45b411cf..d74d1e380 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -19,7 +19,7 @@ percona_docker_image = docker_acc + "/" + "percona-server" + ":" + ps_version def create_network(): - subprocess.run(['sudo', 'docker', 'network', 'create', 'innodbnet']) + subprocess.run(['docker', 'network', 'create', 'innodbnet']) def create_mysql_config(): for N in range(1, 5): @@ -42,7 +42,7 @@ def create_mysql_config(): def start_mysql_containers(): for N in range(1, 5): subprocess.run([ - 'sudo', 'docker', 'run', '-d', + 'docker', 'run', '-d', f'--name=mysql{N}', f'--hostname=mysql{N}', '--net=innodbnet', @@ -54,7 +54,7 @@ def start_mysql_containers(): def create_new_user(): for N in range(1, 5): subprocess.run([ - 'sudo', 'docker', 'exec', f'mysql{N}', + 'docker', 'exec', f'mysql{N}', 'mysql', '-uroot', '-proot', '-e', "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno'; GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option; FLUSH PRIVILEGES;" ]) @@ -62,7 +62,7 @@ def create_new_user(): def verify_new_user(): for N in range(1, 5): subprocess.run([ - 'sudo', 'docker', 'exec', f'mysql{N}', + 'docker', 'exec', f'mysql{N}', 'mysql', '-uinno', '-pinno', '-e', "SHOW VARIABLES WHERE Variable_name = 'hostname';" '-e', "SELECT user FROM mysql.user where user = 'inno';" @@ -70,31 +70,31 @@ def verify_new_user(): time.sleep(30) def docker_restart(): - subprocess.run(['sudo', 'docker', 'restart', 'mysql1', 'mysql2', 'mysql3', 'mysql4']) + subprocess.run(['docker', 'restart', 'mysql1', 'mysql2', 'mysql3', 'mysql4']) time.sleep(10) def create_cluster(): subprocess.run([ - 'sudo', 'docker', 'exec', 'mysql1', + 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'dba', 'create-cluster', 'testCluster' ]) def add_slave(): subprocess.run([ - 'sudo', 'docker', 'exec', 'mysql1', + 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql3', '--recoveryMethod=incremental' ]) time.sleep(10) subprocess.run([ - 'sudo', 'docker', 'exec', 'mysql1', + 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=incremental' ]) def router_bootstrap(): subprocess.run([ - 'sudo', 'docker', 'run', '-d', + 'docker', 'run', '-d', '--name', 'mysql-router', '--net=innodbnet', '-e', 'MYSQL_HOST=mysql1', From 952d9da1831e14fcf803945a9f37a5e8717d2458 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Wed, 4 Oct 2023 11:55:30 +0530 Subject: [PATCH 13/19] Testing host --- .../tests/test_router_static.py | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index d74d1e380..5a44feb8f 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -92,8 +92,9 @@ def add_slave(): 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=incremental' ]) -def router_bootstrap(): - subprocess.run([ +@pytest.fixture(scope='module') +def inspect_data(): + dockerid = subprocess.check_output([ 'docker', 'run', '-d', '--name', 'mysql-router', '--net=innodbnet', @@ -103,7 +104,11 @@ def router_bootstrap(): '-e', 'MYSQL_PASSWORD=inno', '-e', 'MYSQL_INNODB_CLUSTER_MEMBERS=4', router_docker_image - ]) + ]).decode().strip() + inspect_data = json.loads(subprocess.check_output(['docker','inspect','mysql-router'])) + yield inspect_data[0] + subprocess.check_call(['docker', 'rm', '-f', docker_id]) + create_network() create_mysql_config() @@ -113,16 +118,7 @@ def router_bootstrap(): docker_restart() create_cluster() add_slave() -router_bootstrap() - -def get_docker_id(container_name_mysql_router): - try: - command = f'docker ps --filter "name={container_name_mysql_router}" --format "{{.ID}}"' - docker_id = subprocess.check_output(command, shell=True).decode().strip() - return docker_id - except subprocess.CalledProcessError as e: - print(f"Error: {e}") - return None +inspect_data() class TestRouterEnvironment: def test_mysqlrouter_version(self, host): From 2fe22b1dc9999356c182ee83c649f8ae901e390b Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 5 Jul 2024 11:56:59 +0530 Subject: [PATCH 14/19] update --- .../tests/test_router_static.py | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 5a44feb8f..937971379 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -1,25 +1,21 @@ #!/usr/bin/env python3 -import pytest import subprocess -import testinfra import time -from settings import * import json import os -import requests -import docker +import pytest +import testinfra -container_name = 'mysql-router-test' container_name_mysql_router = 'mysql-router' -network_name = 'innodbnet1' +network_name = 'innodbnet' docker_tag = os.getenv('ROUTER_VERSION') docker_acc = os.getenv('DOCKER_ACC') ps_version = os.getenv('PS_VERSION') -router_docker_image = docker_acc + "/" + "percona-mysql-router" + ":" + docker_tag -percona_docker_image = docker_acc + "/" + "percona-server" + ":" + ps_version +router_docker_image = f"{docker_acc}/percona-mysql-router:{docker_tag}" +percona_docker_image = f"{docker_acc}/percona-server:{ps_version}" def create_network(): - subprocess.run(['docker', 'network', 'create', 'innodbnet']) + subprocess.run(['docker', 'network', 'create', network_name], check=True) def create_mysql_config(): for N in range(1, 5): @@ -46,9 +42,9 @@ def start_mysql_containers(): f'--name=mysql{N}', f'--hostname=mysql{N}', '--net=innodbnet', - '-v', f'my{N}.cnf:/etc/my.cnf', + '-v', f"{os.getcwd()}/my{N}.cnf:/etc/my.cnf", '-e', 'MYSQL_ROOT_PASSWORD=root', percona_docker_image - ]) + ], check=True) time.sleep(60) def create_new_user(): @@ -57,46 +53,46 @@ def create_new_user(): 'docker', 'exec', f'mysql{N}', 'mysql', '-uroot', '-proot', '-e', "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno'; GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option; FLUSH PRIVILEGES;" - ]) + ], check=True) def verify_new_user(): for N in range(1, 5): subprocess.run([ 'docker', 'exec', f'mysql{N}', 'mysql', '-uinno', '-pinno', - '-e', "SHOW VARIABLES WHERE Variable_name = 'hostname';" - '-e', "SELECT user FROM mysql.user where user = 'inno';" - ]) + '-e', "SHOW VARIABLES WHERE Variable_name = 'hostname';", + '-e', "SELECT user FROM mysql.user WHERE user = 'inno';" + ], check=True) time.sleep(30) def docker_restart(): - subprocess.run(['docker', 'restart', 'mysql1', 'mysql2', 'mysql3', 'mysql4']) + subprocess.run(['docker', 'restart', 'mysql1', 'mysql2', 'mysql3', 'mysql4'], check=True) time.sleep(10) def create_cluster(): subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'dba', 'create-cluster', 'testCluster' - ]) + ], check=True) def add_slave(): subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql3', '--recoveryMethod=incremental' - ]) + ], check=True) time.sleep(10) subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=incremental' - ]) + ], check=True) @pytest.fixture(scope='module') def inspect_data(): - dockerid = subprocess.check_output([ + docker_id = subprocess.check_output([ 'docker', 'run', '-d', - '--name', 'mysql-router', + '--name', container_name_mysql_router, '--net=innodbnet', '-e', 'MYSQL_HOST=mysql1', '-e', 'MYSQL_PORT=3306', @@ -105,7 +101,7 @@ def inspect_data(): '-e', 'MYSQL_INNODB_CLUSTER_MEMBERS=4', router_docker_image ]).decode().strip() - inspect_data = json.loads(subprocess.check_output(['docker','inspect','mysql-router'])) + inspect_data = json.loads(subprocess.check_output(['docker','inspect', container_name_mysql_router])) yield inspect_data[0] subprocess.check_call(['docker', 'rm', '-f', docker_id]) @@ -118,30 +114,23 @@ def inspect_data(): docker_restart() create_cluster() add_slave() -inspect_data() class TestRouterEnvironment: def test_mysqlrouter_version(self, host): command = "mysqlrouter --version" output = host.check_output(command) - assert ROUTER_VERSION in output + assert docker_tag in output def test_mysqlsh_version(self, host): command = "mysqlsh --version" output = host.check_output(command) - assert PS_VERSION in output + assert ps_version in output def test_mysqlrouter_directory_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_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_user(self, host): mysql_user = host.user('mysql') print(f"Username: {mysql_user.name}, UID: {mysql_user.uid}") @@ -158,4 +147,4 @@ def test_mysqlrouter_config(self, host): assert host.file("/etc/mysqlrouter/mysqlrouter.conf").exists assert host.file("/etc/mysqlrouter/mysqlrouter.conf").user == "root" assert host.file("/etc/mysqlrouter/mysqlrouter.conf").group == "root" - assert oct(host.file("/etc/mysqlrouter/mysqlrouter.conf").mode) == "0o644" + assert oct(host.file("/etc/mysqlrouter/mysqlrouter.conf").mode) == "0o644" From 143000c0c46e1bf98d419531b3added98ea4952f Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 5 Jul 2024 12:09:36 +0530 Subject: [PATCH 15/19] update --- .../percona-mysql-router/tests/test_router_static.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 937971379..2f9ff6045 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -79,13 +79,13 @@ def add_slave(): subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', - 'cluster', 'add-instance', '--uri=inno@mysql3', '--recoveryMethod=incremental' + 'cluster', 'add-instance', '--uri=inno@mysql3', '--recoveryMethod=clone' ], check=True) time.sleep(10) subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', - 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=incremental' + 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=clone' ], check=True) @pytest.fixture(scope='module') From 31a0670f1a31d02b1705a1eca07428c3184efe0c Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 5 Jul 2024 12:44:09 +0530 Subject: [PATCH 16/19] update --- .../tests/test_router_static.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 2f9ff6045..d2b93ca7f 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -88,24 +88,6 @@ def add_slave(): 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=clone' ], check=True) -@pytest.fixture(scope='module') -def inspect_data(): - docker_id = subprocess.check_output([ - 'docker', 'run', '-d', - '--name', container_name_mysql_router, - '--net=innodbnet', - '-e', 'MYSQL_HOST=mysql1', - '-e', 'MYSQL_PORT=3306', - '-e', 'MYSQL_USER=inno', - '-e', 'MYSQL_PASSWORD=inno', - '-e', 'MYSQL_INNODB_CLUSTER_MEMBERS=4', - router_docker_image - ]).decode().strip() - inspect_data = json.loads(subprocess.check_output(['docker','inspect', container_name_mysql_router])) - yield inspect_data[0] - subprocess.check_call(['docker', 'rm', '-f', docker_id]) - - create_network() create_mysql_config() start_mysql_containers() From 3e0b86620d38e13da22c3fbb94bfa460e224b988 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 5 Jul 2024 12:55:18 +0530 Subject: [PATCH 17/19] update --- .../percona-mysql-router/tests/test_router_static.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index d2b93ca7f..39a7535a0 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -76,6 +76,12 @@ def create_cluster(): ], check=True) def add_slave(): + subprocess.run([ + 'docker', 'exec', 'mysql1', + 'mysqlsh', '-uinno', '-pinno', '--', + 'cluster', 'add-instance', '--uri=inno@mysql2', '--recoveryMethod=clone' + ], check=True) + time.sleep(10) subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', @@ -87,6 +93,7 @@ def add_slave(): 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql4', '--recoveryMethod=clone' ], check=True) + time.sleep(120) create_network() create_mysql_config() From 6ff45e91b2c22823e58e9b593ba7a0f021120781 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 5 Jul 2024 13:10:45 +0530 Subject: [PATCH 18/19] update --- .../percona-mysql-router/tests/test_router_static.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index 39a7535a0..b7e7c4cbc 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -81,13 +81,13 @@ def add_slave(): 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql2', '--recoveryMethod=clone' ], check=True) - time.sleep(10) + time.sleep(120) subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', 'cluster', 'add-instance', '--uri=inno@mysql3', '--recoveryMethod=clone' ], check=True) - time.sleep(10) + time.sleep(120) subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--', From daf1917eb0ce0cbe5714e85082902670fb4dc4a5 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Fri, 5 Jul 2024 18:55:05 +0530 Subject: [PATCH 19/19] update --- .../percona-mysql-router/tests/test_router_static.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-image-tests/percona-mysql-router/tests/test_router_static.py b/docker-image-tests/percona-mysql-router/tests/test_router_static.py index b7e7c4cbc..26cfd9311 100644 --- a/docker-image-tests/percona-mysql-router/tests/test_router_static.py +++ b/docker-image-tests/percona-mysql-router/tests/test_router_static.py @@ -82,6 +82,8 @@ def add_slave(): 'cluster', 'add-instance', '--uri=inno@mysql2', '--recoveryMethod=clone' ], check=True) time.sleep(120) + subprocess.run(['docker', 'exec', mysql2 , 'service', 'mysql', 'restart'], check=True) + shell.options["dba.restartWaitTimeout"] = 300 subprocess.run([ 'docker', 'exec', 'mysql1', 'mysqlsh', '-uinno', '-pinno', '--',