Ejemplo n.º 1
0
 def run_once(self):
     super(basic, self).run_once()
     containers = []
     cidfile = self._nonexisting_path(self.tmpdir, "cidfile-")
     subargs = self.config.get('run_options_csv').split(',')
     containers.append(self._init_container(subargs, cidfile, 'sh', None,
                                            InteractiveAsyncDockerCmd))
     name = self.sub_stuff['containers'][0]
     self.failif(utils.wait_for(lambda: os.path.isfile(cidfile), 9) is None,
                 "cidfile didn't appear in 9s after container execution")
     cont = self._get_container_by_name(name)
     long_id = cont.long_id
     self._check_cidfile(long_id, cidfile)
     # cidfile already exists (running container)
     containers.append(self._init_container(subargs, cidfile, 'true',
                                            lambda x: mustfail(x, 125)))
     self._check_failure_cidfile_present(containers[-1])
     # cidfile already exists (exited container)
     # FIXME: this occasionally throws SIGPIPE, presumably because
     #  container isn't fully ready. This is a tough one to solve.
     containers[0].stdin("exit\n")
     containers[0].wait(10)
     containers[0].close()
     containers.append(self._init_container(subargs, cidfile, 'true',
                                            lambda x: mustfail(x, 125)))
     self._check_failure_cidfile_present(containers[-1])
     # restart container with cidfile
     mustpass(dockercmd.DockerCmd(self, 'start', [name]).execute())
     is_alive = lambda: 'Up' in self._get_container_by_name(name).status
     self.failif(utils.wait_for(is_alive, 10) is None, "Container %s "
                 "was not restarted in 10 seconds." % name)
     self._check_cidfile(long_id, cidfile)
     self.sub_stuff['dc'].kill_container_by_name(name)
     self._check_cidfile(long_id, cidfile)
Ejemplo n.º 2
0
 def run_once(self):
     super(basic, self).run_once()
     containers = []
     cidfile = self._nonexisting_path(self.tmpdir, "cidfile-")
     subargs = self.config.get('run_options_csv').split(',')
     containers.append(self._init_container(subargs, cidfile, 'sh', None,
                                            InteractiveAsyncDockerCmd))
     name = self.sub_stuff['containers'][0]
     self.failif(utils.wait_for(lambda: os.path.isfile(cidfile), 9) is None,
                 "cidfile didn't appear in 9s after container execution")
     cont = self._get_container_by_name(name)
     long_id = cont.long_id
     self._check_cidfile(long_id, cidfile)
     # cidfile already exists (running container)
     containers.append(self._init_container(subargs, cidfile, 'true',
                                            lambda x: mustfail(x, 125)))
     self._check_failure_cidfile_present(containers[-1])
     # cidfile already exists (exited container)
     # FIXME: this occasionally throws SIGPIPE, presumably because
     #  container isn't fully ready. This is a tough one to solve.
     containers[0].stdin("exit\n")
     containers[0].wait(10)
     containers[0].close()
     containers.append(self._init_container(subargs, cidfile, 'true',
                                            lambda x: mustfail(x, 125)))
     self._check_failure_cidfile_present(containers[-1])
     # restart container with cidfile
     mustpass(dockercmd.DockerCmd(self, 'start', [name]).execute())
     is_alive = lambda: 'Up' in self._get_container_by_name(name).status
     self.failif(utils.wait_for(is_alive, 10) is None, "Container %s "
                 "was not restarted in 10 seconds." % name)
     self._check_cidfile(long_id, cidfile)
     self.sub_stuff['dc'].kill_container_by_name(name)
     self._check_cidfile(long_id, cidfile)
Ejemplo n.º 3
0
 def postprocess(self):
     super(login_fail, self).postprocess()
     cmdresult = self.sub_stuff['cmdresult']
     OutputGood(cmdresult, ignore_error=True)
     mustfail(cmdresult, 1)
     self.failif_not_in("401 Unauthorized", cmdresult.stderr,
                        "stderr from failed docker login")
Ejemplo n.º 4
0
 def postprocess(self):
     super(login_fail, self).postprocess()
     cmdresult = self.sub_stuff['cmdresult']
     OutputGood(cmdresult, ignore_error=True)
     mustfail(cmdresult, 1)
     self.failif_not_in("401 Unauthorized", cmdresult.stderr,
                        "stderr from failed docker login")
Ejemplo n.º 5
0
 def run_image(self):
     # Can only cp file from containers, not repos
     subargs = ['--name=%s' % self.sub_stuff['run_name']]
     subargs += ['--detach']
     subargs += [self.sub_stuff['import_repo']]
     subargs += ['some', 'dummy', 'command']
     self.logdebug("Next docker command should fail...")
     mustfail(DockerCmd(self, 'run', subargs).execute())
Ejemplo n.º 6
0
 def cleanup(self):
     # Call empty parent's cleanup, not empty's.
     super(empty, self).cleanup()  # pylint: disable=E1003
     # Fail test if **successful**
     image_name = self.sub_stuff['image_name']  # assume id lookup failed
     if self.parent_subtest.config['remove_after_test']:
         dkrcmd = DockerCmd(self, 'rmi', [image_name])
         mustfail(dkrcmd.execute())
Ejemplo n.º 7
0
 def cleanup(self):
     # Call empty parent's cleanup, not empty's.
     super(empty, self).cleanup()  # pylint: disable=E1003
     # Fail test if **successful**
     image_name = self.sub_stuff['image_name']  # assume id lookup failed
     if self.parent_subtest.config['remove_after_test']:
         dkrcmd = DockerCmd(self, 'rmi', [image_name])
         mustfail(dkrcmd.execute(), 1)
Ejemplo n.º 8
0
 def run_image(self):
     # Can only cp file from containers, not repos
     subargs = ['--name=%s' % self.sub_stuff['run_name']]
     subargs += ['--detach']
     subargs += [self.sub_stuff['import_repo']]
     subargs += ['some', 'dummy', 'command']
     self.logdebug("Next docker command should fail...")
     mustfail(DockerCmd(self, 'run', subargs).execute())
Ejemplo n.º 9
0
 def run_once(self):
     super(memory_base, self).run_once()
     memory_containers = self.sub_stuff['memory_containers']
     for subargs in self.sub_stuff['subargs']:
         dkrcmd = DockerCmd(self, 'run -d -i', subargs)
         dkrcmd.execute()
         if self.config['expect_success'] == 'PASS':
             mustpass(dkrcmd)
         else:
             mustfail(dkrcmd, 125)
         memory_containers.append(dkrcmd)
Ejemplo n.º 10
0
 def run_once(self):
     super(memory_base, self).run_once()
     memory_containers = self.sub_stuff['memory_containers']
     for subargs in self.sub_stuff['subargs']:
         dkrcmd = DockerCmd(self, 'run -d -i', subargs)
         dkrcmd.execute()
         if self.config['expect_success'] == 'PASS':
             mustpass(dkrcmd)
         else:
             mustfail(dkrcmd, 125)
         memory_containers.append(dkrcmd)
Ejemplo n.º 11
0
 def postprocess(self):
     NoPanic(self.sub_stuff['cmdresult'])
     expected_exit_status = self.config['extcmd']
     cmdresult = self.sub_stuff['cmdresult']
     mustfail(cmdresult, expected_exit_status)
     # Same checks for both
     for outtype in ('stdout', 'stderr'):
         if self.sub_stuff[outtype] is not None:
             regex = self.sub_stuff[outtype]
             mobj = regex.search(getattr(cmdresult, outtype))
             self.failif(
                 mobj is None, "%s did not match regex '%s':\n%s" %
                 (outtype, regex.pattern, cmdresult))
Ejemplo n.º 12
0
 def run_once(self):
     """
     Main test body
     """
     super(kill_bad_base, self).run_once()
     self.logdebug("Executing couple of bad kill signals.")
     self.failif(self.sub_stuff["container_cmd"].done, "Testing container " "died unexpectadly.")
     for signal in self.config["bad_signals"].split(","):
         mustfail(DockerCmd(self, "kill", ["-s", signal, self.sub_stuff["container_name"]]).execute(), 1)
         self.failif(
             self.sub_stuff["container_cmd"].done, "Testing " "container died after using signal %s." % signal
         )
     dkrcnt = DockerContainers(self)
     nonexisting_name = dkrcnt.get_unique_name()
     self.logdebug("Killing nonexisting containe.")
     mustfail(DockerCmd(self, "kill", [nonexisting_name]).execute(), 1)
Ejemplo n.º 13
0
 def _execute_bad(self, dns, search):
     """ Execute and expect failure """
     subargs = self.stuff['subargs'][:]
     if dns:
         for server in dns:
             subargs.insert(0, '--dns %s' % server)
     if search:
         for name in search:
             subargs.insert(0, '--dns-search %s' % name)
     return mustfail(DockerCmd(self, 'run', subargs).execute(), 125)
Ejemplo n.º 14
0
 def _execute_bad(self, dns, search):
     """ Execute and expect failure """
     subargs = self.stuff["subargs"][:]
     if dns:
         for server in dns:
             subargs.insert(0, "--dns %s" % server)
     if search:
         for name in search:
             subargs.insert(0, "--dns-search %s" % name)
     return mustfail(DockerCmd(self, "run", subargs, verbose=False).execute())
Ejemplo n.º 15
0
 def _execute_bad(self, dns, search):
     """ Execute and expect failure """
     subargs = self.stuff['subargs'][:]
     if dns:
         for server in dns:
             subargs.insert(0, '--dns %s' % server)
     if search:
         for name in search:
             subargs.insert(0, '--dns-search %s' % name)
     return mustfail(DockerCmd(self, 'run', subargs).execute(), 125)
Ejemplo n.º 16
0
 def run_once(self):
     super(create_signal, self).run_once()
     cont = self.sub_stuff['cont']
     sig = getattr(signal, self.config['listen_signal'])
     cont.kill_signal = sig
     # Should not fail
     sigdkrcmd = DockerCmd(self, 'kill',
                           ['--signal', str(sig),
                            self.get_cid()])
     sigdkrcmd = mustfail(sigdkrcmd.execute())
     self.sub_stuff['sigdkrcmd'] = sigdkrcmd
Ejemplo n.º 17
0
 def run_once(self):
     """
     Main test body
     """
     super(kill_bad_base, self).run_once()
     self.logdebug("Executing couple of bad kill signals.")
     self.failif(self.sub_stuff['container_cmd'].done, "Testing container "
                 "died unexpectadly.")
     for signal in self.config['bad_signals'].split(','):
         mustfail(
             DockerCmd(self, 'kill',
                       ['-s', signal, self.sub_stuff['container_name']
                        ]).execute(), 1)
         self.failif(
             self.sub_stuff['container_cmd'].done, "Testing "
             "container died after using signal %s." % signal)
     dkrcnt = DockerContainers(self)
     nonexisting_name = dkrcnt.get_unique_name()
     self.logdebug("Killing nonexisting containe.")
     mustfail(DockerCmd(self, 'kill', [nonexisting_name]).execute(), 1)
Ejemplo n.º 18
0
 def run_once(self):
     """
     Main test body
     """
     super(kill_bad_base, self).run_once()
     self.logdebug("Executing couple of bad kill signals.")
     self.failif(self.sub_stuff['container_cmd'].done, "Testing container "
                 "died unexpectadly.")
     for signal in self.config['bad_signals'].split(','):
         mustfail(DockerCmd(self, 'kill',
                            ['-s', signal,
                             self.sub_stuff['container_name']],
                            verbose=False).execute())
         self.failif(self.sub_stuff['container_cmd'].done, "Testing "
                     "container died after using signal %s." % signal)
     dkrcnt = DockerContainers(self)
     nonexisting_name = dkrcnt.get_unique_name()
     self.logdebug("Killing nonexisting containe.")
     mustfail(DockerCmd(self, 'kill', [nonexisting_name],
                        verbose=False).execute())
Ejemplo n.º 19
0
 def run_once(self):
     super(flag, self).run_once()
     args = ["run"]
     args.append("--name=%s" % self.stuff["containter_name"])
     fin = DockerImage.full_name_from_defaults(self.config)
     args.append(fin)
     args.append("/bin/bash")
     args.append("-c")
     args.append("\"echo negative test for docker flags\"")
     dc = DockerCmd(self, self.config["flag_args"], args)
     self.stuff["cmdresult"] = mustfail(dc.execute())
Ejemplo n.º 20
0
 def run_once(self):
     super(flag, self).run_once()
     args = ["run"]
     args.append("--name=%s" % self.stuff["containter_name"])
     fin = DockerImage.full_name_from_defaults(self.config)
     args.append(fin)
     args.append("/bin/bash")
     args.append("-c")
     args.append('"echo negative test for docker flags"')
     dc = DockerCmd(self, self.config["flag_args"], args)
     self.stuff["cmdresult"] = mustfail(dc.execute())
Ejemplo n.º 21
0
 def run_once(self):
     super(create_signal, self).run_once()
     cont = self.sub_stuff['cont']
     sig = getattr(signal, self.config['listen_signal'])
     cont.kill_signal = sig
     # Should not fail
     sigdkrcmd = DockerCmd(
         self, 'kill',
         ['--signal', str(sig), self.get_cid()])
     sigdkrcmd = mustfail(sigdkrcmd.execute(), 1)
     self.sub_stuff['sigdkrcmd'] = sigdkrcmd
Ejemplo n.º 22
0
    def run_once(self):
        # Execute the start command
        super(simple, self).run_once()
        name = self.sub_stuff['container_name']
        err_msg = ("Start of the %s container failed, but '%s' message is not "
                   "in the output:\n%s")
        # Nonexisting container
        missing_msg = self.config['missing_msg']
        result = mustfail(DockerCmd(self, "start", [name]).execute(), 1)
        self.failif(missing_msg not in str(result), err_msg
                    % ("non-existing", missing_msg, result))

        # Running container
        self._start_container(name)
        result = mustpass(DockerCmd(self, "start", [name]).execute())

        # Stopped container
        mustpass(DockerCmd(self, "kill", [name]).execute())
        result = mustpass(DockerCmd(self, "start", [name]).execute())
Ejemplo n.º 23
0
    def run_once(self):
        # Execute the start command
        super(simple, self).run_once()
        name = self.sub_stuff['container_name']
        # Container does not yet exist; 'start' should fail.
        result = mustfail(DockerCmd(self, "start", [name]).execute(), 1)
        self.failif_not_in(self.config['missing_msg'], str(result),
                           "'docker start <nonexistent container>' failed"
                           " (as expected), but docker error message did not"
                           " include expected diagnostic.")

        # Now run the container. The first "start" here is a NOP but is
        # included to confirm that consecutive "docker start" commands
        # do not fail; rhbz#1096293
        self._start_container(name)
        result = mustpass(DockerCmd(self, "start", [name]).execute())

        # Stop container, then restart it.
        mustpass(DockerCmd(self, "kill", [name]).execute())
        mustpass(DockerCmd(self, "wait", [name]).execute())
        result = mustpass(DockerCmd(self, "start", [name]).execute())
Ejemplo n.º 24
0
 def postprocess(self):
     super(push_fail, self).postprocess()
     cmdresult = self.sub_stuff['pushresult']
     OutputGood(cmdresult, ignore_error=True)
     mustfail(cmdresult, 1)
Ejemplo n.º 25
0
 def postprocess(self):
     super(push_fail, self).postprocess()
     cmdresult = self.sub_stuff['pushresult']
     OutputGood(cmdresult, ignore_error=True)
     mustfail(cmdresult, 1)
Ejemplo n.º 26
0
 def postprocess(self):
     dkrcmd_exec = self.sub_stuff['dkrcmd_exec']
     mustfail(dkrcmd_exec.cmdresult, 1)
     OutputNotBad(dkrcmd_exec.cmdresult)
     super(exec_false, self).postprocess()
Ejemplo n.º 27
0
 def postprocess(self):
     dkrcmd_exec = self.sub_stuff['dkrcmd_exec']
     mustfail(dkrcmd_exec.cmdresult, 1)
     OutputNotBad(dkrcmd_exec.cmdresult)
     super(exec_false, self).postprocess()