Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bf(ZENKO-852): Prevent CI object name conflicts #224

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/zenko_e2e/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from datetime import timedelta
import uuid
import requests


Expand Down Expand Up @@ -27,6 +28,8 @@ def baseurl(url):
return strip_port(strip_proto(url))


OBJ_PREFIX = '-'.join(['test', uuid.uuid4().hex])

SERVICEACCOUNT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount'

K8S_NAMESPACE = os.getenv('ZENKO_K8S_NAMESPACE', None)
Expand Down
13 changes: 6 additions & 7 deletions tests/zenko_e2e/fixtures/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import zenko_e2e.util as util


@pytest.fixture
@pytest.fixture(scope='function')
def objkey():
return util.make_name('test-object')
return '/'.join([conf.OBJ_PREFIX, util.make_name('test-object')])


@pytest.fixture
def empty_object(zenko_bucket):
def empty_object(zenko_bucket, objkey):
zenko_bucket.create()
name = util.gen_bucket_name('test-object')
return zenko_bucket.Object(name)
return zenko_bucket.Object(objkey)


@pytest.fixture
Expand All @@ -27,8 +26,8 @@ def metadata_object(empty_object, emptyfile):
@pytest.fixture
def metadata_multi(zenko_bucket, emptyfile):
zenko_bucket.create()
name1 = util.gen_bucket_name('test-object')
name2 = util.gen_bucket_name('test-object')
name1 = objkey()
name2 = objkey()
obj1 = zenko_bucket.Object(name1)
obj2 = zenko_bucket.Object(name2)
obj1.put(
Expand Down
8 changes: 6 additions & 2 deletions tests/zenko_e2e/util/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def cleanup_bucket(bucket, replicated=False, delete_bucket=True): # noqa pylint:
objects = []
versions = version_list['Versions']
for v in versions: # pylint: disable=invalid-name
objects.append({'VersionId': v['VersionId'], 'Key': v['Key']})
if v['Key'].startswith(conf.OBJ_PREFIX):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could just specify prefix = conf.OBJ_PREFIX before calling list_object_versions() for more efficiency?

PS: I know this is merged already 🤣

objects.append(
{'VersionId': v['VersionId'], 'Key': v['Key']})
response = client.delete_objects(
Bucket=bucket_name, Delete={'Objects': objects})
print(response)
Expand All @@ -118,7 +120,9 @@ def cleanup_bucket(bucket, replicated=False, delete_bucket=True): # noqa pylint:
objects = []
delete_markers = version_list['DeleteMarkers']
for d in delete_markers: # pylint: disable=invalid-name
objects.append({'VersionId': d['VersionId'], 'Key': d['Key']})
if d['Key'].startswith(conf.OBJ_PREFIX):
objects.append(
{'VersionId': d['VersionId'], 'Key': d['Key']})
response = client.delete_objects(
Bucket=bucket_name, Delete={'Objects': objects})
print(response)
Expand Down