Search in sources :

Example 66 with ProductSubscription

use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.

the class ListTests method testListConsumedWithWildcardMatches.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36557", "RHEL7-51337" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: subcription manager list --consumed with wildcard --matches on Subscription Name, Provided Product Name, Contract Number, SKU, Service Level, Provided Product ID.  Note: wildcard match means * matches zero or more char and ? matches one char and is case insensitive.", groups = { "Tier2Tests", "blockedByBug-1146125", "blockedByBug-1204311" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListConsumedWithWildcardMatches() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.6-1"))
        throw new SkipException("The list --matches function was not implemented in this version of subscription-manager.");
    String matchesString;
    List<ProductSubscription> actualProductSubscriptionMatches;
    // register if necessary
    if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
        clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
        clienttasks.autoheal(null, null, true, null, null, null, null);
    } else
        clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    // attach all the currently available subscriptions
    clienttasks.subscribeToTheCurrentlyAllAvailableSubscriptionPoolsCollectively();
    // get all the consumed product subscriptions
    List<ProductSubscription> consumedProductSubscriptions = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, null, null, null, null, null, null).getStdout());
    // randomly choose one of the consumed Product Subscriptions
    ProductSubscription randomConsumedProductSubscription = getRandomListItem(consumedProductSubscriptions);
    // /*debugTesting 1204311*/randomConsumedProductSubscription=ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", "8a9087e34c4816e8014c48184d1b1f30", consumedProductSubscriptions);	// SKU: awesomeos-server-basic-dc; System Type: Virtual; Subscription Type: Standard (Temporary)
    // /*debugTesting 1204311*/randomConsumedProductSubscription=ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", "8a9087e34c4816e8014c48184cec1f16", consumedProductSubscriptions);	// SKU: awesomeos-server-basic-dc; System Type: Physical; Subscription Type: Standard
    // /*debugTesting 1204311*/randomConsumedProductSubscription=ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", "8a9087e34c4816e8014c48180b350dd0", consumedProductSubscriptions);	// SKU: awesomeos-virt-unlmtd-phys; System Type: Virtual; Subscription Type: Standard; Provides Awesome OS Server Bits
    log.info("Testing with randomConsumedProductSubscription=" + randomConsumedProductSubscription);
    // +-------------------------------------------+
    // Consumed Subscriptions
    // +-------------------------------------------+
    // Subscription Name: Awesome OS for All Arch (excpt for x86_64 content)
    // Provides:          Awesome OS for All Arch (excpt for x86_64 content) Bits
    // SKU:               awesomeos-all-no-86_64-cont
    // Contract:          3
    // Account:           12331131231
    // Serial:            2808682313592781316
    // Pool ID:           2c90af8b494355790149435902da0ee8
    // Active:            True
    // Quantity Used:     1
    // Service Level:
    // Service Type:
    // Status Details:
    // Subscription Type: Stackable
    // Starts:            10/23/2014
    // Ends:              10/23/2015
    // System Type:       Physical
    // Test 1: test --matches with a * wild card on Subscription Name:
    matchesString = randomConsumedProductSubscription.productName;
    // drop first word
    matchesString = matchesString.replaceFirst("^\\S+\\s+", "*");
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    // and drop last word
    matchesString = matchesString.replaceFirst("\\s+\\S+$", "*");
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // Test 2: test --matches with a * wild card on Provides:
    if (!randomConsumedProductSubscription.provides.isEmpty()) {
        matchesString = getRandomListItem(randomConsumedProductSubscription.provides);
        // drop last word
        matchesString = matchesString.replaceFirst("\\s+\\S+$", "*");
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        // and drop first word
        matchesString = matchesString.replaceFirst("^\\S+\\s+", "*");
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    } else
        log.warning("Skipping list --consumed --matches test on a Provides item since the provides list is empty on our random consumed subscription: " + randomConsumedProductSubscription);
    // Test 3: test --matches with a ? wild card on SKU:
    matchesString = randomConsumedProductSubscription.productId;
    // drop first char
    matchesString = matchesString.replaceFirst("^.", "?");
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    // and drop last char
    matchesString = matchesString.replaceFirst(".$", "?");
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // Test 4: test --matches with a ? wild card on Contract:
    matchesString = String.valueOf(randomConsumedProductSubscription.contractNumber);
    // drop last char
    matchesString = matchesString.replaceFirst(".$", "?");
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // Test 5: test --matches with a * wild card on Service Level:
    if (randomConsumedProductSubscription.serviceLevel != null && !randomConsumedProductSubscription.serviceLevel.isEmpty()) {
        matchesString = randomConsumedProductSubscription.serviceLevel;
        // drop first char
        matchesString = matchesString.replaceFirst("^.", "*");
        // drop last char
        matchesString = matchesString.replaceFirst(".$", "?");
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    } else
        log.warning("Skipping list --consumed --matches test on a Service Level item since it is null on our random consumed subscription: " + randomConsumedProductSubscription);
    // Test 6: test --matches with a ? wild card on Provided ProductId:
    if (!randomConsumedProductSubscription.provides.isEmpty()) {
        matchesString = getRandomListItem(CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, randomConsumedProductSubscription.poolId));
        int i = randomGenerator.nextInt(matchesString.length());
        matchesString = matchesString.replaceAll(String.valueOf(matchesString.charAt(i)), "?");
        // /*debugTesting 1204311*/matchesString="3?060";
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    } else
        log.warning("Skipping list --consumed --matches test on a Provides ProductId item since the provides list is empty on our random consumed subscription: " + randomConsumedProductSubscription);
// TODO Test 7: test exact --matches on a Content Name provided by a Provided ProductId
// see ListAvailableWithExactMatches_Test()
// TODO Test 8: test exact --matches on a Content Label provided by a Provided ProductId
// see ListAvailableWithExactMatches_Test()
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) BigInteger(java.math.BigInteger) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 67 with ProductSubscription

use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.

the class ListTests method testListConsumedWithExactMatches.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36556", "RHEL7-51335" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: subcription manager list --consumed with exact --matches on Subscription Name, Provided Product Name, Contract Number, SKU, Service Level, Provided Product ID.  Note: exact match means no wildcards and is case insensitive.", groups = { "Tier2Tests", "blockedByBug-1146125" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListConsumedWithExactMatches() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.6-1"))
        throw new SkipException("The list --matches function was not implemented in this version of subscription-manager.");
    String matchesString;
    List<ProductSubscription> actualProductSubscriptionMatches;
    // register if necessary
    if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
        clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
        clienttasks.autoheal(null, null, true, null, null, null, null);
    } else
        clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    // attach all the currently available subscriptions
    clienttasks.subscribeToTheCurrentlyAllAvailableSubscriptionPoolsCollectively();
    // get all the consumed product subscriptions
    List<ProductSubscription> consumedProductSubscriptions = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, null, null, null, null, null, null).getStdout());
    // randomly choose one of the consumed Product Subscriptions
    ProductSubscription randomConsumedProductSubscription = getRandomListItem(consumedProductSubscriptions);
    // /*debugTesting*/randomConsumedProductSubscription=ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productId", "exempt-sla-product-sku", consumedProductSubscriptions);
    log.info("Testing with randomConsumedProductSubscription=" + randomConsumedProductSubscription);
    // +-------------------------------------------+
    // Consumed Subscriptions
    // +-------------------------------------------+
    // Subscription Name: Awesome OS for All Arch (excpt for x86_64 content)
    // Provides:          Awesome OS for All Arch (excpt for x86_64 content) Bits
    // SKU:               awesomeos-all-no-86_64-cont
    // Contract:          3
    // Account:           12331131231
    // Serial:            2808682313592781316
    // Pool ID:           2c90af8b494355790149435902da0ee8
    // Active:            True
    // Quantity Used:     1
    // Service Level:
    // Service Type:
    // Status Details:
    // Subscription Type: Stackable
    // Starts:            10/23/2014
    // Ends:              10/23/2015
    // System Type:       Physical
    // Test 1: test exact --matches on Subscription Name:
    matchesString = randomConsumedProductSubscription.productName;
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // Test 2: test exact --matches on Provides:
    if (!randomConsumedProductSubscription.provides.isEmpty()) {
        matchesString = getRandomListItem(randomConsumedProductSubscription.provides);
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    } else
        log.warning("Skipping list --consumed --matches test on a Provides item since the provides list is empty on our random consumed subscription: " + randomConsumedProductSubscription);
    // Test 3: test exact --matches on SKU:
    matchesString = randomConsumedProductSubscription.productId;
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // Test 4: test exact --matches on Contract:
    matchesString = String.valueOf(randomConsumedProductSubscription.contractNumber);
    actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    // Test 5: test exact --matches on Service Level:
    if (randomConsumedProductSubscription.serviceLevel != null && !randomConsumedProductSubscription.serviceLevel.isEmpty()) {
        matchesString = randomConsumedProductSubscription.serviceLevel;
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    } else
        log.warning("Skipping list --consumed --matches test on a Service Level item since it is null on our random consumed subscription: " + randomConsumedProductSubscription);
    // Test 6: test exact --matches on Provided ProductId:
    if (!randomConsumedProductSubscription.provides.isEmpty()) {
        matchesString = getRandomListItem(CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, randomConsumedProductSubscription.poolId));
        actualProductSubscriptionMatches = ProductSubscription.parse(clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListConsumedWithMatches(matchesString, actualProductSubscriptionMatches, consumedProductSubscriptions);
    } else
        log.warning("Skipping list --consumed --matches test on a Provides ProductId item since the provides list is empty on our random consumed subscription: " + randomConsumedProductSubscription);
// TODO Test 7: test exact --matches on a Content Name provided by a Provided ProductId
// see ListAvailableWithExactMatches_Test()
// TODO Test 8: test exact --matches on a Content Label provided by a Provided ProductId
// see ListAvailableWithExactMatches_Test()
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) BigInteger(java.math.BigInteger) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 68 with ProductSubscription

use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.

the class ListTests method testConsumedEntitlementsListed.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27118", "RHEL7-51350" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager-cli: list consumed entitlements", groups = { "Tier2Tests" }, dataProvider = "getAllSystemSubscriptionPoolProductData", enabled = true)
@ImplementsNitrateTest(caseId = 41679)
public void testConsumedEntitlementsListed(String productId, JSONArray bundledProductDataAsJSONArray) throws JSONException, Exception {
    // if (!productId.equals("awesomeos-virt-unlmtd-phys")) throw new SkipException("debugTesting productId="+productId);
    clienttasks.unregister(null, null, null, null);
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
    Assert.assertNotNull(pool, "SubscriptionPool with ProductId '" + productId + "' is available for subscribing.");
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool_(pool));
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertTrue(!consumedProductSubscriptions.isEmpty(), "The list of Consumed Product Subscription is NOT empty after subscribing to a pool with ProductId '" + productId + "'.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        Assert.assertEquals(productSubscription.serialNumber, entitlementCert.serialNumber, "SerialNumber of Consumed Product Subscription matches the serial number from the current entitlement certificate.");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 69 with ProductSubscription

use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.

the class ListTests method testListConsumedReportsOriginatingPoolId.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36551", "RHEL7-51328" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: list of consumed subscriptions should report the poolId from which the entitlement originated", groups = { "Tier2Tests", "blockedByBug-908671" }, enabled = true)
public // @ImplementsNitrateTest(caseId=, fromPlan=)
void testListConsumedReportsOriginatingPoolId() {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // subscribe to a randomly available pool
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    // verify the list of consumed subscriptions reports the pool.poolId
    List<ProductSubscription> consumedProductSubscriptionsFromPool = ProductSubscription.findAllInstancesWithMatchingFieldFromList("poolId", pool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
    Assert.assertNotNull(consumedProductSubscriptionsFromPool, "Successfully found the consumed subscription reporting the poolId '" + pool.poolId + "' that we just attached.");
    Assert.assertEquals(consumedProductSubscriptionsFromPool.size(), 1, "The number of consumed subscriptions reporting the poolId '" + pool.poolId + "' that we just attached.");
    Assert.assertEquals(consumedProductSubscriptionsFromPool.get(0).poolId, pool.poolId, "Redundant assertion on matching poolId between the attached subscription and the list of consumed subscriptions.");
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 70 with ProductSubscription

use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.

the class MigrationTests method testRhnMigrateClassicToRhsmWithCommaSeparatedActivationKeys.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21888", "RHEL7-51744" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "Execute migration tool rhn-migrate-classic-to-rhsm with valid comma separated keys (and a good org)", groups = { "Tier3Tests", "blockedByBug-1154375" }, enabled = true)
@ImplementsNitrateTest(caseId = 130765)
public void testRhnMigrateClassicToRhsmWithCommaSeparatedActivationKeys() throws Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.14.1-1"))
        throw new SkipException("The --activation-key option was not implemented in this version of subscription-manager.");
    // create valid activation keys
    // randomly choose a valid available pool for this key
    SubscriptionPool pool1 = getRandomListItem(availableSubscriptionPools);
    // choose an activationKey name
    String activationKeyName1 = String.format("activationKeyForOrg_%s_Pool_%s", clientOrgKey, pool1.productId);
    JSONObject jsonActivationKey1 = CandlepinTasks.createActivationKeyUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, clientOrgKey, activationKeyName1, Arrays.asList(pool1.poolId), null);
    // randomly choose a valid available pool for this key
    SubscriptionPool pool2 = getRandomListItem(availableSubscriptionPools);
    // choose an activationKey name
    String activationKeyName2 = String.format("activationKeyForOrg_%s_Pool_%s", clientOrgKey, pool2.productId);
    JSONObject jsonActivationKey2 = CandlepinTasks.createActivationKeyUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, clientOrgKey, activationKeyName2, Arrays.asList(pool2.poolId), null);
    // comma separated name
    String name = activationKeyName1 + "," + activationKeyName2;
    // register with the activation key
    if (false) {
        // debugTesting
        clienttasks.register_(null, null, clientOrgKey, null, null, null, null, null, null, null, name, null, null, null, true, null, null, null, null, null);
        clienttasks.unregister_(null, null, null, null);
    }
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 1196416 - rhn-migrate-classic-to-rhsm with --activation-key option should not prompt for destination credentials
    String bugId = "1196416";
    boolean invokeWorkaroundWhileBugIsOpen = true;
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        testRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, new ArrayList<String>(), "--activation-key=" + name + " " + "--org=" + clientOrgKey, sm_rhnUsername, sm_rhnPassword, sm_clientUsername, sm_clientPassword, clientOrgKey, null, null);
    } else
        // call RhnMigrateClassicToRhsm_Test with rhsmUsername=null and rhsmPassword=null
        // END OF WORKAROUND
        // migrate from RHN Classic to RHSM using the activation key
        testRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, new ArrayList<String>(), "--activation-key=" + name + " " + "--org=" + clientOrgKey, sm_rhnUsername, sm_rhnPassword, null, null, clientOrgKey, null, null);
    // assert that the system is consuming the pools from the activation key.
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertNotNull(ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", pool1.poolId, consumedProductSubscriptions), "Found consumed subscription from pool '" + pool1.poolId + "' after migrating with activation keys '" + name + "'.");
    Assert.assertNotNull(ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", pool2.poolId, consumedProductSubscriptions), "Found consumed subscription from pool '" + pool2.poolId + "' after migrating with activation keys '" + name + "'.");
    int expectedNumberOfConsumedSubscription = 2;
    if (activationKeyName1.equals(activationKeyName2))
        expectedNumberOfConsumedSubscription = 1;
    Assert.assertEquals(consumedProductSubscriptions.size(), expectedNumberOfConsumedSubscription, "Number of consumed subscriptions after migrating from RHN Classic to RHSM with activation key '" + name + "'.");
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Aggregations

ProductSubscription (rhsm.data.ProductSubscription)90 Test (org.testng.annotations.Test)82 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)72 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)56 SkipException (org.testng.SkipException)46 ArrayList (java.util.ArrayList)41 SubscriptionPool (rhsm.data.SubscriptionPool)38 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)31 JSONObject (org.json.JSONObject)31 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)23 HashMap (java.util.HashMap)22 BigInteger (java.math.BigInteger)20 EntitlementCert (rhsm.data.EntitlementCert)17 InstalledProduct (rhsm.data.InstalledProduct)16 Calendar (java.util.Calendar)15 JSONArray (org.json.JSONArray)13 File (java.io.File)10 GregorianCalendar (java.util.GregorianCalendar)10 HashSet (java.util.HashSet)6 ConsumerCert (rhsm.data.ConsumerCert)6