示例#1
0
    def delete_flow_classifier(self, context, fc_id):
        fc = self.get_flow_classifier(context, fc_id)
        fc_context = fc_ctx.FlowClassifierContext(self, context, fc)
        try:
            self.driver_manager.delete_flow_classifier(fc_context)
        except fc_exc.FlowClassifierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error(
                    "Delete flow classifier failed, "
                    "flow_classifier '%s'", fc_id)

        with db_api.CONTEXT_WRITER.using(context):
            fc = self.get_flow_classifier(context, fc_id)
            fc_context = fc_ctx.FlowClassifierContext(self, context, fc)
            super(FlowClassifierPlugin,
                  self).delete_flow_classifier(context, fc_id)
            self.driver_manager.delete_flow_classifier_precommit(fc_context)
        self.driver_manager.delete_flow_classifier_postcommit(fc_context)
示例#2
0
 def test_create_flow_classifier_precommit_no_logical_source_port(self):
     with self.flow_classifier(flow_classifier={
             'name': 'test1',
             'logical_source_port': None
     }) as fc:
         fc_context = fc_ctx.FlowClassifierContext(
             self.flowclassifier_plugin, self.ctx, fc['flow_classifier'])
         self.assertRaises(fc_exc.FlowClassifierBadRequest,
                           self.driver.create_flow_classifier_precommit,
                           fc_context)
示例#3
0
 def test_create_flow_classifier_precommit_no_ports(self):
     with self.flow_classifier(
             flow_classifier={
                 'name': 'test1',
                 'logical_source_port': None,
                 'logical_destination_port': None,
             }) as fc:
         fc_context = fc_ctx.FlowClassifierContext(
             self.flowclassifier_plugin, self.ctx, fc['flow_classifier'])
         with testtools.ExpectedException(fc_exc.FlowClassifierBadRequest):
             self.driver.create_flow_classifier_precommit(fc_context)
示例#4
0
 def test_create_flow_classifier(self):
     with self.flow_classifier(flow_classifier=self._fc) as fc:
         fc_context = fc_ctx.FlowClassifierContext(
             self.flowclassifier_plugin, self.ctx, fc['flow_classifier'])
         with mock.patch.object(self.driver,
                                'update_redirect_section_in_backed'
                                ) as mock_update_section:
             self.driver.create_flow_classifier(fc_context)
             self.assertTrue(mock_update_section.called)
             section = mock_update_section.call_args[0][0]
             self._validate_rule_structure(section.find('rule'))
示例#5
0
 def test_delete_flow_classifier(self):
     with self.flow_classifier(flow_classifier=self._fc) as fc:
         fc_context = fc_ctx.FlowClassifierContext(
             self.flowclassifier_plugin, self.ctx, fc['flow_classifier'])
         self.driver.create_flow_classifier(fc_context)
         with mock.patch.object(self.driver,
                                'update_redirect_section_in_backed'
                                ) as mock_update_section:
             self.driver.delete_flow_classifier(fc_context)
             self.assertTrue(mock_update_section.called)
             section = mock_update_section.call_args[0][0]
             # make sure the rule is not there
             self.assertIsNone(section.find('rule'))
示例#6
0
 def test_create_flow_classifier_precommit_dst_port_range(self):
     with self.flow_classifier(
             flow_classifier={
                 'name': 'test1',
                 'protocol': 'tcp',
                 'destination_port_range_min': 100,
                 'destination_port_range_max': 116,
             }) as fc:
         fc_context = fc_ctx.FlowClassifierContext(
             self.flowclassifier_plugin, self.ctx, fc['flow_classifier'])
         self.assertRaises(fc_exc.FlowClassifierBadRequest,
                           self.driver.create_flow_classifier_precommit,
                           fc_context)
示例#7
0
    def delete_flow_classifier(self, context, fc_id):
        fc = self.get_flow_classifier(context, fc_id)
        fc_context = fc_ctx.FlowClassifierContext(self, context, fc)
        try:
            self.driver_manager.delete_flow_classifier(fc_context)
        except fc_exc.FlowClassfierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _LE("Delete port pair group failed, "
                        "flow_classifier '%s'"), fc_id)

        super(FlowClassifierPlugin,
              self).delete_flow_classifier(context, fc_id)
示例#8
0
 def create_flow_classifier(self, context, flow_classifier):
     fc_db = super(FlowClassifierPlugin, self).create_flow_classifier(
         context, flow_classifier)
     fc_db_context = fc_ctx.FlowClassifierContext(self, context, fc_db)
     try:
         self.driver_manager.create_flow_classifier(fc_db_context)
     except fc_exc.FlowClassifierDriverError as e:
         LOG.exception(e)
         with excutils.save_and_reraise_exception():
             LOG.error(_LE("Create flow classifier failed, "
                           "deleting flow_classifier '%s'"),
                       fc_db['id'])
             self.delete_flow_classifier(context, fc_db['id'])
     return fc_db
示例#9
0
 def test_create_flow_classifier_precommit_dest_port(self):
     with self.port(
             device_owner='compute',
             device_id='test',
     ) as port:
         with self.flow_classifier(
                 flow_classifier={
                     'name': 'test1',
                     'logical_destination_port': port['port']['id'],
                 }) as fc:
             fc_context = fc_ctx.FlowClassifierContext(
                 self.flowclassifier_plugin, self.ctx,
                 fc['flow_classifier'])
             # Make sure validation step doesn't raise an exception
             self.driver.create_flow_classifier_precommit(fc_context)
示例#10
0
 def test_create_flow_classifier_precommit(self):
     with self.port(name='port1',
                    device_owner='compute',
                    device_id='test',
                    arg_list=(portbindings.HOST_ID, ),
                    **{portbindings.HOST_ID: 'test'}) as src_port:
         with self.flow_classifier(
                 flow_classifier={
                     'name': 'test1',
                     'logical_source_port': src_port['port']['id']
                 }) as fc:
             fc_context = fc_ctx.FlowClassifierContext(
                 self.flowclassifier_plugin, self.ctx,
                 fc['flow_classifier'])
             self.driver.create_flow_classifier_precommit(fc_context)
示例#11
0
 def test_create_flow_classifier_precommit_both_ports(self):
     with self.port(
             device_owner='compute',
             device_id='test',
     ) as port:
         with self.flow_classifier(
                 flow_classifier={
                     'name': 'test1',
                     'logical_source_port': port['port']['id'],
                     'logical_destination_port': port['port']['id'],
                 }) as fc:
             with testtools.ExpectedException(
                     fc_exc.FlowClassifierBadRequest):
                 self.driver.create_flow_classifier_precommit(
                     fc_ctx.FlowClassifierContext(
                         self.flowclassifier_plugin, self.ctx,
                         fc['flow_classifier']), )
示例#12
0
 def test_create_flow_classifier_precommit_logical_dest_port(self):
     with self.port(name='port1',
                    device_owner='compute',
                    device_id='test',
                    arg_list=(portbindings.HOST_ID, ),
                    **{portbindings.HOST_ID: 'test'}) as dst_port:
         with self.flow_classifier(
                 flow_classifier={
                     'name': 'test1',
                     'logical_destination_port': dst_port['port']['id']
                 }) as fc:
             fc_context = fc_ctx.FlowClassifierContext(
                 self.flowclassifier_plugin, self.ctx,
                 fc['flow_classifier'])
             self.assertRaises(fc_exc.FlowClassifierBadRequest,
                               self.driver.create_flow_classifier_precommit,
                               fc_context)
示例#13
0
    def update_flow_classifier(self, context, id, flow_classifier):
        original_flowclassifier = self.get_flow_classifier(context, id)
        updated_fc = super(FlowClassifierPlugin, self).update_flow_classifier(
            context, id, flow_classifier)
        fc_db_context = fc_ctx.FlowClassifierContext(
            self, context, updated_fc,
            original_flowclassifier=original_flowclassifier)

        try:
            self.driver_manager.update_flow_classifier(fc_db_context)
        except fc_exc.FlowClassifierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Update flow classifier failed, "
                              "flow_classifier '%s'"),
                          updated_fc['id'])

        return updated_fc
示例#14
0
    def create_flow_classifier(self, context, flow_classifier):
        with db_api.CONTEXT_WRITER.using(context):
            fc_db = super(FlowClassifierPlugin,
                          self).create_flow_classifier(context,
                                                       flow_classifier)
            fc_db_context = fc_ctx.FlowClassifierContext(self, context, fc_db)
            self.driver_manager.create_flow_classifier_precommit(fc_db_context)

        try:
            self.driver_manager.create_flow_classifier_postcommit(
                fc_db_context)
        except fc_exc.FlowClassifierDriverError as e:
            LOG.exception(e)
            with excutils.save_and_reraise_exception():
                LOG.error(
                    "Create flow classifier failed, "
                    "deleting flow_classifier '%s'", fc_db['id'])
                self.delete_flow_classifier(context, fc_db['id'])
        return fc_db
示例#15
0
 def _get_fc_ctx(self, **kwargs):
     return fc_ctx.FlowClassifierContext(
         self.flowclassifier_plugin,
         self.ctx,
         kwargs,
     )
示例#16
0
 def test_create_flow_classifier_precommit(self):
     with self.flow_classifier(flow_classifier=self._fc) as fc:
         fc_context = fc_ctx.FlowClassifierContext(
             self.flowclassifier_plugin, self.ctx, fc['flow_classifier'])
         # just make sure it does not raise an exception
         self.driver.create_flow_classifier_precommit(fc_context)