def _do_test_load_paste_app(self, expected_app_type, paste_group={}, paste_copy=True, paste_append=None): conf = test_utils.TestConfigOpts(groups=paste_group, clean=False) def _appendto(orig, copy, str): shutil.copy(orig, copy) with open(copy, 'ab') as f: f.write(str or '') f.flush() paste_to = os.path.join(conf.temp_file.replace('.conf', '-paste.ini')) if paste_copy: paste_from = os.path.join(os.getcwd(), 'etc/glance-registry-paste.ini') _appendto(paste_from, paste_to, paste_append) app = config.load_paste_app(conf, 'glance-registry') self.assertEquals(expected_app_type, type(app)) if paste_copy: os.remove(conf.temp_file) os.remove(paste_to) os.rmdir(os.path.dirname(conf.temp_file))
def _test_notify(self, priority): test_msg = json.dumps({'a': 'b'}) self.mock_connection = self.mocker.CreateMock(self.orig_connection) self.mock_session = self.mocker.CreateMock(self.orig_session) self.mock_sender = self.mocker.CreateMock(self.orig_sender) self.mock_connection.username = "" self.mock_connection.open() self.mock_connection.session().AndReturn(self.mock_session) for p in ["info", "warn", "error"]: expected_address = ( 'glance/glance_notifications.%s ; {"node": ' '{"x-declare": {"auto-delete": true, "durable": false}, ' '"type": "topic"}, "create": "always"}' % p) self.mock_session.sender(expected_address).AndReturn( self.mock_sender) self.mock_sender.send(mox.IgnoreArg()) self.mocker.ReplayAll() conf = utils.TestConfigOpts({"notifier_strategy": "qpid"}) notifier = self.notify_qpid.QpidStrategy(conf) if priority == 'info': notifier.info(test_msg) elif priority == 'warn': notifier.warn(test_msg) elif priority == 'error': notifier.error(test_msg) self.mocker.VerifyAll()
def setUp(self): self.stubs = stubout.StubOutForTesting() def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' rabbit_self.exchange = self._fake_exchange() return None def dummy(*args, **kwargs): pass self.stubs.Set(kombu.entity.Exchange, 'publish', dummy) self.stubs.Set(glance.notifier.notify_kombu.RabbitStrategy, '_connect', _fake_connect) self.called = False self.conf = utils.TestConfigOpts({ "notifier_strategy": "rabbit", "rabbit_retry_backoff": 0, "rabbit_notification_topic": "fake_topic" }) self.notifier = notifier.Notifier(self.conf) super(TestRabbitContentType, self).setUp()
def setUp(self): super(TestClientExceptions, self).setUp() self.port = utils.get_unused_port() server = wsgi.Server() conf = utils.TestConfigOpts({'bind_host': '127.0.0.1'}) server.start(ExceptionTestApp(), conf, self.port) self.client = client.BaseClient("127.0.0.1", self.port)
def getresponse(self): conf = utils.TestConfigOpts({ 'verbose': VERBOSE, 'debug': DEBUG, 'bind_host': '0.0.0.0', 'bind_port': '9999999', 'registry_host': '0.0.0.0', 'registry_port': '9191', 'default_store': 'file', 'filesystem_store_datadir': base_dir, 'policy_file': os.path.join(base_dir, 'policy.json'), }) api = version_negotiation.VersionNegotiationFilter( context.ContextMiddleware(router.API(conf), conf), conf) res = self.req.get_response(api) # httplib.Response has a read() method...fake it out def fake_reader(): return res.body setattr(res, 'read', fake_reader) return res
def test_get_version_list(self): req = webob.Request.blank('/') req.accept = "application/json" conf = utils.TestConfigOpts({ 'bind_host': '0.0.0.0', 'bind_port': 9292 }) res = req.get_response(versions.Controller(conf)) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/json") results = json.loads(res.body)["versions"] expected = [{ "id": "v1.1", "status": "CURRENT", "links": [{ "rel": "self", "href": "http://0.0.0.0:9292/v1/" }] }, { "id": "v1.0", "status": "SUPPORTED", "links": [{ "rel": "self", "href": "http://0.0.0.0:9292/v1/" }] }] self.assertEqual(results, expected)
def test_get_version_list(self): req = webob.Request.blank('/', base_url='http://0.0.0.0:9292/') req.accept = 'application/json' config_opts = {'bind_host': '0.0.0.0', 'bind_port': 9292} conf = utils.TestConfigOpts(config_opts) res = versions.Controller(conf).index(req) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, 'application/json') results = json.loads(res.body)['versions'] expected = [ { 'id': 'v2', 'status': 'EXPERIMENTAL', 'links': [{'rel': 'self', 'href': 'http://0.0.0.0:9292/v2/'}], }, { 'id': 'v1.1', 'status': 'CURRENT', 'links': [{'rel': 'self', 'href': 'http://0.0.0.0:9292/v1/'}], }, { 'id': 'v1.0', 'status': 'SUPPORTED', 'links': [{'rel': 'self', 'href': 'http://0.0.0.0:9292/v1/'}], }, ] self.assertEqual(results, expected)
def setUp(self): """ Test to see if the pre-requisites for the image cache are working (python-sqlite3 installed) """ if getattr(self, 'disable', False): return if not getattr(self, 'inited', False): try: import sqlite3 except ImportError: self.inited = True self.disabled = True self.disabled_message = ("python-sqlite3 not installed.") return self.inited = True self.disabled = False self.cache_dir = os.path.join("/", "tmp", "test.cache.%d" % random.randint(0, 1000000)) self.conf = test_utils.TestConfigOpts({ 'image_cache_dir': self.cache_dir, 'image_cache_driver': 'sqlite', 'image_cache_max_size': 1024 * 5, 'registry_host': '0.0.0.0', 'registry_port': 9191}) self.cache = image_cache.ImageCache(self.conf)
def setUp(self): super(BaseDBTestCase, self).setUp() conf = test_utils.TestConfigOpts(CONF) self.adm_context = context.RequestContext(is_admin=True) self.context = context.RequestContext(is_admin=False) db_api.configure_db(conf) self.destroy_fixtures() self.create_fixtures()
def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) create_stores(utils.TestConfigOpts({})) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri)
def setUp(self): """Establish a clean test environment""" super(TestRegistryDb, self).setUp() conf = test_utils.TestConfigOpts(CONF) self.adm_context = rcontext.RequestContext(is_admin=True) self.context = rcontext.RequestContext(is_admin=False) db_api.configure_db(conf) self.destroy_fixtures() self.create_fixtures()
def _option_required(self, key): conf = S3_CONF.copy() del conf[key] try: self.store = Store(test_utils.TestConfigOpts(conf)) return self.store.add == self.store.add_disabled except: return False return False
def test_walk_versions(self): """ Walks all version scripts for each tested database, ensuring that there are no errors in the version scripts for each engine """ for key, engine in self.engines.items(): conf = utils.TestConfigOpts( {'sql_connection': TestMigrations.TEST_DATABASES[key]}) conf.register_opt(cfg.StrOpt('sql_connection')) self._walk_versions(conf)
def setUp(self): super(TestClientRedirects, self).setUp() self.port_one = utils.get_unused_port() self.port_two = utils.get_unused_port() server_one = wsgi.Server() server_two = wsgi.Server() conf = utils.TestConfigOpts({'bind_host': '127.0.0.1'}) server_one.start(RedirectTestApp("one"), conf, self.port_one) server_two.start(RedirectTestApp("two"), conf, self.port_two) self.client = client.BaseClient("127.0.0.1", self.port_one)
def test_http_schedule_delete_swallows_error(self): stub_out_registry_image_update(self.stubs) uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() conf = utils.TestConfigOpts({}) create_stores(conf) try: schedule_delete_from_backend(uri, conf, ctx, 'image_id') except exception.StoreDeleteNotSupported: self.fail('StoreDeleteNotSupported should be swallowed')
def setUp(self): self.test_id, self.test_dir = test_utils.get_isolated_test_env() self.stubs = stubout.StubOutForTesting() stubs.stub_out_registry_and_store_server(self.stubs, self.test_dir) options = {'sql_connection': 'sqlite://', 'verbose': False, 'debug': False, 'default_store': 'filesystem', 'filesystem_store_datadir': os.path.join(self.test_dir)} self.conf = test_utils.TestConfigOpts(options)
def setUp(self): """Establish a clean test environment""" self.stubs = stubout.StubOutForTesting() stubs.stub_out_registry_and_store_server(self.stubs) stubs.stub_out_filesystem_backend() conf = test_utils.TestConfigOpts(CONF) self.adm_context = rcontext.RequestContext(is_admin=True) self.context = rcontext.RequestContext(is_admin=False) db_api.configure_db(conf) self.destroy_fixtures() self.create_fixtures()
def test_version_control_existing_db(self): """ Creates a DB without version control information, places it under version control and checks that it can be upgraded without errors. """ for key, engine in self.engines.items(): conf = utils.TestConfigOpts( {'sql_connection': TestMigrations.TEST_DATABASES[key]}) conf.register_opt(cfg.StrOpt('sql_connection')) self._create_unversioned_001_db(engine) self._walk_versions(conf, initial_version=1)
def setUp(self): super(TestHttpStore, self).setUp() self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) self.conf = utils.TestConfigOpts({ 'default_store': 'http', 'known_stores': "glance.store.http.Store", }) configure_registry_client(self.conf)
def test_no_data_loss_2_to_3_to_2(self): """ Here, we test that in the case when we moved a column "type" from the base images table to be records in the image_properties table, that we don't lose any data during the migration. Similarly, we test that on downgrade, we don't lose any data, as the records are moved from the image_properties table back into the base image table. """ for key, engine in self.engines.items(): conf = utils.TestConfigOpts( {'sql_connection': TestMigrations.TEST_DATABASES[key]}) conf.register_opt(cfg.StrOpt('sql_connection')) self._no_data_loss_2_to_3_to_2(engine, conf)
def setUp(self): super(IsolatedUnitTest, self).setUp() self.test_id, self.test_dir = test_utils.get_isolated_test_env() self.stubs = stubout.StubOutForTesting() policy_file = self._copy_data_file('policy.json', self.test_dir) options = {'sql_connection': 'sqlite://', 'verbose': False, 'debug': False, 'default_store': 'filesystem', 'known_stores': test_utils.get_default_stores(), 'filesystem_store_datadir': os.path.join(self.test_dir), 'policy_file': policy_file} self.conf = test_utils.TestConfigOpts(options) stubs.stub_out_registry_and_store_server(self.stubs, self.conf, self.test_dir)
def getresponse(self): sql_connection = kwargs.get('sql_connection', "sqlite:///") context_class = 'glance.registry.context.RequestContext' conf = utils.TestConfigOpts({ 'sql_connection': sql_connection, 'verbose': VERBOSE, 'debug': DEBUG }) api = context.ContextMiddleware(rserver.API(conf), conf, context_class=context_class) res = self.req.get_response(api) # httplib.Response has a read() method...fake it out def fake_reader(): return res.body setattr(res, 'read', fake_reader) return res
def setUp(self): def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' return None self.notify_kombu = common_utils.import_object( "glance.notifier.notify_kombu") self.notify_kombu.RabbitStrategy._send_message = self._send_message self.notify_kombu.RabbitStrategy._connect = _fake_connect self.called = False self.conf = utils.TestConfigOpts({ "notifier_strategy": "rabbit", "rabbit_retry_backoff": 0, "rabbit_notification_topic": "fake_topic" }) self.notifier = notifier.Notifier(self.conf)
def test_add_host_variations(self): """ Test that having http(s):// in the s3serviceurl in config options works as expected. """ variations = [ 'http://localhost:80', 'http://localhost', 'http://localhost/v1', 'http://localhost/v1/', 'https://localhost', 'https://localhost:8080', 'https://localhost/v1', 'https://localhost/v1/', 'localhost', 'localhost:8080/v1' ] for variation in variations: expected_image_id = utils.generate_uuid() expected_s3_size = FIVE_KB expected_s3_contents = "*" * expected_s3_size expected_checksum = \ hashlib.md5(expected_s3_contents).hexdigest() new_conf = S3_CONF.copy() new_conf['s3_store_host'] = variation expected_location = format_s3_location( new_conf['s3_store_access_key'], new_conf['s3_store_secret_key'], new_conf['s3_store_host'], new_conf['s3_store_bucket'], expected_image_id) image_s3 = StringIO.StringIO(expected_s3_contents) self.store = Store(test_utils.TestConfigOpts(new_conf)) location, size, checksum = self.store.add(expected_image_id, image_s3, expected_s3_size) self.assertEquals(expected_location, location) self.assertEquals(expected_s3_size, size) self.assertEquals(expected_checksum, checksum) loc = get_location_from_uri(expected_location) (new_image_s3, new_image_size) = self.store.get(loc) new_image_contents = new_image_s3.getvalue() new_image_s3_size = len(new_image_s3) self.assertEquals(expected_s3_contents, new_image_contents) self.assertEquals(expected_s3_size, new_image_s3_size)
def setUp(self): """ Test to see if the pre-requisites for the image cache are working (python-xattr installed and xattr support on the filesystem) """ if getattr(self, 'disable', False): return self.cache_dir = os.path.join( "/", "tmp", "test.cache.%d" % random.randint(0, 1000000)) utils.safe_mkdirs(self.cache_dir) if not getattr(self, 'inited', False): try: import xattr except ImportError: self.inited = True self.disabled = True self.disabled_message = ("python-xattr not installed.") return self.inited = True self.disabled = False self.conf = test_utils.TestConfigOpts({ 'image_cache_dir': self.cache_dir, 'image_cache_driver': 'xattr', 'image_cache_max_size': 1024 * 5, 'registry_host': '0.0.0.0', 'registry_port': 9191 }) self.cache = image_cache.ImageCache(self.conf) if not xattr_writes_supported(self.cache_dir): self.inited = True self.disabled = True self.disabled_message = ("filesystem does not support xattr") return
def setUp(self): notifier.RabbitStrategy._send_message = self._send_message notifier.RabbitStrategy.connect = lambda s: None self.called = False conf = utils.TestConfigOpts({"notifier_strategy": "rabbit"}) self.notifier = notifier.Notifier(conf)
def setUp(self): conf = utils.TestConfigOpts({"notifier_strategy": "noop"}) self.notifier = notifier.Notifier(conf)
def setUp(self): conf = utils.TestConfigOpts({"notifier_strategy": "logging"}) self.called = False self.logger = logging.getLogger("glance.notifier.logging_notifier") self.notifier = notifier.Notifier(conf)
def test_cannot_create(self): conf = utils.TestConfigOpts({"notifier_strategy": "invalid_notifier"}) self.assertRaises(exception.InvalidNotifierStrategy, notifier.Notifier, conf)
def setUp(self): """Establish a clean test environment""" self.stubs = stubout.StubOutForTesting() stub_out_s3(self.stubs) self.store = Store(test_utils.TestConfigOpts(S3_CONF))