示例#1
0
def verify_and_correct_endpoints_set(endpoints_set, downloaded_file):
    """
    There were some cases where the endpoint is in a wrong format, for example:
        10.182.62.251:870310.186.44.155:9020
    It is probably because the line contains 2 endpoints appended together.
    This method fixes the issue by checking the number of colons of each
    endpoint, and if there are more/less than 1 colon,
    calls zk_util.split_problematic_endpoints_line to fix and put correct
    one back to the endpoints_set.

    Args:
        ``endpoints_set``: the set which has a list of endpoints of serverset.
        ``downloaded_file``: the path of the file the serverset to be downloaded to.

    Returns:
        verified and corrected endpoints_set.
    """
    problematic_lines = []
    for endpoint in endpoints_set:
        if endpoint.count(":") != 1:
            # Log it
            log.error("Incorrect endpoint format: %s, file: %s", endpoint,
                      downloaded_file)
            problematic_lines.append(endpoint)
    if len(problematic_lines) == 0:
        return

    for problematic_line in problematic_lines:
        endpoints_set.remove(problematic_line)
        corrected_hosts = zk_util.split_problematic_endpoints_line(
            problematic_line)
        endpoints_set.update(corrected_hosts)
示例#2
0
def verify_and_correct_endpoints_set(endpoints_set, downloaded_file):
    """
    There were some cases where the endpoint is in a wrong format, for example:
        10.182.62.251:870310.186.44.155:9020
    It is probably because the line contains 2 endpoints appended together.
    This method fixes the issue by checking the number of colons of each
    endpoint, and if there are more/less than 1 colon,
    calls zk_util.split_problematic_endpoints_line to fix and put correct
    one back to the endpoints_set.

    Args:
        ``endpoints_set``: the set which has a list of endpoints of serverset.
        ``downloaded_file``: the path of the file the serverset to be downloaded to.

    Returns:
        verified and corrected endpoints_set.
    """
    problematic_lines = []
    for endpoint in endpoints_set:
        if endpoint.count(":") != 1:
            # Log it
            log.error("Incorrect endpoint format: %s, file: %s",
                      endpoint, downloaded_file)
            problematic_lines.append(endpoint)
    if len(problematic_lines) == 0:
        return

    for problematic_line in problematic_lines:
        endpoints_set.remove(problematic_line)
        corrected_hosts = zk_util.split_problematic_endpoints_line(
            problematic_line)
        endpoints_set.update(corrected_hosts)
示例#3
0
    def test_split_problematic_endpoints_line(self):
        line = "10.99.184.69:9001"
        splitted_parts = \
            zk_util.split_problematic_endpoints_line(line)
        self.assert_splitted_parts_equal(["10.99.184.69:9001"], splitted_parts)

        line = "10.99.184.69:900010.37.170.125:9006"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["10.99.184.69:9000", "10.37.170.125:9006"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "10.99.184.69:900010.37.170.125:900610.99.184.69:9008"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["10.99.184.69:9000", "10.37.170.125:9006", "10.99.184.69:9008"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = ""
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = []
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "10.182.62.251:870310.186.44.155:9020"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["10.182.62.251:8703", "10.186.44.155:9020"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "randomserver:9888randomserver2:9999"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["randomserver:9888", "randomserver2:9999"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "1.1.1.1:1234255.255.255.255:4321"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["1.1.1.1:1234", "255.255.255.255:4321"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)
    def test_split_problematic_endpoints_line(self):
        line = "10.99.184.69:9001"
        splitted_parts = \
            zk_util.split_problematic_endpoints_line(line)
        self.assert_splitted_parts_equal(["10.99.184.69:9001"], splitted_parts)

        line = "10.99.184.69:900010.37.170.125:9006"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["10.99.184.69:9000", "10.37.170.125:9006"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "10.99.184.69:900010.37.170.125:900610.99.184.69:9008"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = [
            "10.99.184.69:9000", "10.37.170.125:9006", "10.99.184.69:9008"
        ]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = ""
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = []
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "10.182.62.251:870310.186.44.155:9020"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["10.182.62.251:8703", "10.186.44.155:9020"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "randomserver:9888randomserver2:9999"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["randomserver:9888", "randomserver2:9999"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)

        line = "1.1.1.1:1234255.255.255.255:4321"
        splitted_parts = zk_util.split_problematic_endpoints_line(line)
        desired_answer = ["1.1.1.1:1234", "255.255.255.255:4321"]
        self.assert_splitted_parts_equal(desired_answer, splitted_parts)