Skip to content

Commit

Permalink
Merge pull request #734 from agrare/update_fog_openstack_v1
Browse files Browse the repository at this point in the history
Update fog-openstack to v1.0
  • Loading branch information
kbrock authored May 8, 2023
2 parents 91f7e00 + 94b6b2b commit 0cec9e5
Show file tree
Hide file tree
Showing 35 changed files with 9,097 additions and 632,637 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def placement_groups
#
#
# For instance collector.placement_groups() returns
# [ <Fog::Compute::OpenStack::ServerGroup
# [ <Fog::OpenStack::Compute::ServerGroup
# id="a31f76c9-5ed6-43b4-86ae-7e2cbcf68302",
# name="Kuldip-VM-Affinity-Rule",
# policies=["affinity"],
# members=["2b5fb204-34ff-445b-aea4-a903d4b6143e"]
# >,
# <Fog::Compute::OpenStack::ServerGroup
# <Fog::OpenStack::Compute::ServerGroup
# id="1734c483-803b-4dcf-94e3-de058a6ddb87",
# name="jay-collection-rule",
# policies=["anti-affinity"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def query_options
def list_events(query_options)
provider_connection.list_events(query_options).body.map do |event_hash|
begin
Fog::Event::OpenStack::Event.new(event_hash)
Fog::OpenStack::Event::Event.new(event_hash)
rescue NameError
Fog::Metering::OpenStack::Event.new(event_hash)
Fog::OpenStack::Metering::Event.new(event_hash)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class BaremetalDelegate < DelegateClass(Fog::Baremetal::OpenStack)
class BaremetalDelegate < DelegateClass(Fog::OpenStack::Baremetal)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class ComputeDelegate < DelegateClass(Fog::Compute::OpenStack)
class ComputeDelegate < DelegateClass(Fog::OpenStack::Compute)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class EventDelegate < DelegateClass(Fog::Event::OpenStack)
class EventDelegate < DelegateClass(Fog::OpenStack::Event)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def self.raw_connect_try_ssl(username, password, address, port, service = "Compu

def self.raw_connect(username, password, auth_url, service = "Compute", extra_opts = nil)
opts = {
:provider => 'OpenStack',
:openstack_auth_url => auth_url,
:openstack_username => username,
:openstack_api_key => password,
Expand All @@ -69,17 +68,15 @@ def self.raw_connect(username, password, auth_url, service = "Compute", extra_op
end

if service == "Planning"
# Special behaviour for Planning service Tuskar, since it is OpenStack specific service, there is no
# Fog::Planning module, only Fog::OpenStack::Planning
Fog::Openstack.const_get(service).new(opts)
Fog::OpenStack::Planning.new(opts)
elsif service == "Workflow"
Fog::Workflow::OpenStack.new(opts)
Fog::OpenStack::Workflow.new(opts)
elsif service == "Metric"
Fog::Metric::OpenStack.new(opts)
Fog::OpenStack::Metric.new(opts)
elsif service == "Event"
Fog::Event::OpenStack.new(opts)
Fog::OpenStack::Event.new(opts)
else
Fog.const_get(service).new(opts)
Fog::OpenStack.const_get(service).new(opts)
end
rescue Fog::OpenStack::Auth::Catalog::ServiceTypeError, Fog::Service::NotFound
$fog_log.warn("MIQ(#{self.class.name}##{__method__}) "\
Expand Down Expand Up @@ -386,7 +383,7 @@ def service_for_each_accessible_tenant(service_name)

def accessor_for_accessible_tenants(service, accessor, unique_id, array_accessor = true)
results = []
not_found_error = Fog.const_get(service)::OpenStack::NotFound
not_found_error = Fog::OpenStack.const_get(service)::NotFound
::Parallel.each(service_for_each_accessible_tenant(service), :in_threads => thread_limit) do |svc, project|

response = begin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class IdentityDelegate < DelegateClass(Fog::Identity::OpenStack)
class IdentityDelegate < DelegateClass(Fog::OpenStack::Identity)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down Expand Up @@ -47,7 +47,7 @@ def visible_tenants_v2
)
end
body = Fog::JSON.decode(response.body)
vtenants = Fog::Identity::OpenStack::V2::Tenants.new
vtenants = Fog::OpenStack::Identity::V2::Tenants.new
vtenants.load(body['tenants'])
vtenants
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class ImageDelegate < DelegateClass(Fog::Image::OpenStack)
class ImageDelegate < DelegateClass(Fog::OpenStack::Image)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand All @@ -17,9 +17,9 @@ def initialize(dobj, os_handle, name)

def version
case @delegated_object
when Fog::Image::OpenStack::V1::Real
when Fog::OpenStack::Image::V1::Real
:v1
when Fog::Image::OpenStack::V2::Real
when Fog::OpenStack::Image::V2::Real
:v2
else
raise "Non supported Glance version #{@delegated_object.class.name}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class IntrospectionDelegate < DelegateClass(Fog::Introspection::OpenStack)
class IntrospectionDelegate < DelegateClass(Fog::OpenStack::Introspection)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class MeteringDelegate < DelegateClass(Fog::Metering::OpenStack)
class MeteringDelegate < DelegateClass(Fog::OpenStack::Metering)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class MetricDelegate < DelegateClass(Fog::Metric::OpenStack)
class MetricDelegate < DelegateClass(Fog::OpenStack::Metric)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class NetworkDelegate < DelegateClass(Fog::Network::OpenStack)
class NetworkDelegate < DelegateClass(Fog::OpenStack::Network)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class NFVDelegate < DelegateClass(Fog::NFV::OpenStack)
class NFVDelegate < DelegateClass(Fog::OpenStack::NFV)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class OrchestrationDelegate < DelegateClass(Fog::Orchestration::OpenStack)
class OrchestrationDelegate < DelegateClass(Fog::OpenStack::Orchestration)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class StorageDelegate < DelegateClass(Fog::Storage::OpenStack)
class StorageDelegate < DelegateClass(Fog::OpenStack::Storage)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class VolumeDelegate < DelegateClass(Fog::Volume::OpenStack)
class VolumeDelegate < DelegateClass(Fog::OpenStack::Volume)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OpenstackHandle
class WorkflowDelegate < DelegateClass(Fog::Workflow::OpenStack)
class WorkflowDelegate < DelegateClass(Fog::OpenStack::Workflow)
include OpenstackHandle::HandledList
include Vmdb::Logging

Expand Down
9 changes: 4 additions & 5 deletions lib/tasks_private/openstack.rake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace :vcr do
host, port, username, password = secrets_yml.values_at("hostname", "port", "userid", "password")

{
:provider => "OpenStack",
:openstack_auth_url => "https://#{host}:#{port}/v3/",
:openstack_username => username,
:openstack_api_key => password,
Expand All @@ -38,29 +37,29 @@ namespace :vcr do
def compute_client
@compute_client ||= begin
require 'fog/openstack'
Fog::Compute.new(fog_connect_opts)
Fog::OpenStack::Compute.new(fog_connect_opts)
end
end

def network_client
@network_client ||= begin
require 'fog/openstack'
Fog::Network.new(fog_connect_opts)
Fog::OpenStack::Network.new(fog_connect_opts)
end
end

def identity_client
@identity_client ||= begin
require 'fog/openstack'
Fog::Identity.new(fog_connect_opts)
Fog::OpenStack::Identity.new(fog_connect_opts)
end
end

def with_retry(retry_count: 10, retry_sleep: 10)
retry_count.times do
yield
sleep(retry_sleep)
rescue Fog::Compute::OpenStack::NotFound
rescue Fog::OpenStack::Compute::NotFound
break
end
end
Expand Down
2 changes: 1 addition & 1 deletion manageiq-providers-openstack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "activesupport", "~> 6.0"
spec.add_dependency "bunny", "~> 2.1.0"
spec.add_dependency "excon", "~> 0.71"
spec.add_dependency "fog-openstack", ">= 0.3.10"
spec.add_dependency "fog-openstack", "~> 1.0"
spec.add_dependency "more_core_extensions", ">= 3.2", "< 5"
spec.add_dependency "parallel", "~> 1.12"

Expand Down
4 changes: 2 additions & 2 deletions spec/legacy/openstack_handle/handle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
end

it "ignores 404 errors from services" do
expect(@openstack_svc).to receive(:security_groups).and_raise(Fog::Network::OpenStack::NotFound)
expect(@openstack_svc).to receive(:security_groups).and_raise(Fog::OpenStack::Network::NotFound)

data = @handle.accessor_for_accessible_tenants("Network", :security_groups, :id)
expect(data).to be_empty
end

it "ignores 404 errors from services returning arrays" do
security_groups = double("security_groups").as_null_object
expect(security_groups).to receive(:to_a).and_raise(Fog::Network::OpenStack::NotFound)
expect(security_groups).to receive(:to_a).and_raise(Fog::OpenStack::Network::NotFound)

expect(@openstack_svc).to receive(:security_groups).and_return(security_groups)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ def stub_excon_errors
not_found = Excon::Errors::NotFound

# Error in all stack relations
allow_any_instance_of(Fog::Orchestration::OpenStack::Stack).to receive(:outputs).and_raise(forbidden, "Fog::Orchestration::OpenStack::Stack.outputs Forbidden")
allow_any_instance_of(Fog::Orchestration::OpenStack::Stack).to receive(:resources).and_raise(not_found, "Fog::Orchestration::OpenStack::Stack.resources NotFound")
allow_any_instance_of(Fog::Orchestration::OpenStack::Stack).to receive(:parameters).and_raise(not_found, "Fog::Orchestration::OpenStack::Stack.parameters NotFound")
allow_any_instance_of(Fog::Orchestration::OpenStack::Stack).to receive(:template).and_raise(not_found, "Fog::Orchestration::OpenStack::Stack.template NotFound")
allow_any_instance_of(Fog::OpenStack::Orchestration::Stacks).to receive(:outputs).and_raise(forbidden, "Fog::OpenStack::Orchestration::Stacks.outputs Forbidden")
allow_any_instance_of(Fog::OpenStack::Orchestration::Stacks).to receive(:resources).and_raise(not_found, "Fog::OpenStack::Orchestration::Stacks.resources NotFound")
allow_any_instance_of(Fog::OpenStack::Orchestration::Stacks).to receive(:parameters).and_raise(not_found, "Fog::OpenStack::Orchestration::Stacks.parameters NotFound")
allow_any_instance_of(Fog::OpenStack::Orchestration::Stacks).to receive(:template).and_raise(not_found, "Fog::OpenStack::Orchestration::Stacks.template NotFound")

# Error in directory relation
allow_any_instance_of(Fog::Storage::OpenStack::Directory).to receive(:files).and_raise(not_found, "Fog::Storage::OpenStack::Directory Files NotFound")
allow_any_instance_of(Fog::OpenStack::Storage::Directory).to receive(:files).and_raise(not_found, "Fog::OpenStack::Storage::Directory Files NotFound")

# Error in Availability zones list
allow_any_instance_of(Fog::Compute::OpenStack::Real).to receive(:availability_zones).and_raise(forbidden, "Fog::Compute::OpenStack::Real.availability_zones Forbidden")
allow_any_instance_of(Fog::Volume::OpenStack::Real).to receive(:availability_zones).and_raise(not_found, "Fog::Volume::OpenStack::Real.availability_zones NotFound")
allow_any_instance_of(Fog::Compute::OpenStack::AvailabilityZones).to receive(:summary).and_raise(forbidden, "Fog::Compute::OpenStack::AvailabilityZones.summary Forbidden")
allow_any_instance_of(Fog::Volume::OpenStack::AvailabilityZones).to receive(:summary).and_raise(not_found, "Fog::Volume::OpenStack::AvailabilityZones.summary NotFound")
allow_any_instance_of(Fog::OpenStack::Compute::Real).to receive(:availability_zones).and_raise(forbidden, "Fog::OpenStack::Compute::Real.availability_zones Forbidden")
allow_any_instance_of(Fog::OpenStack::Volume::Real).to receive(:availability_zones).and_raise(not_found, "Fog::OpenStack::Volume::Real.availability_zones NotFound")
allow_any_instance_of(Fog::OpenStack::Compute::AvailabilityZones).to receive(:summary).and_raise(forbidden, "Fog::OpenStack::Compute::AvailabilityZones.summary Forbidden")
allow_any_instance_of(Fog::OpenStack::Volume::AvailabilityZones).to receive(:summary).and_raise(not_found, "Fog::OpenStack::Volume::AvailabilityZones.summary NotFound")
# Error in list of quotas
allow_any_instance_of(Fog::Compute::OpenStack::Real).to receive(:get_quota).and_raise(forbidden, "Fog::Compute::OpenStack::Real.get_quota Forbidden")
allow_any_instance_of(Fog::Network::OpenStack::Real).to receive(:get_quota).and_raise(not_found, "Fog::Network::OpenStack::Real.get_quota NotFound")
allow_any_instance_of(Fog::Volume::OpenStack::Real).to receive(:get_quota).and_raise(not_found, "Fog::Volume::OpenStack::Real.get_quota NotFound")
allow_any_instance_of(Fog::OpenStack::Compute::Real).to receive(:get_quota).and_raise(forbidden, "Fog::OpenStack::Compute::Real.get_quota Forbidden")
allow_any_instance_of(Fog::OpenStack::Network::Real).to receive(:get_quota).and_raise(not_found, "Fog::OpenStack::Network::Real.get_quota NotFound")
allow_any_instance_of(Fog::OpenStack::Volume::Real).to receive(:get_quota).and_raise(not_found, "Fog::OpenStack::Volume::Real.get_quota NotFound")

# And random error caught by handled_list
allow_any_instance_of(Fog::Compute::OpenStack::KeyPairs).to receive(:all).and_raise(not_found, "Fog::Compute::OpenStack::KeyPairs.all NotFound")
allow_any_instance_of(Fog::Compute::OpenStack::Flavors).to receive(:all).and_raise(forbidden, "Fog::Compute::OpenStack::Flavors.all Forbidden")
allow_any_instance_of(Fog::OpenStack::Compute::KeyPairs).to receive(:all).and_raise(not_found, "Fog::OpenStack::Compute::KeyPairs.all NotFound")
allow_any_instance_of(Fog::OpenStack::Compute::Flavors).to receive(:all).and_raise(forbidden, "Fog::OpenStack::Compute::Flavors.all Forbidden")
end

def assert_with_errors
Expand Down
Loading

0 comments on commit 0cec9e5

Please sign in to comment.