Add exception handling for unavailable virsh

When virt-type is lxd libvirt-bin is not installed. The call to
destroy_libvirt_network fails because virsh is not available.

Add exception handling to destroy_libvirt_network when virt-type is lxd and
virsh is unavailable.

Closes-Bug: 1603566
Change-Id: I448598d5160c183de46938999db1c9d5232b80b2
This commit is contained in:
David Ames 2016-07-15 10:01:48 -07:00
parent c8cd75ba92
commit 39d0628dfb
2 changed files with 23 additions and 0 deletions

View File

@ -618,6 +618,13 @@ def destroy_libvirt_network(netname):
except CalledProcessError:
log("Failed to destroy libvirt network '{}'".format(netname),
level=WARNING)
except OSError as e:
if e.errno == 2:
log("virsh is unavailable. Virt Type is '{}'. Not attempting to "
"destroy libvirt network '{}'"
"".format(config('virt-type'), netname), level=DEBUG)
else:
raise e
def configure_lxd(user='nova'):

View File

@ -794,3 +794,19 @@ class NovaComputeUtilsTests(CharmTestCase):
mock_check_output.return_value = VIRSH_NET_LIST
utils.destroy_libvirt_network('defaultX')
self.assertFalse(mock_check_call.called)
@patch.object(utils, 'check_call')
@patch.object(utils, 'check_output')
def test_destroy_libvirt_network_no_virsh(self, mock_check_output,
mock_check_call):
mock_check_output.side_effect = OSError(2, 'No such file')
utils.destroy_libvirt_network('default')
@patch.object(utils, 'check_call')
@patch.object(utils, 'check_output')
def test_destroy_libvirt_network_no_virsh_unknown_error(self,
mock_check_output,
mock_check_call):
mock_check_output.side_effect = OSError(100, 'Break things')
with self.assertRaises(OSError):
utils.destroy_libvirt_network('default')