Skip to content

Commit

Permalink
chore(test): Tidy up python tool (#263)
Browse files Browse the repository at this point in the history
* Reorganise python code

I don't know whether this is the correct way to structure a python
project, but it was getting a bit messy in that dir so I have moved
things around. Also the Welder package can probably be refactored one day.

* Remove unneeded attributes
  • Loading branch information
Callisto13 authored Nov 16, 2021
1 parent 0413a15 commit 17de35e
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 14 deletions.
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__)))))
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

0 comments on commit 17de35e

Please sign in to comment.