From: David Shea dshea@redhat.com
I could have sworn that I tested this thing after blindly copying it from whatever I originally wrote it for, but the evidence suggests otherwise. --- tests/kickstart_tests/proxy-cmdline.ks | 9 +++++---- tests/kickstart_tests/proxy-kickstart.ks | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/tests/kickstart_tests/proxy-cmdline.ks b/tests/kickstart_tests/proxy-cmdline.ks index e64c03f..2fc17fe 100644 --- a/tests/kickstart_tests/proxy-cmdline.ks +++ b/tests/kickstart_tests/proxy-cmdline.ks @@ -3,8 +3,9 @@ %pre --erroronfail # Write the proxy script to a file in /tmp cat - << "EOF" > /tmp/proxy-test.py -from six.moves import SimpleHTTPServer, socketserver -from six.moves.urllib.request import urlopen +from http.server import SimpleHTTPRequestHandler +import socketserver +from urllib.request import urlopen import os, sys
import logging @@ -13,7 +14,7 @@ log_handler = logging.FileHandler('/tmp/proxy.log') log.setLevel(logging.INFO) log.addHandler(log_handler)
-class ProxyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class ProxyHandler(SimpleHTTPRequestHandler): def do_GET(self): # Log the path then proxy the request via urllib log.info(self.path) @@ -33,7 +34,7 @@ ProxyServer().serve_forever() EOF
# Run the server in the background and exit -python /tmp/proxy-test.py > /dev/null 2>&1 & +python3 /tmp/proxy-test.py > /dev/null 2>&1 & %end
url --url=http://dl.fedoraproject.org/pub/fedora/linux/development/$releasever/$basear... diff --git a/tests/kickstart_tests/proxy-kickstart.ks b/tests/kickstart_tests/proxy-kickstart.ks index accce49..ee067ec 100644 --- a/tests/kickstart_tests/proxy-kickstart.ks +++ b/tests/kickstart_tests/proxy-kickstart.ks @@ -3,8 +3,9 @@ %pre --erroronfail # Write the proxy script to a file in /tmp cat - << "EOF" > /tmp/proxy-test.py -from six.moves import SimpleHTTPServer, socketserver -from six.moves.urllib.request import urlopen +from http.server import SimpleHTTPRequestHandler +import socketserver +from urllib.request import urlopen import os, sys
import logging @@ -13,7 +14,7 @@ log_handler = logging.FileHandler('/tmp/proxy.log') log.setLevel(logging.INFO) log.addHandler(log_handler)
-class ProxyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class ProxyHandler(SimpleHTTPRequestHandler): def do_GET(self): # Log the path then proxy the request via urllib log.info(self.path) @@ -33,7 +34,7 @@ ProxyServer().serve_forever() EOF
# Run the server in the background and exit -python /tmp/proxy-test.py > /dev/null 2>&1 & +python3 /tmp/proxy-test.py > /dev/null 2>&1 & %end
url --url=http://dl.fedoraproject.org/pub/fedora/linux/development/$releasever/$basear... --proxy=127.0.0.1:8080
From: David Shea dshea@redhat.com
Cut two copies of the proxy server down to one copy and a couple of ksflattens. --- tests/kickstart_tests/proxy-cmdline.ks | 42 +++----------------------------- tests/kickstart_tests/proxy-cmdline.sh | 9 +++++++ tests/kickstart_tests/proxy-common.ks | 38 +++++++++++++++++++++++++++++ tests/kickstart_tests/proxy-kickstart.ks | 42 +++----------------------------- tests/kickstart_tests/proxy-kickstart.sh | 7 ++++-- 5 files changed, 58 insertions(+), 80 deletions(-) create mode 100644 tests/kickstart_tests/proxy-common.ks
diff --git a/tests/kickstart_tests/proxy-cmdline.ks b/tests/kickstart_tests/proxy-cmdline.ks index 2fc17fe..ecfa1d4 100644 --- a/tests/kickstart_tests/proxy-cmdline.ks +++ b/tests/kickstart_tests/proxy-cmdline.ks @@ -1,42 +1,3 @@ -# Start a super-simple proxy server on localhost -# A list of proxied requests will be saved to /tmp/proxy.log -%pre --erroronfail -# Write the proxy script to a file in /tmp -cat - << "EOF" > /tmp/proxy-test.py -from http.server import SimpleHTTPRequestHandler -import socketserver -from urllib.request import urlopen -import os, sys - -import logging -log = logging.getLogger("proxy_test") -log_handler = logging.FileHandler('/tmp/proxy.log') -log.setLevel(logging.INFO) -log.addHandler(log_handler) - -class ProxyHandler(SimpleHTTPRequestHandler): - def do_GET(self): - # Log the path then proxy the request via urllib - log.info(self.path) - data = urlopen(self.path).read() - self.send_response(200) - self.send_header('Content-Length', str(len(data))) - self.end_headers() - self.wfile.write(data) - -class ProxyServer(socketserver.TCPServer): - allow_reuse_address = True - - def __init__(self): - socketserver.TCPServer.__init__(self, ('', 8080), ProxyHandler) - -ProxyServer().serve_forever() -EOF - -# Run the server in the background and exit -python3 /tmp/proxy-test.py > /dev/null 2>&1 & -%end - url --url=http://dl.fedoraproject.org/pub/fedora/linux/development/$releasever/$basear... install network --bootproto=dhcp @@ -56,6 +17,9 @@ shutdown %packages %end
+# Run the proxy +%include proxy-common.ks + %post --nochroot # Look for the following as evidence that a proxy was used: # a .treeinfo request diff --git a/tests/kickstart_tests/proxy-cmdline.sh b/tests/kickstart_tests/proxy-cmdline.sh index 05f67f8..91e8625 100755 --- a/tests/kickstart_tests/proxy-cmdline.sh +++ b/tests/kickstart_tests/proxy-cmdline.sh @@ -22,3 +22,12 @@ kernel_args() { echo vnc inst.proxy=http://127.0.0.1:8080 } + +prepare() { + ks=$1 + tmpdir=$2 + + # Flatten the kickstart to include the proxy %pre script + ( cd "$(dirname ${ks})" && ksflatten -o ${tmpdir}/kickstart.ks -c "$(basename $ks)" ) + echo ${tmpdir}/kickstart.ks +} diff --git a/tests/kickstart_tests/proxy-common.ks b/tests/kickstart_tests/proxy-common.ks new file mode 100644 index 0000000..1234f72 --- /dev/null +++ b/tests/kickstart_tests/proxy-common.ks @@ -0,0 +1,38 @@ +# Start a super-simple proxy server on localhost +# A list of proxied requests will be saved to /tmp/proxy.log +%pre --erroronfail +# Write the proxy script to a file in /tmp +cat - << "EOF" > /tmp/proxy-test.py +from http.server import SimpleHTTPRequestHandler +import socketserver +from urllib.request import urlopen +import os, sys + +import logging +log = logging.getLogger("proxy_test") +log_handler = logging.FileHandler('/tmp/proxy.log') +log.setLevel(logging.INFO) +log.addHandler(log_handler) + +class ProxyHandler(SimpleHTTPRequestHandler): + def do_GET(self): + # Log the path then proxy the request via urllib + log.info(self.path) + data = urlopen(self.path).read() + self.send_response(200) + self.send_header('Content-Length', str(len(data))) + self.end_headers() + self.wfile.write(data) + +class ProxyServer(socketserver.TCPServer): + allow_reuse_address = True + + def __init__(self): + socketserver.TCPServer.__init__(self, ('', 8080), ProxyHandler) + +ProxyServer().serve_forever() +EOF + +# Run the server in the background and exit +python3 /tmp/proxy-test.py > /dev/null 2>&1 & +%end diff --git a/tests/kickstart_tests/proxy-kickstart.ks b/tests/kickstart_tests/proxy-kickstart.ks index ee067ec..6dce57e 100644 --- a/tests/kickstart_tests/proxy-kickstart.ks +++ b/tests/kickstart_tests/proxy-kickstart.ks @@ -1,42 +1,3 @@ -# Start a super-simple proxy server on localhost -# A list of proxied requests will be saved to /tmp/proxy.log -%pre --erroronfail -# Write the proxy script to a file in /tmp -cat - << "EOF" > /tmp/proxy-test.py -from http.server import SimpleHTTPRequestHandler -import socketserver -from urllib.request import urlopen -import os, sys - -import logging -log = logging.getLogger("proxy_test") -log_handler = logging.FileHandler('/tmp/proxy.log') -log.setLevel(logging.INFO) -log.addHandler(log_handler) - -class ProxyHandler(SimpleHTTPRequestHandler): - def do_GET(self): - # Log the path then proxy the request via urllib - log.info(self.path) - data = urlopen(self.path).read() - self.send_response(200) - self.send_header('Content-Length', str(len(data))) - self.end_headers() - self.wfile.write(data) - -class ProxyServer(socketserver.TCPServer): - allow_reuse_address = True - - def __init__(self): - socketserver.TCPServer.__init__(self, ('', 8080), ProxyHandler) - -ProxyServer().serve_forever() -EOF - -# Run the server in the background and exit -python3 /tmp/proxy-test.py > /dev/null 2>&1 & -%end - url --url=http://dl.fedoraproject.org/pub/fedora/linux/development/$releasever/$basear... --proxy=127.0.0.1:8080 repo --name=kstest-http --baseurl=HTTP-ADDON-REPO --proxy=127.0.0.1:8080 install @@ -57,6 +18,9 @@ shutdown %packages %end
+# Start the proxy server +%include proxy-common.ks + %post --nochroot # Look for the following as evidence that a proxy was used: # a .treeinfo request diff --git a/tests/kickstart_tests/proxy-kickstart.sh b/tests/kickstart_tests/proxy-kickstart.sh index df0f76b..fa15deb 100755 --- a/tests/kickstart_tests/proxy-kickstart.sh +++ b/tests/kickstart_tests/proxy-kickstart.sh @@ -28,6 +28,9 @@ prepare() { return 1. fi
- sed -e "/^repo/ s|HTTP-ADDON-REPO|${KSTEST_ADDON_HTTP_REPO}|" ${ks} > ${tmpdir}/kickstart.ks - echo ${tmpdir}/kickstart.ks + # Flatten the kickstart to include the proxy %pre script + ( cd "$(dirname ${ks})" && ksflatten -o ${tmpdir}/kickstart.ks -c "$(basename $ks)" ) + + sed -e "/^repo/ s|HTTP-ADDON-REPO|${KSTEST_ADDON_HTTP_REPO}|" ${tmpdir}/kickstart.ks > ${tmpdir}/kickstart-repo.ks + echo ${tmpdir}/kickstart-repo.ks }
These both look good to me.
Added label: ACK.
Closed.
Pushed.
anaconda-patches@lists.fedorahosted.org