def run_once(self): super(every_last, self).run_once() total = len(self.sub_stuff['lastfiles']) self.sub_stuff['expected_total'] = total self.failif(total < self.config['max_files'], "Max files number expected : %d," "exceeds container total has : %d" % (self.config['max_files'], total)) self.loginfo("Testing copy of %d files from container" % total) self.sub_stuff['results'] = {} # cont_path -> cmdresult nfdc = DockerCmd(self, 'cp') nfdc.quiet = True nfiles = 0 for index, srcfile in enumerate(self.sub_stuff['lastfiles']): if index % 100 == 0: self.loginfo("Copied %d of %d", nfiles, total) cont_path = "%s:%s" % (self.sub_stuff['container_name'], srcfile) host_path = self.tmpdir host_fullpath = os.path.join(host_path, os.path.basename(srcfile)) nfdc.subargs = [cont_path, host_path] mustpass(nfdc.execute()) self.failif(not os.path.isfile(host_fullpath), "Not a file: '%s'" % host_fullpath) nfiles += 1 self.sub_stuff['nfiles'] = nfiles if nfiles >= self.config['max_files']: self.loginfo("Configuration max %d, Copied %d of %d" % (self.config['max_files'], nfiles, total)) break
def run_once(self): super(every_last, self).run_once() total = len(self.sub_stuff["lastfiles"]) self.sub_stuff["expected_total"] = total self.failif( total < self.config["max_files"], "Max files number expected : %d," "exceeds container total has : %d" % (self.config["max_files"], total), ) self.loginfo("Testing copy of %d files from container" % total) self.sub_stuff["results"] = {} # cont_path -> cmdresult nfdc = DockerCmd(self, "cp") nfdc.quiet = True nfiles = 0 for index, srcfile in enumerate(self.sub_stuff["lastfiles"]): if index % 100 == 0: self.loginfo("Copied %d of %d", nfiles, total) cont_path = "%s:%s" % (self.sub_stuff["container_name"], srcfile) host_path = self.tmpdir host_fullpath = os.path.join(host_path, os.path.basename(srcfile)) nfdc.subargs = [cont_path, host_path] mustpass(nfdc.execute()) self.failif(not os.path.isfile(host_fullpath), "Not a file: '%s'" % host_fullpath) nfiles += 1 self.sub_stuff["nfiles"] = nfiles if nfiles >= self.config["max_files"]: self.loginfo("Configuration max %d, Copied %d of %d" % (self.config["max_files"], nfiles, total)) break
def filedir_contents_postprocess(self, build_def, command, parameter): bad_command = [command.find('file_exist') < 0, command.find('dir_exist') < 0, command.find('rx_file') < 0] if all(bad_command): raise DockerTestError('Command error: %s' % command) positive = command[0] != '!' # Need a character unlikely in file name params = get_as_list(parameter, ':') path = params[0] try: regex = re.compile(''.join(params[1:])) except IndexError: # parameter not specified regex = None # Only cmd differs between all commands (file, dir, rx). if command.find('file') > -1: cmd = 'cat "%s"' % path else: cmd = 'ls -la "%s"' % path subargs = ['--rm', '--attach', 'stdout', build_def.image_name, cmd] dkrcmd = DockerCmd(self, 'run', subargs) dkrcmd.quiet = True dkrcmd.execute() exists = dkrcmd.exit_status == 0 self.logdebug('%s(%s) exists: %s', command, path, exists) if command.find('exist') > -1: return positive == exists if not exists: return False # guaranteed failure, don't bother searching contents = dkrcmd.stdout.strip() mobj = regex.search(contents) self.logdebug('%s(%s) matches: %s', command, regex.pattern, bool(mobj)) return positive == bool(mobj)
def filedir_contents_postprocess(self, build_def, command, parameter): bad_command = [command.find('file_exist') < 0, command.find('dir_exist') < 0, command.find('rx_file') < 0] if all(bad_command): raise DockerTestError('Command error: %s' % command) positive = command[0] != '!' # Need a character unlikely in file name params = get_as_list(parameter, ':') path = params[0] try: regex = re.compile(''.join(params[1:])) except IndexError: # parameter not specified regex = None # Only cmd differs between all commands (file, dir, rx). if command.find('file') > -1: cmd = 'cat "%s"' % path else: cmd = 'ls -la "%s"' % path subargs = ['--rm', '--attach', 'stdout', build_def.image_name, cmd] dkrcmd = DockerCmd(self, 'run', subargs, verbose=False) dkrcmd.quiet = True dkrcmd.execute() exists = dkrcmd.exit_status == 0 self.logdebug('%s(%s) exists: %s', command, path, exists) if command.find('exist') > -1: return positive == exists if not exists: return False # guaranteed failure, don't bother searching contents = dkrcmd.stdout.strip() mobj = regex.search(contents) self.logdebug('%s(%s) matches: %s', command, regex.pattern, bool(mobj)) return positive == bool(mobj)
def initialize_cmdline(self): subargs = ['--rm', '-v', '%s:/x:Z' % self.tmpdir] for key, value in self.sub_stuff['envd'].iteritems(): subargs.append("-e") subargs.append("%s=%s" % (key, value)) subargs.append(DockerImages(self).default_image) subargs.append("bash -c 'env > /x/env.output'") _ = DockerCmd(self, 'run', subargs, verbose=False) _.quiet = True self.sub_stuff['dkrcmd'] = _
def initialize_cmdline(self): subargs = ['--rm', '-v', '%s:/x:Z' % self.tmpdir] for key, value in self.sub_stuff['envd'].items(): subargs.append("-e") subargs.append("%s=%s" % (key, value)) subargs.append(DockerImages(self).default_image) subargs.append("bash -c 'env > /x/env.output'") _ = DockerCmd(self, 'run', subargs) _.quiet = True self.sub_stuff['dkrcmd'] = _
def container_files(self, fqin): """ Returns a list of tuples as from os.walk() inside fqin """ code = ('%s\nall_files([%s], %s)' % (inspect.getsource(all_files), self.config['exclude_paths'], self.config['exclude_symlinks'])) subargs = [ "--net=none", "--name=%s" % self.sub_stuff['container_name'], "--attach=stdout", fqin, "python -c '%s'" % code ] nfdc = DockerCmd(self, "run", subargs) nfdc.quiet = True self.logdebug("Executing %s", nfdc.command) mustpass(nfdc.execute()) return pickle.load(StringIO(nfdc.stdout))
def container_files(self, fqin): """ Returns a list of tuples as from os.walk() inside fqin """ code = ('%s\nall_files([%s], %s)' % (inspect.getsource(all_files), self.config['exclude_paths'], self.config['exclude_symlinks'])) subargs = ["--net=none", "--name=%s" % self.sub_stuff['container_name'], "--attach=stdout", fqin, "python -c '%s'" % code] nfdc = DockerCmd(self, "run", subargs) nfdc.quiet = True self.logdebug("Executing %s", nfdc.command) mustpass(nfdc.execute()) return pickle.load(StringIO(nfdc.stdout))