|
10 | 10 | import docker |
11 | 11 |
|
12 | 12 | container_name = 'mysql-router-test' |
| 13 | +container_name_mysql_router = 'mysql-router' |
13 | 14 | network_name = 'innodbnet1' |
14 | 15 | docker_tag = os.getenv('ROUTER_VERSION') |
15 | 16 | docker_acc = os.getenv('DOCKER_ACC') |
@@ -112,24 +113,16 @@ def router_bootstrap(): |
112 | 113 | docker_restart() |
113 | 114 | create_cluster() |
114 | 115 | add_slave() |
115 | | -router_bootstrap() |
| 116 | +router_bootstrap() |
116 | 117 |
|
117 | | -# Get the Docker ID of the running container |
118 | | -docker_id = subprocess.check_output(['sudo', 'docker', 'ps', '-q', '--filter', f'name={container_name}']).decode().strip() |
119 | | - |
120 | | -# Define the pytest fixture to provide the host identifier |
121 | | -@pytest.fixture(scope='module') |
122 | | -def host(): |
123 | | - yield docker_id |
124 | | - |
125 | | -# Create an instance of the Host class |
126 | | -class Host: |
127 | | - def check_output(self, command): |
128 | | - result = subprocess.run(['docker', 'exec', docker_id, 'bash', '-c', command], capture_output=True, text=True) |
129 | | - return result.stdout.strip() |
130 | | - |
131 | | -# Instantiate an instance of the Host class |
132 | | -host = Host() |
| 118 | +def get_docker_id(container_name_mysql_router): |
| 119 | + try: |
| 120 | + command = f'docker ps --filter "name={container_name_mysql_router}" --format "{{.ID}}"' |
| 121 | + docker_id = subprocess.check_output(command, shell=True).decode().strip() |
| 122 | + return docker_id |
| 123 | + except subprocess.CalledProcessError as e: |
| 124 | + print(f"Error: {e}") |
| 125 | + return None |
133 | 126 |
|
134 | 127 | class TestRouterEnvironment: |
135 | 128 | def test_mysqlrouter_version(self, host): |
@@ -158,3 +151,15 @@ def test_mysql_user(self, host): |
158 | 151 | print(f"Username: {mysql_user.name}, UID: {mysql_user.uid}") |
159 | 152 | assert mysql_user.exists |
160 | 153 | assert mysql_user.uid == 1001 |
| 154 | + |
| 155 | + def test_mysqlrouter_ports(self, host): |
| 156 | + host.socket("tcp://6446").is_listening |
| 157 | + host.socket("tcp://6447").is_listening |
| 158 | + host.socket("tcp://64460").is_listening |
| 159 | + host.socket("tcp://64470").is_listening |
| 160 | + |
| 161 | + def test_mysqlrouter_config(self, host): |
| 162 | + assert host.file("/etc/mysqlrouter/mysqlrouter.conf").exists |
| 163 | + assert host.file("/etc/mysqlrouter/mysqlrouter.conf").user == "root" |
| 164 | + assert host.file("/etc/mysqlrouter/mysqlrouter.conf").group == "root" |
| 165 | + assert oct(host.file("/etc/mysqlrouter/mysqlrouter.conf").mode) == "0o644" |
0 commit comments