コード例 #1
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_set_cfg():

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.set_cfg('test', 'key', 'value')

    assert_equal(lpc.get_cfg('test', 'key'), lpc.cfgs['test']['key'])
コード例 #2
0
ファイル: tests_init_pass.py プロジェクト: xenisys/linchpin
def setup_lp_api():
    """
    Perform setup of LinchpinContext, lpc.load_config, and LinchPinAPI
    """

    global lpc
    global lpa

    global target
    global pinfile

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.setup_logging()
    lpc.workspace = os.path.realpath(mock_path)

    lpa = LinchpinAPI(lpc)
コード例 #3
0
def setup_lp_cli():

    """
    Perform setup of LinchpinContext, lpc.load_config, and LinchPinAPI
    """

    global lpctx
    global lpc

    global target
    global pinfile

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpctx = LinchpinCliContext()
    lpctx.load_config(lpconfig=config_path)
    lpctx.load_global_evars()
    lpctx.setup_logging()
    lpctx.workspace = os.path.realpath(mock_path)

    lpc = LinchpinCli(lpctx)
コード例 #4
0
def test_load_config():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)

#    assert_dict_equal.__self__.maxDiff = None
    assert_dict_equal(config_data, lpc.cfgs)
コード例 #5
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_get_cfg():

    lpc = LinchpinCliContext()
    lpc.load_config()
    cfg_value = lpc.get_cfg(section='lp', key='pkg')

    assert_equal(cfg_value, config_data['lp']['pkg'])
コード例 #6
0
def test_load_global_evars():

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.load_global_evars()

    assert_dict_equal(evars_data, lpc.evars)
コード例 #7
0
def test_get_cfg():

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    cfg_value = lpc.get_cfg('hookstates', 'up')

    assert_equal(cfg_value, config_data['hookstates']['up'])
コード例 #8
0
ファイル: test_context_pass.py プロジェクト: jjpryor/linchpin
def test_logging_setup():

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.setup_logging()

    assert os.path.isfile(logfile)
コード例 #9
0
def test_get_cfg():

    lpc = LinchpinCliContext()
    lpc.load_config()
    cfg_value = lpc.get_cfg(section='lp', key='pkg')

    assert_equal(cfg_value, config_data['lp']['pkg'])
コード例 #10
0
def test_set_cfg():

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.set_cfg('test', 'key', 'value')

    assert_equal(lpc.get_cfg('test', 'key'), lpc.cfgs['test']['key'])
コード例 #11
0
ファイル: tests_init_pass.py プロジェクト: xenisys/linchpin
def setup_lp_cli():
    """
    Perform setup of LinchpinContext, lpc.load_config, and LinchPinAPI
    """

    global lpctx
    global lpc

    global target
    global pinfile

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpctx = LinchpinCliContext()
    lpctx.load_config(lpconfig=config_path)
    lpctx.load_global_evars()
    lpctx.setup_logging()
    lpctx.workspace = os.path.realpath(mock_path)
    lpctx.pinfile = pinfile
    lpctx.pf_data = None
    lpctx.no_monitor = True
    lpctx.set_evar("no_monitor", True)
    lpctx.set_cfg("progress_bar", "no_progress", str(True))

    lpc = LinchpinCli(lpctx)
    lpc.disable_pbar = True
コード例 #12
0
def setup_lp_fetch_env():
    global lpc
    global lpcli

    global target
    global pinfile
    global mockpath

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.setup_logging()
    lpc.workspace = '/tmp/workspace/'
    mockpath = os.path.realpath(mock_path)

    if not os.path.exists(lpc.workspace):
        os.mkdir(lpc.workspace)

    lpcli = LinchpinCli(lpc)
コード例 #13
0
ファイル: tests_init_pass.py プロジェクト: xenisys/linchpin
def test_cli_create():

    lpctx = LinchpinCliContext()
    lpctx.load_config()
    lpctx.load_global_evars()
    lpc = LinchpinCli(lpctx)

    assert_equal(isinstance(lpc, LinchpinCli), True)
コード例 #14
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_set_evar():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.set_evar('test', 'me')

    assert_equal('me', lpc.evars['test'])
コード例 #15
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_get_evar():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    evar_value = lpc.get_evar('_async')

    assert_equal(evar_value, evars_data['_async'])
コード例 #16
0
def test_cli_create():

    lpctx = LinchpinCliContext()
    lpctx.load_config()
    lpctx.load_global_evars()
    lpc = LinchpinCli(lpctx)

    assert_equal(isinstance(lpc, LinchpinCli), True)
コード例 #17
0
def test_logging_setup():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.set_cfg('logger', 'file', config_data['logger']['file'])
    lpc.setup_logging()

    assert os.path.isfile(logfile)
コード例 #18
0
def test_get_evar():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    evar_value = lpc.get_evar('_async')

    assert_equal(evar_value, evars_data['_async'])
コード例 #19
0
def test_set_evar():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.set_evar('test', 'me')

    assert_equal('me', lpc.evars['test'])
コード例 #20
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_logging_setup():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.set_cfg('logger',
                'file',
                config_data['logger']['file'])
    lpc.setup_logging()

    assert os.path.isfile(logfile)
コード例 #21
0
def test_load_config():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    cfg_data = dict(config_data)

    # remove things that will always differ
    for cfg in ['lp', 'evars']:
        lpc.cfgs.pop(cfg)
        cfg_data.pop(cfg)

    assert_dict_equal(cfg_data['console'], lpc.cfgs['console'])
コード例 #22
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_load_config():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    cfg_data = dict(config_data)

    # remove things that will always differ
    for cfg in ['lp', 'evars']:
        lpc.cfgs.pop(cfg)
        cfg_data.pop(cfg)

    assert_dict_equal(cfg_data['console'],
                      lpc.cfgs['console'])
コード例 #23
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_load_global_evars():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()

    # remove workspace key as it's not from the config file
    for k in lpc.evars.keys():
        if k == 'workspace':
            if lpc.evars.get(k):
                lpc.evars.pop(k)
            if evars_data.get(k):
                evars_data.pop(k)

    assert_dict_equal(evars_data, lpc.evars)
コード例 #24
0
def test_log_info():

    lvl=logging.INFO
    msg = 'Info Msg'
    regex = '^{0}.*{1}'.format(logging.getLevelName(lvl), msg)

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.setup_logging()
    lpc.log_info(msg)

    with open(logfile) as f:
        line = f.readline()

    assert_regexp_matches(line, regex)
コード例 #25
0
def test_log_state():

    lvl=logging.DEBUG
    msg = '{0}: State Msg'.format(logging.getLevelName(lvl))
    regex = '^{0}.*STATE - {1}'.format(logging.getLevelName(lvl), msg)

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.setup_logging()
    lpc.log_state(msg)

    with open(logfile) as f:
        line = f.readline()

    assert_regexp_matches(line, regex)
コード例 #26
0
def test_load_global_evars():

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()

    # remove workspace key as it's not from the config file
    for k in lpc.evars.keys():
        if k == 'workspace':
            if lpc.evars.get(k):
                lpc.evars.pop(k)
            if evars_data.get(k):
                evars_data.pop(k)

    assert_dict_equal(evars_data, lpc.evars)
コード例 #27
0
def test_log_debug():

    lvl = logging.DEBUG
    msg = 'Debug Msg'
    regex = '^{0}.*{1}'.format(logging.getLevelName(lvl), msg)

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.set_cfg('logger', 'file', config_data['logger']['file'])
    lpc.setup_logging()
    lpc.log_debug(msg)

    with open(logfile) as f:
        line = f.readline()

    assertRegex(line, regex)
コード例 #28
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_log_debug():

    lvl=logging.DEBUG
    msg = 'Debug Msg'
    regex = '^{0}.*{1}'.format(logging.getLevelName(lvl), msg)

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.set_cfg('logger',
                'file',
                config_data['logger']['file'])
    lpc.setup_logging()
    lpc.log_debug(msg)

    with open(logfile) as f:
        line = f.readline()

    assert_regexp_matches(line, regex)
コード例 #29
0
def test_log_msg():

    # This test assumes the default message format found around line 139
    # of linchpin/cli/context.py

    lvl=logging.DEBUG
    msg = 'Test Msg'
    regex = '^{0}.*{1}'.format(logging.getLevelName(lvl), msg)

    lpc = LinchpinCliContext()
    lpc.load_config(config_path)
    lpc.setup_logging()
    lpc.log(msg, level=lvl)

    with open(logfile) as f:
        line = f.readline()

    assert_regexp_matches(line, regex)
コード例 #30
0
ファイル: test_context_pass.py プロジェクト: herlo/linch-pin
def test_log_msg():

    # This test assumes the default message format found around line 139
    # of linchpin/cli/context.py

    lvl=logging.DEBUG
    msg = 'Test Msg'
    regex = '^{0}.*{1}'.format(logging.getLevelName(lvl), msg)

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.set_cfg('logger',
                'file',
                config_data['logger']['file'])
    lpc.setup_logging()
    lpc.log(msg, level=lvl)

    with open(logfile) as f:
        line = f.readline()

    assert_regexp_matches(line, regex)
コード例 #31
0
def setup_lp_fetch_env():
    global lpc
    global lpcli

    global target
    global pinfile
    global mockpath

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.setup_logging()

    lpc.workspace = tempfile.mkdtemp(prefix='fetch_')
    print('workspace: {0}'.format(lpc.workspace))

    lpcli = LinchpinCli(lpc)
コード例 #32
0
ファイル: tests_fetch_pass.py プロジェクト: yprokule/linchpin
def setup_lp_fetch_env():
    global lpc
    global lpcli

    global target
    global pinfile
    global mockpath

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.setup_logging()

    lpc.workspace = tempfile.mkdtemp(prefix='fetch_')
    print(('workspace: {0}'.format(lpc.workspace)))

    lpcli = LinchpinCli(lpc)
コード例 #33
0
def _get_hosts(ctx, args, incomplete):
    lpctx = LinchpinCliContext()
    lpctx.load_config(lpconfig=None)
    lpctx.load_global_evars()
    lpcli = LinchpinCli(lpctx)
    return [k for k in lpcli.ctx.inventory.hosts.keys() if incomplete in k]