diff --git a/tacker/db/vnfm/vnfm_db.py b/tacker/db/vnfm/vnfm_db.py index 267bf986a..3c8492409 100644 --- a/tacker/db/vnfm/vnfm_db.py +++ b/tacker/db/vnfm/vnfm_db.py @@ -579,9 +579,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin): context, vnf_info, previous_statuses, - status, - vnf_instance=None, - vnf_lcm_op_occ=None): + status): with context.session.begin(subtransactions=True): timestamp = timeutils.utcnow() (self._model_query(context, VNF). @@ -606,11 +604,6 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin): res_state=status, evt_type=constants.RES_EVT_SCALE, 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): with context.session.begin(subtransactions=True): @@ -883,47 +876,31 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin): context, vnf_info): vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ'] + evt_type = constants.RES_EVT_CREATE if vnf_lcm_op_occs.operation == 'SCALE': - 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_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()) + evt_type = constants.RES_EVT_SCALE, + self._cos_db_plg.create_event(context, res_id=vnf_info['id'], + res_type=constants.RES_TYPE_VNF, + res_state='ERROR', evt_type=evt_type, + tstamp=timeutils.utcnow()) def _update_vnf_rollback_pre(self, context, vnf_info): vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ'] + evt_type = constants.RES_EVT_CREATE if vnf_lcm_op_occs.operation == 'SCALE': - 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_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()) + evt_type = constants.RES_EVT_CREATE + self._cos_db_plg.create_event(context, res_id=vnf_info['id'], + res_type=constants.RES_TYPE_VNF, + res_state='ROLL_BACK', evt_type=evt_type, + tstamp=timeutils.utcnow()) def _update_vnf_rollback(self, context, vnf_info, previous_statuses, - status, - vnf_instance=None, - vnf_lcm_op_occ=None): + status): with context.session.begin(subtransactions=True): timestamp = timeutils.utcnow() (self._model_query(context, VNF). @@ -939,26 +916,14 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin): delete(synchronize_session='fetch')) vnf_lcm_op_occs = vnf_info['vnf_lcm_op_occ'] + evt_type = constants.RES_EVT_CREATE if vnf_lcm_op_occs.operation == 'SCALE': for (key, value) in dev_attrs.items(): if 'vim_auth' not in key: self._vnf_attribute_update_or_create( context, vnf_info['id'], key, value) - 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_SCALE, - 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() + evt_type = constants.RES_EVT_SCALE + self._cos_db_plg.create_event(context, res_id=vnf_info['id'], + res_type=constants.RES_TYPE_VNF, + res_state=status, evt_type=evt_type, + tstamp=timestamp) diff --git a/tacker/tests/unit/vnflcm/test_vnflcm_driver.py b/tacker/tests/unit/vnflcm/test_vnflcm_driver.py index 2fe9884ad..e7306b61c 100644 --- a/tacker/tests/unit/vnflcm/test_vnflcm_driver.py +++ b/tacker/tests/unit/vnflcm/test_vnflcm_driver.py @@ -1919,11 +1919,12 @@ class TestVnflcmDriver(db_base.SqlTestCase): @mock.patch.object(vim_client.VimClient, "get_vim") @mock.patch.object(objects.VnfLcmOpOcc, "save") @mock.patch.object(objects.VnfInstance, "get_by_id") + @mock.patch.object(objects.VnfInstance, "save") @mock.patch.object(driver_manager.DriverManager, "invoke") - def test_scale_in_cnf(self, mock_invoke, mock_vnf_instance_get_by_id, - mock_lcm_save, mock_vim, mock_vnf_package_vnfd, - mock_vnfd_dict, mock_yaml_safe_load, mock_init_hash, - mock_get_service_plugins): + def test_scale_in_cnf(self, mock_invoke, mock_vnf_instance_save, + mock_vnf_instance_get_by_id, mock_lcm_save, mock_vim, + mock_vnf_package_vnfd, mock_vnfd_dict, mock_yaml_safe_load, + mock_init_hash, mock_get_service_plugins): mock_init_hash.return_value = { "vnflcm_noop": "ffea638bfdbde3fb01f191bbe75b031859" "b18d663b127100eb72b19eecd7ed51" @@ -1970,10 +1971,12 @@ class TestVnflcmDriver(db_base.SqlTestCase): @mock.patch.object(objects.VnfPackageVnfd, 'get_by_id') @mock.patch.object(objects.VnfLcmOpOcc, "save") @mock.patch.object(objects.VnfInstance, "get_by_id") + @mock.patch.object(objects.VnfInstance, "save") @mock.patch.object(driver_manager.DriverManager, "invoke") - def test_scale_out_cnf(self, mock_invoke, mock_vnf_instance_get_by_id, - mock_lcm_save, mock_vnf_package_vnfd, mock_vnfd_dict, - mock_yaml_safe_load, mock_get_service_plugins): + 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_yaml_safe_load, mock_get_service_plugins): vnf_info = fakes.vnf_dict_cnf() vnf_info['vnf_lcm_op_occ'] = fakes.vnflcm_scale_out_cnf() vnf_info['scale_level'] = 0 diff --git a/tacker/vnflcm/vnflcm_driver.py b/tacker/vnflcm/vnflcm_driver.py index 97f1895b2..86f54df25 100644 --- a/tacker/vnflcm/vnflcm_driver.py +++ b/tacker/vnflcm/vnflcm_driver.py @@ -27,6 +27,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import excutils +from oslo_utils import timeutils from toscaparser import tosca_template from tacker.common import driver_manager @@ -387,6 +388,7 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver): if vnf_instance.instantiated_vnf_info and\ 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 if vnf_dict['attributes'].get('scaling_group_names'): @@ -1001,14 +1003,15 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver): jsonutils.dump_as_bytes(scaleGroupDict) 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.operation_state = 'COMPLETED' 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 - self._vnfm_plugin._update_vnf_scaling(context, vnf_info, - 'PENDING_' + scale_vnf_request.type, - 'ACTIVE', vnf_instance=vnf_instance, - vnf_lcm_op_occ=vnf_lcm_op_occ) + vnf_instance.save() vnf_info['current_error_point'] = EP.NOTIFY_COMPLETED @@ -1620,11 +1623,11 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver): else: status = 'INACTIVE' vnf_instance.task_state = None - self._vnfm_plugin._update_vnf_rollback(context, vnf_info, - 'ERROR', - status, - vnf_instance=vnf_instance, - vnf_lcm_op_occ=vnf_lcm_op_occs) + self._vnfm_plugin._update_vnf_rollback(context, vnf_info, 'ERROR', + status) + vnf_lcm_op_occs.state_entered_time = timeutils.utcnow() + vnf_lcm_op_occs.save() + vnf_instance.save() def _update_vnf_rollback_status_err(self, context, vnf_info): self._vnfm_plugin.update_vnf_rollback_status_err(context, vnf_info)