Skip to content

Commit 7df7029

Browse files
author
Eric Fried
committed
Consts for need_healing
Followup for [1], this creates private module-level constants for the ``need_healing`` toggle used in the code, indicating whether the allocations need to be healed by creating them or by updating existing allocations. [1] https://review.opendev.org/#/c/668925/7/nova/cmd/manage.py@2069 Change-Id: I60f251cf76eeb7ec0953ad085f3606b0edf5535c
1 parent 7a37940 commit 7df7029

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

nova/cmd/manage.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
'oslo_db=INFO',
8686
'oslo_policy=INFO']
8787

88+
# Consts indicating whether allocations need to be healed by creating them or
89+
# by updating existing allocations.
90+
_CREATE = 'create'
91+
_UPDATE = 'update'
8892

8993
# Decorators for actions
9094
args = cmd_common.args
@@ -2037,7 +2041,7 @@ def _heal_allocations_for_instance(self, ctxt, instance, node_cache,
20372041
# there are no allocations for the instance
20382042
if not allocations.get('allocations'):
20392043
# This instance doesn't have allocations
2040-
need_healing = 'create'
2044+
need_healing = _CREATE
20412045
allocations = self._heal_missing_alloc(ctxt, instance, node_cache)
20422046

20432047
if (allocations.get('project_id') != instance.project_id or
@@ -2047,7 +2051,7 @@ def _heal_allocations_for_instance(self, ctxt, instance, node_cache,
20472051
# and re-put them. We don't use put_allocations here
20482052
# because we don't want to mess up shared or nested
20492053
# provider allocations.
2050-
need_healing = 'update'
2054+
need_healing = _UPDATE
20512055
allocations = self._heal_missing_project_and_user_id(
20522056
allocations, instance)
20532057

@@ -2059,19 +2063,19 @@ def _heal_allocations_for_instance(self, ctxt, instance, node_cache,
20592063
port_allocations, ports_to_update = {}, []
20602064

20612065
if port_allocations:
2062-
need_healing = need_healing or 'update'
2066+
need_healing = need_healing or _UPDATE
20632067
# Merge in any missing port allocations
20642068
allocations['allocations'] = self._merge_allocations(
20652069
allocations['allocations'], port_allocations)
20662070

20672071
if need_healing:
20682072
if dry_run:
2069-
if need_healing == 'create':
2073+
if need_healing == _CREATE:
20702074
output(_('[dry-run] Create allocations for instance '
20712075
'%(instance)s: %(allocations)s') %
20722076
{'instance': instance.uuid,
20732077
'allocations': allocations})
2074-
elif need_healing == 'update':
2078+
elif need_healing == _UPDATE:
20752079
output(_('[dry-run] Update allocations for instance '
20762080
'%(instance)s: %(allocations)s') %
20772081
{'instance': instance.uuid,
@@ -2090,11 +2094,11 @@ def _heal_allocations_for_instance(self, ctxt, instance, node_cache,
20902094
resp = placement.put_allocations(ctxt, instance.uuid,
20912095
allocations)
20922096
if resp:
2093-
if need_healing == 'create':
2097+
if need_healing == _CREATE:
20942098
output(_('Successfully created allocations for '
20952099
'instance %(instance)s.') %
20962100
{'instance': instance.uuid})
2097-
elif need_healing == 'update':
2101+
elif need_healing == _UPDATE:
20982102
output(_('Successfully updated allocations for '
20992103
'instance %(instance)s.') %
21002104
{'instance': instance.uuid})

0 commit comments

Comments
 (0)