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-1650: Set productID for hosts based on system architecture for QPC hosts #2652

Merged
merged 7 commits into from
Oct 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.candlepin.subscriptions.ApplicationProperties;
import org.candlepin.subscriptions.db.model.HardwareMeasurementType;
import org.candlepin.subscriptions.db.model.HostHardwareType;
Expand Down Expand Up @@ -329,6 +330,22 @@ private void handleSla(
private void normalizeQpcFacts(NormalizedFacts normalizedFacts, InventoryHostFacts hostFacts) {
// Check if this is a RHEL host and set product.
if (hostFacts.getQpcProducts() != null && hostFacts.getQpcProducts().contains("RHEL")) {
if (hostFacts.getSystemProfileArch() != null
&& CollectionUtils.isEmpty(hostFacts.getSystemProfileProductIds())) {
switch (hostFacts.getSystemProfileArch()) {
case "x86_64", "i686", "i386":
Copy link
Contributor

@Sgitario Sgitario Oct 17, 2023

Choose a reason for hiding this comment

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

One question about these values, is there any documentation or link where to get more information about it? If so, I think it would be really helpful to add a comment here including a reference or link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm not aware of any, @mirekdlugosz do you happen to know of any docs around the system arch we could link to for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really know, maybe HBI OpenAPI spec file? Or yuptoo.

As I'm on PTO this week, I'm not on position to look for links, sorry. I think it's best to merge as it is and we can add a link in another PR, if we find it.

normalizedFacts.addProduct("RHEL for x86");
break;
case "aarch64":
normalizedFacts.addProduct("RHEL for ARM");
break;
case "ppc64le":
normalizedFacts.addProduct("RHEL for IBM Power");
break;
default:
break;
}
}
normalizedFacts.addProduct("RHEL");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ public static InventoryHostFacts createRhsmHost(
return baseFacts;
}

public static InventoryHostFacts createQpcHost(String qpcProducts, OffsetDateTime syncTimestamp) {
public static InventoryHostFacts createQpcHost(
String qpcProducts, String systemArch, OffsetDateTime syncTimestamp) {
InventoryHostFacts baseFacts = createBaseHost("test_org");
baseFacts.setQpcProducts(qpcProducts);
baseFacts.setSystemProfileArch(systemArch);
baseFacts.setSyncTimestamp(syncTimestamp.toString());
return baseFacts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void testRhsmNormalization() {
@Test
void testQpcNormalization() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("RHEL", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL"));
normalizer.normalize(createQpcHost("RHEL", "x86_64", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL for x86"));
assertEquals(Integer.valueOf(0), normalized.getCores());
assertEquals(Integer.valueOf(0), normalized.getSockets());
}
Expand Down Expand Up @@ -207,21 +207,21 @@ void testIncludesHostWhenLastSyncIsWithinTheConfiguredThreshold() {
@Test
void testRhelFromQpcFacts() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("RHEL", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL"));
normalizer.normalize(createQpcHost("RHEL", "x86_64", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL for x86"));
}

@Test
void testEmptyProductListWhenRhelNotPresent() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("EAP", clock.now()), hypervisorData());
normalizer.normalize(createQpcHost("EAP", null, clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.empty());
}

@Test
void testEmptyProductListWhenQpcProductsNotSet() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost(null, clock.now()), hypervisorData());
normalizer.normalize(createQpcHost(null, null, clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.empty());
}

Expand Down Expand Up @@ -255,8 +255,10 @@ void testDetectsProductFromSyspurposeRole() {
@Test
void testRhelUngroupedIfNoVariants() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("RHEL", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.containsInAnyOrder("RHEL", "RHEL Ungrouped"));
normalizer.normalize(createQpcHost("RHEL", "x86_64", clock.now()), hypervisorData());
assertThat(
normalized.getProducts(),
Matchers.containsInAnyOrder("RHEL for x86", "RHEL", "RHEL Ungrouped"));
}

@Test
Expand Down Expand Up @@ -662,6 +664,36 @@ void testNullSocketsMarketplaceDefaulting() {
assertEquals(0, normalizedFacts.getSockets());
}

@ParameterizedTest
@ValueSource(strings = {"x86_64", "i386", "i686"})
void testQpcSystemArchSetRhelForX86Product(String arch) {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("RHEL", arch, clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL for x86"));
}

@Test
void testQpcSystemArchSetRhelForArm() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("RHEL", "aarch64", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL for ARM"));
}

@Test
void testQpcSystemArchSetRhelForIbmPower() {
NormalizedFacts normalized =
normalizer.normalize(createQpcHost("RHEL", "ppc64le", clock.now()), hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL for IBM Power"));
}

@Test
void testQpcProductIdFromEngId() {
var host = createQpcHost("RHEL", "Test", clock.now());
host.setSystemProfileProductIds("69");
NormalizedFacts normalized = normalizer.normalize(host, hypervisorData());
assertThat(normalized.getProducts(), Matchers.hasItem("RHEL for x86"));
}

private void assertClassification(
NormalizedFacts check, boolean isHypervisor, boolean isHypervisorUnknown, boolean isVirtual) {
assertEquals(isHypervisor, check.isHypervisor());
Expand Down