Merge "Move partition info transformation to extension"

This commit is contained in:
Jenkins 2016-08-24 19:59:04 +00:00 committed by Gerrit Code Review
commit f4bf5159dd
5 changed files with 75 additions and 2 deletions

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nailgun.extensions.volume_manager import extension as volume_ext
from nailgun import objects
@ -208,6 +209,14 @@ class NailgunNodeAdapter(object):
def add_pending_change(self, change):
objects.Node.add_pending_change(self.node, change)
def get_volumes(self):
return volume_ext.VolumeManagerExtension.get_node_volumes(self.node)
def set_volumes(self, volumes):
return volume_ext.VolumeManagerExtension.set_node_volumes(
self.node, volumes
)
class NailgunNetworkGroupAdapter(object):

View File

@ -64,8 +64,8 @@ class Manager(object):
def apply(self, from_version, to_version, data):
strict_from = distutils.version.StrictVersion(from_version)
strict_to = distutils.version.StrictVersion(to_version)
assert strict_from < strict_to, \
"from_version must be smaller than to_version"
assert strict_from <= strict_to, \
"from_version must not be greater than to_version"
data = copy.deepcopy(data)
for version, transformers in self.transformers:
if version <= strict_from:

View File

@ -0,0 +1,53 @@
# coding: utf-8
# 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.
from cluster_upgrade import transformations
def transform_node_volumes(volumes):
try:
os_vg = next(vol for vol in volumes
if 'id' in vol and vol['id'] == 'os')
except StopIteration:
return volumes
other_volumes = [vol for vol in volumes
if 'id' not in vol or vol['id'] != 'os']
for disk in other_volumes:
disk_volumes = disk['volumes']
disk['volumes'] = []
for v in disk_volumes:
if v['type'] == 'pv' and v['vg'] == 'os' and v['size'] > 0:
for vv in os_vg['volumes']:
partition = {'name': vv['name'],
'size': vv['size'],
'type': 'partition',
'mount': vv['mount'],
'file_system': vv['file_system']}
disk['volumes'].append(partition)
else:
if v['type'] == 'lvm_meta_pool' or v['type'] == 'boot':
v['size'] = 0
disk['volumes'].append(v)
return volumes
class Manager(transformations.Manager):
default_config = {
'6.1': ['node_volumes']
}
name = 'volumes'

View File

@ -28,6 +28,7 @@ from nailgun import utils
from . import transformations # That's weird, but that's how hacking likes
from .objects import adapters
from .transformations import cluster as cluster_trs
from .transformations import volumes as volumes_trs
def merge_attributes(a, b):
@ -75,6 +76,7 @@ class UpgradeHelper(object):
network_configuration.NovaNetworkConfigurationSerializer,
}
cluster_transformations = transformations.Lazy(cluster_trs.Manager)
volumes_transformations = transformations.Lazy(volumes_trs.Manager)
@classmethod
def clone_cluster(cls, orig_cluster, data):
@ -215,6 +217,13 @@ class UpgradeHelper(object):
orig_cluster = adapters.NailgunClusterAdapter.get_by_uid(
node.cluster_id)
volumes = cls.volumes_transformations.apply(
orig_cluster.release.environment_version,
seed_cluster.release.environment_version,
node.get_volumes(),
)
node.set_volumes(volumes)
orig_manager = orig_cluster.get_network_manager()
netgroups_id_mapping = cls.get_netgroups_id_mapping(

View File

@ -25,6 +25,8 @@ packages =
[entry_points]
nailgun.extensions =
cluster_upgrade = cluster_upgrade.extension:ClusterUpgradeExtension
nailgun.cluster_upgrade.transformations.volumes.6.1 =
node_volumes = cluster_upgrade.transformations.volumes:transform_node_volumes
nailgun.cluster_upgrade.transformations.cluster.9.0 =
dns_list = cluster_upgrade.transformations.cluster:transform_dns_list
ntp_list = cluster_upgrade.transformations.cluster:transform_ntp_list