-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1134 from seriva/feature/integrated-spec
- Moved spec tests to data folder - Added epicli test command for running spec tests - Added spec test output to build folder - Added spec test dependencies to epicli production container - Restructured Python unit tests and fix some minor issues
- Loading branch information
Showing
49 changed files
with
157 additions
and
1,101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
self.group = input_data.group | ||
|
||
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 directory: "{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 directory: "{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 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) | ||
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, self.group) | ||
|
||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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: | ||
def __init__(self): | ||
self.logger = Log(__name__) | ||
|
||
|
||
def __init__(self): | ||
self.logger = Log(__name__) | ||
|
||
|
||
def check_dependencies(self): | ||
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) | ||
|
||
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) | ||
|
||
|
||
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:{group}' | ||
|
||
self.logger.info(f'Running: "{cmd}"') | ||
|
||
logpipe = LogPipe(__name__) | ||
with Popen(cmd.split(' '), cwd=SPEC_TEST_PATH, env=env, stdout=logpipe, stderr=logpipe) as sp: | ||
logpipe.close() | ||
|
||
if sp.returncode != 0: | ||
raise Exception(f'Error running: "{cmd}"') | ||
else: | ||
self.logger.info(f'Done running: "{cmd}"') | ||
|
||
|
||
@staticmethod | ||
def get_spec_groups(): | ||
return os.listdir(SPEC_TEST_PATH + '/spec') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.