katello 3.4.5 → 3.5.0.rc1

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.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/app/assets/stylesheets/katello/katello.scss +7 -5
  4. data/app/controllers/katello/api/v2/activation_keys_controller.rb +3 -3
  5. data/app/controllers/katello/api/v2/api_controller.rb +8 -0
  6. data/app/controllers/katello/api/v2/capsule_content_controller.rb +6 -1
  7. data/app/controllers/katello/api/v2/content_view_filter_rules_controller.rb +2 -1
  8. data/app/controllers/katello/api/v2/content_view_versions_controller.rb +1 -1
  9. data/app/controllers/katello/api/v2/content_views_controller.rb +1 -1
  10. data/app/controllers/katello/api/v2/host_collections_controller.rb +1 -1
  11. data/app/controllers/katello/api/v2/host_subscriptions_controller.rb +2 -2
  12. data/app/controllers/katello/api/v2/host_tracer_controller.rb +1 -1
  13. data/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb +6 -6
  14. data/app/controllers/katello/api/v2/repositories_controller.rb +6 -7
  15. data/app/controllers/katello/api/v2/repository_sets_controller.rb +25 -4
  16. data/app/controllers/katello/concerns/api/v2/content_overrides_controller.rb +2 -4
  17. data/app/controllers/katello/concerns/api/v2/hostgroups_controller_extensions.rb +10 -27
  18. data/app/controllers/katello/concerns/api/v2/smart_proxies_controller_extensions.rb +10 -14
  19. data/app/controllers/katello/concerns/hosts_controller_extensions.rb +33 -0
  20. data/app/helpers/katello/hosts_and_hostgroups_helper.rb +2 -1
  21. data/app/helpers/katello/organizations_helper.rb +1 -1
  22. data/app/helpers/katello/providers_helper.rb +1 -1
  23. data/app/lib/actions/candlepin/abstract_async_task.rb +1 -1
  24. data/app/lib/actions/candlepin/candlepin_listening_service.rb +17 -6
  25. data/app/lib/actions/candlepin/import_pool_handler.rb +21 -56
  26. data/app/lib/actions/candlepin/listen_on_candlepin_events.rb +1 -0
  27. data/app/lib/actions/candlepin/owner/import_products.rb +1 -3
  28. data/app/lib/actions/candlepin/product/content_create.rb +2 -0
  29. data/app/lib/actions/candlepin/product/content_update.rb +2 -0
  30. data/app/lib/actions/candlepin/product/create.rb +2 -10
  31. data/app/lib/actions/candlepin/product/create_unlimited_subscription.rb +8 -1
  32. data/app/lib/actions/katello/capsule_content/sync.rb +12 -3
  33. data/app/lib/actions/katello/host/attach_subscriptions.rb +1 -1
  34. data/app/lib/actions/katello/host/hypervisors_update.rb +2 -4
  35. data/app/lib/actions/katello/host/remove_subscriptions.rb +1 -1
  36. data/app/lib/actions/katello/organization/create.rb +2 -2
  37. data/app/lib/actions/katello/organization/manifest_refresh.rb +1 -2
  38. data/app/lib/actions/katello/product/content_create.rb +4 -4
  39. data/app/lib/actions/katello/product/create.rb +13 -11
  40. data/app/lib/actions/katello/repository/sync.rb +0 -1
  41. data/app/lib/actions/katello/repository/update.rb +2 -1
  42. data/app/lib/actions/pulp/consumer/generate_applicability.rb +5 -1
  43. data/app/lib/actions/pulp/repository/create.rb +1 -0
  44. data/app/lib/actions/pulp/repository/create_in_plan.rb +4 -4
  45. data/app/lib/actions/pulp/repository/sync.rb +1 -1
  46. data/app/lib/katello/http_resource.rb +1 -1
  47. data/app/lib/katello/lazy_accessor.rb +1 -1
  48. data/app/lib/katello/resources/candlepin.rb +2 -2
  49. data/app/lib/katello/util/data.rb +6 -0
  50. data/app/lib/katello/util/support.rb +1 -1
  51. data/app/models/katello/activation_key.rb +25 -7
  52. data/app/models/katello/concerns/host_managed_extensions.rb +60 -17
  53. data/app/models/katello/concerns/subscription_facet_host_extensions.rb +31 -10
  54. data/app/models/katello/content_facet_applicable_rpm.rb +0 -2
  55. data/app/models/katello/content_facet_erratum.rb +0 -2
  56. data/app/models/katello/content_facet_repository.rb +0 -2
  57. data/app/models/katello/content_view.rb +3 -4
  58. data/app/models/katello/content_view_component.rb +1 -3
  59. data/app/models/katello/content_view_docker_filter_rule.rb +0 -2
  60. data/app/models/katello/content_view_environment.rb +2 -4
  61. data/app/models/katello/content_view_erratum_filter_rule.rb +0 -2
  62. data/app/models/katello/content_view_filter.rb +0 -2
  63. data/app/models/katello/content_view_package_filter_rule.rb +0 -2
  64. data/app/models/katello/content_view_package_group_filter_rule.rb +0 -2
  65. data/app/models/katello/content_view_puppet_environment.rb +0 -2
  66. data/app/models/katello/content_view_puppet_environment_puppet_module.rb +0 -2
  67. data/app/models/katello/content_view_puppet_module.rb +0 -2
  68. data/app/models/katello/content_view_repository.rb +0 -2
  69. data/app/models/katello/content_view_version.rb +0 -2
  70. data/app/models/katello/erratum_bugzilla.rb +0 -2
  71. data/app/models/katello/erratum_cve.rb +0 -2
  72. data/app/models/katello/erratum_package.rb +0 -2
  73. data/app/models/katello/ext/label_from_name.rb +1 -1
  74. data/app/models/katello/glue/candlepin/pool.rb +18 -11
  75. data/app/models/katello/glue/candlepin/product.rb +1 -2
  76. data/app/models/katello/glue/pulp/repo.rb +13 -6
  77. data/app/models/katello/glue/pulp/repos.rb +16 -16
  78. data/app/models/katello/gpg_key.rb +0 -2
  79. data/app/models/katello/host/content_facet.rb +21 -0
  80. data/app/models/katello/host/info_provider.rb +56 -0
  81. data/app/models/katello/host/subscription_facet.rb +5 -3
  82. data/app/models/katello/host_collection.rb +0 -2
  83. data/app/models/katello/host_collection_hosts.rb +0 -2
  84. data/app/models/katello/host_installed_package.rb +0 -2
  85. data/app/models/katello/host_tracer.rb +0 -2
  86. data/app/models/katello/key_host_collection.rb +0 -2
  87. data/app/models/katello/kt_environment.rb +0 -2
  88. data/app/models/katello/model.rb +1 -1
  89. data/app/models/katello/pool.rb +3 -3
  90. data/app/models/katello/product.rb +10 -3
  91. data/app/models/katello/provider.rb +0 -2
  92. data/app/models/katello/repository.rb +0 -2
  93. data/app/models/katello/repository_docker_manifest.rb +0 -2
  94. data/app/models/katello/repository_erratum.rb +0 -2
  95. data/app/models/katello/repository_file.rb +0 -2
  96. data/app/models/katello/repository_ostree_branch.rb +0 -2
  97. data/app/models/katello/repository_package_group.rb +0 -1
  98. data/app/models/katello/repository_puppet_module.rb +0 -2
  99. data/app/models/katello/repository_rpm.rb +0 -2
  100. data/app/models/katello/rpm.rb +2 -2
  101. data/app/models/katello/subscription_facet_activation_key.rb +0 -2
  102. data/app/models/katello/subscription_facet_pool.rb +6 -0
  103. data/app/models/katello/subscription_product.rb +0 -1
  104. data/app/models/katello/sync_plan.rb +0 -2
  105. data/app/models/katello/task_status.rb +2 -4
  106. data/app/models/setting/content.rb +2 -0
  107. data/app/services/katello/candlepin/consumer.rb +1 -2
  108. data/app/services/katello/candlepin/message_handler.rb +88 -0
  109. data/app/services/katello/repository_type_manager.rb +1 -1
  110. data/app/views/dashboard/_content_views_widget.html.erb +2 -2
  111. data/app/views/dashboard/_errata_widget.html.erb +3 -3
  112. data/app/views/foreman/smart_proxies/_content_sync.html.erb +25 -8
  113. data/app/views/foreman/unattended/kickstart-katello-atomic.erb +1 -1
  114. data/app/views/foreman/unattended/kickstart-katello.erb +1 -1
  115. data/app/views/katello/api/v2/common/_org_reference.json.rabl +1 -0
  116. data/app/views/katello/api/v2/content_facet/base.json.rabl +3 -14
  117. data/app/views/katello/api/v2/products/base.json.rabl +1 -1
  118. data/app/views/katello/api/v2/repositories/base.json.rabl +1 -1
  119. data/app/views/katello/api/v2/repository_sets/show.json.rabl +8 -1
  120. data/app/views/katello/api/v2/subscriptions/base.json.rabl +0 -7
  121. data/app/views/katello/api/v2/subscriptions/show.json.rabl +4 -37
  122. data/config/routes/overrides.rb +1 -0
  123. data/db/migrate/20140422000001_update_products_add_organization.rb +1 -1
  124. data/db/migrate/20140610154745_content_view_puppet_environment_id.rb +1 -1
  125. data/db/migrate/20140626204657_add_unlimited_to_activation_keys.rb +1 -1
  126. data/db/migrate/20140626204902_add_unlimited_to_host_collection.rb +1 -1
  127. data/db/migrate/20141209103005_disown_foreman_templates.rb +1 -1
  128. data/db/migrate/20150901213759_remove_distributors.rb +1 -1
  129. data/db/migrate/20150908222711_drop_marketing_engineering_products.rb +1 -1
  130. data/db/migrate/20150930183738_migrate_content_hosts.rb +20 -20
  131. data/db/migrate/20151014144004_host_collection_to_hosts.rb +5 -5
  132. data/db/migrate/20160114200145_add_mirror_on_sync_to_repositories.rb +1 -1
  133. data/db/migrate/20160131182301_add_download_policy_to_katello_repositories.rb +1 -1
  134. data/db/migrate/20160222143432_move_system_description_to_host.rb +2 -2
  135. data/db/migrate/20160404132250_remove_katello_from_notification_name.rb +1 -1
  136. data/db/migrate/20160426145517_move_host_description_to_host_comment.rb +1 -1
  137. data/db/migrate/20160617124149_remove_duplicate_view_filters.rb +4 -4
  138. data/db/migrate/20160619223332_fix_viewer_role.rb +4 -4
  139. data/db/migrate/20160701180402_add_sortable_version_to_puppet_modules.rb +1 -1
  140. data/db/migrate/20160924213020_change_katello_widget_names.rb +1 -1
  141. data/db/migrate/20161014133811_move_content_view_version_description_to_histories.rb +2 -2
  142. data/db/migrate/20161026191118_fix_invalid_interfaces.rb +1 -1
  143. data/db/migrate/20170321012632_fill_in_content_view_components.rb +3 -3
  144. data/db/migrate/20170718142148_create_katello_subscription_facet_pools.rb +15 -0
  145. data/db/migrate/20170821170915_add_index_to_installed_packages.rb +5 -0
  146. data/db/migrate/20170821170916_add_nvra_index_to_installed_packages.rb +5 -0
  147. data/db/migrate/20170913183848_add_errata_counts.rb +23 -0
  148. data/db/seeds.d/101-locations.rb +2 -2
  149. data/db/seeds.d/102-organizations.rb +3 -3
  150. data/db/seeds.d/103-provisioning_templates.rb +29 -31
  151. data/db/seeds.d/104-proxy.rb +10 -12
  152. data/db/seeds.d/106-mail_notifications.rb +30 -32
  153. data/db/seeds.d/107-enable_dynflow.rb +3 -4
  154. data/db/seeds.d/108-subcription-bookmarks.rb +12 -10
  155. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/activation-keys/activation-keys.routes.js +1 -1
  156. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/activation-keys/new/views/activation-key-new.html +1 -1
  157. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/architectures/architecture.factory.js +15 -0
  158. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/architectures/architectures.module.js +14 -0
  159. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/bastion-katello-bootstrap.js +1 -0
  160. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/bastion_katello.js +3 -0
  161. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/capsule-content/capsule-content.controller.js +2 -2
  162. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/bulk/content-hosts-bulk-repository-sets-modal.controller.js +107 -0
  163. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/bulk/views/content-hosts-bulk-repository-sets-modal.html +113 -0
  164. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/content-hosts-helper.service.js +13 -0
  165. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/content-hosts.controller.js +25 -4
  166. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/details/content-host-details-info.controller.js +4 -4
  167. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/details/views/content-host-info.html +15 -12
  168. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/details/views/content-host-repository-sets.html +1 -1
  169. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/views/content-hosts.html +11 -5
  170. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/deletion/views/version-deletion-activation-keys.html +15 -12
  171. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/deletion/views/version-deletion-content-hosts.html +16 -12
  172. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/errata/apply-errata.controller.js +9 -6
  173. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/errata/views/errata-counts.html +6 -12
  174. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/errata/views/errata.html +4 -1
  175. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/hosts/host-bulk-action.factory.js +1 -0
  176. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/packages/views/packages.html +5 -2
  177. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/details/repositories/details/repository-details-info.controller.js +20 -2
  178. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/details/repositories/details/views/repository-info.html +9 -1
  179. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/details/repositories/new/new-repository.controller.js +22 -3
  180. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/details/repositories/new/views/new-repository.html +17 -1
  181. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/products.controller.js +1 -1
  182. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/products.module.js +1 -0
  183. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/repository-sets/repository-set.factory.js +16 -0
  184. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/subscription-details.controller.js +4 -0
  185. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/views/subscription-details.html +0 -19
  186. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/views/subscription-info.html +31 -0
  187. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/subscriptions.routes.js +1 -1
  188. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/tasks/views/tasks-table.html +6 -3
  189. data/lib/katello/permissions/host_permissions.rb +1 -0
  190. data/lib/katello/plugin.rb +7 -5
  191. data/lib/katello/tasks/clean_installed_packages.rake +54 -0
  192. data/lib/katello/tasks/import_subscriptions.rake +8 -0
  193. data/lib/katello/tasks/{setup.rake → reset.rake} +10 -0
  194. data/lib/katello/tasks/test.rake +18 -0
  195. data/lib/katello/version.rb +1 -1
  196. data/vendor/assets/stylesheets/katello/{jquery-ui-1.8.11.custom.css → jquery-ui-1.8.11.custom.css.scss} +0 -0
  197. data/vendor/assets/stylesheets/katello/{jquery.loadmask.css → jquery.loadmask.css.scss} +0 -0
  198. data/vendor/assets/stylesheets/katello/{jquery.treeTable.scss → jquery.treeTable.css.scss} +0 -0
  199. data/vendor/assets/stylesheets/katello/{ui.spinner.css → ui.spinner.css.scss} +0 -0
  200. metadata +43 -21
  201. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/subscription-activation-keys.controller.js +0 -30
  202. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/subscription-content-hosts.controller.js +0 -45
  203. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/views/subscription-activation-keys.html +0 -48
  204. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/views/subscription-content-hosts.html +0 -62
  205. data/lib/katello/tasks/upgrades/2.4/import_subscriptions.rake +0 -12
  206. data/lib/katello/tasks/upgrades/3.3/import_subscriptions.rake +0 -12
@@ -11,11 +11,11 @@ module Actions
11
11
  owner: repository.product.organization.label,
12
12
  name: repository.name,
13
13
  type: repository.content_type,
14
+ arches: repository.arch == "noarch" ? nil : repository.arch,
14
15
  label: repository.custom_content_label,
15
16
  content_url: content_url(repository))
16
17
  content_id = content_create.output[:response][:id]
17
- plan_action(Candlepin::Product::ContentAdd,
18
- owner: repository.product.organization.label,
18
+ plan_action(Candlepin::Product::ContentAdd, owner: repository.product.organization.label,
19
19
  product_id: repository.product.cp_id,
20
20
  content_id: content_id)
21
21
 
@@ -29,13 +29,13 @@ module Actions
29
29
  content_id: content_id,
30
30
  name: repository.name,
31
31
  type: repository.content_type,
32
+ arches: repository.arch == "noarch" ? "" : repository.arch,
32
33
  label: repository.custom_content_label,
33
34
  content_url: content_url(repository),
34
35
  gpg_key_url: repository.yum_gpg_key_url)
35
36
  end
36
37
 
37
- plan_self(repository_id: repository.id,
38
- content_id: content_id)
38
+ plan_self(repository_id: repository.id, content_id: content_id)
39
39
  end
40
40
  end
41
41
 
@@ -2,27 +2,29 @@ module Actions
2
2
  module Katello
3
3
  module Product
4
4
  class Create < Actions::EntryAction
5
- def plan(product, organization)
5
+ def plan(product, organization, subscription_start = nil)
6
6
  sequence do
7
7
  product.provider = organization.anonymous_provider
8
8
  product.organization = organization
9
+ product.setup_label_from_name
10
+ product.cp_id = ::Katello::Product.unused_product_id
11
+ product.save!
9
12
 
10
- cp_create = plan_action(::Actions::Candlepin::Product::Create,
11
- :owner => product.organization.label,
12
- :name => product.name,
13
- :multiplier => 1,
14
- :attributes => [{:name => "arch", :value => "ALL"}])
15
-
16
- cp_id = cp_create.output[:response][:id]
13
+ plan_action(::Actions::Candlepin::Product::Create,
14
+ :owner => product.organization.label,
15
+ :name => product.name,
16
+ :id => product.cp_id,
17
+ :multiplier => 1,
18
+ :attributes => [{:name => "arch", :value => "ALL"}])
17
19
 
18
20
  sub_create = plan_action(::Actions::Candlepin::Product::CreateUnlimitedSubscription,
19
21
  :owner_key => organization.label,
20
- :product_id => cp_id)
22
+ :product_id => product.cp_id,
23
+ :start_time => subscription_start)
21
24
 
22
25
  subscription_id = sub_create.output[:response][:id]
23
26
 
24
- product.save!
25
- action_subject product, :cp_id => cp_id
27
+ action_subject product, :cp_id => product.cp_id
26
28
 
27
29
  plan_self
28
30
  plan_action Katello::Product::ReindexSubscriptions, product, subscription_id
@@ -26,7 +26,6 @@ module Actions
26
26
  pulp_sync_options = {}
27
27
  pulp_sync_options[:download_policy] = ::Runcible::Models::YumImporter::DOWNLOAD_ON_DEMAND if validate_contents
28
28
  pulp_sync_options[:force_full] = true if skip_metadata_check
29
- pulp_sync_options[:auto_publish] = false if skip_metadata_check #skip auto publish, and force it later
30
29
  pulp_sync_options[:remove_missing] = false if incremental
31
30
 
32
31
  fail ::Katello::Errors::InvalidActionOptionError, _("Unable to sync repo. This repository does not have a feed url.") if repo.url.blank? && source_url.blank?
@@ -18,7 +18,8 @@ module Actions
18
18
  :content_url => ::Katello::Glue::Pulp::Repos.custom_content_path(repository.product, repository.label),
19
19
  :gpg_key_url => repository.yum_gpg_key_url,
20
20
  :label => repository.content.label,
21
- :type => repository.content_type)
21
+ :type => repository.content_type,
22
+ :arches => repository.arch == "noarch" ? nil : repository.arch)
22
23
  end
23
24
 
24
25
  if SETTINGS[:katello][:use_pulp] && repository.pulp_update_needed?
@@ -7,7 +7,11 @@ module Actions
7
7
  end
8
8
 
9
9
  def invoke_external_task
10
- pulp_extensions.consumer.regenerate_applicability_by_ids(input[:uuids])
10
+ if input[:uuids].length == 1
11
+ pulp_resources.consumer.regenerate_applicability_by_id(input[:uuids].first)
12
+ else
13
+ pulp_extensions.consumer.regenerate_applicability_by_ids(input[:uuids])
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -92,6 +92,7 @@ module Actions
92
92
  importer.ssl_client_cert = input[:ssl_client_cert]
93
93
  importer.ssl_client_key = input[:ssl_client_key]
94
94
  importer.ssl_validation = input[:ssl_validation]
95
+ importer.remove_missing = input[:mirror_on_sync]
95
96
  importer.basic_auth_username = input[:upstream_username] if input[:upstream_username].present?
96
97
  importer.basic_auth_password = input[:upstream_password] if input[:upstream_password].present?
97
98
  importer
@@ -7,11 +7,11 @@ module Actions
7
7
  def plan(input)
8
8
  plan_self(input)
9
9
  pulp_extensions.repository.create_with_importer_and_distributors(input[:pulp_id],
10
- importer,
11
- distributors,
12
- display_name: input[:name])
10
+ importer,
11
+ distributors,
12
+ display_name: input[:name])
13
13
  rescue => e
14
- raise error_message(e.http_body) || e
14
+ raise e.try(:http_body) ? error_message(e.http_body) || e : e
15
15
  end
16
16
 
17
17
  def error_message(body)
@@ -33,7 +33,7 @@ module Actions
33
33
  sync_options.merge!(input[:options]) if input[:options]
34
34
 
35
35
  output[:pulp_tasks] = pulp_tasks =
36
- [pulp_resources.repository.sync(input[:pulp_id], override_config: sync_options)]
36
+ [pulp_resources.repository.sync(input[:pulp_id], override_config: sync_options)]
37
37
 
38
38
  pulp_tasks
39
39
  end
@@ -55,7 +55,7 @@ module Katello
55
55
  logger.error "Remote server status code " << resp.code.to_s
56
56
  raise RestClientException, {:message => error.to_s, :service_code => service_code, :code => status_code}, caller
57
57
  else
58
- raise NetworkException, [resp.code.to_s, resp.body].reject { |s| s.nil? || s.empty? }.join(' ')
58
+ raise NetworkException, [resp.code.to_s, resp.body].reject { |s| s.blank? }.join(' ')
59
59
  end
60
60
  end
61
61
  fail RestClientException, {:message => message, :service_code => service_code, :code => status_code}, caller
@@ -105,7 +105,7 @@ module Katello
105
105
 
106
106
  def lazy_attribute_will_change!(attr)
107
107
  changed_remote_attributes[attr.to_s] ||=
108
- instance_variable_get("@#{attr}").nil? ? remote_attribute_value(attr) : instance_variable_get("@#{attr}")
108
+ instance_variable_get("@#{attr}").nil? ? remote_attribute_value(attr) : instance_variable_get("@#{attr}")
109
109
  end
110
110
 
111
111
  def lazy_attribute_change(attr)
@@ -158,7 +158,7 @@ module Katello
158
158
  end
159
159
 
160
160
  def available_pools(owner_label, uuid, listall = false)
161
- url = Pool.path(nil, owner_label) + "?consumer=#{uuid}&listall=#{listall}"
161
+ url = Pool.path(nil, owner_label) + "?consumer=#{uuid}&listall=#{listall}&add_future=true"
162
162
  response = Candlepin::CandlepinResource.get(url, self.default_headers).body
163
163
  JSON.parse(response)
164
164
  end
@@ -707,7 +707,7 @@ module Katello
707
707
  self.delete(join_path(path(owner_label, product_id), "content/#{content_id}"), self.default_headers).code.to_i
708
708
  end
709
709
 
710
- def create_unlimited_subscription(owner_key, product_id)
710
+ def create_unlimited_subscription(owner_key, product_id, start_date)
711
711
  start_date ||= Time.now
712
712
  # End it 100 years from now
713
713
  end_date ||= start_date + 10_950.days
@@ -5,6 +5,12 @@ module Katello
5
5
  variable.map { |x| x.with_indifferent_access }
6
6
  end
7
7
 
8
+ def self.md5hash(string)
9
+ md5 = Digest::MD5.new
10
+ md5.update(string)
11
+ md5.hexdigest
12
+ end
13
+
8
14
  def self.ostructize(obj, options = {})
9
15
  options[:prefix_keys] ||= []
10
16
  options[:prefix] ||= '_'
@@ -68,7 +68,7 @@ module Katello
68
68
  end
69
69
  diff_data = diff_data.compact.flatten
70
70
 
71
- return diff_data unless diff_data.nil? || diff_data.empty?
71
+ return diff_data unless diff_data.blank?
72
72
  stringify(params.keys) - stringify(rule.keys)
73
73
  end
74
74
 
@@ -1,11 +1,10 @@
1
1
  module Katello
2
2
  class ActivationKey < Katello::Model
3
- self.include_root_in_json = false
4
-
5
3
  include Glue::Candlepin::ActivationKey if SETTINGS[:katello][:use_cp]
6
4
  include Glue if SETTINGS[:katello][:use_cp]
7
5
  include Katello::Authorization::ActivationKey
8
6
  include ForemanTasks::Concerns::ActionSubject
7
+ include ScopedSearchExtensions
9
8
 
10
9
  belongs_to :organization, :inverse_of => :activation_keys
11
10
  belongs_to :environment, :class_name => "KTEnvironment", :inverse_of => :activation_keys
@@ -16,6 +15,7 @@ module Katello
16
15
  has_many :host_collections, :through => :key_host_collections
17
16
 
18
17
  has_many :pools, :through => :pool_activation_keys, :class_name => "Katello::Pool"
18
+ has_many :subscriptions, :through => :pools
19
19
  has_many :pool_activation_keys, :class_name => "Katello::PoolActivationKey", :dependent => :destroy, :inverse_of => :activation_key
20
20
  has_many :subscription_facet_activation_keys, :class_name => "Katello::SubscriptionFacetActivationKey", :dependent => :destroy
21
21
  has_many :subscription_facets, :through => :subscription_facet_activation_keys
@@ -54,6 +54,8 @@ module Katello
54
54
  scoped_search :rename => :content_view, :on => :name, :relation => :content_view, :complete_value => true
55
55
  scoped_search :on => :content_view_id, :complete_value => true, :only_explicit => true, :validator => ScopedSearch::Validators::INTEGER
56
56
  scoped_search :on => :description, :complete_value => true
57
+ scoped_search :on => :name, :relation => :subscriptions, :rename => :subscription_name, :complete_value => true, :ext_method => :find_by_subscription_name
58
+ scoped_search :on => :id, :relation => :subscriptions, :rename => :subscription_id, :complete_value => true, :ext_method => :find_by_subscription_id
57
59
 
58
60
  def environment_exists
59
61
  if environment_id && environment.nil?
@@ -79,10 +81,6 @@ module Katello
79
81
  end
80
82
  end
81
83
 
82
- def subscriptions
83
- self.pools
84
- end
85
-
86
84
  def available_subscriptions
87
85
  all_pools = self.get_pools.map { |pool| pool["id"] }
88
86
  added_pools = self.pools.pluck(:cp_id)
@@ -105,7 +103,7 @@ module Katello
105
103
  end
106
104
 
107
105
  def all_products
108
- Katello::Product.joins(:subscriptions => :pools).where(:organization_id => organization.id).enabled.uniq
106
+ organization.products.enabled.uniq
109
107
  end
110
108
 
111
109
  def available_content(content_access_mode_all = false, content_access_mode_env = false)
@@ -170,6 +168,26 @@ module Katello
170
168
  _("Activation Keys")
171
169
  end
172
170
 
171
+ def self.find_by_subscription_name(_key, operator, value)
172
+ conditions = sanitize_sql_for_conditions(["#{Katello::Subscription.table_name}.name #{operator} ?", value_to_sql(operator, value)])
173
+ activation_keys = ::Katello::ActivationKey.joins(pools: :subscription).where(conditions)
174
+ return_activation_keys_by_id(activation_keys.pluck(:id))
175
+ end
176
+
177
+ def self.find_by_subscription_id(_key, operator, value)
178
+ conditions = sanitize_sql_for_conditions(["#{Katello::Subscription.table_name}.id #{operator} ?", value_to_sql(operator, value)])
179
+ activation_keys = ::Katello::ActivationKey.joins(pools: :subscription).where(conditions)
180
+ return_activation_keys_by_id(activation_keys.pluck(:id))
181
+ end
182
+
183
+ def self.return_activation_keys_by_id(activation_key_ids)
184
+ if activation_key_ids.empty?
185
+ {:conditions => "1=0"}
186
+ else
187
+ {:conditions => "#{Katello::ActivationKey.table_name}.id IN (#{activation_key_ids.join(',')})"}
188
+ end
189
+ end
190
+
173
191
  private
174
192
 
175
193
  def set_default_content_view
@@ -7,7 +7,6 @@ module Katello
7
7
 
8
8
  included do
9
9
  alias_method_chain :validate_media?, :capsule
10
- alias_method_chain :info, :katello
11
10
  alias_method_chain :smart_proxy_ids, :katello
12
11
 
13
12
  has_many :host_installed_packages, :class_name => "::Katello::HostInstalledPackage", :foreign_key => :host_id, :dependent => :destroy
@@ -46,19 +45,6 @@ module Katello
46
45
  ids.uniq.compact
47
46
  end
48
47
 
49
- def info_with_katello
50
- info = info_without_katello
51
- info['parameters']['kt_env'] = self.lifecycle_environment.try(:label) #deprecated
52
- info['parameters']['kt_cv'] = self.content_view.try(:label) #deprecated
53
- info['parameters']['lifecycle_environment'] = self.lifecycle_environment.try(:label)
54
- info['parameters']['content_view'] = self.content_view.try(:label)
55
- info['parameters']['foreman_host_collections'] = self.host_collections.map(&:name)
56
- if self.content_facet.present?
57
- info['parameters']['kickstart_repository'] = self.content_facet.kickstart_repository.try(:label)
58
- end
59
- info
60
- end
61
-
62
48
  def correct_puppet_environment
63
49
  if content_and_puppet_matched?
64
50
  new_environment = content_facet.content_view.puppet_env(content_facet.lifecycle_environment).try(:puppet_environment)
@@ -77,10 +63,67 @@ module Katello
77
63
  end
78
64
 
79
65
  def import_package_profile(simple_packages)
80
- self.installed_packages.where("nvra not in (?)", simple_packages.map(&:nvra)).destroy_all
81
- existing_nvras = self.installed_packages.pluck(:nvra)
66
+ if Setting[:bulk_query_installed_packages]
67
+ #this method is slow if the clean_installed_packages rake task has not been run, but faster if it has
68
+ found = import_package_profile_in_bulk(simple_packages)
69
+ else
70
+ found = import_package_profile_individually(simple_packages)
71
+ end
72
+
73
+ sync_package_associations(found.map(&:id))
74
+ end
75
+
76
+ def import_package_profile_in_bulk(simple_packages)
77
+ nvras = simple_packages.map { |sp| sp.nvra }
78
+ found = InstalledPackage.where(:nvra => nvras).select(:id, :nvra)
79
+ found_nvras = found.map(&:nvra)
80
+ new_packages = simple_packages.select { |sp| !found_nvras.include?(sp.nvra) }
81
+
82
+ new_packages.each do |simple_package|
83
+ ::Katello::Util::Support.active_record_retry do
84
+ found << InstalledPackage.where(:nvra => simple_package.nvra, :name => simple_package.name).first_or_create!
85
+ end
86
+ end
87
+ found
88
+ end
89
+
90
+ def import_package_profile_individually(simple_packages)
91
+ found = []
82
92
  simple_packages.each do |simple_package|
83
- self.installed_packages.create!(:name => simple_package.name, :nvra => simple_package.nvra) unless existing_nvras.include?(simple_package.nvra)
93
+ ::Katello::Util::Support.active_record_retry do
94
+ #use limit(1)[0] here to avoid a sort by id
95
+ pkg = InstalledPackage.where(:nvra => simple_package.nvra, :name => simple_package.name).limit(1)[0]
96
+ if pkg.nil?
97
+ pkg = InstalledPackage.create!(:nvra => simple_package.nvra, :name => simple_package.name)
98
+ end
99
+ found << pkg
100
+ end
101
+ end
102
+ found
103
+ end
104
+
105
+ def sync_package_associations(new_installed_package_ids)
106
+ old_associated_ids = self.installed_package_ids
107
+ table_name = self.host_installed_packages.table_name
108
+
109
+ new_ids = new_installed_package_ids - old_associated_ids
110
+ delete_ids = old_associated_ids - new_installed_package_ids
111
+
112
+ queries = []
113
+
114
+ if delete_ids.any?
115
+ queries << "DELETE FROM #{table_name} WHERE host_id=#{self.id} AND installed_package_id IN (#{delete_ids.join(', ')})"
116
+ end
117
+
118
+ unless new_ids.empty?
119
+ inserts = new_ids.map { |unit_id| "(#{unit_id.to_i}, #{self.id.to_i})" }
120
+ queries << "INSERT INTO #{table_name} (installed_package_id, host_id) VALUES #{inserts.join(', ')}"
121
+ end
122
+
123
+ ActiveRecord::Base.transaction do
124
+ queries.each do |query|
125
+ ActiveRecord::Base.connection.execute(query)
126
+ end
84
127
  end
85
128
  end
86
129
 
@@ -15,6 +15,8 @@ module Katello
15
15
  accepts_nested_attributes_for :subscription_facet, :update_only => true, :reject_if => lambda { |attrs| attrs.values.compact.empty? }
16
16
 
17
17
  has_many :activation_keys, :through => :subscription_facet
18
+ has_many :pools, :through => :subscription_facet
19
+ has_many :subscriptions, :through => :pools
18
20
  has_one :subscription_status_object, :class_name => 'Katello::SubscriptionStatus', :foreign_key => 'host_id'
19
21
  has_one :hypervisor_host, :through => :subscription_facet
20
22
 
@@ -33,6 +35,8 @@ module Katello
33
35
  :only_explicit => true, :validator => ScopedSearch::Validators::INTEGER
34
36
  scoped_search :on => :hypervisor, :relation => :subscription_facet, :complete_value => true
35
37
  scoped_search :on => :name, :relation => :hypervisor_host, :complete_value => true, :rename => :hypervisor_host, :ext_method => :find_by_hypervisor_host
38
+ scoped_search :on => :name, :relation => :subscriptions, :rename => :subscription_name, :complete_value => true, :ext_method => :find_by_subscription_name
39
+ scoped_search :on => :id, :relation => :pools, :rename => :subscription_id, :complete_value => true, :ext_method => :find_by_subscription_id
36
40
  end
37
41
 
38
42
  def update_action
@@ -45,28 +49,45 @@ module Katello
45
49
  def find_by_activation_key(_key, operator, value)
46
50
  conditions = sanitize_sql_for_conditions(["#{Katello::ActivationKey.table_name}.name #{operator} ?", value_to_sql(operator, value)])
47
51
  hosts = ::Host::Managed.joins(:activation_keys).where(conditions)
48
- if hosts.empty?
49
- { :conditions => "1=0" }
50
- else
51
- { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
52
- end
52
+ return_hosts(hosts)
53
53
  end
54
54
 
55
55
  def find_by_activation_key_id(_key, operator, value)
56
56
  conditions = sanitize_sql_for_conditions(["#{Katello::ActivationKey.table_name}.id #{operator} ?", value_to_sql(operator, value)])
57
57
  hosts = ::Host::Managed.joins(:activation_keys).where(conditions)
58
- if hosts.empty?
59
- { :conditions => "1=0" }
60
- else
61
- { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
62
- end
58
+ return_hosts(hosts)
63
59
  end
64
60
 
65
61
  def find_by_hypervisor_host(_key, operator, value)
66
62
  conditions = sanitize_sql_for_conditions(["#{::Host.table_name}.name #{operator} ?", value_to_sql(operator, value)])
67
63
  hosts = ::Host.where(conditions)
68
64
  hosts = ::Host.joins(:subscription_facet).where("#{Katello::Host::SubscriptionFacet.table_name}.hypervisor_host_id" => hosts)
65
+ return_hosts(hosts)
66
+ end
67
+
68
+ def find_by_subscription_name(_key, operator, value)
69
+ conditions = sanitize_sql_for_conditions(["#{Katello::Subscription.table_name}.name #{operator} ?", value_to_sql(operator, value)])
70
+ sub_facets = ::Katello::Host::SubscriptionFacet.joins(pools: :subscription).where(conditions)
71
+ host_ids = sub_facets.select(:host_id)
72
+ return_hosts_by_id(host_ids)
73
+ end
74
+
75
+ def find_by_subscription_id(_key, operator, value)
76
+ conditions = sanitize_sql_for_conditions(["#{Katello::Pool.table_name}.id #{operator} ?", value_to_sql(operator, value)])
77
+ sub_facets = ::Katello::Host::SubscriptionFacet.joins(:pools).where(conditions)
78
+ host_ids = sub_facets.select(:host_id)
79
+ return_hosts_by_id(host_ids)
80
+ end
81
+
82
+ def return_hosts_by_id(host_ids)
83
+ if host_ids.empty?
84
+ {:conditions => "1=0"}
85
+ else
86
+ {:conditions => "#{::Host::Managed.table_name}.id IN (#{host_ids.to_sql})"}
87
+ end
88
+ end
69
89
 
90
+ def return_hosts(hosts)
70
91
  if hosts.empty?
71
92
  {:conditions => "1=0"}
72
93
  else