Skip to content

Commit

Permalink
Merge pull request #99 from tzumainn/osp12-infra-provider-update
Browse files Browse the repository at this point in the history
update to infra refresher for OSP12
  • Loading branch information
aufi authored Oct 12, 2017
2 parents ba17870 + 42a33bc commit ef12d29
Show file tree
Hide file tree
Showing 5 changed files with 467,814 additions and 529,708 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,39 @@ def ems_inv_to_hashes

private

def all_server_resources
return @all_server_resources if @all_server_resources
def stack_resources_by_depth(stack)
return @stack_resources if @stack_resources
# TODO(lsmola) loading this from already obtained nested stack hierarchy will be more effective. This is one
# extra API call. But we will need to change order of loading, so we have all resources first.
@stack_resources = @orchestration_service.list_resources(:stack => stack, :nested_depth => 2).body['resources']
end

def filter_stack_resources_by_resource_type(resource_type_list)
resources = []
stacks.each do |stack|
root_stacks.each do |stack|
# Filtering just server resources which is important to us for getting Purpose of the node
# (compute, controller, etc.).
resources += all_stack_server_resources(stack).select do |x|
%w(OS::TripleO::Server OS::Nova::Server).include?(x["resource_type"])
resources += stack_resources_by_depth(stack).select do |x|
resource_type_list.include?(x["resource_type"])
end
end
@all_server_resources = resources
resources
end

def all_stack_server_resources(stack)
# TODO(lsmola) loading this from already obtained nested stack hierarchy will be more effective. This is one
# extra API call. But we will need to change order of loading, so we have all resources first.
@orchestration_service.list_resources(:stack => stack, :nested_depth => 2).body['resources']
def stack_resource_groups
return @stack_resource_groups if @stack_resource_groups
@stack_resource_groups = filter_stack_resources_by_resource_type(["OS::Heat::ResourceGroup"])
end

def stack_server_resource_types
return @stack_server_resource_types if @stack_server_resource_types
@stack_server_resource_types = ["OS::TripleO::Server", "OS::Nova::Server"]
@stack_server_resource_types += stack_resource_groups.map { |rg| "OS::TripleO::" + rg["resource_name"] + "Server" }
end

def stack_server_resources
return @stack_server_resources if @stack_server_resources
@stack_server_resources = filter_stack_resources_by_resource_type(stack_server_resource_types)
end

def servers
Expand Down Expand Up @@ -145,7 +161,7 @@ def load_hosts

# Indexed Heat resources, we are interested only in OS::Nova::Server/OS::TripleO::Server
indexed_resources = {}
all_server_resources.each { |p| indexed_resources[p['physical_resource_id']] = p }
stack_server_resources.each { |p| indexed_resources[p['physical_resource_id']] = p }

process_collection(hosts, :hosts) do |host|
parse_host(host, indexed_servers, indexed_resources, cloud_ems_hosts_attributes)
Expand Down Expand Up @@ -349,7 +365,7 @@ def get_clusters_and_host_mapping
next unless uid

nova_server = stack[:resources].detect do |r|
%w(OS::TripleO::Server OS::Nova::Server).include?(r[:resource_category])
stack_server_resource_types.include?(r[:resource_category])
end
next unless nova_server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ def stacks
@stacks ||= detailed_stacks
end

def detailed_stacks
def root_stacks
@root_stacks ||= detailed_stacks(false)
end

def detailed_stacks(show_nested = true)
return [] unless @orchestration_service
# TODO(lsmola) We need a support of GET /{tenant_id}/stacks/detail in FOG, it was implemented here
# https://review.openstack.org/#/c/35034/, but never documented in API reference, so right now we
# can't get list of detailed stacks in one API call.
if @ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) && ::Settings.ems.ems_openstack.refresh.heat.is_global_admin
@orchestration_service.handled_list(:stacks, {:show_nested => true, :global_tenant => true}, true).collect(&:details)
@orchestration_service.handled_list(:stacks, {:show_nested => show_nested, :global_tenant => true}, true).collect(&:details)
else
@orchestration_service.handled_list(:stacks, :show_nested => true).collect(&:details)
@orchestration_service.handled_list(:stacks, :show_nested => show_nested).collect(&:details)
end
rescue Excon::Errors::Forbidden
# Orchestration service is detected but not open to the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:ipaddress => "192.168.24.1", :port => 5000, :api_version => 'v2',
:security_protocol => 'no-ssl')
@ems.update_authentication(
:default => {:userid => "admin", :password => "password_2WpEraURh"})
:default => {:userid => "admin", :password => "7ad8192740977a6f0bcbfd34eaebef9d33048a8b"})
end

it "will perform a full refresh" do
Expand Down Expand Up @@ -51,7 +51,7 @@
@host = ManageIQ::Providers::Openstack::InfraManager::Host.all.order(:ems_ref).detect { |x| x.name.include?('(NovaCompute)') }

expect(@host.maintenance).to eq(false)
expect(@host.maintenance_reason).to eq(nil)
expect(@host.maintenance_reason).to be nil

@host.set_node_maintenance
EmsRefresh.refresh(@ems)
Expand All @@ -65,7 +65,7 @@
@ems.reload
@host.reload
expect(@host.maintenance).to eq(false)
expect(@host.maintenance_reason).to eq(nil)
expect(@host.maintenance_reason).to be nil
end
end

Expand Down
Loading

0 comments on commit ef12d29

Please sign in to comment.