Search in sources :

Example 11 with EntitlementCert

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

the class SubscriptionManagerTasks method unsubscribeFromTheCurrentlyConsumedProductSubscriptionSerialsCollectively.

/**
 * Collectively unsubscribe from all of the currently consumed product subscriptions.
 * This will ultimately issue a single call to unsubscribe --serial SERIAL1 --serial SERIAL2 --serial SERIAL3 for each of the product subscriptions being consumed.
 * @throws Exception
 */
public SSHCommandResult unsubscribeFromTheCurrentlyConsumedProductSubscriptionSerialsCollectively() throws Exception {
    log.info("Unsubscribing from all of the currently consumed product subscription serials in one collective call...");
    List<BigInteger> serials = new ArrayList<BigInteger>();
    // THIS AVOIDS PROBLEMS WHEN MODIFIER ENTITLEMENTS ARE BEING CONSUMED
    for (ProductSubscription productSubscription : getCurrentlyConsumedProductSubscriptions()) {
        EntitlementCert entitlementCert = getEntitlementCertCorrespondingToProductSubscription(productSubscription);
        JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, entitlementCert.id);
        String poolHref = jsonEntitlement.getJSONObject("pool").getString("href");
        JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, poolHref));
        String poolId = jsonPool.getString("id");
        if (CandlepinTasks.isPoolAModifier(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, poolId, candlepinUrl)) {
            // serials to entitlements that modify others should be at the front of the list to be removed, otherwise they will get re-issued under a new serial number when the modified entitlement is removed first.
            serials.add(0, productSubscription.serialNumber);
        } else {
            serials.add(productSubscription.serialNumber);
        }
    }
    // unsubscribe from all serials collectively
    SSHCommandResult result = unsubscribe(false, serials, null, null, null, null, null);
    Assert.assertTrue(getCurrentlyConsumedProductSubscriptions().size() == 0, "Currently no product subscriptions are consumed.");
    Assert.assertTrue(getCurrentEntitlementCertFiles().size() == 0, "This machine has no entitlement certificate files.");
    return result;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) JSONObject(org.json.JSONObject) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) BigInteger(java.math.BigInteger)

Example 12 with EntitlementCert

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

the class SubscriptionManagerTasks method assertEntitlementCertsInYumRepolist.

/**
 * Assert that the given entitlement certs are displayed in the stdout from "yum repolist all".
 * @param entitlementCerts
 */
public void assertEntitlementCertsInYumRepolist(List<EntitlementCert> entitlementCerts, boolean areReported) {
    // # yum repolist all
    // Loaded plugins: refresh-packagekit, rhnplugin, rhsmplugin
    // Updating Red Hat repositories.
    // This system is not registered with RHN.
    // RHN support will be disabled.
    // http://redhat.com/foo/path/never/repodata/repomd.xml: [Errno 14] HTTP Error 404 : http://www.redhat.com/foo/path/never/repodata/repomd.xml
    // Trying other mirror.
    // repo id                      repo name                                                      status
    // always-enabled-content       always-enabled-content                                         disabled
    // content-label                content                                                        disabled
    // never-enabled-content        never-enabled-content                                          enabled: 0
    // rhel-beta                    Red Hat Enterprise Linux 5.90Workstation Beta - x86_64         disabled
    // rhel-beta-debuginfo          Red Hat Enterprise Linux 5.90Workstation Beta - x86_64 - Debug disabled
    // rhel-beta-optional           Red Hat Enterprise Linux 5.90Workstation Beta (Optional) - x86 disabled
    // rhel-beta-optional-debuginfo Red Hat Enterprise Linux 5.90Workstation Beta (Optional) - x86 disabled
    // rhel-beta-optional-source    Red Hat Enterprise Linux 5.90Workstation Beta (Optional) - x86 disabled
    // rhel-beta-source             Red Hat Enterprise Linux 5.90Workstation Beta - x86_64 - Sourc disabled
    // rhel-latest                  Latest RHEL 6                                                  enabled: 0
    // repolist: 0
    // [root@jsefler-itclient01 product]# yum repolist all
    // Loaded plugins: pidplugin, refresh-packagekit, rhnplugin, rhsmplugin
    // Updating Red Hat repositories.
    // INFO:repolib:repos updated: 0
    // This system is not registered with RHN.
    // RHN support will be disabled.
    // red-hat-enterprise-linux-6-entitlement-alpha-rpms                                                                         | 4.0 kB     00:00
    // red-hat-enterprise-linux-6-entitlement-alpha-rpms-updates                                                                 |  951 B     00:00
    // repo id                                                                        repo name                                           status
    // red-hat-enterprise-linux-6-entitlement-alpha-debug-rpms                        Red Hat Enterprise Linux 6 Entitlement Alpha (Debug disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-debug-rpms-updates                Red Hat Enterprise Linux 6 Entitlement Alpha (Debug disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-optional-debug-rpms               Red Hat Enterprise Linux 6 Entitlement Alpha - Opti disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-optional-debug-rpms-updates       Red Hat Enterprise Linux 6 Entitlement Alpha - Opti disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-optional-rpms                     Red Hat Enterprise Linux 6 Entitlement Alpha - Opti disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-optional-rpms-updates             Red Hat Enterprise Linux 6 Entitlement Alpha - Opti disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-optional-source-rpms              Red Hat Enterprise Linux 6 Entitlement Alpha - Opti disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-optional-source-rpms-updates      Red Hat Enterprise Linux 6 Entitlement Alpha - Opti disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-rpms                              Red Hat Enterprise Linux 6 Entitlement Alpha (RPMs) enabled: 3,394
    // red-hat-enterprise-linux-6-entitlement-alpha-rpms-updates                      Red Hat Enterprise Linux 6 Entitlement Alpha (RPMs) enabled:     0
    // red-hat-enterprise-linux-6-entitlement-alpha-source-rpms                       Red Hat Enterprise Linux 6 Entitlement Alpha (Sourc disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-source-rpms-updates               Red Hat Enterprise Linux 6 Entitlement Alpha (Sourc disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-supplementary-debug-rpms          Red Hat Enterprise Linux 6 Entitlement Alpha - Supp disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-supplementary-debug-rpms-updates  Red Hat Enterprise Linux 6 Entitlement Alpha - Supp disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-supplementary-rpms                Red Hat Enterprise Linux 6 Entitlement Alpha - Supp disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-supplementary-rpms-updates        Red Hat Enterprise Linux 6 Entitlement Alpha - Supp disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-supplementary-source-rpms         Red Hat Enterprise Linux 6 Entitlement Alpha - Supp disabled
    // red-hat-enterprise-linux-6-entitlement-alpha-supplementary-source-rpms-updates Red Hat Enterprise Linux 6 Entitlement Alpha - Supp disabled
    // repolist: 3,394
    List<ProductCert> currentProductCerts = this.getCurrentProductCerts();
    // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=697087 - jsefler 04/27/2011
    if (this.redhatRelease.contains("release 5")) {
        boolean invokeWorkaroundWhileBugIsOpen = true;
        String bugId = "697087";
        // 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) {
            List<String> yumRepoListAll = this.getYumRepolist("all");
            List<String> yumRepoListEnabled = this.getYumRepolist("enabled");
            List<String> yumRepoListDisabled = this.getYumRepolist("disabled");
            for (EntitlementCert entitlementCert : entitlementCerts) {
                for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
                    if (!contentNamespace.type.equalsIgnoreCase("yum"))
                        continue;
                    if (areReported && areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
                        if (contentNamespace.enabled) {
                            Assert.assertTrue(yumRepoListEnabled.contains(contentNamespace.label), "Yum repolist enabled includes repo id/label '" + contentNamespace.label + "' that comes from entitlement cert " + entitlementCert.id + "'s content namespace: " + contentNamespace);
                        } else {
                            Assert.assertTrue(yumRepoListDisabled.contains(contentNamespace.label), "Yum repolist disabled includes repo id/label '" + contentNamespace.label + "' that comes from entitlement cert " + entitlementCert.id + "'s content namespace: " + contentNamespace);
                        }
                    } else
                        Assert.assertFalse(yumRepoListAll.contains(contentNamespace.label), "Yum repolist all excludes repo id/label '" + contentNamespace.label + "'.");
                }
            }
            return;
        }
    }
    // END OF WORKAROUND
    // assert all of the entitlement certs are reported in the stdout from "yum repolist all"
    sshCommandRunner.runCommandAndWaitWithoutLogging("killall -9 yum");
    List<String> yumRepolistAll = getYumRepolist("all");
    for (EntitlementCert entitlementCert : entitlementCerts) {
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            // Note: When the repo id and repo name are really long, the repo name in the yum repolist all gets crushed (hence the reason for .* in the regex)
            boolean isReported = yumRepolistAll.contains(contentNamespace.label.trim());
            boolean areAllRequiredTagsInstalled = areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts);
            if (!contentNamespace.type.equalsIgnoreCase("yum")) {
                Assert.assertTrue(!isReported, "ContentNamespace label '" + contentNamespace.label.trim() + "' from EntitlementCert '" + entitlementCert.serialNumber + "' is NOT reported in yum repolist all since its type '" + contentNamespace.type + "' is non-yum.");
            } else if (areReported && areAllRequiredTagsInstalled) {
                Assert.assertTrue(isReported, "ContentNamespace label '" + contentNamespace.label.trim() + "' from EntitlementCert '" + entitlementCert.serialNumber + "' is reported in yum repolist all.");
            } else {
                Assert.assertTrue(!isReported, "ContentNamespace label '" + contentNamespace.label.trim() + "' from EntitlementCert '" + entitlementCert.serialNumber + "' is NOT reported in yum repolist all" + ((areReported && !areAllRequiredTagsInstalled) ? " since all its required tags '" + contentNamespace.requiredTags + "' are NOT found among the currently installed product certs." : "."));
            }
        }
    }
// assert that the sshCommandRunner.getStderr() does not contains an error on the entitlementCert.download_url e.g.: http://redhat.com/foo/path/never/repodata/repomd.xml: [Errno 14] HTTP Error 404 : http://www.redhat.com/foo/path/never/repodata/repomd.xml
// FIXME EVENTUALLY WE NEED TO UNCOMMENT THIS ASSERT
// Assert.assertContainsNoMatch(result.getStderr(), "HTTP Error \\d+", "HTTP Errors were encountered when runnning yum repolist all.");
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ProductCert(rhsm.data.ProductCert)

Example 13 with EntitlementCert

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

the class SubscriptionManagerTasks method listSubscribedRepos.

/**
 * @return SSHCommandResult from "subscription-manager repos --list"
 */
public SSHCommandResult listSubscribedRepos() {
    Calendar now = new GregorianCalendar();
    now.setTimeInMillis(System.currentTimeMillis());
    SSHCommandResult sshCommandResult = repos(true, null, null, (String) null, (String) null, null, null, null, null);
    // Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "The exit code from the repos --list command indicates a success.");
    // List<File> entitlementCertFiles = getCurrentEntitlementCertFiles();
    List<ProductCert> productCerts = getCurrentProductCerts();
    List<EntitlementCert> entitlementCerts = getCurrentEntitlementCerts();
    int numContentNamespaces = 0;
    for (EntitlementCert entitlementCert : entitlementCerts) {
        // we should NOT count contentNamespaces from entitlement certs that are not valid now
        if (entitlementCert.validityNotBefore.after(now) || entitlementCert.validityNotAfter.before(now))
            continue;
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            // we should NOT count contentNamespaces from for which all required tags are not provided by the installed product certs
            if (!areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, productCerts)) {
                log.warning("None of the currently installed product certs provide the required tags '" + contentNamespace.requiredTags + "' for entitled content namespace: " + contentNamespace.name);
                continue;
            }
            // we should NOT count contentNamespaces that are not of type=yum
            if (!contentNamespace.type.equals("yum")) {
                log.warning("Encountered the following Content Namespace whose type is not \"yum\" (it should not contribute to the list of yum repos):  " + contentNamespace);
                continue;
            }
            numContentNamespaces++;
        }
    }
    if (numContentNamespaces == 0) {
        // Assert.assertTrue(sshCommandResult.getStdout().trim().equals("The system is not entitled to use any repositories."), "The system is not entitled to use any repositories.");	// changed by bug 846834
        Assert.assertTrue(sshCommandResult.getStdout().trim().equals("This system has no repositories available through subscriptions."), "This system has no repositories available through subscriptions.");
    } else {
        String title;
        // changed by bug 846834
        title = "Entitled Repositories in " + redhatRepoFile;
        title = "Available Repositories in " + redhatRepoFile;
        Assert.assertTrue(sshCommandResult.getStdout().contains(title), "The list of repositories is entitled '" + title + "'.");
    }
    return sshCommandResult;
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ProductCert(rhsm.data.ProductCert)

Example 14 with EntitlementCert

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

the class SubscriptionManagerTasks method getCurrentEntitlementCertsWithinWarningPeriod.

// DELETEME
// /**
// * @param fieldName
// * @param fieldValue
// * @param subscriptionPools - usually getCurrentlyAvailableSubscriptionPools()
// * @return - the SubscriptionPool from subscriptionPools that has a matching field (if not found, null is returned)
// */
// public SubscriptionPool findSubscriptionPoolWithMatchingFieldFromList(String fieldName, Object fieldValue, List<SubscriptionPool> subscriptionPools) {
// 
// SubscriptionPool subscriptionPoolWithMatchingField = null;
// for (SubscriptionPool subscriptionPool : subscriptionPools) {
// try {
// if (SubscriptionPool.class.getField(fieldName).get(subscriptionPool).equals(fieldValue)) {
// subscriptionPoolWithMatchingField = subscriptionPool;
// }
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// return subscriptionPoolWithMatchingField;
// }
// 
// 
// /**
// * @param fieldName
// * @param fieldValue
// * @param productSubscriptions - usually getCurrentlyConsumedProductSubscriptions()
// * @return - the ProductSubscription from productSubscriptions that has a matching field (if not found, null is returned)
// */
// public ProductSubscription findProductSubscriptionWithMatchingFieldFromList(String fieldName, Object fieldValue, List<ProductSubscription> productSubscriptions) {
// ProductSubscription productSubscriptionWithMatchingField = null;
// for (ProductSubscription productSubscription : productSubscriptions) {
// try {
// if (ProductSubscription.class.getField(fieldName).get(productSubscription).equals(fieldValue)) {
// productSubscriptionWithMatchingField = productSubscription;
// }
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// return productSubscriptionWithMatchingField;
// }
// 
// 
// /**
// * @param fieldName
// * @param fieldValue
// * @param installedProducts - usually getCurrentProductCerts()
// * @return - the InstalledProduct from installedProducts that has a matching field (if not found, null is returned)
// */
// public InstalledProduct findInstalledProductWithMatchingFieldFromList(String fieldName, Object fieldValue, List<InstalledProduct> installedProducts) {
// InstalledProduct installedProductWithMatchingField = null;
// for (InstalledProduct installedProduct : installedProducts) {
// try {
// if (InstalledProduct.class.getField(fieldName).get(installedProduct).equals(fieldValue)) {
// installedProductWithMatchingField = installedProduct;
// }
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// return installedProductWithMatchingField;
// }
// 
// 
// /**
// * @param fieldName
// * @param fieldValue
// * @param productCerts - usually getCurrentlyProductCerts()
// * @return - the ProductCert from productCerts that has a matching field (if not found, null is returned)
// */
// public ProductCert findProductCertWithMatchingFieldFromList(String fieldName, Object fieldValue, List<ProductCert> productCerts) {
// ProductCert productCertWithMatchingField = null;
// for (ProductCert productCert : productCerts) {
// try {
// if (ProductCert.class.getField(fieldName).get(productCert).equals(fieldValue)) {
// productCertWithMatchingField = productCert;
// }
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// return productCertWithMatchingField;
// }
// 
// 
// /**
// * @param fieldName
// * @param fieldValue
// * @param entitlementCerts - usually getCurrentEntitlementCerts()
// * @return - the EntitlementCert from entitlementCerts that has a matching field (if not found, null is returned)
// */
// public EntitlementCert findEntitlementCertWithMatchingFieldFromList(String fieldName, Object fieldValue, List<EntitlementCert> entitlementCerts) {
// EntitlementCert entitlementCertWithMatchingField = null;
// for (EntitlementCert entitlementCert : entitlementCerts) {
// try {
// if (EntitlementCert.class.getField(fieldName).get(entitlementCert).equals(fieldValue)) {
// entitlementCertWithMatchingField = entitlementCert;
// }
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// return entitlementCertWithMatchingField;
// }
// KEEPME FOR FUTURE USAGE SOMEWHERE ELSE
// /**
// * Given a List of instances of some class (e.g. getCurrentEntitlementCerts()), this
// * method is useful for finding the first instance (e.g. an EntitlementCert) whose public
// * field by the name "fieldName" has a value of fieldValue.  If no match is found, null is returned.
// * @param <T>
// * @param fieldName
// * @param fieldValue
// * @param dataInstances
// * @return
// */
// @SuppressWarnings("unchecked")
// public <T> T findFirstInstanceWithMatchingFieldFromList(String fieldName, Object fieldValue, List<T> dataInstances) {
// Collection<T> dataInstancesWithMatchingFieldFromList = Collections2.filter(dataInstances, new ByValuePredicate(fieldName,fieldValue));
// if (dataInstancesWithMatchingFieldFromList.isEmpty()) return null;
// return (T) dataInstancesWithMatchingFieldFromList.toArray()[0];
// }
// 
// /**
// * Given a List of instances of some class (e.g. getAllAvailableSubscriptionPools()), this
// * method is useful for finding a subset of instances whose public field by the name "fieldName"
// * has a value of fieldValue.  If no match is found, an empty list is returned.
// * @param <T>
// * @param fieldName
// * @param fieldValue
// * @param dataInstances
// * @return
// */
// @SuppressWarnings("unchecked")
// public <T> List<T> findAllInstancesWithMatchingFieldFromList(String fieldName, Object fieldValue, List<T> dataInstances) {
// Collection<T> dataInstancesWithMatchingFieldFromList = Collections2.filter(dataInstances, new ByValuePredicate(fieldName,fieldValue));
// return (List<T>) Arrays.asList(dataInstancesWithMatchingFieldFromList.toArray());
// }
// 
// class ByValuePredicate implements Predicate<Object> {
// Object value;
// String fieldName;
// public ByValuePredicate(String fieldName, Object value) {
// this.value=value;
// this.fieldName=fieldName;
// }
// public boolean apply(Object toTest) {
// try {
// return toTest.getClass().getField(fieldName).get(toTest).equals(value);
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// return false;
// }
// }
/**
 * @return a list of the currently granted EntitlementCerts that are within the warningPeriod (days) of its endDate
 */
public List<EntitlementCert> getCurrentEntitlementCertsWithinWarningPeriod() {
    List<EntitlementCert> entitlementCertsWithinWarningPeriod = new ArrayList<EntitlementCert>();
    Calendar now = new GregorianCalendar();
    now.setTimeInMillis(System.currentTimeMillis());
    // assemble all of the current entitlementCerts that are within the warning period
    for (EntitlementCert entitlementCert : getCurrentEntitlementCerts()) {
        // find the warning period
        // assume zero
        int warningPeriod = 0;
        try {
            warningPeriod = Integer.valueOf(entitlementCert.orderNamespace.warningPeriod);
        } catch (NumberFormatException e) {
            log.warning("The OrderNamespace's warningPeriod is non-numeric or non-existing in EntitlementCert: " + entitlementCert);
        }
        // subtract the warningPeriod number of days from the endDate
        entitlementCert.orderNamespace.endDate.add(Calendar.DATE, -1 * warningPeriod);
        // check if we are now inside the warningPeriod
        if (entitlementCert.orderNamespace.endDate.before(now)) {
            entitlementCertsWithinWarningPeriod.add(entitlementCert);
        }
    }
    return entitlementCertsWithinWarningPeriod;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar)

Example 15 with EntitlementCert

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

the class SubscriptionManagerTasks method getCurrentlyExpectedReleases.

/**
 * @return list of the expected releases currently available based on the currently enabled repo content and this major RHEL release
 */
public List<String> getCurrentlyExpectedReleases() {
    HashSet<String> expectedReleaseSet = new HashSet<String>();
    String baseurl = getConfFileParameter(rhsmConfFile, "rhsm", "baseurl");
    List<ProductCert> productCerts = getCurrentProductCerts();
    // loop through all of the currently entitled repo urls
    for (EntitlementCert entitlementCert : getCurrentEntitlementCerts()) {
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (contentNamespace.type.equalsIgnoreCase("yum")) {
                if (contentNamespace.enabled) {
                    // Bug 820639 - subscription-manager release --list should exclude listings from disabled repos
                    if (areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, productCerts)) {
                        // Bug 861151 - subscription-manager release doesn't take variant into account
                        if (contentNamespace.downloadUrl.contains("$releasever")) {
                            if (contentNamespace.downloadUrl.contains("/" + redhatReleaseX + "/")) {
                                // Bug 818298 - subscription-manager release --list should not display releasever applicable to rhel-5 when only rhel-6 product is installed
                                // example contentNamespace.downloadUrl:  /content/dist/rhel/server/5/$releasever/$basearch/iso
                                String listingUrl = contentNamespace.downloadUrl.startsWith("http") ? "" : baseurl;
                                listingUrl += contentNamespace.downloadUrl.split("/\\$releasever/")[0];
                                listingUrl += "/listing";
                                String command = String.format("curl --stderr /dev/null --insecure --tlsv1 --cert %s --key %s %s", entitlementCert.file.getPath(), getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(entitlementCert.file).getPath(), listingUrl);
                                SSHCommandResult result = sshCommandRunner.runCommandAndWaitWithoutLogging(command);
                                // process exceptional results...
                                if (result.getStdout().toUpperCase().contains("<HTML>")) {
                                    // [root@jsefler-6 ~]# curl --stderr /dev/null --insecure --tlsv1 --cert /etc/pki/entitlement/3360706382464344965.pem --key /etc/pki/entitlement/3360706382464344965-key.pem https://cdn.redhat.com/content/dist/rhel/server/6/listing
                                    // <HTML><HEAD>
                                    // <TITLE>Access Denied</TITLE>
                                    // </HEAD><BODY>
                                    // <H1>Access Denied</H1>
                                    // or should this be a failure?
                                    log.warning("curl result: " + result);
                                    Assert.fail("Expected to retrieve a list of available release versions. (Example: 6.1, 6.2, 6Server)");
                                } else if (result.getStdout().trim().startsWith("Unable to locate content")) {
                                    // [root@jsefler-5 ~]# curl --stderr /dev/null --insecure --tlsv1 --cert /etc/pki/entitlement/6653190787244398414.pem --key /etc/pki/entitlement/6653190787244398414-key.pem https://cdn.qa.redhat.com/content/aus/rhel/server/5/listing
                                    // Unable to locate content /content/aus/rhel/server/5/listing
                                    // or should this be a failure?
                                    log.warning("curl result: " + result);
                                    log.warning("Query failed to get an expected release listing from ContentNamespace: \n" + contentNamespace);
                                    log.warning("After setting an older release, a yum repolist of this content set will likely yield: [Errno 14] HTTP Error 404: Not Found");
                                } else {
                                    expectedReleaseSet.addAll(Arrays.asList(result.getStdout().trim().split("\\s*\\n\\s*")));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return new ArrayList<String>(expectedReleaseSet);
// ^^ TODO On second thought, it would technically be more correct to loop over the current YumRepo object rather than the Entitlement Certs since a repo enablement could have been manually overridden
// TODO work in progress
// for (YumRepo yumRepo : getCurrentlySubscribedYumRepos()()) {
// if (yumRepo.enabled) {	// Bug 820639 - subscription-manager release --list should exclude listings from disabled repos
// if (yumRepo.baseurl.contains("$releasever")) {
// if (yumRepo.baseurl.contains("/"+redhatReleaseX+"/")) {	// Bug 818298 - subscription-manager release --list should not display releasever applicable to rhel-5 when only rhel-6 product is installed
// // example contentNamespace.downloadUrl:  /content/dist/rhel/server/5/$releasever/$basearch/iso
// String listingUrl =  yumRepo.baseurl.startsWith("http")? "":baseurl;
// listingUrl += yumRepo.baseurl.split("/\\$releasever/")[0];
// listingUrl += "/listing";
// String command = String.format("curl --stderr /dev/null --insecure --cert %s --key %s %s" , entitlementCert.file.getPath(), getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(entitlementCert.file).getPath(), listingUrl);
// SSHCommandResult result = sshCommandRunner.runCommandAndWaitWithoutLogging(command);
// //	[root@qe-blade-13 ~]# curl --stderr /dev/null --insecure --cert /etc/pki/entitlement/2013167262444796312.pem --key /etc/pki/entitlement/2013167262444796312-key.pem https://cdn.rcm-qa.redhat.com/content/dist/rhel/server/6/listing
// //	6.1
// //	6.2
// //	6Server
// expectedReleaseSet.addAll(Arrays.asList(result.getStdout().trim().split("\\s*\\n\\s*")));
// }
// }
// }
// }
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) HashSet(java.util.HashSet)

Aggregations

EntitlementCert (rhsm.data.EntitlementCert)94 Test (org.testng.annotations.Test)63 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)58 SkipException (org.testng.SkipException)39 ArrayList (java.util.ArrayList)38 File (java.io.File)36 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)35 SubscriptionPool (rhsm.data.SubscriptionPool)33 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)30 JSONObject (org.json.JSONObject)29 ContentNamespace (rhsm.data.ContentNamespace)26 ProductCert (rhsm.data.ProductCert)23 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)17 BigInteger (java.math.BigInteger)17 ProductSubscription (rhsm.data.ProductSubscription)17 List (java.util.List)16 Calendar (java.util.Calendar)11 HashMap (java.util.HashMap)11 ProductNamespace (rhsm.data.ProductNamespace)11 HashSet (java.util.HashSet)8