Exemplo n.º 1
0
 def test_append(self):
     self.q.put(NewCgroupMessage(Cgroup("/some/foo")))
     self.q.put(StaleCgroupMessage(Cgroup("/some/foo")))
     self.q.put(ExitMessage())
     self.engine.run()
     self.assertHasLogged("foo",
                          ["container has started", "container has exited"])
Exemplo n.º 2
0
 def test_no_pids(self):
     self.q.put(RestartCgroupMessage(Cgroup("/some/foo"), []))
     self.q.put(ExitMessage())
     self.engine.run()
     self.assertHasLogged("foo", [
         "container exceeded its memory allocation",
         "container is restarting:",
     ])
Exemplo n.º 3
0
 def test_large_memory_value(self):
     # Newer versions of Python (e.g. 3.4) will show this value in
     # scientific notation, which isn't desirable here.
     size = 2 * 1024 * 1024 * 1024  # 2GB
     MemInfo = namedtuple('MemInfo', ["rss", "vms"])
     ps_table = [{
         "pid": 123,
         "ppid": 0,
         "memory_info": MemInfo(rss=size, vms=size),
         "cmdline": ["some", "proc"],
         "status": psutil.STATUS_RUNNING,
     }]
     self.q.put(RestartCgroupMessage(Cgroup("/some/foo"), ps_table))
     self.q.put(ExitMessage())
     self.engine.run()
     self.assertHasLogged("foo", [
         "container exceeded its memory allocation",
         "container is restarting:",
         re.compile(r"123\s+0\s+2097152\s+2097152\s+R\s+some proc"),
     ])
Exemplo n.º 4
0
 def test_restart_cgroup(self):
     MemInfo = namedtuple('MemInfo', ["rss", "vms"])
     ps_table = [{
         "pid": 123,
         "memory_info": MemInfo(rss=1024 * 8, vms=1024 * 16),
         "cmdline": ["some", "proc"],
         "status": psutil.STATUS_STOPPED,
     }, {
         "pid": 456,
         "memory_info": MemInfo(rss=1024 * 2, vms=1024 * 4),
         "cmdline": ["sh", "-c", "a && b"],
         "status": psutil.STATUS_RUNNING,
     }]
     self.q.put(RestartCgroupMessage(Cgroup("/some/foo"), ps_table))
     self.q.put(ExitMessage())
     self.engine.run()
     self.assertHasLogged("foo", [
         "container exceeded its memory allocation",
         "container is restarting:",
         re.compile(r"123\s+16\s+8\s+T\s+some proc"),
         re.compile(r'456\s+4\s+2\s+R\s+sh -c "a && b"')
     ])
Exemplo n.º 5
0
 def test_restart_timeout(self):
     self.q.put(RestartTimeoutMessage(Cgroup("/some/foo"), 3))
     self.q.put(ExitMessage())
     self.engine.run()
     self.assertHasLogged(
         "foo", ["container did not exit within 3 seconds grace period"])
Exemplo n.º 6
0
 def test_new_cgroup(self):
     self.q.put(NewCgroupMessage(Cgroup("/some/foo")))
     self.q.put(ExitMessage())
     self.engine.run()
     self.assertHasLogged("foo", ["container has started"])
Exemplo n.º 7
0
 def test_exit(self):
     self.q.put(ExitMessage())
     self.engine.run()