def quorum_status(): """ Reports the status of monitor quorum """ base_result = MetricData( name='cephlm.monitor.quorum', messages={ 'ok': 'Monitors are in quorum.', 'warn': 'Monitors ({msg}) is/are not in quorum.', 'fail': 'Monitors ({msg}) have not formed quorum.', 'unknown': 'Probe error: {msg}.' }) msg = '' value = Severity.ok try: output = Monitor.get_quorum_status() quorum = output['quorum'] monitors = output['monmap']['mons'] if len(quorum) < len(monitors): value = Severity.warn for mon in monitors: if mon['rank'] not in quorum: msg += mon['name'] + ', ' msg = msg[:-2] except CephCommandTimeoutException: value = Severity.fail cluster_name, config, config_file = Ceph._get_ceph_config() msg = config.get('global', 'mon_host') except CephCommandException as e: value = Severity.unknown msg = str(e) result = base_result.child(msgkeys={'msg': msg}) result.value = value return result
def test_get_osd_tree_error(self, mock_cmd): Ceph._get_ceph_config = mock.Mock(return_value=('ceph1', dict(), '/etc/ceph/ceph.conf')) regexp = "Failed to run command 'ceph osd tree'" mock_cmd.side_effect = ShellCommandException(regexp) self.assertRaisesRegexp(CephCommandException, regexp, lambda: Ceph.get_osd_tree())
def test_get_monitors(self, mock_status): mock_status.return_value = ClusterStatusData.HEALTH_OK result = Ceph.get_monitors() expected_monitors = [ "ceph3ntw-cp1-ceph-mon0001-osd-client", "ceph3ntw-cp1-ceph-mon0002-osd-client", "ceph3ntw-cp1-ceph-mon0003-osd-client" ] self.assertEqual(result.sort(), expected_monitors.sort())
def test_get_ceph_config(self, mock_path, mock_listdir): mock_path.return_value = True mock_listdir.return_value = [ "ceph1.conf", "ceph.mon.keyring", "ceph.client.admin.keyring" ] with mock.patch('ConfigParser.RawConfigParser') as mocked: mocked.return_value = mock.MagicMock( spec=ConfigParser.RawConfigParser) cluster_name, config, config_file = Ceph._get_ceph_config() self.assertEqual(cluster_name, 'ceph1')
def check_osd_node_ram(): """ Checks for optimal memory requirement in a Ceph OSD node [Run as root] """ base_result = MetricData( name='cephlm.perfscale.osd_node_ram', messages={ 'ok': 'Host RAM({ram}GiB) meets %s GiB per TiB of data disk' '({total_osd_size}TiB) guideline.' % PerfScale.GiB_PER_TiB_DATA, 'warn': 'Host RAM({ram}GiB) violates %s GiB per TiB of data disk' # noqa '({total_osd_size}TiB) guideline.' % PerfScale.GiB_PER_TiB_DATA, 'unknown': 'Probe error: {msg}' }) try: journal_disks, data_disks = Ceph.get_ceph_disk_list() mem_info = get_system_memory_info() disks_info = get_system_disks_size() except (CephLMException, CephCommandException) as e: result = base_result.child(msgkeys={'msg': str(e)}) result.value = Severity.unknown return result total_osd_size, ram = PerfScale._process_osd_ram_data( data_disks, disks_info, mem_info) if not data_disks: # Ideally this check will not be run on non OSD nodes, but in case # it does, we return an empty list return list() result = base_result.child(msgkeys={ 'ram': '%s' % ram, 'total_osd_size': '%s' % total_osd_size }) result.value = PerfScale._process_osd_ram_status(total_osd_size, ram) return result
def test_get_osd_tree(self, mock_cmd): Ceph._get_ceph_config = mock.Mock(return_value=('ceph1', dict(), '/etc/ceph/ceph.conf')) mock_cmd.return_value = json.dumps(OSDData.TEST_OSD_TREE) result = Ceph.get_osd_tree() self.assertEqual(OSDData.TEST_OSD_TREE, result)
def test_get_ceph_disk_list_error(self, mock_cmd): regexp = "Failed to run command 'ceph-disk list'" mock_cmd.side_effect = ShellCommandException(regexp) self.assertRaisesRegexp(CephCommandException, regexp, lambda: Ceph.get_ceph_disk_list())
def test_get_ceph_disk_list(self, mock_cmd): mock_cmd.return_value = CephDisksData.DISK_LIST_STDOUT_OK result = Ceph.get_ceph_disk_list() self.assertEqual(CephDisksData.DISK_LIST_OK, result)
def test_get_status(self, mock_cmd): Ceph._get_ceph_config = mock.Mock(return_value=('ceph1', dict(), '/etc/ceph/ceph.conf')) mock_cmd.return_value = json.dumps(ClusterStatusData.HEALTH_OK) result = Ceph.get_status() self.assertEqual(ClusterStatusData.HEALTH_OK, result)
def test_get_ceph_config_error(self, mock_path, mock_listdir): mock_path.return_value = False mock_listdir.return_value = [] regexp = "Could not find ceph configuration directory /etc/ceph" self.assertRaisesRegexp(CephLMException, regexp, lambda: Ceph._get_ceph_config())
def test_get_quorum_status(self, mock_cmd): Ceph._get_ceph_config = mock.Mock( return_value=('ceph1', dict(), '/etc/ceph/ceph1.conf')) mock_cmd.return_value = json.dumps(MonitorQuorumData.QUORUM_OK) result = Ceph.get_quorum_status() self.assertEqual(MonitorQuorumData.QUORUM_OK, result)
def test_get_ceph_df(self, mock_cmd): Ceph._get_ceph_config = mock.Mock( return_value=('ceph1', dict(), '/etc/ceph/ceph1.conf')) mock_cmd.return_value = json.dumps(PoolData.test_pool_df) result = Ceph.get_ceph_df() self.assertEqual(PoolData.test_pool_df, result)