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())