Example #1
0
def test_write_keyring(tmpdir):
    with tmpdir.join("ceph.conf").open("w"):
        pass
    with tmpdir.join("ceph.client.admin.keyring").open("w"):
        pass

    etc_ceph = os.path.join(str(tmpdir), "etc", "ceph")
    os.makedirs(etc_ceph)

    distro = MagicMock()
    distro.conn = MagicMock()
    remotes.write_file.func_defaults = (str(tmpdir),)
    distro.conn.remote_module = remotes
    distro.conn.remote_module.write_conf = Mock()

    with patch("ceph_deploy.admin.hosts"):
        with patch("ceph_deploy.admin.hosts.get", MagicMock(return_value=distro)):
            with directory(str(tmpdir)):
                main(args=["admin", "host1"])

    keyring_file = os.path.join(etc_ceph, "ceph.client.admin.keyring")
    assert os.path.exists(keyring_file)

    file_mode = oct(os.stat(keyring_file).st_mode & 0777)
    assert file_mode == oct(0600)
Example #2
0
def test_new(tmpdir, capsys):
    with tmpdir.join('ceph.conf').open('w') as f:
        f.write("""\
[global]
fsid = 6ede5564-3cf1-44b5-aa96-1c77b0c3e1d0
mon initial members = host1
""")

    fake_ip_addresses = lambda x: ['10.0.0.1']
    try:
        with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses):
            with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'):
                with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x):
                    with patch('ceph_deploy.new.hosts'):
                        with directory(str(tmpdir)):
                            main(['-v', 'new', '--no-ssh-copykey', 'host1'])
    except SystemExit as e:
        raise AssertionError('Unexpected exit: %s', e)
    out, err = capsys.readouterr()
    err = err.lower()
    assert 'creating new cluster named ceph' in err
    assert 'monitor host1 at 10.0.0.1' in err
    assert 'resolving host host1' in err
    assert "monitor initial members are ['host1']" in err
    assert "monitor addrs are ['10.0.0.1']" in err
def test_write_keyring(tmpdir):
    with tmpdir.join('ceph.conf').open('w'):
        pass
    with tmpdir.join('ceph.client.admin.keyring').open('w'):
        pass

    etc_ceph = os.path.join(str(tmpdir), 'etc', 'ceph')
    os.makedirs(etc_ceph)

    distro = MagicMock()
    distro.conn = MagicMock()
    remotes.write_file.func_defaults = (0644, str(tmpdir), -1, -1)
    distro.conn.remote_module = remotes
    distro.conn.remote_module.write_conf = Mock()

    with patch('ceph_deploy.admin.hosts'):
        with patch('ceph_deploy.admin.hosts.get', MagicMock(return_value=distro)):
            with directory(str(tmpdir)):
                main(args=['admin', 'host1'])

    keyring_file = os.path.join(etc_ceph, 'ceph.client.admin.keyring')
    assert os.path.exists(keyring_file)

    file_mode = oct(os.stat(keyring_file).st_mode & 0777)
    assert file_mode == oct(0600)
Example #4
0
 def new(*args):
     with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses):
         with patch('ceph_deploy.new.hosts'):
             with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'):
                 with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x):
                     with directory(str(tmpdir)):
                         main(args=['new'] + list(args))
                         with tmpdir.join('ceph.conf').open() as f:
                             cfg = conf.ceph.parse(f)
                         return cfg
Example #5
0
def test_write_global_conf_section(tmpdir):
    fake_ip_addresses = lambda x: ['10.0.0.1']

    with patch('ceph_deploy.new.hosts'):
        with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses):
            with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'):
                with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x):
                    with directory(str(tmpdir)):
                        main(args=['new', 'host1'])
    with tmpdir.join('ceph.conf').open() as f:
        cfg = conf.ceph.parse(f)
    assert cfg.sections() == ['global']
def test_simple(tmpdir, capsys):
    with tmpdir.join('ceph.conf').open('w') as f:
        f.write("""\
[global]
fsid = 6ede5564-3cf1-44b5-aa96-1c77b0c3e1d0
mon initial members = host1
""")

    ns = argparse.Namespace()
    ns.pushy = Mock()
    conn = NonCallableMock(name='PushyClient')
    ns.pushy.return_value = conn

    mock_compiled = collections.defaultdict(Mock)
    conn.compile.side_effect = mock_compiled.__getitem__

    MON_SECRET = 'AQBWDj5QAP6LHhAAskVBnUkYHJ7eYREmKo5qKA=='

    def _create_mon(cluster, get_monitor_secret):
        secret = get_monitor_secret()
        assert secret == MON_SECRET

    fake_ip_addresses = lambda x: ['10.0.0.1']
    try:
        with patch('ceph_deploy.new.net.ip_addresses', fake_ip_addresses):
            with patch('ceph_deploy.new.net.get_nonlocal_ip', lambda x: '10.0.0.1'):
                with patch('ceph_deploy.new.arg_validators.Hostname', lambda: lambda x: x):
                    with patch('ceph_deploy.new.hosts'):
                        with directory(str(tmpdir)):
                            main(
                                args=['-v', 'new', '--no-ssh-copykey', 'host1'],
                                namespace=ns,
                                )
                            main(
                                args=['-v', 'mon', 'create', 'host1'],
                                namespace=ns,
                                )
    except SystemExit as e:
        raise AssertionError('Unexpected exit: %s', e)
    out, err = capsys.readouterr()
    err = err.lower()
    assert 'creating new cluster named ceph' in err
    assert 'monitor host1 at 10.0.0.1' in err
    assert 'resolving host host1' in err
    assert "monitor initial members are ['host1']" in err
    assert "monitor addrs are ['10.0.0.1']" in err