예제 #1
0
    def test_copy_snapshot_failure(self, mock_boto3):
        """Assert that an error is given when copy fails."""
        mock_region = random.choice(helper.SOME_AWS_REGIONS)
        mock_snapshot = helper.generate_mock_snapshot()

        mock_copy_error = {
            'Error': {
                'Code': 'MockError',
                'Message': 'The operation failed.'
            }
        }

        resource = mock_boto3.resource.return_value
        resource.Snapshot.return_value = mock_snapshot
        mock_snapshot.copy.side_effect = ClientError(mock_copy_error,
                                                     'CopySnapshot')

        with self.assertRaises(ClientError):
            ec2.copy_snapshot(mock_snapshot.snapshot_id, mock_region)
예제 #2
0
    def test_copy_snapshot_failure(self, mock_boto3):
        """Assert that an error is given when copy fails."""
        mock_region = helper.get_random_region()
        mock_snapshot = helper.generate_mock_snapshot()

        mock_copy_error = {
            "Error": {
                "Code": "MockError",
                "Message": "The operation failed."
            }
        }

        resource = mock_boto3.resource.return_value
        resource.Snapshot.return_value = mock_snapshot
        mock_snapshot.copy.side_effect = ClientError(mock_copy_error,
                                                     "CopySnapshot")

        with self.assertRaises(ClientError):
            ec2.copy_snapshot(mock_snapshot.snapshot_id, mock_region)
예제 #3
0
    def test_copy_snapshot_limit_reached(self, mock_boto3):
        """Assert that an error is returned when the copy limit is reached."""
        mock_region = random.choice(helper.SOME_AWS_REGIONS)
        mock_snapshot = helper.generate_mock_snapshot()

        mock_copy_error = {
            'Error': {
                'Code':
                'ResourceLimitExceeded',
                'Message':
                'You have exceeded an Amazon EC2 resource limit. '
                'For example, you might have too many snapshot '
                'copies in progress.'
            }
        }

        resource = mock_boto3.resource.return_value
        resource.Snapshot.return_value = mock_snapshot
        mock_snapshot.copy.side_effect = ClientError(mock_copy_error,
                                                     'CopySnapshot')

        with self.assertRaises(AwsSnapshotCopyLimitError):
            ec2.copy_snapshot(mock_snapshot.snapshot_id, mock_region)
예제 #4
0
    def test_copy_snapshot_success(self, mock_boto3):
        """Assert that a snapshot copy operation begins."""
        mock_region = random.choice(helper.SOME_AWS_REGIONS)
        mock_snapshot = helper.generate_mock_snapshot()
        mock_copied_snapshot_id = helper.generate_dummy_snapshot_id()
        mock_copy_result = {'SnapshotId': mock_copied_snapshot_id}

        resource = mock_boto3.resource.return_value
        resource.Snapshot.return_value = mock_snapshot
        mock_snapshot.copy.return_value = mock_copy_result

        actual_copied_snapshot_id = ec2.copy_snapshot(
            mock_snapshot.snapshot_id, mock_region)
        self.assertEqual(actual_copied_snapshot_id, mock_copied_snapshot_id)
예제 #5
0
    def test_copy_snapshot_limit_reached(self, mock_boto3):
        """Assert that an error is returned when the copy limit is reached."""
        mock_region = helper.get_random_region()
        mock_snapshot = helper.generate_mock_snapshot()

        mock_copy_error = {
            "Error": {
                "Code":
                "ResourceLimitExceeded",
                "Message":
                "You have exceeded an Amazon EC2 resource limit. "
                "For example, you might have too many snapshot "
                "copies in progress.",
            }
        }

        resource = mock_boto3.resource.return_value
        resource.Snapshot.return_value = mock_snapshot
        mock_snapshot.copy.side_effect = ClientError(mock_copy_error,
                                                     "CopySnapshot")

        with self.assertRaises(AwsSnapshotCopyLimitError):
            ec2.copy_snapshot(mock_snapshot.snapshot_id, mock_region)