From 17de35eb85ae028612e629d03151b6d153d6f429 Mon Sep 17 00:00:00 2001 From: Claudia Date: Tue, 16 Nov 2021 12:36:51 +0000 Subject: [PATCH] chore(test): Tidy up python tool (#263) * 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 --- test/tools/config/__init__.py | 0 test/tools/{ => config}/config.py | 4 ++-- test/tools/{ => config}/schema.yaml | 0 test/tools/{ => config}/userdata.sh | 0 test/tools/metal/__init__.py | 0 test/tools/{metal.py => metal/welder.py} | 0 test/tools/run.py | 17 +++++++++-------- test/tools/test/__init__.py | 0 test/tools/{test.py => test/runner.py} | 5 +---- 9 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 test/tools/config/__init__.py rename test/tools/{ => config}/config.py (96%) rename test/tools/{ => config}/schema.yaml (100%) rename test/tools/{ => config}/userdata.sh (100%) create mode 100644 test/tools/metal/__init__.py rename test/tools/{metal.py => metal/welder.py} (100%) create mode 100644 test/tools/test/__init__.py rename test/tools/{test.py => test/runner.py} (91%) diff --git a/test/tools/config/__init__.py b/test/tools/config/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/tools/config.py b/test/tools/config/config.py similarity index 96% rename from test/tools/config.py rename to test/tools/config/config.py index 38e2cff2..33a197ad 100644 --- a/test/tools/config.py +++ b/test/tools/config/config.py @@ -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() @@ -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: diff --git a/test/tools/schema.yaml b/test/tools/config/schema.yaml similarity index 100% rename from test/tools/schema.yaml rename to test/tools/config/schema.yaml diff --git a/test/tools/userdata.sh b/test/tools/config/userdata.sh similarity index 100% rename from test/tools/userdata.sh rename to test/tools/config/userdata.sh diff --git a/test/tools/metal/__init__.py b/test/tools/metal/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/tools/metal.py b/test/tools/metal/welder.py similarity index 100% rename from test/tools/metal.py rename to test/tools/metal/welder.py diff --git a/test/tools/run.py b/test/tools/run.py index 443efeee..7fc70ce9 100755 --- a/test/tools/run.py +++ b/test/tools/run.py @@ -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 @@ -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']}`") @@ -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() @@ -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() diff --git a/test/tools/test/__init__.py b/test/tools/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/tools/test.py b/test/tools/test/runner.py similarity index 91% rename from test/tools/test.py rename to test/tools/test/runner.py index 440e326c..f99fe5be 100644 --- a/test/tools/test.py +++ b/test/tools/test/runner.py @@ -1,4 +1,4 @@ -from metal import Welder +from metal.welder import Welder class Test: @@ -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