class TestChroot(unittest.TestCase): def setUp(self): self.testrun = TestRunData(Options(), config = _conductor_config_simple()) self.testrun.is_chrooted = True self.testrun.rootstrap_path = self._fake_rootstrap_path() self.chroot = Chroot(self.testrun) def _fake_rootstrap_path(self): return os.path.dirname(os.path.abspath(__file__)) + \ os.sep + FAKE_ROOTSTRAP_PATH def tearDown(self): pass def test_setup_and_remove_chroot(self): self.chroot.prepare() chroot_path = self.chroot.path self.assertTrue(os.path.isdir(chroot_path)) hosts_file = chroot_path + os.sep + os.sep.join(['etc', 'hosts']) self.assertTrue(os.path.isfile(hosts_file)) resolv_conf = chroot_path + os.sep + os.sep.join(['etc', 'resolv.conf']) self.assertTrue(os.path.isfile(resolv_conf)) f = file(hosts_file, 'rb') hosts = f.read() f.close() self.assertTrue('testdevice' in hosts) self.chroot.cleanup() self.assertFalse(os.path.isdir(chroot_path)) def test_home_dir_creation(self): self.chroot.prepare() chroot_path = self.chroot.path home_path = os.environ['HOME'] self.assertTrue(os.path.isdir(chroot_path + os.sep + home_path)) self.chroot.cleanup() self.assertFalse(os.path.isdir(chroot_path)) def test_rootstrap_not_found(self): try: self.testrun.rootstrap_path = "does_not_exists" self.chroot.prepare() except ConductorError, error: self.assertTrue(error.error_code == '310') self.assertTrue('No rootstrap found at' in error.error_info)
class TestChroot(unittest.TestCase): def setUp(self): self.testrun = TestRunData(Options(), config=_conductor_config_simple()) self.testrun.is_chrooted = True self.testrun.rootstrap_path = self._fake_rootstrap_path() self.chroot = Chroot(self.testrun) def _fake_rootstrap_path(self): return os.path.dirname(os.path.abspath(__file__)) + os.sep + FAKE_ROOTSTRAP_PATH def tearDown(self): pass def test_setup_and_remove_chroot(self): self.chroot.prepare() chroot_path = self.chroot.path self.assertTrue(os.path.isdir(chroot_path)) hosts_file = chroot_path + os.sep + os.sep.join(["etc", "hosts"]) self.assertTrue(os.path.isfile(hosts_file)) resolv_conf = chroot_path + os.sep + os.sep.join(["etc", "resolv.conf"]) self.assertTrue(os.path.isfile(resolv_conf)) f = file(hosts_file, "rb") hosts = f.read() f.close() self.assertTrue("testdevice" in hosts) self.chroot.cleanup() self.assertFalse(os.path.isdir(chroot_path)) def test_home_dir_creation(self): self.chroot.prepare() chroot_path = self.chroot.path home_path = os.environ["HOME"] self.assertTrue(os.path.isdir(chroot_path + os.sep + home_path)) self.chroot.cleanup() self.assertFalse(os.path.isdir(chroot_path)) def test_rootstrap_not_found(self): try: self.testrun.rootstrap_path = "does_not_exists" self.chroot.prepare() except ConductorError, error: self.assertTrue(error.error_code == "310") self.assertTrue("No rootstrap found at" in error.error_info)
def test_execute_tests(self): #NOTE: This test goes through lots of code by calling many private methods. #But this test does not check which code was actually executed. self.testrun.id = "1" self.executor.env = "testenvironment" self.executor.target = Stub_Hardware() self.executor.chroot = Chroot(self.testrun) timestamp = time.strftime("%y%m%d-%H%M%S") #test_package must match to string in Stub_Hardware test_package = "mypackage-test" path = os.path.join(self.workdir, "conductor", self.testrun.id + "_%s" % (timestamp), self.executor.env) expected_stdout_file = \ os.path.join(path, "%s_testrunner_stdout.txt" % test_package) expected_stderr_file = \ os.path.join(path, "%s_testrunner_stderr.txt" % test_package) expected_env_info_file = os.path.join(path, \ "%s_environment_before_testing.txt" % self.executor.target) #Check that files do not exist yet self.assertFalse(os.path.isfile(expected_stdout_file)) self.assertFalse(os.path.isfile(expected_stderr_file)) self.assertFalse(os.path.isfile(expected_env_info_file)) errors = self.executor.execute_tests() #Here's the code to be tested. self.assertEquals(errors, 0) #Check that files were created. self.assertTrue(os.path.isfile(expected_stdout_file)) self.assertTrue(os.path.isfile(expected_stderr_file)) self.assertTrue(os.path.isfile(expected_env_info_file))
def setUp(self): self.testrun = TestRunData(Options(), config = _conductor_config_simple()) self.testrun.is_chrooted = True self.testrun.rootstrap_path = self._fake_rootstrap_path() self.chroot = Chroot(self.testrun)
def setUp(self): self.testrun = TestRunData(Options(), config=_conductor_config_simple()) self.testrun.is_chrooted = True self.testrun.rootstrap_path = self._fake_rootstrap_path() self.chroot = Chroot(self.testrun)