|
6 | 6 | fromsubprocessimportcheck_output |
7 | 7 |
|
8 | 8 | importpytest |
| 9 | +importrequests |
9 | 10 |
|
10 | 11 | importgitlab |
11 | 12 | importgitlab.base |
12 | 13 | fromtests.functionalimporthelpers |
13 | 14 |
|
| 15 | +SLEEP_TIME=20 |
| 16 | + |
14 | 17 |
|
15 | 18 | @pytest.fixture(scope="session") |
16 | 19 | deffixture_dir(test_dir): |
@@ -129,15 +132,30 @@ def check_is_alive(): |
129 | 132 | Return a healthcheck function fixture for the GitLab container spinup. |
130 | 133 | """ |
131 | 134 |
|
132 | | -def_check(container:str,start_time:float)->bool: |
| 135 | +def_check( |
| 136 | +*,container:str,start_time:float,docker_ip:str,docker_port:int |
| 137 | + )->bool: |
133 | 138 | setup_time=time.perf_counter()-start_time |
134 | 139 | minutes,seconds=int(setup_time/60),int(setup_time%60) |
135 | 140 | logging.info( |
136 | 141 | f"Checking if GitLab container is up. " |
137 | 142 | f"Have been checking for{minutes} minute(s),{seconds} seconds ..." |
138 | 143 | ) |
139 | 144 | logs= ["docker","logs",container] |
140 | | -return"gitlab Reconfigured!"incheck_output(logs).decode() |
| 145 | +if"gitlab Reconfigured!"notincheck_output(logs).decode(): |
| 146 | +returnFalse |
| 147 | +logging.info("GitLab has finished reconfiguring.") |
| 148 | +gitlab_url=f"http://{docker_ip}:{docker_port}" |
| 149 | +forcheckin ("health","readiness","liveness"): |
| 150 | +url=f"{gitlab_url}/-/{check}" |
| 151 | +logging.info(f"Checking{check!r} endpoint at:{url}") |
| 152 | +result=requests.get(url) |
| 153 | +ifresult.status_code!=200: |
| 154 | +logging.info(f"{check!r} check did not return 200:{result}") |
| 155 | +returnFalse |
| 156 | +logging.info(f"Sleeping for{SLEEP_TIME}") |
| 157 | +time.sleep(SLEEP_TIME) |
| 158 | +returnTrue |
141 | 159 |
|
142 | 160 | return_check |
143 | 161 |
|
@@ -176,7 +194,12 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_ |
176 | 194 | docker_services.wait_until_responsive( |
177 | 195 | timeout=300, |
178 | 196 | pause=10, |
179 | | -check=lambda:check_is_alive("gitlab-test",start_time=start_time), |
| 197 | +check=lambda:check_is_alive( |
| 198 | +container="gitlab-test", |
| 199 | +start_time=start_time, |
| 200 | +docker_ip=docker_ip, |
| 201 | +docker_port=port, |
| 202 | + ), |
180 | 203 | ) |
181 | 204 | setup_time=time.perf_counter()-start_time |
182 | 205 | minutes,seconds=int(setup_time/60),int(setup_time%60) |
@@ -208,6 +231,7 @@ def gl(gitlab_config): |
208 | 231 | logging.info("Instantiating python-gitlab gitlab.Gitlab instance") |
209 | 232 | instance=gitlab.Gitlab.from_config("local", [gitlab_config]) |
210 | 233 |
|
| 234 | +logging.info("Reset GitLab") |
211 | 235 | reset_gitlab(instance) |
212 | 236 |
|
213 | 237 | returninstance |
|