Ejemplo n.º 1
0
 def setUpClass(cls, *args, **kwargs):
     # below code is needed due to different behaviour
     # of creating flexmock in setUp and in setup_extra_flexmock
     from keystoneclient import client as keystone
     mocks = kwargs.get('extra_mocks', list())
     for index in range(len(mocks)):
         mock = mocks[index]
         if mock[0] == keystone and mock[1] == 'Client':
             del mocks[index]
             kwargs['extra_mocks'] = mocks
             setup_extra_flexmock([mock])
             break
     else:
         setup_extra_flexmock([(keystone, 'Client', get_keystone_client)])
     FakeExtensionManager._entry_pt_to_classes['vnc_cfg_api.resync'] = [
         vnc_openstack.OpenstackDriver
     ]
     FakeExtensionManager._entry_pt_to_classes[
         'vnc_cfg_api.resourceApi'] = [vnc_openstack.ResourceApiDriver]
     FakeExtensionManager._entry_pt_to_classes['vnc_cfg_api.neutronApi'] = [
         vnc_openstack.NeutronApiDriver
     ]
     setup_extra_flexmock([(stevedore.extension.ExtensionManager, '__new__',
                            FakeExtensionManager)])
     super(VncOpenstackTestCase, cls).setUpClass(*args, **kwargs)
Ejemplo n.º 2
0
    def setUp(self):
        orig_get_api_connection = getattr(vnc_openstack.ResourceApiDriver,
                                          '_get_api_connection')
        orig_post_project_create = getattr(vnc_openstack.ResourceApiDriver,
                                           'post_project_create')
        orig_pre_project_delete = getattr(vnc_openstack.ResourceApiDriver,
                                          'pre_project_delete')
        orig_domain_project_sync = getattr(vnc_openstack.OpenstackDriver,
                                           'resync_domains_projects')

        self.post_project_create_entered = gevent.event.Event()

        def delayed_get_api_connection(*args, **kwargs):
            self.post_project_create_entered.wait()
            # sleep so hook code is forced to wait
            gevent.sleep(self.CONN_DELAY)

            # Fake errors in connection upto RETRIES_BEFORE_LOG
            orig_retries_before_log = vnc_openstack.RETRIES_BEFORE_LOG
            vnc_openstack.RETRIES_BEFORE_LOG = 2

            orig_vnc_api = vnc_api.VncApi
            try:
                err_instances = []

                class BoundedErrorVncApi(object):
                    def __init__(self, *args, **kwargs):
                        if len(err_instances
                               ) < vnc_openstack.RETRIES_BEFORE_LOG:
                            err_instances.append(True)
                            raise Exception("Faking Api connection exception")
                        vnc_api.VncApi = orig_vnc_api
                        return orig_vnc_api(*args, **kwargs)

                vnc_api.VncApi = BoundedErrorVncApi

                return orig_get_api_connection(self.resource_driver, *args,
                                               **kwargs)
            finally:
                setattr(vnc_openstack, 'RETRIES_BEFORE_LOG',
                        orig_retries_before_log)
                vnc_api.VncApi = orig_vnc_api

        def delayed_post_project_create(*args, **kwargs):
            self.post_project_create_entered.set()
            return orig_post_project_create(self.resource_driver, *args,
                                            **kwargs)

        def stub(*args, **kwargs):
            pass

        test_common.setup_extra_flexmock([
            (vnc_openstack.ResourceApiDriver, '_get_api_connection',
             delayed_get_api_connection),
            (vnc_openstack.ResourceApiDriver, 'post_project_create',
             delayed_post_project_create),
            (vnc_openstack.ResourceApiDriver, 'pre_project_delete', None),
            (vnc_openstack.OpenstackDriver, 'resync_domains_projects', stub),
        ])
        super(DelayedApiServerConnectionTest, self).setUp()

        def unset_mocks():
            setattr(vnc_openstack.ResourceApiDriver, '_get_api_connection',
                    orig_get_api_connection)
            setattr(vnc_openstack.ResourceApiDriver, 'post_project_create',
                    orig_post_project_create)
            setattr(vnc_openstack.ResourceApiDriver, 'pre_project_delete',
                    orig_pre_project_delete)
            setattr(vnc_openstack.OpenstackDriver, 'resync_domains_projects',
                    orig_domain_project_sync)

        self.addCleanup(unset_mocks)