Пример #1
0
    def Run(self):
        # Add one "normal" cron job...
        with test_lib.FakeTime(42):
            self.CreateCronJob(
                flow_name=cron_system.GRRVersionBreakDown.__name__,
                periodicity="1d",
                lifetime="2h",
                description="foo",
                disabled=True,
                token=self.token)

        # ...one disabled cron job,
        with test_lib.FakeTime(84):
            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 = self.CreateCronJob(
                flow_name=cron_system.LastAccessStats.__name__,
                periodicity="7d",
                lifetime="1d",
                token=self.token)

            with test_lib.FakeTime(230):
                if data_store.RelationalDBReadEnabled():
                    data_store.REL_DB.UpdateCronJob(
                        cron_id,
                        last_run_time=rdfvalue.RDFDatetime.Now(),
                        last_run_status=rdf_cronjobs.CronJobRunStatus.Status.
                        ERROR)
                else:
                    cron_urn = cronjobs.GetCronManager().CRON_JOBS_PATH.Add(
                        cron_id)
                    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())
Пример #2
0
  def Run(self):
    # Add one "normal" cron job...
    with test_lib.FakeTime(42):
      self.CreateCronJob(
          flow_name=cron_system.GRRVersionBreakDown.__name__,
          periodicity="1d",
          lifetime="2h",
          description="foo",
          disabled=True,
          token=self.token)

    # ...one disabled cron job,
    with test_lib.FakeTime(84):
      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 = self.CreateCronJob(
          flow_name=cron_system.LastAccessStats.__name__,
          periodicity="7d",
          lifetime="1d",
          token=self.token)

      for i in range(4):
        with test_lib.FakeTime(200 + i * 10):
          cron_urn = cronjobs.CRON_MANAGER.CRON_JOBS_PATH.Add(cron_id)
          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())