Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
fixes #9033: errors encountered in new container wizard are being sho…
Browse files Browse the repository at this point in the history
…wn now
  • Loading branch information
dmitri-d authored and dLobatog committed Jan 28, 2015
1 parent 16234b2 commit 63ae5d9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
12 changes: 8 additions & 4 deletions app/controllers/containers/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def find_state
end

def build_state
@state.send(:"build_#{step}", params[:"docker_container_wizard_states_#{step}"])
s = @state.send(:"build_#{step}", params[:"docker_container_wizard_states_#{step}"])
instance_variable_set("@docker_container_wizard_states_#{step}", s)
end

def set_form
Expand All @@ -42,12 +43,15 @@ def set_form

def create_container
@state.send(:"create_#{step}", params[:"docker_container_wizard_states_#{step}"])
container = Service::Containers.start_container!(@state)
container = (service = Service::Containers.new).start_container!(@state)
if container.present?
process_success(:object => container, :success_redirect => container_path(container))
else
@environment = @state.environment
process_error(:object => @state.environment, :render => 'environment')
@docker_container_wizard_states_environment = @state.environment
process_error(
:error_msg => service.errors,
:object => @state.environment,
:render => 'environment')
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/docker_container_wizard_states/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ class Configuration < ActiveRecord::Base
self.table_name_prefix = 'docker_container_wizard_states_'
belongs_to :wizard_state, :class_name => DockerContainerWizardState,
:foreign_key => :docker_container_wizard_state_id

validates :name, :presence => true
validates :command, :presence => true
end
end
20 changes: 14 additions & 6 deletions app/models/service/containers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Service
class Containers
def self.start_container!(wizard_state)
def errors
@errors ||= []
end

def start_container!(wizard_state)
ActiveRecord::Base.transaction do
container = Container.new(wizard_state.container_attributes) do |r|
# eagerly load environment variables
Expand All @@ -24,17 +28,21 @@ def self.start_container!(wizard_state)
end
end

def self.pull_image(container)
ForemanTasks.async_task(::Service::Actions::ComputeResource::Pull, container)
def pull_image(container)
container.compute_resource.create_image(:fromImage => container.repository_pull_url)
end

def self.start_container(container)
def start_container(container)
started = container.compute_resource.create_container(container.parametrize)
container.uuid = started.id if started
if started
container.uuid = started.id
else
errors << container.compute_resource.errors[:base]
end
started
end

def self.destroy_wizard_state(wizard_state)
def destroy_wizard_state(wizard_state)
wizard_state.destroy
DockerContainerWizardState.destroy_all(["updated_at < ?", (Time.now - 24.hours)])
end
Expand Down
3 changes: 2 additions & 1 deletion test/functionals/containers_steps_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class StepsControllerTest < ActionController::TestCase

test 'wizard finishes with a redirect to the managed container' do
state = DockerContainerWizardState.create!
Service::Containers.expects(:start_container!).with(equals(state)).returns(@container)
Service::Containers.any_instance.expects(:start_container!).with(equals(state))
.returns(@container)
put :update, { :wizard_state_id => state.id,
:id => :environment,
:docker_container_wizard_states_environment => { :tty => false } },
Expand Down
4 changes: 2 additions & 2 deletions test/units/containers_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ContainersServiceTest < ActiveSupport::TestCase
:locations => [taxonomies(:location1)],
:organizations => [taxonomies(:organization1)])
s.build_image(:repository_name => 'test', :tag => 'test')
s.build_configuration(:name => 'test')
s.build_configuration(:name => 'test', :command => '/bin/bash')
s.build_environment(:tty => false)
end
end
Expand All @@ -19,7 +19,7 @@ class ContainersServiceTest < ActiveSupport::TestCase
end
ForemanDocker::Docker.any_instance.expects(:create_container)
.returns(OpenStruct.new(:uuid => 1))
Service::Containers.start_container!(@state)
Service::Containers.new.start_container!(@state)
assert_equal DockerContainerWizardState.where(:id => @state.id).count, 0
end
end

0 comments on commit 63ae5d9

Please sign in to comment.