Merge "Properly remove libvirt default network"
This commit is contained in:
commit
2dfdd7f2f3
|
@ -102,7 +102,7 @@ from nova_compute_utils import (
|
|||
get_hugepage_number,
|
||||
assess_status,
|
||||
set_ppc64_cpu_smt_state,
|
||||
destroy_libvirt_network,
|
||||
remove_libvirt_network,
|
||||
network_manager,
|
||||
libvirt_daemon,
|
||||
LIBVIRT_TYPES,
|
||||
|
@ -188,7 +188,7 @@ def config_changed():
|
|||
create_sysctl(yaml.dump(sysctl_dict),
|
||||
'/etc/sysctl.d/50-nova-compute.conf')
|
||||
|
||||
destroy_libvirt_network('default')
|
||||
remove_libvirt_network('default')
|
||||
|
||||
if migration_enabled() and config('migration-auth-type') == 'ssh':
|
||||
# Check-in with nova-c-c and register new ssh key, if it has just been
|
||||
|
|
|
@ -665,31 +665,37 @@ def create_libvirt_secret(secret_file, secret_uuid, key):
|
|||
check_call(cmd)
|
||||
|
||||
|
||||
def destroy_libvirt_network(netname):
|
||||
"""Delete a network using virsh net-destroy"""
|
||||
def _libvirt_network_exec(netname, action):
|
||||
"""Run action on libvirt network"""
|
||||
try:
|
||||
out = check_output(['virsh', 'net-list']).decode('UTF-8').splitlines()
|
||||
cmd = ['virsh', 'net-list', '--all']
|
||||
out = check_output(cmd).decode('UTF-8').splitlines()
|
||||
if len(out) < 3:
|
||||
return
|
||||
|
||||
for line in out[2:]:
|
||||
res = re.search("^\s+{} ".format(netname), line)
|
||||
if res:
|
||||
check_call(['virsh', 'net-destroy', netname])
|
||||
check_call(['virsh', 'net-{}'.format(action), netname])
|
||||
return
|
||||
|
||||
except CalledProcessError:
|
||||
log("Failed to destroy libvirt network '{}'".format(netname),
|
||||
log("Failed to {} libvirt network '{}'".format(action, 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)
|
||||
"{} libvirt network '{}'"
|
||||
"".format(config('virt-type'), action, netname), level=DEBUG)
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
def remove_libvirt_network(netname):
|
||||
_libvirt_network_exec(netname, 'destroy')
|
||||
_libvirt_network_exec(netname, 'undefine')
|
||||
|
||||
|
||||
def configure_lxd(user='nova'):
|
||||
''' Configure lxd use for nova user '''
|
||||
_release = lsb_release()['DISTRIB_CODENAME'].lower()
|
||||
|
|
|
@ -696,3 +696,13 @@ class NovaBasicDeployment(OpenStackAmuletDeployment):
|
|||
u.log.info("Assert output of aa-status --complaining >= 3. Result: {} "
|
||||
"Exit Code: {}".format(output, code))
|
||||
assert int(output) >= len(services)
|
||||
|
||||
def test_930_check_virsh_default_network(self):
|
||||
"""Verify that the default network created by libvirt was removed
|
||||
by the charm.
|
||||
"""
|
||||
sentry = self.nova_compute_sentry
|
||||
output, code = sentry.run('virsh net-dumpxml default')
|
||||
u.log.info('Assert exit code of virsh net-dumpxml default != 0.'
|
||||
'Result: {} Exit Code: {}'.format(output, code))
|
||||
assert code != 0
|
||||
|
|
|
@ -85,7 +85,7 @@ TO_PATCH = [
|
|||
'assert_libvirt_rbd_imagebackend_allowed',
|
||||
'is_request_complete',
|
||||
'send_request_if_needed',
|
||||
'destroy_libvirt_network',
|
||||
'remove_libvirt_network',
|
||||
# socket
|
||||
'gethostname',
|
||||
'create_sysctl',
|
||||
|
|
|
@ -804,35 +804,35 @@ class NovaComputeUtilsTests(CharmTestCase):
|
|||
|
||||
@patch.object(utils, 'check_call')
|
||||
@patch.object(utils, 'check_output')
|
||||
def test_destroy_libvirt_network(self, mock_check_output, mock_check_call):
|
||||
def test_remove_libvirt_network(self, mock_check_output, mock_check_call):
|
||||
mock_check_output.return_value = VIRSH_NET_LIST.encode()
|
||||
utils.destroy_libvirt_network('default')
|
||||
utils.remove_libvirt_network('default')
|
||||
cmd = ['virsh', 'net-destroy', 'default']
|
||||
mock_check_call.assert_has_calls([call(cmd)])
|
||||
|
||||
@patch.object(utils, 'check_call')
|
||||
@patch.object(utils, 'check_output')
|
||||
def test_destroy_libvirt_network_no_exist(self, mock_check_output,
|
||||
mock_check_call):
|
||||
def test_remove_libvirt_network_no_exist(self, mock_check_output,
|
||||
mock_check_call):
|
||||
mock_check_output.return_value = VIRSH_NET_LIST.encode()
|
||||
utils.destroy_libvirt_network('defaultX')
|
||||
utils.remove_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):
|
||||
def test_remove_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')
|
||||
utils.remove_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):
|
||||
def test_remove_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')
|
||||
utils.remove_libvirt_network('default')
|
||||
|
||||
def test_libvirt_daemon_yakkety(self):
|
||||
self.lsb_release.return_value = {
|
||||
|
|
Loading…
Reference in New Issue