def test_aodh_with_existing_db(self): pg = self.useFixture(postgresql.PostgreSQLDriver(port=12345)) a = self.useFixture(aodh.AodhDriver(database_url=pg.url)) self.assertEqual("aodh://localhost:%d" % a.port, os.getenv("PIFPAF_URL")) r = requests.get(os.getenv("PIFPAF_AODH_HTTP_URL")) self.assertEqual(200, r.status_code)
def test_postgresql(self): port = 9825 f = self.useFixture(postgresql.PostgreSQLDriver(port=port)) self.assertEqual( "postgresql://localhost/postgres?host=%s&port=%d" % (f.tempdir, port), os.getenv("PIFPAF_URL")) self._run("psql template1 -c 'CREATE TABLE FOOBAR();'")
def test_gnocchi_with_existing_indexer(self): port = gnocchi.GnocchiDriver.DEFAULT_PORT + 15 pg = self.useFixture(postgresql.PostgreSQLDriver(port=9833)) self.useFixture(gnocchi.GnocchiDriver(indexer_url=pg.url, port=port)) self.assertEqual("gnocchi://localhost:%d" % port, os.getenv("PIFPAF_URL")) r = requests.get("http://localhost:%d/" % port) self.assertEqual(200, r.status_code)
def _setUp(self): super(AodhDriver, self)._setUp() with open(self.find_config_file("aodh/api_paste.ini"), "r") as src: with open(os.path.join(self.tempdir, "api_paste.ini"), "w") as dst: for line in src.readlines(): if line.startswith("pipeline = "): dst.write("pipeline = request_id api-server") else: dst.write(line) shutil.copy(self.find_config_file("aodh/policy.json"), self.tempdir) pg = self.useFixture( postgresql.PostgreSQLDriver(port=self.database_port)) g = self.useFixture( gnocchi.GnocchiDriver( port=self.gnocchi_port, indexer_port=self.gnocchi_indexer_port, create_legacy_resource_types=( self.gnocchi_create_legacy_resource_types), )) conffile = os.path.join(self.tempdir, "aodh.conf") user = str(uuid.uuid4()) project = str(uuid.uuid4()) with open(conffile, "w") as f: f.write("""[database] connection = %s [api] port = %d [service_credentials] auth_type = gnocchi-noauth user_id = %s project_id = %s roles = admin endpoint = %s""" % (pg.url, self.port, user, project, g.http_url)) self._exec(["aodh-dbsync", "--config-file=%s" % conffile]) c, _ = self._exec( ["aodh-api", "--config-file=%s" % conffile], wait_for_line=b"Running on http://0.0.0.0") self.addCleanup(self._kill, c.pid) self.putenv("PIFPAF_AODH_PORT", str(self.port)) self.putenv("PIFPAF_AODH_GNOCCHI_USER_ID", user) self.putenv("PIFPAF_AODH_GNOCCHI_PROJECT_ID", project) self.putenv("PIFPAF_URL", "aodh://localhost:%d" % self.port) self.putenv("PIFPAF_AODH_HTTP_URL", "http://localhost:%d" % self.port)
def _setUp(self): super(AodhDriver, self)._setUp() if self.database_url is None: pg = self.useFixture( postgresql.PostgreSQLDriver(port=self.database_port)) self.database_url = pg.url g = self.useFixture( gnocchi.GnocchiDriver( port=self.gnocchi_port, indexer_port=self.gnocchi_indexer_port, )) conffile = os.path.join(self.tempdir, "aodh.conf") with open(conffile, "w") as f: f.write("""[database] connection = %s [api] auth_mode= [service_credentials] auth_type = gnocchi-basic user = admin endpoint = %s""" % (self.database_url, g.http_url)) self._exec(["aodh-dbsync", "--config-file=%s" % conffile]) c, _ = self._exec([ "aodh-api", "--port", str(self.port), "--", "--config-file=%s" % conffile ], wait_for_line="Available at http://") self.addCleanup(self._kill, c) c, _ = self._exec( ["aodh-evaluator", "--config-file=%s" % conffile], wait_for_line="initiating evaluation cycle") self.addCleanup(self._kill, c) self.putenv("AODH_PORT", str(self.port)) self.putenv("AODH_GNOCCHI_USER", "admin") self.putenv("URL", "aodh://localhost:%d" % self.port) url = "http://localhost:%d" % self.port self.putenv("AODH_HTTP_URL", url) self.putenv("AODH_ENDPOINT", url, True)
def _setUp(self): super(GnocchiDriver, self)._setUp() shutil.copy(self.find_config_file("gnocchi/api-paste.ini"), self.tempdir) shutil.copy(self.find_config_file("gnocchi/policy.json"), self.tempdir) pg = self.useFixture( postgresql.PostgreSQLDriver(port=self.indexer_port)) conffile = os.path.join(self.tempdir, "gnocchi.conf") with open(conffile, "w") as f: f.write("""[storage] file_basepath = %s driver = file [indexer] url = %s""" % (self.tempdir, pg.url)) gnocchi_upgrade = ["gnocchi-upgrade", "--config-file=%s" % conffile] if self.create_legacy_resource_types: gnocchi_upgrade.append("--create-legacy-resource-types") self._exec(gnocchi_upgrade) c, _ = self._exec(["gnocchi-metricd", "--config-file=%s" % conffile], wait_for_line="metrics wait to be processed") self.addCleanup(self._kill, c.pid) c, _ = self._exec([ "gnocchi-api", "--port", str(self.port), "--", "--config-file=%s" % conffile ], wait_for_line="Available at http://") self.addCleanup(self._kill, c.pid) self.http_url = "http://localhost:%d" % self.port self.putenv("GNOCCHI_PORT", str(self.port)) self.putenv("URL", "gnocchi://localhost:%d" % self.port) self.putenv("GNOCCHI_HTTP_URL", self.http_url) self.putenv("GNOCCHI_ENDPOINT", self.http_url, True) self.putenv("OS_AUTH_TYPE", "gnocchi-noauth", True) self.putenv("GNOCCHI_USER_ID", "admin", True) self.putenv("GNOCCHI_PROJECT_ID", "admin", True)
def _setUp(self): super(GnocchiDriver, self)._setUp() try: shutil.copy(self.find_config_file("gnocchi/api-paste.ini"), self.tempdir) except RuntimeError: pass try: shutil.copy(self.find_config_file("gnocchi/policy.json"), self.tempdir) except RuntimeError: pass if self.indexer_url is None: pg = self.useFixture( postgresql.PostgreSQLDriver(port=self.indexer_port)) self.indexer_url = pg.url if self.storage_url is None: self.storage_url = "file://%s" % self.tempdir conffile = os.path.join(self.tempdir, "gnocchi.conf") storage_parsed = urlparse.urlparse(self.storage_url) storage_driver = storage_parsed.scheme if storage_driver == "s3": storage_config = { "s3_access_key_id": (urlparse.unquote(storage_parsed.username or "gnocchi")), "s3_secret_access_key": (urlparse.unquote(storage_parsed.password or "whatever")), "s3_endpoint_url": "http://%s:%s/%s" % ( storage_parsed.hostname, storage_parsed.port, storage_parsed.path, ) } elif storage_driver == "swift": storage_config = { "swift_authurl": "http://%s:%s%s" % ( storage_parsed.hostname, storage_parsed.port, storage_parsed.path, ), "swift_user": (urlparse.unquote(storage_parsed.username or "admin:admin")), "swift_key": (urlparse.unquote(storage_parsed.password or "admin")), } elif storage_driver == "ceph": storage_config = { "ceph_conffile": storage_parsed.path, } elif storage_driver == "redis": storage_config = { "redis_url": self.storage_url, } elif storage_driver == "file": storage_config = { "file_basepath": (storage_parsed.path or self.tempdir), } else: raise RuntimeError("Storage driver %s is not supported" % storage_driver) if self.coordination_driver == "redis": r = self.useFixture(redis.RedisDriver(port=self.coordination_port)) storage_config["coordination_url"] = r.url storage_config_string = "\n".join("%s = %s" % (k, v) for k, v in storage_config.items()) statsd_resource_id = str(uuid.uuid4()) with open(conffile, "w") as f: f.write("""[DEFAULT] debug = %s verbose = True [storage] driver = %s %s [metricd] metric_processing_delay = 1 metric_cleanup_delay = 1 [statsd] resource_id = %s creator = admin user_id = admin project_id = admin [indexer] url = %s""" % (self.debug, storage_driver, storage_config_string, statsd_resource_id, self.indexer_url)) self._exec(["gnocchi-upgrade", "--config-file=%s" % conffile]) c, _ = self._exec(["gnocchi-metricd", "--config-file=%s" % conffile], wait_for_line="metrics wait to be processed") c, _ = self._exec( ["gnocchi-statsd", "--config-file=%s" % conffile], wait_for_line=("(Resource .* already exists" "|Created resource )")) args = [ "uwsgi", "--http", "localhost:%d" % self.port, "--wsgi-file", spawn.find_executable("gnocchi-api"), "--master", "--die-on-term", "--lazy-apps", "--processes", "4", "--no-orphans", "--enable-threads", "--chdir", self.tempdir, "--add-header", "Connection: close", "--pyargv", "--config-file=%s" % conffile, ] virtual_env = os.getenv("VIRTUAL_ENV") if virtual_env is not None: args.extend(["-H", virtual_env]) c, _ = self._exec(args, wait_for_line="WSGI app 0 \(mountpoint=''\) ready") self.addCleanup(self._kill, c) self.http_url = "http://localhost:%d" % self.port self.putenv("GNOCCHI_PORT", str(self.port)) self.putenv("URL", "gnocchi://localhost:%d" % self.port) self.putenv("GNOCCHI_HTTP_URL", self.http_url) self.putenv("GNOCCHI_ENDPOINT", self.http_url, True) self.putenv("OS_AUTH_TYPE", "gnocchi-basic", True) self.putenv("GNOCCHI_STATSD_RESOURCE_ID", statsd_resource_id, True) self.putenv("GNOCCHI_USER", "admin", True)
def _setUp(self): super(GnocchiDriver, self)._setUp() try: shutil.copy(self.find_config_file("gnocchi/api-paste.ini"), self.tempdir) except RuntimeError: pass try: shutil.copy(self.find_config_file("gnocchi/policy.json"), self.tempdir) except RuntimeError: pass if self.indexer_url is None: pg = self.useFixture( postgresql.PostgreSQLDriver(port=self.indexer_port)) self.indexer_url = pg.url if self.storage_url is None: self.storage_url = "file://%s" % self.tempdir conffile = os.path.join(self.tempdir, "gnocchi.conf") storage_parsed = urlparse.urlparse(self.storage_url) storage_driver = storage_parsed.scheme if storage_driver == "s3": storage_config = { "s3_access_key_id": (urlparse.unquote(storage_parsed.username or "gnocchi")), "s3_secret_access_key": ( urlparse.unquote(storage_parsed.password or "whatever")), "s3_endpoint_url": "http://%s:%s/%s" % ( storage_parsed.hostname, storage_parsed.port, storage_parsed.path, ) } elif storage_driver == "swift": storage_config = { "swift_auth_url": "http://%s:%s/%s" % ( storage_parsed.hostname, storage_parsed.port, storage_parsed.path, ), "swift_user": (urlparse.unquote(storage_parsed.username or "admin:admin")), "swift_key": (urlparse.unquote(storage_parsed.password or "admin")), } elif storage_driver == "ceph": storage_config = { "ceph_conffile": storage_parsed.path, } elif storage_driver == "redis": storage_config = { "redis_url": self.storage_url, } elif storage_driver == "file": storage_config = { "file_basepath": (storage_parsed.path or self.tempdir), } else: raise RuntimeError("Storage driver %s is not supported" % storage_driver) storage_config_string = "\n".join( "%s = %s" % (k, v) for k, v in storage_config.items() ) statsd_resource_id = str(uuid.uuid4()) with open(conffile, "w") as f: f.write("""[storage] driver = %s %s [metricd] metric_processing_delay = 1 metric_cleanup_delay = 1 [statsd] resource_id = %s creator = admin user_id = admin project_id = admin [indexer] url = %s""" % (storage_driver, storage_config_string, statsd_resource_id, self.indexer_url)) gnocchi_upgrade = ["gnocchi-upgrade", "--config-file=%s" % conffile] if self.create_legacy_resource_types: gnocchi_upgrade.append("--create-legacy-resource-types") self._exec(gnocchi_upgrade) c, _ = self._exec(["gnocchi-metricd", "--config-file=%s" % conffile], wait_for_line="metrics wait to be processed") self.addCleanup(self._kill, c.pid) c, _ = self._exec(["gnocchi-statsd", "--config-file=%s" % conffile], wait_for_line=("(Resource .* already exists" "|Created resource )")) self.addCleanup(self._kill, c.pid) c, _ = self._exec( ["gnocchi-api", "--port", str(self.port), "--", "--config-file=%s" % conffile], wait_for_line="Available at http://") self.addCleanup(self._kill, c.pid) self.http_url = "http://localhost:%d" % self.port self.putenv("GNOCCHI_PORT", str(self.port)) self.putenv("URL", "gnocchi://localhost:%d" % self.port) self.putenv("GNOCCHI_HTTP_URL", self.http_url) self.putenv("GNOCCHI_ENDPOINT", self.http_url, True) self.putenv("OS_AUTH_TYPE", "gnocchi-basic", True) self.putenv("GNOCCHI_STATSD_RESOURCE_ID", statsd_resource_id, True) self.putenv("GNOCCHI_USER", "admin", True)