Skip to content

Commit

Permalink
Fix fuzzer selection query logic when developing locally (#3512)
Browse files Browse the repository at this point in the history
No matter how I modify the query logic, the `FuzzerJobs` data type will
not return query results when running locally.

---------

Co-authored-by: Oliver Chang <[email protected]>
Co-authored-by: jonathanmetzman <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2023
1 parent 180c4a9 commit 01626e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
13 changes: 5 additions & 8 deletions src/clusterfuzz/_internal/bot/tasks/task_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from clusterfuzz._internal.metrics import logs
from clusterfuzz._internal.system import environment

# pylint: disable=undefined-variable
# https://github.com/google/clusterfuzz/pull/3512/#issuecomment-1857737156
# Linter throwing a false positive for the is_production() call


class BaseTask:
"""Base module for tasks."""
Expand All @@ -45,13 +49,6 @@ def execute(self, task_argument, job_type, uworker_env):
self.module.execute_task(task_argument, job_type)


def is_production():
return not (environment.is_local_development() or
environment.get_value('UNTRUSTED_RUNNER_TESTS') or
environment.get_value('LOCAL_DEVELOPMENT') or
environment.get_value('UTASK_TESTS'))


class BaseUTask(BaseTask):
"""Base class representing an untrusted task. Children must decide to execute
locally or remotely."""
Expand Down Expand Up @@ -104,7 +101,7 @@ def is_execution_remote():

def execute(self, task_argument, job_type, uworker_env):
"""Executes a utask locally."""
if (not is_production() or
if (not environment.is_production() or
not environment.get_value('REMOTE_UTASK_EXECUTION') or
environment.platform() != 'LINUX'):
self.execute_locally(task_argument, job_type, uworker_env)
Expand Down
13 changes: 8 additions & 5 deletions src/clusterfuzz/_internal/fuzzing/fuzzer_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ def get_fuzz_task_payload(platform=None):
if base_platform != platform:
platforms.append(base_platform)

query = data_types.FuzzerJobs.query()
if environment.is_local_development():
query = query.filter(data_types.FuzzerJobs.platform.IN(platforms))
mappings = list(ndb_utils.get_all_from_query(query))[:1]
else:
if environment.is_production():
query = data_types.FuzzerJobs.query()
query = query.filter(data_types.FuzzerJobs.platform.IN(platforms))

mappings = []
for entity in query:
mappings.extend(entity.fuzzer_jobs)
else:
# 'FuzzerJobs' may not exist locally because they are created by
# the 'batch_fuzzer_jobs' cron job
query = data_types.FuzzerJob.query()
query = query.filter(data_types.FuzzerJob.platform.IN(platforms))
mappings = list(ndb_utils.get_all_from_query(query))[:1]

if not mappings:
return None, None
Expand Down
7 changes: 7 additions & 0 deletions src/clusterfuzz/_internal/system/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,13 @@ def is_local_development():
return bool(get_value('LOCAL_DEVELOPMENT') and not get_value('PY_UNITTESTS'))


def is_production():
"""Returns True if there are no environmental indicators
of local development ocurring."""
return not (is_local_development() or get_value('UNTRUSTED_RUNNER_TESTS') or
get_value('LOCAL_DEVELOPMENT') or get_value('UTASK_TESTS'))


def local_noop(func):
"""Wrap a function into no-op and return None if running in local
development environment."""
Expand Down

0 comments on commit 01626e9

Please sign in to comment.