def setUp(self):
     test_common.setup_extra_flexmock(
         [(stevedore.extension.ExtensionManager, '__new__',
           FakeExtensionManager)])
     FakeExtensionManager._entry_pt_to_classes['vnc_cfg_api.resourceApi'] = \
         [TestExtensionApi.ResourceApiDriver]
     super(TestExtensionApi, self).setUp()
     TestExtensionApi.ResourceApiDriver._test_case = self
Example #2
0
 def setup_flexmock(self):
     import keystoneclient.v2_0.client as keystone
     FakeExtensionManager._entry_pt_to_classes['vnc_cfg_api.resync'] = [
         vnc_openstack.OpenstackDriver
     ]
     FakeExtensionManager._entry_pt_to_classes[
         'vnc_cfg_api.resourceApi'] = [vnc_openstack.ResourceApiDriver]
     setup_extra_flexmock([(keystone.Client, '__new__', get_keystone_client)
                           ])
Example #3
0
 def setup_flexmock(cls):
     from keystoneclient import client as keystone
     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([(keystone, 'Client', get_keystone_client)])
 def setup_flexmock(self):
     from keystoneclient.middleware import auth_token
     class FakeAuthProtocol(object):
         def __init__(self, app, *args, **kwargs):
             self._app = app
         # end __init__
         def __call__(self, env, start_response):
             return self._app(env, start_response)
         # end __call__
         def get_admin_token(self):
             return None
         # end get_admin_token
     # end class FakeAuthProtocol
     test_common.setup_extra_flexmock([(auth_token, 'AuthProtocol', FakeAuthProtocol)])
 def setup_flexmock(self):
     from keystoneclient.middleware import auth_token
     class FakeAuthProtocol(object):
         def __init__(self, app, *args, **kwargs):
             self._app = app
         # end __init__
         def __call__(self, env, start_response):
             # in multi-tenancy mode only admin role admitted
             # by api-server till full rbac support
             env['HTTP_X_ROLE'] = 'admin'
             return self._app(env, start_response)
         # end __call__
         def get_admin_token(self):
             return None
         # end get_admin_token
     # end class FakeAuthProtocol
     test_common.setup_extra_flexmock([(auth_token, 'AuthProtocol', FakeAuthProtocol)])
    def setup_flexmock(self):
        from keystoneclient.middleware import auth_token

        class FakeAuthProtocol(object):
            def __init__(self, app, *args, **kwargs):
                self._app = app

            # end __init__
            def __call__(self, env, start_response):
                return self._app(env, start_response)

            # end __call__
            def get_admin_token(self):
                return None

            # end get_admin_token

        # end class FakeAuthProtocol
        test_common.setup_extra_flexmock([(auth_token, 'AuthProtocol',
                                           FakeAuthProtocol)])
 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)
Example #8
0
    def setup_flexmock(self):
        from keystoneclient.middleware import auth_token

        class FakeAuthProtocol(object):
            def __init__(self, app, *args, **kwargs):
                self._app = app

            # end __init__
            def __call__(self, env, start_response):
                # in multi-tenancy mode only admin role admitted
                # by api-server till full rbac support
                env['HTTP_X_ROLE'] = 'admin'
                return self._app(env, start_response)

            # end __call__
            def get_admin_token(self):
                return None

            # end get_admin_token

        # end class FakeAuthProtocol
        test_common.setup_extra_flexmock([(auth_token, 'AuthProtocol',
                                           FakeAuthProtocol)])
Example #9
0
 def setUp(self):
     setup_extra_flexmock([(stevedore.extension.ExtensionManager, '__new__',
                            FakeExtensionManager)])
     super(VncOpenstackTestCase, self).setUp()
Example #10
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

                resource_driver = FakeExtensionManager.get_extension_objects(
                    'vnc_cfg_api.resourceApi')[0]
                return orig_get_api_connection(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()
            resource_driver = FakeExtensionManager.get_extension_objects(
                'vnc_cfg_api.resourceApi')[0]
            return orig_post_project_create(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)
Example #11
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)
 def setUpClass(cls, *args, **kwargs):
     setup_extra_flexmock([(stevedore.extension.ExtensionManager, '__new__', FakeExtensionManager)])
     super(VncOpenstackTestCase, cls).setUpClass(*args, **kwargs)
 def setup_flexmock(cls):
     import keystoneclient.v2_0.client as keystone
     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([(keystone.Client, '__new__', get_keystone_client)])
 def setUpClass(cls, *args, **kwargs):
     setup_extra_flexmock([(stevedore.extension.ExtensionManager, '__new__',
                            FakeExtensionManager)])
     super(VncOpenstackTestCase, cls).setUpClass(*args, **kwargs)
 def setUp(self):
     setup_extra_flexmock([(stevedore.extension.ExtensionManager, '__new__', FakeExtensionManager)])
     super(VncOpenstackTestCase, self).setUp()