mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-29 07:38:11 +08:00
Add a function to check the configuration for errors. (#1919)
This can be used as a sanity check before a deployment: chanzuckerberg/single-cell#63
This commit is contained in:
@@ -6,6 +6,7 @@ from server.test import PROJECT_ROOT, FIXTURES_ROOT
|
||||
from server.common.config.app_config import AppConfig
|
||||
from contextlib import contextmanager
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -34,12 +35,12 @@ class Elastic_Beanstalk_Test(unittest.TestCase):
|
||||
tempdir = tempfile.TemporaryDirectory(dir=f"{PROJECT_ROOT}/server")
|
||||
tempdirname = tempdir.name
|
||||
|
||||
c = AppConfig()
|
||||
config = AppConfig()
|
||||
# test that eb works
|
||||
c.update_server_config(multi_dataset__dataroot=f"{FIXTURES_ROOT}", app__flask_secret_key="open sesame")
|
||||
config.update_server_config(multi_dataset__dataroot=f"{FIXTURES_ROOT}", app__flask_secret_key="open sesame")
|
||||
|
||||
c.complete_config()
|
||||
c.write_config(f"{tempdirname}/config.yaml")
|
||||
config.complete_config()
|
||||
config.write_config(f"{tempdirname}/config.yaml")
|
||||
|
||||
subprocess.check_call(f"git ls-files . | cpio -pdm {tempdirname}", cwd=f"{PROJECT_ROOT}/server/eb", shell=True)
|
||||
subprocess.check_call(["make", "build"], cwd=tempdirname)
|
||||
@@ -50,3 +51,33 @@ class Elastic_Beanstalk_Test(unittest.TestCase):
|
||||
r = session.get(f"{server}/d/pbmc3k.cxg/api/v0.2/config")
|
||||
data_config = r.json()
|
||||
assert data_config["config"]["displayNames"]["dataset"] == "pbmc3k"
|
||||
|
||||
def test_config(self):
|
||||
check_config_script = os.path.join(PROJECT_ROOT, "server", "eb", "check_config.py")
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
configfile = os.path.join(tempdir, "config.yaml")
|
||||
app_config = AppConfig()
|
||||
app_config.update_server_config(multi_dataset__dataroot=f"{FIXTURES_ROOT}")
|
||||
app_config.write_config(configfile)
|
||||
|
||||
command = ["python", check_config_script, configfile]
|
||||
|
||||
# test failure mode (flask_secret_key not set)
|
||||
env = os.environ.copy()
|
||||
env.pop("CXG_SECRET_KEY", None)
|
||||
with self.assertRaises(subprocess.CalledProcessError) as exception_context:
|
||||
subprocess.check_output(command, env=env)
|
||||
output = str(exception_context.exception.stdout, "utf-8")
|
||||
self.assertTrue(
|
||||
output.startswith(
|
||||
"Error: Invalid type for attribute: app__flask_secret_key, expected type str, got NoneType"
|
||||
)
|
||||
)
|
||||
self.assertEqual(exception_context.exception.returncode, 1)
|
||||
|
||||
# test passing case
|
||||
env = os.environ.copy()
|
||||
env["CXG_SECRET_KEY"] = "secret"
|
||||
output = subprocess.check_output(command, env=env)
|
||||
output = str(output, "utf-8")
|
||||
self.assertTrue(output.startswith("PASS"))
|
||||
|
||||
Reference in New Issue
Block a user