Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_cassandra.py
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | with open(str(cassandra_conf.join("cassandra.yaml")), "w") as fd: | ||||
fd.write( | fd.write( | ||||
CONFIG_TEMPLATE.format( | CONFIG_TEMPLATE.format( | ||||
data_dir=str(cassandra_data), | data_dir=str(cassandra_data), | ||||
storage_port=storage_port, | storage_port=storage_port, | ||||
native_transport_port=native_transport_port, | native_transport_port=native_transport_port, | ||||
) | ) | ||||
) | ) | ||||
if os.environ.get("LOG_CASSANDRA"): | if os.environ.get("SWH_CASSANDRA_LOG"): | ||||
stdout = stderr = None | stdout = stderr = None | ||||
else: | else: | ||||
stdout = stderr = subprocess.DEVNULL | stdout = stderr = subprocess.DEVNULL | ||||
cassandra_bin = os.environ.get("SWH_CASSANDRA_BIN", "/usr/sbin/cassandra") | |||||
proc = subprocess.Popen( | proc = subprocess.Popen( | ||||
[ | [ | ||||
"/usr/sbin/cassandra", | cassandra_bin, | ||||
"-Dcassandra.config=file://%s/cassandra.yaml" % cassandra_conf, | "-Dcassandra.config=file://%s/cassandra.yaml" % cassandra_conf, | ||||
"-Dcassandra.logdir=%s" % cassandra_log, | "-Dcassandra.logdir=%s" % cassandra_log, | ||||
"-Dcassandra.jmx.local.port=%d" % jmx_port, | "-Dcassandra.jmx.local.port=%d" % jmx_port, | ||||
"-Dcassandra-foreground=yes", | "-Dcassandra-foreground=yes", | ||||
], | ], | ||||
start_new_session=True, | start_new_session=True, | ||||
env={ | env={ | ||||
"MAX_HEAP_SIZE": "300M", | "MAX_HEAP_SIZE": "300M", | ||||
"HEAP_NEWSIZE": "50M", | "HEAP_NEWSIZE": "50M", | ||||
"JVM_OPTS": "-Xlog:gc=error:file=%s/gc.log" % cassandra_log, | "JVM_OPTS": "-Xlog:gc=error:file=%s/gc.log" % cassandra_log, | ||||
}, | }, | ||||
stdout=stdout, | stdout=stdout, | ||||
stderr=stderr, | stderr=stderr, | ||||
) | ) | ||||
running = wait_for_peer("127.0.0.1", native_transport_port) | running = wait_for_peer("127.0.0.1", native_transport_port) | ||||
if running: | if running: | ||||
yield (["127.0.0.1"], native_transport_port) | yield (["127.0.0.1"], native_transport_port) | ||||
if not running or os.environ.get("LOG_CASSANDRA"): | if not running or os.environ.get("SWH_CASSANDRA_LOG"): | ||||
with open(str(cassandra_log.join("debug.log"))) as fd: | debug_log_path = str(cassandra_log.join("debug.log")) | ||||
if os.path.exists(debug_log_path): | |||||
with open(debug_log_path) as fd: | |||||
print(fd.read()) | print(fd.read()) | ||||
if not running: | if not running: | ||||
raise Exception("cassandra process stopped unexpectedly.") | raise Exception("cassandra process stopped unexpectedly.") | ||||
pgrp = os.getpgid(proc.pid) | pgrp = os.getpgid(proc.pid) | ||||
os.killpg(pgrp, signal.SIGKILL) | os.killpg(pgrp, signal.SIGKILL) | ||||
▲ Show 20 Lines • Show All 255 Lines • Show Last 20 Lines |