예제 #1
0
    def test_create_zone_raise_error(self, mock_post, mock_auth):
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        json_data = {'title': 'Missing parameter', 'detail': 'Missed A option'}
        mock_post.return_value = self.gen_response(400, 'Bad Request',
                                                   json_data)

        with fixtures.random_seed(0):
            self.assertRaisesRegex(
                exceptions.Backend,
                'Zone creation failed due to: Missed A option',
                backend.create_zone, self.admin_context, self.zone)

        project_id = self.admin_context.project_id or self.zone.tenant_id
        mock_post.assert_called_once_with(
            json={
                'comment': 'Created by Designate for Tenant %s' % project_id,
                'masters': ['192.168.1.1', '192.168.1.2'],
                'type': 'secondary',
                'zone': 'example.com.'
            },
            params={
                'gid': '777',
                'contractId': 'G-XYW'
            },
            url='https://host_value/config-dns/v2/zones')
예제 #2
0
    def test_soft_delete_zone_missed_request_id(self, mock_post, mock_auth):
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        mock_post.side_effect = [
            # emulate, when Force=True is forbidden
            self.gen_response(403, 'Forbidden'),
            # emulate request, when Force=False
            self.gen_response(200, 'Success')
        ]

        with fixtures.random_seed(0):
            self.assertRaisesRegex(
                exceptions.Backend,
                'Zone deletion failed due to: requestId missed in response',
                backend.delete_zone, self.admin_context, self.zone)

        mock_post.assert_has_calls([
            mock.call(
                json={'zones': [u'example.com.']},
                params={'force': True},
                url='https://host_value/config-dns/v2/zones/delete-requests'),
            mock.call(
                json={'zones': [u'example.com.']},
                params={'force': False},
                url='https://host_value/config-dns/v2/zones/delete-requests')
        ])
예제 #3
0
    def test_create_zone_duplicate_zone(self, mock_post, mock_auth):
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        mock_post.return_value = self.gen_response(409, 'Conflict')

        with fixtures.random_seed(0):
            backend.create_zone(self.admin_context, self.zone)

        project_id = self.admin_context.project_id or self.zone.tenant_id
        mock_post.assert_called_once_with(
            json={
                'comment': 'Created by Designate for Tenant %s' % project_id,
                'masters': ['192.168.1.1', '192.168.1.2'],
                'type': 'secondary',
                'zone': u'example.com.'
            },
            params={
                'gid': '777',
                'contractId': 'G-XYW'
            },
            url='https://host_value/config-dns/v2/zones')
예제 #4
0
    def test_create_zone(self, mock_execute):
        with fixtures.random_seed(0):
            self.backend.create_zone(self.admin_context, self.zone)

        mock_execute.assert_called_with([
            'addzone',
            'example.com  { type slave; masters { 192.168.1.1 port 53; 192.168.1.2 port 35;}; file "slave.example.com.cca7908b-dad4-4c50-adba-fb67d4c556e8"; };'  # noqa
        ])
예제 #5
0
    def test_create_zone_with_view(self, mock_execute):
        self.target['options'].append({'key': 'view', 'value': 'guest'}, )

        backend = impl_bind9.Bind9Backend(
            objects.PoolTarget.from_dict(self.target))

        with fixtures.random_seed(1):
            backend.create_zone(self.admin_context, self.zone)

        mock_execute.assert_called_with([
            'addzone',
            'example.com in guest { type slave; masters { 192.168.1.2 port 35; 192.168.1.1 port 53;}; file "slave.example.com.cca7908b-dad4-4c50-adba-fb67d4c556e8"; };'  # noqa
        ])
예제 #6
0
    def test_force_delete_zone(self, mock_post, mock_auth):
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        mock_post.return_value = self.gen_response(200, 'Success')

        with fixtures.random_seed(0):
            backend.delete_zone(self.admin_context, self.zone)

        mock_post.assert_called_once_with(
            json={'zones': ['example.com.']},
            params={'force': True},
            url='https://host_value/config-dns/v2/zones/delete-requests')
예제 #7
0
    def test_soft_delete_zone_failed_after_10_attempts(self, mock_get,
                                                       mock_post, mock_auth):
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        mock_post.side_effect = [
            # emulate, when Force=True is forbidden
            self.gen_response(403, 'Forbidden'),
            # emulate request, when Force=False
            self.gen_response(200, 'Success', {'requestId': 'nice_id'}),
        ]

        # emulate max 10 failed attempts
        mock_get.side_effect = 10 * [
            self.gen_response(200, 'Success', {'isComplete': False})
        ]

        with fixtures.random_seed(0), \
                mock.patch.object(akamai.time, 'sleep') as mock_sleep:
            mock_sleep.return_value = None
            self.assertRaisesRegex(exceptions.Backend,
                                   'Zone was not deleted after 10 attempts',
                                   backend.delete_zone, self.admin_context,
                                   self.zone)

        self.assertEqual(10, mock_sleep.call_count)

        url = 'https://host_value/config-dns/v2/zones/delete-requests/nice_id'
        mock_get.assert_has_calls(10 * [mock.call(url=url)])

        mock_post.assert_has_calls([
            mock.call(
                json={'zones': ['example.com.']},
                params={'force': True},
                url='https://host_value/config-dns/v2/zones/delete-requests'),
            mock.call(
                json={'zones': ['example.com.']},
                params={'force': False},
                url='https://host_value/config-dns/v2/zones/delete-requests')
        ])
예제 #8
0
    def test_create_zone_missed_contract_id(self, mock_post, mock_auth):
        self.target['options'].remove({
            'key': 'akamai_contract_id',
            'value': 'G-XYW'
        })
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        with fixtures.random_seed(0):
            self.assertRaisesRegex(exceptions.Backend,
                                   'contractId is required for zone creation',
                                   backend.create_zone, self.admin_context,
                                   self.zone)

        mock_post.assert_not_called()
예제 #9
0
    def test_force_delete_zone_raise_error(self, mock_post, mock_auth):
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        mock_post.return_value = self.gen_response(
            403, 'Bad Request', {'detail': 'Unexpected error'})

        with fixtures.random_seed(0):
            self.assertRaisesRegex(
                exceptions.Backend,
                'Zone deletion failed due to: Unexpected error',
                backend.delete_zone, self.admin_context, self.zone)

        mock_post.assert_called_once_with(
            json={'zones': ['example.com.']},
            params={'force': True},
            url='https://host_value/config-dns/v2/zones/delete-requests')
예제 #10
0
    def test_create_zone_with_tsig_key(self, mock_post, mock_auth):
        self.target['options'].extend([{
            'key': 'tsig_key_name',
            'value': 'test_key'
        }, {
            'key': 'tsig_key_algorithm',
            'value': 'hmac-sha512'
        }, {
            'key': 'tsig_key_secret',
            'value': 'aaaabbbbccc'
        }])
        backend = akamai.AkamaiBackend(
            objects.PoolTarget.from_dict(self.target))
        mock_auth.EdgeGridAuth.assert_called_once_with(
            access_token='access_token',
            client_secret='client_secret',
            client_token='client_token')

        with fixtures.random_seed(0):
            backend.create_zone(self.admin_context, self.zone)

        project_id = self.admin_context.project_id or self.zone.tenant_id
        mock_post.assert_called_once_with(
            json={
                'comment': 'Created by Designate for Tenant %s' % project_id,
                'masters': ['192.168.1.1', '192.168.1.2'],
                'type': 'secondary',
                'zone': 'example.com.',
                'tsigKey': {
                    'name': 'test_key',
                    'algorithm': 'hmac-sha512',
                    'secret': 'aaaabbbbccc',
                }
            },
            params={
                'gid': '777',
                'contractId': 'G-XYW'
            },
            url='https://host_value/config-dns/v2/zones')