foreman_docker 2.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/app/controllers/api/v2/registries_controller.rb +4 -2
- data/app/controllers/concerns/foreman/controller/parameters/docker_registry.rb +19 -0
- data/app/controllers/containers/steps_controller.rb +21 -2
- data/app/controllers/containers_controller.rb +1 -0
- data/app/controllers/registries_controller.rb +3 -2
- data/app/models/container.rb +0 -5
- data/app/models/docker_container_wizard_states/configuration.rb +0 -4
- data/app/models/docker_container_wizard_states/environment.rb +0 -4
- data/app/models/docker_container_wizard_states/image.rb +0 -2
- data/app/models/docker_container_wizard_states/preliminary.rb +0 -2
- data/app/models/docker_registry.rb +6 -3
- data/app/models/environment_variable.rb +0 -1
- data/app/models/exposed_port.rb +0 -1
- data/app/models/foreman_docker/dns.rb +0 -2
- data/app/models/foreman_docker/docker.rb +1 -3
- data/app/models/service/containers.rb +20 -15
- data/app/views/api/v2/registries/show.json.rabl +2 -2
- data/app/views/compute_resources_vms/index/_docker.html.erb +28 -29
- data/app/views/containers/steps/preliminary.html.erb +2 -1
- data/db/migrate/20141209182008_remove_docker_tables.rb +2 -2
- data/lib/foreman_docker/engine.rb +2 -0
- data/lib/foreman_docker/tasks/test.rake +1 -0
- data/lib/foreman_docker/version.rb +1 -1
- data/test/factories/compute_resources.rb +1 -1
- data/test/functionals/api/v2/containers_controller_test.rb +45 -41
- data/test/functionals/containers_controller_test.rb +15 -0
- data/test/units/containers_service_test.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d60710f8feff575f0ad158fe70dcd4ca943a4b
|
4
|
+
data.tar.gz: c2cb12599647a844761982076c1b8b176d5c378e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96ad25c6bd9fa70731aaa122c26d4515e6094162bd0b998b88b0d64d5f5cd1bc420b21f932ea624c65b5fb9410030a232d5e6dc0c587321b0e4952717f4abd18
|
7
|
+
data.tar.gz: 1e1853fbe2f9f8ce9ecf4f3b8811d7cd0a2a2fbf0afa43298662607559f0cbf7e0d143de93e4c384ce7e16a393aaf157bca069d408c5b931364205aa468860e2
|
data/README.md
CHANGED
@@ -84,7 +84,8 @@ That's it. You're now ready to create and manage containers in your new Docker c
|
|
84
84
|
| ---------------:| --------------:|
|
85
85
|
| >= 1.5 | 0.0.1 - 0.0.3 |
|
86
86
|
| >= 1.6 | 0.1.0 - 0.2.0 |
|
87
|
-
| >= 1.7 | 1.0.0
|
87
|
+
| >= 1.7 | 1.0.0 - 2.1.1 |
|
88
|
+
| >= 1.7 | 3.0.0+ |
|
88
89
|
|
89
90
|
See extras/RELEASE.md for more detailed information on compatibility and releases.
|
90
91
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Api
|
2
2
|
module V2
|
3
3
|
class RegistriesController < ::Api::V2::BaseController
|
4
|
+
include Foreman::Controller::Parameters::DockerRegistry
|
4
5
|
before_filter :find_resource, :except => %w(index create)
|
5
6
|
|
6
7
|
resource_description do
|
@@ -12,6 +13,7 @@ module Api
|
|
12
13
|
def_param_group :registry do
|
13
14
|
param :registry, Hash, :required => true, :action_aware => true do
|
14
15
|
param :name, String, :required => true
|
16
|
+
param_group :taxonomies, ::Api::V2::BaseController
|
15
17
|
param :url, String, :required => true
|
16
18
|
param :description, String
|
17
19
|
param :username, String
|
@@ -34,7 +36,7 @@ module Api
|
|
34
36
|
api :POST, '/registries/', N_('Create a docker registry')
|
35
37
|
param_group :registry, :as => :create
|
36
38
|
def create
|
37
|
-
@registry = DockerRegistry.new(
|
39
|
+
@registry = DockerRegistry.new(docker_registry_params)
|
38
40
|
process_response @registry.save
|
39
41
|
end
|
40
42
|
|
@@ -42,7 +44,7 @@ module Api
|
|
42
44
|
param :id, :identifier, :required => true
|
43
45
|
param_group :registry, :as => :update
|
44
46
|
def update
|
45
|
-
process_response @registry.update_attributes(
|
47
|
+
process_response @registry.update_attributes(docker_registry_params)
|
46
48
|
end
|
47
49
|
|
48
50
|
api :DELETE, '/registries/:id/', N_('Delete a docker registry')
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Foreman::Controller::Parameters::DockerRegistry
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
class_methods do
|
5
|
+
def docker_registry_params_filter
|
6
|
+
Foreman::ParameterFilter.new(::DockerRegistry).tap do |filter|
|
7
|
+
filter.permit :name, :url, :username, :password, :description,
|
8
|
+
:location_ids => [], :organization_ids => []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def docker_registry_params
|
14
|
+
param_name = parameter_filter_context.api? ? 'registry' : 'docker_registry'
|
15
|
+
self.class.docker_registry_params_filter.filter_params(params, parameter_filter_context,
|
16
|
+
param_name
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
@@ -35,10 +35,29 @@ module Containers
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def build_state
|
38
|
-
s = @state.send(:"build_#{step}",
|
38
|
+
s = @state.send(:"build_#{step}", state_params)
|
39
39
|
instance_variable_set("@docker_container_wizard_states_#{step}", s)
|
40
40
|
end
|
41
41
|
|
42
|
+
def state_params
|
43
|
+
attrs = case step
|
44
|
+
when :preliminary
|
45
|
+
[:wizard_state, :compute_resource_id]
|
46
|
+
when :image
|
47
|
+
[:repository_name, :tag, :wizard_state, :registry_id, :capsule_id, :katello]
|
48
|
+
when :configuration
|
49
|
+
[:name, :command, :entrypoint, :cpu_set, :cpu_shares, :memory, :wizard_state]
|
50
|
+
when :environment
|
51
|
+
[:tty, :docker_container_wizard_state_id,
|
52
|
+
:attach_stdin, :attach_stdout, :attach_stderr,
|
53
|
+
:exposed_ports_attributes => [], :environment_variables_attributes => [],
|
54
|
+
:dns_attributes => []
|
55
|
+
]
|
56
|
+
end
|
57
|
+
|
58
|
+
params.require("docker_container_wizard_states_#{step}").permit(*attrs)
|
59
|
+
end
|
60
|
+
|
42
61
|
def set_form
|
43
62
|
instance_variable_set(
|
44
63
|
"@docker_container_wizard_states_#{step}",
|
@@ -46,7 +65,7 @@ module Containers
|
|
46
65
|
end
|
47
66
|
|
48
67
|
def create_container(start = true)
|
49
|
-
@state.send(:"create_#{step}",
|
68
|
+
@state.send(:"create_#{step}", state_params)
|
50
69
|
service = Service::Containers.new
|
51
70
|
container = if start.is_a? TrueClass
|
52
71
|
service.start_container!(@state)
|
@@ -102,6 +102,7 @@ class ContainersController < ::ApplicationController
|
|
102
102
|
if params[:compute_resource_id].present?
|
103
103
|
compute_resource_id = params[:compute_resource_id]
|
104
104
|
container_uuid = params[:id]
|
105
|
+
@container ||= Container.authorized("#{action_permission}_#{controller_name}".to_sym).find_by_uuid(container_uuid)
|
105
106
|
else
|
106
107
|
find_container
|
107
108
|
compute_resource_id = @container.compute_resource_id
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class RegistriesController < ::ApplicationController
|
2
2
|
include Foreman::Controller::AutoCompleteSearch
|
3
|
+
include Foreman::Controller::Parameters::DockerRegistry
|
3
4
|
before_filter :find_registry, :only => [:edit, :update, :destroy]
|
4
5
|
|
5
6
|
def index
|
@@ -12,7 +13,7 @@ class RegistriesController < ::ApplicationController
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def create
|
15
|
-
@registry = DockerRegistry.new(
|
16
|
+
@registry = DockerRegistry.new(docker_registry_params)
|
16
17
|
if @registry.save
|
17
18
|
process_success
|
18
19
|
else
|
@@ -24,7 +25,7 @@ class RegistriesController < ::ApplicationController
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def update
|
27
|
-
if @registry.update_attributes(
|
28
|
+
if @registry.update_attributes(docker_registry_params)
|
28
29
|
process_success
|
29
30
|
else
|
30
31
|
process_error
|
data/app/models/container.rb
CHANGED
@@ -24,11 +24,6 @@ class Container < ActiveRecord::Base
|
|
24
24
|
accepts_nested_attributes_for :exposed_ports, :allow_destroy => true
|
25
25
|
scoped_search :on => :name
|
26
26
|
|
27
|
-
attr_accessible :command, :repository_name, :name, :compute_resource_id, :entrypoint,
|
28
|
-
:cpu_set, :cpu_shares, :memory, :tty, :attach_stdin, :registry_id,
|
29
|
-
:attach_stdout, :attach_stderr, :tag, :uuid, :environment_variables_attributes,
|
30
|
-
:katello, :exposed_ports_attributes, :dns
|
31
|
-
|
32
27
|
validates :name, :uniqueness => { :scope => :compute_resource_id }
|
33
28
|
|
34
29
|
def repository_pull_url
|
@@ -3,9 +3,5 @@ module DockerContainerWizardStates
|
|
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
|
6
|
-
|
7
|
-
validates :command, :presence => true
|
8
|
-
|
9
|
-
attr_accessible :name, :command, :entrypoint, :cpu_set, :cpu_shares, :memory, :wizard_state
|
10
6
|
end
|
11
7
|
end
|
@@ -3,10 +3,6 @@ module DockerContainerWizardStates
|
|
3
3
|
self.table_name_prefix = 'docker_container_wizard_states_'
|
4
4
|
belongs_to :wizard_state, :class_name => DockerContainerWizardState
|
5
5
|
|
6
|
-
attr_accessible :tty, :docker_container_wizard_state_id,
|
7
|
-
:attach_stdin, :attach_stdout, :attach_stderr,
|
8
|
-
:exposed_ports_attributes, :environment_variables_attributes,
|
9
|
-
:dns_attributes
|
10
6
|
# Fix me:
|
11
7
|
# Validations are off on this association as there's a bug in ::Parameter
|
12
8
|
# that forces validation of reference_id. This will fail on new records as
|
@@ -2,8 +2,6 @@ module DockerContainerWizardStates
|
|
2
2
|
class Preliminary < ActiveRecord::Base
|
3
3
|
include Taxonomix
|
4
4
|
|
5
|
-
attr_accessible :wizard_state, :compute_resource_id
|
6
|
-
|
7
5
|
self.table_name_prefix = 'docker_container_wizard_states_'
|
8
6
|
belongs_to :wizard_state, :class_name => DockerContainerWizardState,
|
9
7
|
:foreign_key => :docker_container_wizard_state_id
|
@@ -3,12 +3,15 @@ class DockerRegistry < ActiveRecord::Base
|
|
3
3
|
include Taxonomix
|
4
4
|
include Encryptable
|
5
5
|
|
6
|
+
default_scope do
|
7
|
+
with_taxonomy_scope do
|
8
|
+
order('docker_registries.name')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
has_many :containers, :foreign_key => "registry_id", :dependent => :destroy
|
7
13
|
encrypts :password
|
8
14
|
|
9
|
-
attr_accessible :name, :url, :username, :password, :locations, :organizations,
|
10
|
-
:description
|
11
|
-
|
12
15
|
validates_lengths_from_database
|
13
16
|
validates :name, :presence => true, :uniqueness => true
|
14
17
|
validates :url, :presence => true, :uniqueness => true,
|
@@ -2,5 +2,4 @@ class EnvironmentVariable < Parameter
|
|
2
2
|
belongs_to :container, :foreign_key => :reference_id, :inverse_of => :environment_variables
|
3
3
|
audited :except => [:priority], :associated_with => :container, :allow_mass_assignment => true
|
4
4
|
validates :name, :uniqueness => { :scope => :reference_id }
|
5
|
-
attr_accessible :priority
|
6
5
|
end
|
data/app/models/exposed_port.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class ExposedPort < Parameter
|
2
|
-
attr_accessible :priority
|
3
2
|
# The Parameter class from which ExposedPort class inherits,validates for the
|
4
3
|
# presence of an associated domain, operating system, host or host group. We
|
5
4
|
# will have to reset those validations for the ExposedPort class as they do
|
@@ -2,8 +2,6 @@ require 'resolv'
|
|
2
2
|
|
3
3
|
module ForemanDocker
|
4
4
|
class Dns < Parameter
|
5
|
-
attr_accessible :priority
|
6
|
-
|
7
5
|
# The Parameter class from which this Dns class inherits,validates for the
|
8
6
|
# presence of an associated domain, operating system, host or host group.
|
9
7
|
# We will have to reset those validations for the Dns class as they do not
|
@@ -2,8 +2,6 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module ForemanDocker
|
4
4
|
class Docker < ::ComputeResource
|
5
|
-
attr_accessible :email
|
6
|
-
|
7
5
|
validates :url, :format => { :with => URI.regexp }
|
8
6
|
validates :email, :format => { :with => /.+@.+\..+/i }, :allow_blank => true
|
9
7
|
|
@@ -61,7 +59,7 @@ module ForemanDocker
|
|
61
59
|
|
62
60
|
def tags(image_name)
|
63
61
|
if exist?(image_name)
|
64
|
-
tags_for_local_image(
|
62
|
+
tags_for_local_image(image(image_name))
|
65
63
|
else
|
66
64
|
# If image is not found in the compute resource, get the tags from the Hub
|
67
65
|
hub_api_url = "https://index.docker.io/v1/repositories/#{image_name}/tags"
|
@@ -24,7 +24,8 @@ module Service
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def create_container_object(wizard_state)
|
27
|
-
container = Container.new
|
27
|
+
container = Container.new do |r|
|
28
|
+
r.attributes = wizard_state.container_attributes
|
28
29
|
# eagerly load environment variables and exposed ports configuration
|
29
30
|
state = DockerContainerWizardState.includes(
|
30
31
|
:environment => [:environment_variables, :exposed_ports]).find(wizard_state.id)
|
@@ -38,12 +39,11 @@ module Service
|
|
38
39
|
container.send(:"#{taxonomy}=", wizard_state.preliminary.send(:"#{taxonomy}"))
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
42
|
+
pull_image(container)
|
43
|
+
start_container(container)
|
44
|
+
errors << container.errors unless container.valid?
|
45
45
|
|
46
|
-
fail ActiveRecord::Rollback
|
46
|
+
fail ActiveRecord::Rollback if @errors.present?
|
47
47
|
|
48
48
|
container.name = container.in_fog.name[1..-1] unless container.name.present?
|
49
49
|
|
@@ -51,7 +51,9 @@ module Service
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def pull_image(container)
|
54
|
-
container.compute_resource.
|
54
|
+
success = container.compute_resource.
|
55
|
+
create_image(:fromImage => container.repository_pull_url)
|
56
|
+
errors << container.compute_resource.errors[:base] unless success
|
55
57
|
end
|
56
58
|
|
57
59
|
def start_container(container)
|
@@ -71,24 +73,27 @@ module Service
|
|
71
73
|
|
72
74
|
def load_environment_variables(state, r)
|
73
75
|
state.environment_variables.each do |environment_variable|
|
74
|
-
r.environment_variables.build
|
75
|
-
|
76
|
-
|
76
|
+
var = r.environment_variables.build
|
77
|
+
var.name = environment_variable.name
|
78
|
+
var.value = environment_variable.value
|
79
|
+
var.priority = environment_variable.priority
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
80
83
|
def load_exposed_ports(state, r)
|
81
84
|
state.exposed_ports.each do |e|
|
82
|
-
r.exposed_ports.build
|
83
|
-
|
84
|
-
|
85
|
+
port = r.exposed_ports.build
|
86
|
+
port.name = e.name
|
87
|
+
port.value = e.value
|
88
|
+
port.priority = e.priority
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
92
|
def load_dns(state, r)
|
89
93
|
state.dns.each do |e|
|
90
|
-
r.dns.build
|
91
|
-
|
94
|
+
dns = r.dns.build
|
95
|
+
dns.name = e.name
|
96
|
+
dns.priority = e.priority
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
@@ -1,29 +1,28 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
</table>
|
1
|
+
<thead>
|
2
|
+
<tr>
|
3
|
+
<th><%= _('Name') %></th>
|
4
|
+
<th><%= _('Image') %></th>
|
5
|
+
<th><%= _('CPUs') %></th>
|
6
|
+
<th><%= _('Memory') %></th>
|
7
|
+
<th><%= _('Status') %></th>
|
8
|
+
<th><%= _('Power') %></th>
|
9
|
+
<th><%= _('Action') %></th>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
<tbody>
|
13
|
+
<% @vms.each do |vm| %>
|
14
|
+
<tr>
|
15
|
+
<% name = vm.name || (!vm.attributes['names'].empty? && vm.attributes['names'].first) %>
|
16
|
+
<td><%= link_to_if_authorized name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity) %></td>
|
17
|
+
<td><%= vm.image %></td>
|
18
|
+
<td><%= vm.cores %></td>
|
19
|
+
<td> <%= number_to_human_size vm.memory %> </td>
|
20
|
+
<td> <%= vm.attributes['status'] %> </td>
|
21
|
+
<td> <span <%= vm_power_class(vm.ready?) %>> <%= vm_state(vm) %></span> </td>
|
22
|
+
<td>
|
23
|
+
<%= action_buttons(container_power_action(vm),
|
24
|
+
display_delete_if_authorized(hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.id))) %>
|
25
|
+
</td>
|
26
|
+
</tr>
|
27
|
+
<% end %>
|
28
|
+
</tbody>
|
@@ -21,8 +21,9 @@
|
|
21
21
|
<hr>
|
22
22
|
<%= select_f f, 'compute_resource_id', @container_resources, :id, :to_label, {}, { :label => _('Deploy on') } %>
|
23
23
|
<% else %>
|
24
|
+
|
24
25
|
<div class="alert alert-warning alert-dismissable">
|
25
|
-
<%= image_tag 'false.png' %> <%= (_("You need a Docker compute resource in order to create containers. Please %s and try again.") % link_to('add a new one',
|
26
|
+
<%= image_tag 'false.png' %> <%= (_("You need a Docker compute resource in order to create containers. Please %s and try again.") % link_to('add a new one', new_compute_resource_path)).html_safe %>
|
26
27
|
</div>
|
27
28
|
<% end %>
|
28
29
|
</div>
|
@@ -28,8 +28,8 @@ class RemoveDockerTables < ActiveRecord::Migration
|
|
28
28
|
remove_foreign_key :containers, :name => :containers_docker_tag_id_fk
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
remove_reference :containers, :docker_image, :foreign_key => true
|
32
|
+
remove_reference :containers, :docker_tag, :foreign_key => true
|
33
33
|
|
34
34
|
# these tables might have foreign keys from plugins like katello so use cascade
|
35
35
|
cascade_drop(:docker_images)
|
@@ -103,6 +103,8 @@ module ForemanDocker
|
|
103
103
|
:resource_type => 'Docker/ImageSearch'
|
104
104
|
end
|
105
105
|
|
106
|
+
parameter_filter ComputeResource, :email
|
107
|
+
|
106
108
|
# apipie API documentation
|
107
109
|
# Only available in 1.8, otherwise it has to be in the initializer below
|
108
110
|
if SETTINGS[:version].to_s.include?('develop') ||
|
@@ -7,7 +7,7 @@ FactoryGirl.define do
|
|
7
7
|
user 'dockeruser'
|
8
8
|
password 'dockerpassword'
|
9
9
|
email 'container@containerization.com'
|
10
|
-
url 'unix:///var/run/docker.
|
10
|
+
url 'unix:///var/run/docker.falsesock'
|
11
11
|
end
|
12
12
|
|
13
13
|
factory :docker_cr, :class => ForemanDocker::Docker, :traits => [:docker]
|
@@ -46,7 +46,9 @@ module Api
|
|
46
46
|
end
|
47
47
|
|
48
48
|
test 'delete removes a container in foreman and in Docker host' do
|
49
|
+
Fog.mock!
|
49
50
|
delete :destroy, :id => @container.id
|
51
|
+
Fog.unmock!
|
50
52
|
assert_response :success
|
51
53
|
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
52
54
|
end
|
@@ -60,51 +62,53 @@ module Api
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
|
64
|
-
Fog.mock!
|
65
|
-
Fog
|
66
|
-
put :power, :id => @container.id, :power_action => 'start'
|
67
|
-
assert_response :success
|
68
|
-
end
|
65
|
+
context 'power calls' do
|
66
|
+
setup { Fog.mock! }
|
67
|
+
teardown { Fog.unmock! }
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
76
|
-
end
|
69
|
+
test 'power call turns on/off container in Docker host' do
|
70
|
+
Fog::Compute::Fogdocker::Server.any_instance.expects(:start)
|
71
|
+
put :power, :id => @container.id, :power_action => 'start'
|
72
|
+
assert_response :success
|
73
|
+
end
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
75
|
+
test 'power call checks status of container in Docker host' do
|
76
|
+
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
77
|
+
put :power, :id => @container.id, :power_action => 'status'
|
78
|
+
assert_response :success
|
79
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
80
|
+
end
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
82
|
+
test 'power call host' do
|
83
|
+
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
84
|
+
put :power, :id => @container.id, :power_action => 'status'
|
85
|
+
assert_response :success
|
86
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'creates a container with correct params' do
|
90
|
+
repository_name = "centos"
|
91
|
+
tag = "7"
|
92
|
+
name = "foo"
|
93
|
+
registry_uri = URI.parse(@registry.url)
|
94
|
+
Service::Containers.any_instance.expects(:pull_image).returns(true)
|
95
|
+
Service::Containers.any_instance
|
96
|
+
.expects(:start_container).returns(true).with do |container|
|
97
|
+
container.must_be_kind_of(Container)
|
98
|
+
container.repository_name.must_equal(repository_name)
|
99
|
+
container.tag.must_equal(tag)
|
100
|
+
container.compute_resource_id.must_equal(@compute_resource.id)
|
101
|
+
container.name.must_equal(name)
|
102
|
+
container.repository_pull_url.must_include(registry_uri.host)
|
103
|
+
container.repository_pull_url.must_include("#{repository_name}:#{tag}")
|
104
|
+
end
|
105
|
+
post :create, :container => { :compute_resource_id => @compute_resource.id,
|
106
|
+
:name => name,
|
107
|
+
:registry_id => @registry.id,
|
108
|
+
:repository_name => repository_name,
|
109
|
+
:tag => tag }
|
110
|
+
assert_response :created
|
101
111
|
end
|
102
|
-
post :create, :container => { :compute_resource_id => @compute_resource.id,
|
103
|
-
:name => name,
|
104
|
-
:registry_id => @registry.id,
|
105
|
-
:repository_name => repository_name,
|
106
|
-
:tag => tag }
|
107
|
-
assert_response :created
|
108
112
|
end
|
109
113
|
|
110
114
|
test 'creates a katello container with correct params' do
|
@@ -59,6 +59,21 @@ class ContainersControllerTest < ActionController::TestCase
|
|
59
59
|
flash[:notice]
|
60
60
|
end
|
61
61
|
|
62
|
+
test 'deleting with container params deletes container object' do
|
63
|
+
managed_container = FactoryGirl.create(
|
64
|
+
:container,
|
65
|
+
:compute_resource => @container_resource)
|
66
|
+
managed_container.update(:uuid => @container.id)
|
67
|
+
ComputeResource.any_instance.expects(:destroy_vm).
|
68
|
+
with(@container.id).returns(true)
|
69
|
+
Container.any_instance.expects(:destroy)
|
70
|
+
delete :destroy, { :compute_resource_id => @container_resource.id,
|
71
|
+
:id => @container.id }, set_session_user
|
72
|
+
assert_redirected_to containers_path
|
73
|
+
assert_equal "Container #{managed_container.uuid} is being deleted.",
|
74
|
+
flash[:notice]
|
75
|
+
end
|
76
|
+
|
62
77
|
test 'failed deletion of managed container keeps container in Foreman' do
|
63
78
|
ComputeResource.any_instance.stubs(:destroy_vm).
|
64
79
|
raises(::Foreman::Exception.new('Could not destroy Docker container'))
|
@@ -24,4 +24,15 @@ class ContainersServiceTest < ActiveSupport::TestCase
|
|
24
24
|
Fog.unmock!
|
25
25
|
assert_equal DockerContainerWizardState.where(:id => @state.id).count, 0
|
26
26
|
end
|
27
|
+
|
28
|
+
test 'passes errors from compute resource' do
|
29
|
+
# Since the compute resource will be unreachable, this test will always
|
30
|
+
# fail at the 'pull_image' step
|
31
|
+
containers_service = Service::Containers.new
|
32
|
+
assert_raises(ActiveRecord::Rollback) do
|
33
|
+
containers_service.create_container_object(@state)
|
34
|
+
end
|
35
|
+
assert containers_service.errors.present?
|
36
|
+
end
|
37
|
+
|
27
38
|
end
|
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: 3.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: 2016-
|
11
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- app/assets/stylesheets/foreman_docker/terminal.css.scss
|
69
69
|
- app/controllers/api/v2/containers_controller.rb
|
70
70
|
- app/controllers/api/v2/registries_controller.rb
|
71
|
+
- app/controllers/concerns/foreman/controller/parameters/docker_registry.rb
|
71
72
|
- app/controllers/concerns/foreman_docker/find_container.rb
|
72
73
|
- app/controllers/containers/steps_controller.rb
|
73
74
|
- app/controllers/containers_controller.rb
|