def tearDown(self): '''Clean up after each test_* function''' testlib.config_restore(self.hosts) if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir) os.chdir(self.fs_dir)
def test_mount(self): '''Test mount''' test_iso = 'util-linux/test.iso' test_file = 'testfile.txt' self.tmpdir = tempfile.mkdtemp(prefix='testlib', dir='/tmp') # mount the iso file rc, report = testlib.cmd( ['mount', '-o', 'loop', test_iso, self.tmpdir]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # See if we can see the file inside result = "Couldn't find testfile %s in mounted directory" % test_file self.assertTrue(os.path.exists('%s/%s' % (self.tmpdir, test_file)), result) # unmount it rc, report = testlib.cmd(['umount', self.tmpdir]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # Make sure we can't see the file anymore result = "Found testfile %s in mounted directory" % test_file self.assertFalse(os.path.exists('%s/%s' % (self.tmpdir, test_file)), result) testlib.recursive_rm(self.tmpdir)
def _move_config_dir(self): '''Move the .w3m directory out of the way''' if os.path.exists(self.configdir): if not os.path.exists(self.configdir_bak): shutil.move(self.configdir, self.configdir_bak) else: testlib.recursive_rm(self.configdir)
def tearDown(self): '''Clean up after each test_* function''' rc, result = self.daemon.stop() # Empty out the instance directory if os.path.exists(self.zope_instance): testlib.recursive_rm(self.zope_instance)
def tearDown(self): '''Clean up after each test_* function''' testlib_archive.ArchiveCommon._tearDown(self) os.chdir(self.fs_dir) if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir)
def test_extract(self): '''Jar extract''' # get the contents of the directory (rc, tmp) = testlib.cmd(["find", self.archive_dir]) find_report = self.clean_trailing_slash(self.sort_output(tmp)) # create archive (rc, report) = testlib.cmd(["/usr/bin/fastjar", "-cMf", "archive.jar", \ self.archive_dir]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # test the contents of the created archive testlib.recursive_rm(self.archive_dir) (rc, report) = testlib.cmd(["/usr/bin/fastjar", "-xf", "archive.jar"]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) (rc, tmp) = testlib.cmd(["find", self.archive_dir]) listing_report = self.clean_trailing_slash(self.sort_output(tmp)) result = 'Find has:\n%s\n%s has:\n%s\n' % (find_report, \ "archive.jar", \ listing_report) self.assertEquals(find_report, listing_report, result)
def tearDown(self): '''Clean up after each test_* function''' if self.current_dir != os.getcwd(): os.chdir(self.current_dir) if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir)
def _move_elinks_dir(self): '''Move the .elinks directory out of the way''' if os.path.exists(self.elinksdir): if not os.path.exists(self.elinksdir_bak): shutil.move(self.elinksdir, self.elinksdir_bak) else: testlib.recursive_rm(self.elinksdir)
def _tearDown(self): '''Clean up after each test_* function''' self._stop() time.sleep(2) os.unlink('/etc/nut/ups.conf') os.unlink('/etc/nut/upsd.conf') os.unlink('/etc/nut/upsd.users') os.unlink('/etc/nut/upsmon.conf') os.unlink('/etc/nut/dummy.dev') os.unlink('/etc/nut/nut.conf') testlib.config_restore('/etc/nut/ups.conf') testlib.config_restore('/etc/nut/upsd.conf') testlib.config_restore('/etc/nut/upsd.users') testlib.config_restore('/etc/nut/upsmon.conf') testlib.config_restore('/etc/nut/dummy.dev') testlib.config_restore('/etc/nut/nut.conf') if os.path.exists(self.notifyscript): os.unlink(self.notifyscript) if os.path.exists(self.shutdowncmd): os.unlink(self.shutdowncmd) testlib.config_restore(self.hosts_file) if self.lsb_release['Release'] <= 8.04: testlib.config_restore('/etc/default/nut') if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir) # this is needed because of the potentially hung upsd process in the # CVE-2012-2944 test testlib.cmd(['killall', 'upsd']) testlib.cmd(['killall', '-9', 'upsd'])
def test_ssl(self): '''Test https''' (tmpdir, srvcert_pem, srvkey_pem, clientcert_pem, clientkey_pem, cacert_pem) = testlib_ssl.gen_ssl() self._prepare_ssl(srvkey_pem, srvcert_pem) testlib.recursive_rm(tmpdir) # modern wget now returns 5 on ssl validation errors if self.lsb_release['Release'] <= 9.10: expected = 1 else: expected = 5 # Cert is self-signed, make sure wget says so if self.lsb_release['Release'] <= 8.04: error_str = 'ERROR: Certificate verification error for localhost' else: error_str = "ERROR: cannot verify localhost's certificate" self._test_url_wget("https://localhost/", error_str, expected=expected) # Let's try an SSL page without validating the self-signed cert test_str = testlib_httpd.create_html_page(self.html_page) self._test_url_wget("https://localhost/" + \ os.path.basename(self.html_page), test_str, extra_opts=['--no-check-certificate'])
def test_simple_deny_root_login(self): '''Test deny ssh login to root''' self.modify_sshd_config({"PermitRootLogin": "******"}) self.generate_ssh_keys() if os.path.exists("/root/.ssh"): testlib.config_copydir("/root/.ssh") root_ssh_exists = True else: os.mkdir("/root/.ssh", 0700) root_ssh_exists = False shutil.copy2(self.user.home + "/.ssh/id_rsa.pub", "/root/.ssh/authorized_keys") os.chown("/root/.ssh/authorized_keys", 0, 0) try: expected = 1 rc, out = self.run_ssh_cmd( ['ssh', '-x', 'root@localhost', 'id', '-u'], use_password=False) self.assertEquals(expected, rc, out) #self.assertEquals(["0"], out, out) except pexpect.TIMEOUT: pass else: self.assertNotEquals(["0"], out, out) finally: testlib.recursive_rm("/root/.ssh") if root_ssh_exists: testlib.config_restore("/root/.ssh")
def tearDown(self): '''Clean up after each test_* function''' self.builder = None os.chdir(self.topdir) if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir)
def test_in(self): '''bsdcpio: Copy in''' # get the contents of the directory (rc, tmp) = testlib.cmd(["find", self.archive_dir]) find_report = self.clean_trailing_slash(self.sort_output(tmp)) # create archives for f in self.formats: (rc, report) = testlib.cmd_pipe(["find", self.archive_dir], \ ["bsdcpio", "-o", "-v", "-H", f, \ "-F", "archive." + f]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # test the contents of the created archives for f in self.formats: testlib.recursive_rm(self.archive_dir) (rc, report) = testlib.cmd(["bsdcpio", "-i", "-v", "-F", \ "archive." + f]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) (rc, tmp) = testlib.cmd(["find", self.archive_dir]) listing_report = self.clean_trailing_slash(self.sort_output(tmp)) result = 'Find has:\n%s\n%s has:\n%s\n' % (find_report, \ "archive." + f, \ listing_report) self.assertEquals(find_report, listing_report, result)
def onetime_tearDown(self): '''Clean up after each test_* function''' testlib.config_restore(self.mywiki) testlib.config_restore(self.farmconfig) testlib.config_restore('/etc/apache2/apache2.conf') testlib.recursive_rm(self.datadir) testlib.recursive_rm(self.wwwdir)
def _tearDown(self): '''Common test tear down''' testlib.config_restore(self.nfs_exports) self._stop() if os.path.exists(self.tmpname): os.unlink(self.tmpname) if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir)
def tearDown(self): '''Tear down method''' subprocess.call(['umount',self.mountpoint]) if os.path.exists(self.mountpoint): testlib.recursive_rm(self.mountpoint) if os.path.exists(self.testdir): testlib.recursive_rm(self.testdir) self._tearDown()
def tearDown(self): '''Clean up after each test_* function''' if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir) if os.path.exists(self.apparmor_denied_file): os.unlink(self.apparmor_denied_file) if os.path.exists(self.apparmor_allowed_file): os.unlink(self.apparmor_allowed_file)
def tearDown(self): '''Clean up after each test_* function''' if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) self.user = None for p in self.apparmor_protected_files: if os.path.exists(p): os.unlink(p)
def tearDown(self): '''Clean up after each test_* function''' if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) if os.path.exists(self.elinksdir_bak): if os.path.exists(self.elinksdir): testlib.recursive_rm(self.elinksdir) shutil.move(self.elinksdir_bak, self.elinksdir) os.chdir(self.topdir)
def tearDown(self): '''Clean up after each test_* function''' if self.server: self.server.shutdown() self.server=None os.chdir(self.cwd) if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir)
def tearDown(self): '''Clean up after each test_* function''' if self.tempdir and os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) if os.environ['LYNX_TRACE_FILE'] != "": trace = os.path.expanduser("~/%s" % os.environ['LYNX_TRACE_FILE']) if os.path.exists(trace): os.unlink(trace) os.chdir(self.topdir)
def tearDown(self): '''Clean up after each test_* function''' if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir) testlib.config_restore(self.users_file) testlib.config_restore(self.default_site) self.user = None
def tearDown(self): '''Clean up after each test_* function''' self.builder = None if os.path.exists(self.sources_list): os.unlink(self.sources_list) self._update() os.chdir(self.topdir) if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir)
def test_fake_unmount(self): '''Test umount with --fake option''' # We didn't backport the --fake option to dapper if self.lsb_release['Release'] == 6.06: return self._skipped("Skipped: Dapper doesn't have --fake option") # Make sure we actually have the --fake option first before # mounting stuff rc, report = testlib.cmd(['umount', '--fake', self.tmpdir]) result = "umount doesn't have --fake option!\n" self.assertFalse("unrecognized option '--fake'" in report, result + report) test_iso = 'util-linux/test.iso' test_file = 'testfile.txt' self.tmpdir = tempfile.mkdtemp(prefix='testlib', dir='/tmp') # mount the iso file rc, report = testlib.cmd( ['mount', '-o', 'loop', test_iso, self.tmpdir]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # See if we can see the file inside result = "Couldn't find testfile %s in mounted directory" % test_file self.assertTrue(os.path.exists('%s/%s' % (self.tmpdir, test_file)), result) # fake unmount it rc, report = testlib.cmd(['umount', '--fake', self.tmpdir]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # See if we can see the file inside result = "Couldn't find testfile %s in mounted directory" % test_file self.assertTrue(os.path.exists('%s/%s' % (self.tmpdir, test_file)), result) # unmount it for real rc, report = testlib.cmd(['umount', self.tmpdir]) expected = 0 result = 'Got exit code %d, expected %d\n' % (rc, expected) self.assertEquals(expected, rc, result + report) # Make sure we can't see the file anymore result = "Found testfile %s in mounted directory" % test_file self.assertFalse(os.path.exists('%s/%s' % (self.tmpdir, test_file)), result) testlib.recursive_rm(self.tmpdir)
def tearDown(self): '''Clean up after each test_* function''' self.builder = None os.chdir(self.topdir) if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir) self._tearDown() testlib.config_restore(self.ufw_exe)
def tearDown(self): '''Clean up after each test_* function''' if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) if os.path.exists(self.configdir_bak): if os.path.exists(self.configdir): testlib.recursive_rm(self.configdir) shutil.move(self.configdir_bak, self.configdir) os.chdir(self.topdir) testlib.config_restore(self.hosts_file) testlib_httpd.HttpdCommon._tearDown(self)
def tearDown(self): '''Clean up after each test_* function''' self._stop_cluster() testlib.config_restore(self.cluster_conf) # don't restore this in case want to reboot #testlib.config_restore(self.hosts_file) if os.path.exists("/tmp/rgmanager-dump"): os.unlink("/tmp/rgmanager-dump") if os.path.exists("/var/log/cluster/rgmanager-dump"): os.unlink("/var/log/cluster/rgmanager-dump") if os.path.exists(self.tmpdir): testlib.recursive_rm(self.tmpdir)
def tearDown(self): '''Shutdown methods''' if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) if os.path.exists(self.evil_file): os.unlink(self.evil_file) testlib.config_restore(self.hosts_file) testlib.config_restore(self.default_site) testlib_httpd.HttpdCommon._tearDown(self)
def tearDown(self): '''Shutdown methods''' if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) if os.path.exists(self.php5_content_dispo): os.unlink(self.php5_content_dispo) testlib.config_restore(self.hosts_file) self._disable_mod("php5") testlib_httpd.HttpdCommon._tearDown(self)
def _cleanup_war(self, war_name): '''Removes a war file and directory''' war_file = os.path.join(self.webapp_dir, war_name) war_dir = os.path.join(self.webapp_dir, war_name.split('.')[0]) if os.path.exists(war_file): os.unlink(war_file) if os.path.exists(war_dir): testlib.recursive_rm(war_dir) self.war = ""
def _tearDown(self): '''Restore server configs''' for f in self.conf_files: testlib.config_restore(f) # put saslauthd back for f in ['/var/spool/postfix/var/run/saslauthd', '/var/run/saslauthd']: if os.path.isfile(f) or os.path.islink(f): os.unlink(f) elif os.path.exists(f): testlib.recursive_rm(f) subprocess.call(['mkdir','-p','/var/run/saslauthd']) subprocess.call(['/etc/init.d/saslauthd', 'stop'], stdout=subprocess.PIPE) subprocess.call(['/etc/init.d/saslauthd', 'start'], stdout=subprocess.PIPE)
def tearDown(self): '''Clean up after each test_* function''' try: self.s.quit() except: pass self.user = None self._zap_lists() if os.path.exists(self.tempdir): testlib.recursive_rm(self.tempdir) testlib.config_restore(self.mailman_cfg) testlib.config_restore(self.mailman_aliases) self._tearDown_postfix() self._tearDown_apache() self.mailman_daemon.stop()