Ejemplo n.º 1
0
    def _test_fix_create_update_port(self, ovn_rev, neutron_rev):
        self.port['revision_number'] = neutron_rev

        # Create an entry to the revision_numbers table and assert the
        # initial revision_number for our test object is the expected
        ovn_revision_numbers_db.create_initial_revision(
            self.ctx, self.port['id'], constants.TYPE_PORTS,
            revision_number=ovn_rev)
        row = ovn_revision_numbers_db.get_revision_row(self.ctx,
                                                       self.port['id'])
        self.assertEqual(ovn_rev, row.revision_number)

        if ovn_rev < 0:
            self.fake_ovn_client._nb_idl.get_lswitch_port.return_value = None
        else:
            fake_lsp = mock.Mock(external_ids={
                constants.OVN_REV_NUM_EXT_ID_KEY: ovn_rev})
            self.fake_ovn_client._nb_idl.get_lswitch_port.return_value = (
                fake_lsp)

        self.fake_ovn_client._plugin.get_port.return_value = self.port
        self.periodic._fix_create_update(self.ctx, row)

        # Since the revision number was < 0, make sure create_port()
        # is invoked with the latest version of the object in the neutron
        # database
        if ovn_rev < 0:
            self.fake_ovn_client.create_port.assert_called_once_with(
                self.port)
        # If the revision number is > 0 it means that the object already
        # exist and we just need to update to match the latest in the
        # neutron database so, update_port() should be called.
        else:
            self.fake_ovn_client.update_port.assert_called_once_with(
                self.port)
Ejemplo n.º 2
0
    def _test_fix_security_group_create(self, mock_bump, revision_number):
        with db_api.CONTEXT_WRITER.using(self.ctx):
            sg_name = utils.ovn_addrset_name('fake_id', 'ip4')
            sg = self._make_security_group(self.fmt, sg_name,
                                           '')['security_group']

            ovn_revision_numbers_db.create_initial_revision(
                self.ctx,
                sg['id'],
                constants.TYPE_SECURITY_GROUPS,
                revision_number=revision_number)
            row = ovn_revision_numbers_db.get_revision_row(self.ctx, sg['id'])
            self.assertEqual(revision_number, row.revision_number)

        if revision_number < 0:
            self.fake_ovn_client._nb_idl.get_address_set.return_value = None
            self.fake_ovn_client._nb_idl.get_port_group.return_value = None
        else:
            self.fake_ovn_client._nb_idl.get_address_set.return_value = (
                mock.sentinel.AddressSet)

        self.fake_ovn_client._plugin.get_security_group.return_value = sg
        self.periodic._fix_create_update(self.ctx, row)

        if revision_number < 0:
            self.fake_ovn_client.create_security_group.assert_called_once_with(
                self.ctx, sg)
        else:
            # If the object already exist let's make sure we just bump
            # the revision number in the ovn_revision_numbers table
            self.assertFalse(self.fake_ovn_client.create_security_group.called)
            mock_bump.assert_called_once_with(self.ctx, sg,
                                              constants.TYPE_SECURITY_GROUPS)
 def _create_initial_revision(self, resource_uuid, resource_type,
                              revision_number=ovn_rn_db.INITIAL_REV_NUM,
                              may_exist=False):
     with self.ctx.session.begin(subtransactions=True):
         ovn_rn_db.create_initial_revision(
             self.ctx, resource_uuid, resource_type,
             revision_number=revision_number, may_exist=may_exist)
Ejemplo n.º 4
0
 def create_floatingip_precommit(self, resource, event, trigger, context,
                                 floatingip, floatingip_id, floatingip_db):
     db_rev.create_initial_revision(
         context,
         floatingip_id,
         ovn_const.TYPE_FLOATINGIPS,
         std_attr_id=floatingip_db.standard_attr.id)
Ejemplo n.º 5
0
    def create_router_precommit(self, resource, event, trigger, payload):
        context = payload.context
        router_id = payload.resource_id
        router_db = payload.metadata['router_db']

        db_rev.create_initial_revision(context,
                                       router_id,
                                       ovn_const.TYPE_ROUTERS,
                                       std_attr_id=router_db.standard_attr.id)
Ejemplo n.º 6
0
    def create_floatingip_precommit(self, resource, event, trigger, payload):
        context = payload.context
        floatingip_id = payload.resource_id
        floatingip_db = payload.desired_state

        db_rev.create_initial_revision(
            context,
            floatingip_id,
            ovn_const.TYPE_FLOATINGIPS,
            std_attr_id=floatingip_db.standard_attr.id)
Ejemplo n.º 7
0
 def create_router_precommit(self, resource, event, trigger, context,
                             router, router_id, router_db):
     db_rev.create_initial_revision(
         context, router_id, ovn_const.TYPE_ROUTERS,
         std_attr_id=router_db.standard_attr.id)