Ejemplo n.º 1
0
    def test_directory_compare_from_hash(self):
        test_dir = os.path.join(self.dir_path, "test2")

        # Create data
        os.mkdir(test_dir)
        os.mkdir(os.path.join(test_dir, "subdir"))
        open(os.path.join(test_dir, "file1"), "w").write("random text 1")
        open(os.path.join(test_dir, "file2"), "w").write("random text 2")
        open(os.path.join(test_dir, "subdir", "file3"), "w").write("random text 3")
        open(os.path.join(test_dir, "file4"), "w").write("random text 4")
        open(os.path.join(test_dir, "file5"), "w").write("random text 5")
        open(os.path.join(test_dir, "file6"), "w").write("random text 6")

        l1 = directory_content_with_hash(test_dir)
        l2 = copy.deepcopy(l1)

        # Pertub the data
        l2["file1"] = (l2["file1"][0], 0)
        l2["file2"] = ("not a valid hash", l2["file2"])
        l2["file4"] = ("not a valid hash", 0)
        del l2["file5"]

        # Compare and test
        to_update, to_delete = directory_compare_from_hash(l2, l1)
        assert set(to_update) == set(["file1", "file2", "file4"])
        assert set(to_delete) == set(["file5"])
Ejemplo n.º 2
0
    def start(self):
        # init the synchronization of task directories
        self._last_content_in_task_directory = directory_content_with_hash(get_tasks_directory())
        threading.Timer((30 if not self._is_testing else 2), self._try_synchronize_task_dir).start()

        # connect to agents
        self._try_agent_connection()
Ejemplo n.º 3
0
    def _try_synchronize_task_dir(self):
        """ Check if the remote tasks dirs (on the remote agents) should be updated """
        if self._closed:
            return

        current_content_in_task_directory = directory_content_with_hash(get_tasks_directory())
        changed, deleted = directory_compare_from_hash(current_content_in_task_directory, self._last_content_in_task_directory)
        if len(changed) != 0 or len(deleted) != 0:
            self._last_content_in_task_directory = current_content_in_task_directory
            for agent in self._agents:
                if agent is not None:
                    self._synchronize_task_dir(agent)

        if not self._is_testing:
            threading.Timer(30, self._try_synchronize_task_dir).start()
Ejemplo n.º 4
0
    def test_directory_content_with_hash(self):
        test_dir = os.path.join(self.dir_path, "test1")

        # Create data
        os.mkdir(test_dir)
        os.mkdir(os.path.join(test_dir, "subdir"))

        goal = {}

        open(os.path.join(test_dir, "file1"), "w").write("random text 1")
        goal["file1"] = ("d7e62e68f60f6974309b263192d5fea2", os.stat(os.path.join(test_dir, "file1")).st_mode)

        open(os.path.join(test_dir, "file2"), "w").write("random text 2")
        goal["file2"] = ("5ae848320fda7796dc2f3a1a68300e07", os.stat(os.path.join(test_dir, "file2")).st_mode)

        open(os.path.join(test_dir, "subdir", "file3"), "w").write("random text 3")
        goal["subdir/file3"] = ("312aa75e0816015cdb5ef1989de7bf3f", os.stat(os.path.join(test_dir, "subdir", "file3")).st_mode)

        # Test the function
        assert directory_content_with_hash(test_dir) == goal