def test_service_call(self, create_connection): """ Check that we correctly send the call. """ create_connection.return_value = Mock() create_connection.return_value.recv = Mock(return_value=b'') adress = ('127.0.0.1', 20001) method_name = 'foo' method_params = [12] expected_data = service_call.encode_call(method_name, method_params) service_call.call(adress, method_name, method_params) create_connection.assert_any_call(adress) create_connection.return_value.sendall.assert_any_call(expected_data)
def test_service_call(self, create_connection): """ Check that we correctly send the call. """ create_connection.return_value = Mock() create_connection.return_value.recv = Mock( return_value=msgpack.packb(None)) adress = ('127.0.0.1', 20001) method_name = 'foo' method_params = [12] expected_data = service_call.encode_call(method_name, method_params) service_call.call(adress, method_name, method_params) create_connection.assert_any_call(adress) create_connection.return_value.sendall.assert_any_call(expected_data)
def test_service_call_answer(self, create_connection): """ Check that the service call is correctly answered. """ create_connection.return_value = Mock() adress = ('127.0.0.1', 20001) return_data = msgpack.packb([1, 'bar']) create_connection.return_value.recv = Mock(return_value=return_data) result = service_call.call(adress, 'foo') self.assertEqual(result, [1, 'bar'])
def test_service_call_answer(self, create_connection): """ Check that the service call is correctly answered. """ create_connection.return_value = Mock() adress = ('127.0.0.1', 20001) return_data = msgpack.packb(1)+msgpack.packb('bar') create_connection.return_value.recv = Mock(return_value=return_data) result = service_call.call(adress, 'foo') self.assertEqual(result, (1, 'bar'))
def set_led(host, led, state): """ Sets the given LED on the given host. if led is an iterable but not a string (array for example), every LED in the iterable will be set to state. """ if isinstance(led, str): res = service_call.call(host, 'led_set', [led, state]) if res: raise RuntimeError("Error setting LED: {}".format(str(res))) else: for i in led: set_led(host, i, state)
from cvra_rpc.service_call import call import argparse parser = argparse.ArgumentParser( description="Reboot all the nodes connected to the UAVCAN bus.") parser.add_argument("master", help="IP of the master board.") parser.add_argument("--port", "-p", type=int, help="SimpleRPC port to use.", default=20001) parser.add_argument("ids", metavar='DEVICEID', nargs='*', type=int, help="Device IDs to reboot") parser.add_argument('-a', '--all', help="Try to scan all network.", action='store_true') args = parser.parse_args() if args.all: call((args.master, args.port), "reboot_node", [255]) else: call((args.master, args.port), "reboot_node", args.ids)
from cvra_rpc.service_call import call import argparse parser = argparse.ArgumentParser(description="Reboot all the nodes connected to the UAVCAN bus.") parser.add_argument("master", help="IP of the master board.") parser.add_argument("--port", "-p", type=int, help="SimpleRPC port to use.", default=20001) parser.add_argument("ids", metavar='DEVICEID', nargs='*', type=int, help="Device IDs to reboot") parser.add_argument('-a', '--all', help="Try to scan all network.", action='store_true') args = parser.parse_args() if args.all: call((args.master, args.port), "reboot_node", [255]) else: call((args.master, args.port), "reboot_node", args.ids)
def create_actuator(name): return call((HOST, 20001), 'actuator_create_driver', [name])
from cvra_rpc.service_call import call import argparse parser = argparse.ArgumentParser(description="Reboot all the nodes connected to the UAVCAN bus.") parser.add_argument("master", help="IP of the master board.") parser.add_argument("--port", "-p", type=int, help="SimpleRPC port to use.", default=20001) parser.add_argument("--node", "-n", type=int, help="ID of the node to reboot (default: all).", default=255) args = parser.parse_args() call((args.master, args.port), "reboot_node", [args.node])