summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Callaghan <dcallagh@redhat.com>2014-06-20 13:21:32 +1000
committerGerrit Code Review <gerrit@beaker-project.org>2014-06-24 02:13:24 +0000
commit358cc8420199603c84b6376aa1888f2d81deca4d (patch)
treebc044ee5f6f6a62688f1d089c62ddadfd49b0ab9
parent42f3dd36ee7c7f0a4cf5fc832ba303d4b1477ace (diff)
tests for beaker-pxemenu
-rw-r--r--IntegrationTests/src/bkr/inttest/labcontroller/__init__.py14
-rw-r--r--IntegrationTests/src/bkr/inttest/labcontroller/test_pxemenu.py93
-rw-r--r--LabController/src/bkr/labcontroller/pxemenu.py60
-rw-r--r--Server/bkr/server/tests/data_setup.py19
4 files changed, 140 insertions, 46 deletions
diff --git a/IntegrationTests/src/bkr/inttest/labcontroller/__init__.py b/IntegrationTests/src/bkr/inttest/labcontroller/__init__.py
index 7cd30d3..e8fef62 100644
--- a/IntegrationTests/src/bkr/inttest/labcontroller/__init__.py
+++ b/IntegrationTests/src/bkr/inttest/labcontroller/__init__.py
@@ -34,16 +34,20 @@ def daemons_running_externally():
class LabControllerTestCase(unittest.TestCase):
- def get_lc_fqdn(self):
+ @staticmethod
+ def get_lc_fqdn():
return lc_fqdn
- def get_lc(self):
- return LabController.by_name(self.get_lc_fqdn())
+ @staticmethod
+ def get_lc():
+ return LabController.by_name(lc_fqdn)
- def get_proxy_url(self):
+ @staticmethod
+ def get_proxy_url():
return 'http://%s:8000/' % lc_fqdn
- def get_log_base_url(self):
+ @staticmethod
+ def get_log_base_url():
protocol = get_conf().get('URL_SCHEME', 'http')
server_name = get_conf().get_url_domain()
return '%s://%s' % (protocol, server_name)
diff --git a/IntegrationTests/src/bkr/inttest/labcontroller/test_pxemenu.py b/IntegrationTests/src/bkr/inttest/labcontroller/test_pxemenu.py
new file mode 100644
index 0000000..2187259
--- /dev/null
+++ b/IntegrationTests/src/bkr/inttest/labcontroller/test_pxemenu.py
@@ -0,0 +1,93 @@
+
+import sys
+import os
+import pkg_resources
+import tempfile
+import shutil
+from bkr.server.model import session
+from bkr.server.tests import data_setup
+from bkr.inttest import Process
+from bkr.inttest.labcontroller import LabControllerTestCase
+from bkr.labcontroller.pxemenu import write_menus
+
+class PxemenuTest(LabControllerTestCase):
+
+ maxDiff = None
+
+ @classmethod
+ def setupClass(cls):
+ # Need to populate a directory with fake images, and serve it over
+ # HTTP, so that beaker-pxemenu can download the images when it builds
+ # the menus.
+ cls.distro_dir = tempfile.mkdtemp()
+ os.mkdir(os.path.join(cls.distro_dir, 'pxeboot'))
+ open(os.path.join(cls.distro_dir, 'pxeboot/vmlinuz'), 'w').write('lol')
+ open(os.path.join(cls.distro_dir, 'pxeboot/initrd'), 'w').write('lol')
+ cls.distro_server = Process('http_server.py', args=[sys.executable,
+ pkg_resources.resource_filename('bkr.inttest', 'http_server.py')],
+ listen_port=19998, exec_dir=cls.distro_dir)
+ cls.distro_server.start()
+ cls.tftp_dir = tempfile.mkdtemp()
+
+ @classmethod
+ def teardownClass(cls):
+ shutil.rmtree(cls.distro_dir, ignore_errors=True)
+ shutil.rmtree(cls.tftp_dir, ignore_errors=True)
+ cls.distro_server.stop()
+
+ def test_pxelinux_menu(self):
+ with session.begin():
+ lc = self.get_lc()
+ tag = u'test_pxelinux_menu'
+ distro_tree = data_setup.create_distro_tree(
+ osmajor=u'PinkUshankaLinux8', osminor=u'1',
+ distro_name=u'PinkUshankaLinux8.1', distro_tags=[tag],
+ arch=u'x86_64', lab_controllers=[lc],
+ urls=['http://localhost:19998/'])
+ write_menus(self.tftp_dir, tags=[tag], xml_filter=None)
+ menu = open(os.path.join(self.tftp_dir, 'pxelinux.cfg', 'beaker_menu')).read()
+ self.assertEquals(menu, '''\
+default menu
+prompt 0
+timeout 6000
+ontimeout local
+menu title Beaker
+label local
+ menu label (local)
+ menu default
+ localboot 0
+
+menu begin
+menu title PinkUshankaLinux8
+
+menu begin
+menu title PinkUshankaLinux8.1
+
+label PinkUshankaLinux8.1-Server-x86_64
+ menu title PinkUshankaLinux8.1 Server x86_64
+ kernel /distrotrees/{0}/kernel
+ append initrd=/distrotrees/{0}/initrd method=http://localhost:19998/ repo=http://localhost:19998/
+
+menu end
+
+menu end
+'''.format(distro_tree.id))
+
+ def test_efigrub_menu(self):
+ with session.begin():
+ lc = self.get_lc()
+ tag = u'test_efigrub_menu'
+ distro_tree = data_setup.create_distro_tree(
+ osmajor=u'PinkUshankaLinux8', osminor=u'1',
+ distro_name=u'PinkUshankaLinux8.1', distro_tags=[tag],
+ arch=u'x86_64', lab_controllers=[lc],
+ urls=['http://localhost:19998/'])
+ write_menus(self.tftp_dir, tags=[tag], xml_filter=None)
+ menu = open(os.path.join(self.tftp_dir, 'grub', 'efidefault')).read()
+ self.assertEquals(menu, '''\
+
+title PinkUshankaLinux8.1 Server x86_64
+ root (nd)
+ kernel /distrotrees/{0}/kernel method=http://localhost:19998/ repo=http://localhost:19998/
+ initrd /distrotrees/{0}/initrd
+'''.format(distro_tree.id))
diff --git a/LabController/src/bkr/labcontroller/pxemenu.py b/LabController/src/bkr/labcontroller/pxemenu.py
index 34cddd4..c303b05 100644
--- a/LabController/src/bkr/labcontroller/pxemenu.py
+++ b/LabController/src/bkr/labcontroller/pxemenu.py
@@ -61,32 +61,14 @@ title ${distro_name} ${variant} ${arch}
initrd /distrotrees/${distro_tree_id}/initrd
''')
-def main():
- parser = OptionParser(description='''Writes a netboot menu to the TFTP root
-directory, containing distros from Beaker. Supports menu.c32 from SYSLINUX
-(for PXE systems) and the EFI GRUB boot menu (for EFI systems).''')
- parser.add_option('--tag', metavar='TAG', action='append', dest='tags',
- help='Only include distros tagged with TAG')
- parser.add_option('--xml-filter', metavar='XML',
- help='Only include distro trees which match the given '
- 'XML filter criteria, as in <distroRequires/>')
- parser.add_option('--tftp-root', metavar='DIR',
- default='/var/lib/tftpboot',
- help='Path to TFTP root directory [default: %default]')
- parser.add_option('-q', '--quiet', action='store_true',
- help='Suppress informational output')
- (opts, args) = parser.parse_args()
-
- if opts.quiet:
- os.dup2(os.open('/dev/null', os.O_WRONLY), 1)
-
+def write_menus(tftp_root, tags, xml_filter):
# The order of steps for cleaning images is important,
# to avoid races and to avoid deleting stuff we shouldn't:
# first read the directory,
# then fetch the list of trees,
# and then remove any which aren't in the list.
try:
- existing_tree_ids = os.listdir(os.path.join(opts.tftp_root, 'distrotrees'))
+ existing_tree_ids = os.listdir(os.path.join(tftp_root, 'distrotrees'))
except OSError, e:
if e.errno != errno.ENOENT:
raise
@@ -95,23 +77,23 @@ directory, containing distros from Beaker. Supports menu.c32 from SYSLINUX
proxy = xmlrpclib.ServerProxy('http://localhost:8000', allow_none=True)
distrotrees = proxy.get_distro_trees({
'arch': ['x86_64', 'i386'],
- 'tags': opts.tags,
- 'xml': opts.xml_filter,
+ 'tags': tags,
+ 'xml': xml_filter,
})
obsolete_tree_ids = set(existing_tree_ids).difference(
str(dt['distro_tree_id']) for dt in distrotrees)
print 'Removing images for %s obsolete distro trees' % len(obsolete_tree_ids)
for obs in obsolete_tree_ids:
- shutil.rmtree(os.path.join(opts.tftp_root, 'distrotrees', obs), ignore_errors=True)
+ shutil.rmtree(os.path.join(tftp_root, 'distrotrees', obs), ignore_errors=True)
print 'Generating menu for %s distro trees' % len(distrotrees)
osmajors = _group_distro_trees(distrotrees)
- makedirs_ignore(os.path.join(opts.tftp_root, 'pxelinux.cfg'), mode=0755)
- pxe_menu = atomically_replaced_file(os.path.join(opts.tftp_root, 'pxelinux.cfg', 'beaker_menu'))
- makedirs_ignore(os.path.join(opts.tftp_root, 'grub'), mode=0755)
- atomic_symlink('../distrotrees', os.path.join(opts.tftp_root, 'grub', 'distrotrees'))
- efi_menu = atomically_replaced_file(os.path.join(opts.tftp_root, 'grub', 'efidefault'))
+ makedirs_ignore(os.path.join(tftp_root, 'pxelinux.cfg'), mode=0755)
+ pxe_menu = atomically_replaced_file(os.path.join(tftp_root, 'pxelinux.cfg', 'beaker_menu'))
+ makedirs_ignore(os.path.join(tftp_root, 'grub'), mode=0755)
+ atomic_symlink('../distrotrees', os.path.join(tftp_root, 'grub', 'distrotrees'))
+ efi_menu = atomically_replaced_file(os.path.join(tftp_root, 'grub', 'efidefault'))
with contextlib.nested(pxe_menu, efi_menu) as (pxe_menu, efi_menu):
pxe_menu.write('''default menu
prompt 0
@@ -139,7 +121,7 @@ menu title %s
for distro_tree in distro_trees:
url = _get_url(distro_tree['available'])
try:
- _get_images(opts.tftp_root, distro_tree['distro_tree_id'],
+ _get_images(tftp_root, distro_tree['distro_tree_id'],
url, distro_tree['images'])
except IOError, e:
sys.stderr.write('Error fetching images for distro tree %s: %s\n' %
@@ -156,6 +138,26 @@ menu end
pxe_menu.write('''
menu end
''')
+
+def main():
+ parser = OptionParser(description='''Writes a netboot menu to the TFTP root
+directory, containing distros from Beaker.''')
+ parser.add_option('--tag', metavar='TAG', action='append', dest='tags',
+ help='Only include distros tagged with TAG')
+ parser.add_option('--xml-filter', metavar='XML',
+ help='Only include distro trees which match the given '
+ 'XML filter criteria, as in <distroRequires/>')
+ parser.add_option('--tftp-root', metavar='DIR',
+ default='/var/lib/tftpboot',
+ help='Path to TFTP root directory [default: %default]')
+ parser.add_option('-q', '--quiet', action='store_true',
+ help='Suppress informational output')
+ (opts, args) = parser.parse_args()
+ if args:
+ parser.error('This command does not accept any arguments')
+ if opts.quiet:
+ os.dup2(os.open('/dev/null', os.O_WRONLY), 1)
+ write_menus(opts.tftp_root, opts.tags, opts.xml_filter)
return 0
if __name__ == '__main__':
diff --git a/Server/bkr/server/tests/data_setup.py b/Server/bkr/server/tests/data_setup.py
index ac9ec64..fd121f7 100644
--- a/Server/bkr/server/tests/data_setup.py
+++ b/Server/bkr/server/tests/data_setup.py
@@ -175,8 +175,8 @@ def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
if not name:
name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
distro = Distro.lazy_create(name=name, osversion=osversion)
- if tags:
- distro.tags.extend(tags)
+ for tag in (tags or []):
+ distro.add_tag(tag)
log.debug('Created distro %r', distro)
harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
if not os.path.exists(harness_dir):
@@ -184,18 +184,13 @@ def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
return distro
def create_distro_tree(distro=None, distro_name=None, osmajor=u'DansAwesomeLinux6',
- distro_tags=None, arch=u'i386', variant=u'Server', lab_controllers=None,
- urls=None):
+ osminor=u'9', distro_tags=None, arch=u'i386', variant=u'Server',
+ lab_controllers=None, urls=None):
if distro is None:
- if distro_name is None:
- distro = create_distro(osmajor=osmajor, tags=distro_tags)
- else:
- try:
- distro = Distro.by_name(distro_name)
- except DatabaseLookupError:
- distro = create_distro(name=distro_name)
+ distro = create_distro(name=distro_name, osmajor=osmajor, osminor=osminor,
+ tags=distro_tags)
distro_tree = DistroTree.lazy_create(distro=distro,
- arch=Arch.by_name(arch), variant=variant)
+ arch=Arch.lazy_create(arch=arch), variant=variant)
if distro_tree.arch not in distro.osversion.arches:
distro.osversion.arches.append(distro_tree.arch)
DistroTreeRepo.lazy_create(distro_tree=distro_tree,