Skip to content

Commit

Permalink
NAS-133327 / 25.04 / Remove @accepts from certain failover endpoints (#…
Browse files Browse the repository at this point in the history
…15289)

* make failover event endpoint private

* make failover firewall endpoints private

* remove accepts from zpool_cachefile.py

* address review
  • Loading branch information
yocalebo authored Dec 31, 2024
1 parent 5b92565 commit 01de1f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
19 changes: 8 additions & 11 deletions src/middlewared/middlewared/plugins/failover_/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from collections import defaultdict

from middlewared.utils import filter_list
from middlewared.service import Service, job, accepts
from middlewared.service import Service, job
from middlewared.service_exception import CallError
from middlewared.schema import Dict, Bool, Int
from middlewared.plugins.docker.state_utils import Status as DockerStatus
# from middlewared.plugins.failover_.zpool_cachefile import ZPOOL_CACHE_FILE
from middlewared.plugins.failover_.event_exceptions import AllZpoolsFailedToImport, IgnoreFailoverEvent, FencedError
Expand Down Expand Up @@ -87,21 +86,19 @@ async def become_active_service(self, service, timeout):
timeout=timeout,
)

@accepts(Dict(
'restart_services',
Bool('critical', default=False),
Int('timeout', default=15),
))
async def restart_services(self, data):
"""
Concurrently restart services during a failover
master event.
`critical` Boolean when True will only restart the
critical services.
`timeout` Integer representing the maximum amount
of time to wait for a given service to (re)start.
`data` is a dictionary accepting 2 keys
`critical` Boolean when True will only restart the
critical services.
`timeout` Integer representing the maximum amount
of time to wait for a given service to (re)start.
"""
data.setdefault('critical', False)
data.setdefault('timeout', 15)
to_restart = await self.middleware.call('datastore.query', 'services_services')
to_restart = [i['srv_service'] for i in to_restart if i['srv_enable']]
if data['critical']:
Expand Down
4 changes: 1 addition & 3 deletions src/middlewared/middlewared/plugins/failover_/nftables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from subprocess import run, PIPE, STDOUT

from middlewared.service import Service, accepts, job, CallError
from middlewared.service import Service, job, CallError


FW_RULES_FILE = '/tmp/fw-rules.nft'
Expand Down Expand Up @@ -71,7 +71,6 @@ def flush_chain_INPUT(self):
ip6_flush = not bool(run(['nft', 'flush', 'chain', 'ip6', 'filter', 'INPUT']).returncode)
return ip4_flush and ip6_flush

@accepts()
@job(lock=JOB_LOCK)
def drop_all(self, job):
"""
Expand Down Expand Up @@ -99,7 +98,6 @@ def drop_all(self, job):

return self.generate_rules({'drop': True, 'vips': vips})

@accepts()
@job(lock=JOB_LOCK)
def accept_all(self, job):
"""Accepts all v4/v6 inbound traffic"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# See the file LICENSE.IX for complete terms and conditions

from pathlib import Path
from typing import Literal

from middlewared.service import Service
from middlewared.schema import Str, accepts
from middlewared.plugins.pool_.utils import ZPOOL_CACHE_FILE

ZPOOL_CACHE_FILE_SAVED = f'{ZPOOL_CACHE_FILE}.saved'
Expand All @@ -18,8 +18,10 @@ class Config:
private = True
namespace = 'failover.zpool.cachefile'

@accepts(Str('event', enum=['MASTER', 'BACKUP', 'SYNC'], default='MASTER'))
def setup(self, event):
def setup(
self,
event: Literal["MASTER", "BACKUP", "SYNC"] = "MASTER"
):
saved = Path(ZPOOL_CACHE_FILE_SAVED)
default = Path(ZPOOL_CACHE_FILE)
overwrite = Path(ZPOOL_CACHE_FILE_OVERWRITE)
Expand Down

0 comments on commit 01de1f7

Please sign in to comment.