Skip to content

Commit

Permalink
Merge pull request CentOS-PaaS-SIG#372 from herlo/develop
Browse files Browse the repository at this point in the history
Move to v1.0.4
  • Loading branch information
herlo committed Sep 22, 2017
2 parents 4f9588e + f007d00 commit a8aa3d5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
9 changes: 8 additions & 1 deletion linchpin/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def __init__(self, ctx):
self.workspace = os.path.realpath(os.path.curdir)




def get_cfg(self, section=None, key=None, default=None):
"""
Get cfgs value(s) by section and/or key, or the whole cfgs object
Expand Down Expand Up @@ -208,7 +210,7 @@ def set_magic_vars(self):
self.set_evar('topology_name', topology_name)


def run_playbook(self, pinfile, targets='all', playbook='up'):
def run_playbook(self, pinfile, targets=[], playbook='up'):
"""
This function takes a list of targets, and executes the given
playbook (provison, destroy, etc.) for each provided target.
Expand Down Expand Up @@ -271,6 +273,10 @@ def run_playbook(self, pinfile, targets='all', playbook='up'):
else:
raise LinchpinError("One or more invalid targets found")

# create localhost file in workspace for user if it doesn't exist
if not os.path.exists('{0}/localhost'.format(self.workspace)):
with open('{0}/localhost'.format(self.workspace), 'w') as f:
f.write('localhost\n')

for target in targets:
self.set_evar('topology', self.find_topology(
Expand All @@ -297,6 +303,7 @@ def run_playbook(self, pinfile, targets='all', playbook='up'):
if 'pre' in self.pb_hooks:
self.hook_state = '{0}{1}'.format('pre', playbook)


# invoke the appropriate playbook
return_code, results[target] = (
self._invoke_playbook(playbook=playbook,
Expand Down
19 changes: 14 additions & 5 deletions linchpin/tests/api/test_init_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,27 @@ def test_get_evar_item():
# lpc.load_config()
# lpa = LinchpinAPI(lpc)


@with_setup(setup_lp_api)
def test_run_playbook():

pf_w_path = '{0}/{1}'.format(lpc.workspace, pinfile)
return_code, results = lpa.run_playbook(pf_w_path, targets=[provider])

for res in results[provider]:
name = res._task.get_name()
failed = False
if res.is_failed():
failed = True
failed = False
if return_code:
failed = True
for res in results[provider]:
name = res._task.get_name()
if res.is_failed():
print('name: {}'.format(name))

assert not failed


@with_setup(setup_lp_fetch_env)
def test_fetch_local():

src_path = os.path.join(mockpath, 'fetch/ws1')
src_uri = 'file://{0}'.format(src_path)
lpa.lp_fetch(src_uri, 'workspace', None)
Expand All @@ -233,8 +238,10 @@ def test_fetch_local():
shutil.rmtree(os.path.join(os.path.expanduser('~'), '.cache/linchpin/'))
assert_list_equal(src_list, dest_list)


@with_setup(setup_lp_fetch_env)
def test_fetch_git():

src_url = 'https://github.com/agharibi/SampleLinchpinDirectory.git'
lpa.lp_fetch(src_url, 'topologies', 'ws1')

Expand All @@ -246,8 +253,10 @@ def test_fetch_git():

assert_list_equal(src_list, dest_list)


@with_setup(setup_lp_fetch_env)
def test_fetch_cache():

src_url = 'https://github.com/agharibi/SampleLinchpinDirectory.git'
lpa.lp_fetch(src_url, 'topologies', 'ws1')
lpa.lp_fetch(src_url, 'topologies', 'ws1')
Expand Down
8 changes: 5 additions & 3 deletions linchpin/tests/mockdata/contextdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def load_config_data(self, provider='dummy'):
self.cfg_data['logger']['file'] = self.logfile

self.evars = self.cfg_data.get('evars', {})



def load_new_config(self, provider='dummy'):

self.cfg_data = {}

expanded_path = None
Expand All @@ -100,7 +102,7 @@ def load_new_config(self, provider='dummy'):
existing_paths.append(expanded_path)

if len(existing_paths) == 0:
raise Linchpinerror('Configuration file not foud in'
raise LinchpinError('Configuration file not foud in'
' path: {0}'.format(CONFIG_PATH))
try:
for path in existing_paths:
Expand All @@ -122,7 +124,7 @@ def load_new_config(self, provider='dummy'):
except ConfigParser.InterpolationSyntaxError as e:
raise LinchpinError('Unable to parse configuration file properly:'
'{0}'.format(e))

# override logger file
self.cfg_data['logger']['file'] = self.logfile

Expand Down
1 change: 1 addition & 0 deletions linchpin/tests/mockdata/dummy/fetch/ws1/localhost
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
1 change: 1 addition & 0 deletions linchpin/tests/mockdata/dummy/fetch/ws2/localhost
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
1 change: 1 addition & 0 deletions linchpin/tests/mockdata/dummy/localhost
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
4 changes: 2 additions & 2 deletions linchpin/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__short_version__ = '1.0.3'
__version__ = '1.0.3'
__short_version__ = '1.0.4'
__version__ = '1.0.4'

0 comments on commit a8aa3d5

Please sign in to comment.