コード例 #1
0
 def fixture_response_connected(self, response_code):
     handle = MockCurl({pycurl.RESPONSE_CODE: response_code})
     handle.request_obj = Request(RequestTarget(self.host),
                                  RequestData(self.request))
     handle.output_buffer = io.BytesIO()
     handle.output_buffer.write(self.data)
     return Response.connection_successful(handle)
コード例 #2
0
ファイル: mock_node_communicator.py プロジェクト: vvidic/pcs
def _communication_to_response(
    label,
    dest_list,
    action,
    param_list,
    response_code,
    output,
    debug_output,
    was_connected,
    errno,
    error_msg,
    raw_data,
):
    return Response(
        MockCurlSimple(
            info={pycurl.RESPONSE_CODE: response_code},
            output=output,
            debug_output=debug_output,
            request=Request(
                # We do not need to check if token is the right one in tests:
                # 1) Library commands tests do not care about tokens. That
                #    should be covered once in a specialized test, not in every
                #    single library command test.
                # 2) If we need to test teh case when a token is not accepted
                #    by pcsd, we will do so by setting an appropriate response.
                #    The actual token value doesn't matter.
                RequestTarget(label, dest_list=dest_list, token=None),
                RequestData(action, param_list, raw_data),
            ),
        ),
        was_connected=was_connected,
        errno=errno,
        error_msg=error_msg,
    )
コード例 #3
0
ファイル: config_http.py プロジェクト: miz-take/pcs
 def __communication_to_response(self, label, address_list, action,
                                 param_list, port, token, response_code,
                                 output, debug_output, was_connected, errno,
                                 error_msg):
     return Response(
         MockCurlSimple(info={pycurl.RESPONSE_CODE: response_code},
                        output=output.encode("utf-8"),
                        debug_output=debug_output.encode("utf-8"),
                        request=Request(
                            RequestTarget(label, address_list, port, token),
                            RequestData(action, param_list),
                        )),
         was_connected=was_connected,
         errno=6,
         error_msg=error_msg,
     )
コード例 #4
0
ファイル: test_sync.py プロジェクト: OndrejHome/pcs
 def setUp(self):
     self.mock_com = "communicator"
     self.mock_reporter = MockLibraryReportProcessor()
     self.node = RequestTarget("node")
     self.file_list = [{
         "name": "name1.conf",
         "data": "config1",
         "is_authfile": False
     }, {
         "name": "file1.key",
         "data": to_b64("some key"),
         "is_authfile": True
     }, {
         "name": "name2.conf",
         "data": "config2",
         "is_authfile": False
     }, {
         "name": "file2.key",
         "data": to_b64("another key"),
         "is_authfile": True
     }]
コード例 #5
0
ファイル: test_sbd.py プロジェクト: simhaonline/pcs
 def setUp(self):
     self.target_list = [
         RequestTarget("node{0}".format(i)) for i in range(1, 4)
     ]
コード例 #6
0
sys.path.insert(0, PACKAGE_DIR)

from pcs.common.host import Destination
from pcs.common.node_communicator import Request, RequestData, RequestTarget
from pcs import utils

logger_handler = logging.StreamHandler()
logger_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
logger = logging.getLogger("pcs")
logger.setLevel(logging.DEBUG)
logger.addHandler(logger_handler)

global_target = RequestTarget(
    "TestServer",
    dest_list=[
        Destination("httpbin.org2", 433),
        Destination("httpbin.org", 443),
    ]
)

pprint.pprint(global_target)

def get_request(timeout):
    return Request(global_target, RequestData("delay/{0}".format(timeout)))

lib_env = utils.get_lib_env()
# utils.pcs_options["--debug"] = True
request_list = [get_request((i + 1) * 2) for i in range(6)]
factory = lib_env.get_node_communicator_factory()
factory._request_timeout = 10
communicator = factory.get_multiring_communicator()
コード例 #7
0
def fixture_request():
    return Request(RequestTarget("host"), RequestData("action"))
コード例 #8
0
 def fixture_response_not_connected(self, errno, error_msg):
     handle = MockCurl()
     handle.request_obj = Request(RequestTarget(self.host),
                                  RequestData(self.request))
     return Response.connection_failure(handle, errno, error_msg)
コード例 #9
0
import pprint
import logging

PACKAGE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, PACKAGE_DIR)

from pcs.common.node_communicator import Request, RequestData, RequestTarget
from pcs import utils

logger_handler = logging.StreamHandler()
logger_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
logger = logging.getLogger("old_cli")
logger.setLevel(logging.DEBUG)
logger.addHandler(logger_handler)

global_target = RequestTarget("TestServer", ["httpbin.org2", "httpbin.org"],
                              port=443)

pprint.pprint(global_target)


def get_request(timeout):
    return Request(global_target, RequestData("delay/{0}".format(timeout)))


lib_env = utils.get_lib_env()
# utils.pcs_options["--debug"] = True
request_list = [get_request((i + 1) * 2) for i in range(6)]
factory = lib_env.get_node_communicator_factory()
factory._request_timeout = 10
communicator = factory.get_multiring_communicator()
# communicator.add_requests([get_request(10)])