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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,14 +21,15 @@ main module
from copy import deepcopy from copy import deepcopy
from datetime import datetime, date, timedelta from datetime import datetime, date, timedelta
from timmy import conf
from timmy.env import project_name from timmy.env import project_name
from timmy import tools
from tools import w_list, run_with_lock from tools import w_list, run_with_lock
import logging import logging
import os import os
import re import re
import shutil import shutil
import sys import sys
import tools
class Node(object): class Node(object):
@ -497,7 +498,13 @@ class Node(object):
class NodeManager(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): def __init__(self, conf, nodes_json, logger=None):
self.base_init(conf, logger) self.base_init(conf, logger)

View File

@ -54,7 +54,7 @@ class ConfTest(unittest.TestCase):
'do_print_results': bool, 'do_print_results': bool,
'clean': bool 'clean': bool
} }
config = conf.load_conf(None) config = conf.init_default_conf()
for key in param_types: for key in param_types:
self.assertEqual(type(config[key]), param_types[key], self.assertEqual(type(config[key]), param_types[key],
type_error % (key, type(config[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 ' sep_error = ('default %s value %s has path separator(s) - this '
'will cause NodeManager to search the file by full path ' 'will cause NodeManager to search the file by full path '
'instead of looking in the default rq/%s 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']: for rqfile in config['rqfile']:
f = rqfile['file'] f = rqfile['file']
if os.path.sep in f: if os.path.sep in f: