mirror of
https://github.com/ceph/ceph
synced 2025-01-20 10:01:45 +00:00
Merge pull request #39722 from p-se/wip-pse-cephadm-SUSE-alertmanager
cephadm: `cephadm ls` broken for SUSE downstream alertmanager container Reviewed-by: Michael Fritch <mfritch@suse.com> Reviewed-by: Sebastian Wagner <sebastian.wagner@suse.com>
This commit is contained in:
commit
06258eafd1
@ -54,12 +54,10 @@ import ipaddress
|
||||
import json
|
||||
import logging
|
||||
from logging.config import dictConfig
|
||||
from operator import truediv
|
||||
import os
|
||||
import platform
|
||||
import pwd
|
||||
import random
|
||||
import select
|
||||
import shutil
|
||||
import socket
|
||||
import string
|
||||
@ -283,6 +281,35 @@ class Monitoring(object):
|
||||
},
|
||||
} # type: ignore
|
||||
|
||||
@staticmethod
|
||||
def get_version(ctx, container_id, daemon_type):
|
||||
# type: (CephadmContext, str, str) -> str
|
||||
"""
|
||||
:param: daemon_type Either "prometheus", "alertmanager" or "node-exporter"
|
||||
"""
|
||||
assert daemon_type in ('prometheus', 'alertmanager', 'node-exporter')
|
||||
cmd = daemon_type.replace('-', '_')
|
||||
code = -1
|
||||
err = ''
|
||||
version = ''
|
||||
if daemon_type == 'alertmanager':
|
||||
for cmd in ['alertmanager', 'prometheus-alertmanager']:
|
||||
_, err, code = call(ctx, [
|
||||
ctx.container_path, 'exec', container_id, cmd,
|
||||
'--version'
|
||||
], verbosity=CallVerbosity.SILENT)
|
||||
if code == 0:
|
||||
break
|
||||
cmd = 'alertmanager' # reset cmd for version extraction
|
||||
else:
|
||||
_, err, code = call(ctx, [
|
||||
ctx.container_path, 'exec', container_id, cmd, '--version'
|
||||
])
|
||||
if code == 0 and \
|
||||
err.startswith('%s, version ' % cmd):
|
||||
version = err.split(' ')[2]
|
||||
return version
|
||||
|
||||
##################################
|
||||
def populate_files(config_dir, config_files, uid, gid):
|
||||
# type: (str, Dict, int, int) -> None
|
||||
@ -4638,14 +4665,8 @@ def list_daemons(ctx, detail=True, legacy_dir=None):
|
||||
elif daemon_type in ['prometheus',
|
||||
'alertmanager',
|
||||
'node-exporter']:
|
||||
cmd = daemon_type.replace('-', '_')
|
||||
out, err, code = call(ctx,
|
||||
[container_path, 'exec', container_id,
|
||||
cmd, '--version'])
|
||||
if not code and \
|
||||
err.startswith('%s, version ' % cmd):
|
||||
version = err.split(' ')[2]
|
||||
seen_versions[image_id] = version
|
||||
version = Monitoring.get_version(ctx, container_id, daemon_type)
|
||||
seen_versions[image_id] = version
|
||||
elif daemon_type == 'haproxy':
|
||||
out, err, code = call(ctx,
|
||||
[container_path, 'exec', container_id,
|
||||
|
@ -819,3 +819,39 @@ class TestMaintenance:
|
||||
def test_parser_BAD(self):
|
||||
with pytest.raises(SystemExit):
|
||||
cd._parse_args(['host-maintenance', 'wah'])
|
||||
|
||||
|
||||
class TestMonitoring(object):
|
||||
@mock.patch('cephadm.call')
|
||||
def test_get_version_alertmanager(self, _call):
|
||||
ctx = mock.Mock()
|
||||
daemon_type = 'alertmanager'
|
||||
|
||||
# binary `prometheus`
|
||||
_call.return_value = '', '{}, version 0.16.1'.format(daemon_type), 0
|
||||
version = cd.Monitoring.get_version(ctx, 'container_id', daemon_type)
|
||||
assert version == '0.16.1'
|
||||
|
||||
# binary `prometheus-alertmanager`
|
||||
_call.side_effect = (
|
||||
('', '', 1),
|
||||
('', '{}, version 0.16.1'.format(daemon_type), 0),
|
||||
)
|
||||
version = cd.Monitoring.get_version(ctx, 'container_id', daemon_type)
|
||||
assert version == '0.16.1'
|
||||
|
||||
@mock.patch('cephadm.call')
|
||||
def test_get_version_prometheus(self, _call):
|
||||
ctx = mock.Mock()
|
||||
daemon_type = 'prometheus'
|
||||
_call.return_value = '', '{}, version 0.16.1'.format(daemon_type), 0
|
||||
version = cd.Monitoring.get_version(ctx, 'container_id', daemon_type)
|
||||
assert version == '0.16.1'
|
||||
|
||||
@mock.patch('cephadm.call')
|
||||
def test_get_version_node_exporter(self, _call):
|
||||
ctx = mock.Mock()
|
||||
daemon_type = 'node-exporter'
|
||||
_call.return_value = '', '{}, version 0.16.1'.format(daemon_type.replace('-', '_')), 0
|
||||
version = cd.Monitoring.get_version(ctx, 'container_id', daemon_type)
|
||||
assert version == '0.16.1'
|
||||
|
Loading…
Reference in New Issue
Block a user