def test_reload_file(self):
     ls = LaunchServicer()
     path = interpret_path(
         "$(find fkie_node_manager_daemon)/tests/resources/description_example.launch"
     )
     response = ls.ReloadLaunch(lmsg.LaunchFile(path=path), DummyContext())
     self.assertEqual(
         response.status.code,
         lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
         "wrong status code on reload of not loaded file, result: %d, expected: %d, reported error: %s"
         % (response.status.code,
            lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
            response.status.error_msg))
     response = ls.LoadLaunch(
         lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                launch='description_example.launch',
                                path=path), DummyContext())
     self.assertEqual(
         response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
         "wrong status code on successful load, result: %d, expected: %d, reported error: %s"
         % (response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
            response.status.error_msg))
     response = ls.ReloadLaunch(lmsg.LaunchFile(path=path), DummyContext())
     self.assertEqual(
         response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
         "wrong status code on reload of already loaded file, result: %d, expected: %d, reported error: %s"
         % (response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
            response.status.error_msg))
 def test_get_nodes(self):
     ls = LaunchServicer()
     path = interpret_path(
         "$(find fkie_node_manager_daemon)/tests/resources/description_example.launch"
     )
     response = ls.LoadLaunch(
         lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                launch='description_example.launch',
                                path=path), DummyContext())
     self.assertEqual(
         response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
         "wrong status code on successful load, result: %d, expected: %d, reported error: %s"
         % (response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
            response.status.error_msg))
     response_stream = ls.GetNodes(
         lmsg.ListNodesRequest(request_description=True), DummyContext())
     nodes = {}
     descriptions = []
     for response in response_stream:
         nodes[response.launch_file] = list(response.node)
         for descr in response.description:
             rd = RobotDescription(machine=descr.machine,
                                   robot_name=descr.robot_name,
                                   robot_type=descr.robot_type,
                                   robot_images=list(descr.robot_images),
                                   robot_descr=descr.robot_descr)
             for cap in descr.capabilities:
                 cp = Capability(name=cap.name,
                                 namespace=cap.namespace,
                                 cap_type=cap.type,
                                 images=[img for img in cap.images],
                                 description=cap.description,
                                 nodes=[n for n in cap.nodes])
                 rd.capabilities.append(cp)
             descriptions.append(rd)
     self.assertEqual(
         len(nodes), 1,
         "wrong count of returned launch files for nodes, result: %d, expected: %d"
         % (len(nodes), 1))
     self.assertEqual(
         len(nodes[path]), 15,
         "wrong count of returned nodes, result: %d, expected: %d" %
         (len(nodes[path]), 15))
     self.assertEqual(
         len(descriptions), 2,
         "wrong count of descriptions, result: %d, expected: %d" %
         (len(descriptions), 2))
     self.assertEqual(
         descriptions[0].robot_name, 'pc',
         "wrong robot_name in first description, result: %s, expected: %s, description: %s"
         % (descriptions[0].robot_name, 'pc', descriptions[0]))
     self.assertEqual(
         len(descriptions[0].capabilities), 0,
         "wrong count of capabilities in first description, result: %d, expected: %d, description: %s"
         % (len(descriptions[0].capabilities), 0, descriptions[0]))
     self.assertEqual(
         len(descriptions[1].capabilities), 9,
         "wrong count of capabilities in second description, result: %d, expected: %d, description: %s"
         % (len(descriptions[1].capabilities), 9, descriptions[1]))
示例#3
0
 def load_launch(self,
                 package,
                 launch,
                 path='',
                 args=None,
                 request_args=False,
                 masteruri='',
                 host=''):
     '''
     :return: tuple with launch file, dictionary of requested arguments
     :rtype: str, {str: str}
     '''
     arguments = args
     if arguments is None:
         arguments = {}
     request = lmsg.LoadLaunchRequest(package=package,
                                      launch=launch,
                                      path=path,
                                      request_args=request_args,
                                      masteruri=masteruri,
                                      host=host)
     request.args.extend([
         lmsg.Argument(name=name, value=value)
         for name, value in arguments.items()
     ])
     response = self.lm_stub.LoadLaunch(request,
                                        timeout=settings.GRPC_TIMEOUT)
     if response.status.code == OK:
         pass
     elif response.status.code == MULTIPLE_LAUNCHES:
         raise exceptions.LaunchSelectionRequest(
             [_path for _path in response.path], response.status.error_msg)
     elif response.status.code == PARAMS_REQUIRED:
         raise exceptions.ParamSelectionRequest(
             {arg.name: arg.value
              for arg in response.args}, response.status.error_msg)
     elif response.status.code == ALREADY_OPEN:
         raise exceptions.AlreadyOpenException(response.path[0],
                                               response.status.error_msg)
     else:
         raise exceptions.RemoteException(response.status.code,
                                          response.status.error_msg)
     return response.path[0], {arg.name: arg.value for arg in response.args}
    def test_load_launch(self):
        ls = LaunchServicer()
        path = ''
        args = {}
        request_args = True
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='no_file.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
            "wrong status code if launch file not exists, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
               response.status.error_msg))
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='unknonwn_package',
                                   launch='no_file.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
            "wrong status code if package not exists, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
               response.status.error_msg))
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('MULTIPLE_LAUNCHES'),
            "wrong status code for multiple launch files, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('MULTIPLE_LAUNCHES'),
               response.status.error_msg))
        self.assertEqual(
            len(response.path), 2,
            "wrong count of multiple launch files, result: %d, expected: %d" %
            (len(response.path), 2))
        path = interpret_path(
            "$(find fkie_node_manager_daemon)/tests/resources/description_example.launch"
        )
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('PARAMS_REQUIRED'),
            "wrong status code for request arguments, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('PARAMS_REQUIRED'),
               response.status.error_msg))
        args = {arg.name: arg.value for arg in response.args}
        request_args = False
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
            "wrong status code on successful load, result: %d, expected: %d, reported error: %s"
            % (response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
               response.status.error_msg))

        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('ALREADY_OPEN'),
            "wrong status code if file is already open, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('ALREADY_OPEN'),
               response.status.error_msg))
        self.assertEqual(
            response.path[0], path,
            "Wrong returned path in ALREADY_OPEN reply, expected: %s, got: %s"
            % (response.path[0], path))

        # test loaded file
        response_stream = ls.GetLoadedFiles(lmsg.Empty(), DummyContext())
        items = [response for response in response_stream]
        self.assertEqual(
            len(items), 1,
            "The count of loaded files after successful load is wrong")
        self.assertEqual(
            items[0].path, path,
            "Wrong reported loaded file path, got: %s, expected: %s" %
            (items[0].path, path))
        self.assertEqual(
            items[0].package, 'fkie_node_manager_daemon',
            "Wrong reported loaded package, got: %s, expected: %s" %
            (items[0].package, 'fkie_node_manager_daemon'))
        self.assertEqual(
            items[0].launch, 'description_example.launch',
            "Wrong reported loaded launch, got: %s, expected: %s" %
            (items[0].launch, 'description_example.launch'))