コード例 #1
0
ファイル: test_util_node.py プロジェクト: Vegasq/fuel-octane
def test_untar_files(node, mock_ssh_popen, mock_open):
    content = b'fake data\nin\nthe\narchive'

    proc = mock_ssh_popen.return_value.__enter__.return_value
    buf = io.BytesIO()
    proc.stdin.write = buf.write
    mock_open.return_value = io.BytesIO(content)

    node_util.untar_files('filename', node)

    mock_ssh_popen.assert_called_once_with(['tar', '-xzv', '-C', '/'],
                                           stdin=ssh.PIPE, node=node)
    mock_open.assert_called_once_with('filename', 'rb')
    assert buf.getvalue() == content
コード例 #2
0
ファイル: upgrade_ceph.py プロジェクト: rmoe/fuel-octane
def ceph_set_new_mons(seed_env, filename, conf_filename, db_path):
    nodes = list(env_util.get_controllers(seed_env))
    hostnames = map(short_hostname, node_util.get_hostnames(nodes))
    mgmt_ips = map(remove_mask, node_util.get_ips('management', nodes))

    with contextlib.closing(tarfile.open(filename)) as f:
        conf = f.extractfile(conf_filename).read()
        conf = replace_addresses(conf, hostnames, mgmt_ips)

    fsid = get_fsid(conf)
    monmaptool_cmd = ['monmaptool', '--fsid', fsid, '--clobber', '--create']
    for node_hostname, node_ip in itertools.izip(hostnames, mgmt_ips):
        monmaptool_cmd += ['--add', node_hostname, node_ip]

    for node, node_hostname in itertools.izip(nodes, hostnames):
        node_db_path = "/var/lib/ceph/mon/ceph-{0}".format(node_hostname)
        node_conf = replace_host(conf, node_hostname)
        try:
            ssh.call(['stop', 'ceph-mon', "id={0}".format(node_hostname)],
                     node=node)
        except subprocess.CalledProcessError:
            pass
        ssh.call(['rm', '-rf', node_db_path], node=node)
        node_util.untar_files(filename, node)
        sftp = ssh.sftp(node)
        with sftp.open(conf_filename, 'w') as f:
            f.write(node_conf)
        ssh.call(['mv', db_path, node_db_path], node=node)

        sysvinit = os.path.join(node_db_path, 'sysvinit')
        try:
            sftp.remove(sysvinit)
        except IOError:
            pass
        upstart = os.path.join(node_db_path, 'upstart')
        sftp.open(upstart, 'w').close()

        with ssh.tempdir(node) as tempdir:
            monmap_filename = os.path.join(tempdir, 'monmap')
            ssh.call(monmaptool_cmd + [monmap_filename], node=node)
            ssh.call([
                'ceph-mon', '-i', node_hostname, '--inject-monmap',
                monmap_filename
            ],
                     node=node)

    for node, node_hostname in itertools.izip(nodes, hostnames):
        ssh.call(['start', 'ceph-mon', "id={0}".format(node_hostname)],
                 node=node)
    import_bootstrap_osd(nodes[0])
コード例 #3
0
ファイル: test_util_node.py プロジェクト: rmoe/fuel-octane
def test_untar_files(node, mock_ssh_popen, mock_open):
    content = b'fake data\nin\nthe\narchive'

    proc = mock_ssh_popen.return_value.__enter__.return_value
    buf = io.BytesIO()
    proc.stdin.write = buf.write
    mock_open.return_value = io.BytesIO(content)

    node_util.untar_files('filename', node)

    mock_ssh_popen.assert_called_once_with(['tar', '-xzv', '-C', '/'],
                                           stdin=ssh.PIPE,
                                           node=node)
    mock_open.assert_called_once_with('filename', 'rb')
    assert buf.getvalue() == content
コード例 #4
0
ファイル: upgrade_ceph.py プロジェクト: Vegasq/fuel-octane
def ceph_set_new_mons(seed_env, filename, conf_filename, db_path):
    nodes = list(env_util.get_controllers(seed_env))
    hostnames = map(short_hostname, node_util.get_hostnames(nodes))
    mgmt_ips = map(remove_mask, node_util.get_ips('management', nodes))

    with contextlib.closing(tarfile.open(filename)) as f:
        conf = f.extractfile(conf_filename).read()
        conf = replace_addresses(conf, hostnames, mgmt_ips)

    fsid = get_fsid(conf)
    monmaptool_cmd = ['monmaptool', '--fsid', fsid, '--clobber', '--create']
    for node_hostname, node_ip in itertools.izip(hostnames, mgmt_ips):
        monmaptool_cmd += ['--add', node_hostname, node_ip]

    for node, node_hostname in itertools.izip(nodes, hostnames):
        node_db_path = "/var/lib/ceph/mon/ceph-{0}".format(node_hostname)
        node_conf = replace_host(conf, node_hostname)
        try:
            ssh.call(['stop', 'ceph-mon', "id={0}".format(node_hostname)],
                     node=node)
        except subprocess.CalledProcessError:
            pass
        ssh.call(['rm', '-rf', node_db_path], node=node)
        node_util.untar_files(filename, node)
        sftp = ssh.sftp(node)
        with sftp.open(conf_filename, 'w') as f:
            f.write(node_conf)
        ssh.call(['mv', db_path, node_db_path], node=node)

        sysvinit = os.path.join(node_db_path, 'sysvinit')
        try:
            sftp.remove(sysvinit)
        except IOError:
            pass
        upstart = os.path.join(node_db_path, 'upstart')
        sftp.open(upstart, 'w').close()

        with ssh.tempdir(node) as tempdir:
            monmap_filename = os.path.join(tempdir, 'monmap')
            ssh.call(monmaptool_cmd + [monmap_filename], node=node)
            ssh.call(['ceph-mon', '-i', node_hostname, '--inject-monmap',
                      monmap_filename], node=node)

    for node, node_hostname in itertools.izip(nodes, hostnames):
        ssh.call(['start', 'ceph-mon', "id={0}".format(node_hostname)],
                 node=node)
    import_bootstrap_osd(nodes[0])
コード例 #5
0
ファイル: upgrade_ceph.py プロジェクト: openstack/fuel-octane
def ceph_set_new_mons(orig_env, seed_env, filename, conf_filename, db_path):
    nodes = list(env_util.get_controllers(seed_env))

    with contextlib.closing(tarfile.open(filename)) as f:
        conf = f.extractfile(conf_filename).read()

    fsid = get_fsid(conf)

    for node in nodes:
        node_hostname = short_hostname(node.data['fqdn'])
        node_db_path = "/var/lib/ceph/mon/ceph-{0}".format(node_hostname)
        try:
            ssh.call(['stop', 'ceph-mon', "id={0}".format(node_hostname)],
                     node=node)
        except subprocess.CalledProcessError:
            pass
        with ssh.tempdir(node) as tempdir:
            # save current seed conf and monmap in tmp dir
            monmap_filename = os.path.join(tempdir, 'monmap')
            ssh.call(["ceph-mon", "-i", node_hostname,
                     "--extract-monmap", monmap_filename], node=node)
            seed_conf_path = os.path.join(tempdir, "ceph.conf")
            ssh.call(['cp', conf_filename, seed_conf_path], node=node)

            ssh.call(['rm', '-rf', node_db_path], node=node)
            node_util.untar_files(filename, node)

            # return seed ceph confs
            ssh.call(['cp', seed_conf_path, conf_filename], node=node)
            # change fsid for orig fsid value
            change_fsid(conf_filename, node, fsid)
            # change fsid value in monmap
            ssh.call(["monmaptool", "--fsid", fsid,
                      "--clobber", monmap_filename], node=node)
            ssh.call(['mv', db_path, node_db_path], node=node)
            if version.StrictVersion(orig_env.data["fuel_version"]) < \
                    version.StrictVersion(magic_consts.CEPH_UPSTART_VERSION):
                _activate_upstart_instead_sysvinit(node, db_path, node_db_path)
            # return old monmap value
            ssh.call(['ceph-mon', '-i', node_hostname,
                      '--inject-monmap', monmap_filename], node=node)
        ssh.call(['start', 'ceph-mon', "id={0}".format(node_hostname)],
                 node=node)
    import_bootstrap_osd(nodes[0])