Add preupgrade compute

* preuepgrade_compute command was added
* util functions for change_repositories was added

Change-Id: I745b691fb701960c5cc8a384643e5fa72553978e
This commit is contained in:
Anastasiya 2016-08-18 14:13:34 +03:00 committed by Anastasia Balobashina
parent 0de568c5aa
commit 2ebcb25eed
4 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,123 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import collections
import logging
from cliff import command as cmd
from fuelclient import objects
from octane import magic_consts
from octane.util import apt
from octane.util import helpers
from octane.util import ssh
LOG = logging.getLogger(__name__)
def check_sanity(nodes, release):
if release.data['state'] != 'available':
raise Exception(
"Release with id {0} is not available.".format(release.id)
)
env_id = nodes[0].env.id
for node in nodes:
if node.env.id != env_id:
raise Exception(
"Nodes have different clusters."
)
env_id = node.env.id
if 'compute' not in node.data['roles']:
raise Exception(
"Preupgrade procedure is available only for compute nodes. "
"Node with id {0} is not a compute.".format(node.id)
)
def change_repositories(node, repos):
ssh.remove_all_files_from_dirs(['/etc/apt/sources.list.d',
'/etc/apt/preferences.d'], node)
sftp = ssh.sftp(node)
for repo in repos:
filename_source, content_source = apt.create_repo_source(repo)
ssh.write_content_to_file(sftp, filename_source, content_source)
if repo['priority']:
filename_pref, content_pref = apt.create_repo_preferences(repo)
ssh.write_content_to_file(sftp, filename_pref, content_pref)
ssh.call(['apt-get', 'update'], node=node)
def stop_compute_services(node):
ssh.call(['stop', 'nova-compute'], node=node)
ssh.call(['stop', 'neutron-plugin-openvswitch-agent'], node=node)
def get_repos(release, master_ip=''):
repos = (release.data['attributes_metadata']['editable']['repo_setup']
['repos']['value'])
version = release.data['version']
environment_version = version.split('-')[1]
settings_cls = collections.namedtuple("settings", ["MASTER_IP", "release"])
release_cls = collections.namedtuple("release",
["version", "environment_version"])
settings = settings_cls(master_ip,
release_cls(version, environment_version))
for repo in repos:
repo['uri'] = repo['uri'].format(settings=settings, cluster=settings)
return repos
def preupgrade_compute(release_id, node_ids):
nodes = [objects.node.Node(node_id) for node_id in node_ids]
release = objects.Release(release_id)
check_sanity(nodes, release)
master_ip = helpers.get_astute_dict()["ADMIN_NETWORK"]['ipaddress']
version = release.data['version']
repos = get_repos(release, master_ip)
try:
packages = magic_consts.COMPUTE_PREUPGRADE_PACKAGES[version]
except KeyError:
LOG.exception("Info about packages for a release with id {0} "
"is not exist".format(release_id))
raise
for node in nodes:
change_repositories(node, repos)
stop_compute_services(node)
apt.upgrade_packages(node, packages)
class PreupgradeComputeCommand(cmd.Command):
"""Preupgrade compute"""
def get_parser(self, prog_name):
parser = super(PreupgradeComputeCommand, self).get_parser(prog_name)
parser.add_argument(
'release_id',
type=int,
metavar='RELEASE_ID',
help="Release that repositories will be taken from"
)
parser.add_argument(
'node_ids',
type=int,
metavar='NODE_ID',
help="IDs of compute nodes to be preupgraded",
nargs="+")
return parser
def take_action(self, parsed_args):
preupgrade_compute(parsed_args.release_id, parsed_args.node_ids)

View File

@ -103,3 +103,29 @@ SKIP_CONTROLLER_TASKS = [
"upload_cirros", "ceph_ready_check", "configure_default_route",
"enable_rados",
]
COMPUTE_PREUPGRADE_PACKAGES = {
'liberty-8.0': [
"python-routes", "python-oslo.concurrency", "python-sqlparse",
"nova-common", "python-pkg-resources", "python-oslo.policy",
"neutron-plugin-ml2", "python-oslo.config", "python-glanceclient",
"python-paramiko", "python-jinja2", "python-nova", "python-editor",
"python-contextlib2", "libvirt-clients", "python-oslo.serialization",
"python-urllib3", "python-keystonemiddleware", "python-openssl",
"libvirt0", "fuel-ha-utils", "python-netaddr", "python-oslo.i18n",
"python-cliff", "python-oslo.reports", "python-libvirt",
"neutron-common", "python-oslo.versionedobjects", "python-oslo.db",
"nailgun-mcagents", "python-novaclient", "python-unicodecsv",
"neutron-plugin-openvswitch-agent", "python-oslo.rootwrap",
"python-oslo.utils", "python-ipaddress", "python-oslo.lo",
"python-msgpack", "python-amqp", "python-cryptography", "python-six",
"python-oslo.context", "python-openvswitch", "python-netifaces",
"libvirt-daemon", "network-checker", "python-oslo.messaging",
"mcollective-common", "python-oslo.middleware", "python-jsonschema",
"python-keystoneclient", "python-oslo.service", "python-neutronclient",
"python-requests", "python-singledispatch", "python-neutron",
"python-stevedore", "python-sqlalchemy", "nova-compute",
"nova-compute-qemu", "python-extras", "mcollective", "libvirt-bin",
"python-cinderclient", "python-concurrent.futures"
]
}

View File

@ -13,6 +13,7 @@
import contextlib
import io
import logging
import os
import pipes
import random
import shutil
@ -291,3 +292,16 @@ def get_env_credentials(env):
'user': editable['name']['value'],
'password': editable['password']['value'],
}
def remove_all_files_from_dirs(dir_names, node):
ftp = sftp(node)
for dir_name in dir_names:
for filename in ftp.listdir(dir_name):
path = os.path.join(dir_name, filename)
ftp.unlink(path)
def write_content_to_file(sftp, filename, content):
with sftp.open(filename, 'w') as f:
f.write(content)

View File

@ -31,6 +31,7 @@ octane =
upgrade-node = octane.commands.upgrade_node:UpgradeNodeCommand
upgrade-db = octane.commands.upgrade_db:UpgradeDBCommand
upgrade-ceph = octane.commands.upgrade_ceph:UpgradeCephCommand
preupgrade-compute = octane.commands.preupgrade_compute:PreupgradeComputeCommand
install-node = octane.commands.install_node:InstallNodeCommand
upgrade-control = octane.commands.upgrade_controlplane:UpgradeControlPlaneCommand
upgrade-osd = octane.commands.osd_upgrade:UpgradeOSDCommand