Exemple #1
0
 def test_down_host(self):
     top = make_topology(2, True)
     state = State(top, None, {}, True, True)
     self.assertEqual(
         state.current_topology.get_down(),
         Topology((Host("a0", "1.2.3.0", "eu", "cluster1", 0, False),
                   Host("a1", "1.2.3.1", "eu", "cluster1", 100, False))))
Exemple #2
0
def make_topology(size, has_down_host=False):
    test_topology = []
    for i in range(size):
        test_topology.append(Host("a%d" % i, "1.2.3.%d" % i, "eu", "cluster1", i * 100, not has_down_host))
        test_topology.append(Host("b%d" % i, "2.2.3.%d" % i, "us", "cluster1", (i * 100) + 1, True))
        test_topology.append(Host("c%d" % i, "3.2.3.%d" % i, "eu", "cluster2", i * 100, True))
        test_topology.append(Host("d%d" % i, "4.2.3.%d" % i, "sto", "cluster2", (i * 100) + 1, True))
    return Topology(test_topology)
Exemple #3
0
def make_topology(size, has_down_host=False):
    test_topology = []
    for i in range(size):
        test_topology.append(Host("a%d" % i, "1.2.3.%d" % i, "eu", "cluster1", "rac{}".format(i % 3), not has_down_host, "hostId"))
        test_topology.append(Host("b%d" % i, "2.2.3.%d" % i, "us", "cluster1", "rac{}".format(i % 3), True, "hostId"))
        test_topology.append(Host("c%d" % i, "3.2.3.%d" % i, "eu", "cluster2", "rac{}".format(i % 3), True, "hostId"))
        test_topology.append(Host("d%d" % i, "4.2.3.%d" % i, "us", "cluster2", "rac{}".format(i % 3), True, "hostId"))
    return Topology(test_topology)
Exemple #4
0
 def test_dump_topology_to_json(self):
     topology_a_json = json.dumps(list(test_topology_a))
     topology_b_json = json.dumps(list(test_topology_b))
     topology_a_json_parsed = json.loads(topology_a_json)
     parsed_topology_a = Topology(
         Host(*arr) for arr in topology_a_json_parsed)
     topology_b_json_parsed = json.loads(topology_b_json)
     parsed_topology_b = Topology(
         Host(*arr) for arr in topology_b_json_parsed)
     self.assertEqual(parsed_topology_a.get_hash(),
                      parsed_topology_b.get_hash())
     self.assertEqual(parsed_topology_a.get_hash(),
                      test_topology_a.get_hash())
Exemple #5
0
def parse_nodetool_status(text,
                          cluster_name,
                          reverse_dns_preheat,
                          resolve_hostnames=False):
    topology = []
    datacenter_sections = text.split("Datacenter: ")[1:]
    datacenter_names_and_nodes = [
        _parse_datacenter_name_and_nodes(section)
        for section in datacenter_sections
    ]
    if resolve_hostnames:
        reverse_dns_preheat([
            node[1] for (_, nodes) in datacenter_names_and_nodes
            for node in nodes
        ])
    for (datacenter_name, nodes) in datacenter_names_and_nodes:
        for node in nodes:
            fqdn = node[1]
            if resolve_hostnames:
                try:
                    fqdn = socket.gethostbyaddr(node[1])[0]
                except socket.herror:
                    pass
            topology.append(
                Host(fqdn=fqdn,
                     ip=node[1],
                     dc=datacenter_name,
                     cluster=cluster_name,
                     is_up=(node[0] == "UN"),
                     rack=node[7],
                     host_id=node[6]))

    return Topology(topology)
Exemple #6
0
def parse_nodetool_ring(text, cluster_name, reverse_dns_preheat):
    topology = []
    datacenter_sections = text.split("Datacenter: ")[1:]
    datacenter_names_and_nodes = [
        _parse_datacenter_name_and_nodes(section)
        for section in datacenter_sections
    ]
    reverse_dns_preheat([
        node[0] for (_, nodes) in datacenter_names_and_nodes for node in nodes
    ])
    for (datacenterName, nodes) in datacenter_names_and_nodes:
        for node in nodes:
            fqdn = node[0]
            try:
                fqdn = socket.gethostbyaddr(node[0])[0]
            except socket.herror:
                pass
            topology.append(
                Host(fqdn=fqdn,
                     ip=node[0],
                     dc=datacenterName,
                     cluster=cluster_name,
                     is_up=(node[2] == "Up" and node[3] == "Normal"),
                     token=int(node[7])))

    return Topology(topology)
Exemple #7
0
 def test_without_hosts(self):
     sub = test_topology.without_hosts(
         (Host("a", IP1, "eu", "cluster1", "rac1", True, 'host1'),
          Host("b", IP2, "eu", "cluster1", "rac1", True, 'host2')))
     self.assertEqual(len(sub), 3)
Exemple #8
0
# See the License for the specific language governing permissions and
# limitations under the License.

from cstar.topology import Topology, Host
import json

import unittest

IP1 = "1.2.3.4"
IP2 = "2.3.4.5"
IP3 = "2.3.4.6"
IP4 = "2.3.4.7"
IP5 = "2.3.4.8"

test_topology = Topology(
    (Host("a", IP1, "eu", "cluster1", "rac1", True,
          'host1'), Host("b", IP2, "eu", "cluster1", "rac1", True, 'host2'),
     Host("c", IP3, "us", "cluster1", "rac1", True,
          'host3'), Host("d", IP4, "us", "cluster1", "rac1", True, 'host4'),
     Host("e", IP5, "us", "cluster2", "rac1", True, 'host5')))

test_topology_a = Topology(
    (Host("a", IP1, "eu", "cluster1", "rac1", True,
          'host1'), Host("b", IP2, "eu", "cluster1", "rac1", True, 'host2'),
     Host("c", IP3, "us", "cluster1", "rac1", True,
          'host3'), Host("d", IP4, "us", "cluster1", "rac1", True, 'host4')))

test_topology_b = Topology(
    (Host("a", IP1, "eu", "cluster1", "rac1", True,
          'host1'), Host("b", IP2, "eu", "cluster1", "rac1", True, 'host2'),
     Host("c", IP3, "us", "cluster1", "rac1", True,
          'host3'), Host("d", IP4, "us", "cluster1", "rac1", True, 'host4')))
Exemple #9
0
 def test_without_host(self):
     sub = test_topology.without_host(Host("a", IP1, "eu", "cluster1", 0, True))
     self.assertEqual(len(sub), 4)
Exemple #10
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from cstar.topology import Topology, Host

import unittest


IP1 = "1.2.3.4"
IP2 = "2.3.4.5"
IP3 = "2.3.4.6"
IP4 = "2.3.4.7"
IP5 = "2.3.4.8"

test_topology = Topology((Host("a", IP1, "eu", "cluster1", 0, True), Host("b", IP2, "eu", "cluster1", 10, True),
                          Host("c", IP3, "us", "cluster1", 1, True), Host("d", IP4, "us", "cluster1", 11, True),
                          Host("e", IP5, "us", "cluster2", 0, True)))


class TopologyTest(unittest.TestCase):

    def test_with_dc(self):
        sub = test_topology.with_dc("us")
        self.assertEqual(len(sub), 3)
        [self.assertEqual(host.dc, "us") for host in sub]

    def test_with_cluster(self):
        sub = test_topology.with_cluster("cluster1")
        self.assertEqual(len(sub), 4)
        [self.assertEqual(host.cluster, "cluster1") for host in sub]