From ca37358cace69cd5590f106845337e7361cdaa19 Mon Sep 17 00:00:00 2001 From: Alexander Chadin Date: Thu, 2 Jun 2016 13:11:35 +0300 Subject: [PATCH] Add fix for hardware.cpu.util meter in sd-strategy This patch set removes normalizing for hardware.cpu.util meter since the values that comes from ceilometer hardware.cpu.util are already normalized. Closes-Bug: #1588257 Change-Id: I9494f2cc9bbaa6dfd168fb515f679eb6d7f2398a --- .../strategies/workload_stabilization.py | 3 --- .../strategies/faker_metrics_collector.py | 10 +++---- .../strategies/test_workload_stabilization.py | 26 +++++++++---------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/watcher/decision_engine/strategy/strategies/workload_stabilization.py b/watcher/decision_engine/strategy/strategies/workload_stabilization.py index cdc4bcca6..a26069ac2 100644 --- a/watcher/decision_engine/strategy/strategies/workload_stabilization.py +++ b/watcher/decision_engine/strategy/strategies/workload_stabilization.py @@ -192,9 +192,6 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy): def normalize_hosts_load(self, hosts, current_model): normalized_hosts = deepcopy(hosts) for host in normalized_hosts: - if 'cpu_util' in normalized_hosts[host]: - normalized_hosts[host]['cpu_util'] /= float(100) - if 'memory.resident' in normalized_hosts[host]: h_memory = current_model.get_resource_from_id( resource.ResourceType.memory).get_capacity( diff --git a/watcher/tests/decision_engine/strategy/strategies/faker_metrics_collector.py b/watcher/tests/decision_engine/strategy/strategies/faker_metrics_collector.py index 9c50c1169..7b0e56aa6 100644 --- a/watcher/tests/decision_engine/strategy/strategies/faker_metrics_collector.py +++ b/watcher/tests/decision_engine/strategy/strategies/faker_metrics_collector.py @@ -103,11 +103,11 @@ class FakerMetricsCollector(object): # node 4 mock['VM_7_hostname_7'] = 4 - mock['Node_0'] = 7 - mock['Node_1'] = 5 - mock['Node_2'] = 10 - mock['Node_3'] = 4 - mock['Node_4'] = 2 + mock['Node_0'] = 0.07 + mock['Node_1'] = 0.05 + mock['Node_2'] = 0.1 + mock['Node_3'] = 0.04 + mock['Node_4'] = 0.02 if uuid not in mock.keys(): # mock[uuid] = random.randint(1, 4) diff --git a/watcher/tests/decision_engine/strategy/strategies/test_workload_stabilization.py b/watcher/tests/decision_engine/strategy/strategies/test_workload_stabilization.py index d1d62574f..6220c54fc 100644 --- a/watcher/tests/decision_engine/strategy/strategies/test_workload_stabilization.py +++ b/watcher/tests/decision_engine/strategy/strategies/test_workload_stabilization.py @@ -35,19 +35,19 @@ class TestWorkloadStabilization(base.BaseTestCase): fake_cluster = faker_cluster_state.FakerModelCollector() hosts_load_assert = {'Node_0': - {'cpu_util': 7.0, 'memory.resident': 7.0, + {'cpu_util': 0.07, 'memory.resident': 7.0, 'vcpus': 40}, 'Node_1': - {'cpu_util': 5.0, 'memory.resident': 5, + {'cpu_util': 0.05, 'memory.resident': 5, 'vcpus': 40}, 'Node_2': - {'cpu_util': 10.0, 'memory.resident': 29, + {'cpu_util': 0.1, 'memory.resident': 29, 'vcpus': 40}, 'Node_3': - {'cpu_util': 4.0, 'memory.resident': 8, + {'cpu_util': 0.04, 'memory.resident': 8, 'vcpus': 40}, 'Node_4': - {'cpu_util': 2.0, 'memory.resident': 4, + {'cpu_util': 0.02, 'memory.resident': 4, 'vcpus': 40}} def test_get_vm_load(self): @@ -62,8 +62,8 @@ class TestWorkloadStabilization(base.BaseTestCase): def test_normalize_hosts_load(self): model = self.fake_cluster.generate_scenario_1() sd = strategies.WorkloadStabilization() - fake_hosts = {'Node_0': {'cpu_util': 7.0, 'memory.resident': 7}, - 'Node_1': {'cpu_util': 5.0, 'memory.resident': 5}} + fake_hosts = {'Node_0': {'cpu_util': 0.07, 'memory.resident': 7}, + 'Node_1': {'cpu_util': 0.05, 'memory.resident': 5}} normalized_hosts = {'Node_0': {'cpu_util': 0.07, 'memory.resident': 0.05303030303030303}, @@ -83,10 +83,10 @@ class TestWorkloadStabilization(base.BaseTestCase): def test_get_sd(self): sd = strategies.WorkloadStabilization() - test_cpu_sd = 2.7 + test_cpu_sd = 0.027 test_ram_sd = 9.3 self.assertEqual( - round(sd.get_sd(self.hosts_load_assert, 'cpu_util'), 1), + round(sd.get_sd(self.hosts_load_assert, 'cpu_util'), 3), test_cpu_sd) self.assertEqual( round(sd.get_sd(self.hosts_load_assert, 'memory.resident'), 1), @@ -105,7 +105,7 @@ class TestWorkloadStabilization(base.BaseTestCase): self.assertEqual(sd.calculate_migration_case( self.hosts_load_assert, "VM_5", "Node_2", "Node_1", model)[-1]["Node_1"], - {'cpu_util': 7.5, 'memory.resident': 21, 'vcpus': 40}) + {'cpu_util': 2.55, 'memory.resident': 21, 'vcpus': 40}) def test_simulate_migrations(self): sd = strategies.WorkloadStabilization() @@ -143,7 +143,7 @@ class TestWorkloadStabilization(base.BaseTestCase): def test_execute_multiply_migrations(self): sd = strategies.WorkloadStabilization() model = self.fake_cluster.generate_scenario_1() - sd.thresholds = {'cpu_util': 0.022, 'memory.resident': 0.0001} + sd.thresholds = {'cpu_util': 0.00001, 'memory.resident': 0.0001} sd.ceilometer = mock.MagicMock( statistic_aggregation=self.fake_metrics.mock_get_statistics) sd.simulate_migrations = mock.Mock(return_value=[{'vm': 'VM_4', @@ -151,10 +151,10 @@ class TestWorkloadStabilization(base.BaseTestCase): 'host': 'Node_1'}, {'vm': 'VM_3', 's_host': 'Node_2', - 'host': 'Node_3'}]) + 'host': 'Node_4'}]) with mock.patch.object(sd, 'migrate') as mock_migrate: sd.execute(model) - self.assertEqual(mock_migrate.call_count, 2) + self.assertEqual(mock_migrate.call_count, 1) def test_execute_nothing_to_migrate(self): sd = strategies.WorkloadStabilization()