Skip to content

Commit

Permalink
Move the proxy server script into a common file.
Browse files Browse the repository at this point in the history
Cut two copies of the proxy server down to one copy and a couple of
ksflattens.
  • Loading branch information
dashea committed Jul 30, 2015
1 parent fe04864 commit cfe12c5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 80 deletions.
42 changes: 3 additions & 39 deletions 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/$basearch/os/
install
network --bootproto=dhcp
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/kickstart_tests/proxy-cmdline.sh
Expand Up @@ -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
}
38 changes: 38 additions & 0 deletions 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
42 changes: 3 additions & 39 deletions 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/$basearch/os/ --proxy=127.0.0.1:8080
repo --name=kstest-http --baseurl=HTTP-ADDON-REPO --proxy=127.0.0.1:8080
install
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tests/kickstart_tests/proxy-kickstart.sh
Expand Up @@ -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
}

0 comments on commit cfe12c5

Please sign in to comment.