def test_node_context_no_profile(self): plugin_context = n_ctx.get_admin_context() plugin_context.is_admin = plugin_context.is_advsvc = False plugin_context.tenant_id = 'test_tenant' current = self.create_servicechain_node( service_type='TEST', expected_res_status=201)['servicechain_node'] ctx = context.ServiceChainNodeContext(self.plugin, plugin_context, current) self.assertIsNone(ctx.original) self.assertIsNone(ctx.original_profile) self.assertEqual(ctx.current['id'], current['id']) self.assertIsNone(ctx.current_profile) original = self.create_servicechain_node( service_type='TEST', expected_res_status=201)['servicechain_node'] ctx = context.ServiceChainNodeContext(self.plugin, plugin_context, current, original) self.assertEqual(ctx.original['id'], original['id']) self.assertIsNone(ctx.original_profile) self.assertEqual(ctx.current['id'], current['id']) self.assertIsNone(ctx.current_profile)
def test_node_context_profile(self): # Current node with profile plugin_context = n_ctx.get_admin_context() plugin_context.is_admin = plugin_context.is_advsvc = False plugin_context.tenant_id = 'test-tenant' prof = self.create_service_profile( service_type='LOADBALANCER')['service_profile'] current = self.create_servicechain_node( service_profile_id=prof['id'], expected_res_status=201)['servicechain_node'] ctx = context.ServiceChainNodeContext(self.plugin, plugin_context, current) self.assertIsNone(ctx.original) self.assertIsNone(ctx.original_profile) self.assertEqual(ctx.current['id'], current['id']) self.assertEqual(ctx.current_profile['id'], prof['id']) # Original node with profile prof2 = self.create_service_profile( service_type='LOADBALANCER')['service_profile'] original = self.create_servicechain_node( service_profile_id=prof2['id'], expected_res_status=201)['servicechain_node'] ctx = context.ServiceChainNodeContext(self.plugin, plugin_context, current, original) self.assertEqual(ctx.original['id'], original['id']) self.assertEqual(ctx.original_profile['id'], prof2['id']) self.assertEqual(ctx.current['id'], current['id']) self.assertEqual(ctx.current_profile['id'], prof['id'])
def delete_servicechain_node(self, context, servicechain_node_id): session = context.session with session.begin(subtransactions=True): sc_node = self.get_servicechain_node(context, servicechain_node_id) sc_context = servicechain_context.ServiceChainNodeContext( self, context, sc_node) self.driver_manager.delete_servicechain_node_precommit(sc_context) super(ServiceChainPlugin, self).delete_servicechain_node(context, servicechain_node_id) try: self.driver_manager.delete_servicechain_node_postcommit(sc_context) except Exception: LOG.exception( _("delete_servicechain_node_postcommit failed " "for servicechain_node %s"), servicechain_node_id)
def create_servicechain_node(self, context, servicechain_node): session = context.session with session.begin(subtransactions=True): result = super(ServiceChainPlugin, self).create_servicechain_node( context, servicechain_node) self._validate_shared_create(context, result, 'servicechain_node') sc_context = servicechain_context.ServiceChainNodeContext( self, context, result) self.driver_manager.create_servicechain_node_precommit(sc_context) try: self.driver_manager.create_servicechain_node_postcommit(sc_context) except Exception: with excutils.save_and_reraise_exception(): LOG.error( _("driver_manager.create_servicechain_postcommit " "failed, deleting servicechain_node %s"), result['id']) self.delete_servicechain_node(context, result['id']) return result
def update_servicechain_node(self, context, servicechain_node_id, servicechain_node): session = context.session with session.begin(subtransactions=True): original_sc_node = self.get_servicechain_node( context, servicechain_node_id) updated_sc_node = super(ServiceChainPlugin, self).update_servicechain_node( context, servicechain_node_id, servicechain_node) self._validate_shared_update(context, original_sc_node, updated_sc_node, 'servicechain_node') sc_context = servicechain_context.ServiceChainNodeContext( self, context, updated_sc_node, original_sc_node=original_sc_node) self.driver_manager.update_servicechain_node_precommit( sc_context) self.driver_manager.update_servicechain_node_postcommit(sc_context) return updated_sc_node