2323
2424
2525def test_pmm_services ():
26- req = requests .post (f"https://{ pmm_server_url } /v1/inventory/Services/List " , json = {},
26+ req = requests .get (f"https://{ pmm_server_url } /v1/inventory/services " , json = {},
2727 headers = {"authorization" : "Basic YWRtaW46cGFzc3dvcmQ=" }, verify = False )
2828 print ('\n Getting all mongodb services:' )
2929 mongodb = req .json ()['mongodb' ]
3030 print (mongodb )
3131 assert mongodb
32- assert "service_id" in mongodb [0 ][ 'service_id' ]
32+ assert "service_id" in mongodb [0 ]
3333 for service in mongodb :
3434 assert "rs" or "mongos" in service ['service_name' ]
3535 if not "mongos" in service ['service_name' ]:
@@ -49,11 +49,11 @@ def test_pmm_add_location():
4949 'bucket_name' : 'bcp'
5050 }
5151 }
52- req = requests .post (f"https://{ pmm_server_url } /v1/management/backup/Locations/Add " , json = data ,
52+ req = requests .post (f"https://{ pmm_server_url } /v1/backups/locations " , json = data ,
5353 headers = {"authorization" : "Basic YWRtaW46cGFzc3dvcmQ=" }, verify = False )
5454 print ('\n Adding new location:' )
5555 print (req .json ())
56- assert "location_id" in req .json ()[ 'location_id' ]
56+ assert "location_id" in req .json ()
5757 pytest .location_id = req .json ()['location_id' ]
5858
5959
@@ -64,21 +64,23 @@ def test_pmm_logical_backup():
6464 'name' : 'test' ,
6565 'description' : 'test' ,
6666 'retries' : 0 ,
67- 'data_model' : 'LOGICAL '
67+ 'data_model' : 'DATA_MODEL_LOGICAL '
6868 }
69- req = requests .post (f"https://{ pmm_server_url } /v1/management/backup/Backups/Start" , json = data ,
69+
70+ print (data )
71+ req = requests .post (f"https://{ pmm_server_url } /v1/backups:start" , json = data ,
7072 headers = {"authorization" : "Basic YWRtaW46cGFzc3dvcmQ=" }, verify = False )
7173 print ('\n Creating logical backup:' )
7274 print (req .json ())
73- assert "artifact_id" in req .json ()[ 'artifact_id' ]
75+ assert "artifact_id" in req .json ()
7476 pytest .artifact_id = req .json ()['artifact_id' ]
7577
7678
7779def test_pmm_artifact ():
7880 backup_complete = False
7981 for i in range (600 ):
8082 done = False
81- req = requests .post (f"https://{ pmm_server_url } /v1/management/backup/Artifacts/List " , json = {},
83+ req = requests .get (f"https://{ pmm_server_url } /v1/backups/artifacts " , json = {},
8284 headers = {"authorization" : "Basic YWRtaW46cGFzc3dvcmQ=" }, verify = False )
8385 assert req .json ()['artifacts' ]
8486 for artifact in req .json ()['artifacts' ]:
@@ -118,11 +120,11 @@ def test_pmm_start_restore():
118120 'service_id' : pytest .service_id ,
119121 'artifact_id' : pytest .artifact_id
120122 }
121- req = requests .post (f"https://{ pmm_server_url } /v1/management/backup/Backups/Restore " , json = data ,
123+ req = requests .post (f"https://{ pmm_server_url } /v1/backups/restores:start " , json = data ,
122124 headers = {"authorization" : "Basic YWRtaW46cGFzc3dvcmQ=" }, verify = False )
123125 print ('\n Restoring logical backup:' )
124126 print (req .json ())
125- assert "restore_id" in req .json ()[ 'restore_id' ]
127+ assert "restore_id" in req .json ()
126128 pytest .restore_id = req .json ()['restore_id' ]
127129
128130
@@ -132,7 +134,7 @@ def test_pmm_restore():
132134 restore_complete = False
133135 for i in range (600 ):
134136 done = False
135- req = requests .post (f"https://{ pmm_server_url } /v1/management/backup/RestoreHistory/List " , json = {},
137+ req = requests .get (f"https://{ pmm_server_url } /v1/backups/restores " , json = {},
136138 headers = {"authorization" : "Basic YWRtaW46cGFzc3dvcmQ=" }, verify = False )
137139 assert req .json ()['items' ]
138140 for item in req .json ()['items' ]:
@@ -166,3 +168,27 @@ def test_pbm_restore():
166168 restore_complete = True
167169
168170 assert restore_complete
171+
172+ def test_metrics ():
173+ pmm_admin_list = json .loads (docker_rs101 .check_output ('pmm-admin list --json' , timeout = 30 ))
174+ for agent in pmm_admin_list ['agent' ]:
175+ if agent ['agent_type' ] == 'AGENT_TYPE_MONGODB_EXPORTER' :
176+ agent_id = agent ['agent_id' ]
177+ agent_port = agent ['port' ]
178+ break
179+ try :
180+ command = f"curl -s http://pmm:{ agent_id } @127.0.0.1:{ agent_port } /metrics"
181+ metrics = docker_rs101 .run (command , timeout = 30 )
182+ assert metrics .exit_status == 0 , f"Curl command failed with exit status { metrics .exit_status } "
183+ except Exception as e :
184+ pytest .fail (f"Fail to get metrics from exporter" )
185+
186+ try :
187+ with open ("expected_metrics.txt" , "r" ) as f :
188+ expected_metrics = {line .strip () for line in f if line .strip ()}
189+ except FileNotFoundError :
190+ pytest .fail ("Expected metrics file not found" )
191+
192+ for metric in expected_metrics :
193+ if metric not in metrics .stdout :
194+ pytest .fail (f"Metric '{ metric } ' is missing from the exporter output" )
0 commit comments