Skip to content

Commit

Permalink
fixes #6197 - moving host/guests to virtual_host/virtual_guests
Browse files Browse the repository at this point in the history
This corrects conflict with foreman host link

rubocop fix

spec test fix
  • Loading branch information
Tom McKay committed Jun 16, 2014
1 parent a910ae6 commit d33e553
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 63 deletions.
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/systems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def index
param :fact, String, :desc => N_("Any number of facts about this content host")
end
param :type, String, :desc => N_("Type of the content host, it should always be 'content host'"), :required => true, :action_aware => true
param :guest_ids, Array, :desc => N_("IDs of the guests running on this content host")
param :virtual_guest_ids, Array, :desc => N_("IDs of the virtual guests running on this content host")
param :installed_products, Array, :desc => N_("List of products installed on the content host"), :action_aware => true
param :release_ver, String, :desc => N_("Release version of the content host")
param :service_level, String, :allow_nil => true, :desc => N_("A service level for auto-healing process, e.g. SELF-SUPPORT"), :action_aware => true
Expand All @@ -125,7 +125,7 @@ def create
param :fact, String, :desc => N_("Any number of facts about this content host")
end
param :type, String, :desc => N_("Type of the content host, it should always be 'content host'"), :required => true, :action_aware => true
param :guest_ids, Array, :desc => N_("IDs of the guests running on this content host")
param :virtual_guest_ids, Array, :desc => N_("IDs of the virtual guests running on this content host")
param :installed_products, Array, :desc => N_("List of products installed on the content host"), :action_aware => true
param :release_ver, String, :desc => N_("Release version of the content host")
param :service_level, String, :allow_nil => true, :desc => N_("A service level for auto-healing process, e.g. SELF-SUPPORT"), :action_aware => true
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/katello/systems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def errata_type_class(errata)

def system_type(system)

return _("Guest") if system.guest
return _("Guest") if system.virtual_guest

case system.type
when "Hypervisor"
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/resources/candlepin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ def remove_certificate(uuid, serial_id)
self.delete(uri, self.default_headers).code.to_i
end

def guests(uuid)
def virtual_guests(uuid)
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'guests'), self.default_headers).body
Util::Data.array_with_indifferent_access JSON.parse(response)
rescue
return []
end

def host(uuid)
def virtual_host(uuid)
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'host'), self.default_headers).body
if response.present?
JSON.parse(response).with_indifferent_access
Expand Down
24 changes: 12 additions & 12 deletions app/models/katello/glue/candlepin/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def self.included(base)
lazy_accessor :pools, :initializer => lambda {|s| entitlements.collect { |ent| Resources::Candlepin::Pool.find ent["pool"]["id"]} }
lazy_accessor :available_pools, :initializer => lambda {|s| Resources::Candlepin::Consumer.available_pools(uuid, false) }
lazy_accessor :all_available_pools, :initializer => lambda {|s| Resources::Candlepin::Consumer.available_pools(uuid, true) }
lazy_accessor :host, :initializer => (lambda do |s|
host_attributes = Resources::Candlepin::Consumer.host(self.uuid)
(System.find_by_uuid(host_attributes['uuid']) || System.new(host_attributes)) if host_attributes
end)
lazy_accessor :guests, :initializer => (lambda do |s|
guests_attributes = Resources::Candlepin::Consumer.guests(self.uuid)
guests_attributes.map do |attr|
System.find_by_uuid(attr['uuid']) || System.new(attr)
end
end)
lazy_accessor :virtual_host, :initializer => (lambda do |s|
host_attributes = Resources::Candlepin::Consumer.virtual_host(self.uuid)
(System.find_by_uuid(host_attributes['uuid']) || System.new(host_attributes)) if host_attributes
end)
lazy_accessor :virtual_guests, :initializer => (lambda do |s|
guests_attributes = Resources::Candlepin::Consumer.virtual_guests(self.uuid)
guests_attributes.map do |attr|
System.find_by_uuid(attr['uuid']) || System.new(attr)
end
end)
lazy_accessor :compliance, :initializer => lambda {|s| Resources::Candlepin::Consumer.compliance(uuid) }
lazy_accessor :events, :initializer => lambda {|s| Resources::Candlepin::Consumer.events(uuid) }

Expand Down Expand Up @@ -312,13 +312,13 @@ def sockets=(sock)
facts["cpu.cpu_socket(s)"] = s if @facts
end

def guest
def virtual_guest
v = facts["virt.is_guest"]
return false if (v == false || v.nil?)
return(v == true || v.to_bool)
end

def guest=(val)
def virtual_guest=(val)
facts["virt.is_guest"] = val if @facts
end

Expand Down
14 changes: 7 additions & 7 deletions app/models/katello/glue/elastic_search/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def self.included(base)
:memory,
:sockets,
:status,
:host,
:guests
:virtual_host,
:virtual_guests
]

dynamic_templates = [
Expand Down Expand Up @@ -112,8 +112,8 @@ def self.included(base)
indexes :environment_sort, :type => 'string', :index => :not_analyzed
indexes :content_view_sort, :type => 'string', :index => :not_analyzed

indexes :host, :type => 'string', :analyzer => :kt_name_analyzer
indexes :guests, :type => 'string', :analyzer => :kt_name_analyzer
indexes :virtual_host, :type => 'string', :analyzer => :kt_name_analyzer
indexes :virtual_guests, :type => 'string', :analyzer => :kt_name_analyzer
end

# Whenever a system's 'name' field changes, the objects returned by system.host_collections
Expand Down Expand Up @@ -142,10 +142,10 @@ def extended_index_attrs
:environment_sort => self.environment.try(:name)
}

if self.guest
attrs[:host] = self.host ? self.host.name : ''
if self.virtual_guest
attrs[:virtual_host] = self.virtual_host ? self.virtual_host.name : ''
else
attrs[:guests] = self.guests.map(&:name)
attrs[:virtual_guests] = self.virtual_guests.map(&:name)
end

attrs
Expand Down
12 changes: 6 additions & 6 deletions app/models/katello/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ def as_json(options)
json['content_view'] = content_view.as_json if content_view
json['ipv4_address'] = facts.try(:[], 'network.ipv4_address') if respond_to?(:facts)

if respond_to?(:guest)
if self.guest == 'true'
json['host'] = self.host.attributes if self.host
if respond_to?(:virtual_guest)
if self.virtual_guest == 'true'
json['virtual_host'] = self.virtual_host.attributes if self.virtual_host
else
json['guests'] = self.guests.map(&:attributes)
json['virtual_guests'] = self.virtual_guests.map(&:attributes)
end
end

Expand All @@ -219,8 +219,8 @@ def as_json(options)
end

def type
if respond_to?(:guest) && guest
_("Guest")
if respond_to?(:virtual_guest) && virtual_guest
_("Virtual Guest")
else
case self
when Hypervisor
Expand Down
12 changes: 6 additions & 6 deletions app/views/katello/api/v2/systems/show.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ if params[:fields] == "full"
attributes :compliance
attributes :facts

if @resource.respond_to?(:guest) || @resource.respond_to?(:host)
if @resource.guest
node :host do |system|
system.host.attributes if system.host
if @resource.respond_to?(:virtual_guest) || @resource.respond_to?(:virtual_host)
if @resource.virtual_guest
node :virtual_host do |system|
system.virtual_host.attributes if system.virtual_host
end
else
node :guests do |system|
system.guests.map(&:attributes)
node :virtual_guests do |system|
system.virtual_guests.map(&:attributes)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,14 @@ angular.module('Bastion.content-hosts').controller('ContentHostDetailsInfoContro
memory = Math.round(memory * 100) / 100;
return memory;
}

$scope.virtualGuestIds = function (contentHost) {
var ids = 'id:%s'.replace('%s', contentHost.id);
angular.forEach(contentHost['virtual_guests'], function (host) {
ids += ' id:%s'.replace('%s', host.id);
});

return ids;
};
}]
);
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ <h4 translate>Basic Information</h4>
<span class="info-value">{{ contentHost.type }}</span>
</div>

<div ng-show="contentHost.guests" class="detail">
<span class="info-label" translate>Guests</span>
<div ng-show="contentHost.virtual_guests" class="detail">
<span class="info-label" translate>Virtual Guests</span>
<div class="info-value">
<ul>
<li ng-repeat="guest in system.guests">
<a ui-sref="content-hosts.details.info({contentHostId: guest.uuid})">{{ guest.name }}</a>
</li>
</ul>
<a ng-href="/products?search={{ virtualGuestIds(contentHost) }}"
translate translate-n="contentHost.virtual_guests.length"
translate-plural="{{ contentHost.virtual_guests.length }} Hosts">
1 Host
</a>
</div>
</div>

<div ng-show="contentHost.host" class="detail">
<span class="info-label" translate>Host</span>
<div ng-show="contentHost.virtual_host" class="detail">
<span class="info-label" translate>Virtual Host</span>
<div class="info-value">
<a ui-sref="content-hosts.details.info({contentHostId: system.host.uuid })">{{ system.host.name }}</a>
<a ui-sref="content-hosts.details.info({contentHostId: contentHost.virtual_host.uuid })">{{ contentHost.virtual_host.name }}</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ describe('Controller: ContentHostDetailsInfoController', function() {
expect($scope.memory(facts)).toEqual(1024);
});

it("builds list of guest ids", function () {
var host;
host = {id: 1};
expect($scope.virtualGuestIds(host)).toEqual("id:1");
host = {id: 1, "virtual_guests":[]};
expect($scope.virtualGuestIds(host)).toEqual("id:1");
host = {id: 1, "virtual_guests":[{ id: 2 }, { id: 3}]};
expect($scope.virtualGuestIds(host)).toEqual("id:1 id:2 id:3");
});

describe("populates advanced content host information", function () {

it("creates the content host facts object by converting dot notation response to an object.", function() {
Expand Down
28 changes: 14 additions & 14 deletions spec/controllers/api/v1/systems_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ module Katello
before(:each) do
@sys = System.new(:name => 'test', :environment => @environment_1, :cp_type => 'system', :facts => facts, :uuid => uuid)
System.stubs(:first).returns(@sys)
@sys.stubs(:guests => [])
@sys.stubs(:virtual_guests => [])
end

let(:action) { :upload_package_profile }
Expand Down Expand Up @@ -464,8 +464,8 @@ module Katello

it "should update installed products" do
@sys.facts = {}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:guests).returns([])
System.any_instance.stubs(:virtual_guest).returns('false')
System.any_instance.stubs(:virtual_guests).returns([])
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {}, nil, installed_products, nil, nil, nil, anything, nil, nil).returns(true)
put :update, :id => uuid, :installedProducts => installed_products
response.body.must_equal @sys.to_json
Expand All @@ -474,8 +474,8 @@ module Katello

it "should update releaseVer" do
@sys.facts = {}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:guests).returns([])
System.any_instance.stubs(:virtual_guest).returns('false')
System.any_instance.stubs(:virtual_guests).returns([])
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {}, nil, nil, nil, "1.1", nil, anything, nil, nil).returns(true)
put :update, :id => uuid, :releaseVer => "1.1"
response.body.must_equal @sys.to_json
Expand All @@ -484,8 +484,8 @@ module Katello

it "should update lastCheckin" do
@sys.facts = {}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:guests).returns([])
System.any_instance.stubs(:virtual_guest).returns('false')
System.any_instance.stubs(:virtual_guests).returns([])
timestamp = 3.days.ago
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {}, nil, nil, nil, nil, nil, anything, nil, timestamp.strftime('%F %T')).returns(true)

Expand All @@ -496,8 +496,8 @@ module Katello

it "should update service level agreement" do
@sys.facts = {}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:guests).returns([])
System.any_instance.stubs(:virtual_guest).returns('false')
System.any_instance.stubs(:virtual_guests).returns([])
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {}, nil, nil, nil, nil, "SLA", anything, nil, nil).returns(true)
put :update, :id => uuid, :serviceLevel => "SLA"
response.body.must_equal @sys.to_json
Expand All @@ -507,8 +507,8 @@ module Katello
it "should update environment (katello)" do
promote_content_view(@sys.content_view, @environment_1, @environment_2)
@sys.facts = {}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:guests).returns([])
System.any_instance.stubs(:virtual_guest).returns('false')
System.any_instance.stubs(:virtual_guests).returns([])
System.any_instance.stubs(:regenerate_applicability).returns(TaskStatus.new)
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {}, nil, nil, nil, nil, nil,
"#{@environment_2.id}-#{@sys.content_view.id}", nil, nil).returns(true)
Expand All @@ -520,8 +520,8 @@ module Katello

it "handle memory as int" do
@sys.facts = {'memory.memtotal' => 20000}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:guests).returns([])
System.any_instance.stubs(:virtual_guest).returns('false')
System.any_instance.stubs(:virtual_guests).returns([])
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {'memory.memtotal' => 20000}, nil,
nil, nil, nil, nil, anything, nil, nil).returns(true)
put :update, :id => uuid
Expand All @@ -532,7 +532,7 @@ module Katello
it "should update capabilities (katello)" do
promote_content_view(@sys.content_view, @environment_1, @environment_2)
@sys.capabilities = {:name => 'cores'}
System.any_instance.stubs(:guest).returns('false')
System.any_instance.stubs(:virtual_guest).returns('false')
Resources::Candlepin::Consumer.expects(:update).once.with(uuid, {"sockets" => 0}, nil, nil, nil, nil, nil, anything, {:name => "cores"}, nil).returns(true)
System.any_instance.expects(:update_pulp_consumer).returns(true)

Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/system_test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Katello
module SystemTestData
class << self

def guests
def virtual_guests
[{"href"=>"/consumers/fcba65f1-5fe4-42e0-8f7b-6c719ec2bc42",
"facts"=>
{
Expand Down
2 changes: 1 addition & 1 deletion spec/models/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ module Katello
response = stub
response.stubs(:code => 204, :body => "")
Resources::Candlepin::CandlepinResource.stubs(:default_headers => {}, :get => response)
@system.host.must_be_nil
@system.virtual_host.must_be_nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/support/candlepin/consumer_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.create_system(name, env, cv)
@system.arch = 'x86_64'
@system.sockets = 2
@system.memory = 256
@system.guest = false
@system.virtual_guest = false

return @system
end
Expand Down

0 comments on commit d33e553

Please sign in to comment.