Skip to content

Commit

Permalink
Allow users to update apps without packages as long as they are not
Browse files Browse the repository at this point in the history
requesting to start the app

[#151239418]

Signed-off-by: Annie Sing <asing@pivotal.io>
  • Loading branch information
Lisa Cho authored and Annie Sing committed Jan 10, 2018
1 parent 71c2adc commit ae13d42
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/actions/v2/app_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create(request_attrs)
)

validate_custom_buildpack!(process)
validate_package_is_uploaded!(process)
validate_package_exists!(process, request_attrs)

process.save

Expand Down Expand Up @@ -102,8 +102,8 @@ def custom_buildpacks_disabled?
VCAP::CloudController::Config.config.get(:disable_custom_buildpacks)
end

def validate_package_is_uploaded!(process)
if process.needs_package_in_current_state? && !process.package_available?
def validate_package_exists!(process, request_attrs)
if request_attrs['state'] == 'STARTED' && !process.package_available?
raise CloudController::Errors::ApiError.new_from_details('AppPackageInvalid', 'bits have not been uploaded')
end
end
Expand Down
7 changes: 3 additions & 4 deletions app/actions/v2/app_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def update(app, process, request_attrs)
update_app(app, request_attrs)
update_lifecycle(app, process, request_attrs)
assign_process_values(process, request_attrs)

validate_package_is_uploaded!(process)
validate_package_exists!(process, request_attrs)

process.save
app.reload
Expand Down Expand Up @@ -139,8 +138,8 @@ def validate_not_changing_lifecycle_type!(process, request_attrs)
end
end

def validate_package_is_uploaded!(process)
if process.needs_package_in_current_state? && !process.package_available?
def validate_package_exists!(process, request_attrs)
if request_attrs['state'] == 'STARTED' && !process.package_available?
raise CloudController::Errors::ApiError.new_from_details('AppPackageInvalid', 'bits have not been uploaded')
end
end
Expand Down
11 changes: 6 additions & 5 deletions app/models/runtime/process_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ def dea?
alias_method(:user_provided_ports, :ports)

def package_hash
return nil unless (cached_latest_package = latest_package)
package = latest_package
return nil if package.nil?

if cached_latest_package.bits?
cached_latest_package.package_hash
elsif cached_latest_package.docker?
cached_latest_package.image
if package.bits?
package.package_hash
elsif package.docker?
package.image
end
end

Expand Down
41 changes: 40 additions & 1 deletion spec/unit/actions/v2/app_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,45 @@ module VCAP::CloudController
expect(app.lifecycle_data.buildpacks).to eq(['http://example.com/buildpack'])
end

context 'with a started bits app and no valid package or droplet' do
let(:process) { ProcessModel.make(state: 'STARTED') }
let(:app) { process.app }
let(:new_stack) { Stack.make }

context 'not requesting a state change' do
it 'updates the process' do
request_attrs = {
'instances' => 2,
'stack_guid' => new_stack.guid,
}

app_update.update(app, process, request_attrs)

expect(process.instances).to eq(2)
expect(process.stack_guid).to eq(new_stack.guid)
end
end

context 'requesting state other than STARTED' do
it 'updates the process' do
request_attrs = {
'state' => 'STOPPED'
}

app_update.update(app, process, request_attrs)
expect(process.state).to eq('STOPPED')
end
end

context 'requesting a STARTED state' do
it 'raises an error' do
expect {
app_update.update(process.app, process, { 'state' => 'STARTED' })
}.to raise_error(/bits have not been uploaded/)
end
end
end

context 'updating buildpack' do
context 'when custom buildpacks are disabled' do
let(:process) { ProcessModel.make }
Expand Down Expand Up @@ -179,7 +218,7 @@ module VCAP::CloudController
end
end

context 'when the app needs staged' do
context 'when the app needs staging' do
let(:process) { ProcessModelFactory.make(state: 'STARTED') }

before do
Expand Down

0 comments on commit ae13d42

Please sign in to comment.