Search in sources :

Example 71 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class BashCompletionTests method testBashCompletion.

// Test Methods ***********************************************************************
@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19942", "RHEL7-68140" }, 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 = "Tier1")
@Test(description = "when subscription-manager is run with no args, it should default to the help report", groups = { "Tier1Tests" }, dataProvider = "BashCompletionData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testBashCompletion(Object bugzilla, String bashCommand, Set<String> expectedCompletions) {
    // inspired by https://github.com/lacostej/unity3d-bash-completion/blob/master/lib/completion.py
    List<String> program_args = Arrays.asList(bashCommand.split("\\s+"));
    String program = program_args.get(0);
    List<String> args = program_args.subList(1, program_args.size());
    String COMP_LINE = bashCommand;
    String COMP_WORDS = COMP_LINE.trim();
    Integer COMP_CWORD = args.size();
    Integer COMP_POINT = COMP_LINE.length();
    if (COMP_LINE.endsWith(" ")) {
        COMP_WORDS += " ";
        COMP_CWORD += 1;
    }
    // String script = "bash -i -c 'COMP_LINE=\"subscription-manager attach --\" COMP_WORDS=(subscription-manager attach --) COMP_CWORD=2 COMP_POINT=30; $(complete -p subscription-manager | sed \"s/.*-F \\([^ ]*\\) .*/\\1/\") && echo ${COMPREPLY[*]}'";
    String script = String.format("bash -i -c 'COMP_LINE=\"%s\" COMP_WORDS=(%s) COMP_CWORD=%d COMP_POINT=%d; $(complete -p %s | sed \"s/.*-F \\([^ ]*\\) .*/\\1/\") && echo ${COMPREPLY[*]}'", COMP_LINE, COMP_WORDS, COMP_CWORD, COMP_POINT, program);
    SSHCommandResult result = client.runCommandAndWait(script);
    // IGNORE: Stderr:
    // bash: cannot set terminal process group (-1): Invalid argument
    // bash: no job control in this shell
    log.info(result.toString());
    Set<String> actualCompletions = new HashSet<String>(Arrays.asList(result.getStdout().trim().split("\\s+")));
    // assert all of the expectedOptions were found and that no unexpectedOptions were found
    for (String expectedCompletion : expectedCompletions) {
        if (!actualCompletions.contains(expectedCompletion)) {
            log.warning("Was not presented with the expected bash-completion '" + expectedCompletion + "' for command '" + bashCommand + "'.");
        } else {
            Assert.assertTrue(actualCompletions.contains(expectedCompletion), "The expected command '" + bashCommand + "' option '" + expectedCompletion + "' is available.");
        }
    }
    for (String actualCompletion : actualCompletions) {
        if (!expectedCompletions.contains(actualCompletion))
            log.warning("Was presented with an unexpected bash-completion '" + actualCompletion + "' for command '" + bashCommand + "'.");
    }
    // PERMANENT WORKAROUND FOR CLOSED/WONTFIX Bug 1004402 - rhsmd and rhsmcertd-worker does not bash complete its options
    if ((bashCommand.startsWith("/usr/libexec/rhsmcertd-worker ") || bashCommand.startsWith("/usr/libexec/rhsmd ")) && !actualCompletions.containsAll(expectedCompletions)) {
        String bugId = "1004402";
        try {
            if (!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 {
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        throw new SkipException("Bash completion for '" + bashCommand + "' is broken and bug '" + bugId + "' was CLOSED/WONTFIX.");
    }
    // PERMANENT WORKAROUND
    if ((bashCommand.equals("rct stat-cert -")) && actualCompletions.contains("--no-content") && !expectedCompletions.contains("--no-content")) {
        if (clienttasks.isPackageVersion("subscription-manager", "<", "1.18.2-1")) {
            // commit ac70fc3a50e172030c042bd5f18d78256c56470c // 1374389: rm --no-content from stat-cert completion
            throw new SkipException("Bash completion for '" + bashCommand + "' is broken in this version of subscription-manager '" + clienttasks.installedPackageVersionMap.get("subscription-manager") + "' and was not fixed until subscription-manager-1.18.2-1 by Bug 1374389.");
        }
    }
    // END OF WORKAROUND
    Assert.assertTrue(actualCompletions.containsAll(expectedCompletions), "All of the expected bash-completions for command '" + bashCommand + "' were presented.");
    Assert.assertTrue(expectedCompletions.containsAll(actualCompletions), "All of the presented bash-completions for command '" + bashCommand + "' were expected.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) HashSet(java.util.HashSet) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 72 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class BrandingTests method testBrandbotShouldHandleNonExistantBrandingFile.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL7-51313" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@// Brandbot SHOULD handle /var/lib/rhsm/branded_name not existing.
Test(// Brandbot SHOULD handle /var/lib/rhsm/branded_name not existing.
description = "assert that brandbot does nothing when the brand file is removed", groups = { "Tier2Tests" }, enabled = true)
public void testBrandbotShouldHandleNonExistantBrandingFile() {
    // initscripts-9.49.17-1.el7
    if (Integer.valueOf(clienttasks.redhatReleaseX) < 7)
        throw new SkipException("Brandbot is an initscripts tool feature of Flexible Branding in RHEL7.");
    // > If /var/lib/rhsm/branded_name is removed, what should PRETTY_NAME be? In
    // > initscripts-9.49.11-1.el7.x86_64 it retains its prior value before the
    // > branded_name was removed.  I don't know if that is correct.
    // 
    // (The answer is likely 'whatever PM wants to happen'. But aside from that...)
    // Bill
    String actualBrandName, actualPrettyName;
    log.info("Testing a single line branding to make sure PRETTY_NAME exists before testing the non-existant branding file...");
    // before echo to avoid tail -f /var/log/messages | grep brandbot...   systemd: brandbot.service start request repeated too quickly, refusing to start.
    sleep(5000);
    RemoteFileTasks.runCommandAndAssert(client, "echo 'RHEL Branded OS' > " + brandingFile, 0);
    actualBrandName = getCurrentBrandName();
    Assert.assertEquals(actualBrandName, "RHEL Branded OS", "The brand name contained within the first line of the brand file '" + brandingFile + "'.");
    actualPrettyName = getCurrentPrettyName();
    Assert.assertEquals(actualPrettyName, "RHEL Branded OS", "The PRETTY_NAME contained within the os-release file '" + osReleaseFile + "'.");
    log.info("Testing a non-existant branding file...");
    // before echo to avoid tail -f /var/log/messages | grep brandbot...   systemd: brandbot.service start request repeated too quickly, refusing to start.
    sleep(5000);
    RemoteFileTasks.runCommandAndAssert(client, "rm -f " + brandingFile, 0);
    Assert.assertTrue(!RemoteFileTasks.testExists(client, brandingFile), "The brand file '" + brandingFile + "' should not exist for this test.");
    actualBrandName = getCurrentBrandName();
    Assert.assertNull(actualBrandName, "The brand name is not defined when the brand file '" + brandingFile + "' does not exist.");
    Assert.assertEquals(getCurrentPrettyName(), actualPrettyName, "The PRETTY_NAME contained within the os-release file '" + osReleaseFile + "' (should remain unchanged when the brand file is removed).");
}
Also used : SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 73 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class BrandingTests method testAttachSubscriptionsForFlexibleBranding.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19955", "RHEL7-51004" }, 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 = "Tier1")
@Test(description = "incrementally attach all available subscriptions and verify tests for Flexible Branding", groups = { "Tier1Tests", "AttachSubscriptionsForFlexibleBranding_Test", "blockedByBug-884290" }, priority = 100, enabled = true)
public void testAttachSubscriptionsForFlexibleBranding() throws JSONException, Exception {
    // register
    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, null);
    // we will start out by removing the current brand name.
    // before echo to avoid tail -f /var/log/messages | grep brandbot...   systemd: brandbot.service start request repeated too quickly, refusing to start.
    sleep(5000);
    client.runCommandAndWait("rm -f " + brandingFile);
    // choose subscription pools for FlexibleBranded tests from among the available subscription pools
    List<SubscriptionPool> subscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    SubscriptionPool brandedSubscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", brandedSubscriptionProductId, subscriptionPools);
    // randomly reduce the number of subscriptionPools tested
    subscriptionPools = getRandomSubsetOfList(subscriptionPools, 10);
    // include the branded subscription pool for brandedSubscriptionProductId at the head of subscriptionPools
    if (brandedSubscriptionPool != null)
        subscriptionPools.add(0, brandedSubscriptionPool);
    // loop through subscription pools and assert flexible branding tests after attaching each subscription
    boolean flexibleBrandedSubscriptionsFound = false;
    for (SubscriptionPool pool : subscriptionPools) {
        // TODO this should not matter			if (CandlepinTasks.isPoolAModifier(sm_clientUsername, sm_clientPassword, pool.poolId, sm_serverUrl)) continue; // skip modifier pools
        String brandNameBeforeSubscribing = getCurrentBrandName();
        String brandNameStatBeforeSubscribing = getCurrentBrandNameFileStat();
        String prettyNameBeforeSubscribing = getCurrentPrettyName();
        log.info("Currently, the flexible brand name prior to subscribing to pool '" + pool.subscriptionName + "' is '" + brandNameBeforeSubscribing + "'.");
        clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
        Boolean verifiedSystemsExpectedBrandedNameAfterEvent = verifySystemsExpectedBrandedNameAfterEvent(brandNameBeforeSubscribing, brandNameStatBeforeSubscribing, prettyNameBeforeSubscribing, "subscribing to pool '" + pool.subscriptionName + "'");
        if (verifiedSystemsExpectedBrandedNameAfterEvent == null) {
            // unentitle the system to clear the undefined case of multiple installed OS products
            // clienttasks.unsubscribe_(true, (BigInteger)null, null, null, null);
            testRemoveSubscriptionsForFlexibleBranding();
        } else if (verifiedSystemsExpectedBrandedNameAfterEvent)
            flexibleBrandedSubscriptionsFound = true;
    }
    // throw SkipException when no flexible branding was tested
    if (!flexibleBrandedSubscriptionsFound)
        throw new SkipException("No branding subscriptions were found among the available subscriptions that will brand one of the currently installed OS products.");
}
Also used : SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 74 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class BrandingTests method testRemoveSubscriptionsForFlexibleBranding.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19956", "RHEL7-51005" }, 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 = "Tier1")
@Test(description = "incrementally remove attached subscriptions and verify tests for Flexible Branding", // depend on priority instead of dependsOnMethods={"testAttachSubscriptionsForFlexibleBranding"},
priority = 101, groups = { "Tier1Tests" }, enabled = true)
public void testRemoveSubscriptionsForFlexibleBranding() {
    // loop through all the attached subscriptions and remove them while running tests for branding
    for (ProductSubscription productSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
        String brandNameBeforeUnsubscribing = getCurrentBrandName();
        String brandNameStatBeforeUnsubscribing = getCurrentBrandNameFileStat();
        String prettyNameBeforeUnsubscribing = getCurrentPrettyName();
        log.info("The flexible brand name prior to unsubscribing from subscription '" + productSubscription.productName + "' is currently '" + brandNameBeforeUnsubscribing + "'.");
        clienttasks.unsubscribe_(null, productSubscription.serialNumber, null, null, null, null, null);
        verifySystemsExpectedBrandedNameAfterEvent(brandNameBeforeUnsubscribing, brandNameStatBeforeUnsubscribing, prettyNameBeforeUnsubscribing, "unsubscribing from '" + productSubscription.productName + "'");
    }
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 75 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class BrandingTests method testBrandbotShouldHandleEmptyBrandingFile.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36538", "RHEL7-51311" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@// Brandbot SHOULD handle /var/lib/rhsm/branded_name being empty.
Test(// Brandbot SHOULD handle /var/lib/rhsm/branded_name being empty.
description = "assert that brandbot removes PRETTY_NAME when the first line of the branding file is empty", groups = { "Tier2Tests", "blockedByBug-1031490" }, enabled = true)
public void testBrandbotShouldHandleEmptyBrandingFile() {
    // initscripts-9.49.17-1.el7
    if (Integer.valueOf(clienttasks.redhatReleaseX) < 7)
        throw new SkipException("Brandbot is an initscripts tool feature of Flexible Branding in RHEL7.");
    // > If /var/lib/rhsm/branded_name is an empty file, what should PRETTY_NAME
    // > be?  In initscripts-9.49.11-1.el7.x86_64 PRETTY_NAME is removed from
    // > /etc/os-release.  I think it should be PRETTY_NAME = "".
    // >
    // > What is the consequence of PRETTY_NAME missing from /etc/os-release?
    // 
    // Logical behaviors would be:
    // 
    // 1) removing PRETTY_NAME
    // 2) reverting it to the unbranded name
    // 
    // Since we don't (AFAIK) have the data to do #2, #1 makes sense to me.
    // 
    // Bill
    String messagesLogMarker = System.currentTimeMillis() + " Testing BrandbotShouldHandleEmptyBrandingFile_Test...";
    RemoteFileTasks.markFile(client, clienttasks.messagesLogFile, messagesLogMarker);
    String actualBrandName, actualPrettyName;
    log.info("Testing an empty branding file...");
    // Note: If /var/lib/rhsm/branded_name is written too quickly, this will be found in the rhsm.log...
    // Jul 10 11:42:39 jsefler-rhel7 systemd: start request repeated too quickly for brandbot.service
    // Jul 10 11:42:39 jsefler-rhel7 systemd: brandbot.service failed.
    // will help avoid  systemd: brandbot.service start request repeated too quickly, refusing to start.
    sleep(5000);
    // RemoteFileTasks.runCommandAndAssert(client, "rm -f "+brandingFile+" && touch "+brandingFile, 0);
    RemoteFileTasks.runCommandAndAssert(client, "truncate --size=0 " + brandingFile, 0);
    actualBrandName = getCurrentBrandName();
    Assert.assertEquals(actualBrandName, "", "The brand name contained within the first line of the brand file '" + brandingFile + "' (should be an empty string).");
    // debugTesting the following loop will force /var/log/messages systemd: start request repeated too quickly for brandbot.service
    // for(int i=0; i<6; i++) RemoteFileTasks.runCommandAndAssert(client, "echo `date` >> "+brandingFile, 0);
    actualPrettyName = getCurrentPrettyName();
    if (actualPrettyName != null) {
        // most likely... systemd: start request repeated too quickly for brandbot.service
        String rhsmLogStatement = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.messagesLogFile, messagesLogMarker, "brandbot").trim();
        if (!rhsmLogStatement.isEmpty())
            log.warning(rhsmLogStatement);
    }
    Assert.assertNull(actualPrettyName, "The PRETTY_NAME contained within the os-release file '" + osReleaseFile + "' (should NOT be present when the brand file is empty).");
    log.info("Testing a non-empty branding file, but the first line is empty...");
    // Note: If /var/lib/rhsm/branded_name is written too quickly, this will be found in the rhsm.log...
    // Jul 10 11:42:39 jsefler-rhel7 systemd: start request repeated too quickly for brandbot.service
    // Jul 10 11:42:39 jsefler-rhel7 systemd: brandbot.service failed.
    // will help avoid  systemd: brandbot.service start request repeated too quickly, refusing to start.
    sleep(5000);
    RemoteFileTasks.runCommandAndAssert(client, "echo '' >> " + brandingFile, 0);
    sleep(5000);
    RemoteFileTasks.runCommandAndAssert(client, "echo 'RHEL SubBranded OS (second line)' >> " + brandingFile, 0);
    actualBrandName = getCurrentBrandName();
    Assert.assertEquals(actualBrandName, "", "The brand name contained within the first line of the brand file '" + brandingFile + "' (should be an empty string).");
    actualPrettyName = getCurrentPrettyName();
    if (actualPrettyName != null) {
        // most likely... systemd: start request repeated too quickly for brandbot.service
        String rhsmLogStatement = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.messagesLogFile, messagesLogMarker, "brandbot").trim();
        if (!rhsmLogStatement.isEmpty())
            log.warning(rhsmLogStatement);
    }
    Assert.assertNull(actualPrettyName, "The PRETTY_NAME contained within the os-release file '" + osReleaseFile + "' (should NOT be present when the first line of the brand file is empty).");
}
Also used : SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)687 Test (org.testng.annotations.Test)687 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)401 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)366 SkipException (org.testng.SkipException)328 ArrayList (java.util.ArrayList)144 SubscriptionPool (rhsm.data.SubscriptionPool)137 JSONObject (org.json.JSONObject)95 BigInteger (java.math.BigInteger)90 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)88 HashMap (java.util.HashMap)78 File (java.io.File)74 ProductSubscription (rhsm.data.ProductSubscription)72 InstalledProduct (rhsm.data.InstalledProduct)66 EntitlementCert (rhsm.data.EntitlementCert)58 ProductCert (rhsm.data.ProductCert)54 YumRepo (rhsm.data.YumRepo)34 Repo (rhsm.data.Repo)26 Calendar (java.util.Calendar)25 List (java.util.List)24