Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): Tidy up python tool #263

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added test/tools/config/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions test/tools/config.py → test/tools/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Config:
def __init__(self):
self.dir = dirname(abspath(__file__))
self.base = dirname(dirname(dirname(abspath(__file__))))
self.base = dirname(dirname(dirname(dirname(abspath(__file__)))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe with pathlib.Path it's more readable:

from pathlib import Path
Suggested change
self.base = dirname(dirname(dirname(dirname(abspath(__file__)))))
self.base = str(Path(abspath(__file__)).parent.parent.parent.parent)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, parents[4] should work too, but then we have to check the length first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe with pathlib.Path it's more readable

maybe, i will add that with my next pr in all the places we do this 👍

self.schema = self.dir + '/schema.yaml'
self.params = {}
self.set_default_config()
Expand Down Expand Up @@ -108,7 +108,7 @@ def default_device_config(self):
}

def default_user_data(self):
files = ["hack/scripts/bootstrap.sh", "test/tools/userdata.sh"]
files = ["hack/scripts/bootstrap.sh", "test/tools/config/userdata.sh"]
userdata = ""
for file in files:
with open(self.base + "/" + file) as f:
Expand Down
File renamed without changes.
File renamed without changes.
Empty file added test/tools/metal/__init__.py
Empty file.
File renamed without changes.
17 changes: 9 additions & 8 deletions test/tools/run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3

from test import Test
from metal import Welder
from config import Config
from test.runner import Test
from metal.welder import Welder
from config.config import Config
import click
import os
import sys
Expand Down Expand Up @@ -48,16 +48,16 @@ def run_e2e(config_file, org_id, project_name, ssh_key_name, device_name, skip_t
click.echo(str(e))
sys.exit()

key_dir = dirname(abspath(__file__)) + '/metal'
if cfg['device']['id'] == None:
click.echo(
f"Running e2e tests. Will create project `{cfg['project_name']}`, ssh_key `{cfg['device']['ssh_key_name']}` and device `{cfg['device']['name']}`")
click.echo(
"Note: this will create and bootstrap a new device in Equinix and may take some time")
else:
tool_dir = dirname(abspath(__file__))
if os.path.exists(tool_dir+"/private.key") != True:
if os.path.exists(key_dir+"/private.key") != True:
click.echo(
f"`private.key` file must be saved at `{tool_dir}` when `--existing-device-id` flag set")
f"`private.key` file must be saved at `{key_dir}` when `--existing-device-id` flag set")
sys.exit()
click.echo("running e2e tests using device `{cfg['device']['id']}`")

Expand All @@ -68,7 +68,7 @@ def run_e2e(config_file, org_id, project_name, ssh_key_name, device_name, skip_t

if cfg['test']['skip_teardown']:
dev_id, dev_ip = runner.device_details()
click.echo(f"Device `{dev_id}` left alive for debugging. Use with `--config-file` setting `device.id` to re-run tests. SSH command `ssh -i test/tools/private.key root@{dev_ip}`. Teardown device with `teardown-device` command.")
click.echo(f"Device `{dev_id}` left alive for debugging. Use with `--config-file` setting `device.id` to re-run tests. SSH command `ssh -i {key_dir}/private.key root@{dev_ip}`. Teardown device with `teardown-device` command.")


@cli.command()
Expand Down Expand Up @@ -105,8 +105,9 @@ def create_device(config_file, org_id, project_id, ssh_key_name, device_name, us
welder = Welder(token, cfg)
ip = welder.create_all()

key_dir = dirname(abspath(__file__)) + '/metal'
click.echo(
f"Device {cfg['device']['name']} created. SSH command `ssh -i test/tools/private.key root@{ip}`. Run tests with `run-e2e`. Teardown with `delete-device`.")
f"Device {cfg['device']['name']} created. SSH command `ssh -i {key_dir}/private.key root@{ip}`. Run tests with `run-e2e`. Teardown with `delete-device`.")


@cli.command()
Expand Down
Empty file added test/tools/test/__init__.py
Empty file.
5 changes: 1 addition & 4 deletions test/tools/test.py → test/tools/test/runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from metal import Welder
from metal.welder import Welder


class Test:
Expand All @@ -7,9 +7,6 @@ def __init__(self, auth_token, config):
devCfg = config['device']

self.welder = Welder(auth_token, config)
self.prj_name = config['project']
self.key_name = devCfg['ssh_key_name']
self.dev_name = devCfg['name']
self.skip_teardown = self.testCfg['skip_teardown']
self.dev_id = devCfg['id']
self.dev_ip = None
Expand Down