Skip to content

Commit c141a08

Browse files
authored
NAS-133457 / 25.10 / TNC Support for HA (#16374)
1 parent 8650f16 commit c141a08

File tree

4 files changed

+55
-34
lines changed

4 files changed

+55
-34
lines changed

src/middlewared/middlewared/plugins/failover_/event.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ def vrrp_master(self, job, fobj, ifname, event):
755755
self.run_call('truecommand.start_truecommand_service')
756756
logger.info('Done starting truecommand service (if necessary)')
757757

758+
logger.info('Configuring TrueNAS Connect Service (if necessary)')
759+
self.run_call('tn_connect.state.check')
760+
logger.info('Configuring TrueNAS Connect Service (if necessary)')
761+
758762
# The system, while it was in BACKUP state, might have failed to contact the remote node and reached a
759763
# conclusion that the other node needs to be rebooted. Let's clean this up.
760764
self.run_call('failover.reboot.discard_unbound_remote_reboot_reasons')

src/middlewared/middlewared/plugins/truenas_connect/acme.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ async def update_ui(self):
3838
# Let's restart UI now
3939
# TODO: Hash this out with everyone
4040
await self.middleware.call('system.general.ui_restart', 2)
41+
if await self.middleware.call('failover.licensed'):
42+
# We would like to make sure nginx is reloaded on the remote controller as well
43+
logger.debug('Restarting UI on remote controller')
44+
try:
45+
await self.middleware.call(
46+
'failover.call_remote', 'system.general.ui_restart', [2],
47+
{'raise_connect_error': False, 'timeout': 2, 'connect_timeout': 2}
48+
)
49+
except Exception:
50+
logger.error('Failed to restart UI on remote controller', exc_info=True)
4151

4252
async def update_ui_impl(self):
4353
config = await self.middleware.call('tn_connect.config')
@@ -139,18 +149,10 @@ async def revoke_cert(self):
139149

140150

141151
async def check_status(middleware):
142-
tnc_config = await middleware.call('tn_connect.config')
143-
if tnc_config['status'] == Status.CERT_GENERATION_IN_PROGRESS.name:
144-
logger.debug('Middleware started and cert generation is in progress, initiating process')
145-
middleware.create_task(middleware.call('tn_connect.acme.initiate_cert_generation'))
146-
elif tnc_config['status'] in (
147-
Status.CERT_GENERATION_SUCCESS.name, Status.CERT_RENEWAL_SUCCESS.name,
148-
):
149-
logger.debug('Middleware started and cert generation is already successful, updating UI')
150-
middleware.create_task(middleware.call('tn_connect.acme.update_ui'))
151-
elif tnc_config['status'] == Status.CERT_RENEWAL_IN_PROGRESS.name:
152-
logger.debug('Middleware started and cert renewal is in progress, initiating process')
153-
middleware.create_task(middleware.call('tn_connect.acme.renew_cert'))
152+
if not await middleware.call('failover.is_single_master_node'):
153+
return
154+
155+
await middleware.call('tn_connect.state.check')
154156

155157

156158
async def _event_system_ready(middleware, event_type, args):

src/middlewared/middlewared/plugins/truenas_connect/finalize_registration.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,3 @@ async def poll_once(self, claim_token, system_id, tnc_config):
103103
get_registration_finalization_uri(tnc_config), 'post',
104104
payload={'system_id': system_id, 'claim_token': claim_token},
105105
)
106-
107-
108-
async def check_status(middleware):
109-
tn_config = await middleware.call('tn_connect.config')
110-
if tn_config['status'] == Status.REGISTRATION_FINALIZATION_WAITING.name:
111-
logger.debug(
112-
'Registration finalization failed as middleware was restarted while waiting '
113-
'for TNC registration finalization'
114-
)
115-
# This means middleware got restarted or the system was rebooted while we were waiting for
116-
# registration to finalize, so in this case we set the state to registration failed
117-
await middleware.call('tn_connect.finalize.status_update', Status.REGISTRATION_FINALIZATION_FAILED)
118-
119-
120-
async def _event_system_ready(middleware, event_type, args):
121-
await check_status(middleware)
122-
123-
124-
async def setup(middleware):
125-
middleware.event_subscribe('system.ready', _event_system_ready)
126-
if await middleware.call('system.ready'):
127-
await check_status(middleware)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import logging
2+
3+
from truenas_connect_utils.status import Status
4+
5+
from middlewared.service import Service
6+
7+
8+
logger = logging.getLogger('truenas_connect')
9+
10+
11+
class TrueNASConnectStateService(Service):
12+
13+
class Config:
14+
namespace = 'tn_connect.state'
15+
private = True
16+
17+
async def check(self):
18+
tnc_config = await self.middleware.call('tn_connect.config')
19+
if tnc_config['status'] == Status.REGISTRATION_FINALIZATION_WAITING.name:
20+
logger.debug(
21+
'Registration finalization failed as middleware was restarted while waiting '
22+
'for TNC registration finalization'
23+
)
24+
# This means middleware got restarted or the system was rebooted while we were waiting for
25+
# registration to finalize, so in this case we set the state to registration failed
26+
await self.middleware.call('tn_connect.finalize.status_update', Status.REGISTRATION_FINALIZATION_FAILED)
27+
elif tnc_config['status'] == Status.CERT_GENERATION_IN_PROGRESS.name:
28+
logger.debug('Middleware started and cert generation is in progress, initiating process')
29+
self.middleware.create_task(self.middleware.call('tn_connect.acme.initiate_cert_generation'))
30+
elif tnc_config['status'] in (
31+
Status.CERT_GENERATION_SUCCESS.name, Status.CERT_RENEWAL_SUCCESS.name,
32+
):
33+
logger.debug('Middleware started and cert generation is already successful, updating UI')
34+
self.middleware.create_task(self.middleware.call('tn_connect.acme.update_ui'))
35+
elif tnc_config['status'] == Status.CERT_RENEWAL_IN_PROGRESS.name:
36+
logger.debug('Middleware started and cert renewal is in progress, initiating process')
37+
self.middleware.create_task(self.middleware.call('tn_connect.acme.renew_cert'))

0 commit comments

Comments
 (0)