From 4ce3c6d2a8a8db89bd3c63fc6fb69459dfba61a8 Mon Sep 17 00:00:00 2001 From: petervo Date: Wed, 4 Jan 2017 23:10:51 -0800 Subject: [PATCH] test: Stop using ostree trivial-httpd trivial-httpd will be depreciated. Related: ostreedev/ostree#636 --- test/images/scripts/lib/atomic.install | 62 ++++++++++++++++---------- test/verify/check-ostree | 20 ++++++--- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/test/images/scripts/lib/atomic.install b/test/images/scripts/lib/atomic.install index 5ccc63b2c8ea..f63aa573d181 100755 --- a/test/images/scripts/lib/atomic.install +++ b/test/images/scripts/lib/atomic.install @@ -26,6 +26,7 @@ import urllib import argparse import datetime import json +import re BASEDIR = os.path.dirname(__file__) @@ -35,6 +36,7 @@ class AtomicCockpitInstaller: repo_location = "/var/local-repo" rpm_location = "/usr/share/rpm" key_id = "95A8BA1754D0E95E2B3A98A7EE15015654780CBD" + port = 12345 # Support installing random packages if needed. external_packages = {} @@ -79,34 +81,46 @@ class AtomicCockpitInstaller: if self.verbose: print "install new ostree commit" - port = subprocess.check_output(["ostree", "trivial-httpd", self.repo_location, - "-p", "-", "-d"]) + newenv = dict(os.environ) + newenv['PYTHONUNBUFFERED'] = '1' + webserver_proc = subprocess.Popen(['python', '-m', 'SimpleHTTPServer', str(self.port)], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=self.repo_location, env=newenv) + webserver_status = webserver_proc.stdout.readline() + pattern = r'port {}'.format(self.port) + m = re.search(pattern, webserver_status) + if m is None: + raise Exception("Failed to find {} in {}\n".format(pattern, webserver_status)) # Not an error if this fails subprocess.call(["ostree", "remote", "delete", "local"]) - subprocess.check_call(["ostree", "remote", "add", "local", - "http://127.0.0.1:{0}".format(port.strip()), - "--no-gpg-verify"]) - - # HACK: https://github.com/candlepin/subscription-manager/issues/1404 - subprocess.call(["systemctl", "disable", "rhsmcertd"]) - subprocess.call(["systemctl", "stop", "rhsmcertd"]) - - status = subprocess.check_output(["rpm-ostree", "status"]) - if "local:" in status: - subprocess.check_call(["rpm-ostree", "upgrade"]) - else: - try: - subprocess.check_call(["setenforce", "0"]) - subprocess.check_call(["rpm-ostree", "rebase", - "local:{0}".format(self.branch)]) - except: - os.system("sysctl kernel.core_pattern") - os.system("coredumpctl || true") - raise - finally: - subprocess.check_call(["setenforce", "1"]) + try: + subprocess.check_call(["ostree", "remote", "add", "local", + "http://127.0.0.1:{0}".format(self.port), + "--no-gpg-verify"]) + + # HACK: https://github.com/candlepin/subscription-manager/issues/1404 + subprocess.call(["systemctl", "disable", "rhsmcertd"]) + subprocess.call(["systemctl", "stop", "rhsmcertd"]) + + status = subprocess.check_output(["rpm-ostree", "status"]) + if "local:" in status: + subprocess.check_call(["rpm-ostree", "upgrade"]) + else: + try: + subprocess.check_call(["setenforce", "0"]) + subprocess.check_call(["rpm-ostree", "rebase", + "local:{0}".format(self.branch)]) + except: + os.system("sysctl kernel.core_pattern") + os.system("coredumpctl || true") + raise + finally: + subprocess.check_call(["setenforce", "1"]) + finally: + webserver_proc.terminate() def commit_to_repo(self): if self.verbose: diff --git a/test/verify/check-ostree b/test/verify/check-ostree index fa8d2bbf086b..3cf107549228 100755 --- a/test/verify/check-ostree +++ b/test/verify/check-ostree @@ -40,11 +40,18 @@ KEY_ID = "95A8BA1754D0E95E2B3A98A7EE15015654780CBD" def start_trivial_httpd(m): remote = m.execute("ostree remote show-url local") parts = remote.strip().split(":") + port = parts[-1] - # If ostree supports rpm-ostreed then it support the -P option - args = [parts[-1], REPO_LOCATION] - m.execute("ostree trivial-httpd -d -P {0} {1} ".format(*args)) + script = "cd {0}\nsetsid python -m SimpleHTTPServer {1} >/dev/null 2>&1 < /dev/null &\necho $!".format(REPO_LOCATION, port) + result = m.execute(script=script, + environment={"PYTHONUNBUFFERED" : "1"}) + m.wait_for_cockpit_running(port=port) + return result.strip() + +def stop_trivial_httpd(m, pid): + if pid: + m.execute(["kill", pid]) def generate_new_commit(m, pkg_to_remove): # Make one change of each type to a new rpm tree @@ -180,7 +187,7 @@ class OstreeRestartCase(MachineCase): b.wait_present("table.listing-ct tbody:nth-child(2) div.listing-ct-actions button.enabled") # Serve repo - start_trivial_httpd(m) + server_pid = start_trivial_httpd(m) # Check for new commit b.click("table.listing-ct tbody:nth-child(2) div.listing-ct-actions button") @@ -225,14 +232,13 @@ class OstreeRestartCase(MachineCase): self.check_sig (b, "table.listing-ct tbody:nth-child(3)") # Force an error - pid = m.execute('ps -C ostree -o pid h') - m.execute('kill {0}'.format(pid)) + stop_trivial_httpd(m, server_pid) b.wait_not_present('table.listing-ct tbody:nth-child(3) div.listing-ct-error') b.click("table.listing-ct tbody:nth-child(3) div.listing-ct-actions button") b.wait_present("table.listing-ct tbody:nth-child(3) div.listing-ct-actions button.disabled") b.wait_present("table.listing-ct tbody:nth-child(3) div.listing-ct-actions button.enabled") b.wait_present('table.listing-ct tbody:nth-child(3) div.listing-ct-error') - start_trivial_httpd(m) + server_pid = start_trivial_httpd(m) # Apply update b.click("table.listing-ct tbody:nth-child(3) div.listing-ct-actions button")