def test_receive_should_react_on_final_massage(self, mock_rel_massage): message_body = ( '{ ' '"status": "UPDATE_COMPLETE", ' '"timestamp": "2015-11-24T13:14:16.575Z", ' '"stackName": "my-teststack", ' '"message": "User Initiated", ' '"emitter": "cloudformation", ' '"resourceType": "AWS::CloudFormation::Stack"}') sqs = boto3.resource('sqs') queue = sqs.create_queue(QueueName='BACK_CHANNEL') queue.send_message(MessageBody=message_body) mock_rel_massage.return_value = True receive('BACK_CHANNEL', 600, 'my-teststack', 'eu-west-1', poll_interval=1)
def test_receive_should_log_error_massage(self, mock_rel_massage): message_body = ( '{ ' '"status": "failure", ' '"timestamp": "2015-11-24T13:14:16.575Z", ' '"stackName": "my-teststack", ' '"message": "User Initiated", ' '"emitter": "cloudformation", ' '"resourceType": "AWS::CloudFormation::Stack"}') sqs = boto3.resource('sqs') queue = sqs.create_queue(QueueName='BACK_CHANNEL') queue.send_message(MessageBody=message_body) mock_rel_massage.return_value = True with self.assertRaisesRegexp( DeploymentErrorException, 'Crassus failed with "User Initiated"'): receive('BACK_CHANNEL', 600, 'my-teststack', 'eu-west-1', poll_interval=1)
def test_receive_should_fail_on_no_cnf_message(self, mock_rel_massage): message_body = ( '{ ' '"status": "CREATE_FAILED", ' '"timestamp": "2015-11-24T13:14:16.575Z", ' '"stackName": "my-teststack", ' '"message": "User Initiated", ' '"emitter": "cloudformation", ' '"resourceType": "foo"}') sqs = boto3.resource('sqs') queue = sqs.create_queue(QueueName='BACK_CHANNEL') queue.send_message(MessageBody=message_body) mock_rel_massage.return_value = True with self.assertRaisesRegexp( DeploymentErrorException, 'No final CFN message was received after 1 seconds'): receive('BACK_CHANNEL', 1, 'my-teststack', 'eu-west-1', poll_interval=1)
def wait_success_from_backchannel(self, invoker_role): """ Waits for the cloudformation success message arriving from the cloudformation back channel converter, meaning the stack is updated and ready to run. This means, we read the backchannel (SQS Queue) and wait for a 'UPDATE_COMPLETE' message from cloudformation. Read for 20 minutes (to be on the safe side), raise error if not found, return if found. """ back_channel_url = self.get_stack_output( self.crassus_stack_name, 'outputSqsQueue') wait_seconds = 20 * 60 # Wait until this many seconds try: receive( back_channel_url, wait_seconds, self.app_stack_name, REGION_NAME) except DeploymentErrorException as e: # Failing with exception self.fail(e)
def test_receive_should_read_message_and_process(self, mock_rel_message): message_body = ( '{ ' '"status": "UPDATE_IN_PROGRESS", ' '"timestamp": "2015-11-24T13:14:16.575Z", ' '"stackName": "my-teststack", ' '"message": "User Initiated", ' '"emitter": "cloudformation"}') sqs = boto3.resource('sqs') queue = sqs.create_queue(QueueName='BACK_CHANNEL') queue.send_message(MessageBody=message_body) mock_rel_message.return_value = False with self.assertRaisesRegexp( DeploymentErrorException, 'No final CFN message was received after 1 seconds'): receive('BACK_CHANNEL', 1, 'my-another-teststack', 'eu-west-1', poll_interval=1) with self.assertRaisesRegexp( DeploymentErrorException, 'No final CFN message was received after 1 seconds'): receive('BACK_CHANNEL', 1, 'my-teststack', 'eu-west-1', poll_interval=1)