Fix filter data creation
The tacker-server returns 500 error if a request body of the subscription creation [1] that doesn't have `vnfInstanceSubscriptionFilter` parameter, although it's an optional parameter. The happens simply because the `vnfInstanceSubscriptionFilter` is not handled as an optional parameter in the current codes. This patch fixes such codes to correctly handle the request without a `vnfInstanceSubscriptionFilter` parameter. [1]: https://docs.openstack.org/api-ref/nfv-orchestration/v1/vnflcm.html?expanded=create-a-new-subscription-detail Change-Id: Ibf9310c4ddffcc41e23eea8c5dfd212fd3a9a145 Closes-bug: #1947303
This commit is contained in:
parent
ffe422e83d
commit
ccb0dd3d38
|
@ -308,12 +308,11 @@ def _vnf_lcm_subscriptions_id_get(context,
|
||||||
|
|
||||||
def _add_filter_data(context, subscription_id, filter):
|
def _add_filter_data(context, subscription_id, filter):
|
||||||
with db_api.context_manager.writer.using(context):
|
with db_api.context_manager.writer.using(context):
|
||||||
vnf_instance_subscription_filter = \
|
|
||||||
filter.get('vnfInstanceSubscriptionFilter')
|
|
||||||
|
|
||||||
vnf_products_from_providers = \
|
vnf_products_from_providers = (
|
||||||
vnf_instance_subscription_filter.get(
|
filter.get('vnfInstanceSubscriptionFilter', {})
|
||||||
'vnfProductsFromProviders')
|
.get('vnfProductsFromProviders'))
|
||||||
|
|
||||||
if vnf_products_from_providers:
|
if vnf_products_from_providers:
|
||||||
vnf_products_from_providers = vnf_products_from_providers[0]
|
vnf_products_from_providers = vnf_products_from_providers[0]
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ filter = {
|
||||||
"usageState": ["NOT_IN_USE"],
|
"usageState": ["NOT_IN_USE"],
|
||||||
"vnfPkgId": ["f04857cb-abdc-405f-8254-01501f3fa059"],
|
"vnfPkgId": ["f04857cb-abdc-405f-8254-01501f3fa059"],
|
||||||
"vnfdId": ["b1bb0ce7-5555-0001-95ed-4840d70a1209"],
|
"vnfdId": ["b1bb0ce7-5555-0001-95ed-4840d70a1209"],
|
||||||
|
"vnfInstanceSubscriptionFilter": {"vnfdIds": []},
|
||||||
"vnfProductsFromProviders": [
|
"vnfProductsFromProviders": [
|
||||||
{
|
{
|
||||||
"vnfProvider": "xxxxx",
|
"vnfProvider": "xxxxx",
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
import ddt
|
||||||
|
|
||||||
from tacker import context
|
from tacker import context
|
||||||
from tacker import objects
|
from tacker import objects
|
||||||
from tacker.tests.unit.db.base import SqlTestCase
|
from tacker.tests.unit.db.base import SqlTestCase
|
||||||
|
@ -19,6 +21,7 @@ from tacker.tests.unit.objects import fakes
|
||||||
from tacker.tests import uuidsentinel
|
from tacker.tests import uuidsentinel
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class TestVnfLcmSubScriptions(SqlTestCase):
|
class TestVnfLcmSubScriptions(SqlTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -112,63 +115,26 @@ class TestVnfLcmSubScriptions(SqlTestCase):
|
||||||
return subscription_obj
|
return subscription_obj
|
||||||
|
|
||||||
@mock.patch.object(objects.vnf_lcm_subscriptions,
|
@mock.patch.object(objects.vnf_lcm_subscriptions,
|
||||||
'_vnf_lcm_subscriptions_create')
|
'_vnf_lcm_subscriptions_id_get')
|
||||||
def test_create(self, mock_vnf_lcm_subscriptions_create):
|
@ddt.data(
|
||||||
filter = fakes.filter
|
fakes.filter,
|
||||||
subscription_obj = \
|
{"notificationTypes": ["VnfIdentifierCreationNotification"]}
|
||||||
|
)
|
||||||
|
def test_create(self, filter, mock_vnf_lcm_subscriptions_id_get):
|
||||||
|
"""Test that the `create` method returns a created filter
|
||||||
|
|
||||||
|
Also, test `_vnf_lcm_subscriptions_create` method, which is called
|
||||||
|
from the `create` method, works correctly and a created filter will be
|
||||||
|
returned.
|
||||||
|
|
||||||
|
Case 1: All available parameters are set
|
||||||
|
Case 2: Only the required parameter is set
|
||||||
|
"""
|
||||||
|
|
||||||
|
mock_vnf_lcm_subscriptions_id_get.return_value = None
|
||||||
|
subscription_obj = (
|
||||||
objects.vnf_lcm_subscriptions.LccnSubscriptionRequest(
|
objects.vnf_lcm_subscriptions.LccnSubscriptionRequest(
|
||||||
context=self.context)
|
context=self.context, **fakes.subscription_data))
|
||||||
mock_vnf_lcm_subscriptions_create.return_value = \
|
|
||||||
'{\
|
|
||||||
"filter": "{"operationStates": ["COMPLETED"],\
|
|
||||||
"vnfInstanceNames": ["xxxxxxxxxxxxxxxxxx"],\
|
|
||||||
"operationTypes": ["INSTANTIATE"],\
|
|
||||||
"vnfdIds": ["405d73c7-e964-4c8b-a914-41478ccd7c42"],\
|
|
||||||
"vnfProductsFromProviders": [{\
|
|
||||||
"vnfProvider": "x2x", \
|
|
||||||
"vnfProducts": [{\
|
|
||||||
"vnfProductName": "x2xx", \
|
|
||||||
"versions": [{\
|
|
||||||
"vnfSoftwareVersion": "xx2XX", \
|
|
||||||
"vnfdVersions": ["ss2"]\
|
|
||||||
}]\
|
|
||||||
}]\
|
|
||||||
}, \
|
|
||||||
{\
|
|
||||||
"vnfProvider": "z2z",\
|
|
||||||
"vnfProducts": [{\
|
|
||||||
"vnfProductName": "z2zx", \
|
|
||||||
"versions": [{\
|
|
||||||
"vnfSoftwareVersion": "xx3XX",\
|
|
||||||
"vnfdVersions": \
|
|
||||||
["s3sx", "s3sa"]\
|
|
||||||
}\
|
|
||||||
]},\
|
|
||||||
{\
|
|
||||||
"vnfProductName": "zz3ex",\
|
|
||||||
"versions": [{\
|
|
||||||
"vnfSoftwareVersion": "xxe3eXz",\
|
|
||||||
"vnfdVersions": ["ss3xz", "s3esaz"]\
|
|
||||||
},\
|
|
||||||
{\
|
|
||||||
"vnfSoftwareVersion": "xxeeeXw", \
|
|
||||||
"vnfdVersions": ["ss3xw", "ss3w"]\
|
|
||||||
}]\
|
|
||||||
}]\
|
|
||||||
}],\
|
|
||||||
"notificationTypes": [\
|
|
||||||
"VnfLcmOperationOccurrenceNotification"],\
|
|
||||||
"vnfInstanceIds": ["fb0b9a12-4b55-47ac-9ca8-5fdd52c4c07f"]}",\
|
|
||||||
"callbackUri": "http://localhost/xxx",\
|
|
||||||
"_links": {\
|
|
||||||
"self": {\
|
|
||||||
"href":\
|
|
||||||
"http://localhost:9890//vnflcm/v1/subscriptions\
|
|
||||||
/530a3c43-043a-4b84-9d65-aa0df49f7ced"\
|
|
||||||
}\
|
|
||||||
},\
|
|
||||||
"id": "530a3c43-043a-4b84-9d65-aa0df49f7ced"\
|
|
||||||
}'
|
|
||||||
|
|
||||||
result = subscription_obj.create(filter)
|
result = subscription_obj.create(filter)
|
||||||
self.assertTrue(filter, result)
|
self.assertTrue(filter, result)
|
||||||
|
|
Loading…
Reference in New Issue