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
This commit is contained in:
mikhails
2025-01-24 06:34:35 +04:00
parent d6e3f96cd8
commit fed6500d22
2 changed files with 32 additions and 1 deletions

View File

@@ -76,7 +76,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

@@ -35,6 +35,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,