コード例 #1
0
    def test_process_call_request_exceptions(self):

        request = remote.encode_call_request("test_server_channel",
                                             "raiser_function", ["MYVAR"], [],
                                             {"MYVAR": "VALUE1"}, {}, [])
        test_connector.create_file("/tmp/sremote_test/request.data", request)
        server = ServerChannel()
        return_content = server.process_call_request(
            "/tmp/sremote_test/request.data",
            "/tmp/sremote_test/response.data")
        file_response = open("/tmp/sremote_test/response.data")
        response_content = file_response.read()
        status, reponse_obj = remote.decode_call_response(response_content)
        self.assertFalse(status)

        self.assertEqual(reponse_obj["sremote_type"],
                         "ExceptionRemoteExecError")

        request = remote.encode_call_request("test_server_channel",
                                             "non_exist", ["MYVAR"], [],
                                             {"MYVAR": "VALUE1"}, {}, [])
        test_connector.create_file("/tmp/sremote_test/request.data", request)
        server = ServerChannel()
        return_content = server.process_call_request(
            "/tmp/sremote_test/request.data",
            "/tmp/sremote_test/response.data")
        file_response = open("/tmp/sremote_test/response.data")
        response_content = file_response.read()
        status, reponse_obj = remote.decode_call_response(response_content)
        self.assertFalse(status)

        self.assertEqual(reponse_obj["sremote_type"],
                         "ExceptionRemoteExecError")
コード例 #2
0
 def test_place_and_execute(self):
     self._configure_remote_environment()
     
     serialized_method_call_request = \
             remote.encode_call_request("os", "listdir",
                                     args=["/tmp/sremote_test/"])
     response, output, location, response_location = \
         self._connector.place_and_execute(serialized_method_call_request)
     code, function_return = remote.decode_call_response(response)
     self.assertIn("interpreter.sh", function_return)
コード例 #3
0
 def test_process_call_request_exceptions(self):
     
     request = remote.encode_call_request("test_server_channel",
                                        "raiser_function",
                                        ["MYVAR"],
                                        [],
                                        {"MYVAR": "VALUE1"},
                                        {}, 
                                        [])
     test_connector.create_file("/tmp/sremote_test/request.data", request)
     server = ServerChannel()
     return_content=server.process_call_request(
                                 "/tmp/sremote_test/request.data",
                                  "/tmp/sremote_test/response.data")
     file_response = open("/tmp/sremote_test/response.data")
     response_content = file_response.read()       
     status, reponse_obj = remote.decode_call_response(response_content)
     self.assertFalse(status)
     
     self.assertEqual(reponse_obj["sremote_type"], 
                      "ExceptionRemoteExecError")
     
     
     request = remote.encode_call_request("test_server_channel",
                                        "non_exist",
                                        ["MYVAR"],
                                        [],
                                        {"MYVAR": "VALUE1"},
                                        {}, 
                                        [])
     test_connector.create_file("/tmp/sremote_test/request.data", request)
     server = ServerChannel()
     return_content=server.process_call_request(
                                 "/tmp/sremote_test/request.data",
                                  "/tmp/sremote_test/response.data")
     file_response = open("/tmp/sremote_test/response.data")
     response_content = file_response.read()       
     status, reponse_obj = remote.decode_call_response(response_content)
     self.assertFalse(status)
     
     self.assertEqual(reponse_obj["sremote_type"], 
                      "ExceptionRemoteExecError")
コード例 #4
0
 def test_decode_call_response(self):
     self.assertEqual(
         remote.decode_call_response(
             """{"return_value" : "RETURN VALUE",
                           "success": true,
                           "sremote_version": """ +
             _quote(_get_module_version("sremote")) + """,
                           "modules_check": 
                           {"sremote": """ +
             _quote(_get_module_version("sremote")) + """}}"""),
         (True, "RETURN VALUE"))
コード例 #5
0
 def test_effectice_pwd(self):
     self._configure_remote_environment()
     #- not using /tmp/ folder, because in OsX it maps to /private/tmp/
     self._connector.set_pwd_at_home_dir("tmp/testpwd")
     serialized_method_call_request = \
         remote.encode_call_request("os", "getcwd")
     
     response, output, location, response_location = \
         self._connector.place_and_execute(serialized_method_call_request)
     code, function_return = remote.decode_call_response(response)
     self.assertEqual(self._connector.get_home_dir()+"/tmp/testpwd", 
                      function_return)
コード例 #6
0
ファイル: test_tools.py プロジェクト: gonzalorodrigo/sremote
 def test_decode_call_response(self):
     self.assertEqual(remote.decode_call_response(
                     """{"return_value" : "RETURN VALUE",
                           "success": true,
                           "sremote_version": """+
                           _quote(_get_module_version("sremote"))+ """,
                           "modules_check": 
                           {"sremote": """+
                             _quote(_get_module_version("sremote"))+
                         """}}"""),
                       (True,
                        "RETURN VALUE"
                        ))
コード例 #7
0
 def test_remote_environemt(self):
     self._configure_remote_environment()
     
     serialized_method_call_request = \
             remote.encode_call_request("os", "getenv",
                                     args=["MYVAR",
                                          None],
                                     remote_env_variables =
                                         {"MYVAR":"MYVALUE"}
                                     )
     response, output, location, response_location = \
         self._connector.place_and_execute(serialized_method_call_request)
     code, function_return = remote.decode_call_response(response)
     self.assertEqual(function_return, "MYVALUE")
     
     serialized_method_call_request = \
             remote.encode_call_request("os", "getenv",
                                     args=["PATH",
                                          None],
                                     conditional_remote_env_variables =
                                         {"PATH":"MYVALUE"}
                                     )
     response, output, location, response_location = \
         self._connector.place_and_execute(serialized_method_call_request)
     code, function_return = remote.decode_call_response(response)
     self.assertNotEqual(function_return, "MYVALUE")
     
     serialized_method_call_request = \
     remote.encode_call_request("os", "getenv",
                             args=["PATH",
                                  None],
                             remote_path_addons =
                                 ["/impossible_dir"]
                             )
     response, output, location, response_location = \
         self._connector.place_and_execute(serialized_method_call_request)
     code, function_return = remote.decode_call_response(response)
     self.assertIn("/impossible_dir", function_return.split(":"))
コード例 #8
0
    def test_process_call_request(self):
        request = remote.encode_call_request("os", "getenv", ["MYVAR"], [],
                                             {"MYVAR": "VALUE1"}, {}, [])
        test_connector.create_file("/tmp/sremote_test/request.data", request)
        server = ServerChannel()
        return_content = server.process_call_request(
            "/tmp/sremote_test/request.data",
            "/tmp/sremote_test/response.data")
        file_response = open("/tmp/sremote_test/response.data")
        response_content = file_response.read()

        self.assertEqual(return_content, response_content)

        status, reponse_obj = remote.decode_call_response(response_content)
        self.assertEqual(reponse_obj, "VALUE1")
コード例 #9
0
 def test_process_call_request(self):
     request = remote.encode_call_request("os",
                                        "getenv",
                                        ["MYVAR"],
                                        [],
                                        {"MYVAR": "VALUE1"},
                                        {}, 
                                        [])
     test_connector.create_file("/tmp/sremote_test/request.data", request)
     server = ServerChannel()
     return_content=server.process_call_request(
                                 "/tmp/sremote_test/request.data",
                                  "/tmp/sremote_test/response.data")
     file_response = open("/tmp/sremote_test/response.data")
     response_content = file_response.read()
     
     self.assertEqual(return_content, response_content)
     
     status, reponse_obj = remote.decode_call_response(response_content)
     self.assertEqual(reponse_obj, "VALUE1")
コード例 #10
0
ファイル: api.py プロジェクト: gonzalorodrigo/sremote
    def do_remote_call(self, module_name, method_name, args=[], keep_env=False):
        """Uses _comms_client to send a request to execute
        module_name.method_name(*args) in the remote host. It asumes that
        module_name is installed in the sremote environemnt of the remote 
        host.

        Args:
            module_name: string with the name of the module which method will be
                executed.
            method_name: string with name of the method to be executed.
            args: list or dict containing the argument values. Dict is desired
                for calling methods with default values.
            keep_env: loads user enviroment before calling the method.
        
        Returns:
            If successes: response object and a string with the  std_out of
            the execution. Raises an exception otherwise.
        
        Rises Exceptions:
            ExceptionRemoteNotSetup: Remote end point does not have sremote or
                the version of remote-local sites don't match.
            ExceptionRemoteModulesError: Remote end-point does not have
                module_name or required_registered_modules or versions don't
                match.
            
        """
        if (not isinstance(args, types.ListType) and 
            not isinstance(args, types.DictType)):
            raise Exception("Wrong type for args, expected list or dict, found "
                            + str(type(args)))
        # Encodes and sends the call request to the remote host and calls the
        # interpreter to execute. Then the response is retrieved in a 
        # serialized format..
        request_obj= \
            remote.encode_call_request(module_name, method_name,
                                    args, required_extra_modules =
                                        self._registered_remote_modules,
                                    remote_env_variables=
                                        self._remote_env_variables,
                                    conditional_remote_env_variables=
                                        self._conditional_remote_env_variables,
                                    remote_path_addons=
                                        self._remote_path_addons)
        response_encoded, std_out, request_location, response_location = \
            self._comms_client.place_and_execute(
                                    request_obj,
                                    keep_env=keep_env)
        
        success, response = remote.decode_call_response(response_encoded)
        if (success):
            self._comms_client.delete_file(request_location)
            self._comms_client.delete_file(response_location)
            return response, std_out
        else:
            if response!=None:
                if (type(response) is dict):
                    if response.has_key("sremote_type"):
                        raise remote.ExceptionRemoteExecError(response[
                                                                "message"])
            
            raise remote.ExceptionRemoteNotSetup(
                "Error executing " +module_name+"."+ method_name + "\n  Output:"
                +str(std_out))
コード例 #11
0
ファイル: api.py プロジェクト: yabebalFantaye/sremote
    def do_remote_call(self,
                       module_name,
                       method_name,
                       args=[],
                       keep_env=False):
        """Uses _comms_client to send a request to execute
        module_name.method_name(*args) in the remote host. It asumes that
        module_name is installed in the sremote environemnt of the remote 
        host.

        Args:
            module_name: string with the name of the module which method will be
                executed.
            method_name: string with name of the method to be executed.
            args: list or dict containing the argument values. Dict is desired
                for calling methods with default values.
            keep_env: loads user enviroment before calling the method.
        
        Returns:
            If successes: response object and a string with the  std_out of
            the execution. Raises an exception otherwise.
        
        Rises Exceptions:
            ExceptionRemoteNotSetup: Remote end point does not have sremote or
                the version of remote-local sites don't match.
            ExceptionRemoteModulesError: Remote end-point does not have
                module_name or required_registered_modules or versions don't
                match.
            
        """
        if (not isinstance(args, types.ListType)
                and not isinstance(args, types.DictType)):
            raise Exception(
                "Wrong type for args, expected list or dict, found " +
                str(type(args)))
        # Encodes and sends the call request to the remote host and calls the
        # interpreter to execute. Then the response is retrieved in a
        # serialized format..
        request_obj= \
            remote.encode_call_request(module_name, method_name,
                                    args, required_extra_modules =
                                        self._registered_remote_modules,
                                    remote_env_variables=
                                        self._remote_env_variables,
                                    conditional_remote_env_variables=
                                        self._conditional_remote_env_variables,
                                    remote_path_addons=
                                        self._remote_path_addons)
        response_encoded, std_out, request_location, response_location = \
            self._comms_client.place_and_execute(
                                    request_obj,
                                    keep_env=keep_env)

        success, response = remote.decode_call_response(response_encoded)
        if (success):
            self._comms_client.delete_file(request_location)
            self._comms_client.delete_file(response_location)
            return response, std_out
        else:
            if response != None:
                if (type(response) is dict):
                    if response.has_key("sremote_type"):
                        raise remote.ExceptionRemoteExecError(
                            response["message"])

            raise remote.ExceptionRemoteNotSetup("Error executing " +
                                                 module_name + "." +
                                                 method_name + "\n  Output:" +
                                                 str(std_out))