Add fixes to ensure dkms packages have required headers

This commit is contained in:
James Page 2013-10-14 12:14:43 +01:00
commit 790034fda7
3 changed files with 49 additions and 11 deletions

View File

@ -1,5 +1,7 @@
# Various utilies for dealing with Neutron and the renaming from Quantum.
from subprocess import check_output
from charmhelpers.core.hookenv import (
config,
log,
@ -9,6 +11,13 @@ from charmhelpers.core.hookenv import (
from charmhelpers.contrib.openstack.utils import os_release
def headers_package():
"""Ensures correct linux-headers for running kernel are installed,
for building DKMS package"""
kver = check_output(['uname', '-r']).strip()
return 'linux-headers-%s' % kver
# legacy
def quantum_plugins():
from charmhelpers.contrib.openstack import context
@ -23,15 +32,15 @@ def quantum_plugins():
database=config('neutron-database'),
relation_prefix='neutron')],
'services': ['quantum-plugin-openvswitch-agent'],
'packages': ['quantum-plugin-openvswitch-agent',
'openvswitch-datapath-dkms'],
'packages': [['openvswitch-datapath-dkms', headers_package()],
['quantum-plugin-openvswitch-agent']],
},
'nvp': {
'config': '/etc/quantum/plugins/nicira/nvp.ini',
'driver': 'quantum.plugins.nicira.nicira_nvp_plugin.'
'QuantumPlugin.NvpPluginV2',
'services': [],
'packages': ['quantum-plugin-nicira'],
'packages': [],
}
}
@ -49,15 +58,15 @@ def neutron_plugins():
database=config('neutron-database'),
relation_prefix='neutron')],
'services': ['neutron-plugin-openvswitch-agent'],
'packages': ['neutron-plugin-openvswitch-agent',
'openvswitch-datapath-dkms'],
'packages': [['openvswitch-datapath-dkms', headers_package()],
['quantum-plugin-openvswitch-agent']],
},
'nvp': {
'config': '/etc/neutron/plugins/nicira/nvp.ini',
'driver': 'neutron.plugins.nicira.nicira_nvp_plugin.'
'NeutronPlugin.NvpPluginV2',
'services': [],
'packages': ['neutron-plugin-nicira'],
'packages': [],
}
}

View File

@ -1,3 +1,4 @@
from charmhelpers.core.host import service_running
from charmhelpers.core.hookenv import (
log,
config,
@ -8,15 +9,18 @@ from charmhelpers.fetch import (
)
from charmhelpers.contrib.network.ovs import (
add_bridge,
add_bridge_port
add_bridge_port,
full_restart,
)
from charmhelpers.contrib.openstack.utils import (
configure_installation_source,
get_os_codename_install_source,
get_os_codename_package
)
import charmhelpers.contrib.openstack.context as context
import charmhelpers.contrib.openstack.templating as templating
from charmhelpers.contrib.openstack.neutron import headers_package
from quantum_contexts import (
CORE_PLUGIN, OVS, NVP,
NEUTRON, QUANTUM,
@ -97,10 +101,15 @@ EARLY_PACKAGES = {
def get_early_packages():
'''Return a list of package for pre-install based on configured plugin'''
if config('plugin') in EARLY_PACKAGES:
return EARLY_PACKAGES[config('plugin')]
pkgs = EARLY_PACKAGES[config('plugin')]
else:
return []
# ensure headers are installed build any required dkms packages
if [p for p in pkgs if 'dkms' in p]:
return pkgs + [headers_package()]
return pkgs
def get_packages():
'''Return a list of packages for install based on the configured plugin'''
@ -384,6 +393,8 @@ def do_openstack_upgrade(configs):
def configure_ovs():
if not service_running('openvswitch-switch'):
full_restart()
if config('plugin') == OVS:
add_bridge(INT_BRIDGE)
add_bridge(EXT_BRIDGE)

View File

@ -1,6 +1,9 @@
from mock import MagicMock, call
import charmhelpers.contrib.openstack.templating as templating
templating.OSConfigRenderer = MagicMock()
import quantum_utils
from test_utils import (
@ -19,7 +22,10 @@ TO_PATCH = [
'log',
'add_bridge',
'add_bridge_port',
'networking_name'
'networking_name',
'headers_package',
'full_restart',
'service_running',
]
@ -27,6 +33,7 @@ class TestQuantumUtils(CharmTestCase):
def setUp(self):
super(TestQuantumUtils, self).setUp(quantum_utils, TO_PATCH)
self.networking_name.return_value = 'neutron'
self.headers_package.return_value = 'linux-headers-2.6.18'
def tearDown(self):
# Reset cached cache
@ -44,8 +51,9 @@ class TestQuantumUtils(CharmTestCase):
def test_get_early_packages_ovs(self):
self.config.return_value = 'ovs'
self.assertEquals(quantum_utils.get_early_packages(),
['openvswitch-datapath-dkms'])
self.assertEquals(
quantum_utils.get_early_packages(),
['openvswitch-datapath-dkms', 'linux-headers-2.6.18'])
def test_get_early_packages_nvp(self):
self.config.return_value = 'nvp'
@ -56,6 +64,16 @@ class TestQuantumUtils(CharmTestCase):
self.config.return_value = 'ovs'
self.assertNotEqual(quantum_utils.get_packages(), [])
def test_configure_ovs_starts_service_if_required(self):
self.service_running.return_value = False
quantum_utils.configure_ovs()
self.assertTrue(self.full_restart.called)
def test_configure_ovs_doesnt_restart_service(self):
self.service_running.return_value = True
quantum_utils.configure_ovs()
self.assertFalse(self.full_restart.called)
def test_configure_ovs_ovs_ext_port(self):
self.config.side_effect = self.test_config.get
self.test_config.set('plugin', 'ovs')