Added new DNS driver stub

Change-Id: I0d9d1ff9c4dbac7632337569c386d4a92acbf440
This commit is contained in:
amitgandhinz 2014-10-09 18:32:24 -04:00
parent e66f72d1e7
commit 213c268759
24 changed files with 466 additions and 18 deletions

View File

@ -40,17 +40,11 @@ storage = mockdb
# Provider modules list (a list of comma separated provider module list)
providers = mock,cloudfront,fastly
[drivers:transport:falcon]
bind = 0.0.0.0
port = 8888
[drivers:transport:limits]
max_services_per_page = 20
[drivers:storage:mongodb]
uri = mongodb://localhost
database = poppy
# DNS driver module (e.g. default, designate, rackspace)
dns = default
[drivers:storage:cassandra]
# Comma-separated list of hosts (Example: cass01,cass02,cass03)

View File

@ -37,6 +37,8 @@ _DRIVER_OPTIONS = [
help='Storage driver to use'),
cfg.ListOpt('providers', default=['mock'],
help='Provider driver(s) to use'),
cfg.StrOpt('dns', default='default',
help='DNS driver to use'),
]
_DRIVER_GROUP = 'drivers'
@ -60,6 +62,25 @@ class Bootstrap(object):
LOG.debug("init bootstrap")
@decorators.lazy_property(write=False)
def dns(self):
LOG.debug((u'Loading DNS driver'))
# create the driver manager to load the appropriate drivers
dns_type = 'poppy.dns'
dns_name = self.driver_conf.dns
args = [self.conf]
try:
mgr = driver.DriverManager(namespace=dns_type,
name=dns_name,
invoke_on_load=True,
invoke_args=args)
return mgr.driver
except RuntimeError as exc:
LOG.exception(exc)
@decorators.lazy_property(write=False)
def provider(self):
LOG.debug((u'Loading provider extension(s)'))
@ -102,7 +123,7 @@ class Bootstrap(object):
manager_type = 'poppy.manager'
manager_name = self.driver_conf.manager
args = [self.conf, self.storage, self.provider]
args = [self.conf, self.storage, self.provider, self.dns]
try:
mgr = driver.DriverManager(namespace=manager_type,

0
poppy/dns/__init__.py Normal file
View File

View File

@ -0,0 +1,21 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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 poppy.dns.base import driver
from poppy.dns.base import services
Driver = driver.DNSDriverBase
ServiceBase = services.ServicesControllerBase

View File

@ -0,0 +1,31 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class DNSControllerBase(object):
"""Top-level class for controllers.
:param driver: Instance of the driver
instantiating this controller.
"""
def __init__(self, driver):
self._driver = driver

52
poppy/dns/base/driver.py Normal file
View File

@ -0,0 +1,52 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class DNSDriverBase(object):
"""Interface definition for dns drivers.
DNS drivers are responsible for creating CNAME records in a DNS records
for an operator. Thus allowing the operator to abstract away the
underlying CDN provider used by customers of the API.
Use the Default DNS driver if you just want to pass through and not
use the CNAME capabilities of a DNS provider to mask the underlying
CDN provider url.
:param conf: Configuration containing options for this driver.
:type conf: `oslo.config.ConfigOpts`
"""
def __init__(self, conf):
self._conf = conf
@abc.abstractmethod
def is_alive(self):
"""Check whether the dns provider is ready."""
raise NotImplementedError
@abc.abstractproperty
def dns_name(self):
raise NotImplementedError
@abc.abstractproperty
def service_controller(self):
"""Returns the driver's hostname controller."""
raise NotImplementedError

View File

@ -0,0 +1,27 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
import abc
import six
from poppy.dns.base import controller
@six.add_metaclass(abc.ABCMeta)
class ServicesControllerBase(controller.DNSControllerBase):
def __init__(self, driver):
super(ServicesControllerBase, self).__init__(driver)

View File

@ -0,0 +1,6 @@
"""DNS Default driver"""
from poppy.dns.default import driver
# Hoist classes into package namespace
Driver = driver.DNSProvider

View File

@ -0,0 +1,27 @@
# Copyright (c) 2013 Red Hat, Inc.
#
# 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.
"""Exports Default DNS controllers.
Field Mappings:
In order to reduce the disk / memory space used,
fields name will be, most of the time, the first
letter of their long name. Fields mapping will be
updated and documented in each controller class.
"""
from poppy.dns.default import services
ServiceController = services.ServiceController

View File

@ -0,0 +1,39 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
"""DNS Provider implementation."""
from poppy.dns import base
from poppy.dns.default import controllers
from poppy.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class DNSProvider(base.Driver):
def __init__(self, conf):
super(DNSProvider, self).__init__(conf)
def is_alive(self):
return False
@property
def dns_name(self):
return "Default"
@property
def service_controller(self):
return controllers.ServiceController(self)

View File

@ -0,0 +1,24 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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 poppy.dns import base
class ServiceController(base.ServiceBase):
def __init__(self, driver):
super(ServiceController, self).__init__(driver)
self.driver = driver

View File

@ -0,0 +1,6 @@
"""Openstack Designate driver"""
from poppy.dns.designate import driver
# Hoist classes into package namespace
Driver = driver.DNSProvider

View File

@ -0,0 +1,27 @@
# Copyright (c) 2013 Red Hat, Inc.
#
# 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.
"""Exports Designate DNS controllers.
Field Mappings:
In order to reduce the disk / memory space used,
fields name will be, most of the time, the first
letter of their long name. Fields mapping will be
updated and documented in each controller class.
"""
from poppy.dns.designate import services
ServiceController = services.ServiceController

View File

@ -0,0 +1,39 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
"""DNS Provider implementation."""
from poppy.dns import base
from poppy.dns.designate import controllers
from poppy.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class DNSProvider(base.Driver):
def __init__(self, conf):
super(DNSProvider, self).__init__(conf)
def is_alive(self):
return False
@property
def dns_name(self):
return "Openstack Designate"
@property
def service_controller(self):
return controllers.ServiceController(self)

View File

@ -0,0 +1,24 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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 poppy.dns import base
class ServiceController(base.ServiceBase):
def __init__(self, driver):
super(ServiceController, self).__init__(driver)
self.driver = driver

View File

@ -0,0 +1,6 @@
"""Rackspace Cloud DNS driver"""
from poppy.dns.rackspace import driver
# Hoist classes into package namespace
Driver = driver.DNSProvider

View File

@ -0,0 +1,27 @@
# Copyright (c) 2013 Red Hat, Inc.
#
# 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.
"""Exports Rackspace Cloud DNS controllers.
Field Mappings:
In order to reduce the disk / memory space used,
fields name will be, most of the time, the first
letter of their long name. Fields mapping will be
updated and documented in each controller class.
"""
from poppy.dns.rackspace import services
ServiceController = services.ServiceController

View File

@ -0,0 +1,39 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
"""DNS Provider implementation."""
from poppy.dns import base
from poppy.dns.rackspace import controllers
from poppy.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class DNSProvider(base.Driver):
def __init__(self, conf):
super(DNSProvider, self).__init__(conf)
def is_alive(self):
return False
@property
def dns_name(self):
return "Rackspace Cloud DNS"
@property
def service_controller(self):
return controllers.ServiceController(self)

View File

@ -0,0 +1,24 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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 poppy.dns import base
class ServiceController(base.ServiceBase):
def __init__(self, driver):
super(ServiceController, self).__init__(driver)
self.driver = driver

View File

@ -21,11 +21,11 @@ import six
@six.add_metaclass(abc.ABCMeta)
class ManagerDriverBase(object):
"""Base class for driver manager."""
def __init__(self, conf, storage, providers):
def __init__(self, conf, storage, providers, dns):
self._conf = conf
self._storage = storage
self._providers = providers
self._dns = dns
@property
def storage(self):
@ -43,6 +43,10 @@ class ManagerDriverBase(object):
"""
return self._providers
@property
def dns(self):
return self._dns
@abc.abstractproperty
def services_controller(self):
"""Returns the driver's services controller

View File

@ -22,8 +22,9 @@ from poppy.manager.default import controllers
class DefaultManagerDriver(base.Driver):
def __init__(self, conf, storage, providers):
super(DefaultManagerDriver, self).__init__(conf, storage, providers)
def __init__(self, conf, storage, providers, dns):
super(DefaultManagerDriver, self).__init__(
conf, storage, providers, dns)
@decorators.lazy_property(write=False)
def services_controller(self):

View File

@ -41,6 +41,11 @@ poppy.transport =
poppy.manager =
default = poppy.manager.default:Driver
poppy.dns =
default = poppy.dns.default:Driver
designate = poppy.dns.designate:Driver
rackspace = poppy.dns.rackspace:Driver
poppy.storage =
mongodb = poppy.storage.mongodb:Driver
cassandra = poppy.storage.cassandra:Driver

View File

@ -27,14 +27,16 @@ from tests.unit import base
class DefaultManagerFlavorTests(base.TestCase):
@mock.patch('poppy.storage.base.driver.StorageDriverBase')
@mock.patch('poppy.provider.base.driver.ProviderDriverBase')
def setUp(self, mock_driver, mock_provider):
@mock.patch('poppy.dns.base.driver.DNSDriverBase')
def setUp(self, mock_driver, mock_provider, mock_dns):
super(DefaultManagerFlavorTests, self).setUp()
# create mocked config and driver
conf = cfg.ConfigOpts()
manager_driver = driver.DefaultManagerDriver(conf,
mock_driver,
mock_provider)
mock_provider,
mock_dns)
# stubbed driver
self.fc = flavors.DefaultFlavorsController(manager_driver)

View File

@ -32,14 +32,16 @@ class DefaultManagerServiceTests(base.TestCase):
@mock.patch('poppy.storage.base.driver.StorageDriverBase')
@mock.patch('poppy.provider.base.driver.ProviderDriverBase')
def setUp(self, mock_driver, mock_provider):
@mock.patch('poppy.dns.base.driver.DNSDriverBase')
def setUp(self, mock_driver, mock_provider, mock_dns):
super(DefaultManagerServiceTests, self).setUp()
# create mocked config and driver
conf = cfg.ConfigOpts()
manager_driver = driver.DefaultManagerDriver(conf,
mock_driver,
mock_provider)
mock_provider,
mock_dns)
# stubbed driver
self.sc = services.DefaultServicesController(manager_driver)
@ -113,7 +115,7 @@ class DefaultManagerServiceTests(base.TestCase):
'Fastly': {'error': "fail to create servcice",
'error_detail': 'Fastly Create failed'
' because of XYZ'}})
)
)
))
else:
return mock.Mock(