Ceph plugin detects client.admin keyring

In standard system locations, check for the client.admin key
for each detected Ceph cluster and conditionally suppress
Ceph agent checks that require it if it is not found.

Change-Id: If3a28ceb5cdde40749d077ad465054eba37c848c
Story: 2005172
This commit is contained in:
Stig Telfer 2019-03-08 17:19:00 +00:00
parent b48e1e60bc
commit 2099661acb
2 changed files with 67 additions and 4 deletions

View File

@ -165,6 +165,9 @@ class Ceph(Plugin):
cluster_dict['cluster_name'] = config_file[:-5]
cluster_dict['config_file'] = \
os.path.join(self.ceph_config_dir, config_file)
cluster_dict['admin_key'] = \
cluster_dict['cluster_name'] + '.client.admin.keyring' in \
os.listdir(self.ceph_config_dir)
clusters.append(cluster_dict)
expected_processes = list()
@ -187,8 +190,20 @@ class Ceph(Plugin):
# Configure ceph plugin
instances = []
for cluster in clusters:
cluster_name = cluster['cluster_name']
log.info("\tMonitoring ceph cluster: '{0}'.".format(cluster_name))
instances.append({'cluster_name': cluster_name})
cluster_config = {}
cluster_config['cluster_name'] = cluster['cluster_name']
# If there is no client admin key installed for this cluster
# then we cannot invoke Ceph commands for cluster monitoring.
# In that case we only monitor the locally active processes.
if not cluster['admin_key']:
cluster_config['collect_usage_metrics'] = False
cluster_config['collect_stats_metrics'] = False
cluster_config['collect_mon_metrics'] = False
cluster_config['collect_osd_metrics'] = False
cluster_config['collect_pool_metrics'] = False
log.info("\tMonitoring ceph cluster: '{0}'.".format(cluster['cluster_name']))
instances.append(cluster_config)
config['ceph'] = {'init_config': None, 'instances': instances}
return config

View File

@ -164,6 +164,49 @@ class TestCephDetection(base.BaseTestCase):
@mock.patch('os.path.exists', return_value=True)
@mock.patch('os.listdir', return_value=['ceph.conf', 'ceph1.conf'])
def test_build_config_with_no_admin_key(self, list_dir, path_exists):
self._ceph._service_config = mock.Mock(
side_effect=mocked_service_config)
processes = MON_PROCESSES + RGW_PROCESSES
process_instances = list()
for p in processes:
instance = {
'exact_match': False,
'search_string': p['search_string'],
'detailed': True,
'name': p['name'],
'dimensions': {'component': p['type'], 'service': 'ceph'}
}
process_instances.append(instance)
expected_config = {
'process': {
'init_config': None,
'instances': process_instances,
},
'ceph': {
'init_config': None,
'instances': [{'cluster_name': 'ceph',
'collect_mon_metrics': False,
'collect_osd_metrics': False,
'collect_pool_metrics': False,
'collect_stats_metrics': False,
'collect_usage_metrics': False},
{'cluster_name': 'ceph1',
'collect_mon_metrics': False,
'collect_osd_metrics': False,
'collect_pool_metrics': False,
'collect_stats_metrics': False,
'collect_usage_metrics': False}]
}
}
config = self._ceph.build_config()
self.assertEqual(expected_config, dict(config))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('os.listdir', return_value=['ceph.conf', 'ceph1.conf', 'ceph1.client.admin.keyring'])
def test_build_config(self, list_dir, path_exists):
self._ceph._service_config = mock.Mock(
side_effect=mocked_service_config)
@ -188,7 +231,12 @@ class TestCephDetection(base.BaseTestCase):
},
'ceph': {
'init_config': None,
'instances': [{'cluster_name': 'ceph'},
'instances': [{'cluster_name': 'ceph',
'collect_mon_metrics': False,
'collect_osd_metrics': False,
'collect_pool_metrics': False,
'collect_stats_metrics': False,
'collect_usage_metrics': False},
{'cluster_name': 'ceph1'}]
}
}