Пример #1
0
    def Run(self):
        with test_lib.FakeTime(42):
            hunt_urn = self.StartHunt(description="the hunt")

            self.client_ids = self.SetupClients(5)
            self.AssignTasksToClients(client_ids=self.client_ids)
            # Only running the hunt on a single client, as SampleMock
            # implementation is non-deterministic in terms of resources
            # usage that gets reported back to the hunt.
            self.RunHunt(client_ids=[self.client_ids[-1]], failrate=0)

        # Create replace dictionary.
        replace = {hunt_urn.Basename(): "H:123456"}

        # Add all sub flows to replace dict.
        all_flows = hunts.GRRHunt.GetAllSubflowUrns(hunt_urn,
                                                    self.client_ids,
                                                    token=self.token)

        for flow_urn in all_flows:
            replace[flow_urn.Basename()] = "W:123456"

        self.Check("ListHuntClients",
                   args=hunt_plugin.ApiListHuntClientsArgs(
                       hunt_id=hunt_urn.Basename(), client_status="STARTED"),
                   replace=replace)
        self.Check("ListHuntClients",
                   args=hunt_plugin.ApiListHuntClientsArgs(
                       hunt_id=hunt_urn.Basename(),
                       client_status="OUTSTANDING"),
                   replace=replace)
        self.Check("ListHuntClients",
                   args=hunt_plugin.ApiListHuntClientsArgs(
                       hunt_id=hunt_urn.Basename(), client_status="COMPLETED"),
                   replace=replace)
Пример #2
0
    def Run(self):
        with test_lib.FakeTime(42):
            hunt_urn = self.StartHunt(description="the hunt")

            if data_store.RelationalDBReadEnabled():
                clients = self.SetupTestClientObjects(5)
                client_ids = sorted(clients)
            else:
                client_ids = [urn.Basename() for urn in self.SetupClients(5)]

            self.AssignTasksToClients(client_ids=client_ids)
            # Only running the hunt on a single client, as SampleMock
            # implementation is non-deterministic in terms of resources
            # usage that gets reported back to the hunt.
            client_urns = [rdf_client.ClientURN(client_ids[-1])]
            self.RunHunt(client_ids=client_urns, failrate=0)

        # Create replace dictionary.
        replace = {hunt_urn.Basename(): "H:123456"}

        self.Check("ListHuntClients",
                   args=hunt_plugin.ApiListHuntClientsArgs(
                       hunt_id=hunt_urn.Basename(), client_status="STARTED"),
                   replace=replace)
        self.Check("ListHuntClients",
                   args=hunt_plugin.ApiListHuntClientsArgs(
                       hunt_id=hunt_urn.Basename(),
                       client_status="OUTSTANDING"),
                   replace=replace)
        self.Check("ListHuntClients",
                   args=hunt_plugin.ApiListHuntClientsArgs(
                       hunt_id=hunt_urn.Basename(), client_status="COMPLETED"),
                   replace=replace)
Пример #3
0
  def testListHuntClients(self):
    hunt = implementation.GRRHunt.StartHunt(
        hunt_name=standard.GenericHunt.__name__,
        flow_runner_args=rdf_flows.FlowRunnerArgs(
            flow_name=file_finder.FileFinder.__name__),
        flow_args=rdf_file_finder.FileFinderArgs(
            paths=[os.path.join(self.base_path, "test.plist")],
            action=rdf_file_finder.FileFinderAction(action_type="DOWNLOAD"),),
        client_rate=0,
        token=self.token)
    hunt.Run()

    client_ids = self.SetupClients(5)
    self.AssignTasksToClients(client_ids=client_ids)
    action_mock = action_mocks.FileFinderClientMock()
    hunt_test_lib.TestHuntHelper(
        action_mock, client_ids, iteration_limit=10, token=self.token)

    result = self.handler.Handle(
        hunt_plugin.ApiListHuntClientsArgs(hunt_id=hunt.urn.Basename()),
        token=self.token)

    # TODO(user): This still uses data store internals and will fail on some
    # data stores.

    # This is not super deterministic, we start processing some
    # clients, run the hunt for a bit but there is no order to all
    # this. We should have some clients half finished though (i.e.,
    # with pending requests) and five clients in total.
    self.assertEqual(result.total_count, 5)
    clients = list(result.items)
    pending_requests = [client.pending_requests for client in clients]
    self.assertTrue(any(r.next_state) for r in pending_requests)