| 41 | |
| 42 | @retry(stop_max_attempt_number=MAX_RETRIES, wait_fixed=BACKOFF_SECS * 1000) |
| 43 | def create_tunnel(config, origincert_path, random_uuid): |
| 44 | # Delete any previous existing credentials file. If the agent keeps files around (that's the case in Windows) then |
| 45 | # cloudflared tunnel create will refuse to create the tunnel because it does not want to overwrite credentials |
| 46 | # files. |
| 47 | credentials_path = config["credentials_file"] |
| 48 | try: |
| 49 | os.remove(credentials_path) |
| 50 | except OSError: |
| 51 | pass |
| 52 | |
| 53 | tunnel_name = "cfd_component_test-" + random_uuid |
| 54 | create_cmd = [config["cloudflared_binary"], "tunnel", "--origincert", origincert_path, "create", |
| 55 | "--credentials-file", credentials_path, tunnel_name] |
| 56 | LOGGER.info(f"Creating tunnel with {create_cmd}") |
| 57 | subprocess.run(create_cmd, check=True) |
| 58 | |
| 59 | list_cmd = [config["cloudflared_binary"], "tunnel", "--origincert", origincert_path, "list", "--name", |
| 60 | tunnel_name, "--output", "json"] |
| 61 | LOGGER.info(f"Listing tunnel with {list_cmd}") |
| 62 | cloudflared = subprocess.run(list_cmd, check=True, capture_output=True) |
| 63 | return json.loads(cloudflared.stdout)[0]["id"] |
| 64 | |
| 65 | |
| 66 | @retry(stop_max_attempt_number=MAX_RETRIES, wait_fixed=BACKOFF_SECS * 1000) |