Skip to content

Commit

Permalink
Make skuba source directory configurable
Browse files Browse the repository at this point in the history
Add configuration parameter for skuba source directory.
Fix path for terraform and ssh files to be relative to
this source.

Signed-off-by: Pablo Chacin <pchacin@suse.com>
  • Loading branch information
Pablo Chacin committed Jun 3, 2019
1 parent 18ace51 commit 826db4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
20 changes: 15 additions & 5 deletions ci/infra/testrunner/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __new__(cls, yaml_path, *args, **kwargs):
obj = super().__new__(cls, *args, **kwargs)
obj.platform = None #"openstack, vmware, bare-metal
obj.workspace = None
obj.skuba_dir = None
obj.terraform_dir = None
obj.terraform_json_path = None
obj.ssh_key_option = None
Expand Down Expand Up @@ -85,6 +84,7 @@ class Skuba:
def __init__(self):
super().__init__()
self.binpath = None
self.srcpath = None

class Test:
def __init__(self):
Expand Down Expand Up @@ -117,6 +117,11 @@ def get_var_dict(yaml_path):
def inject_attrs_from_yaml(obj, vars, config_classes):
for key, value in obj.__dict__.items():

# FIXME: If key is the yaml file and is a config class, but has no subelements
# the logic fails. This happens if we comment all values under the key, for example:
# key:
# # subkey: value #commented!
#
if key in vars and isinstance(value, config_classes):
BaseConfig.inject_attrs_from_yaml(value, vars[key], config_classes)
continue
Expand Down Expand Up @@ -144,19 +149,24 @@ def inject_attrs_from_yaml(obj, vars, config_classes):
@staticmethod
def finalize(conf):
conf.workspace = os.path.expanduser(conf.workspace)
conf.skuba_dir = os.path.realpath(os.path.join(conf.workspace, "skuba"))
conf.terraform_dir = os.path.join(conf.skuba_dir, "ci/infra/{}".format(conf.platform))
conf.terraform_json_path = os.path.join(conf.workspace, Constant.TERRAFORM_JSON_OUT)

if not conf.skuba.binpath:
conf.skuba.binpath = os.path.join(conf.workspace, 'go/bin/skuba')

if not conf.skuba.srcpath:
conf.skuba.srcpath = os.path.realpath(os.path.join(conf.workspace, "skuba"))

# TODO: add terraform dir as a configuration parameter
# and set to default if not specified
conf.terraform_dir = os.path.join(conf.skuba.srcpath, "ci/infra/{}".format(conf.platform))

if not conf.jenkins.job_name:
conf.jenkins.job_name = conf.username
conf.jenkins.run_name = "{}-{}".format(conf.jenkins.job_name, str(conf.jenkins.build_number))

#TODO: add the path to shared ssh credentials as a configuration parameter
if conf.ssh_key_option == "id_shared":
conf.ssh_key_option = os.path.join(conf.skuba_dir, "ci/infra/id_shared")
conf.ssh_key_option = os.path.join(conf.skuba.srcpath, "ci/infra/id_shared")
elif conf.ssh_key_option == "id_rsa":
conf.ssh_key_option = os.path.join(os.path.expanduser("~"), ".ssh/id_rsa")

Expand Down
14 changes: 6 additions & 8 deletions ci/infra/testrunner/utils/skuba.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Skuba:
def __init__(self, conf):
self.conf = conf
self.binpath = self.conf.skuba.binpath
self.srcpath = self.conf.skuba.srcpath
self.utils = Utils(self.conf)
self.cwd = "{}/test-cluster".format(self.conf.workspace)

Expand All @@ -33,16 +34,10 @@ def _verify_bootstrap_dependency(self):
@timeout(600)
@step
def create_skuba(self):
"""Configure Environment"""
"""Buids skuba from source"""
self.utils.runshellcommand("rm -fr go")
self.utils.runshellcommand("mkdir -p go/src/github.com/SUSE")
self.utils.runshellcommand("cp -a skuba go/src/github.com/SUSE/")
self.utils.gorun("go version")
print("Building skuba")
self.utils.gorun("make")

@step
def cleanup(self):
self.utils.runshellcommand("cp -a {} go/src/github.com/SUSE/".format(self.srcpath))
self.utils.gorun("go version")
print("Building skuba")
self.utils.gorun("make")
Expand All @@ -60,10 +55,13 @@ def cleanup(self):
cmd = 'chmod -R 777 {}'.format(self.conf.workspace)
self.utils.runshellcommand(cmd)

# TODO: appending workspace is not necessary as runshellcommand has it as workdirectory
dirs = [os.path.join(self.conf.workspace, "test-cluster"),
os.path.join(self.conf.workspace, "go"),
os.path.join(self.conf.workspace, "logs"),
#TODO: move this to utils as ssh_cleanup
os.path.join(self.conf.workspace, "ssh-agent-sock"),
#TODO: duplicated. Remove
os.path.join(self.conf.workspace, "test-cluster")]

cleanup_failure = False
Expand Down
1 change: 1 addition & 0 deletions ci/infra/testrunner/vars/openstack.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ nodeuser: "sles" # Default node username
# Skuba setup
skuba:
binpath: "" # path to skuba binary
srcpath: "" # path to skuba source

openstack:
openrc: "PATH TO YOUR OPENRC FILE" #os.getenv("OPENRC")
Expand Down

0 comments on commit 826db4d

Please sign in to comment.