Skip to content

Commit

Permalink
Use VM install repo URL on the installed system
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
  • Loading branch information
Jiri Jaburek committed May 9, 2019
1 parent e7fb422 commit 1e4fd20
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
27 changes: 24 additions & 3 deletions tests/install_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import os
import sys
import subprocess

def parse_args():
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -82,6 +83,23 @@ def parse_args():

return parser.parse_args()

def detect_url_os(url):
"""Given a repository URL, guess an OS type and version."""
cmd = ["osinfo-detect", "-f", "env", "-t", "tree", url]
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError as e:
if e.errno == os.errno.ENOENT:
return None
else:
raise

contents = proc.stdout.read().rstrip()
if not contents:
return None
pairs = map(lambda x: x.split('='), contents.splitlines())
osinfo = dict(pairs)
return osinfo['OSINFO_TREE']

def main():
data = parse_args()
Expand Down Expand Up @@ -125,9 +143,12 @@ def main():

tmp_kickstart = "/tmp/" + data.ks_basename
with open(data.kickstart) as infile, open(tmp_kickstart, "w") as outfile:
old_content = infile.read()
new_content = old_content.replace("&&HOST_PUBLIC_KEY&&", pub_key)
outfile.write(new_content)
content = infile.read()
content = content.replace("&&HOST_PUBLIC_KEY&&", pub_key)
ostype = detect_url_os(data.url)
if any(filter(lambda x: x in ostype, ['centos.org', 'redhat.com'])):
content = content.replace("&&YUM_REPO_URL&&", data.url)
outfile.write(content)
data.kickstart = tmp_kickstart
print("Using kickstart file: {0}".format(data.kickstart))

Expand Down
11 changes: 11 additions & 0 deletions tests/kickstarts/test_suite.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ printf "%s\n" "&&HOST_PUBLIC_KEY&&" >> /root/.ssh/authorized_keys
chmod og-rw /root/.ssh /root/.ssh/authorized_keys
systemctl enable sshd

# create yum/dnf repository from URL if replaced by install_vm.py
if ! [[ '&&YUM_REPO_URL&&' =~ YUM_REPO_URL ]]; then
cat > /etc/yum.repos.d/inst-ks.repo <<EOF
[inst-ks]
name=Installation repo from kickstart
baseurl=&&YUM_REPO_URL&&
enabled=1
gpgcheck=0
EOF
fi

%end

# Reboot after the installation is complete (optional)
Expand Down

0 comments on commit 1e4fd20

Please sign in to comment.