Skip to content

Commit

Permalink
[OpenStack] Handle missing services better
Browse files Browse the repository at this point in the history
Administrators can configure OpenStack tenants and users in such a way that
restricts access to certain services on certain tenants.  The
`OpenstackHandle#detect_service` method handled this by returning `nil` when it
could not connect to the appropriate service.

However, several callers were not handling the `nil` response properly.

Now, at least callers to `OpenstackHandle#service_for_each_accessible_tenant`
will only have their block called when the requested service is actually
available for the tenant.  Otherwise, a warning will be logged, and that
iteration of the `service_for_each_accessible_tenant` will be skipped.

https://bugzilla.redhat.com/show_bug.cgi?id=1245511
  • Loading branch information
blomquisg committed Aug 27, 2015
1 parent ca5964c commit 5d1e28d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions gems/pending/openstack/openstack_handle/handle.rb
Expand Up @@ -262,13 +262,19 @@ def default_tenant_name
@default_tenant_name ||= accessible_tenant_names.detect { |tn| tn != "services" }
end

def service_for_each_accessible_tenant(service, &block)
if block.arity == 1
accessible_tenant_names.each { |t| block.call(detect_service(service, t)) }
elsif block.arity == 2
accessible_tenants.each { |t| block.call(detect_service(service, t.name), t) }
else
raise "OpenstackHandle#service_for_each_accessible_tenant: unexpected number of block args: #{block.arity}"
def service_for_each_accessible_tenant(service_name, &block)
accessible_tenants.each do |tenant|
service = detect_service(service_name, tenant.name)
if service
case block.arity
when 1 then block.call(service)
when 2 then block.call(service, tenant)
else raise "Unexpected number of block args: #{block.arity}"
end
else
$fog_log.warn("MIQ(#{self.class.name}##{__method__}) "\
"Could not access service #{service_name} for tenant #{tenant.name} on OpenStack #{@address}")
end
end
end

Expand Down

0 comments on commit 5d1e28d

Please sign in to comment.