Skip to content

Commit

Permalink
Use topaz config info to set up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenh committed Jul 3, 2024
1 parent 8724007 commit abecebc
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from dataclasses import dataclass
from datetime import datetime, timedelta
import json
import os.path
import subprocess
import time
from typing import Optional

import grpc
import pytest
import requests


@dataclass(frozen=True)
Expand All @@ -22,7 +22,6 @@ class Service:
class Topaz:
authorizer: Service
directory_grpc: Service
directory_gw: Service

@staticmethod
def start() -> None:
Expand Down Expand Up @@ -81,11 +80,6 @@ def wait_for_ready(self) -> None:
def topaz():
Topaz.stop()

topaz_db_dir = os.path.expanduser("~/.config/topaz/db")

if os.path.exists(f"{topaz_db_dir}/directory.db"):
os.rename(f"{topaz_db_dir}/directory.db", f"{topaz_db_dir}/directory.bak")

svc = topaz_configure()
svc.start()
svc.wait_for_ready()
Expand All @@ -99,9 +93,6 @@ def topaz():

time.sleep(1)

if os.path.exists(f"{topaz_db_dir}/directory.bak"):
os.rename(f"{topaz_db_dir}/directory.bak", f"{topaz_db_dir}/directory.db")


def topaz_configure() -> Topaz:
subprocess.run(
Expand All @@ -111,25 +102,35 @@ def topaz_configure() -> Topaz:
check=True,
)

cert_path = topaz_cert_path()
ca_cert_path_grpc = os.path.join(cert_path, "grpc-ca.crt")
ca_cert_path_gw = os.path.join(cert_path, "gateway-ca.crt")
subprocess.run(
"topaz config use todo",
shell=True,
capture_output=True,
check=True,
)

return Topaz(
authorizer=Service("localhost:8282", ca_cert_path=ca_cert_path_grpc),
directory_grpc=Service("localhost:9292", ca_cert_path=ca_cert_path_grpc),
directory_gw=Service("localhost:9393", ca_cert_path=ca_cert_path_gw),
config = json.loads(
subprocess.run(
"topaz config info",
shell=True,
capture_output=True,
check=True,
)
.stdout.decode()
.strip()
)

cert_path = config["config"]["topaz_certs_dir"]
ca_cert_path_grpc = os.path.join(cert_path, "grpc-ca.crt")

def topaz_cert_path() -> str:
proc = subprocess.run(
"topaz config info | jq .config.topaz_certs_dir -r",
shell=True,
check=True,
capture_output=True,
return Topaz(
authorizer=Service(
config["authorizer"]["topaz_authorizer_svc"], ca_cert_path=ca_cert_path_grpc
),
directory_grpc=Service(
config["directory"]["topaz_directory_svc"], ca_cert_path=ca_cert_path_grpc
),
)
return proc.stdout.decode().strip()


def connect(svc: Service) -> grpc.Channel:
Expand Down

0 comments on commit abecebc

Please sign in to comment.