From 546e274899b61eda297e7b48e8ef47f8326f1707 Mon Sep 17 00:00:00 2001 From: Suresh Venkata Date: Wed, 5 Oct 2016 16:18:50 -0700 Subject: [PATCH] Fixes:ISSU support for openstack ClosesBug:1619413 Change-Id: Idc83d9c6574bcee7400197ea44f322dc79d6d7e3 --- fabfile/tasks/issu_process.py | 281 ++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) diff --git a/fabfile/tasks/issu_process.py b/fabfile/tasks/issu_process.py index 996d265fc..d52a26bfc 100644 --- a/fabfile/tasks/issu_process.py +++ b/fabfile/tasks/issu_process.py @@ -13,6 +13,10 @@ from fabfile.tasks.provision import prov_database_node from fabfile.tasks.provision import prov_control_bgp_node from fabfile.utils.install import get_vrouter_kmod_pkg +from fabfile.utils.host import * +from fabfile.utils.fabos import * +from fabric.contrib.files import exists + @task @roles('compute') @@ -363,3 +367,280 @@ def issu_contrail(): #execute('issu_contrail_migrate_compute') #execute('issu_contrail_finalize') print "Single touch ISSU is not yet supported" + +################################################################################################################# +# +# +# ISSU Openstack JUNO to KILO and KILO to LIBERTY. +# +# +################################################################################################################# +@task +@roles('cfgm') +def issu_openstack_migrate_neutron(from_version, to_version): + """Migrate neutron to new version of openstack""" + execute("issu_openstack_migrate_neutron_node", from_version, to_version, env.host_string) + +@task +def issu_openstack_migrate_neutron_node(from_version, to_version, *args): + auth_host = get_authserver_ip() + auth_port = get_authserver_port() + admin_token = get_keystone_admin_token() + for host_string in args: + with settings(host_string=host_string): + sudo("openstack-config --set /etc/contrail/vnc_api_lib.ini auth AUTHN_SERVER %s" %(auth_host)) + sudo("openstack-config --set /etc/contrail/contrail-keystone-auth.conf KEYSTONE auth_host %s" %(auth_host)) + sudo("openstack-config --set /etc/neutron/plugins/opencontrail/ContrailPlugin.ini KEYSTONE auth_url http://%s:%s/v2.0" %(auth_host, auth_port)) + cmd = "openstack-config --set /etc/neutron/neutron.conf keystone_authtoken" + sudo("%s auth_host %s" %(cmd, auth_host)) + sudo("%s auth_uri http://%s:%s/v2.0/" %(cmd, auth_host, auth_port)) + sudo("%s identity_uri http://%s:5000" %(cmd, auth_host)) + sudo("%s admin_token %s" %(cmd, admin_token)) + if from_version == 'juno' and to_version == 'kilo': + sudo("openstack-config --set /etc/neutron/neutron.conf upgrade_levels compute juno") + elif from_version == 'kilo' and to_version == 'liberty': + sudo("openstack-config --set /etc/neutron/neutron.conf upgrade_levels compute kilo") + else: + raise RuntimeError("Upgrade from %s to %s not supported" %(from_version, to_version)) + + sudo("service neutron-server restart") + sudo("service supervisor-config restart") +@task +@roles('cfgm') +def issu_openstack_upgrade_neutron(from_version, to_version, pkg): + """Upgrade neutron packages in config node""" + execute("issu_openstack_upgrade_neutron_node", from_version, to_version, pkg, env.host_string) + +@task +def issu_openstack_upgrade_neutron_node(from_version, to_version, pkg, *args): + 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, is_openstack_upgrade='True') + ostype = detect_ostype() + if (ostype in ['ubuntu']): + cmd = 'apt-get -y --force-yes -o Dpkg::Options::="--force-overwrite" -o Dpkg::Options::="--force-confold"' + elif ostype in ['centos', 'fedora', 'redhat', 'centoslinux']: + cmd = 'yum -y' + else: + raise RuntimeError("Unsupported OS") + if from_version == 'juno' and to_version == 'kilo': + sudo("%s install neutron-server" %(cmd)) + elif from_version == 'kilo' and to_version == 'liberty': + sudo("%s install neutron-plugin-ml2 python-sqlalchemy-ext python-alembic python-oslo.utils neutron-server" %(cmd)) + else: + raise RuntimeError("Upgrade from %s to %s not supported" %(from_version, to_version)) + + sudo("%s install neutron-plugin-ml2 python-sqlalchemy-ext python-alembic python-oslo.utils neutron-server" %(cmd)) + sudo("%s install python-neutron-lbaas" %(cmd)) + execute('issu_provision_neutron_node', from_version, to_version, host_string) + +@task +def issu_provision_neutron_node(from_version, to_version, *args): + for host_string in args: + val = sudo('openstack-config --get /etc/neutron/neutron.conf DEFAULT lock_path') + sudo("openstack-config --set /etc/neutron/neutron.conf oslo_concurrency lock_path %s" %(val)) + if from_version == 'kilo' and to_version == 'liberty': + PYDIST=sudo('python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"') + sudo('openstack-config --set /etc/neutron/neutron.conf DEFAULT service_plugins neutron_plugin_contrail.plugins.opencontrail.loadbalancer.v2.plugin.LoadBalancerPluginV2') + sudo('openstack-config --set /etc/neutron/neutron.conf DEFAULT api_extensions_path extensions:%s/neutron_plugin_contrail/extensions:%s/neutron_lbaas/extensions' %(PYDIST, PYDIST)) + sudo("service neutron-server restart") + sudo("service supervisor-config restart") + +@task +@roles('compute') +def issu_openstack_migrate_compute(from_version, to_version): + """Migrate compute node to new version of openstack""" + execute("issu_openstack_migrate_compute_node", from_version, to_version, env.host_string) + +@task +def issu_openstack_migrate_compute_node(from_version, to_version, *args): + auth_host = get_authserver_ip() + auth_port = get_authserver_port() + rabbit_host = get_openstack_amqp_server() + openstack_host = env.roledefs['openstack'][0] + for host_string in args: + with settings(host_string=host_string): + sudo("openstack-config --set /etc/nova/nova.conf DEFAULT rabbit_host %s" %(rabbit_host)) + if from_version == 'juno' and to_version == 'kilo': + cmd = "openstack-config --set /etc/nova/nova.conf" + sudo("%s DEFAULT neutron_admin_auth_url http://%s:%s/v2.0/" % (cmd, auth_host, auth_port)) + sudo("%s DEFAULT glance_host %s" %(cmd, openstack_host)) + sudo("%s DEFAULT novncproxy_base_url http://%s/:5999/vnc_auto.html" %(cmd, openstack_host)) + sudo("%s keystone_authtoken auth_host %s" %(cmd, auth_host)) + sudo("%s upgrade_levels compute juno" %(cmd)) + elif from_version == 'kilo' and to_version == 'liberty': + cmd = "openstack-config --set /etc/nova/nova.conf" + sudo("%s neutron admin_auth_url http://%s:%s/v2.0/" %(cmd, auth_host, auth_port)) + sudo("%s glance host root@%s" %(cmd, openstack_host)) + sudo("%s keystone_authtoken auth_host %s" %(cmd, auth_host)) + sudo("%s upgrade_levels compute kilo" %(cmd)) + else: + raise RuntimeError("Upgrade from %s to %s not supported" %(from_version, to_version)) + sudo("service nova-compute restart") +@task +@roles('compute') +def issu_openstack_upgrade_compute(from_version, to_version, pkg): + """Upgrade nova packages in compute node""" + execute("issu_openstack_upgrade_compute_node", from_version, to_version, pkg, env.host_string) + +@task +def issu_openstack_upgrade_compute_node(from_version, to_version, pkg, *args): + 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, is_openstack_upgrade='True') + ostype = detect_ostype() + if (ostype in ['ubuntu']): + cmd = 'apt-get -y --force-yes -o Dpkg::Options::="--force-overwrite" -o Dpkg::Options::="--force-confold"' + elif ostype in ['centos', 'fedora', 'redhat', 'centoslinux']: + cmd = 'yum -y' + else: + raise RuntimeError("Unsupported OS") + print "Invalid OS" + return + sudo("%s install python-neutronclient" %(cmd)) + sudo("%s install python-nova" %(cmd)) + sudo("%s install python-novaclient" %(cmd)) + sudo("%s install nova-compute-libvirt" %(cmd)) + if from_version == 'juno' and to_version == 'kilo': + execute('provision_compute_node', host_string) +@task +def provision_compute_node(*args): + admin_user, admin_password = get_authserver_credentials() + admin_tenant_name = get_admin_tenant_name() + auth_host = get_authserver_ip() + auth_port = get_authserver_port() + auth_protocol = get_authserver_protocol() + signing_dir = "/tmp/keystone-signing-nova" + for host_string in args: + with settings(host_string=host_string): + cmd_get = "openstack-config --get /etc/nova/nova.conf DEFAULT" + cmd_set = "openstack-config --set /etc/nova/nova.conf" + val = sudo("%s compute_driver" %(cmd_get)) + sudo("%s compute compute_driver %s" %(cmd_set, val)) + val = sudo("%s neutron_admin_auth_url" %(cmd_get)) + sudo("%s neutron admin_auth_url %s" %(cmd_set, val)) + val = sudo("%s neutron_admin_username" %(cmd_get)) + sudo("%s neutron admin_username %s" %(cmd_set, val)) + val = sudo("%s neutron_admin_password" %(cmd_get)) + sudo("%s neutron admin_password %s" %(cmd_set, val)) + val = sudo("%s neutron_admin_tenant_name" %(cmd_get)) + sudo("%s neutron admin_tenant_name %s" %(cmd_set, val)) + val = sudo("%s neutron_url" %(cmd_get)) + sudo("%s neutron url %s" %(cmd_set, val)) + val = sudo("%s neutron_url_timeout" %(cmd_get)) + sudo("%s neutron url_timeout %s" %(cmd_set, val)) + val = sudo("%s glance_host" %(cmd_get)) + sudo("%s glance host %s" %(cmd_set, val)) + sudo("%s keystone_authtoken admin_tenant_name %s" %(cmd_set, admin_tenant_name)) + sudo("%s keystone_authtoken admin_user %s" %(cmd_set, admin_user)) + sudo("%s keystone_authtoken admin_password %s" %(cmd_set, admin_password)) + sudo("%s keystone_authtoken auth_host %s" %(cmd_set, auth_host)) + sudo("%s keystone_authtoken auth_protocol %s" %(cmd_set, auth_protocol)) + sudo("%s keystone_authtoken auth_port %s" %(cmd_set, auth_port)) + sudo("%s keystone_authtoken signing_dir %s" %(cmd_set, signing_dir)) + sudo("service nova-compute restart") + +@task +def issu_openstack_finalize_upgrade(): + execute('issu_openstack_finalize_compute') + execute('issu_openstack_finalize_neutron') + execute('issu_openstack_finalize_openstack') + +@task +@roles('compute') +def issu_openstack_finalize_compute(): + execute('issu_openstack_finalize_compute_node', env.host_string) +@task +def issu_openstack_finalize_compute_node(*args): + for host_string in args: + with settings(host_string=host_string): + sudo('openstack-config --del /etc/nova/nova.conf upgrade_levels') + sudo('service nova-compute restart') + +@task +@roles('cfgm') +def issu_openstack_finalize_neutron(): + execute('issu_openstack_finalize_neutron_node', env.host_string) + +@task +def issu_openstack_finalize_neutron_node(*args): + for host_string in args: + with settings(host_string=host_string): + sudo('openstack-config --del /etc/neutron/neutron.conf upgrade_levels') + sudo('service neutron-server restart') + +@task +@roles('openstack') +def issu_openstack_finalize_openstack(): + execute('issu_openstack_finalize_openstack_node', env.host_string) + +@task +def issu_openstack_finalize_openstack_node(*args): + for host_string in args: + with settings(host_string=host_string): + sudo('openstack-config --del /etc/nova/nova.conf upgrade_levels') + sudo('sync; reboot --force') + +@task +@roles('build') +def issu_openstack_migrate_to_new_controller(from_version, to_version): + db_file = 'issu_openstack_db' + execute('issu_openstack_snapshot_db', from_version, to_version, db_file) + execute('issu_openstack_sync', from_version, to_version, db_file) + execute('issu_openstack_migrate_neutron', from_version, to_version) + execute('issu_openstack_migrate_compute', from_version, to_version) + execute('issu_openstack_reboot_openstack') + +@task +@roles('openstack') +def issu_openstack_reboot_openstack(): + execute('issu_openstack_reboot_openstack_node', env.host_string) +@task +def issu_openstack_reboot_openstack_node(*args): + for host_string in args: + with settings(host_string=host_string): + sudo('sync; reboot --force') +@task +@roles('openstack') +def issu_openstack_sync(from_version, to_version, db_file): + sql_passwd = sudo('cat /etc/contrail/mysql.token') + newopenstack=host_string_to_ip(env.host_string) + oldopenstack=host_string_to_ip(env.roledefs['oldopenstack'][0]) + sudo("sed -i 's/%s/%s/g' %s" %(oldopenstack, newopenstack, db_file)) + if from_version == 'kilo' and to_version == 'liberty': + from_string = "$(compute_port)s" + to_string = "8774" + sudo("sed -i 's/%s/%s/g' %s" %(from_string, to_string, db_file)) + print sql_passwd + sudo("mysql --user root --password=%s < %s" %(sql_passwd, db_file)) + sudo("nova-manage db sync") + sudo("keystone-manage db_sync") + sudo("cinder-manage db sync") + sudo("glance-manage db sync") + if from_version == 'juno' and to_version == 'kilo': + sudo("openstack-config --set /etc/nova/nova.conf upgrade_levels compute juno") + elif from_version == 'kilo' and to_version == 'liberty': + sudo("openstack-config --set /etc/nova/nova.conf upgrade_levels compute kilo") + else: + raise RuntimeError("Upgrade from %s to %s not supported" %(from_version, to_version)) + + print "Migrate openstack orchestrator" + +@task +@roles('oldopenstack') +def issu_openstack_snapshot_db(from_version, to_version, db_file): + if from_version == 'kilo' and to_version == 'liberty': + sudo("nova-manage db migrate_flavor_data") + sql_passwd = sudo('cat /etc/contrail/mysql.token') + sudo("mysqldump -u root --password=%s --opt --add-drop-database --all-databases > %s" %(sql_passwd, db_file)) + svc_token = '/etc/contrail/service.token' + mysql_token = '/etc/contrail/mysql.token' + get_as_sudo('~/%s' %db_file, '/tmp') + get_as_sudo(svc_token, '/tmp') + get_as_sudo(mysql_token, '/tmp') + with settings(host_string=env.roledefs['openstack'][0], password=get_env_passwords(env.roledefs['openstack'][0])): + put('/tmp/%s' %(db_file), '~/', use_sudo=True) + put('/tmp/service.token', svc_token, use_sudo=True) + put('/tmp/mysql.token', mysql_token, use_sudo=True)