Skip to content

Commit 3909e93

Browse files
committed
evacuate: respect original SHUTOFF state in --wait completion
When running `openstack server evacuate --wait`, the command would hang indefinitely if the instance was originally in SHUTOFF state, because only “ACTIVE” was treated as a successful completion. We now capture the server’s status before evacuation and dynamically include “SHUTOFF” in the `success_status` list if the instance was already shut off. This ensures that a shutoff instance is accepted as a valid completion without requiring manual intervention. Unit tests have been added and updated to cover both: - pre-evacuation ACTIVE → success_status=['active'] - pre-evacuation SHUTOFF → success_status=['active','shutoff'] Closes-Bug: #2103426 Change-Id: I86ad1cd173a144b16fde1dbac87819fab2d7a50a
1 parent a49a290 commit 3909e93

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

openstackclient/compute/v2/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3879,9 +3879,15 @@ def _show_progress(progress):
38793879
compute_client.evacuate_server(server, **kwargs)
38803880

38813881
if parsed_args.wait:
3882+
orig_status = server.status
3883+
success = ['ACTIVE']
3884+
if orig_status == 'SHUTOFF':
3885+
success.append('SHUTOFF')
3886+
38823887
if utils.wait_for_status(
38833888
compute_client.get_server,
38843889
server.id,
3890+
success_status=success,
38853891
callback=_show_progress,
38863892
):
38873893
self.app.stdout.write(_('Complete\n'))

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7000,6 +7000,7 @@ def setUp(self):
70007000
'image': self.image,
70017001
'networks': {},
70027002
'adminPass': 'passw0rd',
7003+
'status': 'ACTIVE',
70037004
}
70047005
self.server = compute_fakes.create_one_server(attrs=attrs)
70057006
attrs['id'] = self.server.id
@@ -7137,6 +7138,33 @@ def test_evacuate_with_wait_ok(self, mock_wait_for_status):
71377138
mock_wait_for_status.assert_called_once_with(
71387139
self.compute_client.get_server,
71397140
self.server.id,
7141+
success_status=['ACTIVE'],
7142+
callback=mock.ANY,
7143+
)
7144+
7145+
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
7146+
def test_evacuate_with_wait_ok_shutoff(self, mock_wait_for_status):
7147+
self.server.status = 'SHUTOFF'
7148+
self.compute_client.get_server.return_value = self.server
7149+
7150+
args = [
7151+
self.server.id,
7152+
'--wait',
7153+
]
7154+
verify_args = [
7155+
('server', self.server.id),
7156+
('wait', True),
7157+
]
7158+
evac_args = {
7159+
'host': None,
7160+
'on_shared_storage': False,
7161+
'admin_pass': None,
7162+
}
7163+
self._test_evacuate(args, verify_args, evac_args)
7164+
mock_wait_for_status.assert_called_once_with(
7165+
self.compute_client.get_server,
7166+
self.server.id,
7167+
success_status=['ACTIVE', 'SHUTOFF'],
71407168
callback=mock.ANY,
71417169
)
71427170

0 commit comments

Comments
 (0)