コード例 #1
0
 def check_output_inverted(self):
     """
     Inverse version of check_output (fails in case of stdout str presence
     """
     check_stdout = self.config.get("check_stdout")
     results = self.sub_stuff['container_results']
     if check_stdout and check_stdout in results.stdout:
         raise xceptions.DockerTestFail("Expected stdout '%s' not in "
                                        "container_results:\n%s" %
                                        (check_stdout, results))
コード例 #2
0
 def check_output(self):
     """
     Check that config[check_stdout] is present in the execute docker stdout
     """
     check_stdout = self.config.get("check_stdout")
     results = self.sub_stuff['container_results']
     if check_stdout and check_stdout not in results.stdout:
         raise xceptions.DockerTestFail("Expected stdout '%s' not in "
                                        "container_results:\n%s" %
                                        (check_stdout, results))
コード例 #3
0
 def postprocess(self):
     super(cpu_base, self).postprocess()
     result = self.sub_stuff['result']
     invalid = xceptions.DockerTestError("Invalid result %s" % result)
     if self.config['expect_success'] == "PASS":
         if result['FAIL'] is not None:
             raise xceptions.DockerTestFail(result)
         elif result['PASS'] is not None:
             self.logdebug(result)
         else:
             raise invalid
     else:
         self.loginfo("Command expected to fail!")
         if result['PASS'] is not None:
             raise xceptions.DockerTestFail(result)
         elif result['FAIL'] is not None:
             self.logdebug(result)
         else:
             raise invalid
コード例 #4
0
 def fail_missing(self, check, stopped_log, container_out, line):
     """Expected signal missing, log details, fail the test"""
     idx = container_out.idx
     msg = ("Not all signals were handled inside container "
            "after SIGCONT execution.\nExpected output "
            "(unordered):\n  %s\nActual container output:\n"
            "  %s\nFirst missing line:\n  %s"
            % ("\n  ".join([check % sig for sig in stopped_log]),
               "\n  ".join(container_out.get(idx)), line))
     self.logdebug(msg)
     raise xceptions.DockerTestFail("Missing Signal(s), see debug "
                                    "log for more details.")
コード例 #5
0
 def _kill_dash_nine(self, container_cmd):
     """
     Destroy the container with -9, check that it died in 5s
     """
     for _ in xrange(50):    # wait for command to finish
         if container_cmd.done:
             break
         time.sleep(0.1)
     else:
         raise xceptions.DockerTestFail("Container process did not"
                                        " finish when kill -9 "
                                        "was executed.")
     self.sub_stuff['container_results'] = container_cmd.wait()
コード例 #6
0
 def run_once(self):
     # Execute the stop command
     super(stop_base, self).run_once()
     container_cmd = self.sub_stuff['container_cmd']
     self.sub_stuff['stop_results'] = self.sub_stuff['stop_cmd'].execute()
     # Wait for container exit
     for _ in range(50):
         if container_cmd.done:
             break
         time.sleep(0.1)
     else:
         raise xceptions.DockerTestFail("Container process did not finish "
                                        "after stop command execution.")
     self.sub_stuff['container_results'] = container_cmd.wait()
コード例 #7
0
 def _execute_command(self, cmd, signal, _container_pid):
     """
     Execute cmd and verify it was executed properly
     :param cmd: DockerCmd or False to send signal directly
     """
     if cmd is not False:    # Custom command, execute&check cmd status
         result = cmd.execute()
         self.sub_stuff['kill_results'].append(result)
         if signal == -1:
             if result.exit_status == 0:    # Any bad signal
                 msg = ("Kill command %s returned zero status when "
                        "using bad signal."
                        % (self.sub_stuff['kill_results'][-1].command))
                 raise xceptions.DockerTestFail(msg)
         else:
             if result.exit_status != 0:
                 msg = ("Kill command %s returned non-zero status. (%s)"
                        % (self.sub_stuff['kill_results'][-1].command,
                           self.sub_stuff['kill_results'][-1].exit_status))
                 raise xceptions.DockerTestFail(msg)
     else:   # Send signal directly to the docker process
         self.logdebug("Sending signal %s directly to container pid %s",
                       signal, _container_pid)
         os.kill(_container_pid, signal)
コード例 #8
0
 def _check_signal(self, container_out, _check, signal, timeout):
     """
     Check container for $signal check output presence
     """
     _idx = container_out.idx
     check = _check % signal
     output_matches = lambda: check in container_out.get(_idx)
     # Wait until the signal gets logged
     if wait_for(output_matches, timeout, step=0) is None:
         msg = ("Signal %s not handled inside container.\nExpected "
                "output:\n  %s\nActual container output:\n  %s" %
                (signal, check, "\n  ".join(container_out.get(_idx))))
         self.logdebug(msg)
         raise xceptions.DockerTestFail("Unhandled signal(s), see debug"
                                        "log for more details")
コード例 #9
0
 def check_output(self, lines, bad_lines, timeout=5):
     """
     Wait $timeout for all good lines presence in sub_stuff['container_id']
     :param lines: list of expected lines in given order. All other lines
                   in between are ignored.
     :param bad_lines: list of lines, which musn't be present in the output
     :param timeout: operation deadline
     :raise xceptions.DockerTestFail: In case of bad output or timeout
     :warning: It doesn't wait for input when only bad_lines are given!
     """
     endtime = time.time() + timeout
     container_id = self.sub_stuff['container_id']
     while time.time() < endtime:
         log_results = mustpass(
             DockerCmd(self, 'logs', [container_id]).execute())
         log = log_results.stdout.splitlines()
         i = 0  # (good) lines idx
         exp = lines[i]
         for act in log:
             if act in bad_lines:
                 msg = ("Check output fail; all lines present, but "
                        "bad_lines too:\nlines:\n%s\nbad_lines:\n%s\n"
                        "output:\n%s" % (lines, bad_lines, log))
                 raise xceptions.DockerTestFail(msg)
             if exp == act:
                 i += 1
                 if i < len(lines):
                     exp = lines[i]
                 else:
                     exp = None  # lines are done, check only bad_lines...
         if i >= len(lines):
             break
     else:
         msg = ("Check output fail:\ncheck_lines:\n%s\nbad_lines:\n%s\n"
                "docker_output:\n%s" % (lines, bad_lines, log))
         raise xceptions.DockerTestFail(msg)
コード例 #10
0
 def run_once(self):
     # Execute the kill command
     kill_base.run_once(self)
     container_cmd = self.sub_stuff['container_cmd']
     kill_cmds = self.sub_stuff['kill_cmds']
     signals_set = self.sub_stuff['signals_set']
     timeout = self.config['stress_cmd_timeout']
     _check = self.config['check_stdout']
     self.sub_stuff['kill_results'] = [
         utils.run(kill_cmds[0], verbose=True)
     ]
     endtime = time.time() + timeout
     line = None
     out = None
     while endtime > time.time():
         try:
             out = container_cmd.stdout.splitlines()
             for line in [_check % sig for sig in signals_set]:
                 out.remove(line)
             break
         except ValueError:
             pass
     else:
         self.fail_missing(_check, signals_set, Output(container_cmd, 0),
                           line)
     # Kill -9
     if kill_cmds[1] is not False:  # Custom kill command
         self.sub_stuff['kill_results'].append(kill_cmds[1].execute())
     else:  # kill the container process
         os.kill(container_cmd.process_id, 9)
     for _ in xrange(50):
         if container_cmd.done:
             break
         time.sleep(0.1)
     else:
         raise xceptions.DockerTestFail("Container process did not"
                                        " finish when kill -9 "
                                        "was executed.")
     self.sub_stuff['container_results'] = container_cmd.wait()