Merge "formal datasource interface implementation"
This commit is contained in:
@@ -54,7 +54,6 @@ class TestCeilometerHelper(base.BaseTestCase):
|
||||
self.assertEqual(expected, query)
|
||||
|
||||
def test_statistic_aggregation(self, mock_ceilometer):
|
||||
cm = ceilometer_helper.CeilometerHelper()
|
||||
ceilometer = mock.MagicMock()
|
||||
statistic = mock.MagicMock()
|
||||
expected_result = 100
|
||||
@@ -63,113 +62,73 @@ class TestCeilometerHelper(base.BaseTestCase):
|
||||
mock_ceilometer.return_value = ceilometer
|
||||
cm = ceilometer_helper.CeilometerHelper()
|
||||
val = cm.statistic_aggregation(
|
||||
resource_id="INSTANCE_ID",
|
||||
meter_name="cpu_util",
|
||||
resource=mock.Mock(id="INSTANCE_ID"),
|
||||
resource_type='instance',
|
||||
meter_name="instance_cpu_usage",
|
||||
period="7300",
|
||||
granularity=None
|
||||
)
|
||||
self.assertEqual(expected_result, val)
|
||||
|
||||
def test_get_last_sample(self, mock_ceilometer):
|
||||
ceilometer = mock.MagicMock()
|
||||
statistic = mock.MagicMock()
|
||||
expected_result = 100
|
||||
statistic[-1]._info = {'counter_volume': expected_result}
|
||||
ceilometer.samples.list.return_value = statistic
|
||||
mock_ceilometer.return_value = ceilometer
|
||||
cm = ceilometer_helper.CeilometerHelper()
|
||||
val = cm.get_last_sample_value(
|
||||
resource_id="id",
|
||||
meter_name="compute.node.percent"
|
||||
)
|
||||
self.assertEqual(expected_result, val)
|
||||
|
||||
def test_get_last_sample_none(self, mock_ceilometer):
|
||||
ceilometer = mock.MagicMock()
|
||||
expected = []
|
||||
ceilometer.samples.list.return_value = expected
|
||||
mock_ceilometer.return_value = ceilometer
|
||||
cm = ceilometer_helper.CeilometerHelper()
|
||||
val = cm.get_last_sample_values(
|
||||
resource_id="id",
|
||||
meter_name="compute.node.percent"
|
||||
)
|
||||
self.assertEqual(expected, val)
|
||||
|
||||
def test_statistic_list(self, mock_ceilometer):
|
||||
ceilometer = mock.MagicMock()
|
||||
expected_value = []
|
||||
ceilometer.statistics.list.return_value = expected_value
|
||||
mock_ceilometer.return_value = ceilometer
|
||||
cm = ceilometer_helper.CeilometerHelper()
|
||||
val = cm.statistic_list(meter_name="cpu_util")
|
||||
self.assertEqual(expected_value, val)
|
||||
|
||||
def test_get_host_cpu_usage(self, mock_ceilometer):
|
||||
self.helper.get_host_cpu_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_cpu_usage'], 600, None,
|
||||
aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_cpu_usage', 600, 'mean', None)
|
||||
|
||||
def test_get_instance_cpu_usage(self, mock_ceilometer):
|
||||
self.helper.get_instance_cpu_usage('compute1', 600, 'mean')
|
||||
def test_get_host_ram_usage(self, mock_ceilometer):
|
||||
self.helper.get_host_ram_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_cpu_usage'], 600,
|
||||
None, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_ram_usage', 600, 'mean', None)
|
||||
|
||||
def test_get_host_memory_usage(self, mock_ceilometer):
|
||||
self.helper.get_host_memory_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_memory_usage'], 600, None,
|
||||
aggregation='mean')
|
||||
|
||||
def test_get_instance_memory_usage(self, mock_ceilometer):
|
||||
self.helper.get_instance_ram_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_ram_usage'], 600,
|
||||
None, aggregation='mean')
|
||||
|
||||
def test_get_instance_l3_cache_usage(self, mock_ceilometer):
|
||||
self.helper.get_instance_l3_cache_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_l3_cache_usage'], 600,
|
||||
None, aggregation='mean')
|
||||
|
||||
def test_get_instance_ram_allocated(self, mock_ceilometer):
|
||||
self.helper.get_instance_ram_allocated('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_ram_allocated'], 600,
|
||||
None, aggregation='mean')
|
||||
|
||||
def test_get_instance_root_disk_allocated(self, mock_ceilometer):
|
||||
self.helper.get_instance_root_disk_size('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_root_disk_size'], 600,
|
||||
None, aggregation='mean')
|
||||
|
||||
def test_get_host_outlet_temperature(self, mock_ceilometer):
|
||||
def test_get_host_outlet_temp(self, mock_ceilometer):
|
||||
self.helper.get_host_outlet_temp('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_outlet_temp'], 600, None,
|
||||
aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_outlet_temp', 600, 'mean', None)
|
||||
|
||||
def test_get_host_inlet_temperature(self, mock_ceilometer):
|
||||
def test_get_host_inlet_temp(self, mock_ceilometer):
|
||||
self.helper.get_host_inlet_temp('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_inlet_temp'], 600, None,
|
||||
aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_inlet_temp', 600, 'mean', None)
|
||||
|
||||
def test_get_host_airflow(self, mock_ceilometer):
|
||||
self.helper.get_host_airflow('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_airflow'], 600, None,
|
||||
aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_airflow', 600, 'mean', None)
|
||||
|
||||
def test_get_host_power(self, mock_ceilometer):
|
||||
self.helper.get_host_power('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_power'], 600, None,
|
||||
aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_power', 600, 'mean', None)
|
||||
|
||||
def test_get_instance_cpu_usage(self, mock_ceilometer):
|
||||
self.helper.get_instance_cpu_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_cpu_usage', 600, 'mean',
|
||||
None)
|
||||
|
||||
def test_get_instance_ram_usage(self, mock_ceilometer):
|
||||
self.helper.get_instance_ram_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_ram_usage', 600, 'mean',
|
||||
None)
|
||||
|
||||
def test_get_instance_ram_allocated(self, mock_ceilometer):
|
||||
self.helper.get_instance_ram_allocated('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_ram_allocated', 600, 'mean',
|
||||
None)
|
||||
|
||||
def test_get_instance_l3_cache_usage(self, mock_ceilometer):
|
||||
self.helper.get_instance_l3_cache_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_l3_cache_usage', 600, 'mean',
|
||||
None)
|
||||
|
||||
def test_get_instance_root_disk_size(self, mock_ceilometer):
|
||||
self.helper.get_instance_root_disk_size('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_root_disk_size', 600, 'mean',
|
||||
None)
|
||||
|
||||
def test_check_availability(self, mock_ceilometer):
|
||||
ceilometer = mock.MagicMock()
|
||||
|
||||
@@ -48,85 +48,74 @@ class TestGnocchiHelper(base.BaseTestCase):
|
||||
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
result = helper.statistic_aggregation(
|
||||
resource_id='16a86790-327a-45f9-bc82-45839f062fdc',
|
||||
meter_name='cpu_util',
|
||||
resource=mock.Mock(id='16a86790-327a-45f9-bc82-45839f062fdc'),
|
||||
resource_type='instance',
|
||||
meter_name='instance_cpu_usage',
|
||||
period=300,
|
||||
granularity=360,
|
||||
dimensions=None,
|
||||
aggregation='mean',
|
||||
group_by='*'
|
||||
aggregate='mean',
|
||||
)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
def test_get_host_cpu_usage(self, mock_gnocchi):
|
||||
self.helper.get_host_cpu_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.helper.get_host_cpu_usage('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_cpu_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_cpu_usage', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_instance_cpu_usage(self, mock_gnocchi):
|
||||
self.helper.get_instance_cpu_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
def test_get_host_ram_usage(self, mock_gnocchi):
|
||||
self.helper.get_host_ram_usage('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_cpu_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_host_memory_usage(self, mock_gnocchi):
|
||||
self.helper.get_host_memory_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_memory_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_instance_memory_usage(self, mock_gnocchi):
|
||||
self.helper.get_instance_ram_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_ram_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_instance_ram_allocated(self, mock_gnocchi):
|
||||
self.helper.get_instance_ram_allocated('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_ram_allocated'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_instance_root_disk_allocated(self, mock_gnocchi):
|
||||
self.helper.get_instance_root_disk_size('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_root_disk_size'], 600,
|
||||
300, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_ram_usage', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_host_outlet_temperature(self, mock_gnocchi):
|
||||
self.helper.get_host_outlet_temp('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.helper.get_host_outlet_temp('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_outlet_temp'], 600,
|
||||
300, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_outlet_temp', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_host_inlet_temperature(self, mock_gnocchi):
|
||||
self.helper.get_host_inlet_temp('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.helper.get_host_inlet_temp('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_inlet_temp'], 600,
|
||||
300, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_inlet_temp', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_host_airflow(self, mock_gnocchi):
|
||||
self.helper.get_host_airflow('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.helper.get_host_airflow('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_airflow'], 600,
|
||||
300, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_airflow', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_host_power(self, mock_gnocchi):
|
||||
self.helper.get_host_power('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.helper.get_host_power('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_power'], 600,
|
||||
300, aggregation='mean')
|
||||
'compute1', 'compute_node', 'host_power', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_instance_cpu_usage(self, mock_gnocchi):
|
||||
self.helper.get_instance_cpu_usage('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_cpu_usage', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_instance_memory_usage(self, mock_gnocchi):
|
||||
self.helper.get_instance_ram_usage('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_ram_usage', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_instance_ram_allocated(self, mock_gnocchi):
|
||||
self.helper.get_instance_ram_allocated('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_ram_allocated', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_get_instance_root_disk_allocated(self, mock_gnocchi):
|
||||
self.helper.get_instance_root_disk_size('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', 'instance', 'instance_root_disk_size', 600, 'mean',
|
||||
300)
|
||||
|
||||
def test_gnocchi_check_availability(self, mock_gnocchi):
|
||||
gnocchi = mock.MagicMock()
|
||||
|
||||
@@ -56,13 +56,12 @@ class TestMonascaHelper(base.BaseTestCase):
|
||||
|
||||
helper = monasca_helper.MonascaHelper()
|
||||
result = helper.statistic_aggregation(
|
||||
resource_id=None,
|
||||
meter_name='cpu.percent',
|
||||
resource=mock.Mock(id='NODE_UUID'),
|
||||
resource_type='compute_node',
|
||||
meter_name='host_cpu_usage',
|
||||
period=7200,
|
||||
granularity=300,
|
||||
dimensions={'hostname': 'NODE_UUID'},
|
||||
aggregation='avg',
|
||||
group_by='*',
|
||||
aggregate='mean',
|
||||
)
|
||||
self.assertEqual(0.6, result)
|
||||
|
||||
@@ -81,55 +80,14 @@ class TestMonascaHelper(base.BaseTestCase):
|
||||
helper = monasca_helper.MonascaHelper()
|
||||
self.assertEqual('not available', helper.check_availability())
|
||||
|
||||
def test_monasca_statistic_list(self, mock_monasca):
|
||||
monasca = mock.MagicMock()
|
||||
expected_result = [{
|
||||
'columns': ['timestamp', 'value', 'value_meta'],
|
||||
'dimensions': {
|
||||
'hostname': 'rdev-indeedsrv001',
|
||||
'service': 'monasca'},
|
||||
'id': '0',
|
||||
'measurements': [
|
||||
['2016-07-29T12:54:06.000Z', 0.9, {}],
|
||||
['2016-07-29T12:54:36.000Z', 0.9, {}],
|
||||
['2016-07-29T12:55:06.000Z', 0.9, {}],
|
||||
['2016-07-29T12:55:36.000Z', 0.8, {}]],
|
||||
'name': 'cpu.percent'}]
|
||||
|
||||
monasca.metrics.list_measurements.return_value = expected_result
|
||||
mock_monasca.return_value = monasca
|
||||
helper = monasca_helper.MonascaHelper()
|
||||
val = helper.statistics_list(meter_name="cpu.percent", dimensions={})
|
||||
self.assertEqual(expected_result, val)
|
||||
|
||||
def test_monasca_statistic_list_query_retry(self, mock_monasca):
|
||||
monasca = mock.MagicMock()
|
||||
expected_result = [{
|
||||
'columns': ['timestamp', 'value', 'value_meta'],
|
||||
'dimensions': {
|
||||
'hostname': 'rdev-indeedsrv001',
|
||||
'service': 'monasca'},
|
||||
'id': '0',
|
||||
'measurements': [
|
||||
['2016-07-29T12:54:06.000Z', 0.9, {}],
|
||||
['2016-07-29T12:54:36.000Z', 0.9, {}],
|
||||
['2016-07-29T12:55:06.000Z', 0.9, {}],
|
||||
['2016-07-29T12:55:36.000Z', 0.8, {}]],
|
||||
'name': 'cpu.percent'}]
|
||||
|
||||
monasca.metrics.list_measurements.side_effect = [expected_result]
|
||||
mock_monasca.return_value = monasca
|
||||
helper = monasca_helper.MonascaHelper()
|
||||
val = helper.statistics_list(meter_name="cpu.percent", dimensions={})
|
||||
self.assertEqual(expected_result, val)
|
||||
|
||||
def test_get_host_cpu_usage(self, mock_monasca):
|
||||
node = "compute1_compute1"
|
||||
self.mock_aggregation.return_value = 0.6
|
||||
node = mock.Mock(id='compute1')
|
||||
cpu_usage = self.helper.get_host_cpu_usage(node, 600, 'mean')
|
||||
self.assertEqual(0.6, cpu_usage)
|
||||
|
||||
def test_get_instance_cpu_usage(self, mock_monasca):
|
||||
self.mock_aggregation.return_value = 0.6
|
||||
cpu_usage = self.helper.get_instance_cpu_usage('vm1', 600, 'mean')
|
||||
node = mock.Mock(id='vm1')
|
||||
cpu_usage = self.helper.get_instance_cpu_usage(node, 600, 'mean')
|
||||
self.assertEqual(0.6, cpu_usage)
|
||||
|
||||
@@ -28,64 +28,74 @@ class FakeCeilometerMetrics(object):
|
||||
def empty_one_metric(self, emptytype):
|
||||
self.emptytype = emptytype
|
||||
|
||||
def mock_get_statistics(self, resource_id=None, meter_name=None,
|
||||
period=None, granularity=None, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
def mock_get_statistics(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=None, aggregate='mean',
|
||||
granularity=None):
|
||||
result = 0
|
||||
if meter_name == "hardware.cpu.util":
|
||||
result = self.get_usage_node_cpu(resource_id)
|
||||
elif meter_name == "compute.node.cpu.percent":
|
||||
result = self.get_usage_node_cpu(resource_id)
|
||||
elif meter_name == "hardware.memory.used":
|
||||
result = self.get_usage_node_ram(resource_id)
|
||||
elif meter_name == "cpu_util":
|
||||
result = self.get_average_usage_instance_cpu(resource_id)
|
||||
elif meter_name == "memory.resident":
|
||||
result = self.get_average_usage_instance_memory(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.outlet_temperature":
|
||||
result = self.get_average_outlet_temperature(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.airflow":
|
||||
result = self.get_average_airflow(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.temperature":
|
||||
result = self.get_average_inlet_t(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.power":
|
||||
result = self.get_average_power(resource_id)
|
||||
if meter_name == 'host_cpu_usage':
|
||||
result = self.get_usage_compute_node_cpu(resource)
|
||||
elif meter_name == 'host_ram_usage':
|
||||
result = self.get_usage_compute_node_ram(resource)
|
||||
elif meter_name == 'host_outlet_temp':
|
||||
result = self.get_average_outlet_temp(resource)
|
||||
elif meter_name == 'host_inlet_temp':
|
||||
result = self.get_average_inlet_temp(resource)
|
||||
elif meter_name == 'host_airflow':
|
||||
result = self.get_average_airflow(resource)
|
||||
elif meter_name == 'host_power':
|
||||
result = self.get_average_power(resource)
|
||||
elif meter_name == 'instance_cpu_usage':
|
||||
result = self.get_average_usage_instance_cpu(resource)
|
||||
elif meter_name == 'instance_ram_usage':
|
||||
result = self.get_average_usage_instance_memory(resource)
|
||||
return result
|
||||
|
||||
def mock_get_statistics_wb(self, resource_id, meter_name, period,
|
||||
granularity, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
result = 0.0
|
||||
if meter_name == "cpu_util":
|
||||
result = self.get_average_usage_instance_cpu_wb(resource_id)
|
||||
elif meter_name == "memory.resident":
|
||||
result = self.get_average_usage_instance_memory_wb(resource_id)
|
||||
return result
|
||||
def mock_get_statistics_nn(self, resource=None, meter_name=None,
|
||||
period=None, aggregate='mean', granularity=300):
|
||||
"""Statistics for noisy neighbor strategy
|
||||
|
||||
Signature should match DataSourceBase.get_instance_l3_cache_usage
|
||||
"""
|
||||
|
||||
def mock_get_statistics_nn(self, resource_id, period,
|
||||
aggregation, granularity=300):
|
||||
result = 0.0
|
||||
if period == 100:
|
||||
result = self.get_average_l3_cache_current(resource_id)
|
||||
result = self.get_average_l3_cache_current(resource)
|
||||
if period == 200:
|
||||
result = self.get_average_l3_cache_previous(resource_id)
|
||||
result = self.get_average_l3_cache_previous(resource)
|
||||
return result
|
||||
|
||||
def mock_get_statistics_wb(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=None, aggregate='mean',
|
||||
granularity=None):
|
||||
"""Statistics for workload balance strategy"""
|
||||
|
||||
result = 0.0
|
||||
if meter_name == 'instance_cpu_usage':
|
||||
result = self.get_average_usage_instance_cpu_wb(resource)
|
||||
elif meter_name == 'instance_ram_usage':
|
||||
result = self.get_average_usage_instance_memory_wb(resource)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_average_l3_cache_current(uuid):
|
||||
def get_average_l3_cache_current(resource):
|
||||
"""The average l3 cache used by instance"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 35 * oslo_utils.units.Ki
|
||||
mock['cae81432-1631-4d4e-b29c-6f3acdcde906'] = 30 * oslo_utils.units.Ki
|
||||
mock['INSTANCE_3'] = 40 * oslo_utils.units.Ki
|
||||
mock['INSTANCE_4'] = 35 * oslo_utils.units.Ki
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 25 * oslo_utils.units.Ki
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_l3_cache_previous(uuid):
|
||||
def get_average_l3_cache_previous(resource):
|
||||
"""The average l3 cache used by instance"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 34.5 * (
|
||||
oslo_utils.units.Ki)
|
||||
@@ -93,13 +103,14 @@ class FakeCeilometerMetrics(object):
|
||||
oslo_utils.units.Ki)
|
||||
mock['INSTANCE_3'] = 60 * oslo_utils.units.Ki
|
||||
mock['INSTANCE_4'] = 22.5 * oslo_utils.units.Ki
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 25 * oslo_utils.units.Ki
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_outlet_temperature(uuid):
|
||||
def get_average_outlet_temp(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
mock['Node_0'] = 30
|
||||
# use a big value to make sure it exceeds threshold
|
||||
@@ -109,7 +120,9 @@ class FakeCeilometerMetrics(object):
|
||||
return float(mock[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_usage_node_ram(uuid):
|
||||
def get_usage_compute_node_ram(resource):
|
||||
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
# Ceilometer returns hardware.memory.used samples in KB.
|
||||
mock['Node_0'] = 7 * oslo_utils.units.Ki
|
||||
@@ -125,8 +138,10 @@ class FakeCeilometerMetrics(object):
|
||||
return float(mock[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_average_airflow(uuid):
|
||||
def get_average_airflow(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
mock['Node_0'] = 400
|
||||
# use a big value to make sure it exceeds threshold
|
||||
@@ -136,8 +151,10 @@ class FakeCeilometerMetrics(object):
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_inlet_t(uuid):
|
||||
def get_average_inlet_temp(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
mock['Node_0'] = 24
|
||||
mock['Node_1'] = 26
|
||||
@@ -146,8 +163,10 @@ class FakeCeilometerMetrics(object):
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_power(uuid):
|
||||
def get_average_power(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
mock['Node_0'] = 260
|
||||
mock['Node_1'] = 240
|
||||
@@ -156,64 +175,48 @@ class FakeCeilometerMetrics(object):
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_usage_node_cpu(*args, **kwargs):
|
||||
def get_usage_compute_node_cpu(*args, **kwargs):
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid:00
|
||||
:return:
|
||||
"""
|
||||
uuid = args[0]
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
resource = args[0]
|
||||
uuid = "%s_%s" % (resource.uuid, resource.hostname)
|
||||
|
||||
# Normalize
|
||||
mock = {}
|
||||
measurements = {}
|
||||
# node 0
|
||||
mock['Node_0_hostname_0'] = 7
|
||||
mock['Node_1_hostname_1'] = 7
|
||||
measurements['Node_0_hostname_0'] = 7
|
||||
measurements['Node_1_hostname_1'] = 7
|
||||
# node 1
|
||||
mock['Node_2_hostname_2'] = 80
|
||||
measurements['Node_2_hostname_2'] = 80
|
||||
# node 2
|
||||
mock['Node_3_hostname_3'] = 5
|
||||
mock['Node_4_hostname_4'] = 5
|
||||
mock['Node_5_hostname_5'] = 10
|
||||
measurements['Node_3_hostname_3'] = 5
|
||||
measurements['Node_4_hostname_4'] = 5
|
||||
measurements['Node_5_hostname_5'] = 10
|
||||
|
||||
# node 3
|
||||
mock['Node_6_hostname_6'] = 8
|
||||
measurements['Node_6_hostname_6'] = 8
|
||||
# This node doesn't send metrics
|
||||
mock['LOST_NODE_hostname_7'] = None
|
||||
mock['Node_19_hostname_19'] = 10
|
||||
measurements['LOST_NODE_hostname_7'] = None
|
||||
measurements['Node_19_hostname_19'] = 10
|
||||
# node 4
|
||||
mock['INSTANCE_7_hostname_7'] = 4
|
||||
measurements['INSTANCE_7_hostname_7'] = 4
|
||||
|
||||
mock['Node_0'] = 7
|
||||
mock['Node_1'] = 5
|
||||
mock['Node_2'] = 10
|
||||
mock['Node_3'] = 4
|
||||
mock['Node_4'] = 2
|
||||
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
mock[uuid] = 8
|
||||
|
||||
if mock[str(uuid)] is not None:
|
||||
return float(mock[str(uuid)])
|
||||
else:
|
||||
return mock[str(uuid)]
|
||||
result = measurements[uuid]
|
||||
return float(result) if result is not None else None
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_cpu_wb(uuid):
|
||||
def get_average_usage_instance_cpu_wb(resource):
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid:00
|
||||
:param resource:
|
||||
:return:
|
||||
"""
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
uuid = resource.uuid
|
||||
|
||||
# Normalize
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['INSTANCE_1'] = 80
|
||||
@@ -221,19 +224,20 @@ class FakeCeilometerMetrics(object):
|
||||
# node 1
|
||||
mock['INSTANCE_3'] = 20
|
||||
mock['INSTANCE_4'] = 10
|
||||
|
||||
return float(mock[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_memory_wb(uuid):
|
||||
def get_average_usage_instance_memory_wb(resource):
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['INSTANCE_1'] = 30
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 12
|
||||
# node 1
|
||||
mock['INSTANCE_3'] = 12
|
||||
mock['INSTANCE_4'] = 12
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
mock[uuid] = 12
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@@ -244,12 +248,10 @@ class FakeCeilometerMetrics(object):
|
||||
:param uuid:00
|
||||
:return:
|
||||
"""
|
||||
uuid = args[0]
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
resource = args[0]
|
||||
uuid = resource.uuid
|
||||
|
||||
# Normalize
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['INSTANCE_0'] = 7
|
||||
@@ -260,22 +262,22 @@ class FakeCeilometerMetrics(object):
|
||||
mock['INSTANCE_3'] = 5
|
||||
mock['INSTANCE_4'] = 5
|
||||
mock['INSTANCE_5'] = 10
|
||||
|
||||
# node 3
|
||||
mock['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
mock['INSTANCE_7'] = 4
|
||||
|
||||
mock['LOST_INSTANCE'] = None
|
||||
|
||||
# metrics might be missing in scenarios which do not do computations
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
mock[uuid] = 8
|
||||
mock[uuid] = 0
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_memory(uuid):
|
||||
def get_average_usage_instance_memory(resource):
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['INSTANCE_0'] = 2
|
||||
@@ -286,20 +288,17 @@ class FakeCeilometerMetrics(object):
|
||||
mock['INSTANCE_3'] = 8
|
||||
mock['INSTANCE_4'] = 5
|
||||
mock['INSTANCE_5'] = 16
|
||||
|
||||
# node 3
|
||||
mock['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
mock['INSTANCE_7'] = 4
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
mock[uuid] = 10
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_disk(uuid):
|
||||
def get_average_usage_instance_disk(resource):
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['INSTANCE_0'] = 2
|
||||
@@ -310,15 +309,9 @@ class FakeCeilometerMetrics(object):
|
||||
mock['INSTANCE_3'] = 10
|
||||
mock['INSTANCE_4'] = 15
|
||||
mock['INSTANCE_5'] = 20
|
||||
|
||||
# node 3
|
||||
mock['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
mock['INSTANCE_7'] = 4
|
||||
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
mock[uuid] = 4
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@@ -84,23 +84,24 @@ class FakeCeilometerMetrics(object):
|
||||
def __init__(self, model):
|
||||
self.model = model
|
||||
|
||||
def mock_get_statistics(self, resource_id=None, meter_name=None,
|
||||
period=300, granularity=300, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
if meter_name == "compute.node.cpu.percent":
|
||||
return self.get_node_cpu_util(resource_id, period,
|
||||
aggregation, granularity)
|
||||
elif meter_name == "cpu_util":
|
||||
return self.get_instance_cpu_util(resource_id, period,
|
||||
aggregation, granularity)
|
||||
elif meter_name == "memory.resident":
|
||||
return self.get_instance_ram_util(resource_id, period,
|
||||
aggregation, granularity)
|
||||
elif meter_name == "disk.root.size":
|
||||
return self.get_instance_disk_root_size(resource_id, period,
|
||||
aggregation, granularity)
|
||||
def mock_get_statistics(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=300, aggregate='mean',
|
||||
granularity=300):
|
||||
if meter_name == 'host_cpu_usage':
|
||||
return self.get_compute_node_cpu_util(
|
||||
resource, period, aggregate, granularity)
|
||||
elif meter_name == 'instance_cpu_usage':
|
||||
return self.get_instance_cpu_util(
|
||||
resource, period, aggregate, granularity)
|
||||
elif meter_name == 'instance_ram_usage':
|
||||
return self.get_instance_ram_util(
|
||||
resource, period, aggregate, granularity)
|
||||
elif meter_name == 'instance_root_disk_size':
|
||||
return self.get_instance_disk_root_size(
|
||||
resource, period, aggregate, granularity)
|
||||
|
||||
def get_node_cpu_util(self, r_id, period, aggregation, granularity):
|
||||
def get_compute_node_cpu_util(self, resource, period,
|
||||
aggregate, granularity):
|
||||
"""Calculates node utilization dynamicaly.
|
||||
|
||||
node CPU utilization should consider
|
||||
@@ -109,7 +110,7 @@ class FakeCeilometerMetrics(object):
|
||||
Returns relative node CPU utilization <0, 100>.
|
||||
:param r_id: resource id
|
||||
"""
|
||||
node_uuid = '%s_%s' % (r_id.split('_')[0], r_id.split('_')[1])
|
||||
node_uuid = '%s_%s' % (resource.uuid, resource.hostname)
|
||||
node = self.model.get_node_by_uuid(node_uuid)
|
||||
instances = self.model.get_node_instances(node)
|
||||
util_sum = 0.0
|
||||
@@ -122,7 +123,8 @@ class FakeCeilometerMetrics(object):
|
||||
return util_sum * 100.0
|
||||
|
||||
@staticmethod
|
||||
def get_instance_cpu_util(r_id, period, aggregation, granularity):
|
||||
def get_instance_cpu_util(resource, period, aggregate,
|
||||
granularity):
|
||||
instance_cpu_util = dict()
|
||||
instance_cpu_util['INSTANCE_0'] = 10
|
||||
instance_cpu_util['INSTANCE_1'] = 30
|
||||
@@ -134,10 +136,11 @@ class FakeCeilometerMetrics(object):
|
||||
instance_cpu_util['INSTANCE_7'] = 100
|
||||
instance_cpu_util['INSTANCE_8'] = 100
|
||||
instance_cpu_util['INSTANCE_9'] = 100
|
||||
return instance_cpu_util[str(r_id)]
|
||||
return instance_cpu_util[str(resource.uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_instance_ram_util(r_id, period, aggregation, granularity):
|
||||
def get_instance_ram_util(resource, period, aggregate,
|
||||
granularity):
|
||||
instance_ram_util = dict()
|
||||
instance_ram_util['INSTANCE_0'] = 1
|
||||
instance_ram_util['INSTANCE_1'] = 2
|
||||
@@ -149,10 +152,11 @@ class FakeCeilometerMetrics(object):
|
||||
instance_ram_util['INSTANCE_7'] = 2
|
||||
instance_ram_util['INSTANCE_8'] = 4
|
||||
instance_ram_util['INSTANCE_9'] = 8
|
||||
return instance_ram_util[str(r_id)]
|
||||
return instance_ram_util[str(resource.uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_instance_disk_root_size(r_id, period, aggregation, granularity):
|
||||
def get_instance_disk_root_size(resource, period, aggregate,
|
||||
granularity):
|
||||
instance_disk_util = dict()
|
||||
instance_disk_util['INSTANCE_0'] = 10
|
||||
instance_disk_util['INSTANCE_1'] = 15
|
||||
@@ -164,30 +168,31 @@ class FakeCeilometerMetrics(object):
|
||||
instance_disk_util['INSTANCE_7'] = 25
|
||||
instance_disk_util['INSTANCE_8'] = 25
|
||||
instance_disk_util['INSTANCE_9'] = 25
|
||||
return instance_disk_util[str(r_id)]
|
||||
return instance_disk_util[str(resource.uuid)]
|
||||
|
||||
|
||||
class FakeGnocchiMetrics(object):
|
||||
def __init__(self, model):
|
||||
self.model = model
|
||||
|
||||
def mock_get_statistics(self, resource_id=None, meter_name=None,
|
||||
period=300, granularity=300, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
if meter_name == "compute.node.cpu.percent":
|
||||
return self.get_node_cpu_util(resource_id, period,
|
||||
aggregation, granularity)
|
||||
elif meter_name == "cpu_util":
|
||||
return self.get_instance_cpu_util(resource_id, period,
|
||||
aggregation, granularity)
|
||||
elif meter_name == "memory.resident":
|
||||
return self.get_instance_ram_util(resource_id, period,
|
||||
aggregation, granularity)
|
||||
elif meter_name == "disk.root.size":
|
||||
return self.get_instance_disk_root_size(resource_id, period,
|
||||
aggregation, granularity)
|
||||
def mock_get_statistics(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=300, aggregate='mean',
|
||||
granularity=300):
|
||||
if meter_name == 'host_cpu_usage':
|
||||
return self.get_compute_node_cpu_util(
|
||||
resource, period, aggregate, granularity)
|
||||
elif meter_name == 'instance_cpu_usage':
|
||||
return self.get_instance_cpu_util(
|
||||
resource, period, aggregate, granularity)
|
||||
elif meter_name == 'instance_ram_usage':
|
||||
return self.get_instance_ram_util(
|
||||
resource, period, aggregate, granularity)
|
||||
elif meter_name == 'instance_root_disk_size':
|
||||
return self.get_instance_disk_root_size(
|
||||
resource, period, aggregate, granularity)
|
||||
|
||||
def get_node_cpu_util(self, r_id, period, aggregation, granularity):
|
||||
def get_compute_node_cpu_util(self, resource, period, aggregate,
|
||||
granularity):
|
||||
"""Calculates node utilization dynamicaly.
|
||||
|
||||
node CPU utilization should consider
|
||||
@@ -197,7 +202,7 @@ class FakeGnocchiMetrics(object):
|
||||
|
||||
:param r_id: resource id
|
||||
"""
|
||||
node_uuid = '%s_%s' % (r_id.split('_')[0], r_id.split('_')[1])
|
||||
node_uuid = "%s_%s" % (resource.uuid, resource.hostname)
|
||||
node = self.model.get_node_by_uuid(node_uuid)
|
||||
instances = self.model.get_node_instances(node)
|
||||
util_sum = 0.0
|
||||
@@ -210,7 +215,8 @@ class FakeGnocchiMetrics(object):
|
||||
return util_sum * 100.0
|
||||
|
||||
@staticmethod
|
||||
def get_instance_cpu_util(r_id, period, aggregation, granularity):
|
||||
def get_instance_cpu_util(resource, period, aggregate,
|
||||
granularity):
|
||||
instance_cpu_util = dict()
|
||||
instance_cpu_util['INSTANCE_0'] = 10
|
||||
instance_cpu_util['INSTANCE_1'] = 30
|
||||
@@ -222,10 +228,11 @@ class FakeGnocchiMetrics(object):
|
||||
instance_cpu_util['INSTANCE_7'] = 100
|
||||
instance_cpu_util['INSTANCE_8'] = 100
|
||||
instance_cpu_util['INSTANCE_9'] = 100
|
||||
return instance_cpu_util[str(r_id)]
|
||||
return instance_cpu_util[str(resource.uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_instance_ram_util(r_id, period, aggregation, granularity):
|
||||
def get_instance_ram_util(resource, period, aggregate,
|
||||
granularity):
|
||||
instance_ram_util = dict()
|
||||
instance_ram_util['INSTANCE_0'] = 1
|
||||
instance_ram_util['INSTANCE_1'] = 2
|
||||
@@ -237,10 +244,11 @@ class FakeGnocchiMetrics(object):
|
||||
instance_ram_util['INSTANCE_7'] = 2
|
||||
instance_ram_util['INSTANCE_8'] = 4
|
||||
instance_ram_util['INSTANCE_9'] = 8
|
||||
return instance_ram_util[str(r_id)]
|
||||
return instance_ram_util[str(resource.uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_instance_disk_root_size(r_id, period, aggregation, granularity):
|
||||
def get_instance_disk_root_size(resource, period, aggregate,
|
||||
granularity):
|
||||
instance_disk_util = dict()
|
||||
instance_disk_util['INSTANCE_0'] = 10
|
||||
instance_disk_util['INSTANCE_1'] = 15
|
||||
@@ -252,4 +260,4 @@ class FakeGnocchiMetrics(object):
|
||||
instance_disk_util['INSTANCE_7'] = 25
|
||||
instance_disk_util['INSTANCE_8'] = 25
|
||||
instance_disk_util['INSTANCE_9'] = 25
|
||||
return instance_disk_util[str(r_id)]
|
||||
return instance_disk_util[str(resource.uuid)]
|
||||
|
||||
@@ -23,54 +23,74 @@ class FakeGnocchiMetrics(object):
|
||||
def empty_one_metric(self, emptytype):
|
||||
self.emptytype = emptytype
|
||||
|
||||
def mock_get_statistics(self, resource_id=None, meter_name=None,
|
||||
period=None, granularity=None, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
def mock_get_statistics(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=None, aggregate='mean',
|
||||
granularity=None):
|
||||
result = 0
|
||||
if meter_name == "hardware.cpu.util":
|
||||
result = self.get_usage_node_cpu(resource_id)
|
||||
elif meter_name == "compute.node.cpu.percent":
|
||||
result = self.get_usage_node_cpu(resource_id)
|
||||
elif meter_name == "hardware.memory.used":
|
||||
result = self.get_usage_node_ram(resource_id)
|
||||
elif meter_name == "cpu_util":
|
||||
result = self.get_average_usage_instance_cpu(resource_id)
|
||||
elif meter_name == "memory.resident":
|
||||
result = self.get_average_usage_instance_memory(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.outlet_temperature":
|
||||
result = self.get_average_outlet_temperature(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.airflow":
|
||||
result = self.get_average_airflow(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.temperature":
|
||||
result = self.get_average_inlet_t(resource_id)
|
||||
elif meter_name == "hardware.ipmi.node.power":
|
||||
result = self.get_average_power(resource_id)
|
||||
if meter_name == 'host_cpu_usage':
|
||||
result = self.get_usage_compute_node_cpu(resource)
|
||||
elif meter_name == 'host_ram_usage':
|
||||
result = self.get_usage_compute_node_ram(resource)
|
||||
elif meter_name == 'host_outlet_temp':
|
||||
result = self.get_average_outlet_temperature(resource)
|
||||
elif meter_name == 'host_inlet_temp':
|
||||
result = self.get_average_inlet_temp(resource)
|
||||
elif meter_name == 'host_airflow':
|
||||
result = self.get_average_airflow(resource)
|
||||
elif meter_name == 'host_power':
|
||||
result = self.get_average_power(resource)
|
||||
elif meter_name == 'instance_cpu_usage':
|
||||
result = self.get_average_usage_instance_cpu(resource)
|
||||
elif meter_name == 'instance_ram_usage':
|
||||
result = self.get_average_usage_instance_memory(resource)
|
||||
return result
|
||||
|
||||
def mock_get_statistics_nn(self, resource_id, period,
|
||||
aggregation, granularity=300):
|
||||
def mock_get_statistics_nn(self, resource=None, meter_name=None,
|
||||
period=None, aggregate='mean', granularity=300):
|
||||
"""Statistics for noisy neighbor strategy
|
||||
|
||||
Signature should match DataSourceBase.get_instance_l3_cache_usage
|
||||
"""
|
||||
|
||||
result = 0.0
|
||||
if period == 100:
|
||||
result = self.get_average_l3_cache_current(resource_id)
|
||||
result = self.get_average_l3_cache_current(resource)
|
||||
if period == 200:
|
||||
result = self.get_average_l3_cache_previous(resource_id)
|
||||
result = self.get_average_l3_cache_previous(resource)
|
||||
return result
|
||||
|
||||
def mock_get_statistics_wb(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=None, aggregate='mean',
|
||||
granularity=300):
|
||||
"""Statistics for workload balance strategy"""
|
||||
|
||||
result = 0.0
|
||||
if meter_name == 'instance_cpu_usage':
|
||||
result = self.get_average_usage_instance_cpu_wb(resource)
|
||||
elif meter_name == 'instance_ram_usage':
|
||||
result = self.get_average_usage_instance_memory_wb(resource)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_average_l3_cache_current(uuid):
|
||||
def get_average_l3_cache_current(resource):
|
||||
"""The average l3 cache used by instance"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 35 * oslo_utils.units.Ki
|
||||
mock['cae81432-1631-4d4e-b29c-6f3acdcde906'] = 30 * oslo_utils.units.Ki
|
||||
mock['INSTANCE_3'] = 40 * oslo_utils.units.Ki
|
||||
mock['INSTANCE_4'] = 35 * oslo_utils.units.Ki
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 25 * oslo_utils.units.Ki
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_l3_cache_previous(uuid):
|
||||
def get_average_l3_cache_previous(resource):
|
||||
"""The average l3 cache used by instance"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 34.5 * (
|
||||
oslo_utils.units.Ki)
|
||||
@@ -78,33 +98,26 @@ class FakeGnocchiMetrics(object):
|
||||
oslo_utils.units.Ki)
|
||||
mock['INSTANCE_3'] = 60 * oslo_utils.units.Ki
|
||||
mock['INSTANCE_4'] = 22.5 * oslo_utils.units.Ki
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 25 * oslo_utils.units.Ki
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
def mock_get_statistics_wb(self, resource_id, meter_name, period,
|
||||
granularity, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
result = 0.0
|
||||
if meter_name == "cpu_util":
|
||||
result = self.get_average_usage_instance_cpu_wb(resource_id)
|
||||
elif meter_name == "memory.resident":
|
||||
result = self.get_average_usage_instance_memory_wb(resource_id)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_average_outlet_temperature(uuid):
|
||||
def get_average_outlet_temperature(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['Node_0'] = 30
|
||||
# use a big value to make sure it exceeds threshold
|
||||
mock['Node_1'] = 100
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 100
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_usage_node_ram(uuid):
|
||||
def get_usage_compute_node_ram(resource):
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
# Gnocchi returns hardware.memory.used samples in KB.
|
||||
mock['Node_0'] = 7 * oslo_utils.units.Ki
|
||||
@@ -113,83 +126,81 @@ class FakeGnocchiMetrics(object):
|
||||
mock['Node_3'] = 8 * oslo_utils.units.Ki
|
||||
mock['Node_4'] = 4 * oslo_utils.units.Ki
|
||||
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 8
|
||||
|
||||
return float(mock[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_average_airflow(uuid):
|
||||
def get_average_airflow(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['Node_0'] = 400
|
||||
# use a big value to make sure it exceeds threshold
|
||||
mock['Node_1'] = 100
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 200
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_inlet_t(uuid):
|
||||
def get_average_inlet_temp(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['Node_0'] = 24
|
||||
mock['Node_1'] = 26
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 28
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_power(uuid):
|
||||
def get_average_power(resource):
|
||||
"""The average outlet temperature for host"""
|
||||
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
mock['Node_0'] = 260
|
||||
mock['Node_1'] = 240
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 200
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_usage_node_cpu(*args, **kwargs):
|
||||
def get_usage_compute_node_cpu(*args, **kwargs):
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid: instance UUID
|
||||
:return: float value
|
||||
"""
|
||||
uuid = args[0]
|
||||
|
||||
resource = args[0]
|
||||
uuid = "%s_%s" % (resource.uuid, resource.hostname)
|
||||
|
||||
# Normalize
|
||||
mock = {}
|
||||
measurements = {}
|
||||
# node 0
|
||||
mock['Node_0_hostname_0'] = 7
|
||||
mock['Node_1_hostname_1'] = 7
|
||||
measurements['Node_0_hostname_0'] = 7
|
||||
measurements['Node_1_hostname_1'] = 7
|
||||
# node 1
|
||||
mock['Node_2_hostname_2'] = 80
|
||||
measurements['Node_2_hostname_2'] = 80
|
||||
# node 2
|
||||
mock['Node_3_hostname_3'] = 5
|
||||
mock['Node_4_hostname_4'] = 5
|
||||
mock['Node_5_hostname_5'] = 10
|
||||
|
||||
measurements['Node_3_hostname_3'] = 5
|
||||
measurements['Node_4_hostname_4'] = 5
|
||||
measurements['Node_5_hostname_5'] = 10
|
||||
# node 3
|
||||
mock['Node_6_hostname_6'] = 8
|
||||
measurements['Node_6_hostname_6'] = 8
|
||||
# This node doesn't send metrics
|
||||
mock['LOST_NODE_hostname_7'] = None
|
||||
mock['Node_19_hostname_19'] = 10
|
||||
measurements['LOST_NODE_hostname_7'] = None
|
||||
measurements['Node_19_hostname_19'] = 10
|
||||
# node 4
|
||||
mock['INSTANCE_7_hostname_7'] = 4
|
||||
measurements['INSTANCE_7_hostname_7'] = 4
|
||||
|
||||
mock['Node_0'] = 7
|
||||
mock['Node_1'] = 5
|
||||
mock['Node_2'] = 10
|
||||
mock['Node_3'] = 4
|
||||
mock['Node_4'] = 2
|
||||
# metrics might be missing in scenarios which do not do computations
|
||||
if uuid not in measurements.keys():
|
||||
measurements[uuid] = 0
|
||||
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 8
|
||||
|
||||
if mock[str(uuid)] is not None:
|
||||
return float(mock[str(uuid)])
|
||||
else:
|
||||
return mock[str(uuid)]
|
||||
result = measurements[uuid]
|
||||
return float(result) if result is not None else None
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_cpu(*args, **kwargs):
|
||||
@@ -198,8 +209,10 @@ class FakeGnocchiMetrics(object):
|
||||
:param uuid: instance UUID
|
||||
:return: int value
|
||||
"""
|
||||
uuid = args[0]
|
||||
# Normalize
|
||||
|
||||
resource = args[0]
|
||||
uuid = resource.uuid
|
||||
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['INSTANCE_0'] = 7
|
||||
@@ -210,22 +223,24 @@ class FakeGnocchiMetrics(object):
|
||||
mock['INSTANCE_3'] = 5
|
||||
mock['INSTANCE_4'] = 5
|
||||
mock['INSTANCE_5'] = 10
|
||||
|
||||
# node 3
|
||||
mock['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
mock['INSTANCE_7'] = 4
|
||||
|
||||
mock['LOST_INSTANCE'] = None
|
||||
|
||||
# metrics might be missing in scenarios which do not do computations
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 8
|
||||
mock[uuid] = 0
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_memory(uuid):
|
||||
def get_average_usage_instance_memory(resource):
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
|
||||
# node 0
|
||||
mock['INSTANCE_0'] = 2
|
||||
mock['INSTANCE_1'] = 5
|
||||
@@ -235,20 +250,18 @@ class FakeGnocchiMetrics(object):
|
||||
mock['INSTANCE_3'] = 8
|
||||
mock['INSTANCE_4'] = 5
|
||||
mock['INSTANCE_5'] = 16
|
||||
|
||||
# node 3
|
||||
mock['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
mock['INSTANCE_7'] = 4
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 10
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_disk(uuid):
|
||||
def get_average_usage_instance_disk(resource):
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
|
||||
# node 0
|
||||
mock['INSTANCE_0'] = 2
|
||||
mock['INSTANCE_1'] = 2
|
||||
@@ -258,49 +271,42 @@ class FakeGnocchiMetrics(object):
|
||||
mock['INSTANCE_3'] = 10
|
||||
mock['INSTANCE_4'] = 15
|
||||
mock['INSTANCE_5'] = 20
|
||||
|
||||
# node 3
|
||||
mock['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
mock['INSTANCE_7'] = 4
|
||||
|
||||
if uuid not in mock.keys():
|
||||
mock[uuid] = 4
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_cpu_wb(uuid):
|
||||
def get_average_usage_instance_cpu_wb(resource):
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid: instance UUID
|
||||
:return: float value
|
||||
"""
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
|
||||
# Normalize
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
|
||||
# node 0
|
||||
mock['INSTANCE_1'] = 80
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 50
|
||||
# node 1
|
||||
mock['INSTANCE_3'] = 20
|
||||
mock['INSTANCE_4'] = 10
|
||||
|
||||
return float(mock[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_memory_wb(uuid):
|
||||
def get_average_usage_instance_memory_wb(resource):
|
||||
uuid = resource.uuid
|
||||
mock = {}
|
||||
|
||||
# node 0
|
||||
mock['INSTANCE_1'] = 30
|
||||
mock['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 12
|
||||
# node 1
|
||||
mock['INSTANCE_3'] = 12
|
||||
mock['INSTANCE_4'] = 12
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
mock[uuid] = 12
|
||||
|
||||
return mock[str(uuid)]
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import oslo_utils
|
||||
|
||||
|
||||
class FakeMonascaMetrics(object):
|
||||
def __init__(self):
|
||||
@@ -26,117 +24,37 @@ class FakeMonascaMetrics(object):
|
||||
def empty_one_metric(self, emptytype):
|
||||
self.emptytype = emptytype
|
||||
|
||||
def mock_get_statistics(self, resource_id=None, meter_name=None,
|
||||
period=None, granularity=None, dimensions=None,
|
||||
aggregation='avg', group_by='*'):
|
||||
resource_id = dimensions.get(
|
||||
"resource_id") or dimensions.get("hostname")
|
||||
def mock_get_statistics(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=None, aggregate='mean',
|
||||
granularity=None):
|
||||
result = 0.0
|
||||
if meter_name == "cpu.percent":
|
||||
result = self.get_usage_node_cpu(resource_id)
|
||||
elif meter_name == "vm.cpu.utilization_perc":
|
||||
result = self.get_average_usage_instance_cpu(resource_id)
|
||||
# elif meter_name == "hardware.memory.used":
|
||||
# result = self.get_usage_node_ram(resource_id)
|
||||
# elif meter_name == "memory.resident":
|
||||
# result = self.get_average_usage_instance_memory(resource_id)
|
||||
# elif meter_name == "hardware.ipmi.node.outlet_temperature":
|
||||
# result = self.get_average_outlet_temperature(resource_id)
|
||||
# elif meter_name == "hardware.ipmi.node.airflow":
|
||||
# result = self.get_average_airflow(resource_id)
|
||||
# elif meter_name == "hardware.ipmi.node.temperature":
|
||||
# result = self.get_average_inlet_t(resource_id)
|
||||
# elif meter_name == "hardware.ipmi.node.power":
|
||||
# result = self.get_average_power(resource_id)
|
||||
if meter_name == 'host_cpu_usage':
|
||||
result = self.get_usage_compute_node_cpu(resource)
|
||||
elif meter_name == 'instance_cpu_usage':
|
||||
result = self.get_average_usage_instance_cpu(resource)
|
||||
return result
|
||||
|
||||
def mock_get_statistics_wb(self, meter_name, dimensions, period,
|
||||
aggregate='avg'):
|
||||
resource_id = dimensions.get(
|
||||
"resource_id") or dimensions.get("hostname")
|
||||
def mock_get_statistics_wb(self, resource=None, resource_type=None,
|
||||
meter_name=None, period=None, aggregate='mean',
|
||||
granularity=None):
|
||||
"""Statistics for workload balance strategy"""
|
||||
|
||||
result = 0.0
|
||||
if meter_name == "vm.cpu.utilization_perc":
|
||||
result = self.get_average_usage_instance_cpu_wb(resource_id)
|
||||
if meter_name == 'instance_cpu_usage':
|
||||
result = self.get_average_usage_instance_cpu_wb(resource)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_average_outlet_temperature(uuid):
|
||||
"""The average outlet temperature for host"""
|
||||
measurements = {}
|
||||
measurements['Node_0'] = 30
|
||||
# use a big value to make sure it exceeds threshold
|
||||
measurements['Node_1'] = 100
|
||||
if uuid not in measurements.keys():
|
||||
measurements[uuid] = 100
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@staticmethod
|
||||
def get_usage_node_ram(uuid):
|
||||
measurements = {}
|
||||
# Monasca returns hardware.memory.used samples in KB.
|
||||
measurements['Node_0'] = 7 * oslo_utils.units.Ki
|
||||
measurements['Node_1'] = 5 * oslo_utils.units.Ki
|
||||
measurements['Node_2'] = 29 * oslo_utils.units.Ki
|
||||
measurements['Node_3'] = 8 * oslo_utils.units.Ki
|
||||
measurements['Node_4'] = 4 * oslo_utils.units.Ki
|
||||
|
||||
if uuid not in measurements.keys():
|
||||
# measurements[uuid] = random.randint(1, 4)
|
||||
measurements[uuid] = 8
|
||||
|
||||
return float(measurements[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_average_airflow(uuid):
|
||||
"""The average outlet temperature for host"""
|
||||
measurements = {}
|
||||
measurements['Node_0'] = 400
|
||||
# use a big value to make sure it exceeds threshold
|
||||
measurements['Node_1'] = 100
|
||||
if uuid not in measurements.keys():
|
||||
measurements[uuid] = 200
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@staticmethod
|
||||
def get_average_inlet_t(uuid):
|
||||
"""The average outlet temperature for host"""
|
||||
measurements = {}
|
||||
measurements['Node_0'] = 24
|
||||
measurements['Node_1'] = 26
|
||||
if uuid not in measurements.keys():
|
||||
measurements[uuid] = 28
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@staticmethod
|
||||
def get_average_power(uuid):
|
||||
"""The average outlet temperature for host"""
|
||||
measurements = {}
|
||||
measurements['Node_0'] = 260
|
||||
measurements['Node_1'] = 240
|
||||
if uuid not in measurements.keys():
|
||||
measurements[uuid] = 200
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@staticmethod
|
||||
def get_usage_node_cpu(*args, **kwargs):
|
||||
uuid = args[0]
|
||||
if type(uuid) is dict:
|
||||
uuid = uuid.get("resource_id") or uuid.get("hostname")
|
||||
uuid = uuid.rsplit('_', 2)[0]
|
||||
def get_usage_compute_node_cpu(*args, **kwargs):
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid:00
|
||||
:return:
|
||||
"""
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
resource = args[0]
|
||||
uuid = resource.uuid
|
||||
|
||||
# Normalize
|
||||
measurements = {}
|
||||
# node 0
|
||||
measurements['Node_0'] = 7
|
||||
@@ -147,7 +65,6 @@ class FakeMonascaMetrics(object):
|
||||
measurements['Node_3'] = 5
|
||||
measurements['Node_4'] = 5
|
||||
measurements['Node_5'] = 10
|
||||
|
||||
# node 3
|
||||
measurements['Node_6'] = 8
|
||||
measurements['Node_19'] = 10
|
||||
@@ -168,45 +85,18 @@ class FakeMonascaMetrics(object):
|
||||
value = float(sum(values)) / len(values)
|
||||
cpu_usage = value
|
||||
return cpu_usage
|
||||
# return float(measurements[str(uuid)])
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_cpu_wb(uuid):
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid:00
|
||||
:return:
|
||||
"""
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
|
||||
# Normalize
|
||||
measurements = {}
|
||||
# node 0
|
||||
measurements['INSTANCE_1'] = 80
|
||||
measurements['73b09e16-35b7-4922-804e-e8f5d9b740fc'] = 50
|
||||
# node 1
|
||||
measurements['INSTANCE_3'] = 20
|
||||
measurements['INSTANCE_4'] = 10
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_cpu(*args, **kwargs):
|
||||
uuid = args[0]
|
||||
if type(uuid) is dict:
|
||||
uuid = uuid.get("resource_id") or uuid.get("hostname")
|
||||
"""The last VM CPU usage values to average
|
||||
|
||||
:param uuid:00
|
||||
:return:
|
||||
"""
|
||||
# query influxdb stream
|
||||
|
||||
# compute in stream
|
||||
resource = args[0]
|
||||
uuid = resource.uuid
|
||||
|
||||
# Normalize
|
||||
measurements = {}
|
||||
# node 0
|
||||
measurements['INSTANCE_0'] = 7
|
||||
@@ -217,12 +107,11 @@ class FakeMonascaMetrics(object):
|
||||
measurements['INSTANCE_3'] = 5
|
||||
measurements['INSTANCE_4'] = 5
|
||||
measurements['INSTANCE_5'] = 10
|
||||
|
||||
# node 3
|
||||
measurements['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
measurements['INSTANCE_7'] = 4
|
||||
|
||||
if uuid not in measurements.keys():
|
||||
# measurements[uuid] = random.randint(1, 4)
|
||||
measurements[uuid] = 8
|
||||
@@ -237,54 +126,3 @@ class FakeMonascaMetrics(object):
|
||||
value = float(sum(values)) / len(values)
|
||||
cpu_usage = value
|
||||
return cpu_usage
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_memory(uuid):
|
||||
measurements = {}
|
||||
# node 0
|
||||
measurements['INSTANCE_0'] = 2
|
||||
measurements['INSTANCE_1'] = 5
|
||||
# node 1
|
||||
measurements['INSTANCE_2'] = 5
|
||||
# node 2
|
||||
measurements['INSTANCE_3'] = 8
|
||||
measurements['INSTANCE_4'] = 5
|
||||
measurements['INSTANCE_5'] = 16
|
||||
|
||||
# node 3
|
||||
measurements['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
measurements['INSTANCE_7'] = 4
|
||||
if uuid not in measurements.keys():
|
||||
# measurements[uuid] = random.randint(1, 4)
|
||||
measurements[uuid] = 10
|
||||
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@staticmethod
|
||||
def get_average_usage_instance_disk(uuid):
|
||||
measurements = {}
|
||||
# node 0
|
||||
measurements['INSTANCE_0'] = 2
|
||||
measurements['INSTANCE_1'] = 2
|
||||
# node 1
|
||||
measurements['INSTANCE_2'] = 2
|
||||
# node 2
|
||||
measurements['INSTANCE_3'] = 10
|
||||
measurements['INSTANCE_4'] = 15
|
||||
measurements['INSTANCE_5'] = 20
|
||||
|
||||
# node 3
|
||||
measurements['INSTANCE_6'] = 8
|
||||
|
||||
# node 4
|
||||
measurements['INSTANCE_7'] = 4
|
||||
|
||||
if uuid not in measurements.keys():
|
||||
# measurements[uuid] = random.randint(1, 4)
|
||||
measurements[uuid] = 4
|
||||
|
||||
return [{'columns': ['avg'],
|
||||
'statistics': [[float(measurements[str(uuid)])]]}]
|
||||
|
||||
@@ -62,7 +62,7 @@ class TestBasicConsolidation(TestBaseStrategy):
|
||||
self.addCleanup(p_datasource.stop)
|
||||
|
||||
self.m_datasource.return_value = mock.Mock(
|
||||
get_host_cpu_usage=self.fake_metrics.get_usage_node_cpu,
|
||||
get_host_cpu_usage=self.fake_metrics.get_usage_compute_node_cpu,
|
||||
get_instance_cpu_usage=self.fake_metrics.
|
||||
get_average_usage_instance_cpu
|
||||
)
|
||||
@@ -75,7 +75,7 @@ class TestBasicConsolidation(TestBaseStrategy):
|
||||
size_cluster_assert = 5
|
||||
self.assertEqual(size_cluster_assert, size_cluster)
|
||||
|
||||
def test_basic_consolidation_score_node(self):
|
||||
def test_basic_consolidation_score_comute_node(self):
|
||||
model = self.fake_c_cluster.generate_scenario_1()
|
||||
self.m_c_model.return_value = model
|
||||
node_1_score = 0.023333333333333317
|
||||
@@ -96,7 +96,6 @@ class TestBasicConsolidation(TestBaseStrategy):
|
||||
self.assertEqual(
|
||||
instance_0_score,
|
||||
self.strategy.calculate_score_instance(instance_0))
|
||||
|
||||
instance_1 = model.get_instance_by_uuid("INSTANCE_1")
|
||||
instance_1_score = 0.023333333333333317
|
||||
self.assertEqual(
|
||||
@@ -236,69 +235,3 @@ class TestBasicConsolidation(TestBaseStrategy):
|
||||
loaded_action = loader.load(action['action_type'])
|
||||
loaded_action.input_parameters = action['input_parameters']
|
||||
loaded_action.validate_parameters()
|
||||
|
||||
"""def test_periods(self):
|
||||
model = self.fake_c_cluster.generate_scenario_1()
|
||||
self.m_c_model.return_value = model
|
||||
node_1 = model.get_node_by_uuid("Node_1")
|
||||
p_ceilometer = mock.patch.object(
|
||||
strategies.BasicConsolidation, "ceilometer")
|
||||
m_ceilometer = p_ceilometer.start()
|
||||
self.addCleanup(p_ceilometer.stop)
|
||||
p_monasca = mock.patch.object(strategies.BasicConsolidation, "monasca")
|
||||
m_monasca = p_monasca.start()
|
||||
self.addCleanup(p_monasca.stop)
|
||||
p_gnocchi = mock.patch.object(strategies.BasicConsolidation, "gnocchi")
|
||||
m_gnocchi = p_gnocchi.start()
|
||||
self.addCleanup(p_gnocchi.stop)
|
||||
datetime_patcher = mock.patch.object(
|
||||
datetime, 'datetime',
|
||||
mock.Mock(wraps=datetime.datetime)
|
||||
)
|
||||
mocked_datetime = datetime_patcher.start()
|
||||
mocked_datetime.utcnow.return_value = datetime.datetime(
|
||||
2017, 3, 19, 18, 53, 11, 657417)
|
||||
self.addCleanup(datetime_patcher.stop)
|
||||
m_monasca.return_value = mock.Mock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
m_ceilometer.return_value = mock.Mock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
m_gnocchi.return_value = mock.Mock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
self.strategy.calculate_score_node(node_1)
|
||||
resource_id = "%s_%s" % (node_1.uuid, node_1.hostname)
|
||||
if self.strategy.config.datasource == "ceilometer":
|
||||
m_ceilometer.statistic_aggregation.assert_called_with(
|
||||
aggregate='avg', meter_name='compute.node.cpu.percent',
|
||||
period=7200, resource_id=resource_id)
|
||||
elif self.strategy.config.datasource == "monasca":
|
||||
m_monasca.statistic_aggregation.assert_called_with(
|
||||
aggregate='avg', meter_name='cpu.percent',
|
||||
period=7200, dimensions={'hostname': 'Node_1'})
|
||||
elif self.strategy.config.datasource == "gnocchi":
|
||||
stop_time = datetime.datetime.utcnow()
|
||||
start_time = stop_time - datetime.timedelta(
|
||||
seconds=int('7200'))
|
||||
m_gnocchi.statistic_aggregation.assert_called_with(
|
||||
resource_id=resource_id, metric='compute.node.cpu.percent',
|
||||
granularity=300, start_time=start_time, stop_time=stop_time,
|
||||
aggregation='mean')
|
||||
|
||||
self.strategy.input_parameters.update({"period": 600})
|
||||
self.strategy.calculate_score_node(node_1)
|
||||
if self.strategy.config.datasource == "ceilometer":
|
||||
m_ceilometer.statistic_aggregation.assert_called_with(
|
||||
aggregate='avg', meter_name='compute.node.cpu.percent',
|
||||
period=600, resource_id=resource_id)
|
||||
elif self.strategy.config.datasource == "monasca":
|
||||
m_monasca.statistic_aggregation.assert_called_with(
|
||||
aggregate='avg', meter_name='cpu.percent',
|
||||
period=600, dimensions={'hostname': 'Node_1'})
|
||||
elif self.strategy.config.datasource == "gnocchi":
|
||||
stop_time = datetime.datetime.utcnow()
|
||||
start_time = stop_time - datetime.timedelta(
|
||||
seconds=int('600'))
|
||||
m_gnocchi.statistic_aggregation.assert_called_with(
|
||||
resource_id=resource_id, metric='compute.node.cpu.percent',
|
||||
granularity=300, start_time=start_time, stop_time=stop_time,
|
||||
aggregation='mean')"""
|
||||
|
||||
@@ -73,8 +73,8 @@ class TestOutletTempControl(TestBaseStrategy):
|
||||
model = self.fake_c_cluster.generate_scenario_3_with_2_nodes()
|
||||
self.m_c_model.return_value = model
|
||||
n1, n2 = self.strategy.group_hosts_by_outlet_temp()
|
||||
self.assertEqual('Node_1', n1[0]['node'].uuid)
|
||||
self.assertEqual('Node_0', n2[0]['node'].uuid)
|
||||
self.assertEqual('Node_1', n1[0]['compute_node'].uuid)
|
||||
self.assertEqual('Node_0', n2[0]['compute_node'].uuid)
|
||||
|
||||
def test_choose_instance_to_migrate(self):
|
||||
model = self.fake_c_cluster.generate_scenario_3_with_2_nodes()
|
||||
@@ -92,7 +92,7 @@ class TestOutletTempControl(TestBaseStrategy):
|
||||
instance_to_mig = self.strategy.choose_instance_to_migrate(n1)
|
||||
dest_hosts = self.strategy.filter_dest_servers(n2, instance_to_mig[1])
|
||||
self.assertEqual(1, len(dest_hosts))
|
||||
self.assertEqual('Node_0', dest_hosts[0]['node'].uuid)
|
||||
self.assertEqual('Node_0', dest_hosts[0]['compute_node'].uuid)
|
||||
|
||||
def test_execute_no_workload(self):
|
||||
model = self.fake_c_cluster.\
|
||||
|
||||
@@ -55,13 +55,13 @@ class TestWorkloadBalance(TestBaseStrategy):
|
||||
self.strategy = strategies.WorkloadBalance(
|
||||
config=mock.Mock(datasource=self.datasource))
|
||||
self.strategy.input_parameters = utils.Struct()
|
||||
self.strategy.input_parameters.update({'metrics': 'cpu_util',
|
||||
self.strategy.input_parameters.update({'metrics': 'instance_cpu_usage',
|
||||
'threshold': 25.0,
|
||||
'period': 300,
|
||||
'granularity': 300})
|
||||
self.strategy.threshold = 25.0
|
||||
self.strategy._period = 300
|
||||
self.strategy._meter = "cpu_util"
|
||||
self.strategy._meter = 'instance_cpu_usage'
|
||||
self.strategy._granularity = 300
|
||||
|
||||
def test_calc_used_resource(self):
|
||||
@@ -78,18 +78,18 @@ class TestWorkloadBalance(TestBaseStrategy):
|
||||
self.m_c_model.return_value = model
|
||||
self.strategy.threshold = 30
|
||||
n1, n2, avg, w_map = self.strategy.group_hosts_by_cpu_or_ram_util()
|
||||
self.assertEqual(n1[0]['node'].uuid, 'Node_0')
|
||||
self.assertEqual(n2[0]['node'].uuid, 'Node_1')
|
||||
self.assertEqual(n1[0]['compute_node'].uuid, 'Node_0')
|
||||
self.assertEqual(n2[0]['compute_node'].uuid, 'Node_1')
|
||||
self.assertEqual(avg, 8.0)
|
||||
|
||||
def test_group_hosts_by_ram_util(self):
|
||||
model = self.fake_c_cluster.generate_scenario_6_with_2_nodes()
|
||||
self.m_c_model.return_value = model
|
||||
self.strategy._meter = "memory.resident"
|
||||
self.strategy._meter = 'instance_ram_usage'
|
||||
self.strategy.threshold = 30
|
||||
n1, n2, avg, w_map = self.strategy.group_hosts_by_cpu_or_ram_util()
|
||||
self.assertEqual(n1[0]['node'].uuid, 'Node_0')
|
||||
self.assertEqual(n2[0]['node'].uuid, 'Node_1')
|
||||
self.assertEqual(n1[0]['compute_node'].uuid, 'Node_0')
|
||||
self.assertEqual(n2[0]['compute_node'].uuid, 'Node_1')
|
||||
self.assertEqual(avg, 33.0)
|
||||
|
||||
def test_choose_instance_to_migrate(self):
|
||||
@@ -123,7 +123,7 @@ class TestWorkloadBalance(TestBaseStrategy):
|
||||
dest_hosts = self.strategy.filter_destination_hosts(
|
||||
n2, instance_to_mig[1], avg, w_map)
|
||||
self.assertEqual(len(dest_hosts), 1)
|
||||
self.assertEqual(dest_hosts[0]['node'].uuid, 'Node_1')
|
||||
self.assertEqual(dest_hosts[0]['compute_node'].uuid, 'Node_1')
|
||||
|
||||
def test_execute_no_workload(self):
|
||||
model = self.fake_c_cluster.\
|
||||
|
||||
@@ -46,11 +46,16 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
self.fake_metrics = self.fake_datasource_cls()
|
||||
|
||||
self.hosts_load_assert = {
|
||||
'Node_0': {'cpu_util': 0.07, 'memory.resident': 7.0, 'vcpus': 40},
|
||||
'Node_1': {'cpu_util': 0.07, 'memory.resident': 5, 'vcpus': 40},
|
||||
'Node_2': {'cpu_util': 0.8, 'memory.resident': 29, 'vcpus': 40},
|
||||
'Node_3': {'cpu_util': 0.05, 'memory.resident': 8, 'vcpus': 40},
|
||||
'Node_4': {'cpu_util': 0.05, 'memory.resident': 4, 'vcpus': 40}}
|
||||
'Node_0': {'instance_cpu_usage': 0.07,
|
||||
'instance_ram_usage': 7.0, 'vcpus': 40},
|
||||
'Node_1': {'instance_cpu_usage': 0.07,
|
||||
'instance_ram_usage': 5, 'vcpus': 40},
|
||||
'Node_2': {'instance_cpu_usage': 0.8,
|
||||
'instance_ram_usage': 29, 'vcpus': 40},
|
||||
'Node_3': {'instance_cpu_usage': 0.05,
|
||||
'instance_ram_usage': 8, 'vcpus': 40},
|
||||
'Node_4': {'instance_cpu_usage': 0.05,
|
||||
'instance_ram_usage': 4, 'vcpus': 40}}
|
||||
|
||||
p_osc = mock.patch.object(
|
||||
clients, "OpenStackClients")
|
||||
@@ -70,28 +75,32 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
config=mock.Mock(datasource=self.datasource))
|
||||
self.strategy.input_parameters = utils.Struct()
|
||||
self.strategy.input_parameters.update(
|
||||
{'metrics': ["cpu_util", "memory.resident"],
|
||||
'thresholds': {"cpu_util": 0.2, "memory.resident": 0.2},
|
||||
'weights': {"cpu_util_weight": 1.0,
|
||||
"memory.resident_weight": 1.0},
|
||||
{'metrics': ["instance_cpu_usage", "instance_ram_usage"],
|
||||
'thresholds': {"instance_cpu_usage": 0.2,
|
||||
"instance_ram_usage": 0.2},
|
||||
'weights': {"instance_cpu_usage_weight": 1.0,
|
||||
"instance_ram_usage_weight": 1.0},
|
||||
'instance_metrics':
|
||||
{"cpu_util": "compute.node.cpu.percent",
|
||||
"memory.resident": "hardware.memory.used"},
|
||||
{"instance_cpu_usage": "host_cpu_usage",
|
||||
"instance_ram_usage": "host_ram_usage"},
|
||||
'host_choice': 'retry',
|
||||
'retry_count': 1,
|
||||
'periods': {"instance": 720, "node": 600},
|
||||
'aggregation_method': {"instance": "mean", "node": "mean"}})
|
||||
self.strategy.metrics = ["cpu_util", "memory.resident"]
|
||||
self.strategy.thresholds = {"cpu_util": 0.2, "memory.resident": 0.2}
|
||||
self.strategy.weights = {"cpu_util_weight": 1.0,
|
||||
"memory.resident_weight": 1.0}
|
||||
'periods': {"instance": 720, "compute_node": 600},
|
||||
'aggregation_method': {"instance": "mean",
|
||||
"compute_node": "mean"}})
|
||||
self.strategy.metrics = ["instance_cpu_usage", "instance_ram_usage"]
|
||||
self.strategy.thresholds = {"instance_cpu_usage": 0.2,
|
||||
"instance_ram_usage": 0.2}
|
||||
self.strategy.weights = {"instance_cpu_usage_weight": 1.0,
|
||||
"instance_ram_usage_weight": 1.0}
|
||||
self.strategy.instance_metrics = {
|
||||
"cpu_util": "compute.node.cpu.percent",
|
||||
"memory.resident": "hardware.memory.used"}
|
||||
"instance_cpu_usage": "host_cpu_usage",
|
||||
"instance_ram_usage": "host_ram_usage"}
|
||||
self.strategy.host_choice = 'retry'
|
||||
self.strategy.retry_count = 1
|
||||
self.strategy.periods = {"instance": 720, "node": 600}
|
||||
self.strategy.aggregation_method = {"instance": "mean", "node": "mean"}
|
||||
self.strategy.periods = {"instance": 720, "compute_node": 600}
|
||||
self.strategy.aggregation_method = {"instance": "mean",
|
||||
"compute_node": "mean"}
|
||||
|
||||
def test_get_instance_load(self):
|
||||
model = self.fake_c_cluster.generate_scenario_1()
|
||||
@@ -99,7 +108,7 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
instance0 = model.get_instance_by_uuid("INSTANCE_0")
|
||||
instance_0_dict = {
|
||||
'uuid': 'INSTANCE_0', 'vcpus': 10,
|
||||
'cpu_util': 0.07, 'memory.resident': 2}
|
||||
'instance_cpu_usage': 0.07, 'instance_ram_usage': 2}
|
||||
self.assertEqual(
|
||||
instance_0_dict, self.strategy.get_instance_load(instance0))
|
||||
|
||||
@@ -112,14 +121,16 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
|
||||
def test_normalize_hosts_load(self):
|
||||
self.m_c_model.return_value = self.fake_c_cluster.generate_scenario_1()
|
||||
fake_hosts = {'Node_0': {'cpu_util': 0.07, 'memory.resident': 7},
|
||||
'Node_1': {'cpu_util': 0.05, 'memory.resident': 5}}
|
||||
fake_hosts = {'Node_0': {'instance_cpu_usage': 0.07,
|
||||
'instance_ram_usage': 7},
|
||||
'Node_1': {'instance_cpu_usage': 0.05,
|
||||
'instance_ram_usage': 5}}
|
||||
normalized_hosts = {'Node_0':
|
||||
{'cpu_util': 0.07,
|
||||
'memory.resident': 0.05303030303030303},
|
||||
{'instance_cpu_usage': 0.07,
|
||||
'instance_ram_usage': 0.05303030303030303},
|
||||
'Node_1':
|
||||
{'cpu_util': 0.05,
|
||||
'memory.resident': 0.03787878787878788}}
|
||||
{'instance_cpu_usage': 0.05,
|
||||
'instance_ram_usage': 0.03787878787878788}}
|
||||
self.assertEqual(
|
||||
normalized_hosts,
|
||||
self.strategy.normalize_hosts_load(fake_hosts))
|
||||
@@ -147,11 +158,11 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
test_ram_sd = 9.3
|
||||
self.assertEqual(
|
||||
round(self.strategy.get_sd(
|
||||
self.hosts_load_assert, 'cpu_util'), 3),
|
||||
self.hosts_load_assert, 'instance_cpu_usage'), 3),
|
||||
test_cpu_sd)
|
||||
self.assertEqual(
|
||||
round(self.strategy.get_sd(
|
||||
self.hosts_load_assert, 'memory.resident'), 1),
|
||||
self.hosts_load_assert, 'instance_ram_usage'), 1),
|
||||
test_ram_sd)
|
||||
|
||||
def test_calculate_weighted_sd(self):
|
||||
@@ -167,8 +178,9 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
result = self.strategy.calculate_migration_case(
|
||||
self.hosts_load_assert, instance,
|
||||
src_node, dst_node)[-1][dst_node.uuid]
|
||||
result['cpu_util'] = round(result['cpu_util'], 3)
|
||||
self.assertEqual(result, {'cpu_util': 0.095, 'memory.resident': 21.0,
|
||||
result['instance_cpu_usage'] = round(result['instance_cpu_usage'], 3)
|
||||
self.assertEqual(result, {'instance_cpu_usage': 0.095,
|
||||
'instance_ram_usage': 21.0,
|
||||
'vcpus': 40})
|
||||
|
||||
def test_simulate_migrations(self):
|
||||
@@ -191,13 +203,15 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
|
||||
def test_check_threshold(self):
|
||||
self.m_c_model.return_value = self.fake_c_cluster.generate_scenario_1()
|
||||
self.strategy.thresholds = {'cpu_util': 0.001, 'memory.resident': 0.2}
|
||||
self.strategy.thresholds = {'instance_cpu_usage': 0.001,
|
||||
'instance_ram_usage': 0.2}
|
||||
self.strategy.simulate_migrations = mock.Mock(return_value=True)
|
||||
self.assertTrue(self.strategy.check_threshold())
|
||||
|
||||
def test_execute_one_migration(self):
|
||||
self.m_c_model.return_value = self.fake_c_cluster.generate_scenario_1()
|
||||
self.strategy.thresholds = {'cpu_util': 0.001, 'memory.resident': 0.2}
|
||||
self.strategy.thresholds = {'instance_cpu_usage': 0.001,
|
||||
'instance_ram_usage': 0.2}
|
||||
self.strategy.simulate_migrations = mock.Mock(
|
||||
return_value=[
|
||||
{'instance': 'INSTANCE_4', 's_host': 'Node_2',
|
||||
@@ -210,8 +224,8 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
|
||||
def test_execute_multiply_migrations(self):
|
||||
self.m_c_model.return_value = self.fake_c_cluster.generate_scenario_1()
|
||||
self.strategy.thresholds = {'cpu_util': 0.00001,
|
||||
'memory.resident': 0.0001}
|
||||
self.strategy.thresholds = {'instance_cpu_usage': 0.00001,
|
||||
'instance_ram_usage': 0.0001}
|
||||
self.strategy.simulate_migrations = mock.Mock(
|
||||
return_value=[
|
||||
{'instance': 'INSTANCE_4', 's_host': 'Node_2',
|
||||
@@ -225,8 +239,8 @@ class TestWorkloadStabilization(TestBaseStrategy):
|
||||
|
||||
def test_execute_nothing_to_migrate(self):
|
||||
self.m_c_model.return_value = self.fake_c_cluster.generate_scenario_1()
|
||||
self.strategy.thresholds = {'cpu_util': 0.042,
|
||||
'memory.resident': 0.0001}
|
||||
self.strategy.thresholds = {'instance_cpu_usage': 0.042,
|
||||
'instance_ram_usage': 0.0001}
|
||||
self.strategy.simulate_migrations = mock.Mock(return_value=False)
|
||||
self.strategy.instance_migrations_count = 0
|
||||
with mock.patch.object(self.strategy, 'migrate') as mock_migrate:
|
||||
|
||||
Reference in New Issue
Block a user