From 2b63a35e86df18ee804d28efa37af97cfe3d9f93 Mon Sep 17 00:00:00 2001 From: chenke Date: Mon, 23 Sep 2019 09:47:04 +0800 Subject: [PATCH] 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 --- watcher/decision_engine/model/model_root.py | 4 ++++ watcher/tests/decision_engine/model/test_model.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/watcher/decision_engine/model/model_root.py b/watcher/decision_engine/model/model_root.py index 71d9185a7..74fe6a36c 100644 --- a/watcher/decision_engine/model/model_root.py +++ b/watcher/decision_engine/model/model_root.py @@ -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) diff --git a/watcher/tests/decision_engine/model/test_model.py b/watcher/tests/decision_engine/model/test_model.py index d7c0bad2c..557994bd8 100644 --- a/watcher/tests/decision_engine/model/test_model.py +++ b/watcher/tests/decision_engine/model/test_model.py @@ -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())