Beispiel #1
0
 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)
Beispiel #2
0
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)
Beispiel #5
0
 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)
Beispiel #6
0
    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)
Beispiel #7
0
 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)
Beispiel #9
0
 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])
Beispiel #10
0
 def setUp(self) -> None:
     run_command(cmd=f"{CMD_RELATIVE} clean", fail=False)
Beispiel #11
0
 def test_help(self):
     run_command(cmd=f"{CMD_RELATIVE}")
Beispiel #12
0
 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)
Beispiel #13
0
 def test_apply(self):
     run_command(cmd=f"{CMD_RELATIVE} apply")
Beispiel #14
0
 def tearDown(self) -> None:
     run_command(cmd=f"{CMD_RELATIVE} clean", fail=False)
Beispiel #15
0
 def test_clean(self):
     self.test_verify()
     run_command(cmd=f"{CMD_RELATIVE} clean")
Beispiel #16
0
 def test_verify(self):
     self.test_apply()
     run_command(cmd=f"{CMD_RELATIVE} verify")
Beispiel #17
0
 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")
Beispiel #18
0
 def tearDown(self) -> None:
     run_command(cmd=f"{CMD_RELATIVE} clean", fail=False)
     os.remove(self.storage_file)
Beispiel #19
0
 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}")
Beispiel #21
0
 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}")
Beispiel #23
0
 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)
Beispiel #24
0
def is_requre_installed():
    try:
        run_command(f"{CMD_TOOL} --help")
    except (PersistentStorageException, FileNotFoundError):
        return False
    return True
Beispiel #25
0
 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)