Merge "Refactor vnfm_db"
This commit is contained in:
commit
4d6031883c
@ -579,9 +579,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
|
|||||||
context,
|
context,
|
||||||
vnf_info,
|
vnf_info,
|
||||||
previous_statuses,
|
previous_statuses,
|
||||||
status,
|
status):
|
||||||
vnf_instance=None,
|
|
||||||
vnf_lcm_op_occ=None):
|
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
(self._model_query(context, VNF).
|
(self._model_query(context, VNF).
|
||||||
@ -606,11 +604,6 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
|
|||||||
res_state=status,
|
res_state=status,
|
||||||
evt_type=constants.RES_EVT_SCALE,
|
evt_type=constants.RES_EVT_SCALE,
|
||||||
tstamp=timestamp)
|
tstamp=timestamp)
|
||||||
if vnf_lcm_op_occ:
|
|
||||||
vnf_lcm_op_occ.state_entered_time = timestamp
|
|
||||||
vnf_lcm_op_occ.save()
|
|
||||||
if vnf_instance:
|
|
||||||
vnf_instance.save()
|
|
||||||
|
|
||||||
def _update_vnf_pre(self, context, vnf_id, new_status):
|
def _update_vnf_pre(self, context, vnf_id, new_status):
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
@ -883,47 +876,31 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
|
|||||||
context,
|
context,
|
||||||
vnf_info):
|
vnf_info):
|
||||||
vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ']
|
vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ']
|
||||||
|
evt_type = constants.RES_EVT_CREATE
|
||||||
if vnf_lcm_op_occs.operation == 'SCALE':
|
if vnf_lcm_op_occs.operation == 'SCALE':
|
||||||
self._cos_db_plg.create_event(
|
evt_type = constants.RES_EVT_SCALE,
|
||||||
context, res_id=vnf_info['id'],
|
self._cos_db_plg.create_event(context, res_id=vnf_info['id'],
|
||||||
res_type=constants.RES_TYPE_VNF,
|
res_type=constants.RES_TYPE_VNF,
|
||||||
res_state='ERROR',
|
res_state='ERROR', evt_type=evt_type,
|
||||||
evt_type=constants.RES_EVT_SCALE,
|
|
||||||
tstamp=timeutils.utcnow())
|
|
||||||
else:
|
|
||||||
self._cos_db_plg.create_event(
|
|
||||||
context, res_id=vnf_info['id'],
|
|
||||||
res_type=constants.RES_TYPE_VNF,
|
|
||||||
res_state='ERROR',
|
|
||||||
evt_type=constants.RES_EVT_CREATE,
|
|
||||||
tstamp=timeutils.utcnow())
|
tstamp=timeutils.utcnow())
|
||||||
|
|
||||||
def _update_vnf_rollback_pre(self,
|
def _update_vnf_rollback_pre(self,
|
||||||
context,
|
context,
|
||||||
vnf_info):
|
vnf_info):
|
||||||
vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ']
|
vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ']
|
||||||
|
evt_type = constants.RES_EVT_CREATE
|
||||||
if vnf_lcm_op_occs.operation == 'SCALE':
|
if vnf_lcm_op_occs.operation == 'SCALE':
|
||||||
self._cos_db_plg.create_event(
|
evt_type = constants.RES_EVT_CREATE
|
||||||
context, res_id=vnf_info['id'],
|
self._cos_db_plg.create_event(context, res_id=vnf_info['id'],
|
||||||
res_type=constants.RES_TYPE_VNF,
|
res_type=constants.RES_TYPE_VNF,
|
||||||
res_state='ROLL_BACK',
|
res_state='ROLL_BACK', evt_type=evt_type,
|
||||||
evt_type=constants.RES_EVT_SCALE,
|
|
||||||
tstamp=timeutils.utcnow())
|
|
||||||
else:
|
|
||||||
self._cos_db_plg.create_event(
|
|
||||||
context, res_id=vnf_info['id'],
|
|
||||||
res_type=constants.RES_TYPE_VNF,
|
|
||||||
res_state='ROLL_BACK',
|
|
||||||
evt_type=constants.RES_EVT_CREATE,
|
|
||||||
tstamp=timeutils.utcnow())
|
tstamp=timeutils.utcnow())
|
||||||
|
|
||||||
def _update_vnf_rollback(self,
|
def _update_vnf_rollback(self,
|
||||||
context,
|
context,
|
||||||
vnf_info,
|
vnf_info,
|
||||||
previous_statuses,
|
previous_statuses,
|
||||||
status,
|
status):
|
||||||
vnf_instance=None,
|
|
||||||
vnf_lcm_op_occ=None):
|
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
(self._model_query(context, VNF).
|
(self._model_query(context, VNF).
|
||||||
@ -939,26 +916,14 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
|
|||||||
delete(synchronize_session='fetch'))
|
delete(synchronize_session='fetch'))
|
||||||
|
|
||||||
vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ']
|
vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ']
|
||||||
|
evt_type = constants.RES_EVT_CREATE
|
||||||
if vnf_lcm_op_occs.operation == 'SCALE':
|
if vnf_lcm_op_occs.operation == 'SCALE':
|
||||||
for (key, value) in dev_attrs.items():
|
for (key, value) in dev_attrs.items():
|
||||||
if 'vim_auth' not in key:
|
if 'vim_auth' not in key:
|
||||||
self._vnf_attribute_update_or_create(
|
self._vnf_attribute_update_or_create(
|
||||||
context, vnf_info['id'], key, value)
|
context, vnf_info['id'], key, value)
|
||||||
self._cos_db_plg.create_event(
|
evt_type = constants.RES_EVT_SCALE
|
||||||
context, res_id=vnf_info['id'],
|
self._cos_db_plg.create_event(context, res_id=vnf_info['id'],
|
||||||
res_type=constants.RES_TYPE_VNF,
|
res_type=constants.RES_TYPE_VNF,
|
||||||
res_state=status,
|
res_state=status, evt_type=evt_type,
|
||||||
evt_type=constants.RES_EVT_SCALE,
|
|
||||||
tstamp=timestamp)
|
tstamp=timestamp)
|
||||||
else:
|
|
||||||
self._cos_db_plg.create_event(
|
|
||||||
context, res_id=vnf_info['id'],
|
|
||||||
res_type=constants.RES_TYPE_VNF,
|
|
||||||
res_state=status,
|
|
||||||
evt_type=constants.RES_EVT_CREATE,
|
|
||||||
tstamp=timestamp)
|
|
||||||
if vnf_lcm_op_occ:
|
|
||||||
vnf_lcm_op_occ.state_entered_time = timestamp
|
|
||||||
vnf_lcm_op_occ.save()
|
|
||||||
if vnf_instance:
|
|
||||||
vnf_instance.save()
|
|
||||||
|
@ -1919,11 +1919,12 @@ class TestVnflcmDriver(db_base.SqlTestCase):
|
|||||||
@mock.patch.object(vim_client.VimClient, "get_vim")
|
@mock.patch.object(vim_client.VimClient, "get_vim")
|
||||||
@mock.patch.object(objects.VnfLcmOpOcc, "save")
|
@mock.patch.object(objects.VnfLcmOpOcc, "save")
|
||||||
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
||||||
|
@mock.patch.object(objects.VnfInstance, "save")
|
||||||
@mock.patch.object(driver_manager.DriverManager, "invoke")
|
@mock.patch.object(driver_manager.DriverManager, "invoke")
|
||||||
def test_scale_in_cnf(self, mock_invoke, mock_vnf_instance_get_by_id,
|
def test_scale_in_cnf(self, mock_invoke, mock_vnf_instance_save,
|
||||||
mock_lcm_save, mock_vim, mock_vnf_package_vnfd,
|
mock_vnf_instance_get_by_id, mock_lcm_save, mock_vim,
|
||||||
mock_vnfd_dict, mock_yaml_safe_load, mock_init_hash,
|
mock_vnf_package_vnfd, mock_vnfd_dict, mock_yaml_safe_load,
|
||||||
mock_get_service_plugins):
|
mock_init_hash, mock_get_service_plugins):
|
||||||
mock_init_hash.return_value = {
|
mock_init_hash.return_value = {
|
||||||
"vnflcm_noop": "ffea638bfdbde3fb01f191bbe75b031859"
|
"vnflcm_noop": "ffea638bfdbde3fb01f191bbe75b031859"
|
||||||
"b18d663b127100eb72b19eecd7ed51"
|
"b18d663b127100eb72b19eecd7ed51"
|
||||||
@ -1970,8 +1971,10 @@ class TestVnflcmDriver(db_base.SqlTestCase):
|
|||||||
@mock.patch.object(objects.VnfPackageVnfd, 'get_by_id')
|
@mock.patch.object(objects.VnfPackageVnfd, 'get_by_id')
|
||||||
@mock.patch.object(objects.VnfLcmOpOcc, "save")
|
@mock.patch.object(objects.VnfLcmOpOcc, "save")
|
||||||
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
||||||
|
@mock.patch.object(objects.VnfInstance, "save")
|
||||||
@mock.patch.object(driver_manager.DriverManager, "invoke")
|
@mock.patch.object(driver_manager.DriverManager, "invoke")
|
||||||
def test_scale_out_cnf(self, mock_invoke, mock_vnf_instance_get_by_id,
|
def test_scale_out_cnf(self, mock_invoke,
|
||||||
|
mock_vnf_instance_save, mock_vnf_instance_get_by_id,
|
||||||
mock_lcm_save, mock_vnf_package_vnfd, mock_vnfd_dict,
|
mock_lcm_save, mock_vnf_package_vnfd, mock_vnfd_dict,
|
||||||
mock_yaml_safe_load, mock_get_service_plugins):
|
mock_yaml_safe_load, mock_get_service_plugins):
|
||||||
vnf_info = fakes.vnf_dict_cnf()
|
vnf_info = fakes.vnf_dict_cnf()
|
||||||
|
@ -27,6 +27,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
from oslo_utils import timeutils
|
||||||
from toscaparser import tosca_template
|
from toscaparser import tosca_template
|
||||||
|
|
||||||
from tacker.common import driver_manager
|
from tacker.common import driver_manager
|
||||||
@ -387,6 +388,7 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver):
|
|||||||
|
|
||||||
if vnf_instance.instantiated_vnf_info and\
|
if vnf_instance.instantiated_vnf_info and\
|
||||||
vnf_instance.instantiated_vnf_info.instance_id != instance_id:
|
vnf_instance.instantiated_vnf_info.instance_id != instance_id:
|
||||||
|
# TODO(h-asahina): rename instance_id to stack_id
|
||||||
vnf_instance.instantiated_vnf_info.instance_id = instance_id
|
vnf_instance.instantiated_vnf_info.instance_id = instance_id
|
||||||
|
|
||||||
if vnf_dict['attributes'].get('scaling_group_names'):
|
if vnf_dict['attributes'].get('scaling_group_names'):
|
||||||
@ -1001,14 +1003,15 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver):
|
|||||||
jsonutils.dump_as_bytes(scaleGroupDict)
|
jsonutils.dump_as_bytes(scaleGroupDict)
|
||||||
|
|
||||||
if vnf_info['before_error_point'] < EP.NOTIFY_COMPLETED:
|
if vnf_info['before_error_point'] < EP.NOTIFY_COMPLETED:
|
||||||
|
self._vnfm_plugin._update_vnf_scaling(context, vnf_info,
|
||||||
|
'PENDING_' + scale_vnf_request.type, 'ACTIVE')
|
||||||
vnf_lcm_op_occ = vnf_info['vnf_lcm_op_occ']
|
vnf_lcm_op_occ = vnf_info['vnf_lcm_op_occ']
|
||||||
vnf_lcm_op_occ.operation_state = 'COMPLETED'
|
vnf_lcm_op_occ.operation_state = 'COMPLETED'
|
||||||
vnf_lcm_op_occ.resource_changes = resource_changes
|
vnf_lcm_op_occ.resource_changes = resource_changes
|
||||||
|
vnf_lcm_op_occ.state_entered_time = timeutils.utcnow()
|
||||||
|
vnf_lcm_op_occ.save()
|
||||||
vnf_instance.task_state = None
|
vnf_instance.task_state = None
|
||||||
self._vnfm_plugin._update_vnf_scaling(context, vnf_info,
|
vnf_instance.save()
|
||||||
'PENDING_' + scale_vnf_request.type,
|
|
||||||
'ACTIVE', vnf_instance=vnf_instance,
|
|
||||||
vnf_lcm_op_occ=vnf_lcm_op_occ)
|
|
||||||
|
|
||||||
vnf_info['current_error_point'] = EP.NOTIFY_COMPLETED
|
vnf_info['current_error_point'] = EP.NOTIFY_COMPLETED
|
||||||
|
|
||||||
@ -1620,11 +1623,11 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver):
|
|||||||
else:
|
else:
|
||||||
status = 'INACTIVE'
|
status = 'INACTIVE'
|
||||||
vnf_instance.task_state = None
|
vnf_instance.task_state = None
|
||||||
self._vnfm_plugin._update_vnf_rollback(context, vnf_info,
|
self._vnfm_plugin._update_vnf_rollback(context, vnf_info, 'ERROR',
|
||||||
'ERROR',
|
status)
|
||||||
status,
|
vnf_lcm_op_occs.state_entered_time = timeutils.utcnow()
|
||||||
vnf_instance=vnf_instance,
|
vnf_lcm_op_occs.save()
|
||||||
vnf_lcm_op_occ=vnf_lcm_op_occs)
|
vnf_instance.save()
|
||||||
|
|
||||||
def _update_vnf_rollback_status_err(self, context, vnf_info):
|
def _update_vnf_rollback_status_err(self, context, vnf_info):
|
||||||
self._vnfm_plugin.update_vnf_rollback_status_err(context, vnf_info)
|
self._vnfm_plugin.update_vnf_rollback_status_err(context, vnf_info)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user