From 43fefe902379213fdf2ba36e27c22c548c196be5 Mon Sep 17 00:00:00 2001
From: Mario Villaplana <mario.villaplana@gmail.com>
Date: Tue, 20 Dec 2016 19:06:29 +0000
Subject: [PATCH] Add a NodePayload test

This adds a test case for NodePayload to ensure that:

1. All the items in its SCHEMA have corresponding fields within the
payload
2. All the items in its SCHEMA have matching fields in the Node
class

This should help mitigate the potential for either the Node object or
NodePayload to change in a way that breaks node notifications.

Change-Id: I85eb45cbd2b01b539b16b89b4e580cbbda51cbda
---
 ironic/tests/unit/objects/test_node.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/ironic/tests/unit/objects/test_node.py b/ironic/tests/unit/objects/test_node.py
index 467dcea8a4..eab2344a73 100644
--- a/ironic/tests/unit/objects/test_node.py
+++ b/ironic/tests/unit/objects/test_node.py
@@ -195,3 +195,17 @@ class TestNodeObject(base.DbTestCase):
             }
             node._validate_property_values(values['properties'])
             self.assertEqual(expect, values['properties'])
+
+    def test_node_payload_schema(self):
+        """Assert that NodePayload.SCHEMA has expected properties.
+
+           NodePayload.SCHEMA should:
+
+           1. Have each of its keys in NodePayload.fields
+           2. Have each member of the schema match with a corresponding field
+           on the Node object
+        """
+        for schema_key in objects.node.NodePayload.SCHEMA:
+            self.assertIn(schema_key, objects.node.NodePayload.fields)
+            node_key = objects.node.NodePayload.SCHEMA[schema_key][1]
+            self.assertIn(node_key, objects.node.Node.fields)