From 6cc9ea7cfb89143c82f11ee37fc85d714f25c65c Mon Sep 17 00:00:00 2001
From: licanwei
Date: Fri, 26 Jul 2019 17:23:18 +0800
Subject: [PATCH] set disk field to disk capacity
The node.free_disk_gb does not take allocation ratios used
for overcommit into account so this value may be negative.
We do not need this field and plan to set disk to total disk
capacity and then remove disk_capacity.
Partially Implements: blueprint improve-compute-data-model
Change-Id: I72c4490f5a8d0fbd1039f70ff20f07b743b6bb2d
---
watcher/decision_engine/model/collector/nova.py | 7 ++++++-
watcher/decision_engine/model/notification/nova.py | 7 ++++++-
.../model/notification/test_nova_notifications.py | 2 +-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/watcher/decision_engine/model/collector/nova.py b/watcher/decision_engine/model/collector/nova.py
index 3f1fd4eb5..24a7537d1 100644
--- a/watcher/decision_engine/model/collector/nova.py
+++ b/watcher/decision_engine/model/collector/nova.py
@@ -356,7 +356,12 @@ class NovaModelBuilder(base.BaseModelBuilder):
"memory_ratio": memory_ratio,
"memory_mb_reserved": memory_mb_reserved,
"memory_mb_used": memory_used,
- "disk": node.free_disk_gb,
+ # The node.free_disk_gb does not take allocation ratios used
+ # for overcommit into account so this value may be negative.
+ # We do not need this field and plan to set disk to total disk
+ # capacity and then remove disk_capacity.
+ "disk": disk_capacity,
+ # TODO(licanwei): remove and replace by disk field
"disk_capacity": disk_capacity,
"disk_gb_used": disk_used,
"disk_gb_reserved": disk_gb_reserved,
diff --git a/watcher/decision_engine/model/notification/nova.py b/watcher/decision_engine/model/notification/nova.py
index 60c689d70..e5bec587e 100644
--- a/watcher/decision_engine/model/notification/nova.py
+++ b/watcher/decision_engine/model/notification/nova.py
@@ -133,7 +133,12 @@ class NovaNotification(base.NotificationEndpoint):
status=_node.status,
memory=_node.memory_mb,
vcpus=_node.vcpus,
- disk=_node.free_disk_gb,
+ # The node.free_disk_gb does not take allocation ratios used
+ # for overcommit into account so this value may be negative.
+ # We do not need this field and plan to set disk to total disk
+ # capacity and then remove disk_capacity.
+ disk=_node.local_gb,
+ # TODO(licanwei): remove and replace by disk field
disk_capacity=_node.local_gb,
)
self.cluster_data_model.add_node(node)
diff --git a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py
index 1ece440b1..593e05e07 100644
--- a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py
+++ b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py
@@ -313,7 +313,7 @@ class TestNovaNotifications(NotificationTestCase):
node_2 = compute_model.get_node_by_name('Node_2')
self.assertEqual(7777, node_2.memory)
self.assertEqual(42, node_2.vcpus)
- self.assertEqual(974, node_2.disk)
+ self.assertEqual(1337, node_2.disk)
self.assertEqual(1337, node_2.disk_capacity)
@mock.patch.object(nova_helper, "NovaHelper")