Fix broken gate jobs caused by oslo.db upgrades
This patch fixes an issue where the filter attribute of vnflcm subscription (v1 API) could not be retrieved because oslo.db version was updated to 15.0.0 [1]. The reason of the issue was that obj's data type, which was obtained when oslo.db was 14.1.0 and 15.0.0, was different as below: * oslo.db==14.1.0: sqlalchemy.engine.row.LegacyRow * oslo.db==15.0.0: sqlalchemy.engine.row.Row This patch changes the existence validation of the filter key for `vnf_lcm_subscription` in the `sqlalchemy.engine.row.Row` case. [1] https://review.opendev.org/c/openstack/requirements/+/909930 [2] https://pydoc.dev/sqlalchemy/latest/sqlalchemy.engine.row.Row.html Closes-Bug: #2055431 Change-Id: I8c1543bb724b6f2c4f3f4f7edecdfef063d3d9a4
This commit is contained in:
parent
8102bc3a08
commit
b885f93d64
|
@ -16,12 +16,15 @@
|
|||
import json
|
||||
|
||||
from oslo_log import log as logging
|
||||
from sqlalchemy.engine import row
|
||||
|
||||
from tacker.api import views as base
|
||||
from tacker.common.exceptions import TackerException
|
||||
from tacker.common import utils
|
||||
import tacker.conf
|
||||
from tacker.objects import fields
|
||||
from tacker.objects import vnf_instance as _vnf_instance
|
||||
from tacker.objects.vnf_lcm_subscriptions import LccnSubscriptionRequest
|
||||
|
||||
CONF = tacker.conf.CONF
|
||||
|
||||
|
@ -200,8 +203,19 @@ class ViewBuilder(base.BaseViewBuilder):
|
|||
id=decode_id)}}}
|
||||
|
||||
def _basic_subscription_info(self, vnf_lcm_subscription, filter=None):
|
||||
def key_exists(obj, key):
|
||||
# NOTE(ueha): Check `row.LegacyRow` type for back compatibility
|
||||
# of oslo.db<15.0.0 environment.
|
||||
if (isinstance(obj, LccnSubscriptionRequest) or
|
||||
isinstance(obj, row.LegacyRow)):
|
||||
return key in vnf_lcm_subscription
|
||||
elif isinstance(obj, row.Row):
|
||||
return key in vnf_lcm_subscription._mapping
|
||||
# should not occur. code bug.
|
||||
raise TackerException(f'Unexpected obj type: {type(obj)}')
|
||||
|
||||
if not filter:
|
||||
if 'filter' in vnf_lcm_subscription:
|
||||
if key_exists(vnf_lcm_subscription, 'filter'):
|
||||
filter_dict = json.loads(vnf_lcm_subscription.filter)
|
||||
return {
|
||||
'id': vnf_lcm_subscription.id,
|
||||
|
|
|
@ -4456,13 +4456,18 @@ class TestController(base.TestCase):
|
|||
@mock.patch.object(TackerManager, 'get_service_plugins',
|
||||
return_value={'VNFM': FakeVNFMPlugin()})
|
||||
def test_register_subscription(
|
||||
self, mock_get_service_plugins, mock_save):
|
||||
self, mock_get_service_plugins, mock_create):
|
||||
cfg.CONF.set_override('test_callback_uri', False,
|
||||
group='vnf_lcm')
|
||||
body = {
|
||||
'callbackUri': 'http://sample_callback_uri'
|
||||
}
|
||||
|
||||
res_create = {
|
||||
'id': uuidsentinel.subscription_id,
|
||||
'callback_uri': body['callbackUri']
|
||||
}
|
||||
mock_create.return_value = objects.LccnSubscriptionRequest(
|
||||
**res_create)
|
||||
req = fake_request.HTTPRequest.blank(
|
||||
'/subscriptions')
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
|
@ -4478,7 +4483,7 @@ class TestController(base.TestCase):
|
|||
@mock.patch.object(TackerManager, 'get_service_plugins',
|
||||
return_value={'VNFM': FakeVNFMPlugin()})
|
||||
def test_register_subscription_authentication(
|
||||
self, mock_create, mock_get_service_plugins,
|
||||
self, mock_get_service_plugins, mock_create,
|
||||
mock_test_notification):
|
||||
cfg.CONF.set_override('test_callback_uri', True,
|
||||
group='vnf_lcm')
|
||||
|
@ -4497,6 +4502,13 @@ class TestController(base.TestCase):
|
|||
}
|
||||
}
|
||||
}
|
||||
res_create = {
|
||||
'id': uuidsentinel.subscription_id,
|
||||
'callback_uri': body['callbackUri'],
|
||||
"authentication": jsonutils.dumps(body["authentication"])
|
||||
}
|
||||
mock_create.return_value = objects.LccnSubscriptionRequest(
|
||||
**res_create)
|
||||
|
||||
req = fake_request.HTTPRequest.blank(
|
||||
'/subscriptions')
|
||||
|
|
Loading…
Reference in New Issue