Example #1
0
    def Run(self):
        # Add one "normal" cron job...
        with test_lib.FakeTime(42):
            cron_id_1 = self.CreateCronJob(
                flow_name=cron_system.GRRVersionBreakDown.__name__,
                periodicity="1d",
                lifetime="2h",
                description="foo",
                enabled=False,
                token=self.token)

        # ...one disabled cron job,
        with test_lib.FakeTime(84):
            cron_id_2 = self.CreateCronJob(
                flow_name=cron_system.OSBreakDown.__name__,
                periodicity="7d",
                lifetime="1d",
                description="bar",
                token=self.token)

        # ...and one failing cron job.
        with test_lib.FakeTime(126):
            cron_id_3 = self.CreateCronJob(
                flow_name=cron_system.LastAccessStats.__name__,
                periodicity="7d",
                lifetime="1d",
                token=self.token)

        with test_lib.FakeTime(230):
            if data_store.RelationalDBEnabled():
                data_store.REL_DB.UpdateCronJob(
                    cron_id_3,
                    last_run_time=rdfvalue.RDFDatetime.Now(),
                    last_run_status=rdf_cronjobs.CronJobRun.CronJobRunStatus.
                    ERROR)
            else:
                cron_urn = aff4_cronjobs.GetCronManager().CRON_JOBS_PATH.Add(
                    cron_id_3)
                with aff4.FACTORY.OpenWithLock(cron_urn,
                                               token=self.token) as job:
                    job.Set(
                        job.Schema.LAST_RUN_TIME(rdfvalue.RDFDatetime.Now()))
                    job.Set(
                        job.Schema.LAST_RUN_STATUS(
                            status=rdf_cronjobs.CronJobRunStatus.Status.ERROR))

        self.Check("ListCronJobs",
                   args=cron_plugin.ApiListCronJobsArgs(),
                   replace={
                       cron_id_1: "GRRVersionBreakDown",
                       cron_id_2: "OSBreakDown",
                       cron_id_3: "LastAccessStats"
                   })
  def Run(self):
    # Add one "normal" cron job...
    with test_lib.FakeTime(42):
      cron_id_1 = self.CreateCronJob(
          flow_name=file_finder.FileFinder.__name__,
          periodicity="1d",
          lifetime="2h",
          description="foo",
          enabled=False,
          token=self.token)

    # ...one disabled cron job,
    with test_lib.FakeTime(84):
      cron_id_2 = self.CreateCronJob(
          flow_name=file_finder.ClientFileFinder.__name__,
          periodicity="7d",
          lifetime="1d",
          description="bar",
          token=self.token)

    # ...and one failing cron job.
    with test_lib.FakeTime(126):
      cron_id_3 = self.CreateCronJob(
          flow_name=filesystem.ListDirectory.__name__,
          periodicity="7d",
          lifetime="1d",
          token=self.token)

    with test_lib.FakeTime(230):
      data_store.REL_DB.UpdateCronJob(
          cron_id_3,
          last_run_time=rdfvalue.RDFDatetime.Now(),
          last_run_status=rdf_cronjobs.CronJobRun.CronJobRunStatus.ERROR)

    self.Check(
        "ListCronJobs",
        args=cron_plugin.ApiListCronJobsArgs(),
        replace={
            cron_id_1: "FileFinder",
            cron_id_2: "ClientFileFinder",
            cron_id_3: "ListDirectory"
        })