From: Zane Bitter Date: Fri, 22 Feb 2013 15:05:11 +0000 (+0100) Subject: Make quantumclient optional again X-Git-Tag: 2014.1~865^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=45be56e26a8bbedb49851d4e04369e87f418cd08;p=openstack-build%2Fheat-build.git Make quantumclient optional again Don't crash if quantumclient is not available; just don't register the resource types that require it. Change-Id: I9dacc5397327ef7ec784f808227582ee9bd037df Signed-off-by: Zane Bitter --- diff --git a/heat/engine/resources/internet_gateway.py b/heat/engine/resources/internet_gateway.py index 49a68d07..7c398c79 100644 --- a/heat/engine/resources/internet_gateway.py +++ b/heat/engine/resources/internet_gateway.py @@ -13,8 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - +from heat.engine import clients from heat.common import exception from heat.openstack.common import log as logging from heat.engine import resource @@ -89,6 +88,8 @@ class VPCGatewayAttachment(resource.Resource): 'network_id': external_network_id}) def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() vpc = self.stack[self.properties.get('VpcId')] for router_id in vpc.metadata['all_router_ids']: @@ -103,6 +104,9 @@ class VPCGatewayAttachment(resource.Resource): def resource_mapping(): + if clients.quantumclient is None: + return {} + return { 'AWS::EC2::InternetGateway': InternetGateway, 'AWS::EC2::VPCGatewayAttachment': VPCGatewayAttachment, diff --git a/heat/engine/resources/network_interface.py b/heat/engine/resources/network_interface.py index 9dfc4acb..cb7659ba 100644 --- a/heat/engine/resources/network_interface.py +++ b/heat/engine/resources/network_interface.py @@ -13,8 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - +from heat.engine import clients from heat.openstack.common import log as logging from heat.engine import resource @@ -71,6 +70,8 @@ class NetworkInterface(resource.Resource): self.metadata = md def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() try: client.delete_port(self.metadata['port_id']) @@ -83,6 +84,9 @@ class NetworkInterface(resource.Resource): def resource_mapping(): + if clients.quantumclient is None: + return {} + return { 'AWS::EC2::NetworkInterface': NetworkInterface, } diff --git a/heat/engine/resources/quantum/floatingip.py b/heat/engine/resources/quantum/floatingip.py index 9f044212..fc214edf 100644 --- a/heat/engine/resources/quantum/floatingip.py +++ b/heat/engine/resources/quantum/floatingip.py @@ -13,12 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - from heat.engine import clients from heat.openstack.common import log as logging from heat.engine.resources.quantum import quantum +if clients.quantumclient is not None: + from quantumclient.common.exceptions import QuantumClientException + logger = logging.getLogger(__name__) diff --git a/heat/engine/resources/quantum/net.py b/heat/engine/resources/quantum/net.py index fe8c226e..585ed227 100644 --- a/heat/engine/resources/quantum/net.py +++ b/heat/engine/resources/quantum/net.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - from heat.engine import clients from heat.openstack.common import log as logging from heat.engine.resources.quantum import quantum @@ -40,6 +38,8 @@ class Net(quantum.QuantumResource): self.resource_id_set(net['id']) def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() try: client.delete_network(self.resource_id) diff --git a/heat/engine/resources/quantum/port.py b/heat/engine/resources/quantum/port.py index a8890304..c09a072b 100644 --- a/heat/engine/resources/quantum/port.py +++ b/heat/engine/resources/quantum/port.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - from heat.engine import clients from heat.openstack.common import log as logging from heat.engine.resources.quantum import quantum @@ -53,6 +51,8 @@ class Port(quantum.QuantumResource): self.resource_id_set(port['id']) def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() try: client.delete_port(self.resource_id) diff --git a/heat/engine/resources/quantum/router.py b/heat/engine/resources/quantum/router.py index a3984396..1f7f820a 100644 --- a/heat/engine/resources/quantum/router.py +++ b/heat/engine/resources/quantum/router.py @@ -13,11 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - from heat.engine import clients from heat.engine.resources.quantum import quantum +if clients.quantumclient is not None: + from quantumclient.common.exceptions import QuantumClientException + from heat.openstack.common import log as logging logger = logging.getLogger(__name__) diff --git a/heat/engine/resources/quantum/subnet.py b/heat/engine/resources/quantum/subnet.py index 322667e2..da3336a7 100644 --- a/heat/engine/resources/quantum/subnet.py +++ b/heat/engine/resources/quantum/subnet.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - from heat.engine import clients from heat.openstack.common import log as logging from heat.engine.resources.quantum import quantum @@ -59,6 +57,8 @@ class Subnet(quantum.QuantumResource): self.resource_id_set(subnet['id']) def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() try: client.delete_subnet(self.resource_id) diff --git a/heat/engine/resources/route_table.py b/heat/engine/resources/route_table.py index dd50227f..81a710f1 100644 --- a/heat/engine/resources/route_table.py +++ b/heat/engine/resources/route_table.py @@ -13,11 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - +from heat.engine import clients from heat.openstack.common import log as logging from heat.engine import resource +if clients.quantumclient is not None: + from quantumclient.common.exceptions import QuantumClientException + logger = logging.getLogger(__name__) @@ -143,6 +145,9 @@ class SubnetRouteTableAssocation(resource.Resource): def resource_mapping(): + if clients.quantumclient is None: + return {} + return { 'AWS::EC2::RouteTable': RouteTable, 'AWS::EC2::SubnetRouteTableAssocation': SubnetRouteTableAssocation, diff --git a/heat/engine/resources/subnet.py b/heat/engine/resources/subnet.py index 5e988c30..c1752ce2 100644 --- a/heat/engine/resources/subnet.py +++ b/heat/engine/resources/subnet.py @@ -13,8 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - +from heat.engine import clients from heat.common import exception from heat.openstack.common import log as logging from heat.engine import resource @@ -74,6 +73,8 @@ class Subnet(resource.Resource): self.metadata = md def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() router_id = self.metadata['router_id'] subnet_id = self.metadata['subnet_id'] @@ -104,6 +105,9 @@ class Subnet(resource.Resource): def resource_mapping(): + if clients.quantumclient is None: + return {} + return { 'AWS::EC2::Subnet': Subnet, } diff --git a/heat/engine/resources/vpc.py b/heat/engine/resources/vpc.py index 74594269..f53014d9 100644 --- a/heat/engine/resources/vpc.py +++ b/heat/engine/resources/vpc.py @@ -13,8 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from quantumclient.common.exceptions import QuantumClientException - +from heat.engine import clients from heat.openstack.common import log as logging from heat.engine import resource @@ -58,6 +57,8 @@ class VPC(resource.Resource): self.metadata = md def handle_delete(self): + from quantumclient.common.exceptions import QuantumClientException + client = self.quantum() network_id = self.metadata['network_id'] router_id = self.metadata['router_id'] @@ -78,6 +79,9 @@ class VPC(resource.Resource): def resource_mapping(): + if clients.quantumclient is None: + return {} + return { 'AWS::EC2::VPC': VPC, } diff --git a/heat/tests/test_vpc.py b/heat/tests/test_vpc.py index c42f9cf3..015fd2eb 100644 --- a/heat/tests/test_vpc.py +++ b/heat/tests/test_vpc.py @@ -24,8 +24,12 @@ from heat.common import template_format from heat.engine import parser import heat.engine.resources -from quantumclient.common.exceptions import QuantumClientException -from quantumclient.v2_0 import client as quantumclient +try: + from quantumclient.common.exceptions import QuantumClientException + from quantumclient.v2_0 import client as quantumclient +except ImportError: + from nose.exc import SkipTest + raise SkipTest() class VPCTestBase(unittest.TestCase):