Skip to content

Commit

Permalink
Kernel upgrade and setting default kernel changes
Browse files Browse the repository at this point in the history
Change-Id: I024cb98c57bb15bfde506af1a27f3b88478d4faa
Closes-Bug: 1583456
  • Loading branch information
npchandran committed May 23, 2016
1 parent e6aee18 commit 7e4d23b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
34 changes: 27 additions & 7 deletions fabfile/tasks/kernel.py
Expand Up @@ -7,12 +7,18 @@
@task
def set_grub_default_node(*args, **kwargs):
'''Set default kernel version to bootup for given list of nodes'''
value = kwargs.get('value', 'Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-85-generic')
value = kwargs.get('value')
for host_string in args:
with settings(host_string=host_string):
sudo("sed -i \'s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=\"%s\"/g\' /etc/default/grub" % value)
sudo('update-grub')
sudo("grep '^GRUB_DEFAULT=\"%s\"' /etc/default/grub" % value)
dist, version, extra = get_linux_distro()
if 'ubuntu' in dist.lower():
sudo("sed -i \'s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=\"%s\"/g\' /etc/default/grub" % value)
sudo('update-grub')
sudo("grep '^GRUB_DEFAULT=\"%s\"' /etc/default/grub" % value)
elif 'red hat' in dist.lower() or 'centos linux' in dist.lower():
sudo("grub2-set-default \'%s\'" % value)
sudo('grub2-mkconfig -o /boot/grub2/grub.cfg')
sudo("grub2-editenv list | grep \'%s\'" % value)
print '[%s]: Updated Default Grub to (%s)' % (host_string, value)

@task
Expand All @@ -37,6 +43,10 @@ def upgrade_kernel_all(*tgzs, **kwargs):
elif version == '14.04':
(package, os_type) = ('linux-image-3.13.0-85-generic', 'ubuntu')
default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-85-generic'
elif 'centos linux' in dist.lower() and version.startswith('7'):
(package, os_type) = ('kernel-3.10.0-327.10.1.el7.x86_64', 'centoslinux')
elif 'red hat' in dist.lower() and version.startswith('7'):
(package, os_type) = ('kernel-3.10.0-327.10.1.el7.x86_64', 'redhat')
else:
raise RuntimeError("Unsupported platfrom (%s, %s, %s) for"
" kernel upgrade." % (dist, version, extra))
Expand Down Expand Up @@ -66,7 +76,7 @@ def upgrade_kernel_without_openstack(*tgzs, **kwargs):
with settings(host_string=env.roledefs['cfgm'][0], warn_only=True):
dist, version, extra = get_linux_distro()

if 'red hat' in dist.lower():
if ('red hat' in dist.lower() or 'centos linux' in dist.lower()) and version.startswith('7'):
(package, os_type) = ('kernel-3.10.0-327.10.1.el7.x86_64', 'redhat')
else:
raise RuntimeError("Unsupported platfrom (%s, %s, %s) for"
Expand Down Expand Up @@ -121,12 +131,22 @@ def upgrade_kernel_node(*args):
"linux-image-extra-3.13.0-85-generic"])
default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-85-generic'
execute('set_grub_default_node', host_string, value=default_grub)
elif 'red hat' in dist.lower() and version == '7.0':
print "Upgrading kernel to version 3.10.0-229"
elif 'red hat' in dist.lower() and version.startswith('7'):
print "Upgrading RHEL kernel to version 3.10.0-327.10.1"
pkg_install(["kernel-3.10.0-327.10.1.el7.x86_64",
"kernel-tools-3.10.0-327.10.1.el7.x86_64",
"kernel-tools-libs-3.10.0-327.10.1.el7.x86_64",
"kernel-headers-3.10.0-327.10.1.el7.x86_64"], disablerepo=False)
default_grub='Red Hat Enterprise Linux Server (3.10.0-327.10.1.el7.x86_64) 7.2 (Maipo)'
execute('set_grub_default_node', host_string, value=default_grub)
elif 'centos linux' in dist.lower() and version.startswith('7'):
print "Upgrading Centos kernel to version 3.10.0-327.10.1"
pkg_install(["kernel-3.10.0-327.10.1.el7.x86_64",
"kernel-tools-3.10.0-327.10.1.el7.x86_64",
"kernel-tools-libs-3.10.0-327.10.1.el7.x86_64",
"kernel-headers-3.10.0-327.10.1.el7.x86_64"], disablerepo=False)
default_grub='CentOS Linux (3.10.0-327.10.1.el7.x86_64) 7 (Core)'
execute('set_grub_default_node', host_string, value=default_grub)

@task
@EXECUTE_TASK
Expand Down
25 changes: 13 additions & 12 deletions fabfile/utils/cluster.py
Expand Up @@ -197,20 +197,21 @@ def get_nodes_to_upgrade_pkg(package, os_type, *args, **kwargs):
version = kwargs.get('version', None)
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:
if os_type in ['ubuntu']:
installed = sudo("dpkg -l | grep %s" % package)
if not installed:
nodes.append(host_string)
elif (version and
version != '%s-%s' %
(get_release(package), get_build(package))):
nodes.append(host_string)
else:
print 'Required package %s installed. Skipping!' % package
elif os_type in ['centos', 'redhat', 'centoslinux']:
installed = sudo("rpm -qa | grep %s" % package)
else:
raise RuntimeError('Unsupported OS type!')

if not installed:
nodes.append(host_string)
elif (version and
version != '%s-%s' %
(get_release(package), get_build(package))):
nodes.append(host_string)
else:
raise RuntimeError('Actual OS Type (%s) != Expected OS Type (%s)'
'Aborting!' % (act_os_type, os_type))
print 'Required package %s installed. Skipping!' % package
return nodes

def get_package_installed_info(package, os_type, *nodes):
Expand Down

0 comments on commit 7e4d23b

Please sign in to comment.