fix: for timmy as library

move config to NodeManager

Change-Id: I719029de66d01eda36dc55fdf2f23d09e9abd78f
This commit is contained in:
Aleksandr Dobdin 2016-09-22 11:32:55 +00:00
parent a544641657
commit acc17e3fe8
8 changed files with 31 additions and 17 deletions

View File

@ -15,7 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from timmy.conf import load_conf
from timmy.env import project_name, version
from timmy.nodes import Node
from timmy.tools import signal_wrapper
@ -212,10 +211,8 @@ def main(argv=None):
logger = logging.getLogger(project_name)
logger.addHandler(log_handler)
logger.setLevel(loglevel)
conf = load_conf(args.config)
if inventory:
inventory.add_conf(conf)
inventory.check_args(args, conf)
conf = inventory.NodeManager.load_conf(args.config)
inventory.check_args(args, conf)
if args.put or args.command or args.script or args.get:
conf['shell_mode'] = True
conf['do_print_results'] = True

View File

@ -22,7 +22,7 @@ from pkg_resources import resource_filename as resource_fn
from timmy.env import project_name
def load_conf(filename):
def init_default_conf():
"""Configuration parameters"""
conf = {}
conf['hard_filter'] = {}
@ -71,7 +71,11 @@ def load_conf(filename):
conf['do_print_results'] = False
'''Clean - erase previous results in outdir and archive_dir dir, if any.'''
conf['clean'] = True
if filename:
return conf
def update_conf(conf, filename):
if filename is not None:
conf_extra = load_yaml_file(filename)
conf.update(**conf_extra)
return conf
@ -79,5 +83,6 @@ def load_conf(filename):
if __name__ == '__main__':
import yaml
conf = load_conf('config.yaml')
conf = init_default_conf()
conf = update_conf(conf, 'config.yaml')
print(yaml.dump(conf))

View File

@ -16,7 +16,7 @@
# under the License.
project_name = 'timmy'
version = '1.21.0'
version = '1.22.0'
if __name__ == '__main__':
import sys

View File

@ -21,6 +21,7 @@ import os
import sys
import urllib2
from timmy import tools
from timmy import conf
from timmy.nodes import NodeManager as BaseNodeManager
from timmy.nodes import Node as BaseNode
@ -100,6 +101,7 @@ def add_conf(conf):
'''Do not collect from /var/log/remote/<node>
if node is in the array of nodes filtered out by soft filter'''
conf['fuel_logs_exclude_filtered'] = True
return conf
class Node(BaseNode):
@ -189,6 +191,13 @@ class Node(BaseNode):
class NodeManager(BaseNodeManager):
@staticmethod
def load_conf(filename):
config = conf.init_default_conf()
config = add_conf(config)
config = conf.update_conf(config, filename)
return config
def __init__(self, conf, nodes_json=None, logger=None):
self.base_init(conf, logger)
self.token = self.conf['fuel_api_token']

View File

@ -30,9 +30,5 @@ def check_args(args, conf):
pass
def add_conf(conf):
pass
class NodeManager(BaseNodeManager):
pass

View File

@ -21,14 +21,15 @@ main module
from copy import deepcopy
from datetime import datetime, date, timedelta
from timmy import conf
from timmy.env import project_name
from timmy import tools
from tools import w_list, run_with_lock
import logging
import os
import re
import shutil
import sys
import tools
class Node(object):
@ -497,7 +498,13 @@ class Node(object):
class NodeManager(object):
"""Class nodes """
"""Class NodeManager """
@staticmethod
def load_conf(filename):
config = conf.init_default_conf()
config = conf.update_conf(config, filename)
return config
def __init__(self, conf, nodes_json, logger=None):
self.base_init(conf, logger)

View File

@ -54,7 +54,7 @@ class ConfTest(unittest.TestCase):
'do_print_results': bool,
'clean': bool
}
config = conf.load_conf(None)
config = conf.init_default_conf()
for key in param_types:
self.assertEqual(type(config[key]), param_types[key],
type_error % (key, type(config[key]),

View File

@ -49,7 +49,7 @@ class RQDefault(unittest.TestCase):
sep_error = ('default %s value %s has path separator(s) - this '
'will cause NodeManager to search the file by full path '
'instead of looking in the default rq/%s path.')
config = conf.load_conf(None)
config = conf.init_default_conf()
for rqfile in config['rqfile']:
f = rqfile['file']
if os.path.sep in f: