Skip to content

Commit

Permalink
Merge pull request #360 from agrare/full_db_comparison_classic_graph_…
Browse files Browse the repository at this point in the history
…refresh

Add a test comparing classic and graph refresh for vmware
  • Loading branch information
Ladas authored Jan 30, 2019
2 parents c716f77 + 71dd146 commit d104f70
Show file tree
Hide file tree
Showing 6 changed files with 4,257 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def parse_folder(object, kind, props)
:ems_ref => object._ref,
:ems_ref_obj => managed_object_to_vim_string(object),
:uid_ems => object._ref,
:type => "EmsFolder",
:name => CGI.unescape(props[:name]),
:parent => lazy_find_managed_object(props[:parent]),
:hidden => hidden,
Expand All @@ -135,6 +134,7 @@ def parse_host_system(object, kind, props)
:parent => cluster,
}

parse_host_system_summary(host_hash, props)
parse_host_system_config(host_hash, props)
parse_host_system_product(host_hash, props)
parse_host_system_network(host_hash, props)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
class ManageIQ::Providers::Vmware::InfraManager::Inventory::Parser
module HostSystem
def parse_host_system_summary(host_hash, props)
summary = props[:summary]
return if summary.nil?

host_hash[:uid_ems] = summary.fetch_path(:config, :name)
end

def parse_host_system_config(host_hash, props)
config = props[:config]
return if config.nil?

host_hash[:uid_ems] = config[:name]
host_hash[:admin_disabled] = config[:adminDisabled].to_s.downcase == "true"
host_hash[:hyperthreading] = config.fetch_path(:hyperThread, :active).to_s.downcase == "true"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def parse_resource_pool_cpu_allocation(cluster_hash, props)
cluster_hash[:cpu_reserve_expand] = cpu_allocation[:expandableReservation].to_s.downcase == "true"
cluster_hash[:cpu_limit] = cpu_allocation[:limit]
cluster_hash[:cpu_shares] = cpu_allocation.fetch_path(:shares, :shares)
cluster_hash[:cpu_shares_level] = cpu_allocation.fetch_path(:limit, :limit)
cluster_hash[:cpu_shares_level] = cpu_allocation.fetch_path(:shares, :level)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rbvmomi/vim'

describe ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector do
let(:ems) do
let!(:ems) do
_, _, zone = EvmSpecHelper.create_guid_miq_server_zone
hostname = Rails.application.secrets.vmware.try(:[], "hostname") || "HOSTNAME"
FactoryBot.create(:ems_vmware_with_authentication, :hostname => hostname, :zone => zone).tap do |ems|
Expand Down Expand Up @@ -37,6 +37,58 @@
assert_specific_vm
end
end

it "Same as classic refresh" do
with_vcr("classic") { EmsRefresh.init_console; EmsRefresh.refresh(ems) }
inventory_after_classic_refresh = serialize_inventory

with_vcr("graph") { collector.run }
inventory_after_graph_refresh = serialize_inventory

assert_inventory_not_changed(inventory_after_classic_refresh, inventory_after_graph_refresh)
end

def with_vcr(suffix, &block)
path = described_class.name
path << "::#{suffix}"

VCR.use_cassette(path.underscore, :match_requests_on => [:body]) { block.call }
end

def serialize_inventory
tables = [:vms, :hosts, :storages, :host_storages, :hardwares, :guest_devices,
:disks, :networks, :system_services, :snapshots, :operating_systems,
:custom_attributes, :ems_clusters, :resource_pools, :subnets,
#:ems_folders, :switches, :lans
:miq_scsi_luns, :miq_scsi_targets, :storage_profiles, :customization_specs]

global_skip_attrs = ["created_on", "updated_on"]
table_skip_attrs = {
:storages => ["ems_ref", "ems_ref_obj"],
:vms => ["state_changed_on"],
}

tables.each_with_object({}) do |table, inventory|
model = table.to_s.classify.constantize

inventory[table] = model.all.map do |rec|
skip_attrs = global_skip_attrs + table_skip_attrs[table].to_a
rec.attributes.except(*skip_attrs)
end.sort { |rec| rec["id"] }
end
end

def assert_inventory_not_changed(before, after)
expect(before.keys).to match_array(after.keys)
before.keys.each do |model|
expect(before[model].count).to eq(after[model].count)

before[model].each do |item_before|
item_after = after[model].detect { |i| i["id"] == item_before["id"]}
expect(item_before).to eq(item_after)
end
end
end
end

context "targeted refresh" do
Expand Down Expand Up @@ -702,7 +754,7 @@ def assert_specific_resource_pool
:cpu_reserve => 47_984,
:cpu_reserve_expand => true,
:cpu_shares => 4_000,
:cpu_shares_level => nil,
:cpu_shares_level => "normal",
:memory_limit => 59_872,
:memory_reserve => 59_872,
:memory_reserve_expand => true,
Expand Down
Loading

0 comments on commit d104f70

Please sign in to comment.