Skip to content

Commit 403dbcf

Browse files
committed
BUGFIX:
- Schema validator did not work, if node had no instances - /node add_instance failed, if no instances were defined in nodes.yaml
1 parent 4a8bcce commit 403dbcf

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

core/data/impl/nodeimpl.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ async def init_db(self) -> tuple[ConnectionPool, AsyncConnectionPool]:
254254
try:
255255
aconn = await psycopg.AsyncConnection.connect(url)
256256
async with aconn:
257-
self.log.info("- Connection to database established.")
257+
cursor = await aconn.execute("SELECT version()")
258+
version = (await cursor.fetchone())[0]
259+
self.log.info(f"- Connection to {version} established.")
258260
break
259261
except OperationalError:
260262
if attempt == max_attempts:
@@ -377,10 +379,9 @@ async def _upgrade_pending_git(self) -> bool:
377379
self.log.error(f' ./{item.a_path}')
378380
else:
379381
self.log.error(ex)
380-
return False
381382
except ValueError as ex:
382383
self.log.error(ex)
383-
return False
384+
return False
384385

385386
async def _upgrade_pending_non_git(self) -> bool:
386387
try:
@@ -1004,6 +1005,8 @@ async def before_autoupdate(self):
10041005
await asyncio.sleep(1)
10051006

10061007
async def add_instance(self, name: str, *, template: str = "") -> "Instance":
1008+
from services.servicebus import ServiceBus
1009+
10071010
max_bot_port = max_dcs_port = max_webgui_port = -1
10081011
for instance in self.instances:
10091012
if instance.bot_port > max_bot_port:
@@ -1038,6 +1041,8 @@ async def add_instance(self, name: str, *, template: str = "") -> "Instance":
10381041
config_file = os.path.join(self.config_dir, 'nodes.yaml')
10391042
with open(config_file, mode='r', encoding='utf-8') as infile:
10401043
config = yaml.load(infile)
1044+
if 'instances' not in config[self.name]:
1045+
config[self.name]['instances'] = {}
10411046
config[self.name]['instances'][instance.name] = {
10421047
"home": instance.home,
10431048
"bot_port": instance.bot_port
@@ -1049,7 +1054,8 @@ async def add_instance(self, name: str, *, template: str = "") -> "Instance":
10491054
settings = SettingsDict(self, settings_path, root='cfg')
10501055
settings['port'] = instance.dcs_port
10511056
settings['name'] = 'n/a'
1052-
server = DataObjectFactory().new(ServerImpl, node=self.node, port=instance.bot_port, name='n/a')
1057+
bus = ServiceRegistry.get(ServiceBus)
1058+
server = DataObjectFactory().new(ServerImpl, node=self.node, port=instance.bot_port, name='n/a', bus=bus)
10531059
instance.server = server
10541060
self.instances.append(instance)
10551061
return instance
@@ -1113,11 +1119,12 @@ async def migrate_server(self, server: Server, instance: Instance) -> None:
11131119
from services.servicebus import ServiceBus
11141120

11151121
await server.node.unregister_server(server)
1116-
server = DataObjectFactory().new(ServerImpl, node=self.node, port=instance.bot_port, name=server.name, bus=self)
1122+
bus = ServiceRegistry.get(ServiceBus)
1123+
server = DataObjectFactory().new(ServerImpl, node=self.node, port=instance.bot_port, name=server.name, bus=bus)
11171124
instance.server = server
1118-
ServiceRegistry.get(ServiceBus).servers[server.name] = server
1125+
bus.servers[server.name] = server
11191126
if not self.master:
1120-
await ServiceRegistry.get(ServiceBus).send_init(server)
1127+
await bus.send_init(server)
11211128
server.status = Status.SHUTDOWN
11221129

11231130
async def unregister_server(self, server: Server) -> None:

core/services/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ async def wrapper(self, server: Server, *args, **kwargs):
7171

7272

7373
class Service(ABC):
74+
dependencies: list[type[Service]] = None
75+
7476
def __init__(self, node: NodeImpl, name: Optional[str] = None):
7577
self.name = name or self.__class__.__name__
7678
self.running: bool = False

core/utils/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def check_main_structure(value, rule_obj, path):
262262
raise SchemaError(msg="The DEFAULT tag must not have any instances!", path=path)
263263
elif element in node_data.nodes:
264264
for instance in value[element].keys():
265-
if instance not in node_data.instances[element]:
265+
if instance not in node_data.instances.get(element, {}):
266266
raise SchemaError(
267267
msg=f"{instance} is not an instance name of node {element}!",
268268
path=path + '/' + element

0 commit comments

Comments
 (0)