From b7bc3d5e74cdc04a5f60969677f16cf6590a4369 Mon Sep 17 00:00:00 2001 From: Allan Carter Date: Fri, 20 Dec 2024 17:12:36 -0600 Subject: [PATCH] Fix uninitialized var when security groups stack not configured with res. (#294) --- source/cdk/cdk_slurm_stack.py | 73 +++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/source/cdk/cdk_slurm_stack.py b/source/cdk/cdk_slurm_stack.py index 9037017..acf53bd 100644 --- a/source/cdk/cdk_slurm_stack.py +++ b/source/cdk/cdk_slurm_stack.py @@ -710,51 +710,56 @@ def update_config_for_res(self): logger.error(f"RES VDC controller security group not found.") exit(1) - self.config['ExternalLoginNodes'] = self.config.get('ExternalLoginNodes', []) - self.config['ExternalLoginNodes'].append( - { + if 'AdditionalSecurityGroupsStackName' not in self.config: + logger.warning(f"Can't automatically configure RES ExternalLoginNodes or DomainJoinedInstance because AdditionalSecurityGroupsStackName not configured.") + + if 'AdditionalSecurityGroupsStackName' in self.config: + self.config['ExternalLoginNodes'] = self.config.get('ExternalLoginNodes', []) + self.config['ExternalLoginNodes'].append( + { + 'Tags': [ + { + 'Key': 'res:EnvironmentName', + 'Values': [self.res_environment_name] + }, + { + 'Key': 'res:NodeType', + 'Values': ['virtual-desktop-dcv-host'] + } + ], + 'SecurityGroupId': self.slurm_login_node_sg_id + } + ) + + if 'DomainJoinedInstance' in self.config: + logger.error(f"Can't specify both DomainJoinedInstance and RESStackName in config file.") + exit(1) + if 'AdditionalSecurityGroupsStackName' in self.config: + self.config['DomainJoinedInstance'] = { 'Tags': [ + { + 'Key': 'Name', + 'Values': [f"{self.res_environment_name}-cluster-manager",] + }, { 'Key': 'res:EnvironmentName', 'Values': [self.res_environment_name] }, + { + 'Key': 'res:ModuleName', + 'Values': ['cluster-manager'] + }, + { + 'Key': 'res:ModuleId', + 'Values': ['cluster-manager'] + }, { 'Key': 'res:NodeType', - 'Values': ['virtual-desktop-dcv-host'] + 'Values': ['app'] } ], 'SecurityGroupId': self.slurm_login_node_sg_id } - ) - - if 'DomainJoinedInstance' in self.config: - logger.error(f"Can't specify both DomainJoinedInstance and RESStackName in config file.") - exit(1) - self.config['DomainJoinedInstance'] = { - 'Tags': [ - { - 'Key': 'Name', - 'Values': [f"{self.res_environment_name}-cluster-manager",] - }, - { - 'Key': 'res:EnvironmentName', - 'Values': [self.res_environment_name] - }, - { - 'Key': 'res:ModuleName', - 'Values': ['cluster-manager'] - }, - { - 'Key': 'res:ModuleId', - 'Values': ['cluster-manager'] - }, - { - 'Key': 'res:NodeType', - 'Values': ['app'] - } - ], - 'SecurityGroupId': self.slurm_login_node_sg_id - } # Configure the /home mount from RES if /home not already configured home_mount_found = False