Skip to content

Commit

Permalink
Move end-to-end tests into chart/directory/tests dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenh committed Nov 25, 2024
1 parent 122ec23 commit 7f333fe
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 38 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ jobs:
chmod +x ./bin/topaz
./bin/topaz version
echo "TOPAZ=$(realpath ./bin/topaz)" >> "$GITHUB_ENV"
echo "TOPAZ_CERTS_DIR=$(./bin/topaz config info | jq '.config.topaz_certs_dir' -r)" >> "$GITHUB_ENV"
-
name: Install topazd container
run: |
${TOPAZ} install --container-tag=${{ env.TOPAZ_VERSION }}
${TOPAZ} version
-
name: Generate topaz certs
run: ${TOPAZ} certs generate
-
name: Install uv package manager
uses: astral-sh/setup-uv@v3
Expand Down Expand Up @@ -112,6 +116,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SSH_PUBLIC_KEY: ${{ steps.sshkey.outputs.public_key }}
SSH_PRIVATE_KEY: ${{ steps.sshkey.outputs.private_key }}
TOPAZ_CERTS_DIR: ${{ env.TOPAZ_CERTS_DIR }}
run: |
cd tools/ktest
uv run ktest.py ../../test/directory/tests.yaml
uv run --project tools/ktest tools/ktest/ktest.py charts/directory/test/tests.yaml
1 change: 1 addition & 0 deletions charts/directory/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@

build/
ci/
test/
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 5 additions & 28 deletions tools/ktest/ktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from model import Deployment, Spec, Test
from namespace import Namespace

logger = logging.getLogger("k3stest")
logger = logging.getLogger(__name__)

COLOR_HARNESS = "blue"
COLOR_STEP = "magenta"
Expand Down Expand Up @@ -120,8 +120,8 @@ def execute_cleanup(self):
echo("🧹", step, cl=COLOR_STEP)
try:
self.subprocess(step)
except:
pass
except Exception as e:
logger.error("cleanup failed: %s", e)

def set_image_pull_secret(self, ns: Namespace):
if self.test.pull_secret:
Expand Down Expand Up @@ -186,33 +186,10 @@ def git_root(from_path: str) -> str:


def init_logging(level=logging.INFO):
loggers = (
logging.getLogger(name)
for name in logging.root.manager.loggerDict
if name.startswith("k3test")
)
for logger in loggers:
init_logger(logger, level)


def init_logger(logger: logging.Logger, level=logging.INFO):
logger.setLevel(level)

# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

# create formatter
formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(name)s - %(message)s"
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", level=level
)

# add formatter to ch
ch.setFormatter(formatter)

# add ch to logger
logger.addHandler(ch)


if __name__ == "__main__":
main()
24 changes: 16 additions & 8 deletions tools/ktest/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from model import ConfigMap, Secret

logger = logging.getLogger("k3test.namespace")
logger = logging.getLogger(__name__)


class Namespace:
Expand Down Expand Up @@ -96,13 +96,21 @@ def forward(self, svc: str, ports: Mapping[int, int]):
yield proc
finally:
logger.debug("terminating port-forward: %s", svc)
proc.terminate()
try:
proc.wait(1)
except subprocess.TimeoutExpired:
logger.info("timeout expired. killing port-forward: %s", svc)
proc.kill()
logger.debug("port-forward terminated: %s", svc)
for stop in (proc.terminate, proc.kill):
logger.debug("attempting to '%s' port-forward: %s", stop.__name__, svc)
stop()
try:
proc.communicate(timeout=3)
# wait for the port to become available again
time.sleep(1.5)
break
except subprocess.TimeoutExpired:
logger.info("timeout expired waiting for: %s", svc)

if proc.returncode is None:
logger.debug("unable to stop port-forwarding: %s", svc)
else:
logger.debug("port-forward terminated: %s", svc)

@lru_cache(maxsize=32)
def svc_pod(self, svc: str) -> str:
Expand Down

0 comments on commit 7f333fe

Please sign in to comment.