def tearDown(self) -> None: run_command(cmd=f"{CMD_RELATIVE} clean", fail=False) if os.path.exists(self.storage_file): os.remove(self.storage_file) tmpdir = os.path.join("/tmp", os.path.basename(self.storage_file)) if os.path.exists(tmpdir): shutil.rmtree(tmpdir)
def is_sudo_possible(): random_file = "/usr/bin/test_superuser" try: run_command(f"sudo -n touch {random_file}") except (PersistentStorageException, FileNotFoundError): return False run_command(f"sudo rm {random_file}") return True
def testOutput(self): replacement = ("tests_requre.openshift_integration.test_fedpkg.FedPkg." "test_fedpkg_clone.yaml:output:str:random_output") run_command( f"{CMD_TOOL} --replaces {replacement} {self.storage_file_tmp}") with open(self.storage_file_tmp, mode="r") as opened_file: output = opened_file.read() self.assertIn("random_output", output) self.assertIn("requre.openshift_integration", output) self.assertIn("latency: xxxx", output) self.assertNotIn("output: yyy", output)
def testLatency(self): replacement = "clone%store_function_output:latency:int:50" run_command( f"{CMD_TOOL} --replaces {replacement} {self.storage_file_tmp}") with open(self.storage_file_tmp, mode="r") as opened_file: output = opened_file.read() self.assertNotIn("random_output", output) self.assertIn("requre.openshift_integration", output) self.assertNotIn("latency: xxxx", output) self.assertIn("output: yyy", output) self.assertIn("latency: 0", output) self.assertIn("latency: 50", output)
def testSupport(self): envs = (f"{ENV_STORAGE_FILE}={self.storage_file}" f" {ENV_REPLACEMENT_FILE}={DATA_DIR}/e2e_test_replacements.py") cmd = f"""bash -c '{envs} {self.test_command}'""" output = run_command(cmd=cmd, output=True) self.assertIn("static_tmp_1", output) self.assertIn("storage_e2e", output)
def check(self, replacements, apply_latency, latency, delta): """ Check if it is really waiting for function call, when latency is enabled """ envs = (f"{ENV_STORAGE_FILE}={self.storage_file} " f"{ENV_REPLACEMENT_FILE}={DATA_DIR}/{replacements} " f"{ENV_APPLY_LATENCY}={apply_latency}") cmd = f"""bash -c '{envs} {self.test_command}'""" self.assertFalse(os.path.exists(self.storage_file)) before = time.time() run_command(cmd=cmd, output=True) after = time.time() self.assertAlmostEqual(2, after - before, delta=delta) self.assertTrue(os.path.exists(self.storage_file)) before = time.time() run_command(cmd=cmd, output=True) after = time.time() self.assertAlmostEqual(latency, after - before, delta=delta)
def run_command_wrapper(cmd, error_message=None, cwd=None, fail=True, output=False): return run_command(cmd=cmd, error_message=error_message, cwd=cwd, fail=fail, output=output)
def testReplaceAll(self): replacement = ":latency:int:50" output = run_command( f"{CMD_TOOL} --replaces {replacement} {self.storage_file_tmp}", output=True) print(output) with open(self.storage_file_tmp, mode="r") as opened_file: output = opened_file.read() self.assertNotIn("random_output", output) self.assertIn("requre.openshift_integration", output) self.assertNotIn("latency: xxxx", output) self.assertIn("output: yyy", output) self.assertNotIn("latency: 0", output) self.assertIn("latency: 50", output)
def _copy_logic(pers_storage: PersistentObjectStorage, source: str, destination: str) -> None: """ Internal function. Copy files to or back from persistent STORAGE location """ logger.debug(f"Copy files {source} -> {destination}") logger.debug( f"Persistent Storage write mode: {pers_storage.is_write_mode}") if pers_storage.is_write_mode: if os.path.isdir(source): os.makedirs(destination) run_command(cmd=["cp", "-drT", source, destination]) else: run_command(cmd=["cp", "-d", source, destination]) else: if os.path.isdir(destination): if os.path.exists(source): shutil.rmtree(source) os.makedirs(source) run_command(cmd=["cp", "-drTf", destination, source]) else: run_command(cmd=["cp", "-df", destination, source])
def setUp(self) -> None: run_command(cmd=f"{CMD_RELATIVE} clean", fail=False)
def test_help(self): run_command(cmd=f"{CMD_RELATIVE}")
def test_installation_path(self): output = run_command(cmd=f"{CMD_RELATIVE} --system verify", output=True) self.assertIn("Python patched", output) self.assertIn("/usr/lib/python", output)
def test_apply(self): run_command(cmd=f"{CMD_RELATIVE} apply")
def tearDown(self) -> None: run_command(cmd=f"{CMD_RELATIVE} clean", fail=False)
def test_clean(self): self.test_verify() run_command(cmd=f"{CMD_RELATIVE} clean")
def test_verify(self): self.test_apply() run_command(cmd=f"{CMD_RELATIVE} verify")
def setUp(self) -> None: run_command(cmd=f"{CMD_RELATIVE} clean", fail=False) run_command(cmd=f"{CMD_RELATIVE} apply") self.storage_file = os.path.join(tempfile.mktemp(), "storage_e2e.yaml")
def tearDown(self) -> None: run_command(cmd=f"{CMD_RELATIVE} clean", fail=False) os.remove(self.storage_file)
def setUp(self) -> None: run_command(cmd=f"{CMD_RELATIVE} clean", fail=False) run_command(cmd=f"{CMD_RELATIVE} apply") self.storage_file = tempfile.mktemp()
def setUp(self) -> None: run_command(cmd=f"cp {self.storage_file} {self.storage_file_tmp}")
def test_install(self): self.assertIn( "Applying import patch", run_command(cmd=f"{CMD_TOOL} apply", fail=False, output=True), )
def tearDown(self) -> None: run_command(cmd=f"rm {self.storage_file_tmp}")
def test_verify_user(self): self.test_install() output = run_command(cmd=f"{CMD_RELATIVE} verify", output=True) self.assertIn("Python patched", output) self.assertIn(os.path.expanduser("~/.local/lib/python"), output)
def is_requre_installed(): try: run_command(f"{CMD_TOOL} --help") except (PersistentStorageException, FileNotFoundError): return False return True
def testWithoutSupport(self): output = run_command(cmd=self.test_command, output=True) self.assertIn("/tmp/tmp", output) self.assertNotIn("static_tmp_1", output) self.assertNotIn("storage_e2e", output)