def put_inode_object(p, remove): mode = os.stat(p) socket_file = DmServer.get_socket_file() client = Client(socket_file) code, result = client.request({ "op": "put", "inode": mode.st_ino, "remove": remove })
def _client(self): with Tempdir(prefix="Test_", remove=REMOVE_TEMP) as td: app = ServerApp(MyServer, work_dir=td) status_1 = app.status() self.assertEqual(status_1.status, "NOT RUNNING") app.start() client = Client(app.socket_file) self.assertEqual(client.request('msg'), (OK, '1 msg')) self.assertEqual(client.request('msg'), (OK, '2 msg')) self.assertEqual(client.request('msg'), (OK, '3 msg')) status_2 = app.status() self.assertEqual(status_2.status, "RUNNING") app.stop() status_3 = app.status() self.assertEqual(status_3.status, "NOT RUNNING")
def get_inode_object(path): mode = os.stat(path) socket_file = DmServer.get_socket_file() client = Client(socket_file) code, result = client.request({"op": "get", "inode": mode.st_ino}) if code == ReturnCode.OK: return json.loads(result) else: print(result) raise ValueError("failed: %s" % ReturnCode.to_string(code))
def wait_for_states(paths, states): inodes = [os.stat(p).st_ino for p in paths] socket_file = DmServer.get_socket_file() client = Client(socket_file) while True: code, result = client.request({ "op": "is_in_state", "inodes": inodes, "states": states }) if json.loads(result).get('is_in_state'): break time.sleep(1)
def do_get(argv=sys.argv[1:]): parser = ArgumentParser(description='Get a value') parser.add_argument("key", type=str, help="key") parser.add_argument("-v", "--verbose", action='store_true', help="verbose logging") args = parser.parse_args() app = ServerApp(ExampleServer, verbose=args.verbose) app.start() client = Client(app.socket_file) req = {"op": "get", "key": args.key} code, result = client.request(json.dumps(req)) if code == ReturnCode.OK: print(result) else: print(result) raise ValueError("failed: %s" % ReturnCode.to_string(code))