python-common: Reparent AlertManagerSpec to MonitoringSpec

And remove duplicated members

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
This commit is contained in:
Sebastian Wagner 2021-07-23 03:20:43 +02:00
parent 208ce50b92
commit f2b0b45176
No known key found for this signature in database
GPG Key ID: 8D2442807E6979F8
2 changed files with 5 additions and 10 deletions

View File

@ -1020,7 +1020,7 @@ class MonitoringSpec(ServiceSpec):
preview_only: bool = False,
port: Optional[int] = None,
):
assert service_type in ['grafana', 'node-exporter', 'prometheus']
assert service_type in ['grafana', 'node-exporter', 'prometheus', 'alertmanager']
super(MonitoringSpec, self).__init__(
service_type, service_id,
@ -1040,13 +1040,14 @@ class MonitoringSpec(ServiceSpec):
else:
return {'prometheus': 9095,
'node-exporter': 9100,
'alertmanager': 9093,
'grafana': 3000}[self.service_type]
yaml.add_representer(MonitoringSpec, ServiceSpec.yaml_representer)
class AlertManagerSpec(ServiceSpec):
class AlertManagerSpec(MonitoringSpec):
def __init__(self,
service_type: str = 'alertmanager',
service_id: Optional[str] = None,
@ -1062,7 +1063,7 @@ class AlertManagerSpec(ServiceSpec):
super(AlertManagerSpec, self).__init__(
'alertmanager', service_id=service_id,
placement=placement, unmanaged=unmanaged,
preview_only=preview_only, config=config, networks=networks)
preview_only=preview_only, config=config, networks=networks, port=port)
# Custom configuration.
#
@ -1079,17 +1080,10 @@ class AlertManagerSpec(ServiceSpec):
# added to the default receivers'
# <webhook_configs> configuration.
self.user_data = user_data or {}
self.port = port
def get_port_start(self) -> List[int]:
return [self.get_port(), 9094]
def get_port(self) -> int:
if self.port:
return self.port
else:
return 9093
def validate(self) -> None:
super(AlertManagerSpec, self).validate()

View File

@ -327,6 +327,7 @@ def test_alertmanager_spec_1():
assert spec.service_type == 'alertmanager'
assert isinstance(spec.user_data, dict)
assert len(spec.user_data.keys()) == 0
assert spec.get_port_start() == [9093, 9094]
def test_alertmanager_spec_2():