Exemplo n.º 1
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", servers)
     assign_address(2, "Mel", servers)
     # these are skewed by 3 seconds
     entries.insert(generate_doc(
         "status", "Hannah", "PRIMARY", 1, "Mel", datetime.now()))
     sleep(3)
     entries.insert(generate_doc(
         "status", "Mel", "PRIMARY", 1, "self", datetime.now()))
     # one other message to break the matching pattern
     sleep(2)
     entries.insert(generate_doc(
         "status", "Hannah", "ARBITER", 7, "Mel", datetime.now()))
     sleep(2)
     # these are skewed by 5 seconds
     entries.insert(generate_doc(
         "status", "Hannah", "SECONDARY", 2, "Mel", datetime.now()))
     sleep(5)
     entries.insert(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
Exemplo n.º 2
0
    def test_replacing_one_value(self):
        logger = logging.getLogger(__name__)
        servers, entries, clock_skew, db = db_setup()
        skew1 = 5

        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))
        assign_address(5, "pear", servers)
        assign_address(6, "apple", servers)
        doc1 = self.generate_cs_doc("5", "6")
        doc1["partners"]["6"]["5"] = skew1
        clock_skew.insert(doc1)
        doc1 = self.generate_cs_doc("6", "5")
        doc1["partners"]["5"]["0"] = -skew1
        clock_skew.insert(doc1)

        clock_skew.insert(doc1)
        replace_clock_skew(db, "fruit")

        docs = entries.find({"origin_server": "apple"})
        for doc in docs:
            logger.debug("Original Date: {}".format(doc["date"]))
            logger.debug("Adjusted Date: {}".format(doc["adjusted_date"]))
            delta = abs(original_date - doc["adjusted_date"])
            logger.debug("Delta: {}".format(repr(delta)))
            if delta - timedelta(seconds=skew1) < timedelta(milliseconds=1):
                assert True
                continue
            assert False
Exemplo n.º 3
0
    def test_replacing_none(self):
        logger = logging.getLogger(__name__)
        """"Replaces servers without skews."""""
        #result = db_setup()
        servers, entries, clock_skew, db = 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))
        assign_address(5, "pear", servers)
        assign_address(6, "apple", servers)
        doc1 = self.generate_cs_doc("5", "6")
        doc1["partners"]["6"]["0"] = 5
        clock_skew.insert(doc1)
        doc1 = self.generate_cs_doc("6", "5")
        doc1["partners"]["5"]["0"] = 5
        clock_skew.insert(doc1)

        replace_clock_skew(db, "fruit")

        docs = entries.find({"origin_server": "apple"})
        for doc in docs:
            logger.debug("Original Date: {}".format(doc["date"]))
            delta = original_date - doc["date"]
            logger.debug("Delta: {}".format(repr(delta)))

            if delta < timedelta(milliseconds=1):
                assert  True
                continue
            assert False
Exemplo n.º 4
0
 def insert_unknown(self, n, servers):
     """Inserts n unknown servers into .servers collection.
     Assumes, for these tests, that hostnames are unknown
     and must be matched, while IPs are known"""
     for i in range(1, n):
         ip = str(i) + "." + str(i) + "." + str(i) + "." + str(i)
         assign_address(i, ip, servers)
Exemplo n.º 5
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"})
Exemplo n.º 6
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