From c57103ffa6c1f0072ee781a14719cec09f68bc72 Mon Sep 17 00:00:00 2001 From: changzhi Date: Sun, 5 Jul 2015 14:25:18 +0800 Subject: [PATCH] Check instance exists when attach or detach interface I think it is necessary to check instance exists when attach or detach interface to a instance. So add some exception handle when do attach or detach interface. Change-Id: Ie8db50be05333e413dc98c0b624e456ff1def9d3 --- tacker/vm/drivers/nova/nova.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tacker/vm/drivers/nova/nova.py b/tacker/vm/drivers/nova/nova.py index 98c9b98e5..9b9d51afe 100644 --- a/tacker/vm/drivers/nova/nova.py +++ b/tacker/vm/drivers/nova/nova.py @@ -278,12 +278,22 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver): LOG.debug(_('ataching interface %(device_id)s %(port_id)s'), {'device_id': device_id, 'port_id': port_id}) nova = self._nova_client() - instance = nova.servers.get(device_id) + try: + instance = nova.servers.get(device_id) + except self._novaclient.exceptions.NotFound: + LOG.error(_LE("server %s is not found") % + device_id) + return instance.interface_attach(port_id, None, None) def dettach_interface(self, plugin, context, device_id, port_id): LOG.debug(_('detaching interface %(device_id)s %(port_id)s'), {'device_id': device_id, 'port_id': port_id}) nova = self._nova_client() - instance = nova.servers.get(device_id) + try: + instance = nova.servers.get(device_id) + except self._novaclient.exceptions.NotFound: + LOG.error(_LE("server %s is not found") % + device_id) + return instance.interface_detach(port_id)