foreman_docker 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -1
  3. data/app/assets/javascripts/foreman_docker/container_image_search.js +203 -0
  4. data/app/assets/javascripts/foreman_docker/create_registry.js +15 -0
  5. data/app/assets/stylesheets/foreman_docker/autocomplete.css.scss +4 -0
  6. data/app/controllers/concerns/foreman/controller/parameters/docker_registry.rb +1 -1
  7. data/app/controllers/image_search_controller.rb +6 -35
  8. data/app/helpers/container_steps_helper.rb +0 -1
  9. data/app/models/container.rb +1 -1
  10. data/app/models/docker_container_wizard_state.rb +1 -1
  11. data/app/models/docker_container_wizard_states/configuration.rb +1 -1
  12. data/app/models/docker_container_wizard_states/environment.rb +1 -1
  13. data/app/models/docker_container_wizard_states/image.rb +1 -1
  14. data/app/models/docker_container_wizard_states/preliminary.rb +1 -1
  15. data/app/models/docker_parameter.rb +1 -1
  16. data/app/models/docker_registry.rb +8 -4
  17. data/app/models/foreman_docker/docker.rb +10 -2
  18. data/app/models/service/registry_api.rb +10 -5
  19. data/app/views/containers/steps/_form_buttons.html.erb +5 -7
  20. data/app/views/containers/steps/_image_hub_tab.html.erb +16 -17
  21. data/app/views/containers/steps/image.html.erb +1 -3
  22. data/app/views/image_search/_repository_search_results.html.erb +1 -1
  23. data/app/views/registries/_form.html.erb +5 -3
  24. data/app/views/registries/index.html.erb +11 -10
  25. data/db/migrate/20170508130316_add_verify_ssl_option_to_docker_registries.rb +5 -0
  26. data/lib/foreman_docker/engine.rb +7 -6
  27. data/lib/foreman_docker/version.rb +1 -1
  28. data/test/functionals/image_search_controller_test.rb +120 -169
  29. data/test/integration/container_steps_test.rb +118 -18
  30. data/test/integration/registry_creation_test.rb +19 -0
  31. data/test/units/docker_container_wizard_states/image_test.rb +0 -1
  32. data/test/units/docker_registry_test.rb +0 -8
  33. data/test/units/registry_api_test.rb +13 -1
  34. metadata +10 -6
  35. data/app/assets/javascripts/foreman_docker/image_step.js +0 -175
@@ -12,19 +12,17 @@ module Service
12
12
  def initialize(params = {})
13
13
  self.config = DEFAULTS.merge(params)
14
14
  self.url = config[:url]
15
- @user = config[:user] unless config[:user].blank?
16
- @password = config[:password] unless config[:password].blank?
17
15
 
18
16
  Docker.logger = logger if Rails.env.development? || Rails.env.test?
19
17
  end
20
18
 
21
19
  def connection
22
- @connection ||= ::Docker::Connection.new(url, credentials)
20
+ @connection ||= ::Docker::Connection.new(url, default_connection_options.merge(credentials))
23
21
  end
24
22
 
25
23
  def get(path, params = nil)
26
24
  response = connection.get('/'.freeze, params,
27
- DEFAULTS[:connection].merge({ path: "#{path}" }))
25
+ connection.options.merge({ path: "#{path}" }))
28
26
  response = parse_json(response)
29
27
  response
30
28
  end
@@ -65,6 +63,12 @@ module Service
65
63
 
66
64
  private
67
65
 
66
+ def default_connection_options
67
+ @default_connection_options ||= DEFAULTS[:connection].tap do |defaults|
68
+ defaults[:ssl_verify_peer] = config.fetch(:verify_ssl, true)
69
+ end
70
+ end
71
+
68
72
  def parse_json(string)
69
73
  JSON.parse(string)
70
74
  rescue => e
@@ -86,7 +90,8 @@ module Service
86
90
  end
87
91
 
88
92
  def credentials
89
- { user: @user, password: @password }
93
+ { user: config.fetch(:user, nil),
94
+ password: config.fetch(:password, nil) }
90
95
  end
91
96
 
92
97
  def filter_tags(result, query)
@@ -1,20 +1,18 @@
1
1
  <div class="clearfix">
2
- <div class="form-actions">
2
+ <div class="form-actions col-md-6 col-md-offset-2 small-gutter">
3
3
  <% if step == :preliminary %>
4
4
  <%= link_to _("Cancel"), containers_path, :class => "btn btn-danger" %>
5
5
  <% else %>
6
6
  <a class="btn btn-default" href="<%= previous_wizard_path %>">
7
- <span class="glyphicon glyphicon-chevron-left"></span>
8
- <%= _("Back") %>
7
+ <%= _("Previous Step") %>
9
8
  </a>
10
9
  <% end %>
11
- <% next_id = defined?(registry) ? "next_#{registry}" : "next" %>
12
- <%= button_tag(:id => next_id, :type => 'submit', :class => "btn btn-primary pull-right") do %>
10
+
11
+ <%= button_tag(:id => 'next', :type => 'submit', :class => "btn btn-primary") do %>
13
12
  <% if last_step? %>
14
13
  <%= _("Submit") %>
15
14
  <% else %>
16
- <%= _("Next") %>
17
- <span class="glyphicon glyphicon-chevron-right"></span>
15
+ <%= _("Next Step") %>
18
16
  <% end %>
19
17
  <% end %>
20
18
  </div>
@@ -17,47 +17,46 @@
17
17
  <% end %>
18
18
 
19
19
  <% if registry == "registry" -%>
20
- <div class="input-group col-md-6">
21
20
  <%= select_registry f %>
22
- </div>
23
21
  <% end -%>
24
22
 
25
23
  <% help_type = f.object.errors[:repository_name].present? ? :help_block : :help_inline %>
26
24
  <%= text_f(f, :repository_name,
27
25
  :label => _('Search'),
28
- :size => 'col-md-6',
29
26
  :wrapper_class => (image_search_wrapper_class(model) if tab_active?(registry)),
30
- :'data-url' => auto_complete_repository_name_image_search_path(model.compute_resource_id),
27
+ :'data-url' => search_repository_image_search_path(model.compute_resource_id),
31
28
  :value => f.object.repository_name.present? ? f.object.repository_name : '',
32
29
  :'data-registry' => registry,
33
30
  :'data-image' => true,
34
- :'data-search' => true,
35
31
  :'data-min-length' => 1,
36
32
  :focus_on_load => true,
37
33
  :placeholder => _('Find your favorite container, e.g. centos'),
38
34
  :control_group_id => "#{registry}_image_search",
39
- help_type => link_to_function(
40
- icon_text('search', ''),
41
- 'searchRepo(this)',
42
- :class => 'btn btn-default',
43
- :id => "search_repository_#{registry}",
44
- :'data-registry' => registry,
45
- :'data-url' => search_repository_image_search_path(model.compute_resource_id)
46
- ) + content_tag(:span, '', :id => 'image-confirmation').html_safe) %>
35
+ :help_inline => spinner('', class: 'hide autocomplete-status')) %>
47
36
 
48
37
  <%= text_f f, :tag,
49
38
  :control_group_id => "#{registry}_tag_search",
50
39
  :'data-registry' => registry,
51
40
  :'data-tag' => true,
52
- :'data-url' => auto_complete_image_tag_image_search_path(model.compute_resource_id) %>
41
+ :'data-min-length' => 0,
42
+ :'data-url' => search_repository_image_search_path(model.compute_resource_id),
43
+ :help_inline => spinner('', class: 'hide autocomplete-status') %>
44
+
45
+ <div class="col-md-6 col-md-offset-2 small-gutter">
46
+ <%= link_to(icon_text('search', _('Search for images')), "#",
47
+ :id => "search_repository_button_#{registry}",
48
+ :class => 'image-search-button btn btn-default',
49
+ :'data-registry' => registry,
50
+ :'data-url' => search_repository_image_search_path(model.compute_resource_id)) %>
51
+ </div>
53
52
 
54
- <div class="col-md-12">
53
+ <div class="registry-search-results col-md-12">
55
54
  <div data-search-spinner=true class='col-md-offset-3 hide'>
56
55
  <span data-wait-text=true>
57
56
  </span>
58
- <%= spinner('', :id => "loading_repositories_indicator_#{registry}") %>
57
+ <%= spinner('') %>
59
58
  </div>
60
- <div data-repository-search-results=true >
59
+ <div class="registry-search-results-list">
61
60
  </div>
62
61
  </div>
63
62
  <%= render :partial => 'form_buttons', locals: { :registry => registry} %>
@@ -1,4 +1,4 @@
1
- <%= javascript 'foreman_docker/image_step' %>
1
+ <%= javascript 'foreman_docker/container_image_search' %>
2
2
  <%= stylesheet 'foreman_docker/autocomplete' %>
3
3
 
4
4
  <%= render :layout => 'title', :locals => { :step => 2 } do %>
@@ -11,11 +11,9 @@
11
11
  <% end -%>
12
12
 
13
13
  <li class='<%= tab_class(:hub) %>'><a href="#hub" data-toggle="tab" id="hub_tab">
14
- <span class="glyphicon glyphicon-cloud-download"></span>
15
14
  <%= _("Docker hub") %>
16
15
  </a></li>
17
16
  <li class='<%= tab_class(:registry) %>'><a href="#registry" data-toggle="tab" id="registry_tab">
18
- <span class="glyphicon glyphicon-cloud-download"></span>
19
17
  <%= _("External registry") %>
20
18
  </a></li>
21
19
  </ul>
@@ -1,5 +1,5 @@
1
1
  <% repositories.each do |repository| %>
2
- <h3><%= link_to cleanup_image_name(repository['name']), '#', :onclick => 'repoSelected(this)', "data-hub" => use_hub %></h3>
2
+ <h3><%= link_to cleanup_image_name(repository['name']), '#', class: 'repository-name' %></h3>
3
3
  <p>
4
4
  <%= '<span class="glyphicon glyphicon-certificate" title="Official"></span>'.html_safe if repository['is_official'] %>
5
5
  <%= '<span class="glyphicon glyphicon-thumbs-up" title="Trusted"></span>'.html_safe if repository['is_trusted'] %>
@@ -1,3 +1,4 @@
1
+ <%= javascript 'foreman_docker/create_registry' %>
1
2
  <%= form_for @registry, :url => (@registry.new_record? ? registries_path : registry_path(:id => @registry.id)) do |f| %>
2
3
  <%= base_errors_for @registry %>
3
4
  <ul class="nav nav-tabs" data-tabs="tabs">
@@ -14,9 +15,10 @@
14
15
  <div class="tab-pane active" id="primary">
15
16
  <%= text_f f, :name %>
16
17
  <%= text_f f, :url %>
17
- <%= text_f f, :description, :help_inline => _("Description of the registry") %>
18
- <%= text_f f, :username, :help_inline => _("Username used to access the registry") %>
19
- <%= password_f f, :password, :help_inline => _("Password used for authentication to the registry") %>
18
+ <%= text_f f, :description, :label_help => _("Description of the registry") %>
19
+ <%= text_f f, :username, :label_help => _("Username used to access the registry") %>
20
+ <%= password_f f, :password, :label_help => _("Password used for authentication to the registry") %>
21
+ <%= checkbox_f f, :verify_ssl, :label_help => _("Disable to use an insecure registry"), :wrapper_class => 'form-group hidden' %>
20
22
  </div>
21
23
 
22
24
  <%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @registry %>
@@ -3,16 +3,16 @@
3
3
  <%= title_actions(new_link(_("Create Registry"))) %>
4
4
 
5
5
  <table class="table table-bordered table-striped table-condensed" data-table="inline">
6
+ <thead>
7
+ <tr>
8
+ <th><%= sort :name, :as => _("Name") %></th>
9
+ <th class="hidden-tablet hidden-xs"><%= sort :url, :as => _("URL") %></th>
10
+ <th class="hidden-tablet hidden-xs"><%= _("Description") %></th>
11
+ <th><%= _('Actions') %></th>
12
+ </tr>
6
13
  </thead>
7
- <tr>
8
- <th class="text-center"><%= sort :name, :as => _("Name") %></th>
9
- <th class="hidden-tablet hidden-xs text-center"><%= sort :url, :as => _("URL") %></th>
10
- <th class="hidden-tablet hidden-xs text-center"><%= _("Description") %></th>
11
- <th><%= _('Actions') %></th>
12
- </tr>
13
- </thead>
14
-
15
- <% @registries.each do |r| %>
14
+ <tbody>
15
+ <% @registries.each do |r| %>
16
16
  <tr>
17
17
  <td><%= link_to_if_authorized trunc_with_tooltip(r.name), hash_for_edit_registry_path(:id => r).merge(:auth_object => r, :authorizer => authorizer) %></td>
18
18
  <td class="hidden-tablet hidden-xs text-center"><%= trunc_with_tooltip(r.url) %></td>
@@ -22,7 +22,8 @@
22
22
  merge(:auth_object => r, :authorizer => authorizer),
23
23
  :confirm => _("Delete %s?") % r.name) %></td>
24
24
  </tr>
25
- <% end %>
25
+ <% end %>
26
+ </tbody>
26
27
  </table>
27
28
 
28
29
  <%= will_paginate_with_info @registries %>
@@ -0,0 +1,5 @@
1
+ class AddVerifySslOptionToDockerRegistries < ActiveRecord::Migration
2
+ def change
3
+ add_column :docker_registries, :verify_ssl, :boolean, default: true
4
+ end
5
+ end
@@ -20,17 +20,18 @@ module ForemanDocker
20
20
  end
21
21
  end
22
22
 
23
+ foreman_docker_assets = %w[foreman_docker/autocomplete.css
24
+ foreman_docker/terminal.css
25
+ foreman_docker/container_image_search.js
26
+ foreman_docker/create_registry.js]
27
+
23
28
  initializer "foreman_docker.assets.precompile" do |app|
24
- app.config.assets.precompile += %w(foreman_docker/autocomplete.css
25
- foreman_docker/terminal.css
26
- foreman_docker/image_step.js)
29
+ app.config.assets.precompile += foreman_docker_assets
27
30
  end
28
31
 
29
32
  initializer 'foreman_docker.configure_assets', :group => :assets do
30
33
  SETTINGS[:foreman_docker] =
31
- { :assets => { :precompile => ['foreman_docker/autocomplete.css',
32
- 'foreman_docker/terminal.css',
33
- 'foreman_docker/image_step.js'] } }
34
+ { :assets => { :precompile => foreman_docker_assets } }
34
35
  end
35
36
 
36
37
  initializer 'foreman_docker.register_gettext', :after => :load_config_initializers do
@@ -1,3 +1,3 @@
1
1
  module ForemanDocker
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.0'
3
3
  end
@@ -18,204 +18,155 @@ class ImageSearchControllerTest < ActionController::TestCase
18
18
  .stubs(:find).returns(registry)
19
19
  end
20
20
 
21
- describe '#auto_complete_repository_name' do
22
- test 'returns if an image is available' do
23
- exists = ['true', 'false'].sample
24
- search_type = ['hub', 'registry'].sample
25
- subject.instance_variable_set(:@image_search_service, image_search_service)
26
- image_search_service.expects(:available?).returns(exists)
27
-
28
- xhr :get, :auto_complete_repository_name,
29
- { registry: search_type, search: term,
30
- id: compute_resource }, set_session_user
31
- assert_equal exists, response.body
32
- end
33
-
34
- context 'it is a Docker Hub tab request' do
35
- let(:search_type) { 'hub' }
21
+ describe '#search_repository' do
22
+ let(:search_types) { ['hub', 'registry'] }
36
23
 
37
- test 'it queries the compute_resource and Docker Hub' do
38
- compute_resource.expects(:image).with(term)
39
- .returns(term)
40
- compute_resource.expects(:tags_for_local_image)
41
- .returns(tags)
42
- docker_hub.expects(:tags).returns([])
24
+ describe 'calls #search on image_search_service' do
25
+ setup do
26
+ subject.instance_variable_set(:@image_search_service, image_search_service)
27
+ end
43
28
 
44
- xhr :get, :auto_complete_repository_name,
45
- { registry: search_type, search: term,
29
+ test 'passes params search and tags' do
30
+ tags_enabled = ['true', 'false'].sample
31
+ image_search_service.expects(:search).with({ term: term, tags: tags_enabled })
32
+ .returns([])
33
+ xhr :get, :search_repository,
34
+ { registry: search_types.sample, search: term, tags: tags_enabled,
46
35
  id: compute_resource }, set_session_user
47
36
  end
48
- end
49
-
50
- context 'it is a External Registry tab request' do
51
- let(:search_type) { 'registry' }
52
37
 
53
- test 'it only queries the registry api' do
54
- compute_resource.expects(:image).with(term).never
55
- docker_hub.expects(:tags).never
56
- registry.api.expects(:tags).with(term, nil)
57
- .returns(['latest'])
38
+ test 'returns an array of { label:, value: } hashes' do
39
+ image_search_service.expects(:search).with({ term: term, tags: 'true' })
40
+ .returns(tags)
41
+ xhr :get, :search_repository,
42
+ { registry: search_types.sample, search: term, tags: 'true',
43
+ id: compute_resource }, set_session_user
44
+ assert_equal tags.first, JSON.parse(response.body).first['value']
45
+ end
58
46
 
59
- xhr :get, :auto_complete_repository_name,
60
- { registry: search_type, registry_id: registry,
61
- search: term, id: compute_resource }, set_session_user
47
+ test 'returns html with the found images' do
48
+ image_search_service.expects(:search)
49
+ .with({ term: term, tags: 'false' })
50
+ .returns([{ 'name' => term }])
51
+ xhr :get, :search_repository,
52
+ { registry: search_types.sample, search: term,
53
+ id: compute_resource, format: :html}, set_session_user
54
+ assert response.body.include?(term)
62
55
  end
63
- end
64
- end
65
56
 
66
- describe '#auto_complete_image_tag' do
67
- let(:tag_fragment) { 'lat' }
68
- let(:term) { "#{docker_image}:#{tag_fragment}"}
69
-
70
- test 'returns an array of { label:, value: } hashes' do
71
- search_type = ['hub', 'registry'].sample
72
- subject.instance_variable_set(:@image_search_service, image_search_service)
73
- image_search_service.expects(:search)
74
- .with({ term: term, tags: 'true' })
75
- .returns(tags)
76
- xhr :get, :auto_complete_image_tag,
77
- { registry: search_type, search: term,
78
- id: compute_resource }, set_session_user
79
- assert_equal tags.first, JSON.parse(response.body).first['value']
80
- end
57
+ [Docker::Error::DockerError, Excon::Errors::Error, Errno::ECONNREFUSED].each do |error|
58
+ test "search_repository catch exceptions on network errors like #{error}" do
59
+ image_search_service.expects(:search)
60
+ .raises(error)
61
+ xhr :get, :search_repository,
62
+ { registry: search_types.sample, search: term, id: compute_resource }, set_session_user
81
63
 
82
- context 'a Docker Hub tab request' do
83
- let(:search_type) { 'hub' }
64
+ assert_response :error
65
+ assert response.body.include?('An error occured during repository search:')
66
+ end
67
+ end
84
68
 
85
- test 'it searches Docker Hub and the ComputeResource' do
86
- compute_resource.expects(:image).with(docker_image)
87
- .returns(term)
88
- compute_resource.expects(:tags_for_local_image)
89
- .returns(tags)
90
- docker_hub.expects(:tags).returns([])
69
+ test "centos 7 search responses are handled correctly" do
70
+ repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
71
+ repo_full_name = "redhat.com: #{repository}"
72
+ expected = [{ "description" => "Really fancy database app...",
73
+ "is_official" => true,
74
+ "is_trusted" => true,
75
+ "name" => repo_full_name,
76
+ "star_count" => 0
77
+ }]
78
+ image_search_service.expects(:search).returns(expected)
79
+ xhr :get, :search_repository,
80
+ { registry: search_types.sample, search: 'centos', id: compute_resource, format: :html }, set_session_user
81
+ assert_response :success
82
+ refute response.body.include?(repo_full_name)
83
+ assert response.body.include?(repository)
84
+ end
91
85
 
92
- xhr :get, :auto_complete_image_tag,
93
- { registry: search_type, search: term,
94
- id: compute_resource }, set_session_user
86
+ test "fedora search responses are handled correctly" do
87
+ repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
88
+ repo_full_name = repository
89
+ request.env["HTTP_ACCEPT"] = "application/javascript"
90
+ expected = [{ "description" => "Really fancy database app...",
91
+ "is_official" => true,
92
+ "is_trusted" => true,
93
+ "name" => repo_full_name,
94
+ "star_count" => 0
95
+ }]
96
+ image_search_service.expects(:search).returns(expected)
97
+ xhr :get, :search_repository,
98
+ { registry: search_types.sample, search: term, id: compute_resource, format: :html }, set_session_user
99
+ assert_response :success
100
+ assert response.body.include?(repo_full_name)
101
+ assert response.body.include?(repository)
95
102
  end
96
103
  end
97
104
 
98
- context 'it is a External Registry tab request' do
99
- let(:search_type) { 'registry' }
105
+ describe 'for image names' do
106
+ context 'with a Docker Hub tab request' do
107
+ let(:search_type) { 'hub' }
100
108
 
101
- test 'it only queries the registry api' do
102
- compute_resource.expects(:image).with(docker_image).never
103
- docker_hub.expects(:tags).never
104
- registry.api.expects(:tags).with(docker_image, tag_fragment)
105
- .returns([])
109
+ test 'it searches Docker Hub and the ComputeResource' do
110
+ compute_resource.expects(:local_images)
111
+ .returns([OpenStruct.new(info: { 'RepoTags' => [term] })])
112
+ docker_hub.expects(:search).returns({})
106
113
 
107
- xhr :get, :auto_complete_image_tag,
108
- { registry: search_type, registry_id: registry,
109
- search: term, id: compute_resource }, set_session_user
114
+ xhr :get, :search_repository,
115
+ { registry: search_type, search: term,
116
+ id: compute_resource }, set_session_user
117
+ end
110
118
  end
111
- end
112
- end
113
119
 
114
- describe '#search_repository' do
115
- test 'returns html with the found images' do
116
- search_type = ['hub', 'registry'].sample
117
- subject.instance_variable_set(:@image_search_service, image_search_service)
118
- image_search_service.expects(:search)
119
- .with({ term: term, tags: 'false' })
120
- .returns([{ 'name' => term}])
121
- xhr :get, :search_repository,
122
- { registry: search_type, search: term,
123
- id: compute_resource }, set_session_user
124
- assert response.body.include?(term)
125
- end
120
+ context 'with a External Registry tab request' do
121
+ let(:search_type) { 'registry' }
126
122
 
127
- context 'a Docker Hub tab request' do
128
- let(:search_type) { 'hub' }
123
+ test 'it only queries the registry api' do
124
+ compute_resource.expects(:local_images).with(docker_image).never
125
+ docker_hub.expects(:search).never
126
+ registry.api.expects(:search).with(docker_image)
127
+ .returns({})
129
128
 
130
- test 'it searches Docker Hub and the ComputeResource' do
131
- compute_resource.expects(:local_images)
132
- .returns([OpenStruct.new(info: { 'RepoTags' => [term] })])
133
- docker_hub.expects(:search).returns({})
134
-
135
- xhr :get, :search_repository,
136
- { registry: search_type, search: term,
137
- id: compute_resource }, set_session_user
129
+ xhr :get, :search_repository,
130
+ { registry: search_type, registry_id: registry,
131
+ search: term, id: compute_resource }, set_session_user
132
+ end
138
133
  end
139
134
  end
140
135
 
141
- context 'it is a External Registry tab request' do
142
- let(:search_type) { 'registry' }
136
+ describe 'for tags' do
137
+ let(:tag_fragment) { 'lat' }
138
+ let(:term) { "#{docker_image}:#{tag_fragment}"}
143
139
 
144
- test 'it only queries the registry api' do
145
- compute_resource.expects(:local_images).with(docker_image).never
146
- docker_hub.expects(:search).never
147
- registry.api.expects(:search).with(docker_image)
148
- .returns({})
140
+ context 'with a Docker Hub tab request' do
141
+ let(:search_type) { 'hub' }
149
142
 
150
- xhr :get, :search_repository,
151
- { registry: search_type, registry_id: registry,
152
- search: term, id: compute_resource }, set_session_user
143
+ test 'it searches Docker Hub and the ComputeResource' do
144
+ compute_resource.expects(:image).with(docker_image)
145
+ .returns(term)
146
+ compute_resource.expects(:tags_for_local_image)
147
+ .returns(tags)
148
+ docker_hub.expects(:tags).returns([])
149
+
150
+ xhr :get, :search_repository,
151
+ { registry: search_type, search: term, tags: 'true',
152
+ id: compute_resource }, set_session_user
153
+ end
153
154
  end
154
- end
155
- end
156
155
 
157
- [Docker::Error::DockerError, Excon::Errors::Error, Errno::ECONNREFUSED].each do |error|
158
- test 'auto_complete_repository_name catches exceptions on network errors' do
159
- ForemanDocker::ImageSearch.any_instance.expects(:available?)
160
- .raises(error)
161
- xhr :get, :auto_complete_repository_name,
162
- { registry: 'hub', search: term, id: compute_resource }, set_session_user
163
- assert_response_is_expected
164
- end
156
+ context 'with a External Registry tab request' do
157
+ let(:search_type) { 'registry' }
165
158
 
166
- test 'auto_complete_image_tag catch exceptions on network errors' do
167
- ForemanDocker::ImageSearch.any_instance.expects(:search).raises(error)
168
- xhr :get, :auto_complete_image_tag,
169
- { registry: 'hub', search: term, id: compute_resource }, set_session_user
170
- assert_response_is_expected
171
- end
159
+ test 'it only queries the registry api' do
160
+ compute_resource.expects(:image).with(docker_image).never
161
+ docker_hub.expects(:tags).never
162
+ registry.api.expects(:tags).with(docker_image, tag_fragment)
163
+ .returns([])
172
164
 
173
- test 'search_repository catch exceptions on network errors' do
174
- ForemanDocker::ImageSearch.any_instance.expects(:search).raises(error)
175
- xhr :get, :search_repository,
176
- { registry: 'hub', search: term, id: compute_resource }, set_session_user
177
- assert_response_is_expected
165
+ xhr :get, :search_repository,
166
+ { registry: search_type, registry_id: registry, tags: 'true',
167
+ search: term, id: compute_resource }, set_session_user
168
+ end
169
+ end
178
170
  end
179
171
  end
180
-
181
- test "centos 7 search responses are handled correctly" do
182
- repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
183
- repo_full_name = "redhat.com: #{repository}"
184
- request.env["HTTP_ACCEPT"] = "application/javascript"
185
- expected = [{ "description" => "Really fancy database app...",
186
- "is_official" => true,
187
- "is_trusted" => true,
188
- "name" => repo_full_name,
189
- "star_count" => 0
190
- }]
191
- ForemanDocker::ImageSearch.any_instance.expects(:search).returns(expected).at_least_once
192
- xhr :get, :search_repository,
193
- { registry: 'hub', search: 'centos', id: compute_resource }, set_session_user
194
- assert_response :success
195
- refute response.body.include?(repo_full_name)
196
- assert response.body.include?(repository)
197
- end
198
-
199
- test "fedora search responses are handled correctly" do
200
- repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
201
- repo_full_name = repository
202
- request.env["HTTP_ACCEPT"] = "application/javascript"
203
- expected = [{ "description" => "Really fancy database app...",
204
- "is_official" => true,
205
- "is_trusted" => true,
206
- "name" => repo_full_name,
207
- "star_count" => 0
208
- }]
209
- ForemanDocker::ImageSearch.any_instance.expects(:search).returns(expected).at_least_once
210
- xhr :get, :search_repository,
211
- { registry: 'hub', search: 'centos', id: compute_resource }, set_session_user
212
- assert_response :success
213
- assert response.body.include?(repo_full_name)
214
- assert response.body.include?(repository)
215
- end
216
-
217
- def assert_response_is_expected
218
- assert_response :error
219
- assert response.body.include?('An error occured during repository search:')
220
- end
221
172
  end