Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6711: Fix restart vrrp missed comma between services #4054

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions src/op_mode/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
config = ConfigTreeQuery()

service_map = {
'dhcp' : {
'dhcp': {
'systemd_service': 'kea-dhcp4-server',
'path': ['service', 'dhcp-server'],
},
'dhcpv6' : {
'dhcpv6': {
'systemd_service': 'kea-dhcp6-server',
'path': ['service', 'dhcpv6-server'],
},
Expand Down Expand Up @@ -61,24 +61,40 @@
'systemd_service': 'radvd',
'path': ['service', 'router-advert'],
},
'snmp' : {
'snmp': {
'systemd_service': 'snmpd',
},
'ssh' : {
'ssh': {
'systemd_service': 'ssh',
},
'suricata' : {
'suricata': {
'systemd_service': 'suricata',
},
'vrrp' : {
'vrrp': {
'systemd_service': 'keepalived',
'path': ['high-availability', 'vrrp'],
},
'webproxy' : {
'webproxy': {
'systemd_service': 'squid',
},
}
services = typing.Literal['dhcp', 'dhcpv6', 'dns_dynamic', 'dns_forwarding', 'igmp_proxy', 'ipsec', 'mdns_repeater', 'reverse_proxy', 'router_advert', 'snmp', 'ssh', 'suricata' 'vrrp', 'webproxy']
services = typing.Literal[
'dhcp',
'dhcpv6',
'dns_dynamic',
'dns_forwarding',
'igmp_proxy',
'ipsec',
'mdns_repeater',
'reverse_proxy',
'router_advert',
'snmp',
'ssh',
'suricata',
'vrrp',
'webproxy',
]


def _verify(func):
"""Decorator checks if DHCP(v6) config exists"""
Expand All @@ -102,13 +118,18 @@ def _wrapper(*args, **kwargs):

# Check if config does not exist
if not config.exists(path):
raise vyos.opmode.UnconfiguredSubsystem(f'Service {human_name} is not configured!')
raise vyos.opmode.UnconfiguredSubsystem(
f'Service {human_name} is not configured!'
)
if config.exists(path + ['disable']):
raise vyos.opmode.UnconfiguredSubsystem(f'Service {human_name} is disabled!')
raise vyos.opmode.UnconfiguredSubsystem(
f'Service {human_name} is disabled!'
)
return func(*args, **kwargs)

return _wrapper


@_verify
def restart_service(raw: bool, name: services, vrf: typing.Optional[str]):
systemd_service = service_map[name]['systemd_service']
Expand All @@ -117,6 +138,7 @@ def restart_service(raw: bool, name: services, vrf: typing.Optional[str]):
else:
call(f'systemctl restart "{systemd_service}.service"')


if __name__ == '__main__':
try:
res = vyos.opmode.run(sys.modules[__name__])
Expand Down
Loading