Ejemplo n.º 1
0
    def test_project_settings_missing_object(self):

        mock_configuration_bucket_arn = 'mock-arn'

        error_response = {
            'Error': {
                'Message': 'Access Denied',
                'Code': 'AccessDenied'
            }
        }

        client_error = ClientError(error_response, 'get_object')

        with mock_aws.patch_client('s3',
                                   'get_object',
                                   side_effect=client_error,
                                   reload=stack_info) as mock_get_object:
            with mock.patch(
                    'resource_manager_common.stack_info.ProjectInfo.configuration_bucket',
                    new_callable=mock.PropertyMock,
                    return_value=mock_configuration_bucket_arn):
                target = stack_info.ProjectInfo(MOCK_STACK_ARN)
                actual_project_settings = target.project_settings
                self.assertEquals(actual_project_settings, {})
                mock_get_object.assert_called_once_with(
                    Bucket=mock_configuration_bucket_arn,
                    Key='project-settings.json')
Ejemplo n.º 2
0
 def test_deployment_access_arn_discovered_with_deleted(self):
     mock_deployment_access_stack_arn = 'deployment-access-stack-arn'
     mock_describe_stacks_result = {
         'Stacks': [{
             'StackId': 'wrong-stack-id',
             'StackStatus': 'DELETE_COMPLETE'
         }, {
             'StackId': mock_deployment_access_stack_arn,
             'StackStatus': 'UPDATE_COMPLETE'
         }]
     }
     mock_deployment_access_stack_name = MOCK_STACK_NAME + '-Access'
     mock_deployment_access = 'test-deployment-access'
     with mock.patch(
             'resource_manager_common.stack_info.DeploymentAccessInfo',
             return_value=mock_deployment_access
     ) as mock_DeploymentAccessInfo:
         with mock_aws.patch_client('cloudformation',
                                    'describe_stacks',
                                    return_value=mock_describe_stacks_result
                                    ) as mock_describe_stacks:
             target = stack_info.DeploymentInfo(MOCK_STACK_ARN)
             actual_deployment_access = target.deployment_access
             self.assertIs(actual_deployment_access, mock_deployment_access)
             mock_DeploymentAccessInfo.assert_called_once_with(
                 mock_deployment_access_stack_arn,
                 deployment_info=target,
                 client=target.client)
             mock_describe_stacks.assert_called_once_with(
                 StackName=mock_deployment_access_stack_name)
Ejemplo n.º 3
0
    def test_project_settings(self):

        mock_project_settings = {'Test': 'Setting'}

        mock_configuration_bucket_arn = 'mock-arn'

        mock_response = mock_aws.s3_get_object_response(
            json.dumps(mock_project_settings))

        with mock_aws.patch_client('s3',
                                   'get_object',
                                   return_value=mock_response,
                                   reload=stack_info) as mock_get_object:
            with mock.patch(
                    'resource_manager_common.stack_info.ProjectInfo.configuration_bucket',
                    new_callable=mock.PropertyMock,
                    return_value=mock_configuration_bucket_arn):
                with mock.patch(
                        "resource_manager_common.json_utils.JSONCustomEncoder.default",
                        return_value='mock'):
                    target = stack_info.ProjectInfo(MOCK_STACK_ARN)
                    actual_project_settings = target.project_settings
                    self.assertEquals(actual_project_settings,
                                      mock_project_settings)
                    mock_get_object.assert_called_once_with(
                        Bucket=mock_configuration_bucket_arn,
                        Key='project-settings.json')
Ejemplo n.º 4
0
 def test_resources(self):
     mock_resource_summary_1 = make_random_resource_summary()
     mock_resource_summary_2 = make_random_resource_summary()
     mock_resource_summary_list = [
         mock_resource_summary_1, mock_resource_summary_2
     ]
     mock_response = make_list_stack_resources_response(
         mock_resource_summary_list)
     mock_resources = ['mock-resource-info-1', 'mock-resource-info-2']
     with mock_aws.patch_client(
             'cloudformation',
             'list_stack_resources',
             return_value=mock_response) as mock_list_stack_resources:
         with mock.patch('resource_manager_common.stack_info.ResourceInfo',
                         side_effect=mock_resources) as mock_ResourceInfo:
             target = stack_info.StackInfo(MOCK_STACK_ARN, MOCK_STACK_TYPE)
             actual_resources = target.resources
             actual_resources_2 = target.resources
             self.assertItemsEqual(actual_resources, mock_resources)
             self.assertIs(actual_resources, actual_resources_2)
             self.assertIs(actual_resources.stack, target)
             mock_list_stack_resources.assert_called_once_with(
                 StackName=MOCK_STACK_ARN)
             mock_ResourceInfo.assert_any_call(target,
                                               mock_resource_summary_1)
             mock_ResourceInfo.assert_any_call(target,
                                               mock_resource_summary_2)
Ejemplo n.º 5
0
 def test_with_no_stack_type(self):
     mock_response = make_describe_stacks_response(MOCK_STACK_DESCRIPTION)
     with mock_aws.patch_client(
             'cloudformation', 'describe_stacks',
             return_value=mock_response) as mock_describe_stacks:
         with self.assertRaisesRegexp(RuntimeError, MOCK_STACK_ARN):
             stack_info.get_stack_info(MOCK_STACK_ARN)
         mock_describe_stacks.client_factory.assert_called_once_with(
             'cloudformation', region_name=MOCK_REGION)
         mock_describe_stacks.assert_called_once_with(
             StackName=MOCK_STACK_ARN)
Ejemplo n.º 6
0
 def test_stack_description_loaded(self):
     mock_response = make_describe_stacks_response(MOCK_STACK_DESCRIPTION)
     with mock_aws.patch_client(
             'cloudformation', 'describe_stacks',
             return_value=mock_response) as mock_describe_stacks:
         target = stack_info.StackInfo(MOCK_STACK_ARN, MOCK_STACK_TYPE)
         actual_stack_description = target.stack_description
         actual_stack_description_2 = target.stack_description
         self.assertEquals(actual_stack_description, MOCK_STACK_DESCRIPTION)
         self.assertIs(actual_stack_description, actual_stack_description_2)
         mock_describe_stacks.assert_called_once_with(
             StackName=MOCK_STACK_ARN)
Ejemplo n.º 7
0
 def test_with_deployment_stack(self):
     mock_response = make_describe_stacks_response(
         make_stack_description(stack_info.StackInfo.STACK_TYPE_DEPLOYMENT))
     with mock_aws.patch_client(
             'cloudformation', 'describe_stacks',
             return_value=mock_response) as mock_describe_stacks:
         result = stack_info.get_stack_info(MOCK_STACK_ARN)
         self.assertIsInstance(result, stack_info.DeploymentInfo)
         self.assertEqual(result.stack_type,
                          stack_info.StackInfo.STACK_TYPE_DEPLOYMENT)
         mock_describe_stacks.client_factory.assert_called_once_with(
             'cloudformation', region_name=MOCK_REGION)
         mock_describe_stacks.assert_called_once_with(
             StackName=MOCK_STACK_ARN)
Ejemplo n.º 8
0
 def test_deployment_access_arn_discovered_with_access_denied(self):
     mock_describe_stacks_result = ClientError(
         {'Error': {
             'Code': 'ValidationError'
         }}, 'describe-stacks')
     mock_deployment_access_stack_name = MOCK_STACK_NAME + '-Access'
     with mock_aws.patch_client('cloudformation',
                                'describe_stacks',
                                side_effect=mock_describe_stacks_result
                                ) as mock_describe_stacks:
         target = stack_info.DeploymentInfo(MOCK_STACK_ARN)
         actual_deployment_access = target.deployment_access
         self.assertIsNone(actual_deployment_access)
         mock_describe_stacks.assert_called_once_with(
             StackName=mock_deployment_access_stack_name)
Ejemplo n.º 9
0
 def test_deployment_access_arn_discovered_with_not_access_denied(self):
     mock_error_code = 'SomeErrorCode'
     mock_describe_stacks_result = ClientError(
         {'Error': {
             'Code': mock_error_code
         }}, 'describe-stacks')
     mock_deployment_access_stack_name = MOCK_STACK_NAME + '-Access'
     with mock_aws.patch_client('cloudformation',
                                'describe_stacks',
                                side_effect=mock_describe_stacks_result
                                ) as mock_describe_stacks:
         target = stack_info.DeploymentInfo(MOCK_STACK_ARN)
         with self.assertRaisesRegexp(ClientError, mock_error_code):
             actual_deployment_access = target.deployment_access
         mock_describe_stacks.assert_called_once_with(
             StackName=mock_deployment_access_stack_name)
Ejemplo n.º 10
0
 def test_deployment_access_arn_discovered_with_deleted_only(self):
     mock_deployment_access_stack_arn = 'deployment-access-stack-arn'
     mock_describe_stacks_result = {
         'Stacks': [{
             'StackId': 'wrong-stack-id',
             'StackStatus': 'DELETE_COMPLETE'
         }, {
             'StackId': mock_deployment_access_stack_arn,
             'StackStatus': 'DELETE_COMPLETE'
         }]
     }
     mock_deployment_access_stack_name = MOCK_STACK_NAME + '-Access'
     with mock_aws.patch_client('cloudformation',
                                'describe_stacks',
                                return_value=mock_describe_stacks_result
                                ) as mock_describe_stacks:
         target = stack_info.DeploymentInfo(MOCK_STACK_ARN)
         actual_deployment_access = target.deployment_access
         self.assertIsNone(actual_deployment_access)
         mock_describe_stacks.assert_called_once_with(
             StackName=mock_deployment_access_stack_name)