示例#1
0
def test_guess_flavor_flavor(prepare_os, mock_image_cfg, mock_env_cfg, config):
    p = prepare_os.PrepOS(mock_image_cfg, mock_env_cfg)
    with mock.patch.object(p, 'os') as mock_os:
        mock_os.fuzzy_find_flavor.return_value = sentinel.flavor
        assert p.guess_flavor(config.Config({'nova': {
            'flavor': 'x'
        }})) == sentinel.flavor
示例#2
0
def test_prepare_ssh_empty(prepare_os, config, mock_env_cfg):
    p = prepare_os.PrepOS(config.Config({'glance': {
        'name': 'foo'
    }}), mock_env_cfg)
    p.ip = sentinel.ip
    p.prepare_ssh()
    assert p.ssh is None
示例#3
0
def notest_get_environment_not_ok(config):
    mock_config = mock.mock_open(
        read_data='{"env1":{ "os_tenant_name": "good_name"}}')
    with mock.patch.object(config, "open", mock_config):
        with mock.patch.object(config.os.path, "isfile", return_value=True):
            conf = config.Config()
            with pytest.raises(config.TestEnvironmentNotFoundInConfigError):
                conf.get_environment('env3')["os_tenant_name"]
示例#4
0
def test_add_config_simple(config):
    with tempfile.NamedTemporaryFile() as mock_cfg:
        mock_cfg.write('a: b')
        mock_cfg.flush()
        c = config.Config()
        c.add_config(mock_cfg.name)
        assert c.get('a') == 'b'
        assert c.config_list == [mock_cfg.name]
示例#5
0
def test_RotateCommand_actual(commands, mock_env_cfg, config):
    parser, obj = create_subparser(commands.RotateCommand)
    args = parser.parse_args(['rotate', 'uploadlabel'])
    with mock.patch.object(commands.config, "UploadEnvConfig") as uec:
        uec.return_value = config.Config({"uploadlabel": mock_env_cfg})
        with mock.patch.object(commands.osclient, "OSClient"):
            args.command(args)
    assert obj.upload_env
示例#6
0
def test_guess_flavor_flavor_id(prepare_os, mock_image_cfg, mock_env_cfg,
                                config):
    p = prepare_os.PrepOS(mock_image_cfg, mock_env_cfg)
    with mock.patch.object(p, 'os') as mock_os:
        mock_os.get_flavor = lambda x: x
        assert p.guess_flavor(config.Config({'nova': {
            'flavor_id': 'x'
        }})) == 'x'
示例#7
0
def test_spawn_instance_no_config_drive(prepare_os, mock_image_cfg, config):
    env = {'keystone': {}, 'nova': {'flavor': 'mock_flavor'}}
    prep_os = prepare_os.PrepOS(mock_image_cfg, config.Config(env))
    with mock.patch.object(prepare_os.osclient, "OSClient") as mock_os:
        prep_os.os_key = mock.MagicMock()
        prep_os.connect()
        prep_os.spawn_instance(1)
        assert mock_os.return_value.boot_instance.call_args[1][
            'config_drive'] is False
示例#8
0
def test_ObsoleteCommand_actual(commands, mock_env_cfg, config):
    parser, obj = create_subparser(commands.ObsoleteCommand)
    args = parser.parse_args(['mark-obsolete', 'uploadlabel', 'myuuid'])
    assert args.uuid == 'myuuid'
    with mock.patch.object(commands.config, "UploadEnvConfig") as uec:
        uec.return_value = config.Config({'uploadlabel': mock_env_cfg})
        with mock.patch.object(commands.osclient, "OSClient"):
            args.command(args)
    assert obj.upload_env
示例#9
0
def test_UploadCommand_no_glance_section(commands, mock_env_cfg, config):
    img_config = {'filename': 'foobar'}
    parser, obj = create_subparser(commands.UploadCommand)
    args = parser.parse_args(['upload', 'label', 'uploadlabel'])
    with mock.patch.object(commands.config, "UploadEnvConfig") as uec:
        uec.return_value = config.Config({"uploadlabel": mock_env_cfg})
        with mock.patch.object(commands.osclient, "OSClient"):
            with mock.patch.object(commands.config, "ImageConfig") as ic:
                ic.return_value.__getitem__.return_value = img_config
                with pytest.raises(commands.NotFoundInConfigError):
                    args.command(args)
示例#10
0
def mock_image_cfg(config):
    image = config.Config({
        'glance': {
            'name': 'foo'
        },
        'filename': sentinel.filename,
        'tests': {
            'ssh': {
                'username': '******'
            }
        }
    })
    return image
示例#11
0
def test_add_config_double(config, capfd):
    with tempfile.NamedTemporaryFile() as mock_cfg1:
        mock_cfg1.write('some_label: bad!')
        mock_cfg1.flush()
        with tempfile.NamedTemporaryFile() as mock_cfg2:
            mock_cfg2.write('some_label: good')
            mock_cfg2.flush()
            c = config.Config()
            c.add_config(mock_cfg1.name)
            c.add_config(mock_cfg2.name)
            assert c.get('some_label') == 'good'
            assert c.config_list == [mock_cfg1.name, mock_cfg2.name]
    out = capfd.readouterr()[0]
    assert "redefines some_label" in out
示例#12
0
def test_UploadCommand_actual_with_obsolete(commands, cred, mock_env_cfg,
                                            mock_image_cfg, config):
    parser, obj = create_subparser(commands.UploadCommand)
    args = parser.parse_args(['upload', 'label', 'uploadlabel'])
    assert args.imagelabel == 'label'
    assert args.no_obsolete is False
    assert args.images_config is None
    assert args.filename is None

    with mock.patch.object(commands.config,
                           "UploadEnvConfig",
                           autospec=True,
                           strict=True) as uec:
        uec.return_value = config.Config({'uploadlabel': mock_env_cfg})
        with mock.patch.object(commands.osclient, "OSClient") as mock_os:
            mock_os.return_value.older_images.return_value = [
                sentinel.one, sentinel.two
            ]
            with mock.patch.object(commands.config,
                                   "ImageConfig",
                                   autospec=True,
                                   strict=True) as ic:
                ic.return_value = config.Config({'label': mock_image_cfg})
                args.command(args)
示例#13
0
def mock_env_cfg(config):
    env = config.Config({
        'keystone': {
            'auth_url': sentinel.auth,
            'tenant_name': sentinel.tenant,
            'password': sentinel.password,
            'username': sentinel.user
        },
        'nova': {
            'flavor': 'example',
            'nics': [
                {'net_id': sentinel.uuid1},
                {'net_id': sentinel.uuid2}
            ]
        }
    })
    return env
示例#14
0
def test__userdata_with_userdata_file(prepare_os, mock_image_cfg, config):
    with tempfile.NamedTemporaryFile() as t:
        t.write('{"foo":"bar"}')
        t.flush()
        env = config.Config({
            'keystone': {
                'auth_url': sentinel.auth,
                'tenant_name': sentinel.tenant,
                'password': sentinel.password,
                'username': sentinel.user
            },
            'nova': {
                'flavor': 'example',
                'nics': [
                    {'net_id': sentinel.uuid1},
                    {'net_id': sentinel.uuid2}
                ],
                'userdata_file': t.name
            }
        })

        prep_os = prepare_os.PrepOS(mock_image_cfg, env)
        assert prep_os._userdata(env) == '{"foo":"bar"}'
示例#15
0
def test_config_repr(config):
    d = {"a": 1}
    r = repr(config.Config(d))
    assert r == "Config({'a': 1})"
示例#16
0
def test_merge_config_snippet_with_overwrite(config, capfd):
    c = config.Config({'a': 1, 'b': 2, 'c': 3})
    c.merge_config_snippet({'a': 2}, 'new_name')
    assert c.config == {'a': 2, 'b': 2, 'c': 3}
    out = capfd.readouterr()[0]
    assert 'redefines' in out
示例#17
0
def test__userdata_no_userdata(prepare_os, mock_image_cfg, mock_env_cfg,
                               config):
    prep_os = prepare_os.PrepOS(mock_image_cfg, mock_env_cfg)
    assert prep_os._userdata(config.Config({})) is None
示例#18
0
def test_add_config_no_file(config):
    with mock.patch.object(config.os.path, "isfile", return_value=False):
        c = config.Config()
        with pytest.raises(config.ConfigNotFound):
            c.add_config(sentinel.not_a_file)
示例#19
0
def test_gather_snippets(config, file_val, res):
    with mock.patch.object(config.os,
                           'listdir',
                           return_value=['file3', 'file1', 'file2']):
        with mock.patch.object(config.os.path, 'isfile', side_effect=file_val):
            assert config.Config().gather_snippets('path') == res
示例#20
0
def test_len(config, data):
    assert len(config.Config(data)) == len(data)
示例#21
0
 def _prep_conf(self, config):
     c = config.Config()
     c.CONFIG_SEARCH_PATH = ['etc/dibctl', './dibctl', './']
     c.DEFAULT_CONFIG_NAME = 'config.yaml'
     c.CONF_D_NAME = 'config.d'
     return c
示例#22
0
def test_non_zero_true(config):
    assert bool(config.Config({'a': 1})) is True
示例#23
0
def test_empty_is_false(config):
    assert bool(config.Config()) is False
示例#24
0
def test_get_max(config, conf1, conf2, path, result):
    c1 = config.Config(conf1)
    c2 = config.Config(conf2)
    assert config.get_max(c1, c2, path, 99) == result
示例#25
0
def test_gather_snippets_empty(config):
    with mock.patch.object(config.os, 'listdir', return_value=[]):
        assert config.Config().gather_snippets('path') == []
示例#26
0
def test_config_dict_conversion(config):
    d = {"a": 1, "b": "c"}
    x = config.Config(d)
    y = dict(x)
    assert y == d
示例#27
0
def test_config_str(config):
    d = {"a": 1}
    assert str(config.Config(d)) == str(d)
示例#28
0
def test_config_items(config):
    d = {"a": 1}
    l = list(config.Config(d).items())
    assert l == [('a', 1)]
示例#29
0
def test_guess_flavor_flavor_bad(prepare_os, mock_image_cfg, mock_env_cfg,
                                 config, bad):
    p = prepare_os.PrepOS(mock_image_cfg, mock_env_cfg)
    with mock.patch.object(p, 'os'):
        with pytest.raises(prepare_os.FlavorError):
            assert p.guess_flavor(config.Config(bad))
示例#30
0
def test_config_in(config, input, query, result):
    c = config.Config(input)
    c.config_file = 'foo'
    assert (query in c) is result