Skip to content

Commit

Permalink
test: Stop using ostree trivial-httpd
Browse files Browse the repository at this point in the history
trivial-httpd will be depreciated.

Related: ostreedev/ostree#636
  • Loading branch information
petervo committed Jan 5, 2017
1 parent 808eab3 commit 4ce3c6d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
62 changes: 38 additions & 24 deletions test/images/scripts/lib/atomic.install
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import urllib
import argparse
import datetime
import json
import re

BASEDIR = os.path.dirname(__file__)

Expand All @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 13 additions & 7 deletions test/verify/check-ostree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 4ce3c6d

Please sign in to comment.