def _remove_old_tmp_dirs(): pkdlog('scanning for stale tmp dirs') count = 0 cutoff = time.time() - srdb.TMP_DIR_CLEANUP_TIME for dirpath, dirnames, filenames in os.walk(srdb.root()): if (dirpath.endswith(srdb.TMP_DIR_SUFFIX) and os.stat(dirpath).st_mtime < cutoff): pkdlog('removing stale tmp dir: {}', dirpath) pkio.unchecked_remove(dirpath) count += 1 pkdlog('finished scanning for stale tmp dirs ({} found)', count)
def _init_dev_hosts(cls): assert pkconfig.channel_in('dev') from sirepo import srdb assert not (cls.cfg.tls_dir or cls.cfg.hosts), \ 'neither cfg.tls_dir and cfg.hosts nor must be set to get auto-config' # dev mode only; see _cfg_tls_dir and _cfg_hosts cls.cfg.tls_dir = srdb.root().join('docker_tls') cls.cfg.hosts = ('localhost.localdomain',) d = cls.cfg.tls_dir.join(cls.cfg.hosts[0]) if d.check(dir=True): return pkdlog('initializing docker dev env; initial docker pull will take a few minutes...') d.ensure(dir=True) for f in 'key.pem', 'cert.pem': o = subprocess.check_output(['sudo', 'cat', '/etc/docker/tls/' + f]).decode('utf-8') assert o.startswith('-----BEGIN'), \ 'incorrect tls file={} content={}'.format(f, o) d.join(f).write(o) # we just reuse the same cert as the docker server since it's local host d.join('cacert.pem').write(o)
def _cfg_db_dir(value): """DEPRECATED""" if value is not None: srdb.server_init_root(value) return srdb.root()
def proprietary_code_dir(sim_type): return srdb.root().join(_PROPRIETARY_CODE_DIR, sim_type)
def test_runner_myapp(): os.environ['SIREPO_FEATURE_CONFIG_RUNNER_DAEMON'] = '1' os.environ['PYTHONUNBUFFERED'] = '1' py3_env = _assert_py3() from pykern import pkio from pykern import pkunit from pykern.pkdebug import pkdc, pkdp from sirepo import srunit fc = srunit.flask_client(sim_types='myapp') fc.sr_login_as_guest() from sirepo import srdb pkdc(srdb.runner_socket_path()) pkio.unchecked_remove(srdb.runner_socket_path()) runner_env = dict(py3_env) runner_env['SIREPO_SRDB_ROOT'] = str(srdb.root()) runner = subprocess.Popen( ['pyenv', 'exec', 'sirepo', 'runner', 'start'], env=runner_env, ) try: for _ in range(30): if srdb.runner_socket_path().exists(): break time.sleep(0.1) else: pkunit.pkfail('runner daemon did not start up') fc.get('/myapp') data = fc.sr_post( 'listSimulations', {'simulationType': 'myapp', 'search': {'simulationName': 'heightWeightReport'}}, ) pkdc(data) data = data[0].simulation pkdc(data) data = fc.sr_get_json( 'simulationData', params=dict( pretty='1', simulation_id=data.simulationId, simulation_type='myapp', ), ) pkdc(data) run = fc.sr_post( 'runSimulation', dict( forceRun=False, models=data.models, report='heightWeightReport', simulationId=data.models.simulation.simulationId, simulationType=data.simulationType, ), ) pkdc(run) for _ in range(10): run = fc.sr_post( 'runStatus', run.nextRequest ) pkdc(run) if run.state == 'completed': break time.sleep(1) else: pkunit.pkfail('runStatus: failed to complete: {}', run) # Just double-check it actually worked assert u'plots' in run finally: runner.terminate() runner.wait()