Merge "Fix create duplicated subscriptions"
This commit is contained in:
commit
0f4555f2ba
|
@ -187,7 +187,7 @@ _vimConnectionInfo = {
|
||||||
_versions = {
|
_versions = {
|
||||||
'type': 'array',
|
'type': 'array',
|
||||||
'items': {
|
'items': {
|
||||||
'type': 'objects',
|
'type': 'object',
|
||||||
'properties': {
|
'properties': {
|
||||||
'vnfSoftwareVersion': {'type': 'string'},
|
'vnfSoftwareVersion': {'type': 'string'},
|
||||||
'vnfdVersions': {
|
'vnfdVersions': {
|
||||||
|
@ -212,15 +212,15 @@ _vnf_products = {
|
||||||
}
|
}
|
||||||
|
|
||||||
_vnf_products_from_providers = {
|
_vnf_products_from_providers = {
|
||||||
'type': 'object',
|
'type': 'array',
|
||||||
'properties': {
|
'items': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'properties': {
|
'properties': {
|
||||||
'vnfProvider': {'type': 'string'},
|
'vnfProvider': {'type': 'string'},
|
||||||
'vnfProducts': _vnf_products
|
'vnfProducts': _vnf_products
|
||||||
}
|
},
|
||||||
},
|
'required': ['vnfProvider']
|
||||||
'required': ['vnfProvider']
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_lifecycle_change_notifications_filter = {
|
_lifecycle_change_notifications_filter = {
|
||||||
|
|
|
@ -968,21 +968,14 @@ class VnfLcmController(wsgi.Controller):
|
||||||
vnf_lcm_subscription = vnf_lcm_subscription.create(filter)
|
vnf_lcm_subscription = vnf_lcm_subscription.create(filter)
|
||||||
LOG.debug("vnf_lcm_subscription %s" % vnf_lcm_subscription)
|
LOG.debug("vnf_lcm_subscription %s" % vnf_lcm_subscription)
|
||||||
except exceptions.SeeOther as e:
|
except exceptions.SeeOther as e:
|
||||||
if re.search("^303", str(e)):
|
res = webob.Response(content_type='application/json')
|
||||||
res = self._make_problem_detail(
|
res.status_int = http_client.SEE_OTHER.value
|
||||||
"See Other", 303, title='See Other')
|
location = (
|
||||||
link = (
|
'Location',
|
||||||
'LINK',
|
CONF.vnf_lcm.endpoint_url.rstrip("/") +
|
||||||
CONF.vnf_lcm.endpoint_url.rstrip("/") +
|
"/vnflcm/v1/subscriptions/" + str(e))
|
||||||
"/vnflcm/v1/subscriptions/" +
|
res.headerlist.append(location)
|
||||||
str(e)[
|
return res
|
||||||
3:])
|
|
||||||
res.headerlist.append(link)
|
|
||||||
return res
|
|
||||||
else:
|
|
||||||
LOG.error(traceback.format_exc())
|
|
||||||
return self._make_problem_detail(
|
|
||||||
str(e), 500, title='Internal Server Error')
|
|
||||||
|
|
||||||
result = self._view_builder.subscription_create(vnf_lcm_subscription,
|
result = self._view_builder.subscription_create(vnf_lcm_subscription,
|
||||||
filter)
|
filter)
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Copyright 2021 OpenStack Foundation
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""alter vnfd_ids, vnf_instance_ids, vnf_instance_names
|
||||||
|
columns of vnf_lcm_filters
|
||||||
|
|
||||||
|
Revision ID: 70df18f71ba2
|
||||||
|
Revises: a23ebee909a8
|
||||||
|
Create Date: 2021-06-16 14:26:51.998033
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '70df18f71ba2'
|
||||||
|
down_revision = 'a23ebee909a8'
|
||||||
|
|
||||||
|
from alembic import op # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(active_plugins=None, options=None):
|
||||||
|
alter_sql_vnfd_ids = "ALTER TABLE vnf_lcm_filters CHANGE \
|
||||||
|
vnfd_ids vnfd_ids mediumtext GENERATED ALWAYS AS \
|
||||||
|
(json_unquote(json_extract(`filter`, \
|
||||||
|
'$.vnfInstanceSubscriptionFilter.vnfdIds'))) VIRTUAL;"
|
||||||
|
|
||||||
|
alter_sql_vnf_instance_ids = "ALTER TABLE vnf_lcm_filters CHANGE \
|
||||||
|
vnf_instance_ids vnf_instance_ids mediumtext GENERATED ALWAYS AS \
|
||||||
|
(json_unquote(json_extract(`filter`, \
|
||||||
|
'$.vnfInstanceSubscriptionFilter.vnfInstanceIds'))) VIRTUAL;"
|
||||||
|
|
||||||
|
alter_sql_vnf_instance_names = "ALTER TABLE vnf_lcm_filters CHANGE \
|
||||||
|
vnf_instance_names vnf_instance_names mediumtext GENERATED \
|
||||||
|
ALWAYS AS (json_unquote(json_extract(`filter`, \
|
||||||
|
'$.vnfInstanceSubscriptionFilter.vnfInstanceNames'))) \
|
||||||
|
VIRTUAL;"
|
||||||
|
|
||||||
|
op.execute(alter_sql_vnfd_ids)
|
||||||
|
op.execute(alter_sql_vnf_instance_ids)
|
||||||
|
op.execute(alter_sql_vnf_instance_names)
|
|
@ -1 +1 @@
|
||||||
a23ebee909a8
|
70df18f71ba2
|
||||||
|
|
|
@ -53,19 +53,24 @@ def _get_vnf_subscription_filter_values(vnf_subscription_filter):
|
||||||
vnf_instance_names = vnf_subscription_filter.get('vnfInstanceNames', [])
|
vnf_instance_names = vnf_subscription_filter.get('vnfInstanceNames', [])
|
||||||
|
|
||||||
vnfd_products_from_providers = vnf_subscription_filter.get(
|
vnfd_products_from_providers = vnf_subscription_filter.get(
|
||||||
'vnfProductsFromProviders', {})
|
'vnfProductsFromProviders', [])
|
||||||
vnf_provider = vnfd_products_from_providers.get('vnfProvider', "")
|
|
||||||
vnf_products = vnfd_products_from_providers.get('vnfProducts', [])
|
|
||||||
|
|
||||||
|
vnf_provider = ""
|
||||||
vnf_product_name = ""
|
vnf_product_name = ""
|
||||||
vnf_software_version = ""
|
vnf_software_version = ""
|
||||||
vnfd_versions = []
|
vnfd_versions = []
|
||||||
if vnf_products:
|
if vnfd_products_from_providers:
|
||||||
vnf_product_name = vnf_products[0].get('vnfProductName', "")
|
vnfd_products_from_providers = vnfd_products_from_providers[0]
|
||||||
versions = vnf_products[0].get('versions', [])
|
vnf_provider = vnfd_products_from_providers.get('vnfProvider', "")
|
||||||
if versions:
|
vnf_products = vnfd_products_from_providers.get('vnfProducts', [])
|
||||||
vnf_software_version = versions[0].get('vnfSoftwareVersion', "")
|
|
||||||
vnfd_versions = versions[0].get('vnfdVersions', [])
|
if vnf_products:
|
||||||
|
vnf_product_name = vnf_products[0].get('vnfProductName', "")
|
||||||
|
versions = vnf_products[0].get('versions', [])
|
||||||
|
if versions:
|
||||||
|
vnf_software_version = \
|
||||||
|
versions[0].get('vnfSoftwareVersion', "")
|
||||||
|
vnfd_versions = versions[0].get('vnfdVersions', [])
|
||||||
|
|
||||||
vnf_subscription_array = [
|
vnf_subscription_array = [
|
||||||
{'vnfdIds': vnfd_ids},
|
{'vnfdIds': vnfd_ids},
|
||||||
|
@ -233,19 +238,26 @@ def _vnf_lcm_subscriptions_id_get(context,
|
||||||
column_list = _get_vnf_subscription_filter_values(
|
column_list = _get_vnf_subscription_filter_values(
|
||||||
vnf_instance_subscription_filter)
|
vnf_instance_subscription_filter)
|
||||||
|
|
||||||
|
sql_lst = [sql]
|
||||||
for column in column_list:
|
for column in column_list:
|
||||||
for key in column:
|
for key in column:
|
||||||
if key in VNF_INSTANCE_SUBSCRIPTION_FILTER:
|
if key in VNF_INSTANCE_SUBSCRIPTION_FILTER:
|
||||||
value = column[key]
|
value = column[key]
|
||||||
if key in VNF_INSTANCE_SUBSCRIPTION_FILTER_LISTS:
|
if key in VNF_INSTANCE_SUBSCRIPTION_FILTER_LISTS:
|
||||||
value = _make_list(value)
|
if value:
|
||||||
|
value = _make_list(value)
|
||||||
|
sql_lst.append(
|
||||||
|
" JSON_CONTAINS({}, '{}') and ".format(
|
||||||
|
convert_string_to_snakecase(key), value))
|
||||||
|
else:
|
||||||
|
sql_lst.append(" {}_len=0 and ".format(
|
||||||
|
convert_string_to_snakecase(key)))
|
||||||
else:
|
else:
|
||||||
value = '"{}"'.format(value)
|
sql_lst.append(" {}='{}' and ".format(
|
||||||
sql = (sql + " JSON_CONTAINS({}, '{}') and ".format(
|
convert_string_to_snakecase(key), value))
|
||||||
convert_string_to_snakecase(key),
|
|
||||||
value
|
|
||||||
))
|
|
||||||
included_in_filter.append(key)
|
included_in_filter.append(key)
|
||||||
|
sql = ''.join(sql_lst)
|
||||||
|
|
||||||
not_included_in_filter = list(
|
not_included_in_filter = list(
|
||||||
set(VNF_INSTANCE_SUBSCRIPTION_FILTER_LISTS) -
|
set(VNF_INSTANCE_SUBSCRIPTION_FILTER_LISTS) -
|
||||||
|
@ -302,6 +314,8 @@ def _add_filter_data(context, subscription_id, filter):
|
||||||
vnf_products_from_providers = \
|
vnf_products_from_providers = \
|
||||||
vnf_instance_subscription_filter.get(
|
vnf_instance_subscription_filter.get(
|
||||||
'vnfProductsFromProviders')
|
'vnfProductsFromProviders')
|
||||||
|
if vnf_products_from_providers:
|
||||||
|
vnf_products_from_providers = vnf_products_from_providers[0]
|
||||||
|
|
||||||
new_entries = []
|
new_entries = []
|
||||||
new_entries.append({"subscription_uuid": subscription_id,
|
new_entries.append({"subscription_uuid": subscription_id,
|
||||||
|
@ -387,7 +401,7 @@ def _vnf_lcm_subscriptions_create(context, values, filter):
|
||||||
vnf_instance_subscription_filter=subscription_filter)
|
vnf_instance_subscription_filter=subscription_filter)
|
||||||
|
|
||||||
if vnf_lcm_subscriptions_id:
|
if vnf_lcm_subscriptions_id:
|
||||||
raise Exception("303" + vnf_lcm_subscriptions_id)
|
raise exceptions.SeeOther(message=vnf_lcm_subscriptions_id.id)
|
||||||
|
|
||||||
_add_filter_data(context, values.id, filter)
|
_add_filter_data(context, values.id, filter)
|
||||||
|
|
||||||
|
@ -396,7 +410,7 @@ def _vnf_lcm_subscriptions_create(context, values, filter):
|
||||||
callbackUri)
|
callbackUri)
|
||||||
|
|
||||||
if vnf_lcm_subscriptions_id:
|
if vnf_lcm_subscriptions_id:
|
||||||
raise Exception("303" + vnf_lcm_subscriptions_id.id)
|
raise exceptions.SeeOther(message=vnf_lcm_subscriptions_id.id)
|
||||||
_add_filter_data(context, values.id, {})
|
_add_filter_data(context, values.id, {})
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Subscription:
|
||||||
"filter": {
|
"filter": {
|
||||||
"vnfInstanceSubscriptionFilter": {
|
"vnfInstanceSubscriptionFilter": {
|
||||||
"vnfdIds": ["b1bb0ce7-ebca-4fa7-95ed-4840d7000000"],
|
"vnfdIds": ["b1bb0ce7-ebca-4fa7-95ed-4840d7000000"],
|
||||||
"vnfProductsFromProviders": {
|
"vnfProductsFromProviders": [{
|
||||||
"vnfProvider": "Company",
|
"vnfProvider": "Company",
|
||||||
"vnfProducts": [
|
"vnfProducts": [
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ class Subscription:
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}]
|
||||||
},
|
},
|
||||||
"notificationTypes": [
|
"notificationTypes": [
|
||||||
"VnfLcmOperationOccurrenceNotification",
|
"VnfLcmOperationOccurrenceNotification",
|
||||||
|
|
|
@ -3942,7 +3942,7 @@ class TestController(base.TestCase):
|
||||||
'notificationTypes': ['VnfLcmOperationOccurrenceNotification'],
|
'notificationTypes': ['VnfLcmOperationOccurrenceNotification'],
|
||||||
'vnfInstanceSubscriptionFilter': {
|
'vnfInstanceSubscriptionFilter': {
|
||||||
"vnfdIds": [],
|
"vnfdIds": [],
|
||||||
"vnfProductsFromProviders": {
|
"vnfProductsFromProviders": [{
|
||||||
"vnfProvider": "Vnf Provider 1",
|
"vnfProvider": "Vnf Provider 1",
|
||||||
"vnfProducts": [
|
"vnfProducts": [
|
||||||
{
|
{
|
||||||
|
@ -3955,7 +3955,7 @@ class TestController(base.TestCase):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue