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

SWATCH-1929: Replace rhsm.VM_HOST_UUID by system profile.virtual_host_uuid #3043

Merged
merged 1 commit into from Feb 19, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/insert-mock-hosts
Expand Up @@ -35,7 +35,6 @@ def generate_host(inventory_id=None, insights_id=None, account_number=None, org_
'facts': json.dumps({
'rhsm': {
'orgId': org_id or f'org_{account}',
'VM_HOST_UUID': str(hypervisor_uuid) if hypervisor_uuid else None,
'IS_VIRTUAL': is_guest,
},
}),
Expand All @@ -50,7 +49,8 @@ def generate_host(inventory_id=None, insights_id=None, account_number=None, org_
'number_of_sockets': sockets,
'cloud_provider': cloud_provider,
'is_marketplace': is_marketplace,
'host_type': host_type
'host_type': host_type,
'virtual_host_uuid': str(hypervisor_uuid) if hypervisor_uuid else None,
}),
'stale_timestamp': '2030-01-01',
'reporter': 'rhsm-conduit',
Expand Down
Expand Up @@ -75,11 +75,11 @@ int activeSystemCountForOrgId(
nativeQuery = true,
value =
"select "
+ "distinct h.facts->'rhsm'->>'VM_HOST_UUID' as hyp_id, "
+ "distinct h.system_profile_facts->>'virtual_host_uuid' as hyp_id, "
+ "h_.canonical_facts->>'subscription_manager_id' as hyp_subman_id "
+ "from hosts h "
+ "left outer join hosts h_ on h.facts->'rhsm'->>'VM_HOST_UUID' = h_.canonical_facts->>'subscription_manager_id' "
+ "where h.facts->'rhsm'->'VM_HOST_UUID' is not null "
+ "left outer join hosts h_ on h.system_profile_facts->>'virtual_host_uuid' = h_.canonical_facts->>'subscription_manager_id' "
+ "where h.system_profile_facts->>'virtual_host_uuid' is not null "
+ "and h.org_id IN (:orgIds)"
+ "union all "
+ "select "
Expand Down
Expand Up @@ -98,7 +98,6 @@
select
h.id as inventory_id, h.org_id, h.modified_on, h.account, h.display_name,
h.facts->'rhsm'->>'IS_VIRTUAL' as is_virtual,
h.facts->'rhsm'->>'VM_HOST_UUID' as hypervisor_uuid,
h.facts->'satellite'->>'virtual_host_uuid' as satellite_hypervisor_uuid,
h.facts->'satellite'->>'system_purpose_role' as satellite_role,
h.facts->'satellite'->>'system_purpose_sla' as satellite_sla,
Expand All @@ -111,6 +110,7 @@
h.facts->'rhsm'->>'SYSPURPOSE_UNITS' as syspurpose_units,
h.facts->'rhsm'->>'BILLING_MODEL' as billing_model,
h.facts->'qpc'->>'IS_RHEL' as is_rhel,
h.system_profile_facts->>'virtual_host_uuid' as hypervisor_uuid,
h.system_profile_facts->>'infrastructure_type' as system_profile_infrastructure_type,
h.system_profile_facts->>'cores_per_socket' as system_profile_cores_per_socket,
h.system_profile_facts->>'number_of_sockets' as system_profile_sockets,
Expand All @@ -127,11 +127,11 @@
h.stale_timestamp,
coalesce(
h.facts->'satellite'->>'virtual_host_uuid',
h.facts->'rhsm'->>'VM_HOST_UUID',
h.system_profile_facts->>'virtual_host_uuid',
h.canonical_facts->>'subscription_manager_id') as hardware_subman_id,
coalesce(
h.facts->'satellite'->>'virtual_host_uuid',
h.facts->'rhsm'->>'VM_HOST_UUID'
h.system_profile_facts->>'virtual_host_uuid'
) as any_hypervisor_uuid
from hosts h
cross join lateral (
Expand Down
Expand Up @@ -50,7 +50,6 @@ class InventoryRepositoryIT implements ExtendWithInventoryService, ExtendWithSwa
private static final String DISPLAY_NAME = "display name";
private static final String REPORTER = "test";
private static final String SUBSCRIPTION_MANAGER_ID = "subs id";
private static final String VM_HOST_UUID = "vm host uuid test";
private static final String VIRTUAL_HOST_UUID = "virtual host uuid test";
private static final String SYSTEM_PURPOSE_ROLE = "system purpose role test";
private static final String SYSTEM_PURPOSE_SLA = "system purpose sla test";
Expand Down Expand Up @@ -96,7 +95,7 @@ void testStreamFacts() { // NOSONAR
assertEquals(ORG_ID, fact.getOrgId());
assertNotNull(fact.getModifiedOn());
assertTrue(fact.isVirtual());
assertEquals(VM_HOST_UUID, fact.getHypervisorUuid());
assertEquals(VIRTUAL_HOST_UUID, fact.getHypervisorUuid());
assertEquals(VIRTUAL_HOST_UUID, fact.getSatelliteHypervisorUuid());
assertEquals(SYSTEM_PURPOSE_ROLE, fact.getSatelliteRole());
assertEquals(SYSTEM_PURPOSE_SLA, fact.getSatelliteSla());
Expand Down Expand Up @@ -140,7 +139,7 @@ void testGetReportedHypervisors() {
List<Object[]> reportedHypervisors =
repository.getReportedHypervisors(List.of(ORG_ID)).toList();
assertEquals(2, reportedHypervisors.size());
assertEquals(VM_HOST_UUID, reportedHypervisors.get(0)[0]);
assertEquals(VIRTUAL_HOST_UUID, reportedHypervisors.get(0)[0]);
assertEquals(VIRTUAL_HOST_UUID, reportedHypervisors.get(1)[0]);
}

Expand Down Expand Up @@ -168,8 +167,6 @@ private UUID givenHost() {
of(
"IS_VIRTUAL",
"true",
"VM_HOST_UUID",
VM_HOST_UUID,
"GUEST_ID",
GUEST_ID,
"SYNC_TIMESTAMP",
Expand Down Expand Up @@ -217,7 +214,9 @@ private UUID givenHost() {
"is_marketplace",
"true",
"installed_products",
INSTALLED_PRODUCTS),
INSTALLED_PRODUCTS,
"virtual_host_uuid",
VIRTUAL_HOST_UUID),
REPORTER,
now(),
now(),
Expand Down
Expand Up @@ -35,4 +35,6 @@ properties:
type: array
items:
$ref: "hbi-network-interface.yaml"
virtual_host_uuid:
type: string

Expand Up @@ -566,7 +566,7 @@ private void extractVirtualizationFacts(

String vmHypervisorUuid = consumer.getHypervisorUuid();
if (StringUtils.hasLength(vmHypervisorUuid)) {
facts.setVmHostUuid(vmHypervisorUuid);
facts.setVirtualHostUuid(vmHypervisorUuid);
}

String vmId = consumer.getGuestId();
Expand Down
Expand Up @@ -149,6 +149,7 @@ private HbiSystemProfile createSystemProfile(ConduitFacts facts) {
systemProfile.setNetworkInterfaces(facts.getNetworkInterfaces());
systemProfile.setIsMarketplace(facts.getIsMarketplace());
systemProfile.setReleasever(facts.getReleaseVer());
systemProfile.setVirtualHostUuid(facts.getVirtualHostUuid());
return systemProfile;
}

Expand All @@ -166,7 +167,6 @@ private Map<String, Object> buildFactMap(
addFact(rhsmFactMap, "ARCHITECTURE", conduitFacts.getArchitecture());
addFact(rhsmFactMap, "IS_VIRTUAL", conduitFacts.getIsVirtual());
addFact(rhsmFactMap, "VM_HOST", conduitFacts.getVmHost());
addFact(rhsmFactMap, "VM_HOST_UUID", conduitFacts.getVmHostUuid());
addFact(rhsmFactMap, "GUEST_ID", conduitFacts.getGuestId());
addFact(rhsmFactMap, "RH_PROD", conduitFacts.getRhProd());
addFact(rhsmFactMap, "SYSPURPOSE_ROLE", conduitFacts.getSysPurposeRole());
Expand Down
Expand Up @@ -261,7 +261,7 @@ components:
type: boolean
vm_host:
type: string
vm_host_uuid:
virtual_host_uuid:
type: string
guest_id:
type: string
Expand Down
Expand Up @@ -230,7 +230,7 @@ void testUnmodifiedFieldsTransferred() {
assertEquals(uuid, conduitFacts.getSubscriptionManagerId());
assertEquals("test_org", conduitFacts.getOrgId());
assertEquals("hypervisor1.test.com", conduitFacts.getVmHost());
assertEquals(hypervisorUuid, conduitFacts.getVmHostUuid());
assertEquals(hypervisorUuid, conduitFacts.getVirtualHostUuid());
assertEquals("guest", conduitFacts.getGuestId());
assertEquals("host1.test.com", conduitFacts.getFqdn());
assertEquals(systemUuid, conduitFacts.getBiosUuid());
Expand Down