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-20140620.1', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=[u'http://localhost:19998/']) # https://bugzilla.redhat.com/show_bug.cgi?id=1420471 # i386 and RHEL3-5 should be filtered out ignored_combos = [ (u'PinkUshankaLinux8', u'1', u'i386'), (u'RedHatEnterpriseLinux3', u'9', u'x86_64'), (u'RedHatEnterpriseLinux4', u'9', u'x86_64'), (u'RedHatEnterpriseLinuxServer5', u'10', u'x86_64'), ] for osmajor, osminor, arch in ignored_combos: data_setup.create_distro_tree(osmajor=osmajor, osminor=osminor, arch=arch, distro_tags=[tag], 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-20140620.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))
def test_update_harness_repos(self): """Test that the update_repo() call runs as expected. This checks that the harness repos that are supposed to be synced are actually synced. Does not check repo metadata. """ if 'sqlite' in get_engine().name: raise unittest.SkipTest('SQL generated by lazy_create is not valid' ' in sqlite') base_path = mkdtemp() self.addCleanup(rmtree, base_path) faux_remote_harness1 = self._create_remote_harness(base_path, 'foobangmajor') faux_remote_harness2 = self._create_remote_harness(base_path, 'foobazmajor') faux_local_harness = mkdtemp('local_harness') self.addCleanup(rmtree, faux_local_harness) with session.begin(): lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=u'foobangmajor'), harness_dir=False, lab_controllers=[lab_controller]) distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=u'foobazmajor'), harness_dir=False, lab_controllers=[lab_controller]) # I'm not testing the config here, so just use createrepo update_repos('file://%s/' % base_path, faux_local_harness) self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobangmajor'))) self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobazmajor')))
def test_update_harness_repos(self): """Test that the update_repo() call runs as expected. This checks that the harness repos that are supposed to be synced are actually synced. Does not check repo metadata. """ self._create_remote_harness('foobangmajor') self._create_remote_harness('foobazmajor') faux_local_harness = tempfile.mkdtemp('local_harness') self.addCleanup(shutil.rmtree, faux_local_harness) with session.begin(): lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=u'foobangmajor'), harness_dir=False, lab_controllers=[lab_controller]) distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=u'foobazmajor'), harness_dir=False, lab_controllers=[lab_controller]) run_command('repo_update.py', 'beaker-repo-update', ['-b', self.harness_repo_url, '-d', faux_local_harness], ignore_stderr=True) self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobangmajor'))) self.assertTrue(os.path.exists(os.path.join(faux_local_harness, 'foobazmajor')))
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-20140620.1', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=['http://localhost:19998/']) # https://bugzilla.redhat.com/show_bug.cgi?id=1420471 # i386 and RHEL3-5 should be filtered out ignored_combos = [ (u'PinkUshankaLinux8', u'1', u'i386'), (u'RedHatEnterpriseLinux3', u'9', u'x86_64'), (u'RedHatEnterpriseLinux4', u'9', u'x86_64'), (u'RedHatEnterpriseLinuxServer5', u'10', u'x86_64'), ] for osmajor, osminor, arch in ignored_combos: data_setup.create_distro_tree(osmajor=osmajor, osminor=osminor, arch=arch, distro_tags=[tag], 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-20140620.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))
def test_replaces_bad_packages(self): osmajor = u'MauveBeanieLinux3' package = 'tmp-distribution-beaker-task_test-2.0-5.noarch.rpm' with session.begin(): data_setup.create_distro_tree(osmajor=osmajor) self._create_remote_harness(osmajor) local_harness_dir = tempfile.mkdtemp(suffix='local') self.addCleanup(shutil.rmtree, local_harness_dir) # Local harness dir has a corrupted copy of the package os.mkdir(os.path.join(local_harness_dir, osmajor)) orig_size = os.path.getsize( os.path.join(self.harness_repo_dir, osmajor, package)) with open(os.path.join(local_harness_dir, osmajor, package), 'wb') as f: f.write(b'a' * orig_size) run_command( 'repo_update.py', 'beaker-repo-update', ['--debug', '-b', self.harness_repo_url, '-d', local_harness_dir], ignore_stderr=True) self.assertEquals( open(os.path.join(self.harness_repo_dir, osmajor, package), 'rb').read(), open(os.path.join(local_harness_dir, osmajor, package), 'rb').read())
def test_grub2_menu_for_efi(self): with session.begin(): lc = self.get_lc() tag = u'test_grub2_menu_for_efi' 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, 'boot', 'grub2', 'beaker_menu_x86.cfg')).read() self.assertEquals(menu, '''\ set default="Exit PXE" set timeout=60 menuentry "Exit PXE" { exit } submenu "PinkUshankaLinux8" { submenu "PinkUshankaLinux8.1" { menuentry "PinkUshankaLinux8.1 Server x86_64" { linux /distrotrees/%s/kernel method=http://localhost:19998/ repo=http://localhost:19998/ initrd /distrotrees/%s/initrd } } } ''' % (distro_tree.id, distro_tree.id))
def test_grub2_menu_for_efi(self): with session.begin(): lc = self.get_lc() tag = u'test_grub2_menu_for_efi' distro_tree = data_setup.create_distro_tree( osmajor=u'PinkUshankaLinux8', osminor=u'1', distro_name=u'PinkUshankaLinux8.1-20140620.3', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=[u'http://localhost:19998/']) write_menus(self.tftp_dir, tags=[tag], xml_filter=None) menu = open(os.path.join(self.tftp_dir, 'boot', 'grub2', 'beaker_menu_x86.cfg')).read() self.assertEquals(menu, '''\ set default="Exit PXE" set timeout=60 menuentry "Exit PXE" { exit } submenu "PinkUshankaLinux8" { submenu "PinkUshankaLinux8.1" { menuentry "PinkUshankaLinux8.1-20140620.3 Server x86_64" { linux /distrotrees/%s/kernel method=http://localhost:19998/ repo=http://localhost:19998/ initrd /distrotrees/%s/initrd } } } ''' % (distro_tree.id, distro_tree.id))
def test_does_not_run_createrepo_unnecessarily(self): if 'sqlite' in get_engine().name: raise unittest.SkipTest('SQL generated by lazy_create is not valid' ' in sqlite') osmajor = u'GreenBeretLinux99' with session.begin(): lab_controller = data_setup.create_labcontroller( fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=osmajor), harness_dir=False, lab_controllers=[lab_controller]) remote_harness_dir = mkdtemp(suffix='remote') self.addCleanup(rmtree, remote_harness_dir) local_harness_dir = mkdtemp(suffix='local') self.addCleanup(rmtree, local_harness_dir) self._create_remote_harness(remote_harness_dir, osmajor) # run it once, repo is built update_repos('file://%s/' % remote_harness_dir, local_harness_dir) repodata_dir = os.path.join(local_harness_dir, osmajor, 'repodata') mtime = os.path.getmtime(repodata_dir) # run it again, repo should not be rebuilt time.sleep(0.001) update_repos('file://%s/' % remote_harness_dir, local_harness_dir) self.assertEquals(os.path.getmtime(repodata_dir), mtime)
def test_exclude_nonexistent_osmajor(self): with session.begin(): osmajor = OSMajor.lazy_create(osmajor="exist") lab_controller = data_setup.create_labcontroller( fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=osmajor.osmajor, harness_dir=False, lab_controllers=[lab_controller]) nonexistent_osmajor = OSMajor.lazy_create(osmajor=u'notexist') remote_harness_dir = tempfile.mkdtemp(suffix='remote') self.addCleanup(shutil.rmtree, remote_harness_dir) local_harness_dir = tempfile.mkdtemp(suffix='local') self.addCleanup(shutil.rmtree, local_harness_dir) self._create_remote_harness(remote_harness_dir, osmajor.osmajor) run_command( 'repo_update.py', 'beaker-repo-update', ['-b', 'file://%s/' % remote_harness_dir, '-d', local_harness_dir], ignore_stderr=True) self.assertTrue( os.path.exists(os.path.join(local_harness_dir, osmajor.osmajor))) self.assertFalse( os.path.exists( os.path.join(local_harness_dir, nonexistent_osmajor.osmajor)))
def test_does_not_run_createrepo_unnecessarily(self): osmajor = u'GreenBeretLinux99' with session.begin(): lab_controller = data_setup.create_labcontroller( fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=osmajor), harness_dir=False, lab_controllers=[lab_controller]) remote_harness_dir = tempfile.mkdtemp(suffix='remote') self.addCleanup(shutil.rmtree, remote_harness_dir) local_harness_dir = tempfile.mkdtemp(suffix='local') self.addCleanup(shutil.rmtree, local_harness_dir) self._create_remote_harness(remote_harness_dir, osmajor) # run it once, repo is built run_command( 'repo_update.py', 'beaker-repo-update', ['-b', 'file://%s/' % remote_harness_dir, '-d', local_harness_dir], ignore_stderr=True) repodata_dir = os.path.join(local_harness_dir, osmajor, 'repodata') mtime = os.path.getmtime(repodata_dir) # run it again, repo should not be rebuilt time.sleep(0.001) run_command( 'repo_update.py', 'beaker-repo-update', ['-b', 'file://%s/' % remote_harness_dir, '-d', local_harness_dir], ignore_stderr=True) self.assertEquals(os.path.getmtime(repodata_dir), mtime)
def test_ipxe_menu(self): with session.begin(): lc = self.get_lc() tag = u'test_ipxe_menu' distro_tree = data_setup.create_distro_tree( osmajor=u'PinkUshankaLinux8', osminor=u'1', distro_name=u'PinkUshankaLinux8.1-20140620.42', 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, 'ipxe', 'beaker_menu')).read() self.assertEquals( menu, '''\ #!ipxe chain /ipxe/${ip:hexraw} || :main_menu menu Beaker item local (local) item PinkUshankaLinux8 PinkUshankaLinux8 -> choose --default local --timeout 600000 target && goto ${target} || goto local :local echo Booting local disk... iseq ${builtin/platform} pcbios && sanboot --no-describe --drive 0x80 || # exit 1 generates an error message but req'd for some systems to fall through exit 1 || goto main_menu :PinkUshankaLinux8 menu PinkUshankaLinux8 item PinkUshankaLinux8.1 PinkUshankaLinux8.1 -> item main_menu back <- choose target && goto ${target} || goto main_menu :PinkUshankaLinux8.1 menu PinkUshankaLinux8.1 item PinkUshankaLinux8.1-20140620.42-Server-x86_64 PinkUshankaLinux8.1-20140620.42 Server x86_64 item PinkUshankaLinux8 back <- choose target && goto ${target} || goto PinkUshankaLinux8 :PinkUshankaLinux8.1-20140620.42-Server-x86_64 set options kernel initrd=initrd method=http://localhost:19998/ repo=http://localhost:19998/ echo Kernel command line: ${options} prompt --timeout 5000 Press any key for additional options... && set opts 1 || clear opts isset ${opts} && echo -n Additional options: ${} || isset ${opts} && read useropts || kernel /distrotrees/%s/kernel || goto PinkUshankaLinux8.1 initrd /distrotrees/%s/initrd || goto PinkUshankaLinux8.1 imgargs ${options} ${useropts} boot || goto PinkUshankaLinux8.1 ''' % (distro_tree.id, distro_tree.id))
def setUp(self): # We need at least one working tree to exist in every test, # otherwise beaker-expire-distros will just bail out and refuse # to do anything as a safety feature. with session.begin(): self.lc = self.get_lc() self.distro_tree = data_setup.create_distro_tree( osmajor=u'MattAwesomelinux9', osminor=u'1', arch=u'x86_64', lab_controllers=[self.lc], urls=['http://localhost:19998/fakedistros/MattAwesomelinux9'])
def setUp(self): # We need at least one working tree to exist in every test, # otherwise beaker-expire-distros will just bail out and refuse # to do anything as a safety feature. with session.begin(): self.lc = self.get_lc() self.distro_tree = data_setup.create_distro_tree( osmajor=u'MattAwesomelinux9', osminor=u'1', distro_name=u'MattAwesomelinux9.1', arch=u'x86_64', lab_controllers=[self.lc], urls=['http://localhost:19998/fakedistros/MattAwesomelinux9'])
def test_404(self): with session.begin(): distro_tree = data_setup.create_distro_tree( lab_controllers=[self.lc], urls=['http://localhost:19998/error/404']) check_all_trees(ignore_errors=True) with session.begin(): session.expire_all() # The distro tree should be expired. self.assertFalse(any(dla.lab_controller == self.lc for dla in distro_tree.lab_controller_assocs))
def test_distro_tree_with_bad_url_throws_relevant_error(self): with session.begin(): lc = self.get_lc() tag = u'test_bad_url' distro_tree = data_setup.create_distro_tree( osmajor=u'SuperBadWindows10', osminor=u'1', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=[u'barf://localhost:19998/error/404']) with self.assertRaises(ValueError) as exc: write_menus(self.tftp_dir, tags=[tag], xml_filter=None) self.assertIn('Unrecognised URL scheme found in distro tree URL(s)', exc.exception.message)
def test_distro_tree_with_bad_url_throws_relevant_error(self): with session.begin(): lc = self.get_lc() tag = u'test_bad_url' distro_tree = data_setup.create_distro_tree( osmajor=u'SuperBadWindows10', osminor=u'1', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=['barf://localhost:19998/error/404']) with self.assertRaises(ValueError) as exc: write_menus(self.tftp_dir, tags=[tag], xml_filter=None) self.assertIn('Unrecognised URL scheme found in distro tree URL(s)', exc.exception.message)
def test_skip_distro_tree_for_which_image_cannot_be_fetched(self): with session.begin(): lc = self.get_lc() tag = u'test_image_not_found' distro_tree = data_setup.create_distro_tree( osmajor=u'SuperBadWindows10', osminor=u'1', distro_name=u'SuperBadWindows10.1', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=['http://localhost:19998/error/404']) write_menus(self.tftp_dir, tags=[tag], xml_filter=None) menu = open(os.path.join(self.tftp_dir, 'pxelinux.cfg', 'beaker_menu')).read() self.assertNotIn('menu title SuperBadWindows10', menu)
def test_skip_distro_tree_for_which_image_cannot_be_fetched(self): with session.begin(): lc = self.get_lc() tag = u'test_image_not_found' distro_tree = data_setup.create_distro_tree( osmajor=u'SuperBadWindows10', osminor=u'1', distro_tags=[tag], arch=u'x86_64', lab_controllers=[lc], urls=[u'http://localhost:19998/error/404']) write_menus(self.tftp_dir, tags=[tag], xml_filter=None) menu = open(os.path.join(self.tftp_dir, 'pxelinux.cfg', 'beaker_menu')).read() self.assertNotIn('menu title SuperBadWindows10', menu)
def test_500(self): with session.begin(): lc = self.get_lc() distro_tree = data_setup.create_distro_tree( lab_controllers=[lc], urls=[u'http://localhost:19998/error/500']) check_all_trees(ignore_errors=True) with session.begin(): session.expire_all() # The distro tree should not be expired. self.assertTrue( any(dla.lab_controller == self.lc for dla in distro_tree.lab_controller_assocs))
def test_update_harness_repos(self): """Test that the update_repo() call runs as expected. This checks that the harness repos that are supposed to be synced are actually synced. Does not check repo metadata. """ if 'sqlite' in get_engine().name: raise unittest.SkipTest('SQL generated by lazy_create is not valid' ' in sqlite') base_path = mkdtemp() self.addCleanup(rmtree, base_path) faux_remote_harness1 = self._create_remote_harness( base_path, 'foobangmajor') faux_remote_harness2 = self._create_remote_harness( base_path, 'foobazmajor') faux_local_harness = mkdtemp('local_harness') self.addCleanup(rmtree, faux_local_harness) with session.begin(): lab_controller = data_setup.create_labcontroller( fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=u'foobangmajor'), harness_dir=False, lab_controllers=[lab_controller]) distro_tree = data_setup.create_distro_tree( osmajor=OSMajor.lazy_create(osmajor=u'foobazmajor'), harness_dir=False, lab_controllers=[lab_controller]) # I'm not testing the config here, so just use createrepo update_repos('file://%s/' % base_path, faux_local_harness) self.assertTrue( os.path.exists(os.path.join(faux_local_harness, 'foobangmajor'))) self.assertTrue( os.path.exists(os.path.join(faux_local_harness, 'foobazmajor')))
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))
def test_exclude_nonexistent_osmajor(self): if 'sqlite' in get_engine().name: raise unittest.SkipTest('SQL generated by lazy_create is not valid' ' in sqlite') with session.begin(): osmajor = OSMajor.lazy_create(osmajor="exist") lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree(osmajor=osmajor.osmajor, harness_dir=False, lab_controllers=[lab_controller]) nonexistent_osmajor = OSMajor.lazy_create(osmajor=u'notexist') remote_harness_dir = mkdtemp(suffix='remote') self.addCleanup(rmtree, remote_harness_dir) local_harness_dir = mkdtemp(suffix='local') self.addCleanup(rmtree, local_harness_dir) self._create_remote_harness(remote_harness_dir, osmajor.osmajor) update_repos('file://%s/' % remote_harness_dir, local_harness_dir) self.assertTrue(os.path.exists(os.path.join(local_harness_dir, osmajor.osmajor))) self.assertFalse(os.path.exists(os.path.join(local_harness_dir, nonexistent_osmajor.osmajor)))
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))
def test_does_not_run_createrepo_unnecessarily(self): if 'sqlite' in get_engine().name: raise unittest.SkipTest('SQL generated by lazy_create is not valid' ' in sqlite') osmajor = u'GreenBeretLinux99' with session.begin(): lab_controller = data_setup.create_labcontroller(fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree(osmajor=OSMajor.lazy_create(osmajor=osmajor), harness_dir=False, lab_controllers=[lab_controller]) remote_harness_dir = mkdtemp(suffix='remote') self.addCleanup(rmtree, remote_harness_dir) local_harness_dir = mkdtemp(suffix='local') self.addCleanup(rmtree, local_harness_dir) self._create_remote_harness(remote_harness_dir, osmajor) # run it once, repo is built update_repos('file://%s/' % remote_harness_dir, local_harness_dir) repodata_dir = os.path.join(local_harness_dir, osmajor, 'repodata') mtime = os.path.getmtime(repodata_dir) # run it again, repo should not be rebuilt time.sleep(0.001) update_repos('file://%s/' % remote_harness_dir, local_harness_dir) self.assertEquals(os.path.getmtime(repodata_dir), mtime)
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_exclude_nonexistent_osmajor(self): if 'sqlite' in get_engine().name: raise unittest.SkipTest('SQL generated by lazy_create is not valid' ' in sqlite') with session.begin(): osmajor = OSMajor.lazy_create(osmajor="exist") lab_controller = data_setup.create_labcontroller( fqdn=u'dummylab.example.invalid') distro_tree = data_setup.create_distro_tree( osmajor=osmajor.osmajor, harness_dir=False, lab_controllers=[lab_controller]) nonexistent_osmajor = OSMajor.lazy_create(osmajor=u'notexist') remote_harness_dir = mkdtemp(suffix='remote') self.addCleanup(rmtree, remote_harness_dir) local_harness_dir = mkdtemp(suffix='local') self.addCleanup(rmtree, local_harness_dir) self._create_remote_harness(remote_harness_dir, osmajor.osmajor) update_repos('file://%s/' % remote_harness_dir, local_harness_dir) self.assertTrue( os.path.exists(os.path.join(local_harness_dir, osmajor.osmajor))) self.assertFalse( os.path.exists( os.path.join(local_harness_dir, nonexistent_osmajor.osmajor)))
def setup_package(): assert os.path.exists( CONFIG_FILE), 'Config file %s must exist' % CONFIG_FILE load_config(configfile=CONFIG_FILE) log_to_stream(sys.stdout, level=logging.DEBUG) from bkr.inttest import data_setup if not 'BEAKER_SKIP_INIT_DB' in os.environ: data_setup.setup_model() with session.begin(): # Fill in the bare minimum data which Beaker assumes will always be present. # Note that this can be called multiple times (for example, the # beaker-server-redhat add-on package reuses this setup function). if not LabController.query.count(): data_setup.create_labcontroller() if not Task.query.count(): data_setup.create_task( name=u'/distribution/install', requires=u'make gcc nfs-utils wget procmail redhat-lsb ntp ' u'@development-tools @development-libs @development ' u'@desktop-platform-devel @server-platform-devel ' u'libxml2-python expect pyOpenSSL'.split()) data_setup.create_task(name=u'/distribution/check-install') data_setup.create_task( name=u'/distribution/reservesys', requires=u'emacs vim-enhanced unifdef sendmail'.split()) data_setup.create_task(name=u'/distribution/utils/dummy') data_setup.create_task(name=u'/distribution/inventory') if not Distro.query.count(): # The 'BlueShoeLinux5-5' string appears in many tests, because it's # the distro name used in complete-job.xml. data_setup.create_distro_tree(osmajor=u'BlueShoeLinux5', distro_name=u'BlueShoeLinux5-5') if os.path.exists(turbogears.config.get('basepath.rpms')): # Remove any task RPMs left behind by previous test runs for entry in os.listdir(turbogears.config.get('basepath.rpms')): shutil.rmtree(os.path.join(turbogears.config.get('basepath.rpms'), entry), ignore_errors=True) else: os.mkdir(turbogears.config.get('basepath.rpms')) setup_slapd() mail_capture_thread.start() if turbogears.config.get('openstack.identity_api_url'): setup_openstack() turbogears.testutil.make_app(Root) turbogears.testutil.start_server() global processes processes = [] if 'BEAKER_SERVER_BASE_URL' not in os.environ: # need to start the server ourselves # Usual pkg_resources ugliness is needed to ensure gunicorn doesn't # import pkg_resources before we get a chance to specify our # requirements in bkr.server.wsgi processes.extend([ Process('gunicorn', args=[sys.executable, '-c', '__requires__ = ["CherryPy < 3.0"]; import pkg_resources; ' \ 'from gunicorn.app.wsgiapp import run; run()', '--bind', ':%s' % turbogears.config.get('server.socket_port'), '--workers', '8', '--access-logfile', '-', '--preload', 'bkr.server.wsgi:application'], listen_port=turbogears.config.get('server.socket_port')), ]) processes.extend([ Process('slapd', args=[ 'slapd', '-d0', '-F' + slapd_config_dir, '-hldap://127.0.0.1:3899/' ], listen_port=3899, stop_signal=signal.SIGINT), ]) try: for process in processes: process.start() except: for process in processes: process.stop() raise