Fix damodel list return None error When has a compute node

Reason:
When there is a compute node but no virtual machine,
the command 'watcher datamodel list' should display
the information of the compute node instead of return None.

Change-Id: Id5ff7f08ac8a9883af9f0313785b756d813ed5a2
Closes-Bug: #1844948
This commit is contained in:
chenke
2019-09-23 09:47:04 +08:00
parent 519ca2c9fb
commit 2b63a35e86
2 changed files with 15 additions and 0 deletions

View File

@@ -257,6 +257,10 @@ class ModelRoot(nx.DiGraph, base.Model):
new_name = "node_"+str(field)
in_dict[new_name] = cn[field]
node_instances = self.get_node_instances(cn)
if not node_instances:
deep_in_dict = in_dict.copy()
ret_list.append(deep_in_dict)
continue
for instance in sorted(node_instances, key=lambda x: x.uuid):
for field in instance.fields:
new_name = "server_"+str(field)

View File

@@ -85,6 +85,17 @@ class TestModel(base.TestCase):
result_keys = result[0].keys()
self.assertEqual(sorted(expected_keys), sorted(result_keys))
# test compute node has no instance
mock_instances.return_value = []
expected_keys = ['node_uuid']
result = model_root.ModelRoot().to_list()
self.assertEqual(1, len(result))
result_keys = result[0].keys()
self.assertEqual(expected_keys, list(result_keys))
def test_get_node_by_instance_uuid(self):
model = model_root.ModelRoot()
uuid_ = "{0}".format(uuidutils.generate_uuid())