def run(self, opts, github): if self.ref: subprocess.check_call([ "git", "fetch", "origin", self.ref ]) subprocess.check_call([ "git", "checkout", "-f", self.revision ]) # Split a value like verify/fedora-23 (prefix, unused, value) = self.context.partition("/") os.environ["TEST_NAME"] = self.name os.environ["TEST_REVISION"] = self.revision if prefix in [ 'container', 'selenium' ]: os.environ["TEST_OS"] = 'fedora-23' else: os.environ["TEST_OS"] = value if opts.publish: self.start_publishing(opts.publish, github) os.environ["TEST_ATTACHMENTS"] = self.sink.attachments msg = "Testing {0} for {1} with {2} on {3}...\n".format(self.revision, self.name, self.context, testinfra.HOSTNAME) sys.stderr.write(msg) ret = None # Figure out what to do next if prefix == "verify": cmd = [ "timeout", "120m", "./verify/run-tests", "--install", "--jobs", str(opts.jobs) ] elif prefix == "avocado": cmd = [ "timeout", "60m", "./avocado/run-tests", "--install", "--quick", "--tests" ] elif prefix == "koji": cmd = [ "timeout", "120m", "./koji/run-build" ] elif prefix == "selenium": if value not in ['firefox', 'chrome']: ret = "Unknown browser for selenium test" cmd = [ "timeout", "60m", "./avocado/run-tests", "--install", "--quick", "--selenium-tests", "--browser", value] elif prefix == "image" or prefix == "container": cmd = [ "timeout", "90m", "./containers/run-tests", "--install", "--container", value] else: ret = "Unknown context" if cmd and opts.verbose: cmd.append("--verbose") offline = ('offline' in opts) and opts.offline ret = ret or self.rebase(offline) # Actually run the tests if not ret: proc = subprocess.Popen(cmd) ret = testinfra.wait_testing(proc, lambda: self.check_publishing(github)) if ret == 124: ret = "Test run has timed out" # All done if self.sink: self.stop_publishing(ret) return ret
def run(self, opts, github): if self.ref: subprocess.check_call([ "git", "fetch", "origin", self.ref ]) subprocess.check_call([ "git", "checkout", self.revision ]) # Split a value like verify/fedora-23 (prefix, unused, value) = self.context.partition("/") os.environ["TEST_NAME"] = self.name os.environ["TEST_REVISION"] = self.revision if prefix in [ 'container', 'selenium' ]: os.environ["TEST_OS"] = 'fedora-23' else: os.environ["TEST_OS"] = value if opts.publish: self.start_publishing(opts.publish, github) os.environ["TEST_ATTACHMENTS"] = self.sink.attachments msg = "Testing {0} for {1} with {2} on {3}...\n".format(self.revision, self.name, self.context, testinfra.HOSTNAME) sys.stderr.write(msg) ret = None # Figure out what to do next if prefix == "verify": cmd = [ "timeout", "120m", "./verify/run-tests", "--install", "--jobs", str(opts.jobs) ] elif prefix == "avocado": cmd = [ "timeout", "60m", "./avocado/run-tests", "--install", "--quick", "--tests" ] elif prefix == "koji": cmd = [ "timeout", "120m", "./koji/run-build" ] elif prefix == "selenium": if value not in ['firefox', 'chrome']: ret = "Unknown browser for selenium test" cmd = [ "timeout", "60m", "./avocado/run-tests", "--install", "--quick", "--selenium-tests", "--browser", value] elif prefix == "image" or prefix == "container": cmd = [ "timeout", "90m", "./containers/run-tests", "--install", "--container", value] else: ret = "Unknown context" if cmd and opts.verbose: cmd.append("--verbose") ret = ret or self.rebase() # Actually run the tests if not ret: proc = subprocess.Popen(cmd) ret = testinfra.wait_testing(proc, lambda: self.check_publishing(github)) if ret == 124: ret = "Test run has timed out" # All done if self.sink: self.stop_publishing(ret)
def run(self, opts, github): if not github.token: print "Need a github token to run image creation tasks" return if opts.publish: self.start_publishing(opts.publish, github) user = github.get("/user")['login'] msg = "Creating image {0} on {1}...\n".format(self.image, testinfra.HOSTNAME) sys.stderr.write(msg) proc = subprocess.Popen([ "./vm-create", "--verbose", "--upload", self.image ]) ret = testinfra.wait_testing(proc, lambda: self.check_publishing(github)) # Github wants the OAuth token as the username and git will # happily echo that back out. So we censor all output. def run_censored(cmd): def censored(text): return text.replace(github.token, "CENSORED") try: output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) print censored(output) return True except subprocess.CalledProcessError as e: print censored(e.output) print "Failed:", censored(' '.join(e.cmd)) return False # Push the new image link to origin, but don't change any local refs branch = "refresh-" + self.image + "-" + time.strftime("%Y-%m-%d") url = "https://{0}@github.com/{1}/cockpit.git".format(github.token, user) # When image creation fails, remove the link and make a pull # request anyway, for extra attention if ret != 0: os.unlink("images/" + self.image) have_branch = (run_censored([ "git", "checkout", "--detach" ]) and run_censored([ "git", "commit", "-a", "-m", testinfra.ISSUE_TITLE_IMAGE_REFRESH.format(self.image) ]) and run_censored([ "git", "push", url, "+HEAD:refs/heads/" + branch ])) if self.sink: self.stop_publishing(github, ret, (user + "::" + branch) if have_branch else None)
def run(self, opts, github): if not github.token: print "Need a github token to run image creation tasks" return if self.issue and 'pull_request' in self.issue: self.pull = github.get(self.issue['pull_request']['url']) if opts.publish: self.start_publishing(opts.publish, github) user = github.get("/user")['login'] msg = "Creating image {0} on {1}...\n".format(self.image, testinfra.HOSTNAME) sys.stderr.write(msg) if self.pull: subprocess.check_call([ "git", "fetch", "origin", "pull/{}/head".format(self.pull['number']) ]) subprocess.check_call([ "git", "checkout", self.pull['head']['sha'] ]) def check(): if not self.check_publishing(github): self.overtaken = True return False return True cmd = [ "./vm-create", "--verbose", "--upload" ] if 'store' in self.config: cmd += [ "--store", self.config['store'] ] cmd += [ self.image ] os.environ['VIRT_BUILDER_NO_CACHE'] = "yes" proc = subprocess.Popen(cmd) self.overtaken = False ret = testinfra.wait_testing(proc, check) if self.overtaken: if self.sink: self.stop_publishing(github, None, None, None) return # Github wants the OAuth token as the username and git will # happily echo that back out. So we censor all output. def run_censored(cmd): def censored(text): return text.replace(github.token, "CENSORED") try: output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) print censored(output) return True except subprocess.CalledProcessError as e: print censored(e.output) print "Failed:", censored(' '.join(e.cmd)) return False # Push the new image link to origin, but don't change any local refs if self.pull: branch = "refresh-" + self.image + "-" + self.pull['head']['sha'] else: branch = "refresh-" + self.image + "-" + time.strftime("%Y-%m-%d") url = "https://{0}@github.com/{1}/cockpit.git".format(github.token, user) # When image creation fails, remove the link and make a pull # request anyway, for extra attention if ret != 0: os.unlink("images/" + self.image) have_branch = (run_censored([ "git", "checkout", "--detach" ]) and run_censored([ "git", "commit", "-a", "-m", testinfra.ISSUE_TITLE_IMAGE_REFRESH.format(self.image) ]) and run_censored([ "git", "push", url, "+HEAD:refs/heads/" + branch ])) if self.sink: self.stop_publishing(github, ret, user, branch if have_branch else None)
def run(self, opts, github): if not github.token: print "Need a github token to run image creation tasks" return if self.issue and 'pull_request' in self.issue: self.pull = github.get(self.issue['pull_request']['url']) if opts.publish: self.start_publishing(opts.publish, github) user = github.get("/user")['login'] msg = "Creating image {0} on {1}...\n".format(self.image, testinfra.HOSTNAME) sys.stderr.write(msg) if self.pull: subprocess.check_call([ "git", "fetch", "origin", "pull/{}/head".format(self.pull['number']) ]) subprocess.check_call( ["git", "checkout", self.pull['head']['sha']]) def check(): if not self.check_publishing(github): self.overtaken = True return False return True cmd = ["./vm-create", "--verbose", "--upload"] if 'store' in self.config: cmd += ["--store", self.config['store']] cmd += [self.image] os.environ['VIRT_BUILDER_NO_CACHE'] = "yes" proc = subprocess.Popen(cmd) self.overtaken = False ret = testinfra.wait_testing(proc, check) if self.overtaken: if self.sink: self.stop_publishing(github, None, None, None) return # Github wants the OAuth token as the username and git will # happily echo that back out. So we censor all output. def run_censored(cmd): def censored(text): return text.replace(github.token, "CENSORED") try: output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) print censored(output) return True except subprocess.CalledProcessError as e: print censored(e.output) print "Failed:", censored(' '.join(e.cmd)) return False # Push the new image link to origin, but don't change any local refs if self.pull: branch = "refresh-" + self.image + "-" + self.pull['head']['sha'] else: branch = "refresh-" + self.image + "-" + time.strftime("%Y-%m-%d") url = "https://{0}@github.com/{1}/cockpit.git".format( github.token, user) # When image creation fails, remove the link and make a pull # request anyway, for extra attention if ret != 0: os.unlink("images/" + self.image) have_branch = (run_censored( ["git", "checkout", "--detach"]) and run_censored([ "git", "commit", "-a", "-m", testinfra.ISSUE_TITLE_IMAGE_REFRESH.format(self.image) ]) and run_censored( ["git", "push", url, "+HEAD:refs/heads/" + branch])) if self.sink: self.stop_publishing(github, ret, user, branch if have_branch else None)