foreman_docker 3.2.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/app/controllers/api/v2/containers_controller.rb +4 -6
- data/app/controllers/api/v2/registries_controller.rb +1 -1
- data/app/controllers/containers/steps_controller.rb +3 -3
- data/app/controllers/containers_controller.rb +2 -2
- data/app/controllers/registries_controller.rb +1 -1
- data/app/models/container.rb +1 -1
- data/app/models/docker_container_wizard_state.rb +1 -1
- data/app/models/docker_container_wizard_states/configuration.rb +1 -1
- data/app/models/docker_container_wizard_states/environment.rb +1 -1
- data/app/models/docker_container_wizard_states/image.rb +1 -1
- data/app/models/docker_container_wizard_states/preliminary.rb +1 -1
- data/app/models/docker_parameter.rb +1 -1
- data/app/models/docker_registry.rb +1 -1
- data/app/models/foreman_docker/docker.rb +1 -1
- data/app/models/service/registry_api.rb +3 -2
- data/db/migrate/20140930175337_add_email_to_compute_resource.rb +1 -1
- data/db/migrate/20141005233312_create_containers.rb +1 -1
- data/db/migrate/20141007225130_add_compute_resource_id_to_container.rb +1 -1
- data/db/migrate/20141009001613_add_tag_to_container.rb +1 -1
- data/db/migrate/20141009011026_add_attributes_to_container.rb +1 -1
- data/db/migrate/20141010173220_create_docker_images.rb +1 -1
- data/db/migrate/20141018110810_add_uuid_to_containers.rb +1 -1
- data/db/migrate/20141024163003_create_docker_registries.rb +1 -1
- data/db/migrate/20141028164206_change_memory_in_container.rb +1 -1
- data/db/migrate/20141028164633_change_cpuset_in_container.rb +1 -1
- data/db/migrate/20141120123003_add_user_credentials_to_docker_registries.rb +1 -1
- data/db/migrate/20141209182008_remove_docker_tables.rb +1 -1
- data/db/migrate/20141222113313_create_wizard_states.rb +1 -1
- data/db/migrate/20150122011747_add_katello_flag_to_docker_wizard_image.rb +1 -1
- data/db/migrate/20150129054944_add_katello_flag_to_containers.rb +1 -1
- data/db/migrate/20150303175646_remove_katello_flag_from_containers.rb +1 -1
- data/db/migrate/20150814205620_change_container_column_type.rb +1 -1
- data/db/migrate/20160605133025_create_docker_parameters.rb +1 -1
- data/db/migrate/20160605134652_move_parameters_to_docker_parameters.rb +3 -3
- data/db/migrate/20170508130316_add_verify_ssl_option_to_docker_registries.rb +1 -1
- data/lib/foreman_docker/engine.rb +1 -0
- data/lib/foreman_docker/version.rb +1 -1
- data/test/factories/compute_resources.rb +1 -1
- data/test/factories/containers.rb +1 -1
- data/test/factories/docker_registry.rb +3 -3
- data/test/functionals/api/v2/containers_controller_test.rb +34 -34
- data/test/functionals/api/v2/registries_controller_test.rb +11 -11
- data/test/functionals/containers_controller_test.rb +14 -18
- data/test/functionals/containers_steps_controller_test.rb +8 -12
- data/test/functionals/image_search_controller_test.rb +2 -2
- data/test/integration/container_steps_test.rb +2 -2
- data/test/integration/container_test.rb +1 -1
- data/test/integration/registry_creation_test.rb +1 -1
- data/test/test_plugin_helper.rb +3 -3
- data/test/units/container_remover_test.rb +1 -1
- data/test/units/containers_service_test.rb +1 -1
- data/test/units/docker_container_wizard_states/image_test.rb +2 -2
- data/test/units/docker_registry_test.rb +6 -6
- data/test/units/foreman_docker/docker_test.rb +1 -0
- data/test/units/image_search_service_test.rb +2 -2
- data/test/units/registry_api_test.rb +4 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e552869e1ab0cfde41332e6ab9717d5f13415d70
|
4
|
+
data.tar.gz: e00b20498e799f4b647ada00f7778b45b25bc230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6162d8977618e99eed69ff55308f00d1f1983288d5cadd801c6a3aeebb2f10aae1e48d1225568ea34d38bc4463dc0ab5efb58b35bf584a51a21b658cbd74bd99
|
7
|
+
data.tar.gz: 6121f40a5b10d66b9aafee7a498ed16966c9db755a695eeb0b71eb4b97a63801d4e276944dea02b49bfe7fa93bcc3a06a9f8b1189a7960ff74ad6384315597ae
|
data/.rubocop.yml
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
class ContainersController < ::Api::V2::BaseController
|
5
|
-
|
5
|
+
before_action :find_resource, :except => %w(index create)
|
6
6
|
|
7
7
|
resource_description do
|
8
8
|
resource_id 'containers'
|
@@ -17,11 +17,9 @@ module Api
|
|
17
17
|
param_group :search_and_pagination, ::Api::V2::BaseController
|
18
18
|
|
19
19
|
def index
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
scoped = Container.where(compute_resource_id)
|
24
|
-
@containers = scoped.search_for(params[:search], :order => params[:order])
|
20
|
+
scope = resource_scope
|
21
|
+
scope = scope.where(:compute_resource => params[:compute_resource_id]) if params[:compute_resource_id].present?
|
22
|
+
@containers = scope.search_for(params[:search], :order => params[:order])
|
25
23
|
.paginate(:page => params[:page])
|
26
24
|
end
|
27
25
|
|
@@ -2,7 +2,7 @@ module Api
|
|
2
2
|
module V2
|
3
3
|
class RegistriesController < ::Api::V2::BaseController
|
4
4
|
include Foreman::Controller::Parameters::DockerRegistry
|
5
|
-
|
5
|
+
before_action :find_resource, :except => %w(index create)
|
6
6
|
|
7
7
|
resource_description do
|
8
8
|
resource_id 'registries'
|
@@ -5,9 +5,9 @@ module Containers
|
|
5
5
|
|
6
6
|
steps :preliminary, :image, :configuration, :environment
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
before_action :find_state
|
9
|
+
before_action :build_state, :only => [:update]
|
10
|
+
before_action :set_form, :only => [:show]
|
11
11
|
|
12
12
|
def show
|
13
13
|
@container_resources = allowed_resources if step == :preliminary
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ContainersController < ::ApplicationController
|
2
2
|
include ForemanDocker::FindContainer
|
3
3
|
|
4
|
-
|
4
|
+
before_action :find_container, :only => [:show, :commit, :power]
|
5
5
|
|
6
6
|
def index
|
7
7
|
@container_resources = allowed_resources
|
@@ -100,7 +100,7 @@ class ContainersController < ::ApplicationController
|
|
100
100
|
|
101
101
|
def container_deletion
|
102
102
|
# TODO: Refactor to recognize params[:compute_resource_id] as well.
|
103
|
-
compute_resource_id = params[:compute_resource_id].
|
103
|
+
compute_resource_id = params[:compute_resource_id].present? ? params[:compute_resource_id] : nil
|
104
104
|
if compute_resource_id
|
105
105
|
container_uuid = params[:id]
|
106
106
|
@container ||= Container.authorized("#{action_permission}_#{controller_name}".to_sym).find_by_uuid(container_uuid)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class RegistriesController < ::ApplicationController
|
2
2
|
include Foreman::Controller::AutoCompleteSearch
|
3
3
|
include Foreman::Controller::Parameters::DockerRegistry
|
4
|
-
|
4
|
+
before_action :find_registry, :only => [:edit, :update, :destroy]
|
5
5
|
|
6
6
|
def index
|
7
7
|
@registries = DockerRegistry.search_for(params[:search], :order => params[:order])
|
data/app/models/container.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class DockerContainerWizardState <
|
1
|
+
class DockerContainerWizardState < ApplicationRecord
|
2
2
|
has_one :preliminary, :class_name => DockerContainerWizardStates::Preliminary,
|
3
3
|
:dependent => :destroy, :validate => true, :autosave => true
|
4
4
|
has_one :image, :class_name => DockerContainerWizardStates::Image,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module DockerContainerWizardStates
|
2
|
-
class Configuration <
|
2
|
+
class Configuration < ApplicationRecord
|
3
3
|
self.table_name_prefix = 'docker_container_wizard_states_'
|
4
4
|
belongs_to :wizard_state, :class_name => DockerContainerWizardState,
|
5
5
|
:foreign_key => :docker_container_wizard_state_id
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module DockerContainerWizardStates
|
2
|
-
class Image <
|
2
|
+
class Image < ApplicationRecord
|
3
3
|
self.table_name_prefix = 'docker_container_wizard_states_'
|
4
4
|
belongs_to :wizard_state, :class_name => DockerContainerWizardState,
|
5
5
|
:foreign_key => :docker_container_wizard_state_id
|
@@ -2,7 +2,7 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module ForemanDocker
|
4
4
|
class Docker < ::ComputeResource
|
5
|
-
validates :url, :format => { :with => URI.regexp }
|
5
|
+
validates :url, :format => { :with => URI.regexp }, :presence => true
|
6
6
|
validates :email, :format => { :with => /.+@.+\..+/i }, :allow_blank => true
|
7
7
|
|
8
8
|
def self.model_name
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Service
|
2
2
|
class RegistryApi
|
3
|
-
DOCKER_HUB = 'https://
|
3
|
+
DOCKER_HUB = 'https://index.docker.io/'.freeze
|
4
4
|
DEFAULTS = {
|
5
5
|
url: 'http://localhost:5000'.freeze,
|
6
|
-
connection: { omit_default_port: true
|
6
|
+
connection: { omit_default_port: true,
|
7
|
+
headers: { "Content-Type" => "application/json" }}
|
7
8
|
}
|
8
9
|
|
9
10
|
attr_accessor :config, :url
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class MoveParametersToDockerParameters < ActiveRecord::Migration
|
2
|
-
class FakeDockerParameter <
|
1
|
+
class MoveParametersToDockerParameters < ActiveRecord::Migration[4.2]
|
2
|
+
class FakeDockerParameter < ApplicationRecord
|
3
3
|
self.table_name = 'docker_parameters'
|
4
4
|
end
|
5
5
|
|
6
|
-
class FakeParameter <
|
6
|
+
class FakeParameter < ApplicationRecord
|
7
7
|
self.table_name = 'parameters'
|
8
8
|
end
|
9
9
|
|
@@ -47,6 +47,7 @@ module ForemanDocker
|
|
47
47
|
compute_resource ForemanDocker::Docker
|
48
48
|
|
49
49
|
sub_menu :top_menu, :containers_menu, :caption => N_('Containers'),
|
50
|
+
:icon => 'fa fa-cube',
|
50
51
|
:after => :monitor_menu do
|
51
52
|
menu :top_menu, :containers, :caption => N_('All Containers'),
|
52
53
|
:url_hash => { :controller => :containers,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory :docker_registry do
|
3
3
|
sequence(:name) { |n| "hub#{n}" }
|
4
4
|
sequence(:url) { |n| "http://localhost/#{n}" }
|
@@ -11,10 +11,10 @@ FactoryGirl.define do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
trait :with_location do
|
14
|
-
locations { [
|
14
|
+
locations { [FactoryBot.build(:location)] }
|
15
15
|
end
|
16
16
|
|
17
17
|
trait :with_organization do
|
18
|
-
organizations { [
|
18
|
+
organizations { [FactoryBot.build(:organization)] }
|
19
19
|
end
|
20
20
|
end
|
@@ -9,38 +9,38 @@ module Api
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test 'index returns a list of all containers' do
|
12
|
-
get :index,
|
12
|
+
get :index, session: set_session_user
|
13
13
|
assert_response :success
|
14
14
|
assert_template 'index'
|
15
15
|
end
|
16
16
|
|
17
17
|
test 'index can be filtered by name' do
|
18
18
|
%w(thomas clayton wolfe).each do |name|
|
19
|
-
|
19
|
+
FactoryBot.create(:container, :name => name)
|
20
20
|
end
|
21
|
-
get :index, { :search => 'name = thomas' }, set_session_user
|
21
|
+
get :index, params: { :search => 'name = thomas' }, session: set_session_user
|
22
22
|
assert_response :success
|
23
23
|
assert_equal 1, assigns(:containers).length
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'container operations' do
|
27
27
|
setup do
|
28
|
-
@container =
|
29
|
-
@registry =
|
30
|
-
@compute_resource =
|
28
|
+
@container = FactoryBot.create(:container, :name => 'foo')
|
29
|
+
@registry = FactoryBot.create(:docker_registry)
|
30
|
+
@compute_resource = FactoryBot.create(:docker_cr)
|
31
31
|
end
|
32
32
|
|
33
33
|
test 'logs returns latest lines of container log' do
|
34
34
|
fake_container = Struct.new(:logs)
|
35
35
|
fake_container.expects(:logs).returns('I am a log').twice
|
36
36
|
Docker::Container.expects(:get).with(@container.uuid).returns(fake_container)
|
37
|
-
get :logs, :id => @container.id
|
37
|
+
get :logs, params: { :id => @container.id }
|
38
38
|
assert_response :success
|
39
39
|
assert_equal ActiveSupport::JSON.decode(response.body)['logs'], fake_container.logs
|
40
40
|
end
|
41
41
|
|
42
42
|
test 'show returns information about container' do
|
43
|
-
get :show, :id => @container.id
|
43
|
+
get :show, params: { :id => @container.id }
|
44
44
|
assert_response :success
|
45
45
|
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
46
46
|
end
|
@@ -52,7 +52,7 @@ module Api
|
|
52
52
|
|
53
53
|
test 'delete removes a container in foreman and in Docker host' do
|
54
54
|
Fog.mock!
|
55
|
-
delete :destroy, :id => @container.id
|
55
|
+
delete :destroy, params: { :id => @container.id }
|
56
56
|
Fog.unmock!
|
57
57
|
assert_response :success
|
58
58
|
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
@@ -62,7 +62,7 @@ module Api
|
|
62
62
|
ComputeResource.any_instance.expects(:destroy_vm).
|
63
63
|
with('randomuuid').
|
64
64
|
raises(::Foreman::Exception.new('Problem removing container'))
|
65
|
-
delete :destroy, :id => @container.id
|
65
|
+
delete :destroy, params: { :id => @container.id }
|
66
66
|
assert_response :precondition_failed
|
67
67
|
end
|
68
68
|
end
|
@@ -73,20 +73,20 @@ module Api
|
|
73
73
|
|
74
74
|
test 'power call turns on/off container in Docker host' do
|
75
75
|
Fog::Compute::Fogdocker::Server.any_instance.expects(:start)
|
76
|
-
put :power, :id => @container.id, :power_action => 'start'
|
76
|
+
put :power, params: { :id => @container.id, :power_action => 'start' }
|
77
77
|
assert_response :success
|
78
78
|
end
|
79
79
|
|
80
80
|
test 'power call checks status of container in Docker host' do
|
81
81
|
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
82
|
-
put :power, :id => @container.id, :power_action => 'status'
|
82
|
+
put :power, params: { :id => @container.id, :power_action => 'status' }
|
83
83
|
assert_response :success
|
84
84
|
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
85
85
|
end
|
86
86
|
|
87
87
|
test 'power call host' do
|
88
88
|
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
89
|
-
put :power, :id => @container.id, :power_action => 'status'
|
89
|
+
put :power, params: { :id => @container.id, :power_action => 'status' }
|
90
90
|
assert_response :success
|
91
91
|
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
92
92
|
end
|
@@ -107,11 +107,11 @@ module Api
|
|
107
107
|
container.repository_pull_url.must_include(registry_uri.host)
|
108
108
|
container.repository_pull_url.must_include("#{repository_name}:#{tag}")
|
109
109
|
end
|
110
|
-
post :create, :container => { :compute_resource_id => @compute_resource.id,
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
post :create, params: { :container => { :compute_resource_id => @compute_resource.id,
|
111
|
+
:name => name,
|
112
|
+
:registry_id => @registry.id,
|
113
|
+
:repository_name => repository_name,
|
114
|
+
:tag => tag } }
|
115
115
|
assert_response :created
|
116
116
|
end
|
117
117
|
|
@@ -121,12 +121,12 @@ module Api
|
|
121
121
|
name = "foo2"
|
122
122
|
Service::Containers.any_instance.expects(:pull_image).returns(true)
|
123
123
|
Service::Containers.any_instance.expects(:start_container).returns(true)
|
124
|
-
post :create, :container => { :compute_resource_id => @compute_resource.id,
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
124
|
+
post :create, params: { :container => { :compute_resource_id => @compute_resource.id,
|
125
|
+
:name => name,
|
126
|
+
:registry_id => @registry.id,
|
127
|
+
:repository_name => repository_name,
|
128
|
+
:tag => tag,
|
129
|
+
:environment_variables => [{:key => 'ping_host', :value => 'example.com'}]} }
|
130
130
|
assert_response :created
|
131
131
|
end
|
132
132
|
end
|
@@ -150,20 +150,20 @@ module Api
|
|
150
150
|
container_attributes[:name].must_equal(name)
|
151
151
|
wizard_state.image.capsule_id.must_equal(capsule_id)
|
152
152
|
end
|
153
|
-
post :create, :container => { :compute_resource_id => @compute_resource.id,
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
post :create, params: { :container => { :compute_resource_id => @compute_resource.id,
|
154
|
+
:name => name,
|
155
|
+
:capsule_id => capsule_id,
|
156
|
+
:repository_name => repository_name,
|
157
|
+
:tag => tag } }
|
158
158
|
assert_response :created
|
159
159
|
end
|
160
160
|
|
161
161
|
test 'creation fails with invalid container name' do
|
162
|
-
post :create, :container => { :compute_resource_id => @container.compute_resource_id,
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
post :create, params: { :container => { :compute_resource_id => @container.compute_resource_id,
|
163
|
+
:name => @container.name,
|
164
|
+
:registry_id => @registry.id,
|
165
|
+
:repository_name => 'centos',
|
166
|
+
:tag => 'latest' } }
|
167
167
|
assert_response :unprocessable_entity
|
168
168
|
assert_match /Name has already been taken/, @response.body
|
169
169
|
end
|
@@ -4,53 +4,53 @@ module Api
|
|
4
4
|
module V2
|
5
5
|
class RegistriesControllerTest < ActionController::TestCase
|
6
6
|
setup do
|
7
|
-
@registry =
|
7
|
+
@registry = FactoryBot.create(:docker_registry)
|
8
8
|
end
|
9
9
|
|
10
10
|
test 'index returns a list of all containers' do
|
11
|
-
get :index,
|
11
|
+
get :index, session: set_session_user
|
12
12
|
assert_response :success
|
13
13
|
assert_template 'index'
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'index can be filtered by name' do
|
17
17
|
%w(thomas clayton wolfe).each do |name|
|
18
|
-
|
18
|
+
FactoryBot.create(:docker_registry, :name => name)
|
19
19
|
end
|
20
|
-
get :index, { :search => 'name = thomas' }, set_session_user
|
20
|
+
get :index, params: { :search => 'name = thomas' }, session: set_session_user
|
21
21
|
assert_response :success
|
22
22
|
assert_equal 1, assigns(:registries).length
|
23
23
|
end
|
24
24
|
|
25
25
|
test 'creates a new registry with valid params' do
|
26
|
-
docker_attrs =
|
26
|
+
docker_attrs = FactoryBot.attributes_for(:docker_registry)
|
27
27
|
DockerRegistry.any_instance.stubs(:attempt_login)
|
28
|
-
post :create, :registry => docker_attrs
|
28
|
+
post :create, params: { :registry => docker_attrs }
|
29
29
|
assert_response :success
|
30
30
|
end
|
31
31
|
|
32
32
|
test 'does not create a new registry with invalid params' do
|
33
|
-
docker_attrs =
|
33
|
+
docker_attrs = FactoryBot.attributes_for(:docker_registry)
|
34
34
|
docker_attrs.delete(:name)
|
35
|
-
post :create, :registry => docker_attrs
|
35
|
+
post :create, params: { :registry => docker_attrs }
|
36
36
|
assert_response 422
|
37
37
|
end
|
38
38
|
|
39
39
|
test 'shows a docker registry' do
|
40
|
-
get :show, :id => @registry.id
|
40
|
+
get :show, params: { :id => @registry.id }
|
41
41
|
assert_response :success
|
42
42
|
end
|
43
43
|
|
44
44
|
test 'update a docker registry' do
|
45
45
|
DockerRegistry.any_instance.stubs(:attempt_login)
|
46
46
|
new_name = 'hello_world'
|
47
|
-
put :update, :id => @registry.id, :registry => { :name => new_name }
|
47
|
+
put :update, params: { :id => @registry.id, :registry => { :name => new_name } }
|
48
48
|
assert_response :success
|
49
49
|
assert_equal new_name, @registry.reload.name
|
50
50
|
end
|
51
51
|
|
52
52
|
test 'deletes a docker registry' do
|
53
|
-
delete :destroy, :id => @registry.id
|
53
|
+
delete :destroy, params: { :id => @registry.id }
|
54
54
|
assert_response :success
|
55
55
|
assert DockerRegistry.where(:id => @registry.id).blank?
|
56
56
|
end
|
@@ -7,7 +7,7 @@ class ContainersControllerTest < ActionController::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'redirect if Docker provider is not available' do
|
10
|
-
get :index,
|
10
|
+
get :index, session: set_session_user
|
11
11
|
assert_redirected_to new_compute_resource_path
|
12
12
|
end
|
13
13
|
|
@@ -15,15 +15,15 @@ class ContainersControllerTest < ActionController::TestCase
|
|
15
15
|
Fog.mock!
|
16
16
|
# Avoid rendering errors by not retrieving any container
|
17
17
|
ComputeResource.any_instance.stubs(:vms).returns([])
|
18
|
-
|
19
|
-
get :index,
|
18
|
+
FactoryBot.create(:docker_cr)
|
19
|
+
get :index, session: set_session_user
|
20
20
|
assert_template 'index'
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'delete container' do
|
24
24
|
setup do
|
25
25
|
Fog.mock!
|
26
|
-
@container_resource =
|
26
|
+
@container_resource = FactoryBot.create(:docker_cr)
|
27
27
|
@container = @container_resource.vms.first
|
28
28
|
end
|
29
29
|
|
@@ -31,8 +31,7 @@ class ContainersControllerTest < ActionController::TestCase
|
|
31
31
|
|
32
32
|
test 'deleting an unmanaged container redirects to containers index' do
|
33
33
|
ComputeResource.any_instance.expects(:destroy_vm).with(@container.id)
|
34
|
-
delete :destroy, { :compute_resource_id => @container_resource,
|
35
|
-
:id => @container.id }, set_session_user
|
34
|
+
delete :destroy, params: { :compute_resource_id => @container_resource, :id => @container.id }, session: set_session_user
|
36
35
|
assert_redirected_to containers_path
|
37
36
|
assert_equal "Container #{@container.id} is being deleted.",
|
38
37
|
flash[:notice]
|
@@ -42,8 +41,7 @@ class ContainersControllerTest < ActionController::TestCase
|
|
42
41
|
ComputeResource.any_instance.stubs(:destroy_vm).
|
43
42
|
raises(::Foreman::Exception.new('Could not destroy Docker container'))
|
44
43
|
@request.env['HTTP_REFERER'] = "http://test.host/#{containers_path}"
|
45
|
-
delete :destroy, { :compute_resource_id => @container_resource,
|
46
|
-
:id => @container.id }, set_session_user
|
44
|
+
delete :destroy, params: { :compute_resource_id => @container_resource, :id => @container.id }, session: set_session_user
|
47
45
|
assert @container.present?
|
48
46
|
assert_redirected_to :back
|
49
47
|
assert_equal 'Your container could not be deleted in Docker',
|
@@ -51,29 +49,28 @@ class ContainersControllerTest < ActionController::TestCase
|
|
51
49
|
end
|
52
50
|
|
53
51
|
test 'deleting a managed container deletes container in Docker' do
|
54
|
-
managed_container =
|
52
|
+
managed_container = FactoryBot.create(
|
55
53
|
:container,
|
56
54
|
:compute_resource => @container_resource)
|
57
55
|
ComputeResource.any_instance.expects(:destroy_vm).
|
58
56
|
with('randomuuid')
|
59
57
|
Container.any_instance.expects(:uuid).returns('randomuuid').at_least_once
|
60
58
|
Container.any_instance.expects(:destroy)
|
61
|
-
delete :destroy, { :id => managed_container.id }, set_session_user
|
59
|
+
delete :destroy, params: { :id => managed_container.id }, session: set_session_user
|
62
60
|
assert_redirected_to containers_path
|
63
61
|
assert_equal "Container #{managed_container.uuid} is being deleted.",
|
64
62
|
flash[:notice]
|
65
63
|
end
|
66
64
|
|
67
65
|
test 'deleting with container params deletes container object' do
|
68
|
-
managed_container =
|
66
|
+
managed_container = FactoryBot.create(
|
69
67
|
:container,
|
70
68
|
:compute_resource => @container_resource)
|
71
69
|
managed_container.update(:uuid => @container.id)
|
72
70
|
ComputeResource.any_instance.expects(:destroy_vm).
|
73
71
|
with(@container.id).returns(true)
|
74
72
|
Container.any_instance.expects(:destroy)
|
75
|
-
delete :destroy, { :compute_resource_id => @container_resource.id,
|
76
|
-
:id => @container.id }, set_session_user
|
73
|
+
delete :destroy, params: { :compute_resource_id => @container_resource.id, :id => @container.id }, session: set_session_user
|
77
74
|
assert_redirected_to containers_path
|
78
75
|
assert_equal "Container #{managed_container.uuid} is being deleted.",
|
79
76
|
flash[:notice]
|
@@ -82,10 +79,10 @@ class ContainersControllerTest < ActionController::TestCase
|
|
82
79
|
test 'failed deletion of managed container keeps container in Foreman' do
|
83
80
|
ComputeResource.any_instance.stubs(:destroy_vm).
|
84
81
|
raises(::Foreman::Exception.new('Could not destroy Docker container'))
|
85
|
-
managed_container =
|
82
|
+
managed_container = FactoryBot.create(
|
86
83
|
:container,
|
87
84
|
:compute_resource => @container_resource)
|
88
|
-
delete :destroy, { :id => managed_container.id }, set_session_user
|
85
|
+
delete :destroy, params: { :id => managed_container.id }, session: set_session_user
|
89
86
|
assert managed_container.present? # Foreman container would not be deleted
|
90
87
|
assert_redirected_to containers_path
|
91
88
|
assert_equal 'Your container could not be deleted in Docker',
|
@@ -94,7 +91,7 @@ class ContainersControllerTest < ActionController::TestCase
|
|
94
91
|
end
|
95
92
|
|
96
93
|
test 'committing a managed container' do
|
97
|
-
container =
|
94
|
+
container = FactoryBot.create(:container)
|
98
95
|
request.env['HTTP_REFERER'] = container_path(:id => container.id)
|
99
96
|
commit_hash = { :author => 'a', :repo => 'b', :tag => 'c', :comment => 'd' }
|
100
97
|
|
@@ -103,7 +100,6 @@ class ContainersControllerTest < ActionController::TestCase
|
|
103
100
|
.returns(mock_container)
|
104
101
|
mock_container.expects(:commit).with(commit_hash)
|
105
102
|
|
106
|
-
post :commit, { :commit => commit_hash,
|
107
|
-
:id => container.id }, set_session_user
|
103
|
+
post :commit, params: { :commit => commit_hash, :id => container.id }, session: set_session_user
|
108
104
|
end
|
109
105
|
end
|
@@ -5,25 +5,21 @@ module Containers
|
|
5
5
|
setup do
|
6
6
|
stub_image_existance
|
7
7
|
stub_registry_api
|
8
|
-
@container =
|
8
|
+
@container = FactoryBot.create(:container)
|
9
9
|
@state = DockerContainerWizardState.create!
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'wizard finishes with a redirect to the managed container' do
|
13
13
|
Service::Containers.any_instance.expects(:start_container!).with(equals(@state))
|
14
14
|
.returns(@container)
|
15
|
-
put :update, { :wizard_state_id => @state.id,
|
16
|
-
:id => :environment,
|
17
|
-
:start_on_create => true,
|
18
|
-
:docker_container_wizard_states_environment => { :tty => false } },
|
19
|
-
set_session_user
|
15
|
+
put :update, params: { :wizard_state_id => @state.id, :id => :environment, :start_on_create => true, :docker_container_wizard_states_environment => { :tty => false } }, session: set_session_user
|
20
16
|
|
21
17
|
assert_redirected_to container_path(:id => @container.id)
|
22
18
|
end
|
23
19
|
|
24
20
|
describe 'on image step' do
|
25
21
|
setup do
|
26
|
-
@compute_resource =
|
22
|
+
@compute_resource = FactoryBot.create(:docker_cr)
|
27
23
|
@create_options = { :wizard_state => @state,
|
28
24
|
:compute_resource_id => @compute_resource.id }
|
29
25
|
@state.preliminary = DockerContainerWizardStates::Preliminary.create!(@create_options)
|
@@ -31,7 +27,7 @@ module Containers
|
|
31
27
|
end
|
32
28
|
|
33
29
|
test 'image show doesnot load katello' do
|
34
|
-
get :show, { :wizard_state_id => @state.id, :id => :image }, set_session_user
|
30
|
+
get :show, params: { :wizard_state_id => @state.id, :id => :image }, session: set_session_user
|
35
31
|
refute @state.image.katello?
|
36
32
|
refute response.body.include?("katello") # this is code generated by katello partial
|
37
33
|
docker_image = @controller.instance_eval do
|
@@ -54,14 +50,14 @@ module Containers
|
|
54
50
|
end
|
55
51
|
|
56
52
|
test 'has no errors if the image exists' do
|
57
|
-
put :update, @params, set_session_user
|
53
|
+
put :update, params: @params, session: set_session_user
|
58
54
|
assert_valid @state.image
|
59
55
|
assert css_select('#hub_image_search.has-error').size == 0
|
60
56
|
end
|
61
57
|
|
62
58
|
test 'shows an error when the image does not exist' do
|
63
59
|
stub_image_existance(false)
|
64
|
-
put :update, @params, set_session_user
|
60
|
+
put :update, params: @params, session: set_session_user
|
65
61
|
refute_valid @state.image
|
66
62
|
assert_select '#hub_image_search.has-error'
|
67
63
|
end
|
@@ -75,7 +71,7 @@ module Containers
|
|
75
71
|
@state.environment = DockerContainerWizardStates::Environment.create!(environment_options)
|
76
72
|
@state.environment.exposed_ports.create!(:key => '1654', :value => 'tcp')
|
77
73
|
@state.environment.exposed_ports.create!(:key => '1655', :value => 'udp')
|
78
|
-
get :show, { :wizard_state_id => @state.id, :id => :environment }, set_session_user
|
74
|
+
get :show, params: { :wizard_state_id => @state.id, :id => :environment }, session: set_session_user
|
79
75
|
assert response.body.include?("1654")
|
80
76
|
assert response.body.include?("1655")
|
81
77
|
|
@@ -97,7 +93,7 @@ module Containers
|
|
97
93
|
@state.environment = DockerContainerWizardStates::Environment.create!(environment_options)
|
98
94
|
@state.environment.dns.create!(:key => '18.18.18.18')
|
99
95
|
@state.environment.dns.create!(:key => '19.19.19.19')
|
100
|
-
get :show, { :wizard_state_id => @state.id, :id => :environment }, set_session_user
|
96
|
+
get :show, params: { :wizard_state_id => @state.id, :id => :environment }, session: set_session_user
|
101
97
|
assert response.body.include?("18.18.18.18")
|
102
98
|
assert response.body.include?("19.19.19.19")
|
103
99
|
|
@@ -6,8 +6,8 @@ class ImageSearchControllerTest < ActionController::TestCase
|
|
6
6
|
let(:term) { docker_image }
|
7
7
|
|
8
8
|
let(:docker_hub) { Service::RegistryApi.new(url: 'https://nothub.com') }
|
9
|
-
let(:compute_resource) {
|
10
|
-
let(:registry) {
|
9
|
+
let(:compute_resource) { FactoryBot.create(:docker_cr) }
|
10
|
+
let(:registry) { FactoryBot.create(:docker_registry) }
|
11
11
|
let(:image_search_service) { ForemanDocker::ImageSearch.new }
|
12
12
|
|
13
13
|
setup do
|
@@ -2,8 +2,8 @@ require 'integration_test_helper'
|
|
2
2
|
|
3
3
|
class ContainerStepsTest < IntegrationTestWithJavascript
|
4
4
|
let(:wizard_state) { DockerContainerWizardState.create! }
|
5
|
-
let(:compute_resource) {
|
6
|
-
let(:registry) {
|
5
|
+
let(:compute_resource) { FactoryBot.create(:docker_cr) }
|
6
|
+
let(:registry) { FactoryBot.create(:docker_registry) }
|
7
7
|
let(:image_search_service) { ForemanDocker::ImageSearch.new }
|
8
8
|
let(:image_search_results) do
|
9
9
|
[{ 'name' => 'my_fake_repository_result',
|
@@ -10,7 +10,7 @@ class ContainerIntegrationTest < ActionDispatch::IntegrationTest
|
|
10
10
|
test 'shows containers list if compute resource is available' do
|
11
11
|
Fog.mock!
|
12
12
|
ComputeResource.any_instance.stubs(:vms).returns([])
|
13
|
-
|
13
|
+
FactoryBot.create(:docker_cr)
|
14
14
|
visit containers_path
|
15
15
|
assert page.has_link? 'Create container'
|
16
16
|
refute_equal current_path, new_compute_resource_path
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'integration_test_helper'
|
2
2
|
|
3
3
|
class RegistryiCreationTest < IntegrationTestWithJavascript
|
4
|
-
let(:registry_values) {
|
4
|
+
let(:registry_values) { FactoryBot.build(:docker_registry) }
|
5
5
|
|
6
6
|
setup do
|
7
7
|
DockerRegistry.any_instance.stubs(:attempt_login).returns(true)
|
data/test/test_plugin_helper.rb
CHANGED
@@ -9,9 +9,9 @@ def assert_row_button(index_path, link_text, button_text, dropdown = false)
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
# Add plugin to
|
13
|
-
|
14
|
-
|
12
|
+
# Add plugin to FactoryBot's paths
|
13
|
+
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
14
|
+
FactoryBot.reload
|
15
15
|
|
16
16
|
def stub_image_existance(exists = true)
|
17
17
|
Docker::Image.any_instance.stubs(:exist?).returns(exists)
|
@@ -4,7 +4,7 @@ module ForemanDocker
|
|
4
4
|
class ContainerRemoverTest < ActiveSupport::TestCase
|
5
5
|
describe '#remove_unmanaged' do
|
6
6
|
setup do
|
7
|
-
@docker_compute_resource =
|
7
|
+
@docker_compute_resource = FactoryBot.build_stubbed(:docker_cr)
|
8
8
|
ComputeResource.expects(:authorized).
|
9
9
|
with(:destroy_compute_resources_vms).
|
10
10
|
returns(stub(:find => @docker_compute_resource))
|
@@ -7,7 +7,7 @@ class ContainersServiceTest < ActiveSupport::TestCase
|
|
7
7
|
stub_registry_api
|
8
8
|
|
9
9
|
@state = DockerContainerWizardState.create! do |s|
|
10
|
-
s.build_preliminary(:compute_resource_id =>
|
10
|
+
s.build_preliminary(:compute_resource_id => FactoryBot.create(:docker_cr).id,
|
11
11
|
:locations => [taxonomies(:location1)],
|
12
12
|
:organizations => [taxonomies(:organization1)])
|
13
13
|
s.build_image(:repository_name => 'test', :tag => 'test', :wizard_state => s)
|
@@ -5,8 +5,8 @@ module DockerContainerWizardStates
|
|
5
5
|
let(:image) { 'centos' }
|
6
6
|
let(:tags) { ['latest', '5', '4.3'] }
|
7
7
|
let(:docker_hub) { Service::RegistryApi.new(url: 'https://nothub.com') }
|
8
|
-
let(:registry) {
|
9
|
-
let(:compute_resource) {
|
8
|
+
let(:registry) { FactoryBot.create(:docker_registry) }
|
9
|
+
let(:compute_resource) { FactoryBot.create(:docker_cr) }
|
10
10
|
let(:image_search_service) { ForemanDocker::ImageSearch.new }
|
11
11
|
let(:wizard_state) do
|
12
12
|
DockerContainerWizardState.create
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
2
|
|
3
3
|
class DockerRegistryTest < ActiveSupport::TestCase
|
4
|
-
subject {
|
4
|
+
subject { FactoryBot.create(:docker_registry) }
|
5
5
|
|
6
6
|
test 'used_location_ids should return correct location ids' do
|
7
|
-
location =
|
7
|
+
location = FactoryBot.build(:location)
|
8
8
|
r = as_admin do
|
9
|
-
|
9
|
+
FactoryBot.create(:docker_registry, :locations => ([location]))
|
10
10
|
end
|
11
11
|
assert r.used_location_ids.include?(location.id)
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'used_organization_ids should return correct organization ids' do
|
15
|
-
organization =
|
15
|
+
organization = FactoryBot.build(:organization)
|
16
16
|
r = as_admin do
|
17
|
-
|
17
|
+
FactoryBot.create(:docker_registry, :organizations => ([organization]))
|
18
18
|
end
|
19
19
|
assert r.used_organization_ids.include?(organization.id)
|
20
20
|
end
|
21
21
|
|
22
22
|
test 'password is stored encrypted' do
|
23
|
-
registry = as_admin {
|
23
|
+
registry = as_admin { FactoryBot.build(:docker_registry) }
|
24
24
|
registry.password = 'encrypted-whatever'
|
25
25
|
DockerRegistry.any_instance.expects(:encryption_key).at_least_once.returns('fakeencryptionkey')
|
26
26
|
assert registry.is_decryptable?(registry.password_in_db)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
2
|
|
3
3
|
class ImageSearchServiceTest < ActiveSupport::TestCase
|
4
|
-
let(:compute_resource) {
|
5
|
-
let(:registry) {
|
4
|
+
let(:compute_resource) { FactoryBot.create(:docker_cr) }
|
5
|
+
let(:registry) { FactoryBot.create(:docker_registry).api }
|
6
6
|
let(:term) { 'centos' }
|
7
7
|
let(:query) { { term: term, tags: 'false' } }
|
8
8
|
|
@@ -13,6 +13,10 @@ class RegistryApiTest < ActiveSupport::TestCase
|
|
13
13
|
assert_equal url, subject.connection.url
|
14
14
|
end
|
15
15
|
|
16
|
+
test 'it requests json' do
|
17
|
+
assert_equal 'application/json', subject.connection.options[:headers]['Content-Type']
|
18
|
+
end
|
19
|
+
|
16
20
|
context 'authentication is set' do
|
17
21
|
let(:user) { 'username' }
|
18
22
|
let(:password) { 'secretpassword' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_docker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lobato, Amos Benari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.52.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.52.0
|
83
83
|
description: Provision and manage Docker containers and images from Foreman.
|
84
84
|
email:
|
85
85
|
- dlobatog@redhat.com, abenari@redhat.com
|
@@ -268,11 +268,11 @@ test_files:
|
|
268
268
|
- test/factories/compute_resources.rb
|
269
269
|
- test/factories/containers.rb
|
270
270
|
- test/factories/docker_registry.rb
|
271
|
-
- test/functionals/api/v2/registries_controller_test.rb
|
272
271
|
- test/functionals/api/v2/containers_controller_test.rb
|
272
|
+
- test/functionals/api/v2/registries_controller_test.rb
|
273
|
+
- test/functionals/image_search_controller_test.rb
|
273
274
|
- test/functionals/containers_controller_test.rb
|
274
275
|
- test/functionals/containers_steps_controller_test.rb
|
275
|
-
- test/functionals/image_search_controller_test.rb
|
276
276
|
- test/integration/container_test.rb
|
277
277
|
- test/integration/container_steps_test.rb
|
278
278
|
- test/integration/registry_creation_test.rb
|