def test_cli_driver_after_bad_driver_file(cmd, tmpdir, capsys): with set_skein_config(str(tmpdir)): run_command('config gencerts') driver_file = os.path.join(skein.properties.config_dir, 'driver') sock = socket.socket() sock.bind(('', 0)) address = 'localhost:%d' % sock.getsockname()[1] # Find a PID that doesn't exist pid = 1234 while pid_exists(pid): pid += 1 _write_driver(address, pid) assert os.path.exists(driver_file) if cmd == 'start': run_command('driver start') out, err = capsys.readouterr() assert out assert 'Previous driver' in err assert os.path.exists(driver_file) run_command('driver stop') out, err = capsys.readouterr() assert not out assert not err assert not os.path.exists(driver_file)
def global_client(kinit, tmpdir_factory): with set_skein_config(tmpdir_factory.mktemp('config')): run_command('config gencerts') try: run_command('driver start') yield skein.Client.from_global_driver() finally: run_command('driver stop')
def test_cli_driver_force_stop(tmpdir, capsys): with set_skein_config(str(tmpdir)): run_command('config gencerts') driver_file = os.path.join(skein.properties.config_dir, 'driver') proc = subprocess.Popen( [sys.executable, '-c', '"import time;time.sleep(10)"'] ) sock = socket.socket() sock.bind(('', 0)) address = 'localhost:%d' % sock.getsockname()[1] with closing(sock): # PID is not a skein driver _write_driver(address, proc.pid) assert os.path.exists(driver_file) run_command('driver stop', error=True) out, err = capsys.readouterr() assert not out assert err assert os.path.exists(driver_file) run_command('driver stop --force') out, err = capsys.readouterr() assert not out assert not err assert not os.path.exists(driver_file) assert proc.wait() is not None # Find a PID that doesn't exist pid = 1234 while pid_exists(pid): pid += 1 _write_driver(address, pid) assert os.path.exists(driver_file) run_command('driver stop --force') out, err = capsys.readouterr() assert not out assert not err assert not os.path.exists(driver_file)
def test_cli_driver_force_stop(tmpdir, capsys): with set_skein_config(str(tmpdir)): run_command('config gencerts') driver_file = os.path.join(skein.properties.config_dir, 'driver') proc = subprocess.Popen( [sys.executable, '-c', '"import time;time.sleep(10)"']) sock = socket.socket() sock.bind(('', 0)) address = '127.0.0.1:%d' % sock.getsockname()[1] with closing(sock): # PID is not a skein driver _write_driver(address, proc.pid) with open(driver_file) as fil: contents = fil.read() assert os.path.exists(driver_file) run_command('driver start', error=True) out, err = capsys.readouterr() assert not out assert err assert os.path.exists(driver_file) with open(driver_file) as fil: contents2 = fil.read() assert contents == contents2 run_command('driver stop', error=True) out, err = capsys.readouterr() assert not out assert err assert os.path.exists(driver_file) run_command('driver stop --force') out, err = capsys.readouterr() assert not out assert not err assert not os.path.exists(driver_file) assert proc.wait() is not None