Skip to content

Commit 60ac578

Browse files
authored
Merge pull request #77 from stackhpc/upstream/master-2025-10-20
Synchronise master with upstream
2 parents 8e99b4f + 606dc8e commit 60ac578

File tree

4 files changed

+1592
-29
lines changed

4 files changed

+1592
-29
lines changed

ovn_octavia_provider/tests/unit/hacking/test_checks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ def test_assertempty(self):
169169
self.assertEqual(
170170
1, len(list(checks.check_assertempty(fail_code % (ec, ec),
171171
"ovn_octavia_provider/tests/test_assert.py"))))
172+
self.assertEqual(
173+
0, len(list(checks.check_assertempty(
174+
pass_code1 % (ec, ec),
175+
"ovn_octavia_provider/tests/test_file.py"))))
176+
self.assertEqual(
177+
0, len(list(checks.check_assertempty(fail_code % (ec, ec),
178+
"ovn_octavia_provider/test_fake/test_assert.py"))))
172179
self.assertEqual(
173180
0, len(list(checks.check_asserttruefalse(pass_code1 % (ec, ec),
174181
"ovn_octavia_provider/tests/test_assert.py"))))
@@ -270,3 +277,20 @@ def test_check_no_import_mock(self):
270277
fail_line,
271278
"ovn_octavia_provider/tests/test_fake.py",
272279
True))))
280+
281+
def test_check_assertcountequal(self):
282+
filename = "ovn_octavia_provider/tests/test_example.py"
283+
logical_line = "self.assertItemsEqual(a, b)"
284+
result = list(checks.check_assertcountequal(logical_line, filename))
285+
expected_msg = ("N348: Use assertCountEqual(expected, observed) "
286+
"instead of assertItemsEqual(observed, expected)")
287+
self.assertEqual(len(result), 1)
288+
self.assertEqual(result[0][1], expected_msg)
289+
290+
logical_line = "self.assertEqual(a, b)"
291+
result = list(checks.check_assertcountequal(logical_line, filename))
292+
self.assertEqual([], result)
293+
294+
filename = "some_other_path/test_example.py"
295+
result = list(checks.check_assertcountequal(logical_line, filename))
296+
self.assertEqual([], result)

ovn_octavia_provider/tests/unit/test_driver.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,46 @@ def test_create_vip_port_exception(self):
15221522
self.vip_dict,
15231523
[])
15241524

1525+
def test_create_vip_port_exception_with_details(self):
1526+
exception_with_details = Exception()
1527+
exception_with_details.details = "Network not found"
1528+
with mock.patch.object(ovn_helper.OvnProviderHelper, 'create_vip_port',
1529+
side_effect=exception_with_details):
1530+
self.assertRaises(
1531+
exceptions.DriverError,
1532+
self.driver.create_vip_port,
1533+
self.loadbalancer_id,
1534+
self.project_id,
1535+
self.vip_dict,
1536+
[])
1537+
1538+
def test_create_vip_port_exception_with_message(self):
1539+
exception_with_message = Exception()
1540+
exception_with_message.message = "Port creation failed"
1541+
with mock.patch.object(ovn_helper.OvnProviderHelper, 'create_vip_port',
1542+
side_effect=exception_with_message):
1543+
self.assertRaises(
1544+
exceptions.DriverError,
1545+
self.driver.create_vip_port,
1546+
self.loadbalancer_id,
1547+
self.project_id,
1548+
self.vip_dict,
1549+
[])
1550+
1551+
def test_create_vip_port_exception_with_both_details_and_message(self):
1552+
exception_with_both = Exception()
1553+
exception_with_both.details = "Network not found"
1554+
exception_with_both.message = "Port creation failed"
1555+
with mock.patch.object(ovn_helper.OvnProviderHelper, 'create_vip_port',
1556+
side_effect=exception_with_both):
1557+
self.assertRaises(
1558+
exceptions.DriverError,
1559+
self.driver.create_vip_port,
1560+
self.loadbalancer_id,
1561+
self.project_id,
1562+
self.vip_dict,
1563+
[])
1564+
15251565
def test_health_monitor_create(self):
15261566
info = {'id': self.ref_health_monitor.healthmonitor_id,
15271567
'pool_id': self.ref_health_monitor.pool_id,
@@ -1686,6 +1726,39 @@ def test_ensure_loadbalancer_lb_not_found_without_listeners_or_pools(
16861726
}
16871727
mock_update_status.assert_called_once_with(expected_status)
16881728

1729+
@mock.patch.object(ovn_driver.OvnProviderDriver,
1730+
'_check_for_supported_protocols')
1731+
@mock.patch.object(ovn_driver.OvnProviderDriver,
1732+
'_check_for_supported_algorithms')
1733+
@mock.patch.object(ovn_driver.OvnProviderDriver,
1734+
'_check_for_supported_session_persistence')
1735+
def test_get_pool_request_info_skips_session_persistence(
1736+
self, mck_chck_sup_ses_per, mck_chck_sup_alg, mck_chck_sup_pro):
1737+
pool = mock.Mock()
1738+
pool.protocol = 'TCP'
1739+
pool.lb_algorithm = 'SOURCE_IP_PORT'
1740+
pool.pool_id = 'pool-001'
1741+
pool.loadbalancer_id = 'lb-123'
1742+
pool.listener_id = 'listener-999'
1743+
pool.session_persistence = data_models.UnsetType()
1744+
pool.admin_state_up = data_models.UnsetType()
1745+
1746+
expected = {
1747+
'id': pool.pool_id,
1748+
'loadbalancer_id': pool.loadbalancer_id,
1749+
'protocol': pool.protocol,
1750+
'lb_algorithm': pool.lb_algorithm,
1751+
'listener_id': pool.listener_id,
1752+
'admin_state_up': True
1753+
}
1754+
1755+
result = self.driver._get_pool_request_info(pool)
1756+
1757+
mck_chck_sup_pro.assert_called_once_with(pool.protocol)
1758+
mck_chck_sup_alg.assert_called_once_with(pool.lb_algorithm)
1759+
mck_chck_sup_ses_per.assert_not_called()
1760+
self.assertEqual(result, expected)
1761+
16891762
@mock.patch.object(ovn_helper.OvnProviderHelper,
16901763
'_update_status_to_octavia')
16911764
@mock.patch.object(ovn_helper.OvnProviderHelper, 'member_create')

0 commit comments

Comments
 (0)