Skip to content
Merged
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
12 changes: 9 additions & 3 deletions internal/extractor/plugins/sap/host_details.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ WITH host_traits AS (
h.hypervisor_type,
h.running_vms,
h.state,
h.status,
h.service_disabled_reason,
STRING_AGG(t.name, ',') AS traits
FROM openstack_hypervisors h
JOIN openstack_resource_provider_traits t
LEFT JOIN openstack_resource_provider_traits t
ON h.id = t.resource_provider_uuid
GROUP BY h.service_host, h.hypervisor_type, h.running_vms, h.state
GROUP BY h.service_host, h.hypervisor_type, h.running_vms, h.state, h.status, h.service_disabled_reason
)
SELECT
ht.service_host AS compute_host,
Expand All @@ -33,13 +35,17 @@ SELECT
CASE
WHEN ht.traits LIKE '%CUSTOM_DECOMMISSIONING%' THEN false
WHEN ht.traits LIKE '%CUSTOM_EXTERNAL_CUSTOMER_SUPPORTED%' THEN false
WHEN ht.traits LIKE '%COMPUTE_STATUS_DISABLED%' THEN false
WHEN ht.status != 'enabled' THEN false
WHEN ht.state != 'up' THEN false
ELSE true
END AS enabled,
CASE
WHEN ht.traits LIKE '%CUSTOM_DECOMMISSIONING%' THEN 'decommissioning'
WHEN ht.traits LIKE '%CUSTOM_EXTERNAL_CUSTOMER_SUPPORTED%' THEN 'external customer'
WHEN ht.state != 'up' THEN 'not up'
WHEN ht.traits LIKE '%COMPUTE_STATUS_DISABLED%' THEN '[compute status disabled trait] ' || COALESCE(ht.service_disabled_reason, '--')
WHEN ht.status != 'enabled' THEN '[status: not enabled] ' || COALESCE(ht.service_disabled_reason, '--')
WHEN ht.state != 'up' THEN '[state: not up] ' || COALESCE(ht.service_disabled_reason, '--')
ELSE NULL
END AS disabled_reason
FROM host_traits ht
Expand Down
57 changes: 40 additions & 17 deletions internal/extractor/plugins/sap/host_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
t.Fatalf("expected no error, got %v", err)
}

exampleServiceDisabledReason := "example reason"

// Insert mock data into the hypervisors and traits tables
hypervisors := []any{
// VMware host
&nova.Hypervisor{ID: "uuid1", ServiceHost: "nova-compute-bb01", HypervisorType: "vcenter", RunningVMs: 5, State: "up"},
&nova.Hypervisor{ID: "uuid1", ServiceHost: "nova-compute-bb01", HypervisorType: "vcenter", RunningVMs: 5, State: "up", Status: "enabled"},
// KVM host
&nova.Hypervisor{ID: "uuid2", ServiceHost: "node001-bb02", HypervisorType: "qemu", RunningVMs: 3, State: "down"},
&nova.Hypervisor{ID: "uuid2", ServiceHost: "node001-bb02", HypervisorType: "qemu", RunningVMs: 3, State: "down", Status: "enabled"},
// Ironic host (should be skipped)
&nova.Hypervisor{ID: "uuid3", ServiceHost: "ironic-host-01", HypervisorType: "ironic", RunningVMs: 0, State: "up"},
&nova.Hypervisor{ID: "uuid3", ServiceHost: "ironic-host-01", HypervisorType: "ironic", RunningVMs: 0, State: "up", Status: "enabled"},
// Host with no special traits
&nova.Hypervisor{ID: "uuid4", ServiceHost: "node002-bb03", HypervisorType: "test", RunningVMs: 2, State: "up"},
&nova.Hypervisor{ID: "uuid4", ServiceHost: "node002-bb03", HypervisorType: "test", RunningVMs: 2, State: "up", Status: "enabled"},
// Host with disabled status, no entry in the resource providers
&nova.Hypervisor{ID: "uuid5", ServiceHost: "node003-bb03", HypervisorType: "test", RunningVMs: 2, State: "up", Status: "disabled", ServiceDisabledReason: &exampleServiceDisabledReason},
// Host with disabled trait
&nova.Hypervisor{ID: "uuid6", ServiceHost: "node004-bb03", HypervisorType: "test", RunningVMs: 2, State: "up", Status: "enabled", ServiceDisabledReason: &exampleServiceDisabledReason},
}

if err := testDB.Insert(hypervisors...); err != nil {
Expand All @@ -74,10 +80,12 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
&placement.Trait{ResourceProviderUUID: "uuid1", Name: "CUSTOM_EXTERNAL_CUSTOMER_SUPPORTED"},
// KVM host traits
&placement.Trait{ResourceProviderUUID: "uuid2", Name: "CUSTOM_NUMASIZE_C48_M729"},
// Ironic host traits (should be ignored)
// Ironic host traits
&placement.Trait{ResourceProviderUUID: "uuid3", Name: "TRAIT_IGNORED"},
// Disabled KVM host
&placement.Trait{ResourceProviderUUID: "uuid4", Name: "CUSTOM_DECOMMISSIONING"},
// Host with disabled trait
&placement.Trait{ResourceProviderUUID: "uuid6", Name: "COMPUTE_STATUS_DISABLED"},
}

if err := testDB.Insert(traits...); err != nil {
Expand All @@ -92,6 +100,8 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
&shared.HostAZ{AvailabilityZone: nil, ComputeHost: "node001-bb02"},
&shared.HostAZ{AvailabilityZone: &availabilityZone2, ComputeHost: "node002-bb03"},
&shared.HostAZ{AvailabilityZone: &availabilityZone2, ComputeHost: "ironic-host-01"},
&shared.HostAZ{AvailabilityZone: &availabilityZone2, ComputeHost: "node003-bb03"},
&shared.HostAZ{AvailabilityZone: &availabilityZone2, ComputeHost: "node004-bb03"},
}

if err := testDB.Insert(hostAvailabilityZones...); err != nil {
Expand All @@ -117,15 +127,6 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
t.Fatalf("expected no error from Extract, got %v", err)
}

// Only non-ironic hosts should be present
if len(hostDetails) != 4 {
t.Fatalf("expected 4 host details, got %d", len(hostDetails))
}

disabledReasonExternal := "external customer"
disabledReasonDecommissioning := "decommissioning"
disabledReasonStateNotUp := "not up"

expected := []HostDetails{
{
ComputeHost: "nova-compute-bb01",
Expand All @@ -135,7 +136,7 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
HypervisorFamily: "vmware",
WorkloadType: "hana",
Enabled: false,
DisabledReason: &disabledReasonExternal,
DisabledReason: &[]string{"external customer"}[0],
RunningVMs: 5,
},
{
Expand All @@ -146,7 +147,7 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
HypervisorFamily: "kvm",
WorkloadType: "general-purpose",
Enabled: false,
DisabledReason: &disabledReasonStateNotUp,
DisabledReason: &[]string{"[state: not up] --"}[0],
RunningVMs: 3,
},
{
Expand All @@ -157,7 +158,7 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
HypervisorType: "test",
WorkloadType: "general-purpose",
Enabled: false,
DisabledReason: &disabledReasonDecommissioning,
DisabledReason: &[]string{"decommissioning"}[0],
RunningVMs: 2,
},
{
Expand All @@ -171,6 +172,28 @@ func TestHostDetailsExtractor_Extract(t *testing.T) {
DisabledReason: nil,
RunningVMs: 0,
},
{
ComputeHost: "node003-bb03",
AvailabilityZone: "az2",
CPUArchitecture: "unknown",
HypervisorType: "test",
HypervisorFamily: "kvm",
WorkloadType: "general-purpose",
Enabled: false,
DisabledReason: &[]string{"[status: not enabled] " + exampleServiceDisabledReason}[0],
RunningVMs: 2,
},
{
ComputeHost: "node004-bb03",
AvailabilityZone: "az2",
CPUArchitecture: "unknown",
HypervisorType: "test",
HypervisorFamily: "kvm",
WorkloadType: "general-purpose",
Enabled: false,
DisabledReason: &[]string{"[compute status disabled trait] " + exampleServiceDisabledReason}[0],
RunningVMs: 2,
},
}

// Map the host details by compute host name for easier comparison
Expand Down
Loading
Loading