From d50e2c0d35a32eb305fa506bb9b9f0c2935ccdce Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Fri, 3 Apr 2020 17:09:32 +0200 Subject: [PATCH 01/15] - Running spec tests from Epicli --- core/src/epicli/.vscode/launch.json | 12 +---- core/src/epicli/Dockerfile | 4 +- core/src/epicli/cli/engine/TestEngine.py | 48 +++++++++++++++++++ .../src/epicli/cli/engine/spec/SpecCommand.py | 36 ++++++++++++++ core/src/epicli/cli/epicli.py | 16 +++++++ core/src/epicli/cli/helpers/build_saver.py | 1 + .../common/tests}/.rspec | 0 .../common/tests}/Gemfile | 0 .../common/tests}/Gemfile.lock | 0 .../common/tests}/README.md | 0 .../common/tests}/Rakefile | 7 ++- .../common/tests}/rvm.sh | 0 .../spec/applications/applications_spec.rb | 0 .../applications/auth-service/auth-service.rb | 0 .../ignite-stateless/ignite-stateless.rb | 0 .../spec/applications/rabbitmq/rabbitmq.rb | 0 .../elasticsearch_curator_spec.rb | 0 .../tests}/spec/filebeat/filebeat_spec.rb | 0 .../tests}/spec/grafana/grafana_spec.rb | 0 .../tests}/spec/haproxy/haproxy_spec.rb | 0 .../haproxy_exporter/haproxy_exporter_spec.rb | 0 .../common/tests}/spec/ignite/ignite_spec.rb | 0 .../spec/jmx_exporter/jmx_exporter_spec.rb | 0 .../common/tests}/spec/kafka/kafka_spec.rb | 0 .../kafka_exporter/kafka_exporter_spec.rb | 0 .../common/tests}/spec/kibana/kibana_spec.rb | 0 .../kubernetes_master_spec.rb | 0 .../tests}/spec/logging/logging_spec.rb | 0 .../spec/node_exporter/node_exporter_spec.rb | 0 .../tests}/spec/postgresql/postgresql_spec.rb | 0 .../tests}/spec/prometheus/prometheus_spec.rb | 0 .../tests}/spec/rabbitmq/rabbitmq_spec.rb | 0 .../common/tests}/spec/spec_helper.rb | 0 .../tests}/spec/zookeeper/zookeeper_spec.rb | 0 core/src/epicli/run-tests.py | 16 ------- .../tests/docker/test-ci-epicli/Dockerfile | 9 ---- 36 files changed, 110 insertions(+), 39 deletions(-) create mode 100644 core/src/epicli/cli/engine/TestEngine.py create mode 100644 core/src/epicli/cli/engine/spec/SpecCommand.py rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/.rspec (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/Gemfile (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/Gemfile.lock (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/README.md (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/Rakefile (89%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/rvm.sh (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/applications/applications_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/applications/auth-service/auth-service.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/applications/ignite-stateless/ignite-stateless.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/applications/rabbitmq/rabbitmq.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/elasticsearch_curator/elasticsearch_curator_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/filebeat/filebeat_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/grafana/grafana_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/haproxy/haproxy_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/haproxy_exporter/haproxy_exporter_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/ignite/ignite_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/jmx_exporter/jmx_exporter_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/kafka/kafka_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/kafka_exporter/kafka_exporter_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/kibana/kibana_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/kubernetes_master/kubernetes_master_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/logging/logging_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/node_exporter/node_exporter_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/postgresql/postgresql_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/prometheus/prometheus_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/rabbitmq/rabbitmq_spec.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/spec_helper.rb (100%) rename core/src/epicli/{tests/serverspec-cli => data/common/tests}/spec/zookeeper/zookeeper_spec.rb (100%) delete mode 100644 core/src/epicli/tests/docker/test-ci-epicli/Dockerfile diff --git a/core/src/epicli/.vscode/launch.json b/core/src/epicli/.vscode/launch.json index 0e3a62a4e4..e5181dae49 100644 --- a/core/src/epicli/.vscode/launch.json +++ b/core/src/epicli/.vscode/launch.json @@ -17,6 +17,7 @@ // "args": ["apply", "-f", "${workspaceFolder}/clusters/YOUR_DATA_YAML.yml", "--offline-requirements", "${workspaceFolder}/downloads/epirepo"] // "args": ["delete", "-b", "${workspaceFolder}/clusters/build/dir"] // "args": ["init", "-p", "PROVIDER", "-n", "NAME"] + // "args": ["test", "-b", "${workspaceFolder}/clusters/build/dir"] }, { "name": "python unit tests", @@ -28,17 +29,6 @@ "env": { "PYTHONPATH": "${workspaceFolder}" }, "console": "integratedTerminal", "args": ["python"] - }, - { - "name": "server spec tests", - "type": "python", - "request": "launch", - "program": "${workspaceFolder}/run-tests.py", - "cwd": "${workspaceFolder}", - "pythonPath": "${config:python.pythonPath}", - "env": { "PYTHONPATH": "${workspaceFolder}" }, - "console": "integratedTerminal", - "args": ["spec", "-i", "${workspaceFolder}/PATH_TO_CLUSTER_INVENTORY", "-u", "ADMIN_USER", "-k", "${workspaceFolder}/PATH_TO_SSH_KEY"] } ] } \ No newline at end of file diff --git a/core/src/epicli/Dockerfile b/core/src/epicli/Dockerfile index b02ca6f057..b161cb6276 100644 --- a/core/src/epicli/Dockerfile +++ b/core/src/epicli/Dockerfile @@ -12,7 +12,9 @@ COPY /dist/ /epicli WORKDIR /epicli RUN apt-get update \ - && apt-get -y install gcc make musl-dev libffi-dev tar unzip openssh-client vim + && apt-get -y install gcc make musl-dev libffi-dev tar unzip openssh-client vim \ + && sudo apt-get -y install ruby-full \ + && sudo gem install serverspec rake rspec_junit_formatter RUN pip install epicli-${EPICLI_VERSION}-py3-none-any.whl diff --git a/core/src/epicli/cli/engine/TestEngine.py b/core/src/epicli/cli/engine/TestEngine.py new file mode 100644 index 0000000000..5892f13451 --- /dev/null +++ b/core/src/epicli/cli/engine/TestEngine.py @@ -0,0 +1,48 @@ +import os +import shutil + +from cli.helpers.Step import Step +from cli.helpers.Config import Config +from cli.helpers.build_saver import SPEC_OUTPUT_DIR, MANIFEST_FILE_NAME, ANSIBLE_OUTPUT_DIR, INVENTORY_FILE_NAME +from cli.helpers.data_loader import load_yamls_file +from cli.helpers.doc_list_helpers import select_single +from cli.engine.spec.SpecCommand import SpecCommand + +class TestEngine(Step): + def __init__(self, input_data): + super().__init__(__name__) + self.build_directory = input_data.build_directory + + def __enter__(self): + super().__enter__() + return self + + def __exit__(self, exc_type, exc_value, traceback): + super().__exit__(exc_type, exc_value, traceback) + + def test(self): + # get manifest + path_to_manifest = os.path.join(self.build_directory, MANIFEST_FILE_NAME) + if not os.path.isfile(path_to_manifest): + raise Exception(f'No {MANIFEST_FILE_NAME} inside the build folder') + + # get inventory + path_to_inventory = os.path.join(self.build_directory, INVENTORY_FILE_NAME) + if not os.path.isfile(path_to_inventory): + raise Exception(f'No {INVENTORY_FILE_NAME} inside the build folder') + + # get admin user + docs = load_yamls_file(path_to_manifest) + cluster_model = select_single(docs, lambda x: x.kind == 'epiphany-cluster') + admin_user = cluster_model.specification.admin_user + + # get and create the spec output dir if it does not exist + spec_output = os.path.join(self.build_directory, SPEC_OUTPUT_DIR) + if not os.path.exists(spec_output): + os.makedirs(spec_output) + + # run the spec tests + spec_command = SpecCommand() + spec_command.run(spec_output, path_to_inventory, admin_user.name, admin_user.key_path) + + return 0 \ No newline at end of file diff --git a/core/src/epicli/cli/engine/spec/SpecCommand.py b/core/src/epicli/cli/engine/spec/SpecCommand.py new file mode 100644 index 0000000000..7edb731932 --- /dev/null +++ b/core/src/epicli/cli/engine/spec/SpecCommand.py @@ -0,0 +1,36 @@ +import os +import subprocess + +from cli.helpers.Log import LogPipe, Log +from cli.helpers.Config import Config +from cli.helpers.data_loader import DATA_FOLDER_PATH + + +class SpecCommand: + SPEC_TEST_PATH = DATA_FOLDER_PATH + '/common/tests' + + def __init__(self): + self.logger = Log(__name__) + + def __init__(self): + self.logger = Log(__name__) + + def run(self, spec_output, inventory, user, key): + env = os.environ.copy() + env['spec_output'] = spec_output + env['inventory'] = inventory + env['user'] = user + env['keypath'] = key + + cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:all' + + self.logger.info(f'Running: "{cmd}"') + + logpipe = LogPipe(__name__) + with subprocess.Popen(cmd.split(' '), cwd=self.SPEC_TEST_PATH, env=env, stdout=logpipe, stderr=logpipe, shell=True) as sp: + logpipe.close() + + if sp.returncode != 0: + raise Exception(f'Error running: "{cmd}"') + else: + self.logger.info(f'Done running: "{cmd}"') diff --git a/core/src/epicli/cli/epicli.py b/core/src/epicli/cli/epicli.py index 8c0f643222..223bc8e149 100644 --- a/core/src/epicli/cli/epicli.py +++ b/core/src/epicli/cli/epicli.py @@ -16,6 +16,7 @@ from cli.engine.InitEngine import InitEngine from cli.engine.PrepareEngine import PrepareEngine from cli.engine.UpgradeEngine import UpgradeEngine +from cli.engine.TestEngine import TestEngine from cli.helpers.Log import Log from cli.helpers.Config import Config from cli.version import VERSION @@ -88,6 +89,7 @@ def debug_level(x): apply_parser(subparsers) upgrade_parser(subparsers) delete_parser(subparsers) + test_parser(subparsers) ''' validate_parser(subparsers) @@ -219,6 +221,20 @@ def run_upgrade(args): sub_parser.set_defaults(func=run_upgrade) +def test_parser(subparsers): + sub_parser = subparsers.add_parser('test', description='Test a cluster from build artifacts.') + sub_parser.add_argument('-b', '--build', dest='build_directory', type=str, required=True, + help='Absolute path to directory with build artifacts.') + + def run_test(args): + experimental_query() + adjust_paths_from_build(args) + with TestEngine(args) as engine: + return engine.test() + + sub_parser.set_defaults(func=run_test) + + ''' def validate_parser(subparsers): sub_parser = subparsers.add_parser('verify', description='Validates the configuration from file by executing a dry ' diff --git a/core/src/epicli/cli/helpers/build_saver.py b/core/src/epicli/cli/helpers/build_saver.py index 1abf992719..ed2eefb333 100644 --- a/core/src/epicli/cli/helpers/build_saver.py +++ b/core/src/epicli/cli/helpers/build_saver.py @@ -14,6 +14,7 @@ INVENTORY_FILE_NAME = 'inventory' ANSIBLE_OUTPUT_DIR = 'ansible/' ANSIBLE_VAULT_OUTPUT_DIR = 'vault/' +SPEC_OUTPUT_DIR = 'spec/' BUILD_EPICLI = 'BUILD_EPICLI' BUILD_LEGACY = 'BUILD_LEGACY_02X' diff --git a/core/src/epicli/tests/serverspec-cli/.rspec b/core/src/epicli/data/common/tests/.rspec similarity index 100% rename from core/src/epicli/tests/serverspec-cli/.rspec rename to core/src/epicli/data/common/tests/.rspec diff --git a/core/src/epicli/tests/serverspec-cli/Gemfile b/core/src/epicli/data/common/tests/Gemfile similarity index 100% rename from core/src/epicli/tests/serverspec-cli/Gemfile rename to core/src/epicli/data/common/tests/Gemfile diff --git a/core/src/epicli/tests/serverspec-cli/Gemfile.lock b/core/src/epicli/data/common/tests/Gemfile.lock similarity index 100% rename from core/src/epicli/tests/serverspec-cli/Gemfile.lock rename to core/src/epicli/data/common/tests/Gemfile.lock diff --git a/core/src/epicli/tests/serverspec-cli/README.md b/core/src/epicli/data/common/tests/README.md similarity index 100% rename from core/src/epicli/tests/serverspec-cli/README.md rename to core/src/epicli/data/common/tests/README.md diff --git a/core/src/epicli/tests/serverspec-cli/Rakefile b/core/src/epicli/data/common/tests/Rakefile similarity index 89% rename from core/src/epicli/tests/serverspec-cli/Rakefile rename to core/src/epicli/data/common/tests/Rakefile index 9aba62a412..176d1b62e8 100644 --- a/core/src/epicli/tests/serverspec-cli/Rakefile +++ b/core/src/epicli/data/common/tests/Rakefile @@ -19,7 +19,10 @@ unless ENV['keypath'] exit end - +unless ENV['spec_output'] + print "ERROR: Private key path must be specified by 'spec_output' environment variable\n" + exit +end groups = {} hosts = [] @@ -73,7 +76,7 @@ namespace :spec do t.pattern = "spec/#{group}/*_spec.rb" t.fail_on_error = false t.rspec_opts = "--format documentation --format RspecJunitFormatter \ - --out results/" + Time.now.strftime("%Y-%m-%d_%H-%M-%S") + "_#{group}_#{groups[group][host]}.xml" + --out " + ENV['spec_output'] + Time.now.strftime("%Y-%m-%d_%H-%M-%S") + "_#{group}_#{groups[group][host]}.xml" end end end diff --git a/core/src/epicli/tests/serverspec-cli/rvm.sh b/core/src/epicli/data/common/tests/rvm.sh similarity index 100% rename from core/src/epicli/tests/serverspec-cli/rvm.sh rename to core/src/epicli/data/common/tests/rvm.sh diff --git a/core/src/epicli/tests/serverspec-cli/spec/applications/applications_spec.rb b/core/src/epicli/data/common/tests/spec/applications/applications_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/applications/applications_spec.rb rename to core/src/epicli/data/common/tests/spec/applications/applications_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/applications/auth-service/auth-service.rb b/core/src/epicli/data/common/tests/spec/applications/auth-service/auth-service.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/applications/auth-service/auth-service.rb rename to core/src/epicli/data/common/tests/spec/applications/auth-service/auth-service.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/applications/ignite-stateless/ignite-stateless.rb b/core/src/epicli/data/common/tests/spec/applications/ignite-stateless/ignite-stateless.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/applications/ignite-stateless/ignite-stateless.rb rename to core/src/epicli/data/common/tests/spec/applications/ignite-stateless/ignite-stateless.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/applications/rabbitmq/rabbitmq.rb b/core/src/epicli/data/common/tests/spec/applications/rabbitmq/rabbitmq.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/applications/rabbitmq/rabbitmq.rb rename to core/src/epicli/data/common/tests/spec/applications/rabbitmq/rabbitmq.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/elasticsearch_curator/elasticsearch_curator_spec.rb b/core/src/epicli/data/common/tests/spec/elasticsearch_curator/elasticsearch_curator_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/elasticsearch_curator/elasticsearch_curator_spec.rb rename to core/src/epicli/data/common/tests/spec/elasticsearch_curator/elasticsearch_curator_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/filebeat/filebeat_spec.rb b/core/src/epicli/data/common/tests/spec/filebeat/filebeat_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/filebeat/filebeat_spec.rb rename to core/src/epicli/data/common/tests/spec/filebeat/filebeat_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/grafana/grafana_spec.rb b/core/src/epicli/data/common/tests/spec/grafana/grafana_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/grafana/grafana_spec.rb rename to core/src/epicli/data/common/tests/spec/grafana/grafana_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/haproxy/haproxy_spec.rb b/core/src/epicli/data/common/tests/spec/haproxy/haproxy_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/haproxy/haproxy_spec.rb rename to core/src/epicli/data/common/tests/spec/haproxy/haproxy_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/haproxy_exporter/haproxy_exporter_spec.rb b/core/src/epicli/data/common/tests/spec/haproxy_exporter/haproxy_exporter_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/haproxy_exporter/haproxy_exporter_spec.rb rename to core/src/epicli/data/common/tests/spec/haproxy_exporter/haproxy_exporter_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/ignite/ignite_spec.rb b/core/src/epicli/data/common/tests/spec/ignite/ignite_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/ignite/ignite_spec.rb rename to core/src/epicli/data/common/tests/spec/ignite/ignite_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/jmx_exporter/jmx_exporter_spec.rb b/core/src/epicli/data/common/tests/spec/jmx_exporter/jmx_exporter_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/jmx_exporter/jmx_exporter_spec.rb rename to core/src/epicli/data/common/tests/spec/jmx_exporter/jmx_exporter_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/kafka/kafka_spec.rb b/core/src/epicli/data/common/tests/spec/kafka/kafka_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/kafka/kafka_spec.rb rename to core/src/epicli/data/common/tests/spec/kafka/kafka_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/kafka_exporter/kafka_exporter_spec.rb b/core/src/epicli/data/common/tests/spec/kafka_exporter/kafka_exporter_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/kafka_exporter/kafka_exporter_spec.rb rename to core/src/epicli/data/common/tests/spec/kafka_exporter/kafka_exporter_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/kibana/kibana_spec.rb b/core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/kibana/kibana_spec.rb rename to core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/kubernetes_master/kubernetes_master_spec.rb b/core/src/epicli/data/common/tests/spec/kubernetes_master/kubernetes_master_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/kubernetes_master/kubernetes_master_spec.rb rename to core/src/epicli/data/common/tests/spec/kubernetes_master/kubernetes_master_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/logging/logging_spec.rb b/core/src/epicli/data/common/tests/spec/logging/logging_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/logging/logging_spec.rb rename to core/src/epicli/data/common/tests/spec/logging/logging_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/node_exporter/node_exporter_spec.rb b/core/src/epicli/data/common/tests/spec/node_exporter/node_exporter_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/node_exporter/node_exporter_spec.rb rename to core/src/epicli/data/common/tests/spec/node_exporter/node_exporter_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/postgresql/postgresql_spec.rb b/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/postgresql/postgresql_spec.rb rename to core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/prometheus/prometheus_spec.rb b/core/src/epicli/data/common/tests/spec/prometheus/prometheus_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/prometheus/prometheus_spec.rb rename to core/src/epicli/data/common/tests/spec/prometheus/prometheus_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/rabbitmq/rabbitmq_spec.rb b/core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/rabbitmq/rabbitmq_spec.rb rename to core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/spec_helper.rb b/core/src/epicli/data/common/tests/spec/spec_helper.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/spec_helper.rb rename to core/src/epicli/data/common/tests/spec/spec_helper.rb diff --git a/core/src/epicli/tests/serverspec-cli/spec/zookeeper/zookeeper_spec.rb b/core/src/epicli/data/common/tests/spec/zookeeper/zookeeper_spec.rb similarity index 100% rename from core/src/epicli/tests/serverspec-cli/spec/zookeeper/zookeeper_spec.rb rename to core/src/epicli/data/common/tests/spec/zookeeper/zookeeper_spec.rb diff --git a/core/src/epicli/run-tests.py b/core/src/epicli/run-tests.py index 60955279b9..a62e57b894 100644 --- a/core/src/epicli/run-tests.py +++ b/core/src/epicli/run-tests.py @@ -13,7 +13,6 @@ def main(): subparsers = parser.add_subparsers() python_parser(subparsers) - spec_parser(subparsers) arg = parser.parse_args() return arg.func(arg) @@ -28,20 +27,5 @@ def run_python(args): sub_parser.set_defaults(func=run_python) -def spec_parser(subparsers): - sub_parser = subparsers.add_parser('spec', description='Runs the serverspec tests against an existing cluster') - sub_parser.add_argument('-i', '--inventory', dest='inventory', type=str, required=True, - help='The location of the inventory file of the cluster') - sub_parser.add_argument('-u', '--user', dest='user', type=str, required=True, - help='The admin user of the machines in the cluster') - sub_parser.add_argument('-k', '--key', dest='key', type=str, required=True, - help='The SSH key for the machines in the cluster') - - def run_spec(args): - subprocess.call(f'cd tests/serverspec-cli && rake inventory="{args.inventory}" user={args.user} keypath="{args.key}" spec:all', shell=True) - - sub_parser.set_defaults(func=run_spec) - - if __name__ == '__main__': exit(main()) diff --git a/core/src/epicli/tests/docker/test-ci-epicli/Dockerfile b/core/src/epicli/tests/docker/test-ci-epicli/Dockerfile deleted file mode 100644 index f2ed6b391d..0000000000 --- a/core/src/epicli/tests/docker/test-ci-epicli/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -ARG BUILD_ID - -FROM epicli:$BUILD_ID - -RUN sudo apt-get update \ -&& sudo apt-get -y install ruby-full \ -&& sudo gem install serverspec rake rspec_junit_formatter - -COPY --chown=epiuser:epiuser tests/serverspec-cli/ /serverspec From 3a3b8e682306f99f0073115c24d46276420340b9 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Fri, 3 Apr 2020 19:15:00 +0200 Subject: [PATCH 02/15] Minor additions. --- core/src/epicli/cli/engine/TestEngine.py | 3 ++- core/src/epicli/cli/engine/spec/SpecCommand.py | 17 +++++++++++++++-- core/src/epicli/cli/epicli.py | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/core/src/epicli/cli/engine/TestEngine.py b/core/src/epicli/cli/engine/TestEngine.py index 5892f13451..99dedca9c8 100644 --- a/core/src/epicli/cli/engine/TestEngine.py +++ b/core/src/epicli/cli/engine/TestEngine.py @@ -12,6 +12,7 @@ class TestEngine(Step): def __init__(self, input_data): super().__init__(__name__) self.build_directory = input_data.build_directory + self.group = input_data.group def __enter__(self): super().__enter__() @@ -43,6 +44,6 @@ def test(self): # run the spec tests spec_command = SpecCommand() - spec_command.run(spec_output, path_to_inventory, admin_user.name, admin_user.key_path) + spec_command.run(spec_output, path_to_inventory, admin_user.name, admin_user.key_path, self.group) return 0 \ No newline at end of file diff --git a/core/src/epicli/cli/engine/spec/SpecCommand.py b/core/src/epicli/cli/engine/spec/SpecCommand.py index 7edb731932..ec68b7538f 100644 --- a/core/src/epicli/cli/engine/spec/SpecCommand.py +++ b/core/src/epicli/cli/engine/spec/SpecCommand.py @@ -1,5 +1,6 @@ import os import subprocess +import shutil from cli.helpers.Log import LogPipe, Log from cli.helpers.Config import Config @@ -15,14 +16,26 @@ def __init__(self): def __init__(self): self.logger = Log(__name__) - def run(self, spec_output, inventory, user, key): + def check_dependencies(self): + error_str = '''Missing Ruby or one of the following gems: serverspec, rake, rspec_junit_formatter. These need to be installed to run the cluster spec tests from epicli''' + if shutil.which('ruby') == None: + raise Exception(error_str) + + if shutil.which('gem') == None: + raise Exception(error_str) + + #TODO: 'gem query --local' to check rake, rspec_junit_formatter + + def run(self, spec_output, inventory, user, key, group): + self.check_dependencies() + env = os.environ.copy() env['spec_output'] = spec_output env['inventory'] = inventory env['user'] = user env['keypath'] = key - cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:all' + cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:{group}' self.logger.info(f'Running: "{cmd}"') diff --git a/core/src/epicli/cli/epicli.py b/core/src/epicli/cli/epicli.py index 223bc8e149..99d2c734b7 100644 --- a/core/src/epicli/cli/epicli.py +++ b/core/src/epicli/cli/epicli.py @@ -225,6 +225,9 @@ def test_parser(subparsers): sub_parser = subparsers.add_parser('test', description='Test a cluster from build artifacts.') sub_parser.add_argument('-b', '--build', dest='build_directory', type=str, required=True, help='Absolute path to directory with build artifacts.') + #TODO: specify which groups we can run from the spec test folder + sub_parser.add_argument('-g', '--group', choices=['all'], default='all', action='store', dest='group', required=False, + help='Specify which group of tests needs to be run.') def run_test(args): experimental_query() @@ -385,6 +388,9 @@ def dump_external_debug_info(title, args): dump_external_debug_info('ANSIBLE-VAULT VERSION', ['ansible-vault', '--version']) dump_external_debug_info('TERRAFORM VERSION', ['terraform', '--version']) dump_external_debug_info('SKOPEO VERSION', ['skopeo', '--version']) + dump_external_debug_info('RUBY VERSION', ['ruby', '--version']) + dump_external_debug_info('RUBY GEM VERSION', ['gem', '--version']) + dump_external_debug_info('RUBY INSTALLED GEMS', ['gem', 'query', '--local']) dump_file.write('\n\n*****LOG******\n') log_path = os.path.join(get_output_path(), config.log_file) From cfd9a6c202a90f9761643fc0299c52a2cd4809cb Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Fri, 3 Apr 2020 21:28:49 +0200 Subject: [PATCH 03/15] Progress: - Cleaned up a bit - Added tests to make sure Ruby+gems are installed - Start with only 1 group. --- .../src/epicli/cli/engine/spec/SpecCommand.py | 30 ++++++++---- core/src/epicli/cli/epicli.py | 6 +-- core/src/epicli/data/common/tests/Gemfile | 5 -- .../src/epicli/data/common/tests/Gemfile.lock | 47 ------------------- core/src/epicli/data/common/tests/README.md | 32 ------------- core/src/epicli/data/common/tests/Rakefile | 9 ++-- 6 files changed, 29 insertions(+), 100 deletions(-) delete mode 100644 core/src/epicli/data/common/tests/Gemfile delete mode 100644 core/src/epicli/data/common/tests/Gemfile.lock delete mode 100644 core/src/epicli/data/common/tests/README.md diff --git a/core/src/epicli/cli/engine/spec/SpecCommand.py b/core/src/epicli/cli/engine/spec/SpecCommand.py index ec68b7538f..5f2fe6f80c 100644 --- a/core/src/epicli/cli/engine/spec/SpecCommand.py +++ b/core/src/epicli/cli/engine/spec/SpecCommand.py @@ -1,30 +1,37 @@ import os import subprocess import shutil +from subprocess import Popen, PIPE from cli.helpers.Log import LogPipe, Log from cli.helpers.Config import Config from cli.helpers.data_loader import DATA_FOLDER_PATH +SPEC_TEST_PATH = DATA_FOLDER_PATH + '/common/tests' class SpecCommand: - SPEC_TEST_PATH = DATA_FOLDER_PATH + '/common/tests' - def __init__(self): self.logger = Log(__name__) + def __init__(self): self.logger = Log(__name__) + def check_dependencies(self): - error_str = '''Missing Ruby or one of the following gems: serverspec, rake, rspec_junit_formatter. These need to be installed to run the cluster spec tests from epicli''' - if shutil.which('ruby') == None: + required_gems = ['serverspec', 'rake', 'rspec_junit_formatter'] + + error_str = f'''Missing Ruby or one of the following Ruby gems: {', '.join(required_gems)} +These need to be installed to run the cluster spec tests from epicli''' + + if shutil.which('ruby') == None or shutil.which('gem') == None: raise Exception(error_str) - if shutil.which('gem') == None: + p = subprocess.Popen(['gem', 'query', '--local'], stdout=PIPE) + out, err = p.communicate() + if all(n in out.decode('utf-8') for n in required_gems) == False: raise Exception(error_str) - #TODO: 'gem query --local' to check rake, rspec_junit_formatter def run(self, spec_output, inventory, user, key, group): self.check_dependencies() @@ -35,15 +42,20 @@ def run(self, spec_output, inventory, user, key, group): env['user'] = user env['keypath'] = key - cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:{group}' + cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:all' self.logger.info(f'Running: "{cmd}"') logpipe = LogPipe(__name__) - with subprocess.Popen(cmd.split(' '), cwd=self.SPEC_TEST_PATH, env=env, stdout=logpipe, stderr=logpipe, shell=True) as sp: + with Popen(cmd.split(' '), cwd=SPEC_TEST_PATH, env=env, stdout=logpipe, stderr=logpipe, shell=True) as sp: logpipe.close() if sp.returncode != 0: raise Exception(f'Error running: "{cmd}"') else: - self.logger.info(f'Done running: "{cmd}"') + self.logger.info(f'Done running: "{cmd}"') + + + @staticmethod + def get_spec_groups(): + return os.listdir(SPEC_TEST_PATH + '/spec') diff --git a/core/src/epicli/cli/epicli.py b/core/src/epicli/cli/epicli.py index 99d2c734b7..9d36d64f36 100644 --- a/core/src/epicli/cli/epicli.py +++ b/core/src/epicli/cli/epicli.py @@ -24,6 +24,7 @@ from cli.helpers.query_yes_no import query_yes_no from cli.helpers.input_query import prompt_for_password from cli.helpers.build_saver import save_to_file, get_output_path +from cli.engine.spec.SpecCommand import SpecCommand def main(): @@ -225,9 +226,8 @@ def test_parser(subparsers): sub_parser = subparsers.add_parser('test', description='Test a cluster from build artifacts.') sub_parser.add_argument('-b', '--build', dest='build_directory', type=str, required=True, help='Absolute path to directory with build artifacts.') - #TODO: specify which groups we can run from the spec test folder - sub_parser.add_argument('-g', '--group', choices=['all'], default='all', action='store', dest='group', required=False, - help='Specify which group of tests needs to be run.') + #sub_parser.add_argument('-g', '--group', choices=['all'] + SpecCommand.get_spec_groups(), default='all', action='store', dest='group', required=False, + # help='Specify which group of tests needs to be run.') def run_test(args): experimental_query() diff --git a/core/src/epicli/data/common/tests/Gemfile b/core/src/epicli/data/common/tests/Gemfile deleted file mode 100644 index 46c5c7620e..0000000000 --- a/core/src/epicli/data/common/tests/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gem 'serverspec' -gem 'inventoryfile' -gem 'rspec_junit_formatter' diff --git a/core/src/epicli/data/common/tests/Gemfile.lock b/core/src/epicli/data/common/tests/Gemfile.lock deleted file mode 100644 index a708e1db7b..0000000000 --- a/core/src/epicli/data/common/tests/Gemfile.lock +++ /dev/null @@ -1,47 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - diff-lcs (1.3) - inventoryfile (0.2.0) - multi_json (1.13.1) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (5.0.2) - net-telnet (0.2.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-its (1.2.0) - rspec-core (>= 3.0.0) - rspec-expectations (>= 3.0.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - serverspec (2.41.3) - multi_json - rspec (~> 3.0) - rspec-its - specinfra (~> 2.72) - sfl (2.3) - specinfra (2.75.1) - net-scp - net-ssh (>= 2.7) - net-telnet - sfl - -PLATFORMS - ruby - -DEPENDENCIES - inventoryfile - serverspec - -BUNDLED WITH - 1.16.3 diff --git a/core/src/epicli/data/common/tests/README.md b/core/src/epicli/data/common/tests/README.md deleted file mode 100644 index 35a1bf3d68..0000000000 --- a/core/src/epicli/data/common/tests/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Unit testing infrastructure - -## Folder structure - -* Inside ```spec/``` folder create a role that you want to test. -* In the created folder create tests with file name ending with ```_spec.rb``` - -## Ansible inventory - -These test are ment to have ansible inventory on the input. Inventory groups must match folder names in ```spec/``` folder. - -## Setup - -* Install ruby -* ```bundle install``` - -## Running - -To run the tests use: -``` -rake inventory=/home/username/epiphany/build/epiphany/epiphany-vsts-demo/inventory/development user=operations keypath=/home/pljazim/keys/id_rsa spec:all -``` - -Where: - -```inventory``` is a path to your inventory file generated by epiphany (or any other for that matter) -```user``` is the name of the user attached to the key that you are using -```keypath``` is the path to the key that you want to use (-i parameter for ssh). NOTE: Make sure you have correct permissions to the key (600) - -## Additional materials - -* https://vincent.bernat.im/en/blog/2014-serverspec-test-infrastructure diff --git a/core/src/epicli/data/common/tests/Rakefile b/core/src/epicli/data/common/tests/Rakefile index 176d1b62e8..51e8781065 100644 --- a/core/src/epicli/data/common/tests/Rakefile +++ b/core/src/epicli/data/common/tests/Rakefile @@ -3,24 +3,25 @@ require 'rspec/core/rake_task' unless ENV['inventory'] print "ERROR: Inventory file must be specified by 'inventory' environment variable\n" - print " e.g.) bundle exec rake inventory=./hosts spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" exit end unless ENV['user'] print "ERROR: Service user must be specified by 'user' environment variable\n" - print " e.g.) bundle exec rake inventory=./hosts user=operations spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" exit end unless ENV['keypath'] print "ERROR: Private key path must be specified by 'keypath' environment variable\n" - print " e.g.) bundle exec rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" exit end unless ENV['spec_output'] - print "ERROR: Private key path must be specified by 'spec_output' environment variable\n" + print "ERROR: Output path must be specified by 'spec_output' environment variable\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" exit end From 1e04d1a704750bb2ba7688b77cb69d306633aa8f Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Fri, 3 Apr 2020 21:53:27 +0200 Subject: [PATCH 04/15] Minor fixes and changes --- .../src/epicli/cli/engine/spec/SpecCommand.py | 2 +- core/src/epicli/cli/epicli.py | 4 +- core/src/epicli/data/common/tests/rvm.sh | 937 ------------------ core/src/epicli/setup.py | 1 + 4 files changed, 4 insertions(+), 940 deletions(-) delete mode 100644 core/src/epicli/data/common/tests/rvm.sh diff --git a/core/src/epicli/cli/engine/spec/SpecCommand.py b/core/src/epicli/cli/engine/spec/SpecCommand.py index 5f2fe6f80c..57aa2132f6 100644 --- a/core/src/epicli/cli/engine/spec/SpecCommand.py +++ b/core/src/epicli/cli/engine/spec/SpecCommand.py @@ -42,7 +42,7 @@ def run(self, spec_output, inventory, user, key, group): env['user'] = user env['keypath'] = key - cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:all' + cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:{group}' self.logger.info(f'Running: "{cmd}"') diff --git a/core/src/epicli/cli/epicli.py b/core/src/epicli/cli/epicli.py index 9d36d64f36..10d7eb8ca1 100644 --- a/core/src/epicli/cli/epicli.py +++ b/core/src/epicli/cli/epicli.py @@ -226,8 +226,8 @@ def test_parser(subparsers): sub_parser = subparsers.add_parser('test', description='Test a cluster from build artifacts.') sub_parser.add_argument('-b', '--build', dest='build_directory', type=str, required=True, help='Absolute path to directory with build artifacts.') - #sub_parser.add_argument('-g', '--group', choices=['all'] + SpecCommand.get_spec_groups(), default='all', action='store', dest='group', required=False, - # help='Specify which group of tests needs to be run.') + sub_parser.add_argument('-g', '--group', choices=['all'] + SpecCommand.get_spec_groups(), default='all', action='store', dest='group', required=False, + help='Specify which group of tests needs to be run.') def run_test(args): experimental_query() diff --git a/core/src/epicli/data/common/tests/rvm.sh b/core/src/epicli/data/common/tests/rvm.sh deleted file mode 100644 index 254aab1bf6..0000000000 --- a/core/src/epicli/data/common/tests/rvm.sh +++ /dev/null @@ -1,937 +0,0 @@ -#!/usr/bin/env bash - -shopt -s extglob -set -o errtrace -set -o errexit - -rvm_install_initialize() -{ - DEFAULT_SOURCES=(github.com/rvm/rvm bitbucket.org/mpapis/rvm) - - BASH_MIN_VERSION="3.2.25" - if - [[ -n "${BASH_VERSION:-}" && - "$(\printf "%b" "${BASH_VERSION:-}\n${BASH_MIN_VERSION}\n" | LC_ALL=C \sort -t"." -k1,1n -k2,2n -k3,3n | \head -n1)" != "${BASH_MIN_VERSION}" - ]] - then - echo "BASH ${BASH_MIN_VERSION} required (you have $BASH_VERSION)" - exit 1 - fi - - export HOME PS4 - export rvm_trace_flag rvm_debug_flag rvm_user_install_flag rvm_ignore_rvmrc rvm_prefix rvm_path - - PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > " -} - -log() { printf "%b\n" "$*"; } -debug(){ [[ ${rvm_debug_flag:-0} -eq 0 ]] || printf "%b\n" "$*" >&2; } -fail() { log "\nERROR: $*\n" >&2 ; exit 1 ; } - -rvm_install_commands_setup() -{ - \which which >/dev/null 2>&1 || fail "Could not find 'which' command, make sure it's available first before continuing installation." - \which grep >/dev/null 2>&1 || fail "Could not find 'grep' command, make sure it's available first before continuing installation." - if - [[ -z "${rvm_tar_command:-}" ]] && builtin command -v gtar >/dev/null - then - rvm_tar_command=gtar - elif - ${rvm_tar_command:-tar} --help 2>&1 | GREP_OPTIONS="" \grep -- --strip-components >/dev/null - then - rvm_tar_command="${rvm_tar_command:-tar}" - else - case "$(uname)" in - (OpenBSD) - log "Trying to install GNU version of tar, might require sudo password" - if (( UID )) - then sudo pkg_add -z gtar-1 - else pkg_add -z gtar-1 - fi - rvm_tar_command=gtar - ;; - (Darwin|FreeBSD|DragonFly) # it's not possible to autodetect on OSX, the help/man does not mention all flags - rvm_tar_command=tar - ;; - (SunOS) - case "$(uname -r)" in - (5.10) - log "Trying to install GNU version of tar, might require sudo password" - if (( UID )) - then - if \which sudo >/dev/null 2>&1 - then sudo_10=sudo - elif \which /opt/csw/bin/sudo >/dev/null 2>&1 - then sudo_10=/opt/csw/bin/sudo - else fail "sudo is required but not found. You may install sudo from OpenCSW repository (https://www.opencsw.org/about)" - fi - pkginfo -q CSWpkgutil || $sudo_10 pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil - sudo /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable - else - pkginfo -q CSWpkgutil || pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil - /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable - fi - rvm_tar_command=/opt/csw/bin/gtar - ;; - (*) - rvm_tar_command=tar - ;; - esac - esac - builtin command -v ${rvm_tar_command:-gtar} >/dev/null || - fail "Could not find GNU compatible version of 'tar' command, make sure it's available first before continuing installation." - fi - if - [[ " ${rvm_tar_options:-} " != *" --no-same-owner "* ]] && - $rvm_tar_command --help 2>&1 | GREP_OPTIONS="" \grep -- --no-same-owner >/dev/null - then - rvm_tar_options="${rvm_tar_options:-}${rvm_tar_options:+ }--no-same-owner" - fi -} - -usage() -{ - printf "%b" " - -Usage - - rvm-installer [options] [action] - -Options - - [[--]version] - - The version or tag to install. Valid values are: - - latest - The latest tagged version. - latest-minor - The latest minor version of the current major version. - latest- - The latest minor version of version x. - latest-. - The latest patch version of version x.y. - .. - Major version x, minor version y and patch z. - - [--]branch - - The name of the branch from which RVM is installed. This option can be used - with the following formats for : - - / - - If account is rvm or mpapis, installs from one of the following: - - https://github.com/rvm/rvm/archive/master.tar.gz - https://bitbucket.org/mpapis/rvm/get/master.tar.gz - - Otherwise, installs from: - - https://github.com//rvm/archive/master.tar.gz - - / - - If account is rvm or mpapis, installs from one of the following: - - https://github.com/rvm/rvm/archive/.tar.gz - https://bitbucket.org/mpapis/rvm/get/.tar.gz - - Otherwise, installs from: - - https://github.com//rvm/archive/.tar.gz - - [/] - - Installs the branch from one of the following: - - https://github.com/rvm/rvm/archive/.tar.gz - https://bitbucket.org/mpapis/rvm/get/.tar.gz - - [--]source - - Defines the repository from which RVM is retrieved and installed in the format: - - // - - Where: - - - Is bitbucket.org, github.com or a github enterprise site serving - an RVM repository. - - Is the user account in which the RVM repository resides. - - Is the name of the RVM repository. - - Note that when using the [--]source option, one should only use the [/]branch format - with the [--]branch option. Failure to do so will result in undefined behavior. - - --trace - - Provides debug logging for the installation script. -Actions - - master - Installs RVM from the master branch at rvm/rvm on github or mpapis/rvm - on bitbucket.org. - stable - Installs RVM from the stable branch a rvm/rvm on github or mpapis/rvm - on bitbucket.org. - help - Displays this output. - -" -} - -## duplication marker 32fosjfjsznkjneuera48jae -__rvm_curl_output_control() -{ - if - (( ${rvm_quiet_curl_flag:-0} == 1 )) - then - __flags+=( "--silent" "--show-error" ) - elif - [[ " $*" == *" -s"* || " $*" == *" --silent"* ]] - then - # make sure --show-error is used with --silent - [[ " $*" == *" -S"* || " $*" == *" -sS"* || " $*" == *" --show-error"* ]] || - { - __flags+=( "--show-error" ) - } - fi -} - -## duplication marker 32fosjfjsznkjneuera48jae -# -S is automatically added to -s -__rvm_curl() -( - __rvm_which curl >/dev/null || - { - rvm_error "RVM requires 'curl'. Install 'curl' first and try again." - return 200 - } - - typeset -a __flags - __flags=( --fail --location --max-redirs 10 ) - - [[ "$*" == *"--max-time"* ]] || - [[ "$*" == *"--connect-timeout"* ]] || - __flags+=( --connect-timeout 30 --retry-delay 2 --retry 3 ) - - if [[ -n "${rvm_proxy:-}" ]] - then __flags+=( --proxy "${rvm_proxy:-}" ) - fi - - __rvm_curl_output_control - - unset curl - __rvm_debug_command \curl "${__flags[@]}" "$@" || return $? -) - -rvm_error() { printf "ERROR: %b\n" "$*"; } -__rvm_which(){ which "$@" || return $?; true; } -__rvm_debug_command() -{ - debug "Running($#): $*" - "$@" || return $? - true -} -rvm_is_a_shell_function() -{ - [[ -t 0 && -t 1 ]] || return $? - return ${rvm_is_not_a_shell_function:-0} -} - -# Searches the tags for the highest available version matching a given pattern. -# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.10. -> 1.10.3 -# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.10. -> 1.10.3 -# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1. -> 1.11.0 -# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) "" -> 2.0.1 -fetch_version() -{ - typeset _account _domain _pattern _repo _sources _values _version - _sources=(${!1}) - _pattern=$2 - for _source in "${_sources[@]}" - do - IFS='/' read -r _domain _account _repo <<< "${_source}" - _version="$( - fetch_versions ${_domain} ${_account} ${_repo} | - GREP_OPTIONS="" \grep "^${_pattern:-}" | tail -n 1 - )" - if - [[ -n ${_version} ]] - then - echo "${_version}" - return 0 - fi - done -} - -# Returns a sorted list of all version tags from a repository -fetch_versions() -{ - typeset _account _domain _repo _url - _domain=$1 - _account=$2 - _repo=$3 - case ${_domain} in - (bitbucket.org) - _url=https://${_domain}/api/1.0/repositories/${_account}/${_repo}/branches-tags - ;; - (github.com) - _url=https://api.${_domain}/repos/${_account}/${_repo}/tags - ;; - - (*) - _url=https://${_domain}/api/v3/repos/${_account}/${_repo}/tags - ;; - esac - __rvm_curl -s ${_url} | - \awk -v RS=',' -v FS='"' '$2=="name"{print $4}' | - sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -} - -install_release() -{ - typeset _source _sources _url _version _verify_pgp - _sources=(${!1}) - _version=$2 - debug "Downloading RVM version ${_version}" - for _source in "${_sources[@]}" - do - case ${_source} in - (bitbucket.org*) - _url="https://${_source}/get/${_version}.tar.gz" - _verify_pgp="https://${_source}/downloads/${_version}.tar.gz.asc" - ;; - (*) - _url="https://${_source}/archive/${_version}.tar.gz" - _verify_pgp="https://${_source}/releases/download/${_version}/${_version}.tar.gz.asc" - ;; - esac - get_and_unpack "${_url}" "rvm-${_version}.tgz" "$_verify_pgp" && return - done - return $? -} - -install_head() -{ - typeset _branch _source _sources _url - _sources=(${!1}) - _branch=$2 - debug "Selected RVM branch ${_branch}" - for _source in "${_sources[@]}" - do - case ${_source} in - (bitbucket.org*) - _url=https://${_source}/get/${_branch}.tar.gz - ;; - (*) - _url=https://${_source}/archive/${_branch}.tar.gz - ;; - esac - get_and_unpack "${_url}" "rvm-${_branch//\//_}.tgz" && return - done - return $? -} - -# duplication marker dfkjdjngdfjngjcszncv -# Drop in cd which _doesn't_ respect cdpath -__rvm_cd() -{ - typeset old_cdpath ret - ret=0 - old_cdpath="${CDPATH}" - CDPATH="." - chpwd_functions="" builtin cd "$@" || ret=$? - CDPATH="${old_cdpath}" - return $ret -} - -get_package() -{ - typeset _url _file - _url="$1" - _file="$2" - log "Downloading ${_url}" - __rvm_curl -sS ${_url} > ${rvm_archives_path}/${_file} || - { - _return=$? - case $_return in - # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn - (60) - log " -Could not download '${_url}', you can read more about it here: -https://rvm.io/support/fixing-broken-ssl-certificates/ -To continue in insecure mode run 'echo insecure >> ~/.curlrc'. -" - ;; - # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn - (77) - log " -It looks like you have old certificates, you can read more about it here: -https://rvm.io/support/fixing-broken-ssl-certificates/ -" - ;; - # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn - (141) - log " -Curl returned 141 - it is result of a segfault which means it's Curls fault. -Try again and if it crashes more than a couple of times you either need to -reinstall Curl or consult with your distribution manual and contact support. -" - ;; - (*) - log " -Could not download '${_url}'. - curl returned status '$_return'. -" - ;; - esac - return $_return - } -} - -# duplication marker flnglfdjkngjndkfjhsbdjgfghdsgfklgg -rvm_install_gpg_setup() -{ - export rvm_gpg_command - { - rvm_gpg_command="$( \which gpg2 2>/dev/null )" && - [[ ${rvm_gpg_command} != "/cygdrive/"* ]] - } || { - rvm_gpg_command="$( \which gpg 2>/dev/null )" && - [[ ${rvm_gpg_command} != "/cygdrive/"* ]] - } || rvm_gpg_command="" - - debug "Detected GPG program: '$rvm_gpg_command'" - - [[ -n "$rvm_gpg_command" ]] || return $? -} - -# duplication marker rdjgndfnghdfnhgfdhbghdbfhgbfdhbn -verify_package_pgp() -{ - if - "${rvm_gpg_command}" --verify "$2" "$1" - then - log "GPG verified '$1'" - else - typeset _ret=$? - log "\ -Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. \ -Assuming you trust Michal Papis import the mpapis public key (downloading the signatures). - -GPG signature verification failed for '$1' - '$3'! Try to install GPG v2 and then fetch the public key: - - ${SUDO_USER:+sudo }gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 - -or if it fails: - - command curl -sSL https://rvm.io/mpapis.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import - - -the key can be compared with: - - https://rvm.io/mpapis.asc - https://keybase.io/mpapis - -NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade \ -or upgrade to newer version (if available) or use the second method described above. -" - exit $_ret - fi -} - -verify_pgp() -{ - [[ -n "${1:-}" ]] || - { - debug "No PGP url given, skipping." - return 0 - } - - get_package "$1" "$2.asc" || - { - debug "PGP url given but does not exist: '$1'" - return 0 - } - - rvm_install_gpg_setup || - { - log "Found PGP signature at: '$1', -but no GPG software exists to validate it, skipping." - return 0 - } - - verify_package_pgp "${rvm_archives_path}/$2" "${rvm_archives_path}/$2.asc" "$1" -} - -get_and_unpack() -{ - typeset _url _file _patern _return _verify_pgp - _url="$1" - _file="$2" - _verify_pgp="$3" - - get_package "$_url" "$_file" || return $? - verify_pgp "$_verify_pgp" "$_file" || return $? - - [[ -d "${rvm_src_path}/rvm" ]] || \mkdir -p "${rvm_src_path}/rvm" - __rvm_cd "${rvm_src_path}/rvm" || - { - _return=$? - log "Could not change directory '${rvm_src_path}/rvm'." - return $_return - } - - # Remove existing installation - typeset _cleanup_cmd - _cleanup_cmd="rm -rf ${rvm_src_path}/rvm/{,.[!.],..?}*" - - $_cleanup_cmd || { - _return=$? - log "Could not remove old RVM sources. Try:\n\n\tsudo $_cleanup_cmd\n\nThen retry your task again." - return $_return - } - - # Unpack sources - __rvm_debug_command $rvm_tar_command xzf ${rvm_archives_path}/${_file} ${rvm_tar_options:-} --strip-components 1 || - { - _return=$? - log "Could not extract RVM sources." - return $_return - } -} - -rvm_install_default_settings() -{ - # Tracing, if asked for. - if - [[ "$*" == *--trace* ]] || (( ${rvm_trace_flag:-0} > 0 )) - then - set -o xtrace - rvm_trace_flag=1 - fi - - # Variable initialization, remove trailing slashes if they exist on HOME - true \ - ${rvm_trace_flag:=0} ${rvm_debug_flag:=0}\ - ${rvm_ignore_rvmrc:=0} HOME="${HOME%%+(\/)}" - - if - (( rvm_ignore_rvmrc == 0 )) - then - for rvmrc in /etc/rvmrc "$HOME/.rvmrc" - do - if - [[ -s "$rvmrc" ]] - then - if - GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1 - then - printf "%b" " - Error: $rvmrc is for rvm settings only. - rvm CLI may NOT be called from within $rvmrc. - Skipping the loading of $rvmrc - " - exit 1 - else - source "$rvmrc" - fi - fi - done - fi - - if - [[ -z "${rvm_path:-}" ]] - then - if - (( UID == 0 )) - then - rvm_user_install_flag=0 - rvm_prefix="/usr/local" - rvm_path="${rvm_prefix}/rvm" - else - rvm_user_install_flag=1 - rvm_prefix="$HOME" - rvm_path="${rvm_prefix}/.rvm" - fi - fi - if [[ -z "${rvm_prefix}" ]] - then rvm_prefix=$( dirname $rvm_path ) - fi - - # duplication marker kkdfkgnjfndgjkndfjkgnkfjdgn - [[ -n "${rvm_user_install_flag:-}" ]] || - case "$rvm_path" in - (/usr/local/rvm) rvm_user_install_flag=0 ;; - ($HOME/*|/${USER// /_}*) rvm_user_install_flag=1 ;; - (*) rvm_user_install_flag=0 ;; - esac -} - -rvm_install_parse_params() -{ - install_rubies=() - install_gems=() - flags=( ./scripts/install ) - forwarded_flags=() - while - (( $# > 0 )) - do - token="$1" - shift - case "$token" in - - (--trace) - set -o xtrace - rvm_trace_flag=1 - flags=( -x "${flags[@]}" "$token" ) - forwarded_flags+=( "$token" ) - ;; - - (--debug|--quiet-curl) - flags+=( "$token" ) - forwarded_flags+=( "$token" ) - token=${token#--} - token=${token//-/_} - export "rvm_${token}_flag"=1 - printf "%b" "Turning on ${token/_/ } mode.\n" - ;; - - (--path) - if [[ -n "${1:-}" ]] - then - rvm_path="$1" - shift - else - fail "--path must be followed by a path." - fi - ;; - - (--branch|branch) # Install RVM from a given branch - if [[ -n "${1:-}" ]] - then - case "$1" in - (/*) - branch=${1#/} - ;; - (*/) - branch=master - if [[ "${1%/}" -ne rvm ]] && [[ "${1%/}" -ne mpapis ]] - then sources=(github.com/${1%/}/rvm) - fi - ;; - (*/*) - branch=${1#*/} - if [[ "${1%%/*}" -ne rvm ]] && [[ "${1%%/*}" -ne mpapis ]] - then sources=(github.com/${1%%/*}/rvm) - fi - ;; - (*) - branch="$1" - ;; - esac - shift - else - fail "--branch must be followed by a branchname." - fi - ;; - - (--source|source) - if [[ -n "${1:-}" ]] - then - if [[ "$1" = */*/* ]] - then - sources=($1) - shift - else - fail "--source must be in the format //." - fi - else - fail "--source must be followed by a source." - fi - ;; - - (--user-install|--ignore-dotfiles) - token=${token#--} - token=${token//-/_} - export "rvm_${token}_flag"=1 - printf "%b" "Turning on ${token/_/ } mode.\n" - ;; - - (--auto-dotfiles) - flags+=( "$token" ) - export "rvm_auto_dotfiles_flag"=1 - printf "%b" "Turning on auto dotfiles mode.\n" - ;; - - (--auto) - export "rvm_auto_dotfiles_flag"=1 - printf "%b" "Warning, --auto is deprecated in favor of --auto-dotfiles.\n" - ;; - - (--verify-downloads) - if [[ -n "${1:-}" ]] - then - export rvm_verify_downloads_flag="$1" - forwarded_flags+=( "$token" "$1" ) - shift - else - fail "--verify-downloads must be followed by level(0|1|2)." - fi - ;; - - (--autolibs=*) - flags+=( "$token" ) - export rvm_autolibs_flag="${token#--autolibs=}" - forwarded_flags+=( "$token" ) - ;; - - (--without-gems=*|--with-gems=*|--with-default-gems=*) - flags+=( "$token" ) - value="${token#*=}" - token="${token%%=*}" - token="${token#--}" - token="${token//-/_}" - export "rvm_${token}"="${value}" - printf "%b" "Installing RVM ${token/_/ }: ${value}.\n" - ;; - - (--version|version) - version="$1" - shift - ;; - - (head|master) - version="head" - branch="master" - ;; - - (stable) - version="latest" - ;; - - (latest|latest-*|+([[:digit:]]).+([[:digit:]]).+([[:digit:]])) - version="$token" - ;; - - (--ruby) - install_rubies+=( ruby ) - ;; - - (--ruby=*) - token=${token#--ruby=} - install_rubies+=( ${token//,/ } ) - ;; - - (--rails) - install_gems+=( rails ) - ;; - - (--gems=*) - token=${token#--gems=} - install_gems+=( ${token//,/ } ) - ;; - - (--add-to-rvm-group) - export rvm_add_users_to_rvm_group="$1" - shift - ;; - - (help) - usage - exit 0 - ;; - - (*) - usage - exit 1 - ;; - - esac - done - - if (( ${#install_gems[@]} > 0 && ${#install_rubies[@]} == 0 )) - then install_rubies=( ruby ) - fi - - true "${version:=head}" - true "${branch:=master}" - - if [[ -z "${sources[@]}" ]] - then sources=("${DEFAULT_SOURCES[@]}") - fi - - rvm_src_path="$rvm_path/src" - rvm_archives_path="$rvm_path/archives" - rvm_releases_url="https://rvm.io/releases" -} - -rvm_install_validate_rvm_path() -{ - case "$rvm_path" in - (*[[:space:]]*) - printf "%b" " -It looks you are one of the happy *space* users (in home dir name), -RVM is not yet fully ready for it, use this trick to fix it: - - sudo mkdir -p /${USER// /_}.rvm - sudo chown -R \"$USER:\" /${USER// /_}.rvm - echo \"export rvm_path=/${USER// /_}.rvm\" >> \"$HOME/.rvmrc\" - -and start installing again. - -" - exit 2 - ;; - (/usr/share/ruby-rvm) - printf "%b" " -It looks you are one of the happy Ubuntu users, -RVM packaged by Ubuntu is old and broken, -follow this link for details how to fix: - - https://stackoverflow.com/a/9056395/497756 - -" - [[ "${rvm_uses_broken_ubuntu_path:-no}" == "yes" ]] || exit 3 - ;; - esac - - if [[ "$rvm_path" != "/"* ]] - then fail "The rvm install path must be fully qualified. Tried $rvm_path" - fi -} - -rvm_install_validate_volume_mount_mode() -{ - \typeset path partition test_exec - - path=$rvm_path - - # Directory $rvm_path might not exists at this point so we need to traverse the tree upwards - while [[ -n "$path" ]] - do - if [[ -d $path ]] - then - partition=`df -P $path | awk 'END{print $1}'` - - test_exec=$(mktemp $path/rvm-exec-test.XXXXXX) - echo '#!/bin/sh' > "$test_exec" - chmod +x "$test_exec" - - if ! "$test_exec" - then - rm -f "$test_exec" - printf "%b" " -It looks that scripts located in ${path}, which would be RVM destination ${rvm_path}, -are not executable. One of the reasons might be that partition ${partition} holding this location -is mounted in *noexec* mode, which prevents RVM from working correctly. Please verify your setup -and re-mount partition ${partition} without the noexec option." - exit 2 - fi - - rm -f "$test_exec" - break - fi - - path=${path%/*} - done -} - -rvm_install_select_and_get_version() -{ - typeset _version_release - - for dir in "$rvm_src_path" "$rvm_archives_path" - do - [[ -d "$dir" ]] || mkdir -p "$dir" - done - - _version_release="${version}" - case "${version}" in - (head) - _version_release="${branch}" - install_head sources[@] ${branch:-master} || exit $? - ;; - - (latest) - install_release sources[@] $(fetch_version sources[@]) || exit $? - ;; - - (latest-minor) - version="$(\cat "$rvm_path/VERSION")" - install_release sources[@] $(fetch_version sources[@] ${version%.*}) || exit $? - ;; - - (latest-*) - install_release sources[@] $(fetch_version sources[@] ${version#latest-}) || exit $? - ;; - - (+([[:digit:]]).+([[:digit:]]).+([[:digit:]])) # x.y.z - install_release sources[@] ${version} || exit $? - ;; - - (*) - fail "Something went wrong, unrecognized version '$version'" - ;; - esac - echo "${_version_release}" > "$rvm_path/RELEASE" -} - -rvm_install_main() -{ - [[ -f ./scripts/install ]] || - { - log "'./scripts/install' can not be found for installation, something went wrong, it usually means your 'tar' is broken, please report it here: https://github.com/rvm/rvm/issues" - return 127 - } - - # required flag - path to install - flags+=( --path "$rvm_path" ) - \command bash "${flags[@]}" -} - -rvm_install_ruby_and_gems() -( - if - (( ${#install_rubies[@]} > 0 )) - then - source ${rvm_scripts_path:-${rvm_path}/scripts}/rvm - source ${rvm_scripts_path:-${rvm_path}/scripts}/functions/version - __rvm_print_headline - - for _ruby in ${install_rubies[@]} - do command rvm "${forwarded_flags[@]}" install ${_ruby} -j 2 - done - # set the first one as default, skip rest - for _ruby in ${install_rubies[@]} - do - rvm "${forwarded_flags[@]}" alias create default ${_ruby} - break - done - - for _gem in ${install_gems[@]} - do rvm "${forwarded_flags[@]}" all do gem install ${_gem} - done - - printf "%b" " - * To start using RVM you need to run \`source $rvm_path/scripts/rvm\` - in all your open shell windows, in rare cases you need to reopen all shell windows. -" - - if - [[ "${install_gems[*]}" == *"rails"* ]] - then - printf "%b" " - * To start using rails you need to run \`rails new \`. -" - fi - fi -) - -rvm_install() -{ - rvm_install_initialize - rvm_install_commands_setup - rvm_install_default_settings - rvm_install_parse_params "$@" - rvm_install_validate_rvm_path - rvm_install_validate_volume_mount_mode - rvm_install_select_and_get_version - rvm_install_main - rvm_install_ruby_and_gems -} - -rvm_install "$@" diff --git a/core/src/epicli/setup.py b/core/src/epicli/setup.py index 7237829a6c..2e088f8c62 100644 --- a/core/src/epicli/setup.py +++ b/core/src/epicli/setup.py @@ -24,6 +24,7 @@ long_description=readme, author='Epiphany Team', author_email='', + python_requires='=3.7.*', url='https://github.com/epiphany-platform/epiphany', license=license, packages=find_packages(exclude=('tests', 'docs')), From f7e6ea36ea172c91e08c4c24cab7284da820212d Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Sat, 4 Apr 2020 20:37:04 +0200 Subject: [PATCH 05/15] Minor fixes for running specified groups --- core/src/epicli/cli/engine/spec/SpecCommand.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/epicli/cli/engine/spec/SpecCommand.py b/core/src/epicli/cli/engine/spec/SpecCommand.py index 57aa2132f6..af9449c1c4 100644 --- a/core/src/epicli/cli/engine/spec/SpecCommand.py +++ b/core/src/epicli/cli/engine/spec/SpecCommand.py @@ -42,12 +42,12 @@ def run(self, spec_output, inventory, user, key, group): env['user'] = user env['keypath'] = key - cmd = f'rake inventory="{inventory}" user={user} keypath="{key}" spec_output="{spec_output}" spec:{group}' + cmd = f'rake inventory={inventory} user={user} keypath={key} spec_output={spec_output} spec:{group}' self.logger.info(f'Running: "{cmd}"') logpipe = LogPipe(__name__) - with Popen(cmd.split(' '), cwd=SPEC_TEST_PATH, env=env, stdout=logpipe, stderr=logpipe, shell=True) as sp: + with Popen(cmd.split(' '), cwd=SPEC_TEST_PATH, env=env, stdout=logpipe, stderr=logpipe) as sp: logpipe.close() if sp.returncode != 0: From 75413291d7074aad0c89b588e740ae705220d1d6 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Mon, 6 Apr 2020 10:42:07 +0200 Subject: [PATCH 06/15] Cleaning up running of Python tests. --- core/src/epicli/.vscode/launch.json | 2 +- core/src/epicli/run-tests.py | 25 +------------------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/core/src/epicli/.vscode/launch.json b/core/src/epicli/.vscode/launch.json index e5181dae49..f5b39360b2 100644 --- a/core/src/epicli/.vscode/launch.json +++ b/core/src/epicli/.vscode/launch.json @@ -28,7 +28,7 @@ "pythonPath": "${config:python.pythonPath}", "env": { "PYTHONPATH": "${workspaceFolder}" }, "console": "integratedTerminal", - "args": ["python"] + "args": [] } ] } \ No newline at end of file diff --git a/core/src/epicli/run-tests.py b/core/src/epicli/run-tests.py index a62e57b894..0005836957 100644 --- a/core/src/epicli/run-tests.py +++ b/core/src/epicli/run-tests.py @@ -1,31 +1,8 @@ #!/usr/bin/env py -import sys -import argparse -import json -import os import subprocess def main(): - parser = argparse.ArgumentParser( - description=__doc__, - usage='''test []''', - formatter_class=argparse.RawDescriptionHelpFormatter) - - subparsers = parser.add_subparsers() - python_parser(subparsers) - - arg = parser.parse_args() - return arg.func(arg) - - -def python_parser(subparsers): - sub_parser = subparsers.add_parser('python', description='Runs the Epicli python unit tests') - - def run_python(args): - subprocess.call('mkdir -p tests/cli/results/ && python -m pytest ./tests/ --junit-xml=tests/cli/results/result.xml | tee tests/cli/results/result.txt', shell=True) - - sub_parser.set_defaults(func=run_python) - + return subprocess.call('mkdir -p tests/cli/results/ && python -m pytest ./tests/ --junit-xml=tests/cli/results/result.xml | tee tests/cli/results/result.txt', shell=True) if __name__ == '__main__': exit(main()) From cc4d69dfed8b70e8aaf65aa5fa9df8e5c770313d Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Mon, 6 Apr 2020 22:12:48 +0200 Subject: [PATCH 07/15] Re-structure Python unit tests. --- core/src/epicli/.gitignore | 3 +-- core/src/epicli/.vscode/launch.json | 6 +++--- core/src/epicli/run-tests.py | 8 -------- core/src/epicli/tests/{cli => }/conftest.py | 0 .../engine/providers/aws/test_AWSConfigBuilder.py | 0 .../engine/providers/azure/test_AzureConfigBuilder.py | 0 .../engine/providers/test_provider_class_loader_any.py | 0 .../engine/providers/test_provider_class_loader_aws.py | 0 .../engine/providers/test_provider_class_loader_azure.py | 0 core/src/epicli/tests/{cli => }/helpers/test_ObjDict.py | 0 .../tests/{cli => }/helpers/test_doc_list_helpers.py | 0 .../epicli/tests/{cli => }/helpers/test_name_helpers.py | 0 .../tests/{cli => }/helpers/test_objdict_helpers.py | 0 core/src/epicli/tests/pytest.ini | 3 +++ 14 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 core/src/epicli/run-tests.py rename core/src/epicli/tests/{cli => }/conftest.py (100%) rename core/src/epicli/tests/{cli => }/engine/providers/aws/test_AWSConfigBuilder.py (100%) rename core/src/epicli/tests/{cli => }/engine/providers/azure/test_AzureConfigBuilder.py (100%) rename core/src/epicli/tests/{cli => }/engine/providers/test_provider_class_loader_any.py (100%) rename core/src/epicli/tests/{cli => }/engine/providers/test_provider_class_loader_aws.py (100%) rename core/src/epicli/tests/{cli => }/engine/providers/test_provider_class_loader_azure.py (100%) rename core/src/epicli/tests/{cli => }/helpers/test_ObjDict.py (100%) rename core/src/epicli/tests/{cli => }/helpers/test_doc_list_helpers.py (100%) rename core/src/epicli/tests/{cli => }/helpers/test_name_helpers.py (100%) rename core/src/epicli/tests/{cli => }/helpers/test_objdict_helpers.py (100%) create mode 100644 core/src/epicli/tests/pytest.ini diff --git a/core/src/epicli/.gitignore b/core/src/epicli/.gitignore index ecee3f7f82..d6eef6894e 100644 --- a/core/src/epicli/.gitignore +++ b/core/src/epicli/.gitignore @@ -121,8 +121,7 @@ dmypy.json # epicli specific external/ -tests/serverspec-cli/results/ -tests/cli/results/ +tests/results/ .terraform clusters .vscode diff --git a/core/src/epicli/.vscode/launch.json b/core/src/epicli/.vscode/launch.json index f5b39360b2..b4ecff4ebb 100644 --- a/core/src/epicli/.vscode/launch.json +++ b/core/src/epicli/.vscode/launch.json @@ -20,15 +20,15 @@ // "args": ["test", "-b", "${workspaceFolder}/clusters/build/dir"] }, { - "name": "python unit tests", + "name": "unit tests", "type": "python", "request": "launch", - "program": "${workspaceFolder}/run-tests.py", + "module": "pytest", "cwd": "${workspaceFolder}", "pythonPath": "${config:python.pythonPath}", "env": { "PYTHONPATH": "${workspaceFolder}" }, "console": "integratedTerminal", - "args": [] + "args": ["${workspaceFolder}/tests/", "--junitxml=${workspaceFolder}/tests/results/unit_tests_results.xml"] } ] } \ No newline at end of file diff --git a/core/src/epicli/run-tests.py b/core/src/epicli/run-tests.py deleted file mode 100644 index 0005836957..0000000000 --- a/core/src/epicli/run-tests.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env py -import subprocess - -def main(): - return subprocess.call('mkdir -p tests/cli/results/ && python -m pytest ./tests/ --junit-xml=tests/cli/results/result.xml | tee tests/cli/results/result.txt', shell=True) - -if __name__ == '__main__': - exit(main()) diff --git a/core/src/epicli/tests/cli/conftest.py b/core/src/epicli/tests/conftest.py similarity index 100% rename from core/src/epicli/tests/cli/conftest.py rename to core/src/epicli/tests/conftest.py diff --git a/core/src/epicli/tests/cli/engine/providers/aws/test_AWSConfigBuilder.py b/core/src/epicli/tests/engine/providers/aws/test_AWSConfigBuilder.py similarity index 100% rename from core/src/epicli/tests/cli/engine/providers/aws/test_AWSConfigBuilder.py rename to core/src/epicli/tests/engine/providers/aws/test_AWSConfigBuilder.py diff --git a/core/src/epicli/tests/cli/engine/providers/azure/test_AzureConfigBuilder.py b/core/src/epicli/tests/engine/providers/azure/test_AzureConfigBuilder.py similarity index 100% rename from core/src/epicli/tests/cli/engine/providers/azure/test_AzureConfigBuilder.py rename to core/src/epicli/tests/engine/providers/azure/test_AzureConfigBuilder.py diff --git a/core/src/epicli/tests/cli/engine/providers/test_provider_class_loader_any.py b/core/src/epicli/tests/engine/providers/test_provider_class_loader_any.py similarity index 100% rename from core/src/epicli/tests/cli/engine/providers/test_provider_class_loader_any.py rename to core/src/epicli/tests/engine/providers/test_provider_class_loader_any.py diff --git a/core/src/epicli/tests/cli/engine/providers/test_provider_class_loader_aws.py b/core/src/epicli/tests/engine/providers/test_provider_class_loader_aws.py similarity index 100% rename from core/src/epicli/tests/cli/engine/providers/test_provider_class_loader_aws.py rename to core/src/epicli/tests/engine/providers/test_provider_class_loader_aws.py diff --git a/core/src/epicli/tests/cli/engine/providers/test_provider_class_loader_azure.py b/core/src/epicli/tests/engine/providers/test_provider_class_loader_azure.py similarity index 100% rename from core/src/epicli/tests/cli/engine/providers/test_provider_class_loader_azure.py rename to core/src/epicli/tests/engine/providers/test_provider_class_loader_azure.py diff --git a/core/src/epicli/tests/cli/helpers/test_ObjDict.py b/core/src/epicli/tests/helpers/test_ObjDict.py similarity index 100% rename from core/src/epicli/tests/cli/helpers/test_ObjDict.py rename to core/src/epicli/tests/helpers/test_ObjDict.py diff --git a/core/src/epicli/tests/cli/helpers/test_doc_list_helpers.py b/core/src/epicli/tests/helpers/test_doc_list_helpers.py similarity index 100% rename from core/src/epicli/tests/cli/helpers/test_doc_list_helpers.py rename to core/src/epicli/tests/helpers/test_doc_list_helpers.py diff --git a/core/src/epicli/tests/cli/helpers/test_name_helpers.py b/core/src/epicli/tests/helpers/test_name_helpers.py similarity index 100% rename from core/src/epicli/tests/cli/helpers/test_name_helpers.py rename to core/src/epicli/tests/helpers/test_name_helpers.py diff --git a/core/src/epicli/tests/cli/helpers/test_objdict_helpers.py b/core/src/epicli/tests/helpers/test_objdict_helpers.py similarity index 100% rename from core/src/epicli/tests/cli/helpers/test_objdict_helpers.py rename to core/src/epicli/tests/helpers/test_objdict_helpers.py diff --git a/core/src/epicli/tests/pytest.ini b/core/src/epicli/tests/pytest.ini new file mode 100644 index 0000000000..83116c7d2c --- /dev/null +++ b/core/src/epicli/tests/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +junit_family = xunit1 +addopts = -p no:warnings \ No newline at end of file From 2bcd31063ef595f34620068a7bdb232bf58465e5 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Mon, 6 Apr 2020 23:32:01 +0200 Subject: [PATCH 08/15] Minor fixes --- core/src/epicli/Dockerfile | 4 ++-- core/src/epicli/cli/engine/TestEngine.py | 6 ++++-- core/src/epicli/cli/engine/spec/__init__.py | 0 core/src/epicli/setup.py | 1 - 4 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 core/src/epicli/cli/engine/spec/__init__.py diff --git a/core/src/epicli/Dockerfile b/core/src/epicli/Dockerfile index b161cb6276..c0b8e3a364 100644 --- a/core/src/epicli/Dockerfile +++ b/core/src/epicli/Dockerfile @@ -13,8 +13,8 @@ WORKDIR /epicli RUN apt-get update \ && apt-get -y install gcc make musl-dev libffi-dev tar unzip openssh-client vim \ - && sudo apt-get -y install ruby-full \ - && sudo gem install serverspec rake rspec_junit_formatter + && apt-get -y install ruby-full \ + && gem install serverspec rake rspec_junit_formatter RUN pip install epicli-${EPICLI_VERSION}-py3-none-any.whl diff --git a/core/src/epicli/cli/engine/TestEngine.py b/core/src/epicli/cli/engine/TestEngine.py index 99dedca9c8..6970160d04 100644 --- a/core/src/epicli/cli/engine/TestEngine.py +++ b/core/src/epicli/cli/engine/TestEngine.py @@ -25,17 +25,19 @@ def test(self): # get manifest path_to_manifest = os.path.join(self.build_directory, MANIFEST_FILE_NAME) if not os.path.isfile(path_to_manifest): - raise Exception(f'No {MANIFEST_FILE_NAME} inside the build folder') + raise Exception(f'No "{MANIFEST_FILE_NAME}" inside the build folder: "{self.build_directory}"') # get inventory path_to_inventory = os.path.join(self.build_directory, INVENTORY_FILE_NAME) if not os.path.isfile(path_to_inventory): - raise Exception(f'No {INVENTORY_FILE_NAME} inside the build folder') + raise Exception(f'No "{INVENTORY_FILE_NAME}" inside the build folder: "{self.build_directory}"') # get admin user docs = load_yamls_file(path_to_manifest) cluster_model = select_single(docs, lambda x: x.kind == 'epiphany-cluster') admin_user = cluster_model.specification.admin_user + if not os.path.isfile(admin_user.key_path): + raise Exception(f'No SSH key file in folder: "{admin_user.key_path}"') # get and create the spec output dir if it does not exist spec_output = os.path.join(self.build_directory, SPEC_OUTPUT_DIR) diff --git a/core/src/epicli/cli/engine/spec/__init__.py b/core/src/epicli/cli/engine/spec/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core/src/epicli/setup.py b/core/src/epicli/setup.py index 2e088f8c62..7237829a6c 100644 --- a/core/src/epicli/setup.py +++ b/core/src/epicli/setup.py @@ -24,7 +24,6 @@ long_description=readme, author='Epiphany Team', author_email='', - python_requires='=3.7.*', url='https://github.com/epiphany-platform/epiphany', license=license, packages=find_packages(exclude=('tests', 'docs')), From 66c354aeacd2e4bec820e8725e853307550e0b5b Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij <11056665+seriva@users.noreply.github.com> Date: Tue, 7 Apr 2020 15:51:49 +0200 Subject: [PATCH 09/15] Update core/src/epicli/.vscode/launch.json Co-Authored-By: to-bar <46519524+to-bar@users.noreply.github.com> --- core/src/epicli/.vscode/launch.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/epicli/.vscode/launch.json b/core/src/epicli/.vscode/launch.json index b4ecff4ebb..744d077991 100644 --- a/core/src/epicli/.vscode/launch.json +++ b/core/src/epicli/.vscode/launch.json @@ -28,7 +28,7 @@ "pythonPath": "${config:python.pythonPath}", "env": { "PYTHONPATH": "${workspaceFolder}" }, "console": "integratedTerminal", - "args": ["${workspaceFolder}/tests/", "--junitxml=${workspaceFolder}/tests/results/unit_tests_results.xml"] + "args": ["${workspaceFolder}/tests/", "--junitxml=${workspaceFolder}/tests/results/unit_test_results.xml"] } ] -} \ No newline at end of file +} From 0f34636c2feccf67e687641bb1edcc41803f3bc6 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij <11056665+seriva@users.noreply.github.com> Date: Tue, 7 Apr 2020 15:52:22 +0200 Subject: [PATCH 10/15] Update core/src/epicli/cli/engine/TestEngine.py Co-Authored-By: to-bar <46519524+to-bar@users.noreply.github.com> --- core/src/epicli/cli/engine/TestEngine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/epicli/cli/engine/TestEngine.py b/core/src/epicli/cli/engine/TestEngine.py index 6970160d04..e6c4a5c284 100644 --- a/core/src/epicli/cli/engine/TestEngine.py +++ b/core/src/epicli/cli/engine/TestEngine.py @@ -25,7 +25,7 @@ def test(self): # get manifest path_to_manifest = os.path.join(self.build_directory, MANIFEST_FILE_NAME) if not os.path.isfile(path_to_manifest): - raise Exception(f'No "{MANIFEST_FILE_NAME}" inside the build folder: "{self.build_directory}"') + raise Exception(f'No "{MANIFEST_FILE_NAME}" inside the build directory: "{self.build_directory}"') # get inventory path_to_inventory = os.path.join(self.build_directory, INVENTORY_FILE_NAME) @@ -48,4 +48,4 @@ def test(self): spec_command = SpecCommand() spec_command.run(spec_output, path_to_inventory, admin_user.name, admin_user.key_path, self.group) - return 0 \ No newline at end of file + return 0 From 950f6b002dcc72d4fb01eeb7e2706d4aabb39d99 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij <11056665+seriva@users.noreply.github.com> Date: Tue, 7 Apr 2020 15:52:35 +0200 Subject: [PATCH 11/15] Update core/src/epicli/cli/engine/TestEngine.py Co-Authored-By: to-bar <46519524+to-bar@users.noreply.github.com> --- core/src/epicli/cli/engine/TestEngine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/epicli/cli/engine/TestEngine.py b/core/src/epicli/cli/engine/TestEngine.py index e6c4a5c284..883c5154d6 100644 --- a/core/src/epicli/cli/engine/TestEngine.py +++ b/core/src/epicli/cli/engine/TestEngine.py @@ -30,7 +30,7 @@ def test(self): # get inventory path_to_inventory = os.path.join(self.build_directory, INVENTORY_FILE_NAME) if not os.path.isfile(path_to_inventory): - raise Exception(f'No "{INVENTORY_FILE_NAME}" inside the build folder: "{self.build_directory}"') + raise Exception(f'No "{INVENTORY_FILE_NAME}" inside the build directory: "{self.build_directory}"') # get admin user docs = load_yamls_file(path_to_manifest) From 4022f4d0d95d167547b4f83287c727779517312e Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij <11056665+seriva@users.noreply.github.com> Date: Tue, 7 Apr 2020 15:52:51 +0200 Subject: [PATCH 12/15] Update core/src/epicli/cli/epicli.py Co-Authored-By: to-bar <46519524+to-bar@users.noreply.github.com> --- core/src/epicli/cli/epicli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/epicli/cli/epicli.py b/core/src/epicli/cli/epicli.py index 10d7eb8ca1..f48d2d8655 100644 --- a/core/src/epicli/cli/epicli.py +++ b/core/src/epicli/cli/epicli.py @@ -227,7 +227,7 @@ def test_parser(subparsers): sub_parser.add_argument('-b', '--build', dest='build_directory', type=str, required=True, help='Absolute path to directory with build artifacts.') sub_parser.add_argument('-g', '--group', choices=['all'] + SpecCommand.get_spec_groups(), default='all', action='store', dest='group', required=False, - help='Specify which group of tests needs to be run.') + help='Group of tests to be run, e.g. kafka.') def run_test(args): experimental_query() From 07ba409630460381e92ef91670190b7abda102c4 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij <11056665+seriva@users.noreply.github.com> Date: Tue, 7 Apr 2020 15:53:23 +0200 Subject: [PATCH 13/15] Update core/src/epicli/cli/helpers/build_saver.py Co-Authored-By: to-bar <46519524+to-bar@users.noreply.github.com> --- core/src/epicli/cli/helpers/build_saver.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/epicli/cli/helpers/build_saver.py b/core/src/epicli/cli/helpers/build_saver.py index ed2eefb333..ec2d63cd29 100644 --- a/core/src/epicli/cli/helpers/build_saver.py +++ b/core/src/epicli/cli/helpers/build_saver.py @@ -14,7 +14,7 @@ INVENTORY_FILE_NAME = 'inventory' ANSIBLE_OUTPUT_DIR = 'ansible/' ANSIBLE_VAULT_OUTPUT_DIR = 'vault/' -SPEC_OUTPUT_DIR = 'spec/' +SPEC_OUTPUT_DIR = 'spec_tests/' BUILD_EPICLI = 'BUILD_EPICLI' BUILD_LEGACY = 'BUILD_LEGACY_02X' @@ -142,4 +142,3 @@ def copy_files_recursively(src, dst): def copy_file(src, dst): shutil.copy2(src, dst) - From 532e167318c45ab8cbeb5e2e3648da6ff03ceeb1 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij <11056665+seriva@users.noreply.github.com> Date: Tue, 7 Apr 2020 15:54:47 +0200 Subject: [PATCH 14/15] Update core/src/epicli/cli/engine/TestEngine.py Co-Authored-By: to-bar <46519524+to-bar@users.noreply.github.com> --- core/src/epicli/cli/engine/TestEngine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/epicli/cli/engine/TestEngine.py b/core/src/epicli/cli/engine/TestEngine.py index 883c5154d6..a6f6a3e9bc 100644 --- a/core/src/epicli/cli/engine/TestEngine.py +++ b/core/src/epicli/cli/engine/TestEngine.py @@ -37,7 +37,7 @@ def test(self): cluster_model = select_single(docs, lambda x: x.kind == 'epiphany-cluster') admin_user = cluster_model.specification.admin_user if not os.path.isfile(admin_user.key_path): - raise Exception(f'No SSH key file in folder: "{admin_user.key_path}"') + raise Exception(f'No SSH key file in directory: "{admin_user.key_path}"') # get and create the spec output dir if it does not exist spec_output = os.path.join(self.build_directory, SPEC_OUTPUT_DIR) From b0590ca593660eba94b259e58dc03e1899592006 Mon Sep 17 00:00:00 2001 From: Luuk van Venrooij Date: Tue, 7 Apr 2020 16:11:35 +0200 Subject: [PATCH 15/15] Added comment for suppressing pytest warnings and better Rakefile error messages. --- core/src/epicli/data/common/tests/Rakefile | 8 ++++---- core/src/epicli/tests/pytest.ini | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/epicli/data/common/tests/Rakefile b/core/src/epicli/data/common/tests/Rakefile index 51e8781065..b307aa0a77 100644 --- a/core/src/epicli/data/common/tests/Rakefile +++ b/core/src/epicli/data/common/tests/Rakefile @@ -3,25 +3,25 @@ require 'rspec/core/rake_task' unless ENV['inventory'] print "ERROR: Inventory file must be specified by 'inventory' environment variable\n" - print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec_output=./spec_output/ spec:all\n" exit end unless ENV['user'] print "ERROR: Service user must be specified by 'user' environment variable\n" - print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec_output=./spec_output/ spec:all\n" exit end unless ENV['keypath'] print "ERROR: Private key path must be specified by 'keypath' environment variable\n" - print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec_output=./spec_output/ spec:all\n" exit end unless ENV['spec_output'] print "ERROR: Output path must be specified by 'spec_output' environment variable\n" - print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec:all\n" + print " e.g.) rake inventory=./hosts user=operations keypath=./id_rsa spec_output=./spec_output/ spec:all\n" exit end diff --git a/core/src/epicli/tests/pytest.ini b/core/src/epicli/tests/pytest.ini index 83116c7d2c..50d1b71088 100644 --- a/core/src/epicli/tests/pytest.ini +++ b/core/src/epicli/tests/pytest.ini @@ -1,3 +1,4 @@ [pytest] junit_family = xunit1 +; disable warnings since this will only complain about external Python modules we have no control over. addopts = -p no:warnings \ No newline at end of file