Browse Source

Merge "Ensure instance_info is clean before deploy and after failure" into stable/stein

tags/0.11.1^0
Zuul Gerrit Code Review 7 months ago
parent
commit
3f2e391389
3 changed files with 21 additions and 8 deletions
  1. +11
    -8
      metalsmith/_provisioner.py
  2. +3
    -0
      metalsmith/test/test_provisioner.py
  3. +7
    -0
      releasenotes/notes/iinfo-2014b1de4dbeca2d.yaml

+ 11
- 8
metalsmith/_provisioner.py View File

@@ -34,6 +34,7 @@ LOG = logging.getLogger(__name__)

_CREATED_PORTS = 'metalsmith_created_ports'
_ATTACHED_PORTS = 'metalsmith_attached_ports'
_PRESERVE_INSTANCE_INFO_KEYS = {'capabilities', 'traits'}


class Provisioner(_utils.GetNodeMixin):
@@ -283,7 +284,7 @@ class Provisioner(_utils.GetNodeMixin):

capabilities['boot_option'] = 'netboot' if netboot else 'local'

instance_info = node.instance_info.copy()
instance_info = self._clean_instance_info(node.instance_info)
instance_info['root_gb'] = root_size_gb
instance_info['capabilities'] = capabilities
instance_info[self.HOSTNAME_FIELD] = hostname
@@ -364,6 +365,11 @@ class Provisioner(_utils.GetNodeMixin):
nodes, 'active', timeout=timeout)
return [_instance.Instance(self.connection, node) for node in nodes]

def _clean_instance_info(self, instance_info):
return {key: value
for key, value in instance_info.items()
if key in _PRESERVE_INSTANCE_INFO_KEYS}

def _clean_up(self, node, nics=None):
if nics is None:
created_ports = node.extra.get(_CREATED_PORTS, [])
@@ -376,17 +382,14 @@ class Provisioner(_utils.GetNodeMixin):
extra = node.extra.copy()
for item in (_CREATED_PORTS, _ATTACHED_PORTS):
extra.pop(item, None)
instance_info = node.instance_info.copy()
instance_info.pop(self.HOSTNAME_FIELD, None)
LOG.debug('Updating node %(node)s with instance info %(iinfo)s '
'and extras %(extra)s and releasing the lock',
LOG.debug('Updating node %(node)s with empty instance info (was '
'%(iinfo)s) and extras %(extra)s and releasing the lock',
{'node': _utils.log_res(node),
'iinfo': instance_info,
'iinfo': node.instance_info,
'extra': extra})
try:
self.connection.baremetal.update_node(
node, instance_info=instance_info, extra=extra,
instance_id=None)
node, instance_info={}, extra=extra, instance_id=None)
except Exception as exc:
LOG.debug('Failed to clear node %(node)s extra: %(exc)s',
{'node': _utils.log_res(node), 'exc': exc})


+ 3
- 0
metalsmith/test/test_provisioner.py View File

@@ -510,6 +510,9 @@ class TestProvisionNode(Base):
self.image.ramdisk_id = None
del self.instance_info['kernel']
del self.instance_info['ramdisk']
# Ensure stale values clean up
self.node.instance_info['kernel'] = 'bad value'
self.node.instance_info['ramdisk'] = 'bad value'

self.pr.provision_node(self.node, 'image', [{'network': 'network'}])



+ 7
- 0
releasenotes/notes/iinfo-2014b1de4dbeca2d.yaml View File

@@ -0,0 +1,7 @@
---
fixes:
- |
Fixes stale ``instance_info`` remaining after deploy failures.
- |
Cleans up ``instance_info`` before updating it before deployment to make
sure not stale information is left there.

Loading…
Cancel
Save