Esempio n. 1
0
 def test_success(self):
     """
     Returns todays scaling groups based on number of tenants fetched
     since last time. Updates the current fetch in file
     """
     seq = [
         (GetAllGroups(), const(self.groups)),
         (ReadFileLines("file"), const(["2", "0.0"])),
         (Func(datetime.utcnow), const(datetime(1970, 1, 2))),
         (WriteFileLines("file", [7, 86400.0]), noop)
     ]
     r = perform_sequence(seq, get_todays_scaling_groups(["t1"], "file"))
     self.assertEqual(
         r,
         keyfilter(lambda k: k in ["t{}".format(i) for i in range(1, 9)],
                   self.groups))
Esempio n. 2
0
 def test_error_writing(self):
     """
     Logs and ignores error writing to the file
     """
     seq = [
         (GetAllGroups(), const(self.groups)),
         (ReadFileLines("file"), const(["2", "0.0"])),
         (Func(datetime.utcnow), const(datetime(1970, 1, 2))),
         (WriteFileLines("file", [7, 86400.0]),
          lambda i: raise_(IOError("bad"))),
         (LogErr(mock.ANY, "error updating number of tenants", {}), noop)
     ]
     r = perform_sequence(seq, get_todays_scaling_groups(["t1"], "file"))
     self.assertEqual(
         r,
         keyfilter(lambda k: k in ["t{}".format(i) for i in range(1, 9)],
                   self.groups))
Esempio n. 3
0
 def test_no_last_info(self):
     """
     Returns first 5 non-convergence tenants if could not fetch last info
     from file
     """
     seq = [
         (GetAllGroups(), const(self.groups)),
         (ReadFileLines("file"), lambda i: raise_(IOError("e"))),
         (LogErr(mock.ANY, "error reading previous number of tenants", {}),
          noop),
         (Func(datetime.utcnow), const(datetime(1970, 1, 2))),
         (WriteFileLines("file", [5, 86400.0]), noop)
     ]
     r = perform_sequence(seq, get_todays_scaling_groups(["t1"], "file"))
     self.assertEqual(
         r,
         keyfilter(lambda k: k in ["t{}".format(i) for i in range(1, 7)],
                   self.groups))