def test_symlink_latest_log_directory(self):
        handler = FileProcessorHandler(base_log_folder=self.base_log_folder,
                                       filename_template=self.filename)
        handler.dag_dir = self.dag_dir

        date1 = (timezone.utcnow() + timedelta(days=1)).strftime("%Y-%m-%d")
        date2 = (timezone.utcnow() + timedelta(days=2)).strftime("%Y-%m-%d")

        path1 = os.path.join(self.base_log_folder, date1, "log1")
        path2 = os.path.join(self.base_log_folder, date1, "log2")

        if os.path.exists(path1):
            os.remove(path1)
        if os.path.exists(path2):
            os.remove(path2)

        link = os.path.join(self.base_log_folder, "latest")

        with freeze_time(date1):
            handler.set_context(filename=os.path.join(self.dag_dir, "log1"))
            self.assertTrue(os.path.islink(link))
            self.assertEqual(os.path.basename(os.readlink(link)), date1)
            self.assertTrue(os.path.exists(os.path.join(link, "log1")))

        with freeze_time(date2):
            handler.set_context(filename=os.path.join(self.dag_dir, "log2"))
            self.assertTrue(os.path.islink(link))
            self.assertEqual(os.path.basename(os.readlink(link)), date2)
            self.assertTrue(os.path.exists(os.path.join(link, "log2")))
コード例 #2
0
    def test_symlink_latest_log_directory(self):
        handler = FileProcessorHandler(base_log_folder=self.base_log_folder,
                                       filename_template=self.filename)
        handler.dag_dir = self.dag_dir

        date1 = (timezone.utcnow() + timedelta(days=1)).strftime("%Y-%m-%d")
        date2 = (timezone.utcnow() + timedelta(days=2)).strftime("%Y-%m-%d")

        p1 = os.path.join(self.base_log_folder, date1, "log1")
        p2 = os.path.join(self.base_log_folder, date1, "log2")

        if os.path.exists(p1):
            os.remove(p1)
        if os.path.exists(p2):
            os.remove(p2)

        link = os.path.join(self.base_log_folder, "latest")

        with freeze_time(date1):
            handler.set_context(filename=os.path.join(self.dag_dir, "log1"))
            self.assertTrue(os.path.islink(link))
            self.assertEqual(os.path.basename(os.readlink(link)), date1)
            self.assertTrue(os.path.exists(os.path.join(link, "log1")))

        with freeze_time(date2):
            handler.set_context(filename=os.path.join(self.dag_dir, "log2"))
            self.assertTrue(os.path.islink(link))
            self.assertEqual(os.path.basename(os.readlink(link)), date2)
            self.assertTrue(os.path.exists(os.path.join(link, "log2")))
コード例 #3
0
    def test_non_template(self):
        date = timezone.utcnow().strftime("%Y-%m-%d")
        handler = FileProcessorHandler(base_log_folder=self.base_log_folder, filename_template=self.filename)
        handler.dag_dir = self.dag_dir

        path = os.path.join(self.base_log_folder, "latest")
        self.assertTrue(os.path.islink(path))
        self.assertEqual(os.path.basename(os.readlink(path)), date)

        handler.set_context(filename=os.path.join(self.dag_dir, "logfile"))
        self.assertTrue(os.path.exists(os.path.join(path, "logfile")))
コード例 #4
0
    def test_template(self):
        date = timezone.utcnow().strftime("%Y-%m-%d")
        handler = FileProcessorHandler(base_log_folder=self.base_log_folder,
                                       filename_template=self.filename_template)
        handler.dag_dir = self.dag_dir

        path = os.path.join(self.base_log_folder, "latest")
        self.assertTrue(os.path.islink(path))
        self.assertEqual(os.path.basename(os.readlink(path)), date)

        handler.set_context(filename=os.path.join(self.dag_dir, "logfile"))
        self.assertTrue(os.path.exists(os.path.join(path, "logfile.log")))
コード例 #5
0
    def test_symlink_latest_log_directory_exists(self):
        handler = FileProcessorHandler(base_log_folder=self.base_log_folder, filename_template=self.filename)
        handler.dag_dir = self.dag_dir

        date1 = (timezone.utcnow() + timedelta(days=1)).strftime("%Y-%m-%d")

        path1 = os.path.join(self.base_log_folder, date1, "log1")
        if os.path.exists(path1):
            os.remove(path1)

        link = os.path.join(self.base_log_folder, "latest")
        if os.path.exists(link):
            os.remove(link)
        os.makedirs(link)

        with freeze_time(date1):
            handler.set_context(filename=os.path.join(self.dag_dir, "log1"))
コード例 #6
0
    def test_symlink_latest_log_directory_exists(self):
        handler = FileProcessorHandler(base_log_folder=self.base_log_folder,
                                       filename_template=self.filename)
        handler.dag_dir = self.dag_dir

        date1 = (timezone.utcnow() + timedelta(days=1)).strftime("%Y-%m-%d")

        p1 = os.path.join(self.base_log_folder, date1, "log1")
        if os.path.exists(p1):
            os.remove(p1)

        link = os.path.join(self.base_log_folder, "latest")
        if os.path.exists(link):
            os.remove(link)
        os.makedirs(link)

        with freeze_time(date1):
            handler.set_context(filename=os.path.join(self.dag_dir, "log1"))