コード例 #1
0
 def test_gatherkeys_backs_up(self):
     """
     Test 'gatherkeys' succeeds when getinig keys that are always different.
     Test 'gatherkeys' does backup keys that are not identical.
     """
     args = mock.Mock()
     args.cluster = "ceph"
     args.mon = ['host1']
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     assert "ceph.client.admin.keyring" in dir_content
     assert "ceph.bootstrap-mds.keyring" in dir_content
     assert "ceph.mon.keyring" in dir_content
     assert "ceph.bootstrap-osd.keyring" in dir_content
     assert "ceph.bootstrap-rgw.keyring" in dir_content
     assert len(dir_content) == 5
     # Now we repeat as new keys are generated and old
     # are backed up
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     mocked_time = mock_time_strftime(None)
     assert "ceph.client.admin.keyring" in dir_content
     assert "ceph.bootstrap-mds.keyring" in dir_content
     assert "ceph.mon.keyring" in dir_content
     assert "ceph.bootstrap-osd.keyring" in dir_content
     assert "ceph.bootstrap-rgw.keyring" in dir_content
     assert "ceph.client.admin.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-mds.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.mon.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-osd.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-rgw.keyring-%s" % (mocked_time) in dir_content
     assert len(dir_content) == 10
コード例 #2
0
ファイル: test_gather_keys.py プロジェクト: ceph/ceph-deploy
 def test_gatherkeys_backs_up(self):
     """
     Test 'gatherkeys' succeeds when getting keys that are always different.
     Test 'gatherkeys' does backup keys that are not identical.
     """
     args = mock.Mock()
     args.cluster = "ceph"
     args.mon = ['host1']
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     assert "ceph.client.admin.keyring" in dir_content
     assert "ceph.bootstrap-mds.keyring" in dir_content
     assert "ceph.bootstrap-mgr.keyring" in dir_content
     assert "ceph.mon.keyring" in dir_content
     assert "ceph.bootstrap-osd.keyring" in dir_content
     assert "ceph.bootstrap-rgw.keyring" in dir_content
     assert len(dir_content) == 6
     # Now we repeat as new keys are generated and old
     # are backed up
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     mocked_time = mock_time_strftime(None)
     assert "ceph.client.admin.keyring" in dir_content
     assert "ceph.bootstrap-mds.keyring" in dir_content
     assert "ceph.bootstrap-mgr.keyring" in dir_content
     assert "ceph.mon.keyring" in dir_content
     assert "ceph.bootstrap-osd.keyring" in dir_content
     assert "ceph.bootstrap-rgw.keyring" in dir_content
     assert "ceph.client.admin.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-mds.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-mgr.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.mon.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-osd.keyring-%s" % (mocked_time) in dir_content
     assert "ceph.bootstrap-rgw.keyring-%s" % (mocked_time) in dir_content
     assert len(dir_content) == 12
コード例 #3
0
ファイル: test_gather_keys.py プロジェクト: ceph/ceph-deploy
 def test_gatherkeys_fail(self):
     """
     Test 'gatherkeys' fails when connecting to mon fails.
     """
     args = mock.Mock()
     args.cluster = "ceph"
     args.mon = ['host1']
     with pytest.raises(RuntimeError):
         gatherkeys.gatherkeys(args)
コード例 #4
0
 def test_gatherkeys_fail(self):
     """
     Test 'gatherkeys' fails when connecting to mon fails.
     """
     args = mock.Mock()
     args.cluster = "ceph"
     args.mon = ['host1']
     with pytest.raises(RuntimeError):
         gatherkeys.gatherkeys(args)
コード例 #5
0
ファイル: mon.py プロジェクト: hl10502/ceph-deploy
def mon_create_initial(args):
    # 获取ceph.conf中的mon_initial_members
    mon_initial_members = get_mon_initial_members(args, error_on_empty=True)

    # create them normally through mon_create
    args.mon = mon_initial_members
    # 创建mon
    mon_create(args)

    # make the sets to be able to compare late
    mon_in_quorum = set([])
    mon_members = set([host for host in mon_initial_members])

    for host in mon_initial_members:
        mon_name = 'mon.%s' % host
        LOG.info('processing monitor %s', mon_name)
        sleeps = [20, 20, 15, 10, 10, 5]
        tries = 5
        rlogger = logging.getLogger(host)
        distro = hosts.get(
            host,
            username=args.username,
            callbacks=[packages.ceph_is_installed]
        )

        while tries:
            # 获取mon的状态
            status = mon_status_check(distro.conn, rlogger, host, args)
            has_reached_quorum = status.get('state', '') in ['peon', 'leader']
            if not has_reached_quorum:
                LOG.warning('%s monitor is not yet in quorum, tries left: %s' % (mon_name, tries))
                tries -= 1
                sleep_seconds = sleeps.pop()
                LOG.warning('waiting %s seconds before retrying', sleep_seconds)
                time.sleep(sleep_seconds)  # Magic number
            else:
                mon_in_quorum.add(host)
                LOG.info('%s monitor has reached quorum!', mon_name)
                break
        distro.conn.exit()

    # 集群中的mon_in_quorum与ceph.conf中的mon_initial_members完全匹配
    if mon_in_quorum == mon_members:
        LOG.info('all initial monitors are running and have formed quorum')
        LOG.info('Running gatherkeys...')
        # 调用gatherkeys模块gatherkeys函数,收集用于配置新节点的keys
        gatherkeys.gatherkeys(args)
    else:
        LOG.error('Some monitors have still not reached quorum:')
        for host in mon_members - mon_in_quorum:
            LOG.error('%s', host)
        raise SystemExit('cluster may not be in a healthy state')
コード例 #6
0
def mon_create_initial(args):
    cfg = conf.ceph.load(args)
    cfg_initial_members = cfg.safe_get('global', 'mon_initial_members')
    if cfg_initial_members is None:
        raise RuntimeError('No `mon initial members` defined in config')
    mon_initial_members = re.split(r'[,\s]+', cfg_initial_members)

    # create them normally through mon_create
    mon_create(args)

    # make the sets to be able to compare late
    mon_in_quorum = set([])
    mon_members = set([host for host in mon_initial_members])

    for host in mon_initial_members:
        mon_name = 'mon.%s' % host
        LOG.info('processing monitor %s', mon_name)
        sleeps = [20, 20, 15, 10, 10, 5]
        tries = 5
        rlogger = logging.getLogger(host)
        rconn = get_connection(host, username=args.username, logger=rlogger)
        while tries:
            status = mon_status_check(rconn, rlogger, host, args)
            has_reached_quorum = status.get('state', '') in ['peon', 'leader']
            if not has_reached_quorum:
                LOG.warning('%s monitor is not yet in quorum, tries left: %s' %
                            (mon_name, tries))
                tries -= 1
                sleep_seconds = sleeps.pop()
                LOG.warning('waiting %s seconds before retrying',
                            sleep_seconds)
                time.sleep(sleep_seconds)  # Magic number
            else:
                mon_in_quorum.add(host)
                LOG.info('%s monitor has reached quorum!', mon_name)
                break
        rconn.exit()

    if mon_in_quorum == mon_members:
        LOG.info('all initial monitors are running and have formed quorum')
        LOG.info('Running gatherkeys...')
        gatherkeys.gatherkeys(args)
    else:
        LOG.error('Some monitors have still not reached quorum:')
        for host in mon_members - mon_in_quorum:
            LOG.error('%s', host)
        raise SystemExit('cluster may not be in a healthy state')
コード例 #7
0
ファイル: mon.py プロジェクト: kfei/ceph-deploy
def mon_create_initial(args):
    cfg = conf.ceph.load(args)
    cfg_initial_members = cfg.safe_get('global', 'mon_initial_members')
    if cfg_initial_members is None:
        raise RuntimeError('No `mon initial members` defined in config')
    mon_initial_members = re.split(r'[,\s]+', cfg_initial_members)

    # create them normally through mon_create
    mon_create(args)

    # make the sets to be able to compare late
    mon_in_quorum = set([])
    mon_members = set([host for host in mon_initial_members])

    for host in mon_initial_members:
        mon_name = 'mon.%s' % host
        LOG.info('processing monitor %s', mon_name)
        sleeps = [20, 20, 15, 10, 10, 5]
        tries = 5
        rlogger = logging.getLogger(host)
        rconn = get_connection(host, username=args.username, logger=rlogger)
        while tries:
            status = mon_status_check(rconn, rlogger, host, args)
            has_reached_quorum = status.get('state', '') in ['peon', 'leader']
            if not has_reached_quorum:
                LOG.warning('%s monitor is not yet in quorum, tries left: %s' %
                            (mon_name, tries))
                tries -= 1
                sleep_seconds = sleeps.pop()
                LOG.warning('waiting %s seconds before retrying',
                            sleep_seconds)
                time.sleep(sleep_seconds)  # Magic number
            else:
                mon_in_quorum.add(host)
                LOG.info('%s monitor has reached quorum!', mon_name)
                break
        rconn.exit()

    if mon_in_quorum == mon_members:
        LOG.info('all initial monitors are running and have formed quorum')
        LOG.info('Running gatherkeys...')
        gatherkeys.gatherkeys(args)
    else:
        LOG.error('Some monitors have still not reached quorum:')
        for host in mon_members - mon_in_quorum:
            LOG.error('%s', host)
        raise SystemExit('cluster may not be in a healthy state')
コード例 #8
0
ファイル: mon.py プロジェクト: justyu/ceph-deploy
def mon_create_initial(args):
    mon_initial_members = get_mon_initial_members(args, error_on_empty=True)

    # create them normally through mon_create
    args.mon = mon_initial_members
    mon_create(args)

    # make the sets to be able to compare late
    mon_in_quorum = set([])
    mon_members = set([host for host in mon_initial_members])

    for host in mon_initial_members:
        mon_name = 'mon.%s' % host
        LOG.info('processing monitor %s', mon_name)
        sleeps = [20, 20, 15, 10, 10, 5]
        tries = 5
        rlogger = logging.getLogger(host)
        distro = hosts.get(
            host,
            username=args.username,
            callbacks=[packages.ceph_is_installed]
        )

        while tries:
            status = mon_status_check(distro.conn, rlogger, host, args)
            has_reached_quorum = status.get('state', '') in ['peon', 'leader']
            if not has_reached_quorum:
                LOG.warning('%s monitor is not yet in quorum, tries left: %s' % (mon_name, tries))
                tries -= 1
                sleep_seconds = sleeps.pop()
                LOG.warning('waiting %s seconds before retrying', sleep_seconds)
                time.sleep(sleep_seconds)  # Magic number
            else:
                mon_in_quorum.add(host)
                LOG.info('%s monitor has reached quorum!', mon_name)
                break
        distro.conn.exit()

    if mon_in_quorum == mon_members:
        LOG.info('all initial monitors are running and have formed quorum')
        LOG.info('Running gatherkeys...')
        gatherkeys.gatherkeys(args)
    else:
        LOG.error('Some monitors have still not reached quorum:')
        for host in mon_members - mon_in_quorum:
            LOG.error('%s', host)
        raise SystemExit('cluster may not be in a healthy state')
コード例 #9
0
 def test_gatherkeys_success(self):
     """
     Test 'gatherkeys' succeeds when getinig keys that are always the same.
     Test 'gatherkeys' does not backup identical keys
     """
     args = mock.Mock()
     args.cluster = "ceph"
     args.mon = ['host1']
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     assert "ceph.client.admin.keyring" in dir_content
     assert "ceph.bootstrap-mds.keyring" in dir_content
     assert "ceph.mon.keyring" in dir_content
     assert "ceph.bootstrap-osd.keyring" in dir_content
     assert "ceph.bootstrap-rgw.keyring" in dir_content
     assert len(dir_content) == 5
     # Now we repeat as no new keys are generated
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     assert len(dir_content) == 5
コード例 #10
0
 def test_gatherkeys_success(self):
     """
     Test 'gatherkeys' succeeds when getinig keys that are always the same.
     Test 'gatherkeys' does not backup identical keys
     """
     args = mock.Mock()
     args.cluster = "ceph"
     args.mon = ['host1']
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     assert "ceph.client.admin.keyring" in dir_content
     assert "ceph.bootstrap-mds.keyring" in dir_content
     assert "ceph.mon.keyring" in dir_content
     assert "ceph.bootstrap-osd.keyring" in dir_content
     assert "ceph.bootstrap-rgw.keyring" in dir_content
     assert len(dir_content) == 5
     # Now we repeat as no new keys are generated
     gatherkeys.gatherkeys(args)
     dir_content = os.listdir(self.test_dir)
     assert len(dir_content) == 5
コード例 #11
0
ファイル: mon.py プロジェクト: varadakari/ceph-deploy
def mon_create_initial(args):
    mon_initial_members = get_mon_initial_members(args, error_on_empty=True)

    # create them normally through mon_create
    mon_create(args)

    # make the sets to be able to compare late
    mon_in_quorum = set([])
    mon_members = set([host for host in mon_initial_members])

    for host in mon_initial_members:
        mon_name = "mon.%s" % host
        LOG.info("processing monitor %s", mon_name)
        sleeps = [20, 20, 15, 10, 10, 5]
        tries = 5
        rlogger = logging.getLogger(host)
        rconn = get_connection(host, username=args.username, logger=rlogger)
        while tries:
            status = mon_status_check(rconn, rlogger, host, args)
            has_reached_quorum = status.get("state", "") in ["peon", "leader"]
            if not has_reached_quorum:
                LOG.warning("%s monitor is not yet in quorum, tries left: %s" % (mon_name, tries))
                tries -= 1
                sleep_seconds = sleeps.pop()
                LOG.warning("waiting %s seconds before retrying", sleep_seconds)
                time.sleep(sleep_seconds)  # Magic number
            else:
                mon_in_quorum.add(host)
                LOG.info("%s monitor has reached quorum!", mon_name)
                break
        rconn.exit()

    if mon_in_quorum == mon_members:
        LOG.info("all initial monitors are running and have formed quorum")
        LOG.info("Running gatherkeys...")
        gatherkeys.gatherkeys(args)
    else:
        LOG.error("Some monitors have still not reached quorum:")
        for host in mon_members - mon_in_quorum:
            LOG.error("%s", host)
        raise SystemExit("cluster may not be in a healthy state")