def test_migration(self): main_flavors = len(db.flavor_get_all(self.context)) match, done = flavor_obj.migrate_flavors(self.context, 50) self.assertEqual(main_flavors, match) self.assertEqual(main_flavors, done) self.assertEqual(0, len(db.flavor_get_all(self.context))) self.assertEqual(main_flavors, len(objects.FlavorList.get_all(self.context)))
def test_migration(self): # create a flavor in the main database that will be migrated _create_main_flavor(self.context) main_flavors = len(db.flavor_get_all(self.context)) self.assertEqual(1, main_flavors) match, done = flavor_obj.migrate_flavors(self.context, 50) self.assertEqual(main_flavors, match) self.assertEqual(main_flavors, done) self.assertEqual(0, len(db.flavor_get_all(self.context))) self.assertEqual(main_flavors, len(objects.FlavorList.get_all(self.context)))
def test_migrate_flavors_duplicate_unicode(self, mock_log_error): """Tests that we handle a duplicate flavor when migrating and that we handle when the exception message is in unicode. """ # First create a flavor that will be migrated from main to API DB. main_flavor = _create_main_flavor(self.context) # Now create that same flavor in the API DB. del main_flavor['id'] api_flavor = ForcedFlavor(self.context, **main_flavor) api_flavor.create() # Now let's run the online data migration which will fail to create # a duplicate flavor in the API database and will raise FlavorIdExists # or FlavorExists which we want to modify to have a unicode message. with mock.patch.object(exception.FlavorIdExists, 'msg_fmt', u'\xF0\x9F\x92\xA9'): with mock.patch.object(exception.FlavorExists, 'msg_fmt', u'\xF0\x9F\x92\xA9'): match, done = flavor_obj.migrate_flavors(self.context, 50) # we found one self.assertEqual(1, match) # but we didn't migrate it self.assertEqual(0, done) # and we logged an error for the duplicate flavor mock_log_error.assert_called()
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() 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())