Exemplo n.º 1
0
    def test_out_of_order_rabbit_publish(self):
        """ Test to make sure api-server preserves the state of the
            object even if the CREATE msg is queued after UPDATE in rabbit
        """
        self.wait_till_api_server_idle()

        api_server = self._server_info['api_server']
        orig_dbe_create_publish = api_server._db_conn._msgbus.dbe_create_publish
        self.block_untill_update_publish = True

        def out_of_order_dbe_create_publish(obj_type, obj_ids, *args,
                                            **kwargs):
            if obj_type == 'virtual_network':
                while self.block_untill_update_publish:
                    gevent.sleep(1)
            return orig_dbe_create_publish(obj_type, obj_ids, *args, **kwargs)

        api_server._db_conn._msgbus.dbe_create_publish = \
                out_of_order_dbe_create_publish
        logger.info("Creating VN object, without publishing it to IFMAP.")
        vn_obj = VirtualNetwork('vn1')
        vn_obj.set_uuid(str(uuid.uuid4()))
        ipam_obj = NetworkIpam('ipam1')
        vn_obj.add_network_ipam(ipam_obj, VnSubnetsType())
        self._vnc_lib.network_ipam_create(ipam_obj)
        vn_create_greenlet = gevent.spawn(self._vnc_lib.virtual_network_create,
                                          vn_obj)
        gevent.sleep(0)
        logger.info("Update VN object, Expected to update the object in",
                    "Cassandra DB and skip publishing to IFMAP.")
        vn_obj = self._vnc_lib.virtual_network_read(id=vn_obj.uuid)
        vn_obj.display_name = 'test_update_1'
        self._vnc_lib.virtual_network_update(vn_obj)
        gevent.sleep(2)
        with testtools.ExpectedException(KeyError):
            api_server._db_conn._ifmap_db._id_to_metas[\
                    'contrail:virtual-network:default-domain:default-project:vn1']

        logger.info(
            "Unblock create notify to amqp, Create expected to read from DB",
            "and publish to IFMAP with the updated object info.")
        self.block_untill_update_publish = False
        vn_uuid = vn_create_greenlet.get(timeout=3)
        gevent.sleep(2)
        self.assertEqual(api_server._db_conn._ifmap_db._id_to_metas[\
                'contrail:virtual-network:default-domain:default-project:vn1'][\
                'display-name']['']._Metadata__value, 'test_update_1')

        logger.info(
            "update after publishing to IFAMAP, Expected to publish to IFMAP")
        vn_obj.display_name = 'test_update_2'
        self._vnc_lib.virtual_network_update(vn_obj)
        gevent.sleep(2)
        self.assertEqual(api_server._db_conn._ifmap_db._id_to_metas[\
                'contrail:virtual-network:default-domain:default-project:vn1'][\
                'display-name']['']._Metadata__value, 'test_update_2')
    def test_out_of_order_rabbit_publish(self):
        """ Test to make sure api-server preserves the state of the
            object even if the CREATE msg is queued after UPDATE in rabbit
        """
        self.wait_till_api_server_idle()

        api_server = self._server_info['api_server']
        orig_dbe_create_publish = api_server._db_conn._msgbus.dbe_create_publish
        self.block_untill_update_publish = True

        def out_of_order_dbe_create_publish(obj_type, obj_ids, *args,
                                            **kwargs):
            if obj_type == 'virtual_network':
                while self.block_untill_update_publish:
                    gevent.sleep(1)
            return orig_dbe_create_publish(obj_type, obj_ids, *args, **kwargs)

        api_server._db_conn._msgbus.dbe_create_publish = \
                out_of_order_dbe_create_publish
        logger.info("Creating VN object, without publishing it to IFMAP.")
        vn_obj = VirtualNetwork('vn1')
        vn_obj.set_uuid(str(uuid.uuid4()))
        ipam_obj = NetworkIpam('ipam1')
        vn_obj.add_network_ipam(ipam_obj, VnSubnetsType())
        self._vnc_lib.network_ipam_create(ipam_obj)
        vn_create_greenlet = gevent.spawn(self._vnc_lib.virtual_network_create,
                                          vn_obj)
        gevent.sleep(0)
        logger.info("Update VN object, Expected to update the object in",
                    "Cassandra DB and skip publishing to IFMAP.")
        vn_obj = self._vnc_lib.virtual_network_read(id=vn_obj.uuid)
        vn_obj.display_name = 'test_update_1'
        self._vnc_lib.virtual_network_update(vn_obj)
        gevent.sleep(2)
        self.assertTill(self.ifmap_doesnt_have_ident, obj=vn_obj)

        logger.info(
            "Unblock create notify to amqp, Create expected to read from DB",
            "and publish to IFMAP with the updated object info.")
        self.block_untill_update_publish = False
        vn_uuid = vn_create_greenlet.get(timeout=3)
        self.assertTill(self.ifmap_ident_has_link,
                        obj=vn_obj,
                        link_name='display-name')
        self.assertTrue('test_update_1' in self.ifmap_ident_has_link(
            obj=vn_obj, link_name='display-name')['meta'])

        logger.info(
            "update after publishing to IFAMAP, Expected to publish to IFMAP")
        vn_obj.display_name = 'test_update_2'
        self._vnc_lib.virtual_network_update(vn_obj)
        self.assertTill(lambda: 'test_update_2' in self.ifmap_ident_has_link(
            obj=vn_obj, link_name='display-name')['meta'])
Exemplo n.º 3
0
    def test_out_of_order_rabbit_publish(self):
        """ Test to make sure api-server preserves the state of the
            object even if the CREATE msg is queued after UPDATE in rabbit
        """
        self.wait_till_api_server_idle()

        api_server = test_common.vnc_cfg_api_server.server
        orig_dbe_create_publish = api_server._db_conn._msgbus.dbe_create_publish
        self.block_untill_update_publish = True
        def out_of_order_dbe_create_publish(obj_type, obj_ids, *args, **kwargs):
            if obj_type == 'virtual_network':
                while self.block_untill_update_publish:
                    gevent.sleep(1)
            return orig_dbe_create_publish(obj_type,obj_ids, *args, **kwargs)

        api_server._db_conn._msgbus.dbe_create_publish = \
                out_of_order_dbe_create_publish
        logger.info("Creating VN object, without publishing it to IFMAP.")
        vn_obj = VirtualNetwork('vn1')
        vn_obj.set_uuid(str(uuid.uuid4()))
        ipam_obj = NetworkIpam('ipam1')
        vn_obj.add_network_ipam(ipam_obj, VnSubnetsType())
        self._vnc_lib.network_ipam_create(ipam_obj)
        vn_create_greenlet = gevent.spawn(self._vnc_lib.virtual_network_create, vn_obj)
        gevent.sleep(0)
        logger.info("Update VN object, Expected to update the object in",
                    "Cassandra DB and skip publishing to IFMAP.")
        vn_obj = self._vnc_lib.virtual_network_read(id=vn_obj.uuid)
        vn_obj.display_name = 'test_update_1'
        self._vnc_lib.virtual_network_update(vn_obj)
        gevent.sleep(2)
        with testtools.ExpectedException(KeyError):
            api_server._db_conn._ifmap_db._id_to_metas[\
                    'contrail:virtual-network:default-domain:default-project:vn1']

        logger.info("Unblock create notify to amqp, Create expected to read from DB",
                    "and publish to IFMAP with the updated object info.")
        self.block_untill_update_publish = False
        vn_uuid = vn_create_greenlet.get(timeout=3)
        gevent.sleep(2)
        self.assertEqual(api_server._db_conn._ifmap_db._id_to_metas[\
                'contrail:virtual-network:default-domain:default-project:vn1'][\
                'display-name']['']._Metadata__value, 'test_update_1')

        logger.info("update after publishing to IFAMAP, Expected to publish to IFMAP")
        vn_obj.display_name = 'test_update_2'
        self._vnc_lib.virtual_network_update(vn_obj)
        gevent.sleep(2)
        self.assertEqual(api_server._db_conn._ifmap_db._id_to_metas[\
                'contrail:virtual-network:default-domain:default-project:vn1'][\
                'display-name']['']._Metadata__value, 'test_update_2')
Exemplo n.º 4
0
    def test_out_of_order_rabbit_publish(self):
        """ Test to make sure api-server preserves the state of the
            object even if the CREATE msg is queued after UPDATE in rabbit
        """
        self.wait_till_api_server_idle()

        api_server = self._server_info['api_server']
        orig_dbe_create_publish = api_server._db_conn._msgbus.dbe_create_publish
        self.block_untill_update_publish = True
        def out_of_order_dbe_create_publish(obj_type, obj_ids, *args, **kwargs):
            if obj_type == 'virtual_network':
                while self.block_untill_update_publish:
                    gevent.sleep(1)
            return orig_dbe_create_publish(obj_type,obj_ids, *args, **kwargs)

        api_server._db_conn._msgbus.dbe_create_publish = \
                out_of_order_dbe_create_publish
        logger.info("Creating VN object, without publishing it to IFMAP.")
        vn_obj = VirtualNetwork('vn1')
        vn_obj.set_uuid(str(uuid.uuid4()))
        ipam_obj = NetworkIpam('ipam1')
        vn_obj.add_network_ipam(ipam_obj, VnSubnetsType())
        self._vnc_lib.network_ipam_create(ipam_obj)
        vn_create_greenlet = gevent.spawn(self._vnc_lib.virtual_network_create, vn_obj)
        gevent.sleep(0)
        logger.info("Update VN object, Expected to update the object in",
                    "Cassandra DB and skip publishing to IFMAP.")
        vn_obj = self._vnc_lib.virtual_network_read(id=vn_obj.uuid)
        vn_obj.display_name = 'test_update_1'
        self._vnc_lib.virtual_network_update(vn_obj)
        gevent.sleep(2)
        self.assertTill(self.ifmap_doesnt_have_ident, obj=vn_obj)

        logger.info("Unblock create notify to amqp, Create expected to read from DB",
                    "and publish to IFMAP with the updated object info.")
        self.block_untill_update_publish = False
        vn_uuid = vn_create_greenlet.get(timeout=3)
        self.assertTill(self.ifmap_ident_has_link, obj=vn_obj,
                        link_name='display-name')
        self.assertTrue('test_update_1' in self.ifmap_ident_has_link(
                            obj=vn_obj, link_name='display-name')['meta'])

        logger.info("update after publishing to IFAMAP, Expected to publish to IFMAP")
        vn_obj.display_name = 'test_update_2'
        self._vnc_lib.virtual_network_update(vn_obj)
        self.assertTill(lambda: 'test_update_2' in self.ifmap_ident_has_link(
                            obj=vn_obj, link_name='display-name')['meta'])