summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2019-03-08 14:29:45 +0100
committerDmitry Tantsur <divius.inside@gmail.com>2019-03-08 14:31:47 +0100
commit8e7b8d3f398fd206af74708d53857154f9e8e6a1 (patch)
tree611538ea8e1def3114cf41d702947556a03da7a8
parentd64e020fd05c9c6c89f11b636a05f1ba675cb4d6 (diff)
Ensure instance_info is clean before deploy and after failure
Currently stale values can be left in instance_info (and reused next time) if a deployment attempts fails. This change ensures that we: 1) Purge instance_info completely on failures 2) Only keep traits and capabilities in instance_info on deploy. Change-Id: I52a85620d9ac2f471bca6498294871f3bb16d47f
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, 11 Mar 2019 11:33:56 +0000 Reviewed-on: https://review.openstack.org/642016 Project: openstack/metalsmith Branch: refs/heads/master
-rw-r--r--metalsmith/_provisioner.py19
-rw-r--r--metalsmith/test/test_provisioner.py3
-rw-r--r--releasenotes/notes/iinfo-2014b1de4dbeca2d.yaml7
3 files changed, 21 insertions, 8 deletions
diff --git a/metalsmith/_provisioner.py b/metalsmith/_provisioner.py
index d6f103c..bcfe4dc 100644
--- a/metalsmith/_provisioner.py
+++ b/metalsmith/_provisioner.py
@@ -34,6 +34,7 @@ LOG = logging.getLogger(__name__)
34 34
35_CREATED_PORTS = 'metalsmith_created_ports' 35_CREATED_PORTS = 'metalsmith_created_ports'
36_ATTACHED_PORTS = 'metalsmith_attached_ports' 36_ATTACHED_PORTS = 'metalsmith_attached_ports'
37_PRESERVE_INSTANCE_INFO_KEYS = {'capabilities', 'traits'}
37 38
38 39
39class Provisioner(_utils.GetNodeMixin): 40class Provisioner(_utils.GetNodeMixin):
@@ -279,7 +280,7 @@ class Provisioner(_utils.GetNodeMixin):
279 280
280 capabilities['boot_option'] = 'netboot' if netboot else 'local' 281 capabilities['boot_option'] = 'netboot' if netboot else 'local'
281 282
282 instance_info = node.instance_info.copy() 283 instance_info = self._clean_instance_info(node.instance_info)
283 instance_info['root_gb'] = root_size_gb 284 instance_info['root_gb'] = root_size_gb
284 instance_info['capabilities'] = capabilities 285 instance_info['capabilities'] = capabilities
285 instance_info[self.HOSTNAME_FIELD] = hostname 286 instance_info[self.HOSTNAME_FIELD] = hostname
@@ -360,6 +361,11 @@ class Provisioner(_utils.GetNodeMixin):
360 nodes, 'active', timeout=timeout) 361 nodes, 'active', timeout=timeout)
361 return [_instance.Instance(self.connection, node) for node in nodes] 362 return [_instance.Instance(self.connection, node) for node in nodes]
362 363
364 def _clean_instance_info(self, instance_info):
365 return {key: value
366 for key, value in instance_info.items()
367 if key in _PRESERVE_INSTANCE_INFO_KEYS}
368
363 def _clean_up(self, node, nics=None): 369 def _clean_up(self, node, nics=None):
364 if nics is None: 370 if nics is None:
365 created_ports = node.extra.get(_CREATED_PORTS, []) 371 created_ports = node.extra.get(_CREATED_PORTS, [])
@@ -372,17 +378,14 @@ class Provisioner(_utils.GetNodeMixin):
372 extra = node.extra.copy() 378 extra = node.extra.copy()
373 for item in (_CREATED_PORTS, _ATTACHED_PORTS): 379 for item in (_CREATED_PORTS, _ATTACHED_PORTS):
374 extra.pop(item, None) 380 extra.pop(item, None)
375 instance_info = node.instance_info.copy() 381 LOG.debug('Updating node %(node)s with empty instance info (was '
376 instance_info.pop(self.HOSTNAME_FIELD, None) 382 '%(iinfo)s) and extras %(extra)s and releasing the lock',
377 LOG.debug('Updating node %(node)s with instance info %(iinfo)s '
378 'and extras %(extra)s and releasing the lock',
379 {'node': _utils.log_res(node), 383 {'node': _utils.log_res(node),
380 'iinfo': instance_info, 384 'iinfo': node.instance_info,
381 'extra': extra}) 385 'extra': extra})
382 try: 386 try:
383 self.connection.baremetal.update_node( 387 self.connection.baremetal.update_node(
384 node, instance_info=instance_info, extra=extra, 388 node, instance_info={}, extra=extra, instance_id=None)
385 instance_id=None)
386 except Exception as exc: 389 except Exception as exc:
387 LOG.debug('Failed to clear node %(node)s extra: %(exc)s', 390 LOG.debug('Failed to clear node %(node)s extra: %(exc)s',
388 {'node': _utils.log_res(node), 'exc': exc}) 391 {'node': _utils.log_res(node), 'exc': exc})
diff --git a/metalsmith/test/test_provisioner.py b/metalsmith/test/test_provisioner.py
index db1aef5..e4e7e63 100644
--- a/metalsmith/test/test_provisioner.py
+++ b/metalsmith/test/test_provisioner.py
@@ -505,6 +505,9 @@ class TestProvisionNode(Base):
505 self.image.ramdisk_id = None 505 self.image.ramdisk_id = None
506 del self.instance_info['kernel'] 506 del self.instance_info['kernel']
507 del self.instance_info['ramdisk'] 507 del self.instance_info['ramdisk']
508 # Ensure stale values clean up
509 self.node.instance_info['kernel'] = 'bad value'
510 self.node.instance_info['ramdisk'] = 'bad value'
508 511
509 self.pr.provision_node(self.node, 'image', [{'network': 'network'}]) 512 self.pr.provision_node(self.node, 'image', [{'network': 'network'}])
510 513
diff --git a/releasenotes/notes/iinfo-2014b1de4dbeca2d.yaml b/releasenotes/notes/iinfo-2014b1de4dbeca2d.yaml
new file mode 100644
index 0000000..1468d24
--- /dev/null
+++ b/releasenotes/notes/iinfo-2014b1de4dbeca2d.yaml
@@ -0,0 +1,7 @@
1---
2fixes:
3 - |
4 Fixes stale ``instance_info`` remaining after deploy failures.
5 - |
6 Cleans up ``instance_info`` before updating it before deployment to make
7 sure not stale information is left there.