diff options
author | Anderson Mesquita <andersonvom@gmail.com> | 2014-01-24 16:44:32 -0600 |
---|---|---|
committer | Richard Lee <rblee88@gmail.com> | 2014-02-20 10:56:11 -0600 |
commit | fa37be061cc19545550eace9531250e5209bb1be (patch) | |
tree | 99186530d1f45d3f9792a9b056d85d8b496f2ce8 /contrib | |
parent | 33c1be512b1680ba92b55ca00dfa385d48d4d6ca (diff) | |
download | heat-fa37be061cc19545550eace9531250e5209bb1be.tar.gz |
Fix resource mapping for Rackspace
resource_mapping() always returns all existing resource names and
their classes. available_resource_mapping() takes the dependencies
into account and only returns the ones whose dependencies have been
met.
Partial-Bug: #1271226
Change-Id: I3a7467e87f7ff81badd51f121ecea98f2924e506
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/rackspace/resources/auto_scale.py | 16 | ||||
-rw-r--r-- | contrib/rackspace/resources/cloud_dns.py | 18 | ||||
-rw-r--r-- | contrib/rackspace/resources/cloud_loadbalancer.py | 18 | ||||
-rw-r--r-- | contrib/rackspace/resources/cloud_server.py | 19 | ||||
-rw-r--r-- | contrib/rackspace/tests/test_auto_scale.py | 6 |
5 files changed, 50 insertions, 27 deletions
diff --git a/contrib/rackspace/resources/auto_scale.py b/contrib/rackspace/resources/auto_scale.py index 1211e46d8..6f3fc727d 100644 --- a/contrib/rackspace/resources/auto_scale.py +++ b/contrib/rackspace/resources/auto_scale.py @@ -27,17 +27,15 @@ from heat.common import exception try: from pyrax.exceptions import Forbidden from pyrax.exceptions import NotFound + PYRAX_INSTALLED = True except ImportError: class Forbidden(Exception): """Dummy pyrax exception - only used for testing.""" class NotFound(Exception): """Dummy pyrax exception - only used for testing.""" - def resource_mapping(): - return {} -else: - def resource_mapping(): - return unprotected_resources() + + PYRAX_INSTALLED = False class Group(resource.Resource): @@ -565,9 +563,15 @@ class WebHook(resource.Resource): pass -def unprotected_resources(): +def resource_mapping(): return { 'Rackspace::AutoScale::Group': Group, 'Rackspace::AutoScale::ScalingPolicy': ScalingPolicy, 'Rackspace::AutoScale::WebHook': WebHook } + + +def available_resource_mapping(): + if PYRAX_INSTALLED: + return resource_mapping() + return {} diff --git a/contrib/rackspace/resources/cloud_dns.py b/contrib/rackspace/resources/cloud_dns.py index 6f4b14c6d..6df292570 100644 --- a/contrib/rackspace/resources/cloud_dns.py +++ b/contrib/rackspace/resources/cloud_dns.py @@ -12,17 +12,13 @@ try: from pyrax.exceptions import NotFound + PYRAX_INSTALLED = True except ImportError: #Setup fake exception for testing without pyrax class NotFound(Exception): pass - def resource_mapping(): - return {} -else: - - def resource_mapping(): - return {'Rackspace::Cloud::DNS': CloudDns} + PYRAX_INSTALLED = False from heat.common import exception from heat.engine import constraints @@ -203,3 +199,13 @@ class CloudDns(resource.Resource): except NotFound: pass self.resource_id_set(None) + + +def resource_mapping(): + return {'Rackspace::Cloud::DNS': CloudDns} + + +def available_resource_mapping(): + if PYRAX_INSTALLED: + return resource_mapping() + return {} diff --git a/contrib/rackspace/resources/cloud_loadbalancer.py b/contrib/rackspace/resources/cloud_loadbalancer.py index da3e75523..d72a0921d 100644 --- a/contrib/rackspace/resources/cloud_loadbalancer.py +++ b/contrib/rackspace/resources/cloud_loadbalancer.py @@ -13,17 +13,13 @@ # under the License. try: from pyrax.exceptions import NotFound + PYRAX_INSTALLED = True except ImportError: #Setup fake exception for testing without pyrax class NotFound(Exception): pass - def resource_mapping(): - return {} -else: - - def resource_mapping(): - return {'Rackspace::Cloud::LoadBalancer': CloudLoadBalancer} + PYRAX_INSTALLED = False from heat.openstack.common import log as logging from heat.openstack.common.gettextutils import _ @@ -612,3 +608,13 @@ class CloudLoadBalancer(resource.Resource): function = attribute_function[key] logger.info('%s.GetAtt(%s) == %s' % (self.name, key, function)) return unicode(function) + + +def resource_mapping(): + return {'Rackspace::Cloud::LoadBalancer': CloudLoadBalancer} + + +def available_resource_mapping(): + if PYRAX_INSTALLED: + return resource_mapping() + return {} diff --git a/contrib/rackspace/resources/cloud_server.py b/contrib/rackspace/resources/cloud_server.py index 6bff9f3f2..c571c651b 100644 --- a/contrib/rackspace/resources/cloud_server.py +++ b/contrib/rackspace/resources/cloud_server.py @@ -14,8 +14,8 @@ import socket import copy import tempfile -import paramiko from Crypto.PublicKey import RSA +import paramiko from heat.common import exception from heat.engine.resources import nova_utils @@ -26,12 +26,9 @@ from heat.openstack.common.gettextutils import _ try: import pyrax # noqa + PYRAX_INSTALLED = True except ImportError: - def resource_mapping(): - return {} -else: - def resource_mapping(): - return {'Rackspace::Cloud::Server': CloudServer} + PYRAX_INSTALLED = False logger = logging.getLogger(__name__) @@ -417,3 +414,13 @@ bash -x /var/lib/cloud/data/cfn-userdata > /root/cfn-userdata.log 2>&1 || if name == 'privateIPv4': return nova_utils.get_ip(self.server, 'private', 4) return super(CloudServer, self)._resolve_attribute(name) + + +def resource_mapping(): + return {'Rackspace::Cloud::Server': CloudServer} + + +def available_resource_mapping(): + if PYRAX_INSTALLED: + return resource_mapping() + return {} diff --git a/contrib/rackspace/tests/test_auto_scale.py b/contrib/rackspace/tests/test_auto_scale.py index 72eb51d77..d1e6f986f 100644 --- a/contrib/rackspace/tests/test_auto_scale.py +++ b/contrib/rackspace/tests/test_auto_scale.py @@ -201,7 +201,7 @@ class ScalingGroupTest(HeatTestCase): def setUp(self): super(ScalingGroupTest, self).setUp() utils.setup_dummy_db() - for res_name, res_class in auto_scale.unprotected_resources().items(): + for res_name, res_class in auto_scale.resource_mapping().items(): resource._register_class(res_name, res_class) self.fake_auto_scale = FakeAutoScale() self.patch(clients.OpenStackClients, @@ -353,7 +353,7 @@ class PolicyTest(HeatTestCase): def setUp(self): super(PolicyTest, self).setUp() utils.setup_dummy_db() - for res_name, res_class in auto_scale.unprotected_resources().items(): + for res_name, res_class in auto_scale.resource_mapping().items(): resource._register_class(res_name, res_class) self.fake_auto_scale = FakeAutoScale() self.patch(clients.OpenStackClients, @@ -495,7 +495,7 @@ class WebHookTest(HeatTestCase): def setUp(self): super(WebHookTest, self).setUp() utils.setup_dummy_db() - for res_name, res_class in auto_scale.unprotected_resources().items(): + for res_name, res_class in auto_scale.resource_mapping().items(): resource._register_class(res_name, res_class) self.fake_auto_scale = FakeAutoScale() self.patch(clients.OpenStackClients, |