Add baremetal strategy validation
This patch set adds validation of baremetal model. It also fixes PEP issues with storage capacity balance strategy. Change-Id: I53e37d91fa6c65f7c3d290747169007809100304 Depends-On: I177b443648301eb50da0da63271ecbfd9408bd4f
This commit is contained in:
@@ -89,7 +89,7 @@ class StrategyEndpoint(object):
|
|||||||
|
|
||||||
def _get_cdm(self, strategy):
|
def _get_cdm(self, strategy):
|
||||||
models = []
|
models = []
|
||||||
for model in ['compute_model', 'storage_model']:
|
for model in ['compute_model', 'storage_model', 'baremetal_model']:
|
||||||
try:
|
try:
|
||||||
getattr(strategy, model)
|
getattr(strategy, model)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
"ex_pools",
|
"ex_pools",
|
||||||
help="exclude pools",
|
help="exclude pools",
|
||||||
default=['local_vstorage']),
|
default=['local_vstorage']),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_pools(self, cinder):
|
def get_pools(self, cinder):
|
||||||
"""Get all volume pools excepting ex_pools.
|
"""Get all volume pools excepting ex_pools.
|
||||||
@@ -147,8 +147,8 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
status_volumes = list(
|
status_volumes = list(
|
||||||
filter(lambda v: v.status in valid_status, nosnap_volumes))
|
filter(lambda v: v.status in valid_status, nosnap_volumes))
|
||||||
valid_volumes = [v for v in status_volumes
|
valid_volumes = [v for v in status_volumes
|
||||||
if getattr(v, 'migration_status') == 'success'
|
if getattr(v, 'migration_status') == 'success' or
|
||||||
or getattr(v, 'migration_status') is None]
|
getattr(v, 'migration_status') is None]
|
||||||
LOG.info("valid volumes: %s", valid_volumes)
|
LOG.info("valid volumes: %s", valid_volumes)
|
||||||
|
|
||||||
return valid_volumes
|
return valid_volumes
|
||||||
@@ -200,11 +200,11 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
total_cap = float(pool.total_capacity_gb)
|
total_cap = float(pool.total_capacity_gb)
|
||||||
allocated = float(pool.allocated_capacity_gb)
|
allocated = float(pool.allocated_capacity_gb)
|
||||||
ratio = pool.max_over_subscription_ratio
|
ratio = pool.max_over_subscription_ratio
|
||||||
if total_cap*ratio < allocated+float(volume.size):
|
if total_cap * ratio < allocated + float(volume.size):
|
||||||
LOG.info("pool %s allocated over", pool.name)
|
LOG.info("pool %s allocated over", pool.name)
|
||||||
continue
|
continue
|
||||||
free_cap = float(pool.free_capacity_gb)-float(volume.size)
|
free_cap = float(pool.free_capacity_gb) - float(volume.size)
|
||||||
if free_cap > (1-threshold)*total_cap:
|
if free_cap > (1 - threshold) * total_cap:
|
||||||
target_pool_name = pool.name
|
target_pool_name = pool.name
|
||||||
index = self.dest_pools.index(pool)
|
index = self.dest_pools.index(pool)
|
||||||
setattr(self.dest_pools[index], 'free_capacity_gb',
|
setattr(self.dest_pools[index], 'free_capacity_gb',
|
||||||
@@ -232,8 +232,8 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
|
|
||||||
for src_key in src_extra_specs.keys():
|
for src_key in src_extra_specs.keys():
|
||||||
dst_pool_type = [pt for pt in dst_pool_type
|
dst_pool_type = [pt for pt in dst_pool_type
|
||||||
if pt.extra_specs.get(src_key)
|
if pt.extra_specs.get(src_key) ==
|
||||||
== src_extra_specs.get(src_key)]
|
src_extra_specs.get(src_key)]
|
||||||
if dst_pool_type:
|
if dst_pool_type:
|
||||||
if volume.volume_type:
|
if volume.volume_type:
|
||||||
if dst_pool_type[0].name != volume.volume_type:
|
if dst_pool_type[0].name != volume.volume_type:
|
||||||
@@ -256,11 +256,11 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
total_cap = float(pool.total_capacity_gb)
|
total_cap = float(pool.total_capacity_gb)
|
||||||
allocated = float(pool.allocated_capacity_gb)
|
allocated = float(pool.allocated_capacity_gb)
|
||||||
ratio = pool.max_over_subscription_ratio
|
ratio = pool.max_over_subscription_ratio
|
||||||
if total_cap*ratio < allocated+float(volume.size):
|
if total_cap * ratio < allocated + float(volume.size):
|
||||||
LOG.info("pool %s allocated over", pool.name)
|
LOG.info("pool %s allocated over", pool.name)
|
||||||
continue
|
continue
|
||||||
free_cap = float(pool.free_capacity_gb)-float(volume.size)
|
free_cap = float(pool.free_capacity_gb) - float(volume.size)
|
||||||
if free_cap > (1-threshold)*total_cap:
|
if free_cap > (1 - threshold) * total_cap:
|
||||||
target_type = self.check_pool_type(volume, pool)
|
target_type = self.check_pool_type(volume, pool)
|
||||||
if target_type is None:
|
if target_type is None:
|
||||||
continue
|
continue
|
||||||
@@ -280,7 +280,7 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
retype_dicts = dict()
|
retype_dicts = dict()
|
||||||
migrate_dicts = dict()
|
migrate_dicts = dict()
|
||||||
total_cap = float(pool.total_capacity_gb)
|
total_cap = float(pool.total_capacity_gb)
|
||||||
used_cap = float(pool.total_capacity_gb)-float(pool.free_capacity_gb)
|
used_cap = float(pool.total_capacity_gb) - float(pool.free_capacity_gb)
|
||||||
seek_flag = True
|
seek_flag = True
|
||||||
|
|
||||||
volumes_in_pool = list(
|
volumes_in_pool = list(
|
||||||
@@ -306,13 +306,13 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
vol_flag = True
|
vol_flag = True
|
||||||
if vol_flag:
|
if vol_flag:
|
||||||
used_cap -= float(vol.size)
|
used_cap -= float(vol.size)
|
||||||
if used_cap < threshold*total_cap:
|
if used_cap < threshold * total_cap:
|
||||||
seek_flag = False
|
seek_flag = False
|
||||||
break
|
break
|
||||||
if seek_flag:
|
if seek_flag:
|
||||||
noboot_volumes = list(
|
noboot_volumes = list(
|
||||||
filter(lambda v: v.bootable.lower() == 'false'
|
filter(lambda v: v.bootable.lower() == 'false' and
|
||||||
and v.status == 'in-use', volumes_in_pool))
|
v.status == 'in-use', volumes_in_pool))
|
||||||
noboot_volumes.sort(key=lambda v: float(v.size))
|
noboot_volumes.sort(key=lambda v: float(v.size))
|
||||||
LOG.info("noboot volumes: %s ", str(noboot_volumes))
|
LOG.info("noboot volumes: %s ", str(noboot_volumes))
|
||||||
for vol in noboot_volumes:
|
for vol in noboot_volumes:
|
||||||
@@ -328,13 +328,15 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
vol_flag = True
|
vol_flag = True
|
||||||
if vol_flag:
|
if vol_flag:
|
||||||
used_cap -= float(vol.size)
|
used_cap -= float(vol.size)
|
||||||
if used_cap < threshold*total_cap:
|
if used_cap < threshold * total_cap:
|
||||||
seek_flag = False
|
seek_flag = False
|
||||||
break
|
break
|
||||||
|
|
||||||
if seek_flag:
|
if seek_flag:
|
||||||
boot_volumes = list(filter(lambda v: v.bootable.lower() == 'true'
|
boot_volumes = list(
|
||||||
and v.status == 'in-use', volumes_in_pool))
|
filter(lambda v: v.bootable.lower() == 'true' and
|
||||||
|
v.status == 'in-use', volumes_in_pool)
|
||||||
|
)
|
||||||
boot_volumes.sort(key=lambda v: float(v.size))
|
boot_volumes.sort(key=lambda v: float(v.size))
|
||||||
LOG.info("boot volumes: %s ", str(boot_volumes))
|
LOG.info("boot volumes: %s ", str(boot_volumes))
|
||||||
for vol in boot_volumes:
|
for vol in boot_volumes:
|
||||||
@@ -350,7 +352,7 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
vol_flag = True
|
vol_flag = True
|
||||||
if vol_flag:
|
if vol_flag:
|
||||||
used_cap -= float(vol.size)
|
used_cap -= float(vol.size)
|
||||||
if used_cap < threshold*total_cap:
|
if used_cap < threshold * total_cap:
|
||||||
seek_flag = False
|
seek_flag = False
|
||||||
break
|
break
|
||||||
return retype_dicts, migrate_dicts
|
return retype_dicts, migrate_dicts
|
||||||
@@ -370,7 +372,7 @@ class StorageCapacityBalance(base.WorkloadStabilizationBaseStrategy):
|
|||||||
"""
|
"""
|
||||||
all_pools = self.get_pools(self.cinder)
|
all_pools = self.get_pools(self.cinder)
|
||||||
all_volumes = self.get_volumes(self.cinder)
|
all_volumes = self.get_volumes(self.cinder)
|
||||||
threshold = float(self.volume_threshold)/100
|
threshold = float(self.volume_threshold) / 100
|
||||||
self.source_pools, self.dest_pools = self.group_pools(
|
self.source_pools, self.dest_pools = self.group_pools(
|
||||||
all_pools, threshold)
|
all_pools, threshold)
|
||||||
LOG.info(" source pools: %s dest pools:%s",
|
LOG.info(" source pools: %s dest pools:%s",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
# Copyright (c) 2017 Servionica
|
# Copyright (c) 2018 Servionica
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -55,10 +55,12 @@ class TestStrategyEndpoint(base.BaseTestCase):
|
|||||||
strategy = mock.MagicMock()
|
strategy = mock.MagicMock()
|
||||||
strategy.compute_model = mock.MagicMock()
|
strategy.compute_model = mock.MagicMock()
|
||||||
del strategy.storage_model
|
del strategy.storage_model
|
||||||
|
strategy.baremetal_model = mock.MagicMock()
|
||||||
se = strategy_base.StrategyEndpoint(mock.MagicMock())
|
se = strategy_base.StrategyEndpoint(mock.MagicMock())
|
||||||
result = se._get_cdm(strategy)
|
result = se._get_cdm(strategy)
|
||||||
expected_result = {'type': 'CDM',
|
expected_result = {'type': 'CDM',
|
||||||
'state': [{"compute_model": "available"},
|
'state': [{"compute_model": "available"},
|
||||||
{"storage_model": "not available"}],
|
{"storage_model": "not available"},
|
||||||
|
{"baremetal_model": "available"}],
|
||||||
'mandatory': True, 'comment': ''}
|
'mandatory': True, 'comment': ''}
|
||||||
self.assertEqual(expected_result, result)
|
self.assertEqual(expected_result, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user