Merge "Add basic get backend test"

This commit is contained in:
Zuul 2022-08-16 01:39:33 +00:00 committed by Gerrit Code Review
commit 927e34ee5a
4 changed files with 60 additions and 30 deletions

View File

@ -27,12 +27,13 @@ GOOD_STATUSES = [
def get_backend(target):
cls = base.Backend.get_driver(target.type)
msg = "Backend Driver '%s' loaded. Has status of '%s'" \
% (target.type, cls.__backend_status__)
message = "Backend Driver '%s' loaded. Has status of '%s'" % (
target.type, cls.__backend_status__
)
if cls.__backend_status__ in GOOD_STATUSES:
LOG.info(msg)
LOG.info(message)
else:
LOG.warning(msg)
LOG.warning(message)
return cls(target)

View File

@ -51,12 +51,6 @@ class Backend(DriverPlugin):
self.max_retries = CONF['service:worker'].poll_max_retries
self.delay = CONF['service:worker'].poll_delay
def start(self):
LOG.info('Starting %s backend', self.get_canonical_name())
def stop(self):
LOG.info('Stopped %s backend', self.get_canonical_name())
# Core Backend Interface
@abc.abstractmethod
def create_zone(self, context, zone):

View File

@ -1,20 +0,0 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Author: Kiall Mac Innes <kiall@hpe.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from designate.tests import TestCase
class BackendTestCase(TestCase):
pass

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import oslotest.base
import stevedore.exception
from designate import backend
from designate.backend import impl_pdns4
from designate import context
from designate import objects
class BaseBackendTestCase(oslotest.base.BaseTestCase):
def setUp(self):
super(BaseBackendTestCase, self).setUp()
self.context = mock.Mock()
self.admin_context = mock.Mock()
mock.patch.object(
context.DesignateContext, 'get_admin_context',
return_value=self.admin_context).start()
self.target = {
'type': 'pdns4',
'masters': [
],
'options': [
],
}
def test_get_backend(self):
pool_target = objects.PoolTarget.from_dict(self.target)
self.assertIsInstance(
backend.get_backend(pool_target),
impl_pdns4.PDNS4Backend
)
def test_get_backend_does_not_exist(self):
self.target['type'] = 'unknown'
pool_target = objects.PoolTarget.from_dict(self.target)
self.assertRaises(
stevedore.exception.NoMatches,
backend.get_backend, pool_target
)