Skip to content

Commit c8a2505

Browse files
Merge pull request #588 from lmiccini/fix-instanceha-test-mocks
Fix InstanceHA test mock configurations
2 parents 34b47b4 + 2cd5605 commit c8a2505

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

test/instanceha/functional_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ def list(self, search_opts=None):
125125
servers.append(server)
126126
return servers
127127

128+
def reset_state(self, server, state):
129+
"""Reset server state."""
130+
if server in self.servers_data:
131+
self.servers_data[server]['status'] = state.upper()
132+
128133
def evacuate(self, server, host=None):
129134
"""Evacuate a server.
130135
@@ -156,6 +161,7 @@ def add_server(self, **kwargs):
156161
'host': kwargs.get('host', 'compute-0'),
157162
'flavor': kwargs.get('flavor', {'id': 'flavor-1', 'extra_specs': {}}),
158163
'image': kwargs.get('image', {'id': 'image-1'}),
164+
'OS-EXT-STS:task_state': kwargs.get('task_state', None),
159165
}
160166
self.servers_data[server_id] = server_data
161167
return server_id

test/instanceha/test_coverage_gaps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,13 @@ def _run_monitor(self, status_sequence, monotonic_values=None, start_time=100):
713713
if monotonic_values is None:
714714
monotonic_values = [start_time + i for i in range(len(status_sequence) + 5)]
715715

716+
conn = Mock()
717+
conn.servers.evacuate.return_value = (Mock(status_code=200, reason='OK'), {})
718+
716719
with patch('instanceha.time.sleep'):
717720
with patch('instanceha.time.monotonic', side_effect=monotonic_values):
718721
with patch('instanceha._server_evacuation_status', side_effect=status_sequence):
719-
return instanceha._monitor_evacuation(Mock(), 'srv-1', 'resp-1', start_time)
722+
return instanceha._monitor_evacuation(conn, 'srv-1', 'resp-1', start_time)
720723

721724
def test_immediate_completion(self):
722725
status = Mock(completed=True, error=False)

test/instanceha/test_critical_error_paths.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def test_smart_evacuation_timeout(self):
244244
mock_connection = Mock()
245245
mock_server = Mock()
246246
mock_server.id = 'server-123'
247+
setattr(mock_server, 'OS-EXT-STS:task_state', None)
247248

248249
# Mock evacuation to succeed
249250
mock_connection.servers.evacuate.return_value = (Mock(status_code=200, reason='OK'), {})
@@ -267,6 +268,7 @@ def test_smart_evacuation_retry_exhaustion(self):
267268
mock_connection = Mock()
268269
mock_server = Mock()
269270
mock_server.id = 'server-123'
271+
setattr(mock_server, 'OS-EXT-STS:task_state', None)
270272

271273
# Mock evacuation to succeed
272274
mock_connection.servers.evacuate.return_value = (Mock(status_code=200, reason='OK'), {})

test/instanceha/test_unit_core.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,8 @@ def _create_test_configs(self):
13651365
'auth_url': 'http://keystone:5000/v3',
13661366
'user_domain_name': 'Default',
13671367
'project_domain_name': 'Default'
1368-
}
1368+
},
1369+
'region_name': 'regionOne'
13691370
}
13701371
}
13711372
}
@@ -1462,6 +1463,7 @@ class MockUnauthorized(Exception):
14621463

14631464
self._assert_no_secrets_in_logs()
14641465

1466+
@patch.dict(os.environ, {'OS_CLOUD': 'testcloud'})
14651467
def test_create_connection_exception_no_secret_exposure(self):
14661468
"""Test that create_connection exceptions don't expose passwords."""
14671469
# Clear log capture
@@ -1609,6 +1611,7 @@ class MockConflict(Exception):
16091611

16101612
self._assert_no_secrets_in_logs()
16111613

1614+
@patch.dict(os.environ, {'OS_CLOUD': 'testcloud'})
16121615
def test_get_nova_connection_exception_no_secret_exposure(self):
16131616
"""Test that _get_nova_connection exceptions don't expose passwords."""
16141617
# Clear log capture
@@ -1630,6 +1633,7 @@ def test_get_nova_connection_exception_no_secret_exposure(self):
16301633

16311634
self._assert_no_secrets_in_logs()
16321635

1636+
@patch.dict(os.environ, {'OS_CLOUD': 'testcloud'})
16331637
def test_establish_nova_connection_exception_no_secret_exposure(self):
16341638
"""Test that _establish_nova_connection exceptions don't expose passwords."""
16351639
# Clear log capture
@@ -2691,6 +2695,7 @@ def test_complete_evacuation_workflow(self):
26912695
server1.name = 'test-server-1'
26922696
server1.image = {'id': 'image-1'}
26932697
server1.flavor = {'id': 'flavor-1'}
2698+
setattr(server1, 'OS-EXT-STS:task_state', None)
26942699
nova_state['servers'].append(server1)
26952700

26962701
# Create service and config
@@ -2757,6 +2762,7 @@ def test_service_poll_cycle_integration(self):
27572762
server.name = f'test-server-{i}'
27582763
server.image = {'id': 'image-1'}
27592764
server.flavor = {'id': 'flavor-1'}
2765+
setattr(server, 'OS-EXT-STS:task_state', None)
27602766
nova_state['servers'].append(server)
27612767

27622768
# Create service
@@ -2841,6 +2847,7 @@ def test_multi_host_failure_scenario(self):
28412847
server.host = f'compute-{i}.example.com'
28422848
server.status = 'ACTIVE'
28432849
server.name = f'test-server-{i}'
2850+
setattr(server, 'OS-EXT-STS:task_state', None)
28442851
# First 3 have evacuable tag, last 2 don't
28452852
if i < 3:
28462853
server.image = {'id': 'image-1'}
@@ -3204,6 +3211,7 @@ def test_smart_evacuation_with_migration_tracking(self):
32043211
"""Test smart evacuation tracks migration status to completion."""
32053212
conn = Mock()
32063213
server = Mock(id='server-123', status='ACTIVE', host='compute-01')
3214+
setattr(server, 'OS-EXT-STS:task_state', None)
32073215

32083216
# Mock evacuation response
32093217
response = Mock(status_code=200, reason='OK')
@@ -3229,6 +3237,7 @@ def test_smart_evacuation_timeout_handling(self):
32293237
"""Test smart evacuation handles timeout correctly."""
32303238
conn = Mock()
32313239
server = Mock(id='server-456', status='ACTIVE')
3240+
setattr(server, 'OS-EXT-STS:task_state', None)
32323241

32333242
response = Mock(status_code=200, reason='OK')
32343243
conn.servers.evacuate.return_value = (response, {})
@@ -3249,6 +3258,7 @@ def test_smart_evacuation_retry_logic(self):
32493258
"""Test smart evacuation retries on errors."""
32503259
conn = Mock()
32513260
server = Mock(id='server-789', status='ACTIVE')
3261+
setattr(server, 'OS-EXT-STS:task_state', None)
32523262

32533263
response = Mock(status_code=200, reason='OK')
32543264
conn.servers.evacuate.return_value = (response, {})

0 commit comments

Comments
 (0)