summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2018-09-10 15:04:37 +0200
committerDmitry Tantsur <divius.inside@gmail.com>2018-09-10 16:49:01 +0200
commitc06e2c9baffedc4e2c31dd2b8fa842ff7faf373a (patch)
tree21cb159e7f76d360c35132ae2b8c4b2e3ecc84cb
parentd12d966218359e1a8d46db86fcc167fd751cb805 (diff)
Allow overriding traits in provision_node (similar to capabilities)
Notes
Notes (review): Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Workflow+1: Dmitry Tantsur <divius.inside@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 10 Sep 2018 17:39:16 +0000 Reviewed-on: https://review.openstack.org/601269 Project: openstack/metalsmith Branch: refs/heads/master
-rw-r--r--metalsmith/_provisioner.py8
-rw-r--r--metalsmith/test/test_provisioner.py45
2 files changed, 52 insertions, 1 deletions
diff --git a/metalsmith/_provisioner.py b/metalsmith/_provisioner.py
index 7e34985..62f1815 100644
--- a/metalsmith/_provisioner.py
+++ b/metalsmith/_provisioner.py
@@ -196,7 +196,7 @@ class Provisioner(object):
196 196
197 def provision_node(self, node, image, nics=None, root_disk_size=None, 197 def provision_node(self, node, image, nics=None, root_disk_size=None,
198 config=None, hostname=None, netboot=False, 198 config=None, hostname=None, netboot=False,
199 capabilities=None, wait=None): 199 capabilities=None, traits=None, wait=None):
200 """Provision the node with the given image. 200 """Provision the node with the given image.
201 201
202 Example:: 202 Example::
@@ -227,6 +227,10 @@ class Provisioner(object):
227 overwrites the capabilities set by :meth:`reserve_node`. 227 overwrites the capabilities set by :meth:`reserve_node`.
228 Note that the capabilities are not checked against the ones 228 Note that the capabilities are not checked against the ones
229 provided by the node - use :meth:`reserve_node` for that. 229 provided by the node - use :meth:`reserve_node` for that.
230 :param traits: Requested traits of the node. If present, overwrites
231 the traits set by :meth:`reserve_node`. Note that the traits are
232 not checked against the ones provided by the node - use
233 :meth:`reserve_node` for that.
230 :param wait: How many seconds to wait for the deployment to finish, 234 :param wait: How many seconds to wait for the deployment to finish,
231 None to return immediately. 235 None to return immediately.
232 :return: :py:class:`metalsmith.Instance` object with the current 236 :return: :py:class:`metalsmith.Instance` object with the current
@@ -270,6 +274,8 @@ class Provisioner(object):
270 '/extra/%s' % _ATTACHED_PORTS: attached_ports, 274 '/extra/%s' % _ATTACHED_PORTS: attached_ports,
271 '/instance_info/%s' % _os_api.HOSTNAME_FIELD: hostname} 275 '/instance_info/%s' % _os_api.HOSTNAME_FIELD: hostname}
272 updates.update(image._node_updates(self.connection)) 276 updates.update(image._node_updates(self.connection))
277 if traits is not None:
278 updates['/instance_info/traits'] = traits
273 279
274 LOG.debug('Updating node %(node)s with %(updates)s', 280 LOG.debug('Updating node %(node)s with %(updates)s',
275 {'node': _utils.log_node(node), 'updates': updates}) 281 {'node': _utils.log_node(node), 'updates': updates})
diff --git a/metalsmith/test/test_provisioner.py b/metalsmith/test/test_provisioner.py
index 56fceb2..e36d943 100644
--- a/metalsmith/test/test_provisioner.py
+++ b/metalsmith/test/test_provisioner.py
@@ -675,6 +675,51 @@ abcd image
675 self.assertFalse(self.api.release_node.called) 675 self.assertFalse(self.api.release_node.called)
676 self.assertFalse(self.conn.network.delete_port.called) 676 self.assertFalse(self.conn.network.delete_port.called)
677 677
678 def test_with_traits(self):
679 inst = self.pr.provision_node(self.node, 'image',
680 [{'network': 'network'}],
681 traits=['1', '2'])
682 self.updates['/instance_info/traits'] = ['1', '2']
683
684 self.assertEqual(inst.uuid, self.node.uuid)
685 self.assertEqual(inst.node, self.node)
686
687 self.conn.network.create_port.assert_called_once_with(
688 network_id=self.conn.network.find_network.return_value.id)
689 self.api.attach_port_to_node.assert_called_once_with(
690 self.node.uuid, self.conn.network.create_port.return_value.id)
691 self.api.update_node.assert_called_once_with(self.node, self.updates)
692 self.api.validate_node.assert_called_once_with(self.node,
693 validate_deploy=True)
694 self.api.node_action.assert_called_once_with(self.node, 'active',
695 configdrive=mock.ANY)
696 self.assertFalse(self.wait_mock.called)
697 self.assertFalse(self.api.release_node.called)
698 self.assertFalse(self.conn.network.delete_port.called)
699
700 def test_override_existing_traits(self):
701 self.node.traits = ['42']
702 inst = self.pr.provision_node(self.node, 'image',
703 [{'network': 'network'}],
704 traits=['1', '2'])
705 self.updates['/instance_info/traits'] = ['1', '2']
706
707 self.assertEqual(inst.uuid, self.node.uuid)
708 self.assertEqual(inst.node, self.node)
709
710 self.conn.network.create_port.assert_called_once_with(
711 network_id=self.conn.network.find_network.return_value.id)
712 self.api.attach_port_to_node.assert_called_once_with(
713 self.node.uuid, self.conn.network.create_port.return_value.id)
714 self.api.update_node.assert_called_once_with(self.node, self.updates)
715 self.api.validate_node.assert_called_once_with(self.node,
716 validate_deploy=True)
717 self.api.node_action.assert_called_once_with(self.node, 'active',
718 configdrive=mock.ANY)
719 self.assertFalse(self.wait_mock.called)
720 self.assertFalse(self.api.release_node.called)
721 self.assertFalse(self.conn.network.delete_port.called)
722
678 def test_with_wait(self): 723 def test_with_wait(self):
679 self.conn.network.find_port.return_value = mock.Mock( 724 self.conn.network.find_port.return_value = mock.Mock(
680 spec=['fixed_ips'], 725 spec=['fixed_ips'],