Ejemplo n.º 1
0
    def test_one_known_one_unknown(self):
        """Test on a db with two servers, one
        known and one unknown (self_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "Parvati", True, servers)
        assign_address(2, "unknown", True, servers)
        # add a few entries

        entries.insert(self.generate_doc(
            "status", "Parvati", "PRIMARY", 1, "Padma", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "Parvati", "SECONDARY", 2, "Padma", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "Parvati", "ARBITER", 2, "Padma", datetime.now()))

        date = datetime.now() + timedelta(seconds=3)

        entries.insert(self.generate_doc(
            "status", "2", "PRIMARY", 1, "self", date))
        entries.insert(self.generate_doc(
            "status", "2", "SECONDARY", 2, "self", date))
        entries.insert(self.generate_doc(
            "status", "2", "ARBITER", 7, "self", date))

        assert address_matchup(db, "hp") == -1
Ejemplo n.º 2
0
 def test_two_different_skews(self):
     """Test the case where corresponding entries
     are skewed randomly in time
     """
     # only tests a-b, not b-a
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Hannah", False, servers)
     assign_address(2, "Mel", False, servers)
     # these are skewed by 3 seconds
     entries.insert(self.generate_doc(
         "status", "Hannah", "PRIMARY", 1, "Mel", datetime.now()))
     sleep(3)
     entries.insert(self.generate_doc(
         "status", "Mel", "PRIMARY", 1, "self", datetime.now()))
     # one other message to break the matching pattern
     sleep(2)
     entries.insert(self.generate_doc(
         "status", "Hannah", "ARBITER", 7, "Mel", datetime.now()))
     sleep(2)
     # these are skewed by 5 seconds
     entries.insert(self.generate_doc(
         "status", "Hannah", "SECONDARY", 2, "Mel", datetime.now()))
     sleep(5)
     entries.insert(self.generate_doc(
         "status", "Mel", "SECONDARY", 2, "self", datetime.now()))
     skews = detect("Hannah", "Mel", db, "wildcats")
     assert skews
     assert len(skews) == 2
     assert in_skews(5, skews)
     assert skews['5'] == 1
     assert in_skews(3, skews)
     assert skews['3'] == 1
Ejemplo n.º 3
0
    def test_one_known_one_unknown_networkss(self):
        """Test on a db with two servers, one
        known and one unknown (network_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address("1", "1.1.1.1", False, servers)
        assign_address("2", "unknown", False, servers)
        # add a few entries
        entries.insert(self.generate_doc(
            "status", "1.1.1.1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "1.1.1.1", "SECONDARY", 2, "2.2.2.2", datetime.now()))
        entries.insert(self.generate_doc(
            "status",  "1.1.1.1", "ARBITER", 2, "2.2.2.2", datetime.now()))
        date = datetime.now() + timedelta(seconds=3)
        entries.insert(self.generate_doc(
            "status", "2", "PRIMARY", 1, "self", date))
        entries.insert(self.generate_doc(
            "status", "2", "SECONDARY", 2, "self", date))
        entries.insert(self.generate_doc(
            "status", "2", "ARBITER", 7, "self", date))

        assert address_matchup(db, "hp") == 1
        assert servers.find_one({"server_num": "2"})["network_name"] == "2.2.2.2"
        # check that entries were not changed
        assert entries.find({"origin_server": "2"}).count() == 3
Ejemplo n.º 4
0
    def test_one_known_one_unknown(self):
        """Test on a db with two servers, one
        known and one unknown (self_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "Parvati", True, servers)
        assign_address(2, "unknown", True, servers)
        # add a few entries

        entries.insert(
            self.generate_doc("status", "Parvati", "PRIMARY", 1, "Padma",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "Parvati", "SECONDARY", 2, "Padma",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "Parvati", "ARBITER", 2, "Padma",
                              datetime.now()))

        date = datetime.now() + timedelta(seconds=3)

        entries.insert(
            self.generate_doc("status", "2", "PRIMARY", 1, "self", date))
        entries.insert(
            self.generate_doc("status", "2", "SECONDARY", 2, "self", date))
        entries.insert(
            self.generate_doc("status", "2", "ARBITER", 7, "self", date))

        assert address_matchup(db, "hp") == -1
Ejemplo n.º 5
0
    def test_one_known_one_unknown_networkss(self):
        """Test on a db with two servers, one
        known and one unknown (network_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address("1", "1.1.1.1", False, servers)
        assign_address("2", "unknown", False, servers)
        # add a few entries
        entries.insert(
            self.generate_doc("status", "1.1.1.1", "PRIMARY", 1, "2.2.2.2",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "1.1.1.1", "SECONDARY", 2, "2.2.2.2",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "1.1.1.1", "ARBITER", 2, "2.2.2.2",
                              datetime.now()))
        date = datetime.now() + timedelta(seconds=3)
        entries.insert(
            self.generate_doc("status", "2", "PRIMARY", 1, "self", date))
        entries.insert(
            self.generate_doc("status", "2", "SECONDARY", 2, "self", date))
        entries.insert(
            self.generate_doc("status", "2", "ARBITER", 7, "self", date))

        assert address_matchup(db, "hp") == 1
        assert servers.find_one({"server_num":
                                 "2"})["network_name"] == "2.2.2.2"
        # check that entries were not changed
        assert entries.find({"origin_server": "2"}).count() == 3
Ejemplo n.º 6
0
 def test_two_different_skews(self):
     """Test the case where corresponding entries
     are skewed randomly in time
     """
     # only tests a-b, not b-a
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Hannah", False, servers)
     assign_address(2, "Mel", False, servers)
     # these are skewed by 3 seconds
     entries.insert(self.generate_doc(
         "status", "Hannah", "PRIMARY", 1, "Mel", datetime.now()))
     sleep(3)
     entries.insert(self.generate_doc(
         "status", "Mel", "PRIMARY", 1, "self", datetime.now()))
     # one other message to break the matching pattern
     sleep(2)
     entries.insert(self.generate_doc(
         "status", "Hannah", "ARBITER", 7, "Mel", datetime.now()))
     sleep(2)
     # these are skewed by 5 seconds
     entries.insert(self.generate_doc(
         "status", "Hannah", "SECONDARY", 2, "Mel", datetime.now()))
     sleep(5)
     entries.insert(self.generate_doc(
         "status", "Mel", "SECONDARY", 2, "self", datetime.now()))
     skews = detect("Hannah", "Mel", db, "wildcats")
     assert skews
     assert len(skews) == 2
     assert in_skews(5, skews)
     assert skews['5'] == 1
     assert in_skews(3, skews)
     assert skews['3'] == 1
Ejemplo n.º 7
0
    def test_organize_two_servers(self):
        logger = logging.getLogger(__name__)
        servers, entries, clock_skew, db = self.db_setup()
        original_date = datetime.now()

        entries.insert(
            self.generate_doc("status", "apple", "STARTUP2", 5, "pear",
                              original_date))
        entries.insert(
            self.generate_doc("status", "pear", "STARTUP2"
                              "", 5, "apple",
                              original_date + timedelta(seconds=5)))

        assign_address(self, 1, "apple", servers)
        assign_address(self, 2, "pear", servers)

        organized_servers = organize_servers(db, "fruit")
        logger.debug(
            "Organized servers Printing: {}".format(organized_servers))
        for server_name in organized_servers:
            logger.debug("Server Name: {}".format(server_name))
            for item in organized_servers[server_name]:
                logger.debug("Item list: {}".format(item))
                logger.debug("Item: {}".format(item))
                assert item
Ejemplo n.º 8
0
 def insert_unknown(self, n, servers):
     """Inserts n unknown servers into .servers collection.
     Assumes, for these tests, that self_names are unknown
     and must be matched, while network_names are known
     """
     for i in range(1, n):
         ip = str(i) + "." + str(i) + "." + str(i) + "." + str(i)
         assign_address(i, ip, False, servers)
Ejemplo n.º 9
0
 def insert_unknown(self, n, servers):
     """Inserts n unknown servers into .servers collection.
     Assumes, for these tests, that self_names are unknown
     and must be matched, while network_names are known
     """
     for i in range(1, n):
         ip = str(i) + "." + str(i) + "." + str(i) + "." + str(i)
         assign_address(i, ip, False, servers)
Ejemplo n.º 10
0
 def test_clock_skew_two(self):
     """Two different servers"""
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Sam", False, servers)
     assign_address(2, "Nuni", False, servers)
     # fill in some entries
     entries.insert(
         self.generate_doc("status", "Sam", "SECONDARY", 2, "Nuni",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "DOWN", 8, "Nuni",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "STARTUP2", 5, "Nuni",
                           datetime.now()))
     sleep(3)
     entries.insert(
         self.generate_doc("status", "Nuni", "SECONDARY", 2, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Nuni", "DOWN", 8, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Nuni", "STARTUP2", 5, "self",
                           datetime.now()))
     server_clock_skew(db, "wildcats")
     cursor = clock_skew.find()
     assert cursor.count() == 2
     # check first server entry
     doc = clock_skew.find_one({"server_num": "1"})
     assert doc
     assert doc["type"] == "clock_skew"
     assert doc["partners"]
     assert doc["partners"]["2"]
     assert len(doc["partners"]["2"]) == 1
     assert not "1" in doc["partners"]
     t1, wt1 = doc["partners"]["2"].popitem()
     t1 = int(t1)
     assert abs(abs(t1) - 3) < .01
     assert t1 > 0
     assert wt1 == 6
     # check second server entry
     doc2 = clock_skew.find_one({"server_num": "2"})
     assert doc2
     assert doc2["type"] == "clock_skew"
     assert doc2["partners"]
     assert doc2["partners"]["1"]
     assert len(doc2["partners"]["1"]) == 1
     assert not "2" in doc2["partners"]
     t2, wt2 = doc2["partners"]["1"].popitem()
     t2 = int(t2)
     assert abs(abs(t2) - 3) < .01
     assert t2 < 0
     assert wt2 == 6
     # compare entries against each other
     assert abs(t1) == abs(t2)
     assert t1 == -t2
Ejemplo n.º 11
0
 def test_detect_simple(self):
     """A simple test of the detect() method in post.py"""
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Erica", False, servers)
     assign_address(2, "Alison", False, servers)
     # fill in some entries
     entries.insert(self.generate_doc(
         "status", "Erica", "STARTUP2", 5, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "DOWN", 8, "self", datetime.now()))
     # wait for a bit (skew the clocks)
     sleep(3)
     # fill in more entries
     entries.insert(self.generate_doc(
         "status", "Alison", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "Erica", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "Erica", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "DOWN", 8, "Erica", datetime.now()))
     # check a - b
     skews1 = detect("Erica", "Alison", db, "wildcats")
     assert skews1
     assert len(skews1) == 1
     t1, wt1 = skews1.popitem()
     t1 = int(t1)
     assert t1
     assert -.01 < (abs(t1) - 3) < .01
     assert t1 > 0
     # check b - a
     skews2 = detect("Alison", "Erica", db, "wildcats")
     assert skews2
     assert len(skews2) == 1
     t2, wt2 = skews2.popitem()
     t2 = int(t2)
     assert t2
     assert t2 < 0
     assert abs(abs(t2) - 3) < .01
     # compare runs against each other
     assert abs(t1) == abs(t2)
     assert t1 == -t2
     assert wt1 == wt2
     assert wt1 == 6
Ejemplo n.º 12
0
 def test_detect_simple(self):
     """A simple test of the detect() method in post.py"""
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Erica", False, servers)
     assign_address(2, "Alison", False, servers)
     # fill in some entries
     entries.insert(self.generate_doc(
         "status", "Erica", "STARTUP2", 5, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "DOWN", 8, "self", datetime.now()))
     # wait for a bit (skew the clocks)
     sleep(3)
     # fill in more entries
     entries.insert(self.generate_doc(
         "status", "Alison", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "Erica", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "Erica", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "DOWN", 8, "Erica", datetime.now()))
     # check a - b
     skews1 = detect("Erica", "Alison", db, "wildcats")
     assert skews1
     assert len(skews1) == 1
     t1, wt1 = skews1.popitem()
     t1 = int(t1)
     assert t1
     assert -.01 < (abs(t1) - 3) < .01
     assert t1 > 0
     # check b - a
     skews2 = detect("Alison", "Erica", db, "wildcats")
     assert skews2
     assert len(skews2) == 1
     t2, wt2 = skews2.popitem()
     t2 = int(t2)
     assert t2
     assert t2 < 0
     assert abs(abs(t2) - 3) < .01
     # compare runs against each other
     assert abs(t1) == abs(t2)
     assert t1 == -t2
     assert wt1 == wt2
     assert wt1 == 6
Ejemplo n.º 13
0
 def test_target_server_match_IP_no_match(self):
     """Test method on entries where one cites 'self',
     other cites incorrect network_name"""
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("self", "4.4.4.4")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 14
0
 def test_target_server_match_IP_no_match(self):
     """Test method on entries where one cites 'self',
     other cites incorrect network_name"""
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("self", "4.4.4.4")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 15
0
 def test_target_server_match_self_name_no_match(self):
     """Test method on entries where one cites 'self',
     other cites incorrect network_name
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("self", "*****@*****.**")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", False, servers)
     assign_address(2, "*****@*****.**", False, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 16
0
 def test_target_server_match_self_name(self):
     """Test method on entries where one cites 'self',
     other cites self_name
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("*****@*****.**", "self")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", True, servers)
     assign_address(2, "*****@*****.**", True, servers)
     assert target_server_match(a, b, servers)
Ejemplo n.º 17
0
 def test_target_server_match_both_different_network_names(self):
     """Test method on two entries with different
     info.server fields, both network addresses
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("1.2.3.4", "5.6.7.8")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 18
0
 def test_target_server_match_self_name(self):
     """Test method on entries where one cites 'self',
     other cites self_name
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("*****@*****.**", "self")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", True, servers)
     assign_address(2, "*****@*****.**", True, servers)
     assert target_server_match(a, b, servers)
Ejemplo n.º 19
0
 def test_target_server_match_both_different_network_names(self):
     """Test method on two entries with different
     info.server fields, both network addresses
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("1.2.3.4", "5.6.7.8")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 20
0
 def test_target_server_match_self_name_no_match(self):
     """Test method on entries where one cites 'self',
     other cites incorrect network_name
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("self", "*****@*****.**")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", False, servers)
     assign_address(2, "*****@*****.**", False, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 21
0
 def test_target_server_match_both_different_self_names(self):
     """Test method on two entries with different
     info.server fields, both self_names
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("*****@*****.**", "*****@*****.**")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", True, servers)
     assign_address(2, "*****@*****.**", True, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 22
0
 def test_detect_a_has_more(self):
     """Test the scenario where server a has more
     entries about b than b has about itself
     """
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Erica", False, servers)
     assign_address(2, "Alison", False, servers)
     # fill in some entries
     entries.insert(
         self.generate_doc("status", "Erica", "STARTUP2", 5, "Alison",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "SECONDARY", 2, "Alison",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "PRIMARY", 1, "Alison",
                           datetime.now()))
     # wait for a bit (skew the clocks)
     sleep(3)
     # fill in more entries
     entries.insert(
         self.generate_doc("status", "Alison", "SECONDARY", 2, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "PRIMARY", 1, "self",
                           datetime.now()))
     # first pair doesn't match
     skews1 = detect("Erica", "Alison", db, "wildcats")
     assert skews1
     assert len(skews1) == 1
     t1, wt1 = skews1.popitem()
     t1 = int(t1)
     assert t1
     assert wt1
     assert wt1 == 3
     assert abs(abs(t1) - 3) < .01
     # replace some entries
     entries.remove({"origin_server": "Alison"})
     entries.insert(
         self.generate_doc("status", "Alison", "STARTUP2", 5, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "STARTUP2", 5, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "SECONDARY", 2, "self",
                           datetime.now()))
     # second pair doesn't match
     skews2 = detect("Erica", "Alison", db, "wildcats")
     assert skews2
     assert len(skews2) == 1
     assert in_skews(3, skews2)
     assert skews2['3'] == 4
Ejemplo n.º 23
0
 def test_target_server_match_both_different_self_names(self):
     """Test method on two entries with different
     info.server fields, both self_names
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("*****@*****.**", "*****@*****.**")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", True, servers)
     assign_address(2, "*****@*****.**", True, servers)
     assert not target_server_match(a, b, servers)
Ejemplo n.º 24
0
 def test_target_server_match_unknown_self_name(self):
     """Test method on entries where one cites 'self',
     other cites first server's true self_name, but
     self_name is not yet recorded in the .servers collection
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("*****@*****.**", "self")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", True, servers)
     assign_address(2, "unknown", True, servers)
     assert target_server_match(a, b, servers)
Ejemplo n.º 25
0
 def db_setup_n_servers(self, n):
     """Set up necessary server connection, and
     add n servers to the .servers collection.  Set
     the server_num to an int i < n, set the IP
     field to i.i.i.i, and the self_name to [email protected]"""
     servers, entries, db = self.db_setup()
     for i in range(1,n + 1):
         ip = str(i) + "." + str(i) + "." + str(i) + "." + str(i)
         self_name = str(i) + "@10gen.com"
         assign_address(i, ip, False, servers)
         assign_address(i, self_name, True, servers)
     return [servers, entries, db]
Ejemplo n.º 26
0
 def test_target_server_match_unknown_network_name(self):
     """Test method on entries where one cites 'self',
     other cites first server's true IP, but IP is not yet
     recorded in the .servers collection
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("self", "1.1.1.1")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "unknown", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assert target_server_match(a, b, servers)
Ejemplo n.º 27
0
 def test_target_server_match_unknown_self_name(self):
     """Test method on entries where one cites 'self',
     other cites first server's true self_name, but
     self_name is not yet recorded in the .servers collection
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("*****@*****.**", "self")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "*****@*****.**", True, servers)
     assign_address(2, "unknown", True, servers)
     assert target_server_match(a, b, servers)
Ejemplo n.º 28
0
 def db_setup_n_servers(self, n):
     """Set up necessary server connection, and
     add n servers to the .servers collection.  Set
     the server_num to an int i < n, set the IP
     field to i.i.i.i, and the self_name to [email protected]"""
     servers, entries, db = self.db_setup()
     for i in range(1, n + 1):
         ip = str(i) + "." + str(i) + "." + str(i) + "." + str(i)
         self_name = str(i) + "@10gen.com"
         assign_address(i, ip, False, servers)
         assign_address(i, self_name, True, servers)
     return [servers, entries, db]
Ejemplo n.º 29
0
 def test_target_server_match_unknown_network_name(self):
     """Test method on entries where one cites 'self',
     other cites first server's true IP, but IP is not yet
     recorded in the .servers collection
     """
     servers, entries, db = self.db_setup()
     a, b = self.generate_entries("self", "1.1.1.1")
     a["origin_server"] = "1"
     b["origin_server"] = "2"
     assign_address(1, "unknown", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assert target_server_match(a, b, servers)
Ejemplo n.º 30
0
 def test_detect_network_delay(self):
     """Test the case where there are time differences
     too small to be considered clock skew
     """
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Erica", False, servers)
     assign_address(2, "Alison", False, servers)
     # fill in some entries
     entries.insert(
         self.generate_doc("status", "Erica", "STARTUP2", 5, "Alison",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "SECONDARY", 2, "Alison",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "PRIMARY", 1, "Alison",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "PRIMARY", 1, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "SECONDARY", 2, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Erica", "DOWN", 8, "self",
                           datetime.now()))
     # wait for a bit (skew the clocks)
     sleep(1)
     # fill in more entries
     entries.insert(
         self.generate_doc("status", "Alison", "STARTUP2", 5, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "SECONDARY", 2, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "PRIMARY", 1, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "PRIMARY", 1, "Erica",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "SECONDARY", 2, "Erica",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Alison", "DOWN", 8, "Erica",
                           datetime.now()))
     # run detect()!
     skews1 = detect("Erica", "Alison", db, "wildcats")
     skews2 = detect("Alison", "Erica", db, "wildcats")
     assert not skews1
     assert not skews2
Ejemplo n.º 31
0
 def test_clock_skew_two(self):
     """Two different servers"""
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Sam", False, servers)
     assign_address(2, "Nuni", False, servers)
     # fill in some entries
     entries.insert(self.generate_doc(
             "status", "Sam", "SECONDARY", 2, "Nuni", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "Sam", "DOWN", 8, "Nuni", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "Sam", "STARTUP2", 5, "Nuni", datetime.now()))
     sleep(3)
     entries.insert(self.generate_doc(
             "status", "Nuni", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "Nuni", "DOWN", 8, "self", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "Nuni", "STARTUP2", 5, "self", datetime.now()))
     server_clock_skew(db, "wildcats")
     cursor = clock_skew.find()
     assert cursor.count() == 2
     # check first server entry
     doc = clock_skew.find_one({"server_num" : "1"})
     assert doc
     assert doc["type"] == "clock_skew"
     assert doc["partners"]
     assert doc["partners"]["2"]
     assert len(doc["partners"]["2"]) == 1
     assert not "1" in doc["partners"]
     t1, wt1 = doc["partners"]["2"].popitem()
     t1 = int(t1)
     assert abs(abs(t1) - 3) < .01
     assert t1 > 0
     assert wt1 == 6
     # check second server entry
     doc2 = clock_skew.find_one({"server_num" : "2"})
     assert doc2
     assert doc2["type"] == "clock_skew"
     assert doc2["partners"]
     assert doc2["partners"]["1"]
     assert len(doc2["partners"]["1"]) == 1
     assert not "2" in doc2["partners"]
     t2, wt2 = doc2["partners"]["1"].popitem()
     t2 = int(t2)
     assert abs(abs(t2) - 3) < .01
     assert t2 < 0
     assert wt2 == 6
     # compare entries against each other
     assert abs(t1) == abs(t2)
     assert t1 == -t2
Ejemplo n.º 32
0
 def test_clock_skew_one(self):
     """DB with entries from one server"""
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Sam", False, servers)
     entries.insert(self.generate_doc(
             "status", "Sam", "STARTUP2", 5, "Gaya", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "Sam", "PRIMARY", 1, "self", datetime.now()))
     server_clock_skew(db, "wildcats")
     doc = db["wildcats.clock_skew"].find_one()
     assert doc
     assert doc["server_num"] == "1"
     assert not doc["partners"]
Ejemplo n.º 33
0
 def test_clock_skew_one(self):
     """DB with entries from one server"""
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Sam", False, servers)
     entries.insert(self.generate_doc(
             "status", "Sam", "STARTUP2", 5, "Gaya", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "Sam", "PRIMARY", 1, "self", datetime.now()))
     server_clock_skew(db, "wildcats")
     doc = db["wildcats.clock_skew"].find_one()
     assert doc
     assert doc["server_num"] == "1"
     assert not doc["partners"]
Ejemplo n.º 34
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", False, servers)
     # fill in entries
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     # address_matchup will return -1
     assert address_matchup(db, "hp") == -1
Ejemplo n.º 35
0
 def test_detect_zero_skew(self):
     """Test the case where there is no clock skew."""
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Sam", False, servers)
     assign_address(2, "Gaya", False, servers)
     # fill in some entries (a - b)
     entries.insert(
         self.generate_doc("status", "Sam", "STARTUP2", 5, "Gaya",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Gaya", "STARTUP2", 5, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "ARBITER", 7, "Gaya",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Gaya", "ARBITER", 7, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "DOWN", 8, "Gaya",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Gaya", "DOWN", 8, "self",
                           datetime.now()))
     # fill in some entries (b - a)
     entries.insert(
         self.generate_doc("status", "Gaya", "STARTUP2", 5, "Sam",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "STARTUP2", 5, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Gaya", "STARTUP2", 5, "Sam",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "STARTUP2", 5, "self",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Gaya", "STARTUP2", 5, "Sam",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "Sam", "STARTUP2", 5, "self",
                           datetime.now()))
     skews1 = detect("Sam", "Gaya", db, "wildcats")
     skews2 = detect("Gaya", "Sam", db, "wildcats")
     assert not skews1
     assert not skews2
Ejemplo n.º 36
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", True, servers)
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "Ravenclaw", True, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assign_address(3, "Slytherin", True, 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(
         self.generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "4.4.4.4",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "PRIMARY", 1, "1.1.1.1",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "PRIMARY", 1, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "PRIMARY", 1, "4.4.4.4",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "3", "PRIMARY", 1, "1.1.1.1",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "3", "PRIMARY", 1, "2.2.2.2",
                           datetime.now()))
     entries.insert(
         self.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"})["network_name"] == "3.3.3.3"
     assert servers.find_one({"self_name":
                              "Slytherin"})["network_name"] == "3.3.3.3"
     assert not servers.find_one({"network_name": "4.4.4.4"})
Ejemplo n.º 37
0
 def test_detect_a_has_more(self):
     """Test the scenario where server a has more
     entries about b than b has about itself
     """
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Erica", False, servers)
     assign_address(2, "Alison", False, servers)
     # fill in some entries
     entries.insert(self.generate_doc(
         "status", "Erica", "STARTUP2", 5, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "Alison", datetime.now()))
     # wait for a bit (skew the clocks)
     sleep(3)
     # fill in more entries
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "self", datetime.now()))
     # first pair doesn't match
     skews1 = detect("Erica", "Alison", db, "wildcats")
     assert skews1
     assert len(skews1) == 1
     t1, wt1 = skews1.popitem()
     t1 = int(t1)
     assert t1
     assert wt1
     assert wt1 == 3
     assert abs(abs(t1) - 3) < .01
     # replace some entries
     entries.remove(
         {"origin_server": "Alison"})
     entries.insert(self.generate_doc(
         "status", "Alison", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "self", datetime.now()))
     # second pair doesn't match
     skews2 = detect("Erica", "Alison", db, "wildcats")
     assert skews2
     assert len(skews2) == 1
     assert in_skews(3, skews2)
     assert skews2['3'] == 4
Ejemplo n.º 38
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", False, servers)
     # fill in entries
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "4.4.4.4",
                           datetime.now()))
     # address_matchup will return -1
     assert address_matchup(db, "hp") == -1
Ejemplo n.º 39
0
 def test_detect_network_delay(self):
     """Test the case where there are time differences
     too small to be considered clock skew
     """
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Erica", False, servers)
     assign_address(2, "Alison", False, servers)
     # fill in some entries
     entries.insert(self.generate_doc(
         "status", "Erica", "STARTUP2", 5, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "Alison", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "PRIMARY", 1, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Erica", "DOWN", 8, "self", datetime.now()))
     # wait for a bit (skew the clocks)
     sleep(1)
     # fill in more entries
     entries.insert(self.generate_doc(
         "status", "Alison", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "PRIMARY", 1, "Erica", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "SECONDARY", 2, "Erica", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Alison", "DOWN", 8, "Erica", datetime.now()))
     # run detect()!
     skews1 = detect("Erica", "Alison", db, "wildcats")
     skews2 = detect("Alison", "Erica", db, "wildcats")
     assert not skews1
     assert not skews2
Ejemplo n.º 40
0
    def test_organize_two_servers(self):
        logger = logging.getLogger(__name__)
        servers, entries, clock_skew, db = self.db_setup()
        original_date = datetime.now()

        entries.insert(self.generate_doc(
            "status", "apple", "STARTUP2", 5, "pear", original_date))
        entries.insert(self.generate_doc("status", "pear", "STARTUP2"
            "", 5, "apple", original_date + timedelta(seconds=5)))

        assign_address(self, 1, "apple", servers)
        assign_address(self, 2, "pear", servers)

        organized_servers = organize_servers(db, "fruit")
        logger.debug("Organized servers Printing: {}".format(organized_servers))
        for server_name in organized_servers:
            logger.debug("Server Name: {}".format(server_name))
            for item in organized_servers[server_name]:
                logger.debug("Item list: {}".format(item))
                logger.debug("Item: {}".format(item))
                assert item
Ejemplo n.º 41
0
    def test_two_known_one_unknown(self):
        """Test on a db with two known servers and one
        unknown server (self_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "Moony", True, servers)
        assign_address(2, "Padfoot", True, servers)
        assign_address(3, "unknown", True, servers)

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

        assert address_matchup(db, "hp") == -1
Ejemplo n.º 42
0
    def test_two_known_one_unknown_networkss(self):
        """Test on a db with two known servers and one
        unknown server (network_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "1.1.1.1", False, servers)
        assign_address(2, "2.2.2.2", False, servers)
        assign_address(3, "unknown", False, servers)
        entries.insert(
            self.generate_doc("status", "1.1.1.1", "PRIMARY", 1, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "2.2.2.2", "PRIMARY", 1, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "3", "PRIMARY", 1, "self",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "1.1.1.1", "SECONDARY", 2, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "2.2.2.2", "SECONDARY", 2, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "3", "SECONDARY", 2, "self",
                              datetime.now()))

        assert address_matchup(db, "hp") == 1
        assert servers.find_one({"server_num":
                                 "3"})["network_name"] == "3.3.3.3"
        # check that entries were not changed
        assert entries.find({"origin_server": "3"}).count() == 2
Ejemplo n.º 43
0
 def test_missing_four_one_two_one(self):
     """Test on a db with four total servers: one named,
     one unnamed, two not present (simulates missing logs)
     """
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Gryffindor", True, servers)
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "Ravenclaw", True, servers)
     # fill in entries
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     # address_matchup will return -1
     assert address_matchup(db, "hp") == -1
     # but Ravenclaw should be named
     assert servers.find_one({"server_num": "2"})["network_name"] == "2.2.2.2"
     assert servers.find_one({"self_name": "Ravenclaw"})["network_name"] == "2.2.2.2"
     assert not servers.find_one({"network_name": "3.3.3.3"})
     assert not servers.find_one({"network_name": "4.4.4.4"})
Ejemplo n.º 44
0
 def test_known_networks_unknown_names(self):
     """Test on db with three servers whose network_names
     are known, self_names are unknown
     """
     servers, entries, clock_skew, db = self.db_setup()
     # add servers
     assign_address(1, "1.1.1.1", True, servers)
     assign_address(2, "2.2.2.2", True, servers)
     assign_address(3, "3.3.3.3", True, servers)
     # add entries
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "Crabbe", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "SECONDARY", 2, "Goyle", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "ARBITER", 7, "Malfoy", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "RECOVERING", 3, "Goyle", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "3", "DOWN", 8, "Malfoy", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "3", "FATAL", 4, "Crabbe", datetime.now()))
     # check name matching
     assert address_matchup(db, "hp") == 1
     assert servers.find_one({"server_num": "1"})["network_name"] == "Malfoy"
     assert servers.find_one({"self_name": "1.1.1.1"})["network_name"] == "Malfoy"
     assert servers.find_one({"server_num": "2"})["network_name"] == "Crabbe"
     assert servers.find_one({"self_name": "2.2.2.2"})["network_name"] == "Crabbe"
     assert servers.find_one({"server_num": "3"})["network_name"] == "Goyle"
     assert servers.find_one({"self_name": "3.3.3.3"})["network_name"] == "Goyle"
Ejemplo n.º 45
0
    def test_two_known_one_unknown_networkss(self):
        """Test on a db with two known servers and one
        unknown server (network_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "1.1.1.1", False, servers)
        assign_address(2, "2.2.2.2", False, servers)
        assign_address(3, "unknown", False, servers)
        entries.insert(self.generate_doc(
            "status", "1.1.1.1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "2.2.2.2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "3", "PRIMARY", 1, "self", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "1.1.1.1", "SECONDARY", 2, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "2.2.2.2", "SECONDARY", 2, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
             "status", "3", "SECONDARY", 2, "self", datetime.now()))

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

        # add entries about server 3, Neville

        entries.insert(
            self.generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "2", "PRIMARY", 1, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "3", "PRIMARY", 1, "self",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "1", "FATAL", 4, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "2", "FATAL", 4, "3.3.3.3",
                              datetime.now()))
        entries.insert(
            self.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"})["network_name"] == "5.6.7.8"
        assert servers.find_one({"server_num":
                                 "3"})["network_name"] == "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
Ejemplo n.º 47
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", True, servers)
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "Ravenclaw", True, servers)
     assign_address(3, "Slytherin", True, servers)
     # fill in entries
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "4.4.4.4",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "PRIMARY", 1, "1.1.1.1",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "PRIMARY", 1, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "PRIMARY", 1, "4.4.4.4",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "3", "PRIMARY", 1, "1.1.1.1",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "3", "PRIMARY", 1, "2.2.2.2",
                           datetime.now()))
     entries.insert(
         self.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"})["network_name"] == "2.2.2.2"
     assert servers.find_one({"self_name":
                              "Ravenclaw"})["network_name"] == "2.2.2.2"
     assert servers.find_one({"server_num":
                              "3"})["network_name"] == "3.3.3.3"
     assert servers.find_one({"self_name":
                              "Slytherin"})["network_name"] == "3.3.3.3"
     assert not servers.find_one({"network_name": "4.4.4.4"})
Ejemplo n.º 48
0
 def test_all_known_networkss(self):
     """Test on db where all servers' names
     are already known (network_names only)
     """
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assign_address(3, "3.3.3.3", False, servers)
     assert address_matchup(db, "hp") == 1
Ejemplo n.º 49
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", True, servers)
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "Ravenclaw", True, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assign_address(3, "Slytherin", True, 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(self.generate_doc(
             "status", "1", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "1", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "2", "PRIMARY", 1, "4.4.4.4", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "3", "PRIMARY", 1, "1.1.1.1", datetime.now()))
     entries.insert(self.generate_doc(
             "status", "3", "PRIMARY", 1, "2.2.2.2", datetime.now()))
     entries.insert(self.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"})["network_name"] == "3.3.3.3"
     assert servers.find_one({"self_name": "Slytherin"})["network_name"] == "3.3.3.3"
     assert not servers.find_one({"network_name": "4.4.4.4"})
Ejemplo n.º 50
0
 def test_all_known(self):
     """Test on db where all servers' names
     are already known (self_names only)
     """
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Harry", True, servers)
     assign_address(2, "Hermione", True, servers)
     assign_address(3, "Ron", True, servers)
     assert address_matchup(db, "hp") == -1
Ejemplo n.º 51
0
 def test_all_known_networkss(self):
     """Test on db where all servers' names
     are already known (network_names only)
     """
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "1.1.1.1", False, servers)
     assign_address(2, "2.2.2.2", False, servers)
     assign_address(3, "3.3.3.3", False, servers)
     assert address_matchup(db, "hp") == 1
Ejemplo n.º 52
0
 def test_all_known(self):
     """Test on db where all servers' names
     are already known (self_names only)
     """
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "Harry", True, servers)
     assign_address(2, "Hermione", True, servers)
     assign_address(3, "Ron", True, servers)
     assert address_matchup(db, "hp") == -1
Ejemplo n.º 53
0
 def test_detect_zero_skew(self):
     """Test the case where there is no clock skew."""
     servers, entries, clock_skew, db = self.db_setup()
     # fill in some servers
     assign_address(1, "Sam", False, servers)
     assign_address(2, "Gaya", False, servers)
     # fill in some entries (a - b)
     entries.insert(self.generate_doc(
         "status", "Sam", "STARTUP2", 5, "Gaya", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Gaya", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Sam", "ARBITER", 7, "Gaya", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Gaya", "ARBITER", 7, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Sam", "DOWN", 8, "Gaya", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Gaya", "DOWN", 8, "self", datetime.now()))
     # fill in some entries (b - a)
     entries.insert(self.generate_doc(
         "status", "Gaya", "STARTUP2", 5, "Sam", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Sam", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Gaya", "STARTUP2", 5, "Sam", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Sam", "STARTUP2", 5, "self", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Gaya", "STARTUP2", 5, "Sam", datetime.now()))
     entries.insert(self.generate_doc(
         "status", "Sam", "STARTUP2", 5, "self", datetime.now()))
     skews1 = detect("Sam", "Gaya", db, "wildcats")
     skews2 = detect("Gaya", "Sam", db, "wildcats")
     assert not skews1
     assert not skews2
Ejemplo n.º 54
0
 def test_all_servers_unknown(self):
     """Test on db where all servers are unknown
     (neither self or network name)
     """
     # this case could be handled, in the future
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "unknown", True, servers)
     assign_address(2, "unknown", False, servers)
     assign_address(3, "unknown", True, servers)
     assert address_matchup(db, "hp") == -1
Ejemplo n.º 55
0
 def test_all_servers_unknown(self):
     """Test on db where all servers are unknown
     (neither self or network name)
     """
     # this case could be handled, in the future
     servers, entries, clock_skew, db = self.db_setup()
     assign_address(1, "unknown", True, servers)
     assign_address(2, "unknown", False, servers)
     assign_address(3, "unknown", True, servers)
     assert address_matchup(db, "hp") == -1
Ejemplo n.º 56
0
    def test_one_known_two_unknown(self):
        """Test on a db with one known server and
        two unknown servers (self_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        # add servers
        assign_address(1, "unknown", True, servers)
        assign_address(2, "Luna", True, servers)
        assign_address(3, "unknown", True, servers)
        # add entries about server 1, Ginny
        entries.insert(
            self.generate_doc("status", "1", "UNKNOWN", 6, "self",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "Luna", "UNKNOWN", 6, "Ginny",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "3", "UNKNOWN", 6, "Ginny",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "1", "ARBITER", 7, "self",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "Luna", "ARBITER", 7, "Ginny",
                              datetime.now()))
        entries.insert(
            self.generate_doc("status", "3", "ARBITER", 7, "Ginny",
                              datetime.now()))

        # add entries about server 3, Neville

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

        # check name matching
        assert address_matchup(db, "hp") == -1
Ejemplo n.º 57
0
    def test_one_known_two_unknown_networks(self):
        """Test on a db with one known server and
        two unknown servers (network_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        # add servers
        assign_address(1, "unknown", False, servers)
        assign_address(2, "1.2.3.4", False, servers)
        assign_address(3, "unknown", False, servers)
        # add entries about server 1, Ginny
        entries.insert(self.generate_doc(
            "status", "1", "UNKNOWN", 6, "self", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "2", "UNKNOWN", 6, "5.6.7.8", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "3", "UNKNOWN", 6, "5.6.7.8", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "1", "ARBITER", 7, "self", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "2", "ARBITER", 7, "5.6.7.8", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "3", "ARBITER", 7, "5.6.7.8", datetime.now()))

        # add entries about server 3, Neville

        entries.insert(self.generate_doc(
            "status", "1", "PRIMARY", 1, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "2", "PRIMARY", 1, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "3", "PRIMARY", 1, "self", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "1", "FATAL", 4, "3.3.3.3", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "2", "FATAL", 4, "3.3.3.3", datetime.now()))
        entries.insert(self.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"})["network_name"] == "5.6.7.8"
        assert servers.find_one({"server_num": "3"})["network_name"] == "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
Ejemplo n.º 58
0
 def test_known_names_unknown_networkss(self):
     """Test on a db with three servers whose self_names
     are known, network_names are unknown
     """
     servers, entries, clock_skew, db = self.db_setup()
     # add servers
     assign_address(1, "Grubblyplank", True, servers)
     assign_address(2, "Hagrid", True, servers)
     assign_address(3, "Trelawney", True, servers)
     # add entries
     entries.insert(
         self.generate_doc("status", "1", "PRIMARY", 1, "2.2.2.2",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "1", "SECONDARY", 2, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "ARBITER", 7, "1.1.1.1",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "2", "RECOVERING", 3, "3.3.3.3",
                           datetime.now()))
     entries.insert(
         self.generate_doc("status", "3", "DOWN", 8, "1.1.1.1",
                           datetime.now()))
     entries.insert(
         self.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"})["network_name"] == "1.1.1.1"
     assert servers.find_one({"self_name":
                              "Grubblyplank"})["network_name"] == "1.1.1.1"
     assert servers.find_one({"server_num":
                              "2"})["network_name"] == "2.2.2.2"
     assert servers.find_one({"self_name":
                              "Hagrid"})["network_name"] == "2.2.2.2"
     assert servers.find_one({"server_num":
                              "3"})["network_name"] == "3.3.3.3"
     assert servers.find_one({"self_name":
                              "Trelawney"})["network_name"] == "3.3.3.3"
Ejemplo n.º 59
0
    def test_one_known_two_unknown(self):
        """Test on a db with one known server and
        two unknown servers (self_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        # add servers
        assign_address(1, "unknown", True, servers)
        assign_address(2, "Luna", True, servers)
        assign_address(3, "unknown", True, servers)
        # add entries about server 1, Ginny
        entries.insert(self.generate_doc(
            "status", "1", "UNKNOWN", 6, "self", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "Luna", "UNKNOWN", 6, "Ginny", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "3", "UNKNOWN", 6, "Ginny", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "1", "ARBITER", 7, "self", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "Luna", "ARBITER", 7, "Ginny", datetime.now()))
        entries.insert(self.generate_doc(
            "status", "3", "ARBITER", 7, "Ginny", datetime.now()))

        # add entries about server 3, Neville

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

        # check name matching
        assert address_matchup(db, "hp") == -1
Ejemplo n.º 60
0
    def test_two_known_one_unknown(self):
        """Test on a db with two known servers and one
        unknown server (self_names only)
        """
        servers, entries, clock_skew, db = self.db_setup()
        assign_address(1, "Moony", True, servers)
        assign_address(2, "Padfoot", True, servers)
        assign_address(3, "unknown", True, servers)

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

        assert address_matchup(db, "hp") == -1