Skip to content

Commit d44c5aa

Browse files
authored
Use data bundle bucket name from the database. (#4661)
This allows data bundles to be moved, and to be stored in different buckets than `${BUNDLE_NAME}-corpus.${BUCKET_DOMAIN}`. Bug: https://crbug.com/387828386
1 parent 9029bfc commit d44c5aa

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

src/appengine/handlers/corpora.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def post(self):
6767

6868
user_email = helpers.get_user_email()
6969
bucket_name = data_handler.get_data_bundle_bucket_name(name)
70-
bucket_url = data_handler.get_data_bundle_bucket_url(name)
7170

7271
if not data_handler.create_data_bundle_bucket_and_iams(name, [user_email]):
7372
raise helpers.EarlyExitError('Failed to create bucket %s.' % bucket_name,
@@ -82,12 +81,13 @@ def post(self):
8281
data_bundle.bucket_name = bucket_name
8382
data_bundle.put()
8483

84+
bucket_url = data_bundle.bucket_url()
8585
template_values = {
8686
'title':
8787
'Success',
8888
'message': (
8989
'Upload data to the corpus using: '
90-
'gsutil -d -m rsync -r <local_corpus_directory> %s' % bucket_url),
90+
f'gsutil -d -m rsync -r <local_corpus_directory> {bucket_url}'),
9191
}
9292
return self.render('message.html', template_values)
9393

src/clusterfuzz/_internal/bot/tasks/setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,7 @@ def _is_data_bundle_up_to_date(data_bundle, data_bundle_directory):
741741

742742
# Check when the bucket url had last updates. If no new updates, no need to
743743
# update directory.
744-
bucket_url = data_handler.get_data_bundle_bucket_url(data_bundle.name)
745-
last_updated_time = storage.last_updated(bucket_url)
744+
last_updated_time = storage.last_updated(data_bundle.bucket_url())
746745
if last_updated_time and last_sync_time > last_updated_time:
747746
logs.info(
748747
'Data bundle %s has no new content from last sync.' % data_bundle.name)

src/clusterfuzz/_internal/datastore/data_handler.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,11 +1029,6 @@ def get_data_bundle_bucket_name(data_bundle_name):
10291029
return '%s-corpus.%s' % (data_bundle_name, domain)
10301030

10311031

1032-
def get_data_bundle_bucket_url(data_bundle_name):
1033-
"""Return data bundle bucket url on GCS."""
1034-
return 'gs://%s' % get_data_bundle_bucket_name(data_bundle_name)
1035-
1036-
10371032
def get_value_from_fuzzer_environment_string(fuzzer_name,
10381033
variable_pattern,
10391034
default=None):

src/clusterfuzz/_internal/datastore/data_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ class DataBundle(Model):
791791
# where the libFuzzer binary will run (untrusted).
792792
sync_to_worker = ndb.BooleanProperty(default=False)
793793

794+
def bucket_url(self) -> str:
795+
"""Returns the GCS URL of the bucket storing this data bundle's contents."""
796+
return f'gs://{self.bucket_name}'
797+
794798

795799
class Config(Model):
796800
"""Configuration."""

src/clusterfuzz/_internal/fuzzing/corpus_manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from clusterfuzz._internal.base import utils
2424
from clusterfuzz._internal.bot.tasks import task_types
2525
from clusterfuzz._internal.bot.tasks.utasks import uworker_io
26-
from clusterfuzz._internal.datastore import data_handler
2726
from clusterfuzz._internal.google_cloud_utils import storage
2827
from clusterfuzz._internal.metrics import logs
2928
from clusterfuzz._internal.protos import uworker_msg_pb2
@@ -607,8 +606,7 @@ def get_proto_data_bundle_corpus(
607606
workers to download the data bundle files using the fastest means available to
608607
them."""
609608
data_bundle_corpus = uworker_msg_pb2.DataBundleCorpus() # pylint: disable=no-member
610-
data_bundle_corpus.gcs_url = data_handler.get_data_bundle_bucket_url(
611-
data_bundle.name)
609+
data_bundle_corpus.gcs_url = data_bundle.bucket_url()
612610
data_bundle_corpus.data_bundle.CopyFrom(
613611
uworker_io.entity_to_protobuf(data_bundle))
614612
if task_types.task_main_runs_on_uworker():

src/clusterfuzz/_internal/tests/core/bot/tasks/utasks/corpus_pruning_task_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,9 @@ def setUp(self):
454454
self.quarantine_corpus.rsync_from_disk(
455455
os.path.join(TEST_DIR, 'quarantine'), delete=True)
456456

457-
self.mock.get_data_bundle_bucket_name.return_value = TEST_GLOBAL_BUCKET
458-
data_types.DataBundle(name='bundle', sync_to_worker=True).put()
457+
data_types.DataBundle(
458+
name='bundle', bundle_name=TEST_GLOBAL_BUCKET,
459+
sync_to_worker=True).put()
459460

460461
self.fuzzer = data_types.Fuzzer(
461462
revision=1,

0 commit comments

Comments
 (0)