Support "-" in region name for FIP's

After moving to raw strings for regular expressions region names with a
"-" in name have been broken because raw string duplicates backslashes
and it was two backslashes in inital regular experession.
With this changes extra back slash deleted what is correct to r''
string.

Closes-Bug: 2096623
Change-Id: Ibdf8d93bdb8926b22c3ac978ccb72d795ad4c581
(cherry picked from commit fed6500d22)
(cherry picked from commit 5490df4e6b)
(cherry picked from commit a33f737640)
This commit is contained in:
mikhails
2025-01-24 06:34:35 +04:00
committed by Omer
parent f0f9ad6c4d
commit eaecbaa817
2 changed files with 32 additions and 1 deletions

View File

@@ -75,7 +75,7 @@ RE_CERT_TYPE = re.compile(r'(^[A-Z]+$)|(^[0-9]+$)')
RE_CERT_ALGO = re.compile(r'(^[A-Z]+[A-Z0-9\-]+[A-Z0-9]$)|(^[0-9]+$)')
# Floating IP regexes
RE_FIP = re.compile(r'^(?P<region>[A-Za-z0-9\\.\\-_]{1,100}):(?P<id>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$') # noqa
RE_FIP = re.compile(r'^(?P<region>[A-Za-z0-9\.\-_]{1,100}):(?P<id>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$') # noqa
# Error Validation regexes
RE_REQUIRED = re.compile(r'\'([\w]*)\' is a required property')

View File

@@ -33,6 +33,37 @@ class FloatingIPTest(oslotest.base.BaseTestCase):
)
)
self.assertEqual(
('region-one', '2fc6745d-1631-4f34-b13d-90f9014236c0'),
floatingips.fip_key_to_data(
'region-one:2fc6745d-1631-4f34-b13d-90f9014236c0'
)
)
self.assertEqual(
('region-1', '2fc6745d-1631-4f34-b13d-90f9014236c0'),
floatingips.fip_key_to_data(
'region-1:2fc6745d-1631-4f34-b13d-90f9014236c0'
)
)
self.assertEqual(
('region-1-test', '2fc6745d-1631-4f34-b13d-90f9014236c0'),
floatingips.fip_key_to_data(
'region-1-test:2fc6745d-1631-4f34-b13d-90f9014236c0'
)
)
self.assertEqual(
('region.1.test', '2fc6745d-1631-4f34-b13d-90f9014236c0'),
floatingips.fip_key_to_data(
'region.1.test:2fc6745d-1631-4f34-b13d-90f9014236c0'
)
)
self.assertEqual(
('region.test', '2fc6745d-1631-4f34-b13d-90f9014236c0'),
floatingips.fip_key_to_data(
'region.test:2fc6745d-1631-4f34-b13d-90f9014236c0'
)
)
def test_fip_key_to_data_bad_request(self):
self.assertRaisesRegex(
exceptions.BadRequest,