Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip]Upgrade Ovirt Cluster through Ansibel #304

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/manageiq/providers/redhat/infra_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ManageIQ::Providers::Redhat::InfraManager < ManageIQ::Providers::InfraManager
require_nested :EmsCluster
require_nested :EventCatcher
require_nested :EventParser
require_nested :RefreshWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ def use_graph_refresh?
use_ovirt_sdk? && supported_api_versions.include?('4')
end

def connect(options = {})
raise "no credentials defined" if missing_credentials?(options[:auth_type])
version = options[:version] || highest_allowed_api_version
unless options[:skip_supported_api_validation] || supports_the_api_version?(version)
raise "version #{version} of the api is not supported by the provider"
end

# Prepare the options to call the method that creates the actual connection:
connect_options = {
def apply_connection_options_defaults(options)
{
:id => id,
:scheme => options[:scheme] || 'https',
:server => options[:ip] || address,
Expand All @@ -48,7 +41,17 @@ def connect(options = {})
:verify_ssl => default_endpoint.verify_ssl,
:ca_certs => default_endpoint.certificate_authority
}
end

def connect(options = {})
raise "no credentials defined" if missing_credentials?(options[:auth_type])
version = options[:version] || highest_allowed_api_version
unless options[:skip_supported_api_validation] || supports_the_api_version?(version)
raise "version #{version} of the api is not supported by the provider"
end

# Prepare the options to call the method that creates the actual connection:
connect_options = apply_connection_options_defaults(options)
# Starting with version 4 of oVirt authentication doesn't work when using directly the IP address, it requires
# the fully qualified host name, so if we received an IP address we try to convert it into the corresponding
# host name:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class ManageIQ::Providers::Redhat::InfraManager::EmsCluster < ::EmsCluster
Copy link
Contributor

@Ladas Ladas Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borod108 lets try to define this as

module ManageIQ
  module Providers
    module Redhat
      class InfraManager
         class EmsCluster < ::EmsCluster
         end
      end
    end
  end
end

def upgrade(options = {})
role_options = {:role_name => "oVirt.cluster-upgrade"}
job = ManageIQ::Providers::AnsibleRoleWorkflow.create_job({}, extra_vars_for_upgrade(options), role_options)
job.signal(:start)
job.miq_task
end

private

def extra_vars_for_upgrade(options = {})
connect_options = ext_management_system.apply_connection_options_defaults(options)

url = URI::Generic.build(
:scheme => connect_options[:scheme],
:host => connect_options[:server],
:port => connect_options[:port],
:path => connect_options[:path]
).to_s

{
:engine_url => url,
:engine_user => connect_options[:username],
:engine_password => connect_options[:password],
:cluster_name => name,
:hostname => "localhost"
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def initialize_infra_inventory_collections
# --- IC groups definitions ---

def add_clusters_group
add_collection(infra, :ems_clusters)
add_collection(infra, :ems_clusters) do |builder|
builder.add_properties(:model_class => ::EmsCluster)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borod108 and with the nested definition ^, lets try

:model_class => ManageIQ::Providers::Redhat::InfraManager::EmsCluster

and then verify it stores the right :type into the DB

end
add_resource_pools
end

Expand Down
3 changes: 3 additions & 0 deletions spec/factories/ems_cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FactoryGirl.define do
factory :ems_cluster_redhat, :class => "ManageIQ::Providers::Redhat::InfraManager::EmsCluster", :parent => :ems_cluster
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe ManageIQ::Providers::Redhat::InfraManager::EmsCluster do
context "#upgrade" do
before do
@ems = FactoryGirl.create(:ems_redhat_with_authentication)
@cluster = FactoryGirl.create(:ems_cluster_redhat, :ems_id => @ems.id)
my_server = double("my_server", :guid => "guid1")
allow(MiqServer).to receive(:my_server).and_return(my_server)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What receive(:my_server) stands for ? it doesn't seems like a method name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end
it "sends the right parameters to the upgrade" do
env_vars = {}
extra_args = {:engine_url => "https://#{@ems.address}/ovirt-engine/api",
:engine_user => @ems.authentication_userid,
:engine_password => @ems.authentication_password,
:cluster_name => @cluster.name,
:hostname => "localhost"}
role_arg = {:role_name=>"oVirt.cluster-upgrade"}
expect(ManageIQ::Providers::AnsibleRoleWorkflow).to receive(:create_job).with(env_vars, extra_args, role_arg).and_call_original
@cluster.upgrade
end
end
end