def get_resource_name(self, stack_name, logical_name): try: return self.cf_client.describe_stack_resource( StackName=stack_name, LogicalResourceId=logical_name )['StackResourceDetail']['PhysicalResourceId'] except Exception as e: Log.error('resource {0} in stack {1} not found'.format(logical_name, stack_name), e)
def check_configs_are_set(self): missing_configs = [ config for config, value in self.SIT_CONFIGS.iteritems() if value is None ] if missing_configs: Log.error('The following configs are not set: {0}'.format( missing_configs))
def check_roles_not_empty(self): empty_roles = [ role for role in self.ROLES if not self.sit_helper.get_states_for_role(role) ] if empty_roles: Log.error( 'The following servers are missing roles inside of roles.yml file: {0}' .format(empty_roles))
def get_resource_name(self, stack_name, logical_name): try: return self.cf_client.describe_stack_resource( StackName=stack_name, LogicalResourceId=logical_name )['StackResourceDetail']['PhysicalResourceId'] except Exception as e: Log.error( 'resource {0} in stack {1} not found'.format( logical_name, stack_name), e)
def update_stack(self, stack_name, template_body, tag_value): logging.info('Updating stack: {0}'.format(stack_name)) try: self.cf_client.update_stack(StackName=stack_name, TemplateBody=template_body, Capabilities=['CAPABILITY_IAM'], Tags=[{ 'Key': 'Name', 'Value': tag_value }])['StackId'] except Exception as e: Log.error('Failed to update stack {0}'.format(stack_name), e)
def update_stack(self, stack_name, template_body, tag_value): logging.info('Updating stack: {0}'.format(stack_name)) try: self.cf_client.update_stack( StackName=stack_name, TemplateBody=template_body, Capabilities=['CAPABILITY_IAM'], Tags=[ { 'Key': 'Name', 'Value': tag_value } ] )['StackId'] except Exception as e: Log.error('Failed to update stack {0}'.format(stack_name), e)
def check_stack_exists(self): stack_name = self.TROPOSPHERE_CONFIGS['stack_name'] if not self.cf_helper.get_stack_info(stack_name): Log.error( 'Stack "{0}" does not exist. Please run setup_troposphere'. format(stack_name))
def check_roles_file(self): if self.ROLES < 1: Log.error( 'roles.yml file is not setup properly. You require at least one role to test' )
def check_stack_exists(self): stack_name = self.TROPOSPHERE_CONFIGS['stack_name'] if not self.cf_helper.get_stack_info(stack_name): Log.error('Stack "{0}" does not exist. Please run setup_troposphere'.format(stack_name))
def stack_created_successfully(self): if not self.cf_helper.stack_was_created_successfully(self.STACK_NAME): Log.error('stack was not created')
def check_configs_are_set(self): missing_configs = [config for config, value in self.SIT_CONFIGS.iteritems() if value is None] if missing_configs: Log.error('The following configs are not set: {0}'.format(missing_configs))
def validate_template(self, template_body): logging.info('Validating template') try: self.cf_client.validate_template(TemplateBody=template_body) except Exception as e: Log.error('stack validation error', e)
def test_error(self): self.assertRaises(SystemExit, Log.error(2))
def validate_configs(self): logging.info('Validating configs') missing_configs = [config for config, value in self.configs.iteritems() if value is None] if missing_configs: Log.error('The following configs have not been added in configs/troposphere.yml: {0}'.format(missing_configs))
def check_roles_file(self): if self.ROLES < 1: Log.error('roles.yml file is not setup properly. You require at least one role to test')
def not_found_error(self, resource_name, resource): Log.error('{0} "{1}" not found. Please update configs/troposphere.yml'.format(resource_name, resource))
def check_roles_not_empty(self): empty_roles = [role for role in self.ROLES if not self.sit_helper.get_states_for_role(role)] if empty_roles: Log.error('The following servers are missing roles inside of roles.yml file: {0}'.format(empty_roles))