def upgrade_kernel_all(reboot='yes'): """creates repo and upgrades kernel in Ubuntu""" execute('pre_check') execute('create_install_repo') nodes = [] with settings(host_string=env.roledefs['all'][0], warn_only=True): dist, version, extra = get_linux_distro() if version == '12.04': (package, os_type) = ('linux-image-3.13.0-34-generic', 'ubuntu') elif version == '14.04': (package, os_type) = ('linux-image-3.13.0-40-generic', 'ubuntu') else: raise RuntimeError("Unsupported platfrom (%s, %s, %s) for" " kernel upgrade." % (dist, version, extra)) nodes = get_nodes_to_upgrade_pkg(package, os_type, *env.roledefs['all']) if not nodes: print "kernel is already of expected version" return execute(upgrade_kernel_node, *nodes) if reboot == 'yes': node_list_except_build = list(nodes) if env.host_string in nodes: node_list_except_build.remove(env.host_string) reboot_nodes(*node_list_except_build) reboot_nodes(env.host_string) else: reboot_nodes(*nodes)
def upgrade_config_node(from_rel, pkg, *args): """Upgrades config pkgs in one or list of nodes. USAGE:fab upgrade_config_node:[email protected],[email protected]""" for host_string in args: with settings(host_string=host_string): execute('install_pkg_node', pkg, host_string) execute('create_install_repo_node', host_string) pkg_install(['contrail-setup']) if get_orchestrator() is 'vcenter': pkg = get_vcenter_plugin_pkg() install_contrail_vcenter_plugin(pkg) #Downgrading keepalived as we are packaging lower version of keepalivd in R2.20 if (LooseVersion(from_rel) == LooseVersion('2.20') and LooseVersion(get_release()) >= LooseVersion('2.20')): dist, version, extra = get_linux_distro() if version == '14.04': cmd = 'DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes' cmd += ' -o Dpkg::Options::="--force-overwrite"' cmd += ' -o Dpkg::Options::="--force-confold" install keepalived=1.2.13-0~276~ubuntu14.04.1' sudo(cmd) pkgs = get_config_pkgs() cmd = frame_vnc_config_cmd(host_string, 'upgrade-vnc-config') cmd += ' -P %s' % ' '.join(pkgs) cmd += ' -F %s' % from_rel cmd += ' -T %s' % get_release() sudo(cmd)
def upgrade_kernel_node(*args): """upgrades the kernel image in given nodes.""" for host_string in args: with settings(host_string=host_string): execute('create_install_repo_node', host_string) dist, version, extra = get_linux_distro() if version == '12.04': 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"]) default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-34-generic' execute('set_grub_default_node', host_string, value=default_grub) elif version == '14.04': print "Installing 3.13.0-83 kernel headers" apt_install(["linux-headers-3.13.0-83", "linux-headers-3.13.0-83-generic"]) print "Upgrading the kernel to 3.13.0-83" apt_install(["linux-image-3.13.0-83-generic", "linux-image-extra-3.13.0-83-generic"]) default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-83-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" pkg_install(["kernel-3.10.0-229.el7.x86_64", "kernel-tools-3.10.0-229.el7.x86_64", "kernel-tools-libs-3.10.0-229.el7.x86_64", "kernel-headers-3.10.0-229.el7.x86_64"], disablerepo=False)
def upgrade_kernel_without_openstack(*tgzs, **kwargs): """creates repo and upgrades kernel""" reboot = kwargs.get('reboot', 'yes') non_openstack_nodes = [ node for node in env.roledefs['all'] if node not in env.roledefs['openstack'] ] execute('create_installer_repo') execute('create_install_repo_without_openstack', *tgzs) nodes = [] with settings(host_string=env.roledefs['cfgm'][0], warn_only=True): dist, version, extra = get_linux_distro() 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" " kernel upgrade." % (dist, version, extra)) nodes = get_package_installed_info(package, os_type, *non_openstack_nodes) if not nodes['not_installed']: print "Nodes are already booted with expected version" return if nodes['installed']: print "Nodes (%s) are already booted in expected "\ "kernel version" % ", ".join(nodes['installed']) execute(upgrade_kernel_node, *nodes['not_installed'], **kwargs) if reboot == 'yes': if env.host_string in nodes: nodes.remove(env.host_string).append(env.host_string) reboot_nodes(*nodes['not_installed']) else: print "WARNING: Reboot Skipped as reboot=False; "\ "Reboot manually to avoid misconfiguration"
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() if version == '12.04': 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"]) elif version == '14.04': print "Installing 3.13.0-40 kernel headers" apt_install(["linux-headers-3.13.0-40", "linux-headers-3.13.0-40-generic"]) print "Upgrading the kernel to 3.13.0-40" apt_install(["linux-image-3.13.0-40-generic", "linux-image-extra-3.13.0-40-generic"]) elif 'red hat' in dist.lower() and version == '7.0': print "Upgrading kernel to version 3.10.0-229" pkg_install(["kernel-3.10.0-229.el7.x86_64", "kernel-tools-3.10.0-229.el7.x86_64", "kernel-tools-libs-3.10.0-229.el7.x86_64", "kernel-headers-3.10.0-229.el7.x86_64"], disablerepo=False)
def upgrade_kernel_without_openstack(reboot='yes'): """creates repo and upgrades kernel""" non_openstack_nodes = [node for node in env.roledefs['all'] if node not in env.roledefs['openstack']] execute('create_install_repo_without_openstack') nodes = [] with settings(host_string=env.roledefs['cfgm'][0], warn_only=True): dist, version, extra = get_linux_distro() if 'red hat' in dist.lower() and version == '7.0': (package, os_type) = ('kernel-3.10.0-229.el7.x86_64', 'redhat') else: raise RuntimeError("Unsupported platfrom (%s, %s, %s) for" " kernel upgrade." % (dist, version, extra)) nodes = get_package_installed_info(package, os_type, *non_openstack_nodes) if not nodes['not_installed']: print "Nodes are already booted with expected version" return if nodes['installed']: print "Nodes (%s) are already booted in expected "\ "kernel version" % ", ".join(nodes['installed']) execute(upgrade_kernel_node, *nodes['not_installed']) if reboot == 'yes': if env.host_string in nodes: nodes.remove(env.host_string).append(env.host_string) reboot_nodes(*nodes['not_installed']) else: print "WARNING: Reboot Skipped as reboot=False; "\ "Reboot manually to avoid misconfiguration"
def upgrade_biosdevname_all(reboot='yes'): """creates repo and upgrades biosdevname in Ubuntu""" execute('pre_check') execute('create_install_repo') nodes = [] with settings(host_string=env.roledefs['all'][0], warn_only=True): dist, version, extra = get_linux_distro() if version == '14.04': (package, os_type) = ('biosdevname', 'ubuntu') nodes = get_nodes_to_upgrade_pkg(package, os_type, *env.roledefs['all'], version='0.4.1-0ubuntu6.1') if not nodes: print "biosdevname is already of expected version" return execute(upgrade_biosdevname_node, *nodes) if reboot == 'yes': node_list_except_build = list(nodes) if env.host_string in nodes: node_list_except_build.remove(env.host_string) reboot_nodes(*node_list_except_build) reboot_nodes(env.host_string) else: reboot_nodes(*nodes)
def upgrade_kernel_all(*tgzs, **kwargs): """creates repo and upgrades kernel in Ubuntu""" reboot = kwargs.get('reboot', 'yes') execute('create_installer_repo') execute('create_install_repo', *tgzs) nodes = [] with settings(host_string=env.roledefs['all'][0], warn_only=True): dist, version, extra = get_linux_distro() if version == '12.04': (package, os_type) = ('linux-image-3.13.0-34-generic', 'ubuntu') default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-34-generic' elif version == '14.04': (package, os_type) = ('linux-image-3.13.0-40-generic', 'ubuntu') default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-40-generic' else: raise RuntimeError("Unsupported platfrom (%s, %s, %s) for" " kernel upgrade." % (dist, version, extra)) nodes = get_nodes_to_upgrade_pkg(package, os_type, *env.roledefs['all']) if not nodes: print "kernel is already of expected version" return execute(upgrade_kernel_node, *nodes) execute('set_grub_default_node', *nodes, value=default_grub) if reboot == 'yes': node_list_except_build = list(nodes) if env.host_string in nodes: node_list_except_build.remove(env.host_string) reboot_nodes(*node_list_except_build) reboot_nodes(env.host_string) else: reboot_nodes(*nodes)
def upgrade_kernel_node(*args): """upgrades the kernel image in given nodes.""" for host_string in args: with settings(host_string=host_string): execute('create_install_repo_node', host_string) dist, version, extra = get_linux_distro() if version == '12.04': 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"]) default_grub = 'Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-34-generic' execute('set_grub_default_node', host_string, value=default_grub) elif version == '14.04': print "Installing 3.13.0-85 kernel headers" apt_install([ "linux-headers-3.13.0-85", "linux-headers-3.13.0-85-generic" ]) print "Upgrading the kernel to 3.13.0-85" apt_install([ "linux-image-3.13.0-85-generic", "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.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)
def save_systemd_logs(): dist, version, extra = get_linux_distro() # No systemd on ubuntu 14.04 if '14.04' in version: return sudo('journalctl > /var/log/journalctl.log') save_contrail_systemd_logs() if get_orchestrator() == 'openstack': save_openstack_container_logs()
def install_test_repo_node(container=None, *args): '''Installs test repo in given node''' for host_string in args: with settings(host_string=host_string, warn_only=True): trusty_repo = 'fabfile/contraillabs/repo/trusty_test.list' xenial_repo = 'fabfile/contraillabs/repo/xenial_test.list' ubuntu_repo_dest = '/etc/apt/sources.list.d/test_repo.list' el7_repo = 'fabfile/contraillabs/repo/centos_el7_test.repo' rh_repo = 'fabfile/contraillabs/repo/el7_test.repo' rh_repo_dest = '/etc/yum.repos.d/contrail_test.repo' if container: os_type, version, extra = get_linux_distro(container=container) os_type = os_type.lower() extra = extra.lower() if os_type in ['ubuntu']: if 'trusty' in extra: put_to_container(container, trusty_repo, ubuntu_repo_dest) if 'xenial' in extra: put_to_container(container, xenial_repo, ubuntu_repo_dest) run_in_container(container, 'apt-get update') if os_type in ['centos', 'centoslinux']: put_to_container(container, el7_repo, rh_repo_dest) run_in_container(container, 'yum clean all') if os_type in ['redhat']: put_to_container(container, rh_repo, rh_repo_dest) run_in_container(container, 'yum clean all') else: os_type, version, extra = get_linux_distro() os_type = os_type.lower() extra = extra.lower() if os_type in ['ubuntu']: if 'trusty' in extra: put(trusty_repo, ubuntu_repo_dest) if 'xenial' in extra: put(xenial_repo, ubuntu_repo_dest) sudo('apt-get update') if os_type in ['centos', 'centoslinux']: put(el7_repo, rh_repo_dest) sudo('yum clean all') if os_type in ['redhat']: put(rh_repo, rh_repo_dest) sudo('yum clean all')
def install_test_repo_node(container=None, *args): '''Installs test repo in given node''' for host_string in args: with settings(host_string=host_string, warn_only=True): trusty_repo = 'fabfile/contraillabs/repo/trusty_test.list' xenial_repo = 'fabfile/contraillabs/repo/xenial_test.list' ubuntu_repo_dest = '/etc/apt/sources.list.d/test_repo.list' el7_repo = 'fabfile/contraillabs/repo/centos_el7_test.repo' rh_repo = 'fabfile/contraillabs/repo/el7_test.repo' rh_repo_dest = '/etc/yum.repos.d/contrail_test.repo' if container: os_type, version, extra = get_linux_distro(container=container) os_type = os_type.lower() extra = extra.lower() if os_type in ['ubuntu']: if 'trusty' in extra : put_to_container(container, trusty_repo, ubuntu_repo_dest) if 'xenial' in extra : put_to_container(container, xenial_repo, ubuntu_repo_dest) run_in_container(container, 'apt-get update') if os_type in ['centos', 'centoslinux']: put_to_container(container, el7_repo, rh_repo_dest) run_in_container(container, 'yum clean all') if os_type in ['redhat']: put_to_container(container, rh_repo, rh_repo_dest) run_in_container(container, 'yum clean all') else: os_type, version, extra = get_linux_distro() os_type = os_type.lower() extra = extra.lower() if os_type in ['ubuntu']: if 'trusty' in extra : put(trusty_repo, ubuntu_repo_dest) if 'xenial' in extra : put(xenial_repo, ubuntu_repo_dest) sudo('apt-get update') if os_type in ['centos', 'centoslinux']: put(el7_repo, rh_repo_dest) sudo('yum clean all') if os_type in ['redhat']: put(rh_repo, rh_repo_dest) sudo('yum clean all')
def upgrade_compute_node(from_rel, pkg, *args, **kwargs): """Upgrades compute pkgs in one or list of nodes. USAGE:fab upgrade_compute_node:[email protected],[email protected]""" for host_string in args: with settings(host_string=host_string): execute('install_pkg_node', pkg, host_string) execute('create_install_repo_node', host_string) pkg_install(['contrail-setup']) configure_nova = kwargs.get('configure_nova', 'yes') manage_nova_compute = kwargs.get('manage_nova_compute', 'yes') if (env.host_string in get_tsn_nodes() or get_orchestrator() == 'vcenter'): manage_nova_compute='no' # Identify packages to upgrade cmd = frame_vnc_compute_cmd( host_string, 'upgrade-vnc-compute', configure_nova=configure_nova, manage_nova_compute=manage_nova_compute) if ('vcenter_compute' in env.roledefs and env.host_string in env.roledefs['vcenter_compute']): pkgs = get_vcenter_compute_pkgs() roles = ['vcenter_compute'] else: pkgs = get_compute_pkgs(manage_nova_compute=manage_nova_compute) if (getattr(env, 'interface_rename', True) and detect_ostype() not in ['ubuntu', 'redhat']): pkgs.append('contrail-interface-name') if LooseVersion(from_rel) <= LooseVersion('3.2.0.0'): dist, version, extra = get_linux_distro() if version == '14.04': if 'contrail-vrouter-3.13.0-40-generic' in pkgs: pkgs.remove('contrail-vrouter-3.13.0-40-generic') if 'contrail-vrouter-3.13.0-85-generic' in pkgs: pkgs.remove('contrail-vrouter-3.13.0-85-generic') if 'contrail-vrouter-3.13.0-100-generic' in pkgs: pkgs.remove('contrail-vrouter-3.13.0-100-generic') if 'contrail-vrouter-3.13.0-106-generic' in pkgs: pkgs.remove('contrail-vrouter-3.13.0-106-generic') pkgs.append('contrail-vrouter-3.13.0-106-generic') # Identify roles of this node. roles = ['compute'] if env.host_string in get_tsn_nodes(): roles.append('tsn') if env.host_string in get_toragent_nodes(): roles.append('toragent') cmd += ' -P %s' % ' '.join(pkgs) cmd += ' -F %s' % from_rel cmd += ' -T %s' % get_release() cmd += ' -R %s' % ' '.join(roles) sudo(cmd)
def set_grub_default_node(*args, **kwargs): '''Set default kernel version to bootup for given list of nodes''' value = kwargs.get('value') for host_string in args: with settings(host_string=host_string): 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)
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 == '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 == '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"])
def set_grub_default_node(*args, **kwargs): '''Set default kernel version to bootup for given list of nodes''' value = kwargs.get('value') for host_string in args: with settings(host_string=host_string): 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)
def upgrade_kernel_node(*args, **kwargs): """upgrades the kernel image in given nodes.""" for host_string in args: with settings(host_string=host_string): execute('create_install_repo_node', host_string) dist, version, extra = get_linux_distro() if version == '12.04': 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"]) default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-34-generic' execute('set_grub_default_node', host_string, value=default_grub) elif version == '14.04': if 'version' in kwargs: kernel_ver = kwargs.get('version') else: kernel_ver = "3.13.0-85" print "Installing "+kernel_ver+" kernel headers" apt_install(["linux-headers-"+kernel_ver, "linux-headers-"+kernel_ver+"-generic"]) print "Upgrading the kernel to "+kernel_ver apt_install(["linux-image-"+kernel_ver+"-generic", "linux-image-extra-"+kernel_ver+"-generic"]) default_grub='Advanced options for Ubuntu>Ubuntu, with Linux '+kernel_ver+'-generic' execute('set_grub_default_node', host_string, value=default_grub) 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)
def upgrade_compute_node(from_rel, pkg, *args, **kwargs): """Upgrades compute pkgs in one or list of nodes. USAGE:fab upgrade_compute_node:[email protected],[email protected]""" for host_string in args: with settings(host_string=host_string): execute("install_pkg_node", pkg, host_string) execute("create_install_repo_node", host_string) pkg_install(["contrail-setup"]) configure_nova = kwargs.get("configure_nova", "yes") manage_nova_compute = kwargs.get("manage_nova_compute", "yes") if env.host_string in get_tsn_nodes() or get_orchestrator() == "vcenter": manage_nova_compute = "no" # Identify packages to upgrade cmd = frame_vnc_compute_cmd( host_string, "upgrade-vnc-compute", configure_nova=configure_nova, manage_nova_compute=manage_nova_compute, ) if "vcenter_compute" in env.roledefs and env.host_string in env.roledefs["vcenter_compute"]: pkgs = get_vcenter_compute_pkgs() roles = ["vcenter_compute"] else: pkgs = get_compute_pkgs(manage_nova_compute=manage_nova_compute) if getattr(env, "interface_rename", True) and detect_ostype() not in ["ubuntu", "redhat"]: pkgs.append("contrail-interface-name") if LooseVersion(from_rel) <= LooseVersion("3.0.2.0"): dist, version, extra = get_linux_distro() if version == "14.04" and "contrail-vrouter-3.13.0-40-generic" in pkgs: pkgs.remove("contrail-vrouter-3.13.0-40-generic") pkgs.append("contrail-vrouter-3.13.0-85-generic") # Identify roles of this node. roles = ["compute"] if env.host_string in get_tsn_nodes(): roles.append("tsn") if env.host_string in get_toragent_nodes(): roles.append("toragent") cmd += " -P %s" % " ".join(pkgs) cmd += " -F %s" % from_rel cmd += " -T %s" % get_release() cmd += " -R %s" % " ".join(roles) sudo(cmd)
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 == '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 == '14.04': print "Installing 3.13.0-40 kernel headers" apt_install(["linux-headers-3.13.0-40", "linux-headers-3.13.0-40-generic"]) print "Upgrading the kernel to 3.13.0-40" apt_install(["linux-image-3.13.0-40-generic", "linux-image-extra-3.13.0-40-generic"])
def upgrade_kernel_all(*tgzs, **kwargs): """creates repo and upgrades kernel in Ubuntu""" reboot = kwargs.get('reboot', 'yes') execute('create_installer_repo') execute('create_install_repo', *tgzs) nodes = [] kernel_ver = kwargs.get('version') with settings(host_string=env.roledefs['all'][0], warn_only=True): dist, version, extra = get_linux_distro() if version == '12.04': (package, os_type) = ('linux-image-3.13.0-34-generic', 'ubuntu') default_grub = 'Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-34-generic' elif version == '14.04': if kernel_ver is None: kernel_ver = '3.13.0-106' (package, os_type) = ('linux-image-' + kernel_ver + '-generic', 'ubuntu') default_grub = 'Advanced options for Ubuntu>Ubuntu, with Linux ' + kernel_ver + '-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)) nodes = get_nodes_to_upgrade_pkg(package, os_type, *env.roledefs['all']) if not nodes: print "kernel is already of expected version" return execute(upgrade_kernel_node, *nodes, **kwargs) if reboot == 'yes': node_list_except_build = list(nodes) if env.host_string in nodes: node_list_except_build.remove(env.host_string) reboot_nodes(*node_list_except_build) reboot_nodes(env.host_string) else: reboot_nodes(*nodes)
def install_test_repo_node(*args): '''Installs test repo in given node''' for host_string in args: with settings(host_string=host_string): os_type = detect_ostype().lower() os_type, version, extra = get_linux_distro() if os_type in ['ubuntu']: if 'trusty' in extra : put('fabfile/contraillabs/repo/trusty_test.repo', '/etc/apt/sources.list.d/') if 'xenial' in extra : put('fabfile/contraillabs/repo/xenial_test.repo', '/etc/apt/sources.list.d/') sudo('apt-get update') if os_type in ['centos', 'centoslinux']: put('fabfile/contraillabs/repo/centos_el7_test.repo', '/etc/yum.repos.d/contrail_test.repo') run('yum clean all') if os_type in ['redhat']: put('fabfile/contraillabs/repo/el7_test.repo', '/etc/yum.repos.d/contrail_test.repo') run('yum clean all')
def install_test_repo_node(*args): '''Installs test repo in given node''' for host_string in args: with settings(host_string=host_string): os_type = detect_ostype().lower() os_type, version, extra = get_linux_distro() if os_type in ['ubuntu']: if 'trusty' in extra: put('fabfile/contraillabs/repo/trusty_test.repo', '/etc/apt/sources.list.d/') if 'xenial' in extra: put('fabfile/contraillabs/repo/xenial_test.repo', '/etc/apt/sources.list.d/') sudo('apt-get update') if os_type in ['centos', 'centoslinux']: put('fabfile/contraillabs/repo/centos_el7_test.repo', '/etc/yum.repos.d/contrail_test.repo') run('yum clean all') if os_type in ['redhat']: put('fabfile/contraillabs/repo/el7_test.repo', '/etc/yum.repos.d/contrail_test.repo') run('yum clean all')
def get_nodes_to_upgrade(*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): dist, version, extra = get_linux_distro() if version == '12.04': (package, os_type) = ('linux-image-3.13.0-34-generic', 'ubuntu') elif version == '14.04': (package, os_type) = ('linux-image-3.13.0-35-generic', 'ubuntu') else: raise RuntimeError('Unsupported platfrom (%s, %s, %s) for kernel upgrade.' % (dist, version, extra)) 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
def upgrade_kernel_all(*tgzs, **kwargs): """creates repo and upgrades kernel in Ubuntu""" reboot = kwargs.get('reboot', 'yes') execute('create_installer_repo') execute('create_install_repo', *tgzs) nodes = [] kernel_ver = kwargs.get('version') with settings(host_string=env.roledefs['all'][0], warn_only=True): dist, version, extra = get_linux_distro() if version == '12.04': (package, os_type) = ('linux-image-3.13.0-34-generic', 'ubuntu') default_grub='Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-34-generic' elif version == '14.04': if kernel_ver is None: kernel_ver='3.13.0-85' (package, os_type) = ('linux-image-'+kernel_ver+'-generic', 'ubuntu') default_grub='Advanced options for Ubuntu>Ubuntu, with Linux '+kernel_ver+'-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)) nodes = get_nodes_to_upgrade_pkg(package, os_type, *env.roledefs['all']) if not nodes: print "kernel is already of expected version" return execute(upgrade_kernel_node, *nodes, **kwargs) if reboot == 'yes': node_list_except_build = list(nodes) if env.host_string in nodes: node_list_except_build.remove(env.host_string) reboot_nodes(*node_list_except_build) reboot_nodes(env.host_string) else: reboot_nodes(*nodes)