Skip to content

Commit

Permalink
Add continue link and tests
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Gunaratne <sam.gunaratne@broadcom.com>
Co-authored-by: Seth Boyles <seth.boyles@broadcom.com>
  • Loading branch information
Samze and sethboyles committed Jul 23, 2024
1 parent fda1d35 commit 563bd95
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/models/runtime/deployment_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ def before_update
end

def deploying?
state == DEPLOYING_STATE
# represents states that are still progressing forward
deploying_states = [DeploymentModel::DEPLOYING_STATE,
DeploymentModel::PAUSED_STATE,
DeploymentModel::PREPAUSED_STATE]
deploying_states.include?(state)
end

def cancelable?
valid_states_for_cancel = [DeploymentModel::DEPLOYING_STATE,
DeploymentModel::CANCELING_STATE]
DeploymentModel::CANCELING_STATE,
DeploymentModel::PAUSED_STATE,
DeploymentModel::PREPAUSED_STATE]
valid_states_for_cancel.include?(state)
end

Expand Down
7 changes: 7 additions & 0 deletions app/presenters/v3/deployment_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def build_links
method: 'POST'
}
end
end.tap do |links|
if deployment.continuable?
links[:continue] = {
href: url_builder.build_url(path: "/v3/deployments/#{deployment.guid}/actions/continue"),
method: 'POST'
}
end
end
end
end
Expand Down
76 changes: 73 additions & 3 deletions spec/request/deployments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,39 @@
h
end

context 'PAUSED deployment' do
let(:user) { make_developer_for_space(space) }
let(:deployment) do
VCAP::CloudController::DeploymentModelTestFactory.make(
app: app_model,
droplet: droplet,
previous_droplet: old_droplet,
strategy: 'canary',
state: VCAP::CloudController::DeploymentModel::PAUSED_STATE,
status_value: VCAP::CloudController::DeploymentModel::ACTIVE_STATUS_VALUE,
status_reason: VCAP::CloudController::DeploymentModel::PAUSED_STATUS_REASON
)
end

it 'includes the continue action in the links' do
get "/v3/deployments/#{deployment.guid}", nil, user_header
parsed_response = Oj.load(last_response.body)
expect(parsed_response['links']['continue']).to eq({
'href' => "#{link_prefix}/v3/deployments/#{deployment.guid}/actions/continue",
'method' => 'POST'
})
end

it 'includes the cancel action in the links' do
get "/v3/deployments/#{deployment.guid}", nil, user_header
parsed_response = Oj.load(last_response.body)
expect(parsed_response['links']['cancel']).to eq({
'href' => "#{link_prefix}/v3/deployments/#{deployment.guid}/actions/cancel",
'method' => 'POST'
})
end
end

it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end

Expand Down Expand Up @@ -1580,14 +1613,51 @@ def json_for_deployment(deployment, app_model, droplet, status_value, status_rea
end
end

context 'when the deployment is in a deploying state' do
let(:user) { make_developer_for_space(space) }
let(:state) { VCAP::CloudController::DeploymentModel::DEPLOYING_STATE }

it 'returns 422 with an error' do
post "/v3/deployments/#{deployment.guid}/actions/continue", {}.to_json, user_header
expect(last_response.status).to eq(422), last_response.body
end
end

context 'when the deployment is in a canceling state' do
let(:user) { make_developer_for_space(space) }
let(:state) { VCAP::CloudController::DeploymentModel::CANCELING_STATE }

it 'returns 422 with an error' do
post "/v3/deployments/#{deployment.guid}/actions/continue", {}.to_json, user_header
expect(last_response.status).to eq(422), last_response.body
end
end

context 'when the deployment is in a deployed state' do
let(:user) { make_developer_for_space(space) }
let(:state) { VCAP::CloudController::DeploymentModel::DEPLOYED_STATE }

it 'returns 422 with an error' do
post "/v3/deployments/#{deployment.guid}/actions/continue", {}.to_json, user_header
expect(last_response.status).to eq(422), last_response.body
end
end

context 'when the deployment is in a canceled state' do
let(:user) { make_developer_for_space(space) }
let(:state) { VCAP::CloudController::DeploymentModel::CANCELED_STATE }

it 'returns 422 with an error' do
post "/v3/deployments/#{deployment.guid}/actions/continue", {}.to_json, user_header
expect(last_response.status).to eq(422), last_response.body
end
end
# TODO how much do we want to test here ?
#
# context 'when the deployment is not a canary' do
# note from Seth: I don't think we need this case, what if we add the `pause` action :)
# let(:state) { VCAP::CloudController::DeploymentModel::PREPAUSED_STATE }

# end
# context 'when the deployment is not in a state where it will never pause' do
# let(:state) { VCAP::CloudController::DeploymentModel::DEPLOYING_STATE }
# end

# context 'when the deployment is superseeded' do
Expand Down
23 changes: 23 additions & 0 deletions spec/unit/models/runtime/deployment_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ module VCAP::CloudController
expect(deployment.deploying?).to be(true)
end

it 'returns true if the deployment is PAUSED' do
deployment.state = DeploymentModel::PAUSED_STATE

expect(deployment.deploying?).to be(true)
end

it 'returns true if the deployment is PREPAUSED' do
deployment.state = DeploymentModel::PREPAUSED_STATE

expect(deployment.deploying?).to be(true)
end
it 'returns false if the deployment has been deployed' do
deployment.state = 'DEPLOYED'

Expand All @@ -85,6 +96,18 @@ module VCAP::CloudController
expect(deployment.cancelable?).to be(true)
end

it 'returns true if the deployment is PAUSED' do
deployment.state = DeploymentModel::PAUSED_STATE

expect(deployment.cancelable?).to be(true)
end

it 'returns true if the deployment is PREPAUSED' do
deployment.state = DeploymentModel::PREPAUSED_STATE

expect(deployment.cancelable?).to be(true)
end

it 'returns false if the deployment is DEPLOYED' do
deployment.state = DeploymentModel::DEPLOYED_STATE

Expand Down

0 comments on commit 563bd95

Please sign in to comment.