-
-
- <% processes(@container).each do |process| %>
-
-
+ <% if @container.uuid.present? %>
+ <% if @container.in_fog.ready? %>
+
+
+
+ <% processes = Docker::Container.get(@container.uuid).top %>
+
+ <% processes(@container).each do |process| %>
+
+
-index' class='collapse accordion-body'>
+
<%= JSON.pretty_generate(process) %>
+
+ <% end %>
+
-
-index' class='collapse accordion-body'>
-
<%= JSON.pretty_generate(process) %>
+
+
+ <%= logs(@container, :stdout => true, :tail => 100) %>
+
- <% end %>
-
-
-
- <%= logs(@container, :stdout => true, :tail => 100) %>
-
-
-
+ <% else %>
+
+
<%= _("Notice") %>
+
+ <%= _("Your container is stopped.") %>
+
<%= _("Please turn on your container to see processes running, logs, and more.") %>
+
+ <% end %>
<% else %>
<%= _("Notice") %>
- <%= _("Your container is stopped.") %>
-
<%= _("Please turn on your container to see processes running, logs, and more.") %>
+ <%= _("Your container is being provisioned.") %>
+
<%= _("Please wait until your image is pulled to the Docker host. You can track progress at Monitor > Tasks.") %>
<% end %>
diff --git a/foreman_docker.gemspec b/foreman_docker.gemspec
index cfebdd2..dff22fb 100644
--- a/foreman_docker.gemspec
+++ b/foreman_docker.gemspec
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
s.add_dependency 'docker-api', '1.17'
s.add_dependency 'wicked', '~> 1.1'
+ s.add_dependency 'foreman-tasks', '~> 0.6.0'
end
diff --git a/lib/foreman_docker/engine.rb b/lib/foreman_docker/engine.rb
index 58fbf83..547eacc 100644
--- a/lib/foreman_docker/engine.rb
+++ b/lib/foreman_docker/engine.rb
@@ -4,6 +4,7 @@
require 'fog/fogdocker'
require 'wicked'
require 'docker'
+require 'foreman-tasks'
module ForemanDocker
# Inherit from the Rails module of the parent app (Foreman), not the plugin.
@@ -14,6 +15,10 @@ class Engine < ::Rails::Engine
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
+ initializer "foreman_docker.require_dynflow", :before => "foreman_tasks.initialize_dynflow" do
+ ::ForemanTasks.dynflow.require!
+ end
+
initializer 'foreman_docker.load_app_instance_data' do |app|
app.config.paths['db/migrate'] += ForemanDocker::Engine.paths['db/migrate'].existent
end
diff --git a/test/actions/provision_test.rb b/test/actions/provision_test.rb
new file mode 100644
index 0000000..bb2329c
--- /dev/null
+++ b/test/actions/provision_test.rb
@@ -0,0 +1,58 @@
+require 'test_plugin_helper'
+
+module ForemanDocker
+ module Service
+ module Actions
+ module Container
+ class TestBase < ActiveSupport::TestCase
+ include Dynflow::Testing
+ include FactoryGirl::Syntax::Methods
+
+ let(:container) { FactoryGirl.create(:container) }
+ end
+
+ class ProvisionTest < TestBase
+ let(:action_class) { ForemanDocker::Service::Actions::Container::Provision }
+
+ it 'plans pull and start' do
+ action = create_action(action_class)
+ action.stubs(:action_subject).with(container)
+ plan_action(action, container)
+ %w(Pull Start).each do |container_action|
+ container_action = "ForemanDocker::Service::Actions::Container::#{container_action}"
+ assert_action_planed_with(action, container_action.constantize, container)
+ end
+ end
+ end
+
+ class PullTest < TestBase
+ let(:action_class) { ForemanDocker::Service::Actions::Container::Pull }
+
+ it 'pulls the container image' do
+ ::Container.expects(:find).returns(container)
+ container.compute_resource.expects(:create_image).returns(true)
+ action = create_action(action_class)
+ action.stubs(:action_subject).with(container)
+ plan_action(action, container)
+ run_action(action) { |dynflow_action| dynflow_action.expects(:pull_docker_image) }
+ action.pull_docker_image(container, []).join
+ end
+ end
+
+ class StartTest < TestBase
+ let(:action_class) { ForemanDocker::Service::Actions::Container::Start }
+
+ it 'starts the container' do
+ ::Container.expects(:find).returns(container)
+ container.compute_resource.expects(:create_container).returns(container)
+ action = create_action(action_class)
+ action.stubs(:action_subject).with(container)
+ plan_action(action, container)
+ assert_run_phase(action)
+ run_action(action)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/test/functionals/api/v2/containers_controller_test.rb b/test/functionals/api/v2/containers_controller_test.rb
index a505f66..c6edd6d 100644
--- a/test/functionals/api/v2/containers_controller_test.rb
+++ b/test/functionals/api/v2/containers_controller_test.rb
@@ -73,24 +73,23 @@ class ContainersControllerTest < ActionController::TestCase
repository_name = "centos"
tag = "7"
name = "foo"
- registry_uri = URI.parse(@registry.url)
- Service::Containers.any_instance.expects(:pull_image).returns(true)
- Service::Containers.any_instance
- .expects(:start_container).returns(true).with do |container|
- container.must_be_kind_of(Container)
- container.repository_name.must_equal(repository_name)
- container.tag.must_equal(tag)
- container.compute_resource_id.must_equal(@compute_resource.id)
- container.name.must_equal(name)
- container.repository_pull_url.must_include(registry_uri.host)
- container.repository_pull_url.must_include("#{repository_name}:#{tag}")
+ container_mock = mock('container')
+ container_mock.expects(:save).returns(true)
+ ForemanDocker::Service::Containers.any_instance
+ .expects(:start_container!).returns(container_mock).with do |wizard_state|
+ wizard_state.must_be_kind_of(DockerContainerWizardState)
+ container_attributes = wizard_state.container_attributes
+ container_attributes[:repository_name].must_equal(repository_name)
+ container_attributes[:tag].must_equal(tag)
+ container_attributes[:compute_resource_id].must_equal(@compute_resource.id)
+ container_attributes[:name].must_equal(name)
end
post :create, :container => { :compute_resource_id => @compute_resource.id,
:name => name,
:registry_id => @registry.id,
:repository_name => repository_name,
:tag => tag }
- assert_response :created
+ assert_response :success
end
test 'creates a katello container with correct params' do
@@ -102,7 +101,7 @@ class ContainersControllerTest < ActionController::TestCase
tag = "7"
name = "foo"
capsule_id = "10000"
- Service::Containers.any_instance.expects(:start_container!)
+ ForemanDocker::Service::Containers.any_instance.expects(:start_container!)
.returns(@container).with do |wizard_state|
wizard_state.must_be_kind_of(DockerContainerWizardState)
container_attributes = wizard_state.container_attributes
@@ -117,7 +116,7 @@ class ContainersControllerTest < ActionController::TestCase
:capsule_id => capsule_id,
:repository_name => repository_name,
:tag => tag }
- assert_response :created
+ assert_response :success
end
end
end
diff --git a/test/functionals/containers_steps_controller_test.rb b/test/functionals/containers_steps_controller_test.rb
index ef9ce2b..c8ae231 100644
--- a/test/functionals/containers_steps_controller_test.rb
+++ b/test/functionals/containers_steps_controller_test.rb
@@ -8,8 +8,8 @@ class StepsControllerTest < ActionController::TestCase
test 'wizard finishes with a redirect to the managed container' do
state = DockerContainerWizardState.create!
- Service::Containers.any_instance.expects(:start_container!).with(equals(state))
- .returns(@container)
+ ForemanDocker::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 } },
diff --git a/test/functionals/image_search_controller_test.rb b/test/functionals/image_search_controller_test.rb
index c062ed9..873748a 100644
--- a/test/functionals/image_search_controller_test.rb
+++ b/test/functionals/image_search_controller_test.rb
@@ -5,29 +5,28 @@ class ImageSearchControllerTest < ActionController::TestCase
@container = FactoryGirl.create(:docker_cr)
end
- [Docker::Error::DockerError, Excon::Errors::Error, Errno::ECONNREFUSED].each do |error|
- test 'auto_complete_repository_name catches exceptions on network errors' do
- ForemanDocker::Docker.any_instance.expects(:exist?).raises(error)
- get :auto_complete_repository_name, { :search => "test", :id => @container.id },
- set_session_user
- assert_response_is_expected
- end
+ context 'network errors' do
+ [Docker::Error::DockerError, Excon::Errors::Error, Errno::ECONNREFUSED].each do |error|
+ test 'auto_complete_repository_name catches exceptions on network errors' do
+ ::Docker::Image.expects(:exist?).raises(error)
+ get :auto_complete_repository_name, { :search => "test", :id => @container.id },
+ set_session_user
+ end
- test 'auto_complete_image_tag catch exceptions on network errors' do
- ForemanDocker::Docker.any_instance.expects(:tags).raises(error)
- get :auto_complete_image_tag, { :search => "test", :id => @container.id }, set_session_user
- assert_response_is_expected
- end
+ test 'auto_complete_image_tag catch exceptions on network errors' do
+ ForemanDocker::Docker.any_instance.expects(:tags).raises(error)
+ get :auto_complete_image_tag, { :search => "test", :id => @container.id }, set_session_user
+ end
- test 'search_repository catch exceptions on network errors' do
- ForemanDocker::Docker.any_instance.expects(:search).raises(error)
- get :search_repository, { :search => "test", :id => @container.id }, set_session_user
- assert_response_is_expected
+ test 'search_repository catch exceptions on network errors' do
+ ForemanDocker::Docker.any_instance.expects(:search).raises(error)
+ get :search_repository, { :search => "test", :id => @container.id }, set_session_user
+ end
end
- end
- def assert_response_is_expected
- assert_response :error
- assert response.body.include?('An error occured during repository search:')
+ teardown do
+ assert_response :error
+ assert response.body.include?('An error occured during repository search:')
+ end
end
end
diff --git a/test/test_plugin_helper.rb b/test/test_plugin_helper.rb
index 84a9b0e..3b92b94 100644
--- a/test/test_plugin_helper.rb
+++ b/test/test_plugin_helper.rb
@@ -9,6 +9,10 @@ def assert_row_button(index_path, link_text, button_text, dropdown = false)
end
end
+require 'dynflow/testing'
+Mocha::Mock.send :include, Dynflow::Testing::Mimic
+Dynflow::Testing.logger_adapter.level = 1
+
# Add plugin to FactoryGirl's paths
FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
FactoryGirl.reload
diff --git a/test/units/containers_service_test.rb b/test/units/containers_service_test.rb
index 39a416e..6170a87 100644
--- a/test/units/containers_service_test.rb
+++ b/test/units/containers_service_test.rb
@@ -12,14 +12,10 @@ class ContainersServiceTest < ActiveSupport::TestCase
end
end
- test 'removes current state after successful container creation' do
- ret = OpenStruct.new(:id => 1)
- ForemanDocker::Docker.any_instance.expects(:create_image).returns(ret).with do |subject|
- subject.must_equal(:fromImage => "test:test")
- end
- ForemanDocker::Docker.any_instance.expects(:create_container)
- .returns(OpenStruct.new(:uuid => 1))
- Service::Containers.new.start_container!(@state)
+ test 'removes current state after container creation task is scheduled' do
+ ForemanTasks.expects(:async_task).returns(true)
+ assert_equal DockerContainerWizardState.where(:id => @state.id).count, 1
+ ForemanDocker::Service::Containers.new.start_container!(@state)
assert_equal DockerContainerWizardState.where(:id => @state.id).count, 0
end
end