Skip to content

Commit

Permalink
Fixes #17622: Display need for virt-who in the UI
Browse files Browse the repository at this point in the history
Uses the virt_limit property of a pool and if its a Red Hat
subscription to determine if a user needs virt-who. This is displayed
on the subscription list, and subscription details. As well, if
a manifest includes subscriptions that require virt-who an info
alert is displayed to point them to the Red Hat virtual instance
guide.
  • Loading branch information
ehelms committed Jan 24, 2017
1 parent b67a1eb commit d6f204f
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/models/katello/glue/candlepin/owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def owner_info
end

def owner_details
Resources::Candlepin::Owner.find self.label
details = Resources::Candlepin::Owner.find self.label
details['virt_who'] = self.subscriptions.using_virt_who.any?
details
end

def service_level
Expand Down
4 changes: 3 additions & 1 deletion app/models/katello/glue/candlepin/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def stacking_subscription(org_label, stacking_id)
end

def import_data
pool_attributes = {}
pool_attributes = {}.with_indifferent_access
pool_json = self.backend_data
product_attributes = pool_json["productAttributes"] + pool_json["attributes"]

Expand Down Expand Up @@ -126,6 +126,8 @@ def import_data
pool_attributes[:unmapped_guest] = true
end

pool_attributes[:virt_who] = pool_attributes['virt_limit'] != "0" && !pool_attributes['virt_limit'].nil? && subscription.redhat?

exceptions = pool_attributes.keys.map(&:to_sym) - self.attribute_names.map(&:to_sym)
self.update_attributes(pool_attributes.except!(*exceptions))
self.save!
Expand Down
1 change: 1 addition & 0 deletions app/models/katello/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Pool < Katello::Model
scoped_search :on => :consumed, :complete_value => true, :validator => ScopedSearch::Validators::INTEGER
scoped_search :on => :account_number, :complete_value => true, :rename => :account, :validator => ScopedSearch::Validators::INTEGER
scoped_search :on => :contract_number, :complete_value => true, :rename => :contract, :validator => ScopedSearch::Validators::INTEGER
scoped_search :on => :virt_who, :complete_value => true, :only_explicit => true
scoped_search :on => :name, :relation => :subscription, :complete_value => true, :rename => :name
scoped_search :on => :support_level, :relation => :subscription, :complete_value => true
scoped_search :on => :sockets, :relation => :subscription, :complete_value => true, :validator => ScopedSearch::Validators::INTEGER
Expand Down
12 changes: 12 additions & 0 deletions app/models/katello/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def self.with_subscribable_content
where("#{Katello::Product.table_name}.id" => Product.with_subscribable_content)
end

def self.using_virt_who
joins(:pools).where("#{Katello::Pool.table_name}.virt_who" => true)
end

def redhat?
self.products.any? { |product| product.redhat? }
end
Expand All @@ -33,6 +37,14 @@ def recently_expired?
pools.any?(&:recently_expired?)
end

def virt_who_pools
pools.where("#{Katello::Pool.table_name}.virt_who" => true)
end

def virt_who?
virt_who_pools.any?
end

def self.humanize_class_name(_name = nil)
_("Subscription")
end
Expand Down
1 change: 1 addition & 0 deletions app/views/katello/api/v2/subscriptions/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ attributes :type
attributes :name => :product_name
attributes :unmapped_guest
attributes :virt_only
attributes :virt_who

node :host, :if => lambda { |sub| sub && sub.hypervisor } do |subscription|
{
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20161209162947_add_virt_who_to_katello_pools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddVirtWhoToKatelloPools < ActiveRecord::Migration
def up
add_column :katello_pools, :virt_who, :boolean, :default => false, :null => false
end

def down
remove_column :katello_pools, :virt_who
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ angular.module('Bastion.subscriptions').controller('SubscriptionDetailsControlle

return "";
};

$scope.virtWhoToolTip = translate("If the virt-who field is Yes then the subscription requires the use of virt-who. Learn how to configure and use this tool in the <a href=\"https://access.redhat.com/documentation/en/red-hat-satellite/6.2/single/virtual-instances-guide/\">Virtual Instances Guide</a>.");
}]
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ <h4 translate>Subscription Info</h4>

<dt translate>Description</dt>
<dd>{{ subscription.description }}</dd>

<dt>
<span translate>Virt-Who Usage Required</span>
<i class="pf pficon-info"
tooltip-html-unsafe="{{ virtWhoToolTip }}"
tooltip-trigger="click"
tooltip-animation="false"
tooltip-placement="right"
tooltip-close-popup-delay="5"
tooltip-append-to-body="true">
</i>
</dt>
<dd>{{ subscription.virt_who | booleanToYesNo }}</dd>

<dt translate>Consumed</dt>
<dd>{{ subscription | subscriptionConsumedFilter }}</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ <h4 translate>Subscription Manifest</h4>
</div>

</form>


<div bst-alert="info" ng-if="details.virt_who">
<span translate>
The uploaded manifest contains subscriptions that require the use of virt-who. Learn how to configure and use this tool in the <a href="https://access.redhat.com/documentation/en/red-hat-satellite/6.2/single/virtual-instances-guide/">Virtual Instances Guide</a>.
</span>
</div>
</section>

<section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ <h2 translate>Subscriptions</h2>
<th bst-table-column="supportLevel"><span translate>Support Level</span></th>
<th bst-table-column="contractNumber"><span translate>Contract</span></th>
<th bst-table-column="accountNumber"><span translate>Account</span></th>
<th bst-table-column="virtLimit"><span translate>Requires Virt-Who Usage</span></th>
</tr>
</thead>

<tbody>
<tr bst-table-row ng-repeat-start="(name, subscriptions) in groupedSubscriptions">
<td bst-table-cell colspan="7">
<td bst-table-cell colspan="8">
<b>{{ name }}</b>
</td>
</tr>
Expand All @@ -57,6 +58,7 @@ <h2 translate>Subscriptions</h2>
<td bst-table-cell>{{ subscription.support_level }}</td>
<td bst-table-cell>{{ subscription.contract_number }}</td>
<td bst-table-cell>{{ subscription.account_number }}</td>
<td bst-table-cell><i class="fa fa-check" ng-if="subscription.virt_who"></i></td>
</tr>
</tbody>
</table>
Expand Down
1 change: 1 addition & 0 deletions lib/katello/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def find_assets(args = {})
load "#{Katello::Engine.root}/lib/katello/tasks/upgrades/3.0/delete_docker_v1_content.rake"
load "#{Katello::Engine.root}/lib/katello/tasks/upgrades/3.0/update_puppet_repository_distributors.rake"
load "#{Katello::Engine.root}/lib/katello/tasks/upgrades/3.0/update_subscription_facet_backend_data.rake"
load "#{Katello::Engine.root}/lib/katello/tasks/upgrades/3.3/import_subscriptions.rake"
end
end

Expand Down
12 changes: 12 additions & 0 deletions lib/katello/tasks/upgrades/3.3/import_subscriptions.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace :katello do
namespace :upgrades do
namespace '3.3' do
task :import_subscriptions => ["environment"] do
User.current = User.anonymous_api_admin
puts _("Importing Subscriptions")
Katello::Subscription.import_all
Katello::Pool.import_all
end
end
end
end
1 change: 1 addition & 0 deletions test/fixtures/models/katello_pools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pool_one:
ram: 2
multi_entitlement: true
consumed: 1
virt_who: true

pool_two:
cp_id: "xyz123"
Expand Down
5 changes: 5 additions & 0 deletions test/models/pool_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ def test_search_support_level
assert_includes subscriptions, @pool_one
end

def test_search_virt_who
subscriptions = Pool.search_for("virt_who = true")
assert_includes subscriptions, @pool_one
end

def test_for_activation_key
Pool::ActiveRecord_Relation.any_instance.expects(:where).with(cp_id: [1])
Pool.for_activation_key(OpenStruct.new(get_key_pools: [{'id' => 1}]))
Expand Down
14 changes: 14 additions & 0 deletions test/models/subscription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@ def test_with_subscribable_content
@other.products.delete(fedora)
refute_includes Subscription.with_subscribable_content, @other
end

def test_virt_who_scope
assert_equal 1, Subscription.using_virt_who.length
end

def test_virt_who
assert_equal 1, @basic.virt_who_pools.length
assert_equal 0, @other.virt_who_pools.length
end

def test_virt_who?
assert @basic.virt_who?
refute @other.virt_who?
end
end
end

0 comments on commit d6f204f

Please sign in to comment.