diff options
author | Zuul <zuul@review.opendev.org> | 2020-08-12 23:29:19 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-08-12 23:29:19 +0000 |
commit | c37755ead64f7860d86f68ed679797eada8217aa (patch) | |
tree | 0be481065d6ac8d0615067cb73791f6a3418ef62 /ironic/tests/unit/objects | |
parent | e078d0bbc889f31abf69e7c2858b3c4a0ad0a961 (diff) | |
parent | 9b4a63aa62c0dd7dcd582e20277c5eddb58c16b9 (diff) | |
download | ironic-c37755ead64f7860d86f68ed679797eada8217aa.tar.gz |
Merge "Add RPC objects for deployment API"
Diffstat (limited to 'ironic/tests/unit/objects')
-rw-r--r-- | ironic/tests/unit/objects/test_deployment.py | 117 | ||||
-rw-r--r-- | ironic/tests/unit/objects/test_objects.py | 1 |
2 files changed, 118 insertions, 0 deletions
diff --git a/ironic/tests/unit/objects/test_deployment.py b/ironic/tests/unit/objects/test_deployment.py new file mode 100644 index 000000000..cb62fad8e --- /dev/null +++ b/ironic/tests/unit/objects/test_deployment.py @@ -0,0 +1,117 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_utils import uuidutils + +from ironic.common import exception +from ironic import objects +from ironic.tests.unit.db import base as db_base +from ironic.tests.unit.objects import utils as obj_utils + + +class TestDeploymentObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn): + + def setUp(self): + super(TestDeploymentObject, self).setUp() + self.uuid = uuidutils.generate_uuid() + self.instance_info = { + 'image_source': 'http://source', + 'kernel': 'http://kernel', + 'ramdisk': 'http://ramdisk', + 'image_checksum': '1234', + 'root_device': {'size': 42}, + } + self.node = obj_utils.create_test_node( + self.context, + provision_state='active', + instance_uuid=self.uuid, + instance_info=self.instance_info) + + def _check(self, do): + self.assertEqual(self.uuid, do.uuid) + self.assertEqual(self.node.uuid, do.node_uuid) + self.assertEqual(self.context, do._context) + self.assertEqual('http://source', do.image_ref) + self.assertEqual('http://kernel', do.kernel_ref) + self.assertEqual('http://ramdisk', do.ramdisk_ref) + self.assertEqual('1234', do.image_checksum) + self.assertEqual({'size': 42}, do.root_device) + + def test_get_by_uuid(self): + do = objects.Deployment.get_by_uuid(self.context, self.uuid) + self._check(do) + + def test_get_by_node_uuid(self): + do = objects.Deployment.get_by_node_uuid(self.context, self.node.uuid) + self._check(do) + + def test_not_found(self): + self.assertRaises(exception.InstanceNotFound, + objects.Deployment.get_by_uuid, + self.context, uuidutils.generate_uuid()) + self.assertRaises(exception.NodeNotFound, + objects.Deployment.get_by_node_uuid, + self.context, uuidutils.generate_uuid()) + + def test_create(self): + do = objects.Deployment(self.context) + do.node_uuid = self.node.uuid + do.image_ref = 'new-image' + do.create() + self.assertIsNotNone(do.uuid) + + node = objects.Node.get_by_uuid(self.context, do.node_uuid) + self.assertEqual(do.uuid, node.instance_uuid) + self.assertEqual('new-image', node.instance_info['image_source']) + self.assertFalse(do.obj_what_changed()) + + def test_create_with_node(self): + do = objects.Deployment(self.context) + do.node_uuid = self.node.uuid + do.image_ref = 'new-image' + do.create(node=self.node) + self.assertIsNotNone(do.uuid) + self.assertEqual(do.uuid, self.node.instance_uuid) + self.assertEqual('new-image', self.node.instance_info['image_source']) + self.assertFalse(do.obj_what_changed()) + self.assertFalse(self.node.obj_what_changed()) + + def test_destroy(self): + do = objects.Deployment(self.context) + do.node_uuid = self.node.uuid + do.image_ref = 'new-image' + do.create() + do.destroy() + + node = objects.Node.get_by_uuid(self.context, do.node_uuid) + self.assertIsNone(node.instance_uuid) + self.assertEqual({}, node.instance_info) + self.assertFalse(do.obj_what_changed()) + + def test_destroy_with_node(self): + do = objects.Deployment(self.context) + do.node_uuid = self.node.uuid + do.image_ref = 'new-image' + do.create() + do.destroy(node=self.node) + self.assertIsNone(self.node.instance_uuid) + self.assertEqual({}, self.node.instance_info) + self.assertFalse(do.obj_what_changed()) + self.assertFalse(self.node.obj_what_changed()) + + def test_refresh(self): + do = objects.Deployment.get_by_uuid(self.context, self.uuid) + do.node_uuid = None + do.image_source = 'updated' + do.refresh() + self._check(do) + self.assertFalse(do.obj_what_changed()) diff --git a/ironic/tests/unit/objects/test_objects.py b/ironic/tests/unit/objects/test_objects.py index 1320d96d3..ffdf375fd 100644 --- a/ironic/tests/unit/objects/test_objects.py +++ b/ironic/tests/unit/objects/test_objects.py @@ -719,6 +719,7 @@ expected_object_fingerprints = { 'DeployTemplate': '1.1-4e30c8e9098595e359bb907f095bf1a9', 'DeployTemplateCRUDNotification': '1.0-59acc533c11d306f149846f922739c15', 'DeployTemplateCRUDPayload': '1.0-200857e7e715f58a5b6d6b700ab73a3b', + 'Deployment': '1.0-ff10ae028c5968f1596131d85d7f5f9d', } |