예제 #1
0
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
    })
예제 #2
0
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))
예제 #3
0
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)
예제 #4
0
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))
예제 #5
0
    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")
예제 #6
0
    def test_client_request_all(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)
            data = []
            for code, msg in client.request_all('lst3'):
                data += [(code, msg)]
            self.assertEqual(data, [(OK, '1 lst3'), (OK, '2 lst3'),
                                    (OK, '3 lst3')])

            status_2 = app.status()
            self.assertEqual(status_2.status, "RUNNING")

            app.stop()

            status_3 = app.status()
            self.assertEqual(status_3.status, "NOT RUNNING")
예제 #7
0
 def _timeout(self):
     socket_file = "/path/to/nothing.socket"
     client = Client(socket_file, conn_trials=3)
     with self.assertRaises(Exception):
         client.connect()