@@ -112,24 +112,16 @@ def router_bootstrap():
112112docker_restart ()
113113create_cluster ()
114114add_slave ()
115- router_bootstrap ()
115+ router_bootstrap ()
116116
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 ()
117+ def get_docker_id (container_name ):
118+ try :
119+ command = f'docker ps --filter "name=mysq-router" --format "{{.ID}}"'
120+ docker_id = subprocess .check_output (command , shell = True ).decode ().strip ()
121+ return docker_id
122+ except subprocess .CalledProcessError as e :
123+ print (f"Error: { e } " )
124+ return None
133125
134126class TestRouterEnvironment :
135127 def test_mysqlrouter_version (self , host ):
@@ -158,3 +150,15 @@ def test_mysql_user(self, host):
158150 print (f"Username: { mysql_user .name } , UID: { mysql_user .uid } " )
159151 assert mysql_user .exists
160152 assert mysql_user .uid == 1001
153+
154+ def test_mysqlrouter_ports (self , host ):
155+ host .socket ("tcp://6446" ).is_listening
156+ host .socket ("tcp://6447" ).is_listening
157+ host .socket ("tcp://64460" ).is_listening
158+ host .socket ("tcp://64470" ).is_listening
159+
160+ def test_mysqlrouter_config (self , host ):
161+ assert host .file ("/etc/mysqlrouter/mysqlrouter.conf" ).exists
162+ assert host .file ("/etc/mysqlrouter/mysqlrouter.conf" ).user == "root"
163+ assert host .file ("/etc/mysqlrouter/mysqlrouter.conf" ).group == "root"
164+ assert oct (host .file ("/etc/mysqlrouter/mysqlrouter.conf" ).mode ) == "0o644"
0 commit comments