forked from ManageIQ/manageiq-providers-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ManageIQ#264 from nasark/subclass_kubevirt
Subclass Kubevirt InfraManager to separate Openshift Virtualization provider
- Loading branch information
Showing
27 changed files
with
4,857 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager < ManageIQ::Providers::Kubevirt::InfraManager | ||
belongs_to :parent_manager, | ||
:foreign_key => :parent_ems_id, | ||
:inverse_of => :infra_manager, | ||
:class_name => "ManageIQ::Providers::Openshift::ContainerManager" | ||
|
||
# | ||
# This is the list of features that this provider supports: | ||
# | ||
supports :catalog | ||
supports :provisioning | ||
|
||
def self.ems_type | ||
@ems_type ||= "openshift_infra".freeze | ||
end | ||
|
||
def self.description | ||
@description ||= "OpenShift Virtualization".freeze | ||
end | ||
|
||
def self.catalog_types | ||
{"openshift" => N_("OpenShift Virtualization")} | ||
end | ||
|
||
def self.vendor | ||
"openshift_infra".freeze | ||
end | ||
|
||
def self.product_name | ||
"OpenShift Virtualization".freeze | ||
end | ||
|
||
def self.version | ||
"0.1.0".freeze | ||
end | ||
|
||
def default_authentication_type | ||
:openshift | ||
end | ||
|
||
def self.display_name(number = 1) | ||
n_('Infrastructure Provider (OpenShift Virtualization)', 'Infrastructure Providers (OpenShift Virtualization)', number) | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
app/models/manageiq/providers/openshift/infra_manager/cluster.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Cluster.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Cluster < ManageIQ::Providers::Kubevirt::InfraManager::Cluster | ||
end |
4 changes: 4 additions & 0 deletions
4
app/models/manageiq/providers/openshift/infra_manager/connection.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Connection.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Connection < ManageIQ::Providers::Kubevirt::InfraManager::Connection | ||
end |
4 changes: 4 additions & 0 deletions
4
app/models/manageiq/providers/openshift/infra_manager/host.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Host.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Host < ManageIQ::Providers::Kubevirt::InfraManager::Host | ||
end |
4 changes: 4 additions & 0 deletions
4
app/models/manageiq/providers/openshift/infra_manager/provision.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Provision.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Provision < ManageIQ::Providers::Kubevirt::InfraManager::Provision | ||
end |
9 changes: 9 additions & 0 deletions
9
app/models/manageiq/providers/openshift/infra_manager/provision_workflow.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class ManageIQ::Providers::Openshift::InfraManager::ProvisionWorkflow < ManageIQ::Providers::Kubevirt::InfraManager::ProvisionWorkflow | ||
def self.provider_model | ||
ManageIQ::Providers::Openshift::InfraManager | ||
end | ||
|
||
def dialog_name_from_automate(message = 'get_dialog_name') | ||
super(message, {'platform' => 'openshift'}) | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/infra_manager/refresh_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::InfraManager::RefreshWorker < ManageIQ::Providers::BaseManager::RefreshWorker | ||
end |
9 changes: 9 additions & 0 deletions
9
app/models/manageiq/providers/openshift/infra_manager/refresh_worker/runner.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'concurrent/atomic/atomic_boolean' | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::RefreshWorker::Runner < ManageIQ::Providers::Kubevirt::InfraManager::RefreshWorker::Runner | ||
private | ||
|
||
def provider_class | ||
ManageIQ::Providers::Openshift | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/infra_manager/refresher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::InfraManager::Refresher < ManageIQ::Providers::Kubevirt::InfraManager::Refresher | ||
end |
4 changes: 4 additions & 0 deletions
4
app/models/manageiq/providers/openshift/infra_manager/storage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Storage.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Storage < ManageIQ::Providers::Kubevirt::InfraManager::Storage | ||
end |
7 changes: 7 additions & 0 deletions
7
app/models/manageiq/providers/openshift/infra_manager/template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Template.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Template < ManageIQ::Providers::Kubevirt::InfraManager::Template | ||
def self.display_name(number = 1) | ||
n_('Template (OpenShift Virtualization)', 'Templates (OpenShift Virtualization)', number) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ManageIQ::Providers::Kubevirt::InfraManager::Vm.include(ActsAsStiLeafClass) | ||
|
||
class ManageIQ::Providers::Openshift::InfraManager::Vm < ManageIQ::Providers::Kubevirt::InfraManager::Vm | ||
def self.display_name(number = 1) | ||
n_('Virtual Machine (OpenShift Virtualization)', 'Virtual Machines (OpenShift Virtualization)', number) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
class ManageIQ::Providers::Openshift::Inventory < ManageIQ::Providers::Kubernetes::Inventory | ||
def self.parser_class_for(ems, target) | ||
if !ems.kind_of?(EmsInfra) | ||
super | ||
else | ||
parser_type = if target_is_vm?(target) | ||
"PartialTargetRefresh" | ||
else | ||
"FullRefresh" | ||
end | ||
"ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::#{parser_type}".safe_constantize | ||
end | ||
end | ||
|
||
def self.build(ems, target) | ||
if !ems.kind_of?(EmsInfra) | ||
super | ||
else | ||
collector_class = collector_class_for(ems, target) | ||
|
||
collector = if target_is_vm?(target) | ||
collector_class.new(ems, target) | ||
else | ||
collector_class.new(ems, ems) | ||
end | ||
|
||
persister = persister_class_for(ems, target).new(ems, target) | ||
new( | ||
persister, | ||
collector, | ||
parser_classes_for(ems, target).map(&:new) | ||
) | ||
end | ||
end | ||
|
||
def self.target_is_vm?(target) | ||
target.kind_of?(ManageIQ::Providers::Openshift::InfraManager::Vm) | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/inventory/collector/infra_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::Inventory::Collector::InfraManager < ManageIQ::Providers::Kubevirt::Inventory::Collector | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/inventory/parser/infra_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager < ManageIQ::Providers::Kubevirt::Inventory::Parser | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/inventory/parser/infra_manager/full_refresh.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::FullRefresh < ManageIQ::Providers::Kubevirt::Inventory::Parser::FullRefresh | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/inventory/parser/infra_manager/partial_refresh.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::PartialRefresh < ManageIQ::Providers::Kubevirt::Inventory::Parser::PartialRefresh | ||
end |
2 changes: 2 additions & 0 deletions
2
...els/manageiq/providers/openshift/inventory/parser/infra_manager/partial_target_refresh.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::PartialTargetRefresh < ManageIQ::Providers::Kubevirt::Inventory::Parser::PartialTargetRefresh | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/openshift/inventory/persister/infra_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ManageIQ::Providers::Openshift::Inventory::Persister::InfraManager < ManageIQ::Providers::Kubevirt::Inventory::Persister | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
spec/models/manageiq/providers/openshift/infra_manager/refresher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
describe ManageIQ::Providers::Openshift::InfraManager::Refresher do | ||
context '#refresh' do | ||
let(:ems) do | ||
host = Rails.application.secrets.openshift[:hostname] | ||
token = Rails.application.secrets.openshift[:token] | ||
port = Rails.application.secrets.openshift[:port] | ||
zone = EvmSpecHelper.local_miq_server.zone | ||
|
||
FactoryBot.create(:ems_openshift_infra, | ||
:name => "openshift Virtualization Manager", | ||
:zone => zone).tap do |ems| | ||
ems.parent_manager.authentications << FactoryBot.create(:authentication, {:authtype => :bearer, | ||
:type => "AuthToken", | ||
:auth_key => token, | ||
:userid => "_"}) | ||
ems.parent_manager.default_endpoint.update!(:role => :default, | ||
:hostname => host, | ||
:port => port, | ||
:security_protocol => "ssl-without-validation") | ||
end | ||
end | ||
|
||
it 'works correctly with one node' do | ||
2.times do | ||
VCR.use_cassette(described_class.name.underscore) do | ||
EmsRefresh.refresh(ems) | ||
end | ||
|
||
assert_counts | ||
assert_specific_vm | ||
assert_specific_host | ||
assert_specific_cluster | ||
assert_specific_storage | ||
end | ||
end | ||
|
||
def assert_counts | ||
expect(ems.vms.count).to eq(1) | ||
expect(ems.hosts.count).to eq(6) | ||
expect(ems.clusters.count).to eq(1) | ||
expect(ems.storages.count).to eq(1) | ||
end | ||
|
||
def assert_specific_vm | ||
vm = ems.vms.find_by(:name => "fedora-gold-porcupine-50") | ||
expect(vm).to have_attributes( | ||
:ems_ref => "50c54ad2-c2a6-44ae-89f5-14d2f313882c", | ||
:name => "fedora-gold-porcupine-50", | ||
:type => "ManageIQ::Providers::Openshift::InfraManager::Vm", | ||
:uid_ems => "50c54ad2-c2a6-44ae-89f5-14d2f313882c", | ||
:vendor => "openshift_infra", | ||
:power_state => "on", | ||
:connection_state => "connected" | ||
) | ||
end | ||
|
||
def assert_specific_host | ||
host = ems.hosts.find_by(:ems_ref => "248af02e-7da9-49a4-b026-1dd1a341b0de") | ||
expect(host).to have_attributes( | ||
:connection_state => "connected", | ||
:ems_ref => "248af02e-7da9-49a4-b026-1dd1a341b0de", | ||
:type => "ManageIQ::Providers::Openshift::InfraManager::Host", | ||
:uid_ems => "248af02e-7da9-49a4-b026-1dd1a341b0de", | ||
:vmm_product => "OpenShift Virtualization", | ||
:vmm_vendor => "openshift_infra", | ||
:vmm_version => "0.1.0", | ||
:ems_cluster => ems.ems_clusters.find_by(:ems_ref => "0") | ||
) | ||
end | ||
|
||
def assert_specific_cluster | ||
cluster = ems.ems_clusters.find_by(:ems_ref => "0") | ||
expect(cluster).to have_attributes( | ||
:ems_ref => "0", | ||
:name => "openshift Virtualization Manager", | ||
:uid_ems => "0", | ||
:type => "ManageIQ::Providers::Openshift::InfraManager::Cluster" | ||
) | ||
end | ||
|
||
def assert_specific_storage | ||
storage = ems.storages.find_by(:ems_ref => "0") | ||
expect(storage).to have_attributes( | ||
:name => "openshift Virtualization Manager", | ||
:total_space => 0, | ||
:free_space => 0, | ||
:ems_ref => "0", | ||
:type => "ManageIQ::Providers::Openshift::InfraManager::Storage" | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.