Remove resource used fields from ComputeNode

The node resource(vcpu, memory and disk) used infomation need
to change when creating or deleting instances. Now Placement do
not send notifications, so there is not a good way to capture
the change. We remove these fields and leave the process to strategy.

Partially Implements: blueprint improve-compute-data-model

Change-Id: I3f9a3279a26f3df444117d9265e74cca57b38d6e
This commit is contained in:
licanwei
2019-08-09 10:28:40 +08:00
parent 152af02bf1
commit 4e4cfc959b
4 changed files with 2 additions and 66 deletions

View File

@@ -341,23 +341,6 @@ class NovaModelBuilder(base.BaseModelBuilder):
disk_gb_reserved = 0
disk_ratio = 1.0
usages = self.placement_helper.get_usages_for_resource_provider(
node.id)
if usages and orc.VCPU in usages:
vcpus_used = usages[orc.VCPU]
else:
vcpus_used = node.vcpus_used
if usages and orc.MEMORY_MB in usages:
memory_used = usages[orc.MEMORY_MB]
else:
memory_used = node.memory_mb_used
if usages and orc.DISK_GB in usages:
disk_used = usages[orc.DISK_GB]
else:
disk_used = node.local_gb_used
# build up the compute node.
node_attributes = {
# The id of the hypervisor as a UUID from version 2.53.
@@ -366,7 +349,6 @@ class NovaModelBuilder(base.BaseModelBuilder):
"memory": memory_mb,
"memory_ratio": memory_ratio,
"memory_mb_reserved": memory_mb_reserved,
"memory_mb_used": memory_used,
# 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
@@ -374,13 +356,11 @@ class NovaModelBuilder(base.BaseModelBuilder):
"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,
"disk_ratio": disk_ratio,
"vcpus": vcpus,
"vcpu_reserved": vcpu_reserved,
"vcpu_ratio": vcpu_ratio,
"vcpus_used": vcpus_used,
"state": node.state,
"status": node.status,
"disabled_reason": node.service["disabled_reason"]}

View File

@@ -40,13 +40,10 @@ class ComputeNode(compute_resource.ComputeResource):
"state": wfields.StringField(default=ServiceState.ONLINE.value),
"memory": wfields.NonNegativeIntegerField(),
"memory_mb_reserved": wfields.NonNegativeIntegerField(),
"memory_mb_used": wfields.NonNegativeIntegerField(),
"disk": wfields.IntegerField(),
"disk_capacity": wfields.NonNegativeIntegerField(),
"disk_gb_reserved": wfields.NonNegativeIntegerField(),
"disk_gb_used": wfields.NonNegativeIntegerField(),
"vcpus": wfields.NonNegativeIntegerField(),
"vcpus_used": wfields.NonNegativeIntegerField(),
"vcpu_reserved": wfields.NonNegativeIntegerField(),
"memory_ratio": wfields.NonNegativeFloatField(),
"vcpu_ratio": wfields.NonNegativeFloatField(),
@@ -65,24 +62,9 @@ class ComputeNode(compute_resource.ComputeResource):
return (self.disk-self.disk_gb_reserved)*self.disk_ratio
@property
def vcpus_capacity(self):
def vcpu_capacity(self):
return (self.vcpus-self.vcpu_reserved)*self.vcpu_ratio
@property
def memory_mb_free(self):
total = (self.memory-self.memory_mb_reserved)*self.memory_ratio
return total-self.memory_mb_used
@property
def disk_gb_free(self):
total = (self.disk-self.disk_gb_reserved)*self.disk_ratio
return total-self.disk_gb_used
@property
def vcpus_free(self):
total = (self.vcpus-self.vcpu_reserved)*self.vcpu_ratio
return total-self.vcpus_used
@base.WatcherObjectRegistry.register_if(False)
class StorageNode(storage_resource.StorageResource):

View File

@@ -165,23 +165,6 @@ class NovaNotification(base.NotificationEndpoint):
disk_gb_reserved = 0
disk_ratio = 1.0
usages = self.placement_helper.get_usages_for_resource_provider(
_node.id)
if usages and orc.VCPU in usages:
vcpus_used = usages[orc.VCPU]
else:
vcpus_used = _node.vcpus_used
if usages and orc.MEMORY_MB in usages:
memory_used = usages[orc.MEMORY_MB]
else:
memory_used = _node.memory_mb_used
if usages and orc.DISK_GB in usages:
disk_used = usages[orc.DISK_GB]
else:
disk_used = _node.local_gb_used
# build up the compute node.
node_attributes = {
# The id of the hypervisor as a UUID from version 2.53.
@@ -190,7 +173,6 @@ class NovaNotification(base.NotificationEndpoint):
"memory": memory_mb,
"memory_ratio": memory_ratio,
"memory_mb_reserved": memory_mb_reserved,
"memory_mb_used": memory_used,
# 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
@@ -198,13 +180,11 @@ class NovaNotification(base.NotificationEndpoint):
"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,
"disk_ratio": disk_ratio,
"vcpus": vcpus,
"vcpu_reserved": vcpu_reserved,
"vcpu_ratio": vcpu_ratio,
"vcpus_used": vcpus_used,
"state": _node.state,
"status": _node.status,
"disabled_reason": _node.service["disabled_reason"]}

View File

@@ -154,18 +154,12 @@ class TestNovaClusterDataModelCollector(base.TestCase):
memory_total = (node.memory-node.memory_mb_reserved)*node.memory_ratio
self.assertEqual(node.memory_mb_capacity, memory_total)
memory_free = memory_total - node.memory_mb_used
self.assertEqual(node.memory_mb_free, memory_free)
disk_total = (node.disk_capacity-node.disk_gb_reserved)*node.disk_ratio
self.assertEqual(node.disk_gb_capacity, disk_total)
disk_free = disk_total - node.disk_gb_used
self.assertEqual(node.disk_gb_free, disk_free)
vcpus_total = (node.vcpus-node.vcpu_reserved)*node.vcpu_ratio
self.assertEqual(node.vcpus_capacity, vcpus_total)
vcpus_free = vcpus_total - node.vcpus_used
self.assertEqual(node.vcpus_free, vcpus_free)
self.assertEqual(node.vcpu_capacity, vcpus_total)
m_nova_helper.get_compute_node_by_name.assert_called_once_with(
minimal_node['hypervisor_hostname'], servers=True, detailed=True)