Merge "Change hardware.cpu_util in workload_stabilization"
This commit is contained in:
@@ -31,6 +31,7 @@ import copy
|
||||
import itertools
|
||||
import math
|
||||
import random
|
||||
import re
|
||||
|
||||
import oslo_cache
|
||||
from oslo_config import cfg
|
||||
@@ -119,7 +120,7 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
||||
"description": "Mapping to get hardware statistics using"
|
||||
" instance metrics",
|
||||
"type": "object",
|
||||
"default": {"cpu_util": "hardware.cpu.util",
|
||||
"default": {"cpu_util": "compute.node.cpu.percent",
|
||||
"memory.resident": "hardware.memory.used"}
|
||||
},
|
||||
"host_choice": {
|
||||
@@ -224,7 +225,7 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
||||
def get_hosts_load(self):
|
||||
"""Get load of every available host by gathering instances load"""
|
||||
hosts_load = {}
|
||||
for node_id in self.get_available_nodes():
|
||||
for node_id, node in self.get_available_nodes().items():
|
||||
hosts_load[node_id] = {}
|
||||
host_vcpus = self.compute_model.get_resource_by_uuid(
|
||||
element.ResourceType.cpu_cores).get_capacity(
|
||||
@@ -232,19 +233,27 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
||||
hosts_load[node_id]['vcpus'] = host_vcpus
|
||||
|
||||
for metric in self.metrics:
|
||||
|
||||
resource_id = ''
|
||||
meter_name = self.instance_metrics[metric]
|
||||
if re.match('^compute.node', meter_name) is not None:
|
||||
resource_id = "%s_%s" % (node.uuid, node.hostname)
|
||||
else:
|
||||
resource_id = node_id
|
||||
|
||||
avg_meter = self.ceilometer.statistic_aggregation(
|
||||
resource_id=node_id,
|
||||
resource_id=resource_id,
|
||||
meter_name=self.instance_metrics[metric],
|
||||
period="60",
|
||||
aggregate='avg'
|
||||
)
|
||||
if avg_meter is None:
|
||||
raise exception.NoSuchMetricForHost(
|
||||
metric=self.instance_metrics[metric],
|
||||
metric=meter_name,
|
||||
host=node_id)
|
||||
if self.instance_metrics[metric] == 'hardware.memory.used':
|
||||
if meter_name == 'hardware.memory.used':
|
||||
avg_meter /= oslo_utils.units.Ki
|
||||
if self.instance_metrics[metric] == 'hardware.cpu.util':
|
||||
if meter_name == 'compute.node.cpu.percent':
|
||||
avg_meter /= 100
|
||||
hosts_load[node_id][metric] = avg_meter
|
||||
return hosts_load
|
||||
|
||||
@@ -40,10 +40,10 @@ class TestWorkloadStabilization(base.TestCase):
|
||||
|
||||
self.hosts_load_assert = {
|
||||
'Node_0': {'cpu_util': 0.07, 'memory.resident': 7.0, 'vcpus': 40},
|
||||
'Node_1': {'cpu_util': 0.05, 'memory.resident': 5, 'vcpus': 40},
|
||||
'Node_2': {'cpu_util': 0.1, 'memory.resident': 29, 'vcpus': 40},
|
||||
'Node_3': {'cpu_util': 0.04, 'memory.resident': 8, 'vcpus': 40},
|
||||
'Node_4': {'cpu_util': 0.02, 'memory.resident': 4, '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}}
|
||||
|
||||
p_model = mock.patch.object(
|
||||
strategies.WorkloadStabilization, "compute_model",
|
||||
@@ -76,7 +76,7 @@ class TestWorkloadStabilization(base.TestCase):
|
||||
'weights': {"cpu_util_weight": 1.0,
|
||||
"memory.resident_weight": 1.0},
|
||||
'instance_metrics':
|
||||
{"cpu_util": "hardware.cpu.util",
|
||||
{"cpu_util": "compute.node.cpu.percent",
|
||||
"memory.resident": "hardware.memory.used"},
|
||||
'host_choice': 'retry',
|
||||
'retry_count': 1})
|
||||
@@ -84,9 +84,9 @@ class TestWorkloadStabilization(base.TestCase):
|
||||
self.strategy.thresholds = {"cpu_util": 0.2, "memory.resident": 0.2}
|
||||
self.strategy.weights = {"cpu_util_weight": 1.0,
|
||||
"memory.resident_weight": 1.0}
|
||||
self.strategy.instance_metrics = {"cpu_util": "hardware.cpu.util",
|
||||
"memory.resident":
|
||||
"hardware.memory.used"}
|
||||
self.strategy.instance_metrics = {
|
||||
"cpu_util": "compute.node.cpu.percent",
|
||||
"memory.resident": "hardware.memory.used"}
|
||||
self.strategy.host_choice = 'retry'
|
||||
self.strategy.retry_count = 1
|
||||
|
||||
@@ -123,7 +123,7 @@ class TestWorkloadStabilization(base.TestCase):
|
||||
self.hosts_load_assert)
|
||||
|
||||
def test_get_sd(self):
|
||||
test_cpu_sd = 0.027
|
||||
test_cpu_sd = 0.296
|
||||
test_ram_sd = 9.3
|
||||
self.assertEqual(
|
||||
round(self.strategy.get_sd(
|
||||
@@ -144,7 +144,7 @@ class TestWorkloadStabilization(base.TestCase):
|
||||
self.hosts_load_assert, "INSTANCE_5", "Node_2", "Node_1")[-1][
|
||||
"Node_1"]
|
||||
result['cpu_util'] = round(result['cpu_util'], 3)
|
||||
self.assertEqual(result, {'cpu_util': 0.075, 'memory.resident': 21,
|
||||
self.assertEqual(result, {'cpu_util': 0.095, 'memory.resident': 21.0,
|
||||
'vcpus': 40})
|
||||
|
||||
def test_simulate_migrations(self):
|
||||
|
||||
Reference in New Issue
Block a user