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

Check S3 bucket name and add possibility to retry failed deployment #28

Open
wants to merge 13 commits into
base: pre-production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
88 changes: 88 additions & 0 deletions app/deployments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,94 @@ def createdep():
return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))


@deployments_bp.route("/<depid>/retry")
@auth.authorized_with_valid_token
def retrydep(depid=None):
"""
A function to retry a failed deployment.
Parameters:
- depid: str, the ID of the deployment
"""
tosca_info, _, _ = tosca.get()
access_token = iam.token["access_token"]

# retrieve deployment from DB
dep = dbhelpers.get_deployment(depid)
if dep is None:
return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))

inputs = process_deployment_data(dep)[0]
if dep is None or dep.selected_template == "":
ettore-infn marked this conversation as resolved.
Show resolved Hide resolved
flash(
"The selected deployment is invalid. Try creating it from scratch.", "danger"
)
return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))

# Get the max num retry for the new name
max_num_retry = 0
str_retry = " retry_"
tmp_name = dep.description.split(str_retry)[0]
deps = dbhelpers.get_user_deployments(session["userid"])

for tmp_dep in deps:
if (tmp_name + str_retry in tmp_dep.description and 'DELETE' not in tmp_dep.status):
ettore-infn marked this conversation as resolved.
Show resolved Hide resolved
num_retry = int(tmp_dep.description.split(str_retry)[1])

if num_retry > max_num_retry:
max_num_retry = num_retry

additionaldescription = tmp_name + str_retry + str(max_num_retry + 1)

source_template = tosca_info[dep.selected_template]
ettore-infn marked this conversation as resolved.
Show resolved Hide resolved
form_data = inputs
template, template_text = load_template(dep.selected_template)

uuidgen_deployment = str(uuid_generator.uuid1())

doprocess, inputs, stinputs = process_inputs(
source_template, inputs, form_data, uuidgen_deployment
)

# If input is a bucket_name check for validity
for name in inputs:
if search("bucket_name", name):
errors = check_s3_bucket_name(uuidgen_deployment + "-" + inputs[name])

if errors:
for error in errors:
flash(error, "danger")
return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))

app.logger.debug(f"Calling orchestrator with inputs: {inputs}")

if doprocess:
storage_encryption, vault_secret_uuid, vault_secret_key = (
add_storage_encryption(access_token, inputs)
)
params = {} # is it needed??
create_deployment(
template,
inputs,
stinputs,
form_data,
dep.selected_template,
source_template,
template_text,
additionaldescription,
params,
storage_encryption,
vault_secret_uuid,
vault_secret_key,
)

flash(
f"Retry action for deployment {dep.description} <{depid}> successfully triggered!",
"success",
)

return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))


def check_s3_bucket_name(name):
"""
Validates an S3 bucket name based on the given rules.
Expand Down
5 changes: 5 additions & 0 deletions app/deployments/templates/deployments.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
{% if 'CREATE_FAILED' in deployment.status %}
<a class="dropdown-item" href="{{ url_for('deployments_bp.retrydep', depid=deployment.uuid) }}">
<span class="fas fa-sync-alt mr-2 grey-text"></span>Retry
</a>
{% endif %}
<a class="dropdown-item" data-toggle="modal" data-target="#editDeployment" data-id="{{ deployment.uuid }}" data-description="{{ deployment.description }}" data-action="{{ url_for('deployments_bp.editdeployment') }}">
<span class="fas fa-edit mr-2 grey-text"></span>Edit</a>
<a class="dropdown-item" href="{{ url_for('deployments_bp.deptemplate', depid=deployment.uuid) }}"><span class="fas fa-search mr-2 grey-text"></span>Show template</a>
Expand Down
4 changes: 2 additions & 2 deletions app/lib/dbhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def updatedeploymentsstatus(deployments, userid):
template_parameters="",
template_metadata="",
selected_template="",
inputs="",
stinputs="",
inputs=json.dumps(dep_json["inputs"]),
stinputs=json.dumps(dep_json["stinputs"]),
params="",
deployment_type=getdeploymenttype(dep_json),
provider_name=providername,
Expand Down