コード例 #1
0
ファイル: GeneralTests.java プロジェクト: kbidarkar/rhsm-qe
 @Test(
     description = "subscription-manager-cli: attempt to access functionality that does not exist",
     groups = {},
     dataProvider = "NegativeFunctionalityData")
 public void AttemptingCommandsThatAreInvalid_Test(
     Object blockedByBug,
     String command,
     Integer expectedExitCode,
     String expectedStdout,
     String expectedStderr) {
   log.info(
       "Testing subscription-manager-cli command that is invalid, expecting it to fail: "
           + command);
   SSHCommandResult result = client.runCommandAndWait(command);
   if (expectedExitCode != null)
     Assert.assertEquals(result.getExitCode(), expectedExitCode, "The expected exit code.");
   if (expectedStdout != null)
     Assert.assertEquals(
         result.getStdout().trim(), expectedStdout, "The expected stdout message.");
   if (expectedStderr != null)
     Assert.assertEquals(
         result.getStderr().trim(), expectedStderr, "The expected stderr message.");
 }
コード例 #2
0
ファイル: GeneralTests.java プロジェクト: kbidarkar/rhsm-qe
  @Test(
      description = "assert the exit code from service rhsmcertd status when running and stopped",
      groups = {"AcceptanceTests", "blockedByBug-913118", "blockedByBug-912707"})
  protected void verifyRhsmcertdDoesNotThrowDeprecationWarnings_Test()
      throws JSONException, Exception {
    clienttasks.unregister(null, null, null);
    String marker =
        System.currentTimeMillis()
            + " Testing verifyRhsmcertdDoesNotThrowDeprecationWarnings_Test...";
    RemoteFileTasks.markFile(client, clienttasks.varLogMessagesFile, marker);

    String command = clienttasks.rhsmComplianceD + " -s";
    SSHCommandResult result = client.runCommandAndWait(command);
    Assert.assertEquals(
        result.getExitCode(), Integer.valueOf(0), "ExitCode from command '" + command + "'.");
    Assert.assertTrue(
        result.getStdout().isEmpty(), "Stdout from command '" + command + "' is empty.");
    Assert.assertTrue(
        result.getStderr().isEmpty(), "Stderr from command '" + command + "' is empty.");

    String rhsmcertdLogResult =
        RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.varLogMessagesFile, marker, null)
            .trim();
    String expectedMessage =
        "In order for Subscription Manager to provide your system with updates, your system must be registered with the Customer Portal. Please enter your Red Hat login to ensure your system is up-to-date.";
    Assert.assertTrue(
        rhsmcertdLogResult.contains(expectedMessage),
        "Syslog contains expected message '" + expectedMessage + "'.");
    String unexpectedMessage = "DeprecationWarning";
    Assert.assertTrue(
        !rhsmcertdLogResult.contains(unexpectedMessage),
        "Syslog does not contain message '" + unexpectedMessage + "'.");

    clienttasks.register(
        sm_clientUsername,
        sm_clientPassword,
        sm_clientOrg,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        (List<String>) null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null);
    /*
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    if (pools.isEmpty()) throw new SkipException("Cannot randomly pick a pool for subscribing when there are no available pools for testing.");
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size())); // randomly pick a pool
    clienttasks.subscribe(null,null,pool.poolId,null,null,null,null,null,null,null,null);
    */
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    // TODO: I can only seem to reproduce the error after consuming an entitlement from stage -
    // don't know why - maybe it requires an entitlement with a warning period - let's just
    // subscribe to all the pools.
    result = client.runCommandAndWait(command);
    //	[root@rhsm-accept-rhel5 ~]# /usr/libexec/rhsmd -s
    //	/usr/lib64/python2.4/site-packages/rhsm/certificate.py:123: DeprecationWarning: Call to
    // deprecated function: hasNow
    //	  category=DeprecationWarning)
    //	[root@rhsm-accept-rhel5 ~]#
    Assert.assertEquals(
        result.getExitCode(), Integer.valueOf(0), "ExitCode from command '" + command + "'.");
    Assert.assertTrue(
        result.getStdout().isEmpty(), "Stdout from command '" + command + "' is empty.");
    Assert.assertTrue(
        result.getStderr().isEmpty(), "Stderr from command '" + command + "' is empty.");
  }
コード例 #3
0
ファイル: StackingTests.java プロジェクト: kbidarkar/rhsm-qe
  @Test(
      description =
          "subscription-manager: subscribe to each pool with the same stacking_id to achieve compliance",
      enabled = true,
      groups = {
        "AcceptanceTests",
        "blockedByBug-739671",
        "blockedByBug-740377",
        "blockedByBug-861993",
        "blockedByBug-955142"
      },
      dataProvider = "getAvailableStackableAttributeSubscriptionPoolsData")
  // @ImplementsNitrateTest(caseId=)
  public void StackEachPoolToAchieveAttributeCompliance_Test(
      Object bugzilla, String attribute, List<SubscriptionPool> stackableAttributeSubscriptionPools)
      throws JSONException, Exception {

    // The strategy in this test is to simulate the facts on the systems so that the attribute being
    // tested ("cores","ram",or "sockets")
    // will achieve full compliance for all of the provided products after attaching a quantity of
    // one entitlement
    // from each pool in the list of stackable subscription pools.  As wee incrementally attach from
    // each pool, we will assert
    // a partial compliance until the final subscription is attached which should achieve full
    // compliance.

    // loop through the pools to determine the minimum attribute count for which one
    // of each stackable pool is needed to achieve compliance of the provided products
    // also keep a list of all the provided productIds
    Integer minimumAttributeValue = 0;
    Integer minimumSocketsValue = 0;
    Set<String> productIdsProvidedForByAllStackableSubscriptionPools = new HashSet<String>();
    Map<String, Integer> poolProductAttributeValueMap = new HashMap<String, Integer>();
    for (SubscriptionPool pool : stackableAttributeSubscriptionPools) {
      String attributeValue =
          CandlepinTasks.getPoolProductAttributeValue(
              sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, attribute);
      productIdsProvidedForByAllStackableSubscriptionPools.addAll(
          CandlepinTasks.getPoolProvidedProductIds(
              sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId));
      minimumAttributeValue += Integer.valueOf(attributeValue);
      poolProductAttributeValueMap.put(pool.poolId, Integer.valueOf(attributeValue));
    }

    // override the system facts setting the attribute count to a value for which all the stackable
    // subscriptions are needed to achieve compliance
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("memory.memtotal", "1");
    factsMap.put("cpu.cpu_socket(s)", "1");
    factsMap.put("cpu.core(s)_per_socket", "1");
    if (attribute.equals("ram")) {
      factsMap.put(
          "memory.memtotal",
          String.valueOf(
              minimumAttributeValue
                  * 1048576)); // "memory.memtotal" is stored in Kilobytes; "ram" is specified in
                               // Gigabytes; for conversions, see
                               // http://www.whatsabyte.com/P1/byteconverter.htm
    }
    if (attribute.equals("sockets")) {
      factsMap.put("cpu.cpu_socket(s)", String.valueOf(minimumAttributeValue));
    }
    if (attribute.equals("cores")) {
      if (Integer.valueOf(minimumAttributeValue) % 2
          == 0) { // configure facts for an even number of cores
        factsMap.put("cpu.core(s)_per_socket", "2");
        minimumSocketsValue = Integer.valueOf(minimumAttributeValue) / 2;
        factsMap.put("cpu.cpu_socket(s)", String.valueOf(minimumSocketsValue));
      } else { // configure facts for an odd number of cores
        factsMap.put("cpu.core(s)_per_socket", "1");
        minimumSocketsValue = Integer.valueOf(minimumAttributeValue);
        factsMap.put("cpu.cpu_socket(s)", String.valueOf(minimumSocketsValue));
      }
    }
    clienttasks.createFactsFileWithOverridingValues(factsMap);

    // register the system which has now been instrumented with facts to test the stack
    clienttasks.register(
        sm_clientUsername,
        sm_clientPassword,
        sm_clientOrg,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        (List<String>) null,
        null,
        null,
        null,
        true,
        false,
        null,
        null,
        null);

    // assert installed product status for all the products that the stacked subscriptions will
    // provide for
    List<InstalledProduct> currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
    for (String productId : productIdsProvidedForByAllStackableSubscriptionPools) {
      List<InstalledProduct> installedProducts =
          InstalledProduct.findAllInstancesWithMatchingFieldFromList(
              "productId", productId, currentlyInstalledProducts);
      if (installedProducts.isEmpty()) continue; // this productIdProvidedFor is not installed
      if (installedProducts.size() > 1)
        Assert.fail(
            "Something is seriously wrong.  Found multiple InstalledProduct "
                + installedProducts
                + " with a common productId '"
                + productId
                + "'."); // this should be impossible because the would all share the same
                         // /etc/pki/product/<productId>.pem file name
      InstalledProduct installedProduct = installedProducts.get(0);
      List<String> expectedStatusDetails =
          Arrays.asList(new String[] {"Not covered by a valid subscription."});
      Assert.assertEquals(
          installedProduct.status,
          "Not Subscribed",
          "Prior to subscribing to any of the stackable subscription pools, Installed product '"
              + installedProduct.productName
              + "' which is provided for by the subscription stack should have this status.");
      if (installedProduct.statusDetails.isEmpty())
        log.warning("Status Details appears empty.  Is your candlepin server older than 0.8.6?");
      Assert.assertEquals(
          installedProduct.statusDetails,
          expectedStatusDetails,
          "Prior to subscribing to any of the stackable subscription pools, Installed product '"
              + installedProduct.productName
              + "' which is provided for by the subscription stack should have these status details: "
              + expectedStatusDetails);
      // Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails),"Prior to subscribing to any of the stackable subscription pools, Installed product '"+installedProduct.productName+"' which is provided for by the subscription stack should have these status details: "+expectedStatusDetails);
    }

    // incrementally attach one entitlement from each pool in the stack asserting the installed
    // product's status and details along the way
    // the final attachment should achieve full compliance for the provided products in the stack
    int s = 0;
    Integer attributeValueStackedThusFar = 0;
    Integer socketsValueStackedThusFar = 0;
    Set<String> productIdsProvidedForThusFar = new HashSet<String>();
    for (SubscriptionPool pool : stackableAttributeSubscriptionPools) {
      clienttasks.subscribe(
          null, null, pool.poolId, null, null, null, null, null, null, null, null);

      // add some test coverage for bugs 861993 and 955142
      EntitlementCert entitlementCert =
          clienttasks.getEntitlementCertCorrespondingToSubscribedPool(pool);
      if (attribute.equals("ram")) {
        Assert.assertEquals(
            entitlementCert.orderNamespace.ramLimit,
            poolProductAttributeValueMap.get(pool.poolId).toString(),
            "rct cat-cert tool reports the expected RAM Limit value in the Order for subscription '"
                + pool.subscriptionName
                + "'.");
      }
      if (attribute.equals("sockets")) {
        Assert.assertEquals(
            entitlementCert.orderNamespace.socketLimit,
            poolProductAttributeValueMap.get(pool.poolId).toString(),
            "rct cat-cert tool reports the expected Socket Limit value in the Order for subscription '"
                + pool.subscriptionName
                + "'.");
      }
      if (attribute.equals("cores")) {
        Assert.assertEquals(
            entitlementCert.orderNamespace.coreLimit,
            poolProductAttributeValueMap.get(pool.poolId).toString(),
            "rct cat-cert tool reports the expected Core Limit value in the Order for subscription '"
                + pool.subscriptionName
                + "'.");
      }

      // keep a running total of how much of the stackable attribute our entitlements have covered
      // thus far
      attributeValueStackedThusFar += poolProductAttributeValueMap.get(pool.poolId);

      // special case: when testing cores, we also need to track the sockets stacked thus far since
      // the subscription may potentially includes a sockets attribute too
      if (attribute.equals("cores")) {
        String socketsValue =
            CandlepinTasks.getPoolProductAttributeValue(
                sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "sockets");
        if (socketsValue != null) {
          socketsValueStackedThusFar += Integer.valueOf(socketsValue);
        }
      }

      // keep a running set of which productIdsProvidedFor have been covered by the subscriptions
      // thus far
      productIdsProvidedForThusFar.addAll(
          CandlepinTasks.getPoolProvidedProductIds(
              sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId));

      if (++s
          < stackableAttributeSubscriptionPools
              .size()) { // are we still indexing through each pool in the stack (therefore
                         // partially compliant)?

        // assert the installed products that have been provided for by the stack of subscriptions
        // thus far are Partially Subscribed
        for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
          if (productIdsProvidedForThusFar.contains(installedProduct.productId)) {
            List<String> expectedStatusDetails = new ArrayList<String>();
            if (attribute.equals("ram")) {
              expectedStatusDetails.add(
                  String.format(
                      "Only covers %sGB of %sGB of RAM.",
                      attributeValueStackedThusFar, minimumAttributeValue));
            }
            if (attribute.equals("sockets")) {
              expectedStatusDetails.add(
                  String.format(
                      "Only covers %s of %s sockets.",
                      attributeValueStackedThusFar, minimumAttributeValue));
            }
            if (attribute.equals("cores")) {
              expectedStatusDetails.add(
                  String.format(
                      "Only covers %s of %s cores.",
                      attributeValueStackedThusFar, minimumAttributeValue));
            }
            if (attribute.equals("cores")
                && socketsValueStackedThusFar > 0
                && socketsValueStackedThusFar
                    < minimumSocketsValue) { // when a cores stack also includes sockets, we will
                                             // have more status details
              expectedStatusDetails.add(
                  String.format(
                      "Only covers %s of %s sockets.",
                      socketsValueStackedThusFar, minimumSocketsValue));
            }
            if (installedProduct.statusDetails.isEmpty())
              log.warning(
                  "Status Details appears empty.  Is your candlepin server older than 0.8.6?");
            Assert.assertEquals(
                installedProduct.status,
                "Partially Subscribed",
                "After an incremental attachment of one stackable subscription for '"
                    + pool.subscriptionName
                    + "' poolId="
                    + pool.poolId
                    + ", Installed product '"
                    + installedProduct.productName
                    + "' which is provided for by the subscription stack should have this status.");
            Assert.assertTrue(
                isEqualNoOrder(installedProduct.statusDetails, expectedStatusDetails),
                "After an incremental attachment of one stackable subscription for '"
                    + pool.subscriptionName
                    + "' poolId="
                    + pool.poolId
                    + ", Installed product '"
                    + installedProduct.productName
                    + "' which is provided for by the subscription stack should have these status details: "
                    + expectedStatusDetails);

          } else {
            if (productIdsProvidedForByAllStackableSubscriptionPools.contains(
                installedProduct.productId)) {
              List<String> expectedStatusDetails =
                  Arrays.asList(new String[] {"Not covered by a valid subscription."});
              if (installedProduct.statusDetails.isEmpty())
                log.warning(
                    "Status Details appears empty.  Is your candlepin server older than 0.8.6?");
              Assert.assertEquals(
                  installedProduct.status,
                  "Not Subscribed",
                  "After an incremental attachment of one stackable subscription for '"
                      + pool.subscriptionName
                      + "' poolId="
                      + pool.poolId
                      + ", Installed product '"
                      + installedProduct.productName
                      + "' which is NOT YET provided for by the subscription stack THUS FAR should have this status.");
              Assert.assertEquals(
                  installedProduct.statusDetails,
                  expectedStatusDetails,
                  "After an incremental attachment of one stackable subscription for '"
                      + pool.subscriptionName
                      + "' poolId="
                      + pool.poolId
                      + ", Installed product '"
                      + installedProduct.productName
                      + "' which is NOT YET provided for by the subscription stack THUS FAR should have these status details: "
                      + expectedStatusDetails);
              // Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails), "After an incremental attachment of one stackable subscription for '"+pool.subscriptionName+"' poolId="+pool.poolId+", Installed product '"+installedProduct.productName+"' which is NOT YET provided for by the subscription stack THUS FAR should have these status details: "+expectedStatusDetails);
            } else {
              /* These asserts are valid, but not really relevant to this test.  Commented out to reduce noisy logging.
              List<String> expectedStatusDetails = Arrays.asList(new String[]{"Not covered by a valid subscription."});
              Assert.assertEquals(installedProduct.status,"Not Subscribed","After subscribing to stackable subscription for '"+pool.subscriptionName+"' poolId="+pool.poolId+", Installed product '"+installedProduct.productName+"' which is NOT provided for by the subscription stack should have this status.");
              Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails), "After subscribing to stackable subscription for '"+pool.subscriptionName+"' poolId="+pool.poolId+", Installed product '"+installedProduct.productName+"' which is NOT provided for by the subscription stack should have these status details: "+expectedStatusDetails);
              */
            }
          }
        }
      } else { // we have now attached the final entitlement (each pool in the stack has been
               // subscribed)

        // assert all of the installed products provided for by the subscription stack are now fully
        // Subscribed
        for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
          if (productIdsProvidedForByAllStackableSubscriptionPools.contains(
              installedProduct.productId)) {

            // special case: when sockets are also stacked with cores, we will have more status
            // details and may not yet have met socket compliance
            if (attribute.equals("cores")
                && socketsValueStackedThusFar > 0
                && socketsValueStackedThusFar < minimumSocketsValue) {
              List<String> expectedStatusDetails =
                  Arrays.asList(
                      new String[] {
                        String.format(
                            "Only covers %s of %s sockets.",
                            socketsValueStackedThusFar, minimumSocketsValue)
                      });
              if (installedProduct.statusDetails.isEmpty())
                log.warning(
                    "Status Details appears empty.  Is your candlepin server older than 0.8.6?");
              Assert.assertEquals(
                  installedProduct.status,
                  "Partially Subscribed",
                  "After attaching the final stackable subscription for '"
                      + pool.subscriptionName
                      + "' poolId="
                      + pool.poolId
                      + ", all system cores should be covered excepty sockets for Installed product '"
                      + installedProduct.productName
                      + "'.");
              Assert.assertEquals(
                  installedProduct.statusDetails,
                  expectedStatusDetails,
                  "After attaching the final stackable subscription for '"
                      + pool.subscriptionName
                      + "' poolId="
                      + pool.poolId
                      + ", all system cores should be covered except sockets for Installed product '"
                      + installedProduct.productName
                      + "'.  Expecting status details: "
                      + expectedStatusDetails);
              // Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails), "After subscribing to stackable subscription pool '"+pool.subscriptionName+"' id="+pool.poolId+", All system cores should be covered, but not the sockets for Installed product '"+installedProduct.productName+"'.  Expecting status details: "+expectedStatusDetails);
            } else {

              // assert this installed product is now fully subscribed
              Assert.assertEquals(
                  installedProduct.status,
                  "Subscribed",
                  "After incrementally attaching the final stackable subscription for '"
                      + pool.subscriptionName
                      + "' poolId="
                      + pool.poolId
                      + ", Installed product '"
                      + installedProduct.productName
                      + "' which is provided for by the subscription stack should have this status.");
              Assert.assertTrue(
                  installedProduct.statusDetails.isEmpty(),
                  "The status details of Installed product '"
                      + installedProduct.productName
                      + "' which is fully subscribed should now be empty.");
            }
          } else {
            // installed product should be Not Subscribed since it is not affected by the consumed
            // stack of subscription
            Assert.assertEquals(
                installedProduct.status,
                "Not Subscribed",
                "The stackable subscriptions being tested do NOT provide for installed product '"
                    + installedProduct.productName
                    + "'.");
          }
        }
      }
    }
  }