Skip to content

Commit

Permalink
Enhance upgrade_kernel_all task to work for 14.04(trusty) as well.
Browse files Browse the repository at this point in the history
Recommended kernel version of contrail with Ubuntu Trusty is 3.13.0-35-generic,
However standard 14.04 LTS ISO comes with 3.13.0-24 kernel, so upgrading the kernel to
the recommended version before deploying contrail. Similar support required in server-manager
as well, so marking bug as partially fixed.

Change-Id: Ie194d6e6d64ba61d473644df5d89fcf9b0f1e283
Partail-Bug: 1390834
  • Loading branch information
cijohnson committed Nov 11, 2014
1 parent 838431e commit 8d869d8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 66 deletions.
1 change: 1 addition & 0 deletions fabfile/__init__.py
Expand Up @@ -32,6 +32,7 @@
from tasks.ha import *
from tasks.zookeeper import *
from tasks.backup_restore import *
from tasks.kernel import *

# For contrail use
try:
Expand Down
65 changes: 0 additions & 65 deletions fabfile/tasks/install.py
Expand Up @@ -609,68 +609,3 @@ def install_webui_packages(source_dir):
run('sudo mv firefox /opt/firefox')
run('sudo ln -sf /opt/firefox/firefox /usr/bin/firefox')
#end install_webui_packages

@task
@roles('build')
def upgrade_kernel_all():
"""creates repo and upgrades kernel in Ubuntu"""
execute('pre_check')
execute(create_install_repo)
nodes = get_nodes_to_upgrade('linux-image-3.13.0-34-generic', 'ubuntu', *env.roledefs['all'])
execute(upgrade_kernel_node, *nodes)
node_list_except_build = list(nodes)
if env.host_string in nodes:
node_list_except_build.remove(env.host_string)
execute("reboot_nodes", *node_list_except_build)
execute("reboot_nodes", env.host_string)
else:
execute("reboot_nodes", *nodes)

@task
def get_nodes_to_upgrade(package, os_type, *args):
"""get the list of nodes in which kernel needs to be upgraded"""
nodes = []
for host_string in args:
with settings(host_string=host_string, warn_only=True):
act_os_type = detect_ostype()
if act_os_type == os_type:
version = run("dpkg -l | grep %s" % package)
if not version:
nodes.append(host_string)
else:
print 'Has required Kernel. Skipping!'
else:
raise RuntimeError('Actual OS Type (%s) != Expected OS Type (%s)'
'Aborting!' % (act_os_type, os_type))
return nodes

@task
@EXECUTE_TASK
@roles('all')
def upgrade_kernel():
"""upgrades the kernel image in all nodes."""
execute("upgrade_kernel_node", env.host_string)

@task
def upgrade_kernel_node(*args):
"""upgrades the kernel image in given nodes."""
for host_string in args:
with settings(host_string=host_string):
print "upgrading apparmor before upgrading kernel"
apt_install(["apparmor"])
print "Installing 3.13.0-34 kernel headers"
apt_install(["linux-headers-3.13.0-34"])
apt_install(["linux-headers-3.13.0-34-generic"])
print "Upgrading the kernel to 3.13.0-34"
apt_install(["linux-image-3.13.0-34-generic"])

@task
def reboot_nodes(*args):
"""reboots the given nodes"""
for host_string in args:
with settings(host_string=host_string):
print "Rebooting (%s) to boot with new kernel version" % host_string
try:
sudo('reboot --force', timeout=3)
except CommandTimeout:
pass
81 changes: 81 additions & 0 deletions fabfile/tasks/kernel.py
@@ -0,0 +1,81 @@
from fabfile.config import *
from fabfile.utils.fabos import detect_ostype, get_linux_distro
from fabfile.tasks.install import apt_install

@task
@roles('build')
def upgrade_kernel_all():
"""creates repo and upgrades kernel in Ubuntu"""
execute('pre_check')
execute('create_install_repo')
dist, version, extra = get_linux_distro()
nodes = []
if version is '12.04':
nodes = get_nodes_to_upgrade('linux-image-3.13.0-34-generic', 'ubuntu', *env.roledefs['all'])
elif version is '14.04':
nodes = get_nodes_to_upgrade('linux-image-3.13.0-35-generic', 'ubuntu', *env.roledefs['all'])
if not nodes:
print "kernel is already of expected version"
execute(upgrade_kernel_node, *nodes)
node_list_except_build = list(nodes)
if env.host_string in nodes:
node_list_except_build.remove(env.host_string)
execute("reboot_nodes", *node_list_except_build)
execute("reboot_nodes", env.host_string)
else:
execute("reboot_nodes", *nodes)

@task
def get_nodes_to_upgrade(package, os_type, *args):
"""get the list of nodes in which kernel needs to be upgraded"""
nodes = []
for host_string in args:
with settings(host_string=host_string, warn_only=True):
act_os_type = detect_ostype()
if act_os_type == os_type:
version = run("dpkg -l | grep %s" % package)
if not version:
nodes.append(host_string)
else:
print 'Has required Kernel. Skipping!'
else:
raise RuntimeError('Actual OS Type (%s) != Expected OS Type (%s)'
'Aborting!' % (act_os_type, os_type))
return nodes

@task
@EXECUTE_TASK
@roles('all')
def upgrade_kernel():
"""upgrades the kernel image in all nodes."""
execute("upgrade_kernel_node", env.host_string)

@task
def upgrade_kernel_node(*args):
"""upgrades the kernel image in given nodes."""
for host_string in args:
with settings(host_string=host_string):
dist, version, extra = get_linux_distro()
print "upgrading apparmor before upgrading kernel"
if version is '12.04':
apt_install(["apparmor"])
print "Installing 3.13.0-34 kernel headers"
apt_install(["linux-headers-3.13.0-34"])
apt_install(["linux-headers-3.13.0-34-generic"])
print "Upgrading the kernel to 3.13.0-34"
apt_install(["linux-image-3.13.0-34-generic"])
elif version is '14.04':
print "Upgrading the kernel to 3.13.0-35"
apt_install(["linux-image-3.13.0-35-generic",
"linux-image-extra-3.13.0-35-generic"])

@task
def reboot_nodes(*args):
"""reboots the given nodes"""
for host_string in args:
with settings(host_string=host_string):
print "Rebooting (%s) to boot with new kernel version" % host_string
try:
sudo('reboot --force', timeout=3)
except CommandTimeout:
pass
6 changes: 5 additions & 1 deletion fabfile/utils/fabos.py
Expand Up @@ -12,9 +12,13 @@ def install_pkg(tgt_host, pkg_file):
run("rpm -iv --force %s" %(pkg_file.split('/')[-1]))
#end _install_pkg

def detect_ostype():
def get_linux_distro():
linux_distro = "python -c 'from platform import linux_distribution; print linux_distribution()'"
(dist, version, extra) = ast.literal_eval(run(linux_distro))
return (dist, version, extra)

def detect_ostype():
(dist, version, extra) = get_linux_distro()
if extra is not None and 'xen' in extra:
dist = 'xen'
if 'red hat' in dist.lower():
Expand Down

0 comments on commit 8d869d8

Please sign in to comment.