Merge "Check for standard-attr-tag
Neutron extension"
This commit is contained in:
commit
5bf52b6b14
kuryr_libnetwork
@ -43,6 +43,7 @@ LOG = log.getLogger(__name__)
|
||||
MANDATORY_NEUTRON_EXTENSION = "subnet_allocation"
|
||||
TAG_NEUTRON_EXTENSION = "tag"
|
||||
TAG_EXT_NEUTRON_EXTENSION = "tag-ext"
|
||||
TAG_STANDARD_NEUTRON_EXTENSION = 'standard-attr-tag'
|
||||
SUBNET_POOLS_V4 = []
|
||||
SUBNET_POOLS_V6 = []
|
||||
DEFAULT_DRIVER = driver.get_driver_instance()
|
||||
@ -83,20 +84,36 @@ def check_for_neutron_ext_support():
|
||||
.format(MANDATORY_NEUTRON_EXTENSION))
|
||||
|
||||
|
||||
def check_for_neutron_tag_support(ext_name):
|
||||
"""Validates tag and tag-ext extension support availability in Neutron."""
|
||||
if ext_name == TAG_EXT_NEUTRON_EXTENSION:
|
||||
ext_rename = "tag_ext"
|
||||
else:
|
||||
ext_rename = ext_name
|
||||
setattr(app, ext_rename, True)
|
||||
def check_for_neutron_tag_support():
|
||||
"""Validates tagging extensions availability in Neutron.
|
||||
|
||||
Checks if either tag, tag-ext or standard-attr-tag is available and sets
|
||||
``app`` properties accordingly.
|
||||
"""
|
||||
|
||||
app.tag_ext = True
|
||||
app.tag = True
|
||||
|
||||
# Check for modern extension first.
|
||||
try:
|
||||
app.neutron.show_extension(ext_name)
|
||||
except n_exceptions.NeutronClientException as e:
|
||||
setattr(app, ext_rename, False)
|
||||
if e.status_code == n_exceptions.NotFound.status_code:
|
||||
LOG.warning("Neutron extension %s not supported. "
|
||||
"Continue without using them.", ext_name)
|
||||
app.neutron.show_extension(TAG_STANDARD_NEUTRON_EXTENSION)
|
||||
except n_exceptions.NeutronClientException:
|
||||
pass
|
||||
else:
|
||||
# Okay, this means we have functionality of both tag and tag_ext,
|
||||
# we're good to go!
|
||||
return
|
||||
|
||||
# Fallback to legacy extensions.
|
||||
for ext in (TAG_NEUTRON_EXTENSION, TAG_EXT_NEUTRON_EXTENSION):
|
||||
try:
|
||||
app.neutron.show_extension(ext)
|
||||
except n_exceptions.NeutronClientException as e:
|
||||
ext_param = ext.replace('-', '_') # identifiers cannot have '-'
|
||||
setattr(app, ext_param, False)
|
||||
if e.status_code == n_exceptions.NotFound.status_code:
|
||||
LOG.warning("Neutron extension %s not supported. "
|
||||
"Continue without using them.", ext)
|
||||
|
||||
|
||||
def load_default_subnet_pools():
|
||||
|
@ -26,10 +26,7 @@ def configure_app():
|
||||
log.setup(config.CONF, 'kuryr')
|
||||
controllers.neutron_client()
|
||||
controllers.check_for_neutron_ext_support()
|
||||
controllers.check_for_neutron_tag_support(
|
||||
controllers.TAG_NEUTRON_EXTENSION)
|
||||
controllers.check_for_neutron_tag_support(
|
||||
controllers.TAG_EXT_NEUTRON_EXTENSION)
|
||||
controllers.check_for_neutron_tag_support()
|
||||
controllers.load_default_subnet_pools()
|
||||
controllers.load_port_driver()
|
||||
|
||||
|
@ -60,10 +60,7 @@ class ConfigurationTest(base.TestKuryrBase):
|
||||
kuryr_uri = parse.urlparse(config.CONF.kuryr_uri)
|
||||
mock_neutron_client.assert_called_once()
|
||||
mock_check_neutron_ext_support.assert_called_once()
|
||||
mock_check_for_neutron_tag_support.assert_any_call(
|
||||
controllers.TAG_NEUTRON_EXTENSION)
|
||||
mock_check_for_neutron_tag_support.assert_any_call(
|
||||
controllers.TAG_EXT_NEUTRON_EXTENSION)
|
||||
mock_check_for_neutron_tag_support.assert_called_once_with()
|
||||
mock_run.assert_called_once_with(kuryr_uri.hostname, 23750,
|
||||
ssl_context=None)
|
||||
|
||||
@ -81,28 +78,34 @@ class ConfigurationTest(base.TestKuryrBase):
|
||||
mock_extension.assert_called_once_with(ext_alias)
|
||||
|
||||
@mock.patch('kuryr_libnetwork.controllers.app.neutron.show_extension')
|
||||
@ddt.data('tag', 'tag-ext')
|
||||
def test_check_for_neutron_tag_support_with_ex(self,
|
||||
ext_name,
|
||||
mock_extension):
|
||||
err = n_exceptions.NotFound.status_code
|
||||
ext_not_found_ex = n_exceptions.NeutronClientException(
|
||||
status_code=err,
|
||||
message="")
|
||||
mock_extension.side_effect = ext_not_found_ex
|
||||
controllers.check_for_neutron_tag_support(ext_name)
|
||||
mock_extension.assert_called_once_with(ext_name)
|
||||
def test_check_for_neutron_tag_support_with_modern_ext(self,
|
||||
mock_extension):
|
||||
controllers.check_for_neutron_tag_support()
|
||||
mock_extension.assert_called_once_with('standard-attr-tag')
|
||||
self.assertTrue(controllers.app.tag)
|
||||
self.assertTrue(controllers.app.tag_ext)
|
||||
|
||||
@mock.patch('kuryr_libnetwork.controllers.app.neutron.show_extension')
|
||||
@ddt.data('fake_ext')
|
||||
def test_check_for_neutron_tag_support_wrong_ext_name_with_ex(
|
||||
self,
|
||||
ext_name,
|
||||
mock_extension):
|
||||
@ddt.data({'tag': True, 'tag-ext': True},
|
||||
{'tag': True, 'tag-ext': False},
|
||||
{'tag': False, 'tag-ext': True},
|
||||
{'tag': False, 'tag-ext': False})
|
||||
def test_check_for_neutron_tag_support_with_legacy_ext(self, ext_matrix,
|
||||
mock_extension):
|
||||
err = n_exceptions.NotFound.status_code
|
||||
ext_not_found_ex = n_exceptions.NeutronClientException(
|
||||
status_code=err,
|
||||
message="")
|
||||
mock_extension.side_effect = ext_not_found_ex
|
||||
controllers.check_for_neutron_tag_support(ext_name)
|
||||
mock_extension.assert_called_once_with(ext_name)
|
||||
|
||||
def mock_fn(ext):
|
||||
if not ext_matrix.get(ext, False):
|
||||
raise ext_not_found_ex
|
||||
|
||||
mock_extension.side_effect = mock_fn
|
||||
controllers.check_for_neutron_tag_support()
|
||||
mock_extension.assert_any_call('standard-attr-tag')
|
||||
mock_extension.assert_any_call('tag')
|
||||
mock_extension.assert_any_call('tag-ext')
|
||||
|
||||
self.assertEqual(controllers.app.tag, ext_matrix['tag'])
|
||||
self.assertEqual(controllers.app.tag_ext, ext_matrix['tag-ext'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user