Skip to content

Commit c4be975

Browse files
author
Yair Fried
committed
Merge branch 'master' of github.com:rhosqeauto/InfraRed into old_install
2 parents f82839d + bc86ce4 commit c4be975

6 files changed

Lines changed: 254 additions & 97 deletions

File tree

cli/conf.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import ConfigParser
2-
3-
import clg
42
import os
53
import yaml
64

5+
import clg
6+
import yamlordereddictloader
7+
78
from cli import exceptions
89
from cli import utils
910

@@ -43,38 +44,41 @@ class SpecManager(object):
4344

4445
SPEC_EXTENSION = '.spec'
4546

46-
def __init__(self, config):
47-
self.config = config
47+
@classmethod
48+
def parse_args(cls, module_name, config, args=None):
49+
"""
50+
Looks for all the specs for specified module
51+
and parses the commandline input arguments accordingly.
4852
49-
def get_specs(self, module_name):
53+
:param module_name: the module name: installer|provisioner|tester
54+
"""
55+
cmd = clg.CommandLine(cls._get_specs(module_name, config))
56+
return cmd.parse(args)
57+
58+
@classmethod
59+
def _get_specs(cls, module_name, config):
5060
"""
5161
Gets specs files as a dict from settings/<module_name> folder.
5262
:param module_name: the module name: installer|provisioner|tester
5363
"""
5464
res = {}
55-
for spec_file in self.__get_all_specs(subfolder=module_name):
56-
spec = yaml.load(open(spec_file))
65+
for spec_file in cls._get_all_specs(config, subfolder=module_name):
66+
spec = yaml.load(open(spec_file),
67+
Loader=yamlordereddictloader.Loader)
5768
utils.dict_merge(res, spec)
5869
return res
5970

60-
def parse_args(self, module_name, args=None):
61-
"""
62-
Looks for all the specs for specified module
63-
and parses the commandline input arguments accordingly.
64-
"""
65-
cmd = clg.CommandLine(self.get_specs(module_name))
66-
return cmd.parse(args)
67-
68-
def __get_all_specs(self, subfolder=None):
71+
@classmethod
72+
def _get_all_specs(cls, config, subfolder=None):
6973
root_dir = utils.validate_settings_dir(
70-
self.config.get('defaults', 'settings'))
74+
config.get('defaults', 'settings'))
7175
if subfolder:
7276
root_dir = os.path.join(root_dir, subfolder)
7377

7478
res = []
7579
for dirpath, _, filenames in os.walk(root_dir):
7680
for filename in [f for f in filenames
77-
if f.endswith(self.SPEC_EXTENSION)]:
81+
if f.endswith(cls.SPEC_EXTENSION)]:
7882
res.append(os.path.join(dirpath, filename))
7983

8084
return res

cli/exceptions.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ def __init__(self, env_var):
3535

3636

3737
class IRPlaybookFailedException(IRException):
38-
def __init__(self, playbook):
39-
super(self.__class__, self).__init__(
40-
'Playbook "%s" failed!' % playbook)
38+
def __init__(self, playbook, message=""):
39+
msg = 'Playbook "%s" failed!' % playbook
40+
msg = msg + message if message else msg
41+
super(self.__class__, self).__init__(msg)
4142

4243

4344
class IRYAMLConstructorError(IRException):
@@ -57,3 +58,14 @@ def __init__(self, trace_message):
5758

5859
class IRNotImplemented(IRException):
5960
pass
61+
62+
63+
class IRUnknownApplicationException(IRException):
64+
"""
65+
This exceptions is raised when unknown application is
66+
started by user.
67+
"""
68+
def __init__(self, app_name):
69+
self.app_name = app_name
70+
super(IRUnknownApplicationException, self).__init__(
71+
"Application is unknown: '{}'".format(app_name))

cli/execute.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ def execute_ansible(playbook, args):
136136

137137
print ""
138138
if len(failed_hosts) > 0:
139-
raise Exception(2)
139+
raise exceptions.IRPlaybookFailedException(
140+
playbook, "Failed hosts: %s" % failed_hosts)
140141
if len(unreachable_hosts) > 0:
141-
raise Exception(3)
142+
raise exceptions.IRPlaybookFailedException(
143+
playbook, "Unreachable hosts: %s" % unreachable_hosts)
142144

143145

144146
def ansible_wrapper(args):

cli/install.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ def get_args(entry_point, args=None):
3838
"""
3939
:return args: return loaded arguments from CLI
4040
"""
41-
42-
spec_manager = conf.SpecManager(CONF)
43-
args = spec_manager.parse_args(entry_point, args=args)
41+
# todo(obaranov) remove one-line method.
42+
args = conf.SpecManager.parse_args(entry_point, CONF, args=args)
4443
return args
4544

4645

0 commit comments

Comments
 (0)