From 3edc50a6378aaa1931dad1fd94bac024a100c19b Mon Sep 17 00:00:00 2001 From: Robert Myers Date: Fri, 7 Jun 2013 10:56:16 -0500 Subject: [PATCH] Allow remote implementations to be overridden. * Adds new config settings for default remote clients * Removes monkey patching during test runs * Add fake implementations to test config. Implements: blueprint: custom-remotes Change-Id: Ic1fa423d9192eceb64f0de54bad869e73fb3a1e5 --- etc/reddwarf/reddwarf.conf.test | 6 ++++++ reddwarf/common/cfg.py | 10 +++++++++ reddwarf/common/remote.py | 36 +++++++++++---------------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/etc/reddwarf/reddwarf.conf.test b/etc/reddwarf/reddwarf.conf.test index 46ec47ce11..3eca9efed0 100644 --- a/etc/reddwarf/reddwarf.conf.test +++ b/etc/reddwarf/reddwarf.conf.test @@ -1,6 +1,12 @@ [DEFAULT] +# Fake out the remote implementations remote_implementation = fake +remote_nova_client = reddwarf.tests.fakes.nova.fake_create_nova_client +remote_nova_volume_client = reddwarf.tests.fakes.nova.fake_create_nova_volume_client +remote_guest_client = reddwarf.tests.fakes.guestagent.fake_create_guest_client +remote_swift_client = reddwarf.tests.fakes.swift.fake_create_swift_client + fake_mode_events = eventlet log_file = rdtest.log diff --git a/reddwarf/common/cfg.py b/reddwarf/common/cfg.py index 9db28fab2d..a28889a938 100644 --- a/reddwarf/common/cfg.py +++ b/reddwarf/common/cfg.py @@ -145,6 +145,16 @@ common_opts = [ help="Chunk size to stream to swift container."), cfg.IntOpt('backup_segment_max_size', default=2 * (1024 ** 3), help="Maximum size of each segment of the backup file."), + cfg.StrOpt('remote_dns_client', + default='reddwarf.common.remote.dns_client'), + cfg.StrOpt('remote_guest_client', + default='reddwarf.common.remote.guest_client'), + cfg.StrOpt('remote_nova_client', + default='reddwarf.common.remote.nova_client'), + cfg.StrOpt('remote_nova_volume_client', + default='reddwarf.common.remote.nova_volume_client'), + cfg.StrOpt('remote_swift_client', + default='reddwarf.common.remote.swift_client'), ] diff --git a/reddwarf/common/remote.py b/reddwarf/common/remote.py index feb15d1121..06cab00fd9 100644 --- a/reddwarf/common/remote.py +++ b/reddwarf/common/remote.py @@ -16,11 +16,12 @@ # under the License. from reddwarf.common import cfg +from reddwarf.openstack.common.importutils import import_class from novaclient.v1_1.client import Client from swiftclient.client import Connection - CONF = cfg.CONF + COMPUTE_URL = CONF.nova_compute_url PROXY_AUTH_URL = CONF.reddwarf_auth_url VOLUME_URL = CONF.nova_volume_url @@ -28,17 +29,17 @@ OBJECT_STORE_URL = CONF.swift_url USE_SNET = CONF.backup_use_snet -def create_dns_client(context): +def dns_client(context): from reddwarf.dns.manager import DnsManager return DnsManager() -def create_guest_client(context, id): +def guest_client(context, id): from reddwarf.guestagent.api import API return API(context, id) -def create_nova_client(context): +def nova_client(context): client = Client(context.user, context.auth_token, project_id=context.tenant, auth_url=PROXY_AUTH_URL) client.client.auth_token = context.auth_token @@ -47,7 +48,7 @@ def create_nova_client(context): return client -def create_nova_volume_client(context): +def nova_volume_client(context): # Quite annoying but due to a paste config loading bug. # TODO(hub-cap): talk to the openstack-common people about this client = Client(context.user, context.auth_token, @@ -58,7 +59,7 @@ def create_nova_volume_client(context): return client -def create_swift_client(context): +def swift_client(context): client = Connection(preauthurl=OBJECT_STORE_URL + context.tenant, preauthtoken=context.auth_token, tenant_name=context.tenant, @@ -66,21 +67,8 @@ def create_swift_client(context): return client -# Override the functions above with fakes. -if CONF.remote_implementation == "fake": - from reddwarf.tests.fakes.nova import fake_create_nova_client - from reddwarf.tests.fakes.nova import fake_create_nova_volume_client - from reddwarf.tests.fakes.guestagent import fake_create_guest_client - from reddwarf.tests.fakes.swift import fake_create_swift_client - - def create_guest_client(context, id): - return fake_create_guest_client(context, id) - - def create_nova_client(context): - return fake_create_nova_client(context) - - def create_nova_volume_client(context): - return fake_create_nova_volume_client(context) - - def create_swift_client(context): - return fake_create_swift_client(context) +create_dns_client = import_class(CONF.remote_dns_client) +create_guest_client = import_class(CONF.remote_guest_client) +create_nova_client = import_class(CONF.remote_nova_client) +create_nova_volume_client = import_class(CONF.remote_nova_volume_client) +create_swift_client = import_class(CONF.remote_swift_client)