def setUp(self): super(TestBaseFilterHandler, self).setUp() self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs self.stubs.Set(base_filter.base_handler.extension, 'ExtensionManager', FakeExtensionManager) self.handler = base_filter.BaseFilterHandler(BaseFakeFilter, 'fake_filters')
def setUp(self): """Run before each test method to initialize test environment.""" super(NoDBTestCase, self).setUp() self.useFixture( nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0), self.TIMEOUT_SCALING_FACTOR)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(nova_fixtures.OutputStreamCapture()) self.useFixture(nova_fixtures.StandardLogging()) self.useFixture(conf_fixture.ConfFixture(CONF)) # NOTE(blk-u): WarningsFixture must be after the Database fixture # because sqlalchemy-migrate messes with the warnings filters. self.useFixture(nova_fixtures.WarningsFixture()) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.policy = self.useFixture(policy_fixture.PolicyFixture()) self.useFixture(nova_fixtures.PoisonFunctions())
def setUp(self, conf=cfg.CONF): super(BaseTestCase, self).setUp() moxfixture = self.useFixture(moxstubout.MoxStubout()) self.mox = moxfixture.mox self.stubs = moxfixture.stubs self.conf = conf self.addCleanup(self.conf.reset)
def setUp(self): super(TestCase, self).setUp() self.tempdir = self.useFixture(fixtures.TempDir()) moxfixture = self.useFixture(moxstubout.MoxStubout()) self.mox = moxfixture.mox self.stubs = moxfixture.stubs cfg.CONF([], project='pycadf')
def setUp(self): """Run before each test.""" super(MigrationsTestCaseV21, self).setUp() self.controller = self.migrations.MigrationsController() self.req = FakeRequest() self.context = self.req.environ['nova.context'] mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox
def setUp(self): super(GettextTest, self).setUp() moxfixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = moxfixture.stubs self.mox = moxfixture.mox # remember so we can reset to it later in case it changes self._USE_LAZY = _lazy.USE_LAZY self.t = _factory.TranslatorFactory('oslo.i18n.test')
def setUp(self): super(TestCreatingLocations, self).setUp() moxfixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = moxfixture.stubs conf = copy.deepcopy(SWIFT_CONF) self.store = Store(self.conf) self.config(**conf) reload(swift) self.addCleanup(self.conf.reset)
def test_basic_stubout(self): f = self.useFixture(moxstubout.MoxStubout()) before = TestMoxStubout._stubable f.mox.StubOutWithMock(TestMoxStubout, '_stubable') after = TestMoxStubout._stubable self.assertNotEqual(before, after) f.cleanUp() after2 = TestMoxStubout._stubable self.assertEqual(before, after2)
def setUp(self): self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs self.CONF = self.useFixture(config.Config()).conf self.sample_resources = { 'r1': quota.BaseResource('r1'), 'r2': quota.BaseResource('r2') } dbapi = mock.Mock() dbapi.quota_usage_get_all_by_project_and_user = mock.Mock( return_value={ 'project_id': 'p1', 'user_id': 'u1', 'r1': { 'reserved': 1, 'in_use': 2 }, 'r2': { 'reserved': 2, 'in_use': 3 } }) dbapi.quota_get_all_by_project_and_user = mock.Mock(return_value={ 'project_id': 'p1', 'user_id': 'u1', 'r1': 5, 'r2': 6 }) dbapi.quota_get = mock.Mock(return_value='quota_get') dbapi.quota_reserve = mock.Mock(return_value='quota_reserve') dbapi.quota_class_get = mock.Mock(return_value='quota_class_get') dbapi.quota_class_reserve = mock.Mock( return_value='quota_class_reserve') dbapi.quota_class_get_default = mock.Mock(return_value={ 'r1': 1, 'r2': 2 }) dbapi.quota_class_get_all_by_name = mock.Mock(return_value={'r1': 9}) dbapi.quota_get_all_by_project = mock.Mock( return_value=dict([('r%d' % i, i) for i in range(3)])) dbapi.quota_get_all = mock.Mock(return_value=[{ 'resource': 'r1', 'hard_limit': 3 }, { 'resource': 'r2', 'hard_limit': 4 }]) dbapi.quota_usage_get_all_by_project = mock.Mock( return_value=dict([('r%d' % i, { 'in_use': i, 'reserved': i + 1 }) for i in range(3)])) self.dbapi = dbapi self.driver = quota.DbQuotaDriver(dbapi) self.ctxt = FakeContext() return super(DbQuotaDriverTestCase, self).setUp()
def setUp(self, conf=cfg.CONF): super(BaseTestCase, self).setUp() from oslo.messaging import conffixture self.messaging_conf = self.useFixture(conffixture.ConfFixture(conf)) self.conf = self.messaging_conf.conf moxfixture = self.useFixture(moxstubout.MoxStubout()) self.mox = moxfixture.mox self.stubs = moxfixture.stubs
def setUp(self): super(ForeverRetryUncaughtExceptionsTest, self).setUp() moxfixture = self.useFixture(moxstubout.MoxStubout()) self.mox = moxfixture.mox self.useFixture(fixtures.MockPatch('time.sleep', return_value=None)) self.mox.StubOutWithMock(logging, 'exception') self.mox.StubOutWithMock(timeutils, 'now', use_mock_anything=True) self.mox.StubOutWithMock(self, 'exception_to_raise')
def setUp(self): super(TestPaginateQuery, self).setUp() mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.query = self.mox.CreateMockAnything() self.mox.StubOutWithMock(sqlalchemy, 'asc') self.mox.StubOutWithMock(sqlalchemy, 'desc') self.marker = FakeTable(user_id='user', project_id='p', snapshot_id='s') self.model = FakeTable
def setUp(self): super(TestImageCacheNoDep, self).setUp() self.driver = None def init_driver(self2): self2.driver = self.driver mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.stubs.Set(image_cache.ImageCache, 'init_driver', init_driver)
def setUp(self): super(TestCase, self).setUp() self.useFixture(fixtures.FakeLogger('credsmgr')) CONF.set_default('connection', 'sqlite://', 'database') CONF.set_default('sqlite_synchronous', True, 'database') utils.setup_dummy_db() self.addCleanup(utils.reset_dummy_db) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs
def setUp(self, conf=cfg.CONF): super(BaseTestCase, self).setUp() from oslo_messaging import conffixture self.messaging_conf = self.useFixture(conffixture.ConfFixture(conf)) self.messaging_conf.transport_driver = 'fake' self.conf = self.messaging_conf.conf self.conf.project = 'project' self.conf.prog = 'prog' moxfixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = moxfixture.stubs
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.useFixture( versionedobjects_fixtures.Timeout( os.environ.get('OS_TEST_TIMEOUT', 0), self.TIMEOUT_SCALING_FACTOR)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(versionedobjects_fixtures.TranslationFixture()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(versionedobjects_fixtures.OutputStreamCapture()) self.useFixture(versionedobjects_fixtures.StandardLogging()) # NOTE(sdague): because of the way we were using the lock # wrapper we eneded up with a lot of tests that started # relying on global external locking being set up for them. We # consider all of these to be *bugs*. Tests should not require # global external locking, or if they do, they should # explicitly set it up themselves. # # The following REQUIRES_LOCKING class parameter is provided # as a bridge to get us there. No new tests should be added # that require it, and existing classes and tests should be # fixed to not need it. if self.REQUIRES_LOCKING: lock_path = self.useFixture(fixtures.TempDir()).path self.fixture = self.useFixture( config_fixture.Config(lockutils.CONF)) self.fixture.config(lock_path=lock_path, group='oslo_concurrency') # NOTE(blk-u): WarningsFixture must be after the Database fixture # because sqlalchemy-migrate messes with the warnings filters. self.useFixture(versionedobjects_fixtures.WarningsFixture()) # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry. objects_base.VersionedObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.VersionedObject._obj_classes) self.addCleanup(self._restore_obj_registry) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.useFixture(conf_fixture.ConfFixture(CONF)) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.policy = self.useFixture(policy_fixture.PolicyFixture()) if self.USES_DB: self.useFixture(masakari_fixtures.Database()) else: self.useFixture(masakari_fixtures.DatabasePoisonFixture())
def setUp(self): super(BaseTestCase, self).setUp() # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[]) self.addCleanup(CONF.reset) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) self.set_policy()
def setUp(self): super(TestSingleTenantStoreConnections, self).setUp() moxfixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = moxfixture.stubs self.stubs.Set(swiftclient, 'Connection', FakeConnection) self.store = swift.SingleTenantStore(self.conf) self.store.configure() specs = { 'scheme': 'swift', 'auth_or_store_url': 'example.com/v2/', 'user': '******', 'key': 'key1', 'container': 'cont', 'obj': 'object' } self.location = swift.StoreLocation(specs, self.conf) self.addCleanup(self.conf.reset)
def setUp(self): super(TestMultiTenantStoreConnections, self).setUp() moxfixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = moxfixture.stubs self.stubs.Set(swiftclient, 'Connection', FakeConnection) self.context = context.RequestContext(user='******', tenant='tenant', auth_token='0123') self.store = swift.MultiTenantStore(self.conf) specs = { 'scheme': 'swift', 'auth_or_store_url': 'example.com', 'container': 'cont', 'obj': 'object' } self.location = swift.StoreLocation(specs, self.conf) self.addCleanup(self.conf.reset)
def setUp(self): """Establish a clean test environment.""" super(TestStoreAuthV1, self).setUp() conf = self.getConfig() conf_file = 'glance-swift.conf' self.swift_config_file = self.copy_data_file(conf_file, self.test_dir) conf.update({'swift_store_config_file': self.swift_config_file}) moxfixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = moxfixture.stubs stub_out_swiftclient(self.stubs, conf['swift_store_auth_version']) self.store = Store(self.conf) self.config(**conf) self.store.configure() self.register_store_schemes(self.store) self.addCleanup(self.conf.reset)
def setUp(self): super(OVSvAppVCDriverTestCase, self).setUp() self.fixture = self.useFixture(config_fixture.Config(lockutils.CONF)) self.fixture.config(disable_process_locking=True, group='oslo_concurrency') self.user_id = 'test_user_id' self.project_id = 'test_project_id' self.context = context.RequestContext(self.user_id, self.project_id, is_admin=False) reset_fakes() vm_util.vm_refs_cache_reset() stubs.set_stubs(self) image_fake.stub_out_image_service(self) image_ref = image_fake.get_valid_image_id() (image_service, image_id) = glance.get_remote_image_service( self.context, image_ref) metadata = image_service.show(self.context, image_id) self.image = { 'id': image_ref, 'disk_format': 'vmdk', 'size': int(metadata['size']), } self.fake_image_uuid = self.image['id'] self.image = objects.ImageMeta.from_dict(self.image) self.vnc_host = 'ha-host' self.flags(host_ip='test_url', host_username='******', host_password='******', use_linked_clone=False, cluster_name='test_cluster', task_poll_interval=10, datastore_regex='.*', vmwareapi_nic_attach_retry_count=1, group='vmware') self.flags(enabled=False, group='vnc') self.flags(image_cache_subdirectory_name='vmware_base', my_ip='') self.vnc_host = 'ha-host' self.conn = ovsvapp_vc_driver.OVSvAppVCDriver(None) self.node_name = self.conn._nodename mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox
def setUp(self): super(BaseTestCase, self).setUp() # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[], default_config_files=[]) self.addCleanup(CONF.reset) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.mock_exception = mock.patch('searchlight.common.exception', True) self.mock_exception.start() self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) service_policies._ENFORCERS = None self.set_policy() utils.register_plugin_opts()
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.useFixture(conveyor_fixtures.Timeout( os.environ.get('OS_TEST_TIMEOUT', 0), self.TIMEOUT_SCALING_FACTOR)) self.useFixture(log_fixture.get_logging_handle_error_fixture()) # NOTE(sdague): because of the way we were using the lock # wrapper we eneded up with a lot of tests that started # relying on global external locking being set up for them. We # consider all of these to be *bugs*. Tests should not require # global external locking, or if they do, they should # explicitly set it up themselves. # # The following REQUIRES_LOCKING class parameter is provided # as a bridge to get us there. No new tests should be added # that require it, and existing classes and tests should be # fixed to not need it. if self.REQUIRES_LOCKING: lock_path = self.useFixture(fixtures.TempDir()).path self.fixture = self.useFixture( config_fixture.Config(lockutils.CONF)) self.fixture.config(lock_path=lock_path, group='oslo_concurrency') self.useFixture(conf_fixture.ConfFixture(CONF)) self.useFixture(conveyor_fixtures.RPCFixture('conveyor.test')) # NOTE(mnaser): All calls to utils.is_neutron() are cached in # nova.utils._IS_NEUTRON. We set it to None to avoid any # caching of that value. utils._IS_NEUTRON = None mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs)
def setUp(self): super(BaseTestCase, self).setUp() self._config_fixture = self.useFixture(cfg_fixture.Config()) # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[]) self.addCleanup(CONF.reset) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.mock_object(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) self.set_policy() # Limit the amount of DeprecationWarning messages in the unit test logs self.useFixture(glance_fixtures.WarningsFixture()) # Make sure logging output is limited but still test debug formatting self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(glance_fixtures.StandardLogging())
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.useFixture(nova_fixtures.Timeout( os.environ.get('OS_TEST_TIMEOUT', 0), self.TIMEOUT_SCALING_FACTOR)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(nova_fixtures.OutputStreamCapture()) self.useFixture(nova_fixtures.StandardLogging()) # NOTE(sdague): because of the way we were using the lock # wrapper we ended up with a lot of tests that started # relying on global external locking being set up for them. We # consider all of these to be *bugs*. Tests should not require # global external locking, or if they do, they should # explicitly set it up themselves. # # The following REQUIRES_LOCKING class parameter is provided # as a bridge to get us there. No new tests should be added # that require it, and existing classes and tests should be # fixed to not need it. if self.REQUIRES_LOCKING: lock_path = self.useFixture(fixtures.TempDir()).path self.fixture = self.useFixture( config_fixture.Config(lockutils.CONF)) self.fixture.config(lock_path=lock_path, group='oslo_concurrency') self.useFixture(conf_fixture.ConfFixture(CONF)) self.useFixture(nova_fixtures.RPCFixture('nova.test')) # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry. objects_base.NovaObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.NovaObjectRegistry._registry._obj_classes) self.addCleanup(self._restore_obj_registry) # NOTE(danms): Reset the cached list of cells from nova.compute import api api.CELLS = [] self.cell_mappings = {} self.host_mappings = {} # NOTE(danms): If the test claims to want to set up the database # itself, then it is responsible for all the mapping stuff too. if self.USES_DB: # NOTE(danms): Full database setup involves a cell0, cell1, # and the relevant mappings. self.useFixture(nova_fixtures.Database(database='api')) self._setup_cells() self.useFixture(nova_fixtures.DefaultFlavorsFixture()) elif not self.USES_DB_SELF: # NOTE(danms): If not using the database, we mock out the # mapping stuff and effectively collapse everything to a # single cell. self.useFixture(nova_fixtures.SingleCellSimple()) self.useFixture(nova_fixtures.DatabasePoisonFixture()) # NOTE(blk-u): WarningsFixture must be after the Database fixture # because sqlalchemy-migrate messes with the warnings filters. self.useFixture(nova_fixtures.WarningsFixture()) self.useFixture(ovo_fixture.StableObjectJsonFixture()) # NOTE(mnaser): All calls to utils.is_neutron() are cached in # nova.utils._IS_NEUTRON. We set it to None to avoid any # caching of that value. utils._IS_NEUTRON = None mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) self.useFixture(nova_fixtures.PoisonFunctions()) openstack_driver.DRIVER_CACHE = {} self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.useFixture( nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0), self.TIMEOUT_SCALING_FACTOR)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.output = nova_fixtures.OutputStreamCapture() self.useFixture(self.output) self.stdlog = nova_fixtures.StandardLogging() self.useFixture(self.stdlog) # NOTE(sdague): because of the way we were using the lock # wrapper we ended up with a lot of tests that started # relying on global external locking being set up for them. We # consider all of these to be *bugs*. Tests should not require # global external locking, or if they do, they should # explicitly set it up themselves. # # The following REQUIRES_LOCKING class parameter is provided # as a bridge to get us there. No new tests should be added # that require it, and existing classes and tests should be # fixed to not need it. if self.REQUIRES_LOCKING: lock_path = self.useFixture(fixtures.TempDir()).path self.fixture = self.useFixture( config_fixture.Config(lockutils.CONF)) self.fixture.config(lock_path=lock_path, group='oslo_concurrency') self.useFixture(conf_fixture.ConfFixture(CONF)) if self.STUB_RPC: self.useFixture(nova_fixtures.RPCFixture('nova.test')) # we cannot set this in the ConfFixture as oslo only registers the # notification opts at the first instantiation of a Notifier that # happens only in the RPCFixture CONF.set_default('driver', ['test'], group='oslo_messaging_notifications') # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry. objects_base.NovaObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.NovaObjectRegistry._registry._obj_classes) self.addCleanup(self._restore_obj_registry) objects.Service.clear_min_version_cache() # NOTE(danms): Reset the cached list of cells from nova.compute import api api.CELLS = [] context.CELL_CACHE = {} context.CELLS = [] self.cell_mappings = {} self.host_mappings = {} # NOTE(danms): If the test claims to want to set up the database # itself, then it is responsible for all the mapping stuff too. if self.USES_DB: # NOTE(danms): Full database setup involves a cell0, cell1, # and the relevant mappings. self.useFixture(nova_fixtures.Database(database='api')) self.useFixture(nova_fixtures.Database(database='placement')) self._setup_cells() self.useFixture(nova_fixtures.DefaultFlavorsFixture()) elif not self.USES_DB_SELF: # NOTE(danms): If not using the database, we mock out the # mapping stuff and effectively collapse everything to a # single cell. self.useFixture(nova_fixtures.SingleCellSimple()) self.useFixture(nova_fixtures.DatabasePoisonFixture()) # NOTE(blk-u): WarningsFixture must be after the Database fixture # because sqlalchemy-migrate messes with the warnings filters. self.useFixture(nova_fixtures.WarningsFixture()) self.useFixture(ovo_fixture.StableObjectJsonFixture()) # NOTE(mnaser): All calls to utils.is_neutron() are cached in # nova.utils._IS_NEUTRON. We set it to None to avoid any # caching of that value. utils._IS_NEUTRON = None # Reset the traits sync and rc cache flags def _reset_traits(): resource_provider._TRAITS_SYNCED = False _reset_traits() self.addCleanup(_reset_traits) resource_provider._RC_CACHE = None # Reset the global QEMU version flag. images.QEMU_VERSION = None mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) self.placement_policy = self.useFixture( policy_fixture.PlacementPolicyFixture()) self.useFixture(nova_fixtures.PoisonFunctions()) openstack_driver.DRIVER_CACHE = {} self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture()) # NOTE(mikal): make sure we don't load a privsep helper accidentally self.useFixture(nova_fixtures.PrivsepNoHelperFixture()) self.useFixture(mock_fixture.MockAutospecFixture()) # FIXME(danms): Disable this for all tests by default to avoid breaking # any that depend on default/previous ordering self.flags(build_failure_weight_multiplier=0.0, group='filter_scheduler')
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() self.useFixture( nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0), self.TIMEOUT_SCALING_FACTOR)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(nova_fixtures.OutputStreamCapture()) self.useFixture(nova_fixtures.StandardLogging()) # NOTE(sdague): because of the way we were using the lock # wrapper we eneded up with a lot of tests that started # relying on global external locking being set up for them. We # consider all of these to be *bugs*. Tests should not require # global external locking, or if they do, they should # explicitly set it up themselves. # # The following REQUIRES_LOCKING class parameter is provided # as a bridge to get us there. No new tests should be added # that require it, and existing classes and tests should be # fixed to not need it. if self.REQUIRES_LOCKING: lock_path = self.useFixture(fixtures.TempDir()).path self.fixture = self.useFixture( config_fixture.Config(lockutils.CONF)) self.fixture.config(lock_path=lock_path, group='oslo_concurrency') self.useFixture(conf_fixture.ConfFixture(CONF)) self.useFixture(nova_fixtures.RPCFixture('nova.test')) if self.USES_DB: self.useFixture(nova_fixtures.Database()) self.useFixture(nova_fixtures.Database(database='api')) # NOTE(danms): Flavors are encoded in our original migration # which means we have no real option other than to migrate them # onlineish every time we build a new database (for now). ctxt = context.get_admin_context() flavor_obj.migrate_flavors(ctxt, 100, hard_delete=True) elif not self.USES_DB_SELF: self.useFixture(nova_fixtures.DatabasePoisonFixture()) # NOTE(blk-u): WarningsFixture must be after the Database fixture # because sqlalchemy-migrate messes with the warnings filters. self.useFixture(nova_fixtures.WarningsFixture()) # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry. objects_base.NovaObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.NovaObjectRegistry._registry._obj_classes) self.addCleanup(self._restore_obj_registry) self.useFixture(nova_fixtures.StableObjectJsonFixture()) # NOTE(mnaser): All calls to utils.is_neutron() are cached in # nova.utils._IS_NEUTRON. We set it to None to avoid any # caching of that value. utils._IS_NEUTRON = None mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(self._clear_attrs) self.useFixture(fixtures.EnvironmentVariable('http_proxy')) self.policy = self.useFixture(policy_fixture.PolicyFixture()) self.useFixture(nova_fixtures.PoisonFunctions()) openstack_driver.DRIVER_CACHE = {} self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() # Create default notifier self.notifier = fake_notifier.get_fake_notifier() # Mock rpc get notifier with fake notifier method that joins all # notifications with the default notifier self.patch('cinder.rpc.get_notifier', side_effect=self._get_joined_notifier) if self.MOCK_WORKER: # Mock worker creation for all tests that don't care about it clean_path = 'cinder.objects.cleanable.CinderCleanableObject.%s' for method in ('create_worker', 'set_worker', 'unset_worker'): self.patch(clean_path % method, return_value=None) # Unit tests do not need to use lazy gettext i18n.enable_lazy(False) test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) except ValueError: # If timeout value is invalid do not set a timeout. test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) environ_enabled = (lambda var_name: strutils.bool_from_string( os.environ.get(var_name))) if environ_enabled('OS_STDOUT_CAPTURE'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if environ_enabled('OS_STDERR_CAPTURE'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.useFixture(log_fixture.get_logging_handle_error_fixture()) self.useFixture(cinder_fixtures.StandardLogging()) rpc.add_extra_exmods("cinder.tests.unit") self.addCleanup(rpc.clear_extra_exmods) self.addCleanup(rpc.cleanup) self.messaging_conf = messaging_conffixture.ConfFixture(CONF) self.messaging_conf.transport_driver = 'fake' self.messaging_conf.response_timeout = 15 self.useFixture(self.messaging_conf) # Load oslo_messaging_notifications config group so we can set an # override to prevent notifications from being ignored due to the # short-circuit mechanism. oslo_messaging.get_notification_transport(CONF) # We need to use a valid driver for the notifications, so we use test. self.override_config('driver', ['test'], group='oslo_messaging_notifications') rpc.init(CONF) # NOTE(geguileo): This is required because _determine_obj_version_cap # and _determine_rpc_version_cap functions in cinder.rpc.RPCAPI cache # versions in LAST_RPC_VERSIONS and LAST_OBJ_VERSIONS so we may have # weird interactions between tests if we don't clear them before each # test. rpc.LAST_OBJ_VERSIONS = {} rpc.LAST_RPC_VERSIONS = {} conf_fixture.set_defaults(CONF) CONF([], default_config_files=[]) # NOTE(vish): We need a better method for creating fixtures for tests # now that we have some required db setup for the system # to work properly. self.start = timeutils.utcnow() CONF.set_default('connection', 'sqlite://', 'database') CONF.set_default('sqlite_synchronous', False, 'database') global _DB_CACHE if not _DB_CACHE: _DB_CACHE = Database(sqla_api, migration, sql_connection=CONF.database.connection) self.useFixture(_DB_CACHE) # NOTE(danms): Make sure to reset us back to non-remote objects # for each test to avoid interactions. Also, backup the object # registry. objects_base.CinderObject.indirection_api = None self._base_test_obj_backup = copy.copy( objects_base.CinderObjectRegistry._registry._obj_classes) self.addCleanup(self._restore_obj_registry) # emulate some of the mox stuff, we can't use the metaclass # because it screws with our generators mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs self.addCleanup(CONF.reset) self.addCleanup(self._common_cleanup) self.injected = [] self._services = [] fake_notifier.mock_notifier(self) self.override_config('fatal_exception_format_errors', True) # This will be cleaned up by the NestedTempfile fixture lock_path = self.useFixture(fixtures.TempDir()).path self.fixture = self.useFixture(config_fixture.Config(lockutils.CONF)) self.fixture.config(lock_path=lock_path, group='oslo_concurrency') lockutils.set_defaults(lock_path) self.override_config('policy_file', os.path.join( os.path.abspath( os.path.join( os.path.dirname(__file__), '..', )), self.POLICY_PATH), group='oslo_policy') self._disable_osprofiler() self._disallow_invalid_uuids() # NOTE(geguileo): This is required because common get_by_id method in # cinder.db.sqlalchemy.api caches get methods and if we use a mocked # get method in one test it would carry on to the next test. So we # clear out the cache. sqla_api._GET_METHODS = {} self.override_config('backend_url', 'file://' + lock_path, group='coordination') coordination.COORDINATOR.start() self.addCleanup(coordination.COORDINATOR.stop)
def setUp(self): super(TestBaseFilter, self).setUp() self.mox = self.useFixture(moxstubout.MoxStubout()).mox self.filter = base_filter.BaseFilter()