Esempio n. 1
0
 def test_missing_four_one_two_one(self):
     """Test on a db with four total servers: one named,
     two unnamed, one not present (simulates midding log)"""
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Gryffindor", servers)
     assign_address(1, "1.1.1.1", servers)
     assign_address(2, "Ravenclaw", servers)
     assign_address(3, "Slytherin", servers)
     # fill in entries
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(generate_doc("status", "2", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(generate_doc("status", "2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc("status", "2", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(generate_doc("status", "3", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(generate_doc("status", "3", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(generate_doc("status", "3", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     # address_matchup will return -1
     assert address_matchup(db, "hp") == -1
     # but Slytherin and Ravenclaw should be named
     assert servers.find_one({"server_num": "2"})["server_IP"] == "2.2.2.2"
     assert servers.find_one({"server_name": "Ravenclaw"})["server_IP"] == "2.2.2.2"
     assert servers.find_one({"server_num": "3"})["server_IP"] == "3.3.3.3"
     assert servers.find_one({"server_name": "Slytherin"})["server_IP"] == "3.3.3.3"
     assert not servers.find_one({"server_IP": "4.4.4.4"})
Esempio n. 2
0
 def test_missing_four_two_one_one(self):
     """Test on db with four total servers: two named,
     one unnamed, one not present (simulates a missing log)"""
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Gryffindor", servers)
     assign_address(1, "1.1.1.1", servers)
     assign_address(2, "Ravenclaw", servers)
     assign_address(2, "2.2.2.2", servers)
     assign_address(3, "Slytherin", servers)
     # this case should be possible with the strong algorithm (aka a complete graph)
     # although we will be left with one unmatched name, "Hufflepuff" - "4.4.4.4"
     # fill in entries
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(generate_doc("status", "2", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(generate_doc("status", "2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc("status", "2", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(generate_doc("status", "3", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(generate_doc("status", "3", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(generate_doc("status", "3", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     # address_matchup will return -1
     assert address_matchup(db, "hp") == -1
     # but Slytherin should be named
     assert servers.find_one({"server_num": "3"})["server_IP"] == "3.3.3.3"
     assert servers.find_one({"server_name": "Slytherin"})["server_IP"] == "3.3.3.3"
     assert not servers.find_one({"server_IP": "4.4.4.4"})
Esempio n. 3
0
 def test_missing_three_total_one_present(self):
     """Test on a db with three total servers, one unnamed,
     two not present (missing logs)"""
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "unknown", servers)
     # fill in entries
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc("status", "1", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     # address_matchup will return -1
     assert address_matchup(db, "hp") == -1
Esempio n. 4
0
 def edge(self, x, y, entries):
     """Inserts a two-way edge between two given vertices
     (represents a connection between servers)"""
     # convert a letter into the int string
     letter_codes = {
             "A": 1,
             "B": 2,
             "C": 3,
             "D": 4,
             "E": 5,
             }
     ix = str(letter_codes[x])
     iy = str(letter_codes[y])
     entries.insert(generate_doc("status", ix, "ARBITER", 7, y, datetime.now()))
     entries.insert(generate_doc("status", iy, "ARBITER", 7, x, datetime.now()))
     return
Esempio n. 5
0
 def test_known_names_unknown_IPs(self):
     """Test on a db with three servers whose names
     are known, IPs are unknown"""
     servers, entries, clock_skew, db = self.db_setup()
     # add servers
     assign_address(1, "Grubblyplank", servers)
     assign_address(2, "Hagrid", servers)
     assign_address(3, "Trelawney", servers)
     # add entries
     entries.insert(generate_doc(
         "status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(generate_doc(
         "status", "1", "SECONDARY", 2, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc(
         "status", "2", "ARBITER", 7, "1.1.1.1", datetime.now()))
     entries.insert(generate_doc(
         "status", "2", "RECOVERING", 3, "3.3.3.3", datetime.now()))
     entries.insert(generate_doc(
         "status", "3", "DOWN", 8, "1.1.1.1", datetime.now()))
     entries.insert(generate_doc(
         "status", "3", "FATAL", 4, "2.2.2.2", datetime.now()))
     # check name matching
     assert address_matchup(db, "hp") == 1
     assert servers.find_one(
         {"server_num": "1"})["server_IP"] == "1.1.1.1"
     assert servers.find_one(
         {"server_name": "Grubblyplank"})["server_IP"] == "1.1.1.1"
     assert servers.find_one(
         {"server_num": "2"})["server_IP"] == "2.2.2.2"
     assert servers.find_one(
         {"server_name": "Hagrid"})["server_IP"] == "2.2.2.2"
     assert servers.find_one(
         {"server_num": "3"})["server_IP"] == "3.3.3.3"
     assert servers.find_one(
         {"server_name": "Trelawney"})["server_IP"] == "3.3.3.3"
Esempio n. 6
0
    def test_two_known_one_unknown(self):
        """Test on a db with two known servers and one
        unknown server (hostnames only)"""
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "Moony", servers)
        assign_address(2, "Padfoot", servers)
        assign_address(3, "unknown", servers)

        entries.insert(generate_doc(
            "status", "Moony", "PRIMARY", 1, "Prongs", datetime.now()))
        entries.insert(generate_doc(
            "status", "Padfoot", "PRIMARY", 1, "Prongs", datetime.now()))
        entries.insert(generate_doc(
            "status", "3", "PRIMARY", 1, "self", datetime.now()))
        entries.insert(generate_doc(
            "status", "Moony", "SECONDARY", 2, "Prongs", datetime.now()))
        entries.insert(generate_doc(
            "status", "Padfoot", "SECONDARY", 2, "Prongs", datetime.now()))
        entries.insert(generate_doc(
            "status", "3", "SECONDARY", 2, "self", datetime.now()))

        assert address_matchup(db, "hp") == 1
        assert servers.find_one({"server_num": "3"})["server_name"] == "Prongs"
        # check that entries were not changed
        assert entries.find({"origin_server": "3"}).count() == 2
Esempio n. 7
0
    def test_one_known_one_unknown_IPs(self):
        """Test on a db with two servers, one
        known and one unknown (IPs only)"""
        servers, entries, clock_skew, db = self.db_setup()
        assign_address("1", "1.1.1.1", servers)
        assign_address("2", "unknown", servers)
        # add a few entries
        entries.insert(generate_doc(
            "status", "1.1.1.1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
        entries.insert(generate_doc(
            "status", "1.1.1.1", "SECONDARY", 2, "2.2.2.2", datetime.now()))
        entries.insert(generate_doc(
            "status",  "1.1.1.1", "ARBITER", 2, "2.2.2.2", datetime.now()))
        date = datetime.now() + timedelta(seconds=3)
        entries.insert(generate_doc(
            "status", "2", "PRIMARY", 1, "self", date))
        entries.insert(generate_doc(
            "status", "2", "SECONDARY", 2, "self", date))
        entries.insert(generate_doc(
            "status", "2", "ARBITER", 7, "self", date))

        assert address_matchup(db, "hp") == 1
        assert servers.find_one({"server_num": "2"})["server_IP"] == "2.2.2.2"
        # check that entries were not changed
        assert entries.find({"origin_server": "2"}).count() == 3
Esempio n. 8
0
    def test_one_known_two_unknown_IPs(self):
        """Test on a db with one known server and
        two unknown servers (IPs only)"""
        servers, entries, clock_skew, db = self.db_setup()
        # add servers
        assign_address(1, "unknown", servers)
        assign_address(2, "1.2.3.4", servers)
        assign_address(3, "unknown", servers)
        # add entries about server 1, Ginny
        entries.insert(generate_doc(
            "status", "1", "UNKNOWN", 6, "self", datetime.now()))
        entries.insert(generate_doc(
            "status", "2", "UNKNOWN", 6, "5.6.7.8", datetime.now()))
        entries.insert(generate_doc(
            "status", "3", "UNKNOWN", 6, "5.6.7.8", datetime.now()))
        entries.insert(generate_doc(
            "status", "1", "ARBITER", 7, "self", datetime.now()))
        entries.insert(generate_doc(
            "status", "2", "ARBITER", 7, "5.6.7.8", datetime.now()))
        entries.insert(generate_doc(
            "status", "3", "ARBITER", 7, "5.6.7.8", datetime.now()))

        # add entries about server 3, Neville

        entries.insert(generate_doc(
            "status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
        entries.insert(generate_doc(
            "status", "2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
        entries.insert(generate_doc(
            "status", "3", "PRIMARY", 1, "self", datetime.now()))
        entries.insert(generate_doc(
            "status", "1", "FATAL", 4, "3.3.3.3", datetime.now()))
        entries.insert(generate_doc(
            "status", "2", "FATAL", 4, "3.3.3.3", datetime.now()))
        entries.insert(generate_doc(
            "status", "3", "FATAL", 4, "self", datetime.now()))

        # check name matching
        assert address_matchup(db, "hp") == 1
        assert servers.find_one({"server_num": "1"})["server_IP"] == "5.6.7.8"
        assert servers.find_one({"server_num": "3"})["server_IP"] == "3.3.3.3"
        # check that entries were not changed
        assert entries.find({"origin_server": "1"}).count() == 4
        assert entries.find({"origin_server": "3"}).count() == 4