Commit c7dd3503 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Full integration test for admin. Allow admin to delete published upload and dataset with doi.

parent ad0325ee
Pipeline #72280 passed with stages
in 21 minutes and 37 seconds
...@@ -104,7 +104,7 @@ deploy: ...@@ -104,7 +104,7 @@ deploy:
- helm dependency update ops/helm/nomad - helm dependency update ops/helm/nomad
- helm upgrade --namespace nomad --install $RELEASE_NAME ops/helm/nomad -f ops/helm/nomad/ci-dev-values.yaml --set proxy.external.path=/dev/nomad/$RELEASE_NAME,image.tag=$CI_COMMIT_REF_NAME,roll=true --wait - helm upgrade --namespace nomad --install $RELEASE_NAME ops/helm/nomad -f ops/helm/nomad/ci-dev-values.yaml --set proxy.external.path=/dev/nomad/$RELEASE_NAME,image.tag=$CI_COMMIT_REF_NAME,roll=true --wait
- docker pull $TEST_IMAGE - docker pull $TEST_IMAGE
- docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod $TEST_IMAGE python -m nomad.cli client -n $CI_DEV_CLUSTER_PROXY/dev/nomad/$RELEASE_NAME/api -u admin -w $CI_NOMAD_ADMIN_PASSWORD integrationtests --skip-doi - docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod $TEST_IMAGE python -m nomad.cli client -n $CI_DEV_CLUSTER_PROXY/dev/nomad/$RELEASE_NAME/api -u admin -w $CI_NOMAD_ADMIN_PASSWORD integrationtests
except: except:
- /^dev-.*$/ - /^dev-.*$/
......
...@@ -175,7 +175,10 @@ class DatasetResource(Resource): ...@@ -175,7 +175,10 @@ class DatasetResource(Resource):
abort(404, 'Dataset with name %s does not exist for current user' % name) abort(404, 'Dataset with name %s does not exist for current user' % name)
if result.doi is not None and len(result.doi) > 0: if result.doi is not None and len(result.doi) > 0:
abort(400, 'Dataset with name %s has a DOI and cannot be deleted' % name) if g.user.is_admin:
DOI.objects(doi__in=result.doi).delete()
else:
abort(400, 'Dataset with name %s has a DOI and cannot be deleted' % name)
# edit all affected entries # edit all affected entries
edit( edit(
......
...@@ -419,7 +419,7 @@ class UploadResource(Resource): ...@@ -419,7 +419,7 @@ class UploadResource(Resource):
if upload.user_id != str(g.user.user_id) and not g.user.is_admin: if upload.user_id != str(g.user.user_id) and not g.user.is_admin:
abort(401, message='Upload with id %s does not belong to you.' % upload_id) abort(401, message='Upload with id %s does not belong to you.' % upload_id)
if upload.published: if upload.published and not g.user.is_admin:
abort(400, message='The upload is already published') abort(400, message='The upload is already published')
if upload.tasks_running: if upload.tasks_running:
......
...@@ -90,7 +90,8 @@ def handle_common_errors(func): ...@@ -90,7 +90,8 @@ def handle_common_errors(func):
@click.option('-w', '--password', default=nomad_config.client.password, help='the password used to login.') @click.option('-w', '--password', default=nomad_config.client.password, help='the password used to login.')
@click.option('--no-ssl-verify', help='disables SSL verificaton when talking to nomad.', is_flag=True) @click.option('--no-ssl-verify', help='disables SSL verificaton when talking to nomad.', is_flag=True)
@click.option('--no-token', is_flag=True, help='replaces token with basic auth, e.g. to work with v0.6.x or older API versions') @click.option('--no-token', is_flag=True, help='replaces token with basic auth, e.g. to work with v0.6.x or older API versions')
def client(url: str, user: str, password: str, no_ssl_verify: bool, no_token: bool): @click.pass_context
def client(ctx, url: str, user: str, password: str, no_ssl_verify: bool, no_token: bool):
logger = utils.get_logger(__name__) logger = utils.get_logger(__name__)
logger.info('Used nomad is %s' % url) logger.info('Used nomad is %s' % url)
...@@ -98,6 +99,8 @@ def client(url: str, user: str, password: str, no_ssl_verify: bool, no_token: bo ...@@ -98,6 +99,8 @@ def client(url: str, user: str, password: str, no_ssl_verify: bool, no_token: bo
nomad_config.client.url = url nomad_config.client.url = url
ctx.obj.user = user
global _create_client global _create_client
def _create_client(*args, **kwargs): # pylint: disable=W0612 def _create_client(*args, **kwargs): # pylint: disable=W0612
......
...@@ -183,11 +183,11 @@ def integrationtests(ctx, skip_parsers, skip_publish, skip_doi, skip_mirror): ...@@ -183,11 +183,11 @@ def integrationtests(ctx, skip_parsers, skip_publish, skip_doi, skip_mirror):
assert doi assert doi
has_doi = True has_doi = True
if not has_doi: if not has_doi or ctx.obj.user == 'admin':
print('deleting dataset') print('deleting dataset')
result = client.datasets.delete_dataset(name=dataset).response().result result = client.datasets.delete_dataset(name=dataset).response().result
if not skip_mirror: if not skip_mirror and ctx.obj.user == 'admin':
print('getting upload mirror') print('getting upload mirror')
# get_upload_mirror gives 404 # get_upload_mirror gives 404
payload = dict(query=dict(upload_id=upload.upload_id)) payload = dict(query=dict(upload_id=upload.upload_id))
...@@ -196,7 +196,7 @@ def integrationtests(ctx, skip_parsers, skip_publish, skip_doi, skip_mirror): ...@@ -196,7 +196,7 @@ def integrationtests(ctx, skip_parsers, skip_publish, skip_doi, skip_mirror):
assert len(client.mirror.get_upload_mirror(upload_id=upload.upload_id).response().result.calcs) > 0 assert len(client.mirror.get_upload_mirror(upload_id=upload.upload_id).response().result.calcs) > 0
finally: finally:
if not published: if not published or ctx.obj.user == 'admin':
print('delete the upload again') print('delete the upload again')
client.uploads.delete_upload(upload_id=upload.upload_id).response() client.uploads.delete_upload(upload_id=upload.upload_id).response()
while upload.process_running: while upload.process_running:
......
...@@ -625,14 +625,14 @@ class Upload(Proc): ...@@ -625,14 +625,14 @@ class Upload(Proc):
''' '''
logger = self.get_logger() logger = self.get_logger()
with utils.lnr(logger, 'staged upload delete failed'): with utils.lnr(logger, 'upload delete failed'):
with utils.timer( with utils.timer(
logger, 'upload deleted from index', step='index', logger, 'upload deleted from index', step='index',
upload_size=self.upload_files.size): upload_size=self.upload_files.size):
search.delete_upload(self.upload_id) search.delete_upload(self.upload_id)
with utils.timer( with utils.timer(
logger, 'staged upload deleted', step='files', logger, 'upload deleted', step='files',
upload_size=self.upload_files.size): upload_size=self.upload_files.size):
self.upload_files.delete() self.upload_files.delete()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment