Search in sources :

Example 1 with SubscriptionManagerTasks

use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.

the class SubscriptionManagerCLITestScript method ensureSELinuxIsEnforcingBeforeSuite.

@BeforeSuite(groups = { "setup" }, dependsOnMethods = { "setupBeforeSuite" }, description = "Ensure SELinux is Enforcing before running the test suite.")
public void ensureSELinuxIsEnforcingBeforeSuite() {
    for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
        if (clienttasks != null) {
            // mark the audit.log file so it can be asserted for denials in verifyNoSELinuxDenialsWereLoggedAfterClass()
            RemoteFileTasks.markFile(clienttasks.sshCommandRunner, clienttasks.auditLogFile, selinuxSuiteMarker);
            // TEMPORARY WORKAROUND
            boolean invokeWorkaroundWhileBugIsOpen = true;
            // Bug 1257940 - systemd-hwdb should be confined
            String bugId = "1257940";
            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) {
                log.warning("Skipping BeforeSuite assertion that selinux is Enforcing while bug " + bugId + " is open.");
                continue;
            }
            // END OF WORKAROUND
            // TEMPORARY WORKAROUND
            invokeWorkaroundWhileBugIsOpen = true;
            // Bug 1342401 - Allow NetworkManager to create temporary /etc/resolv.conf.XXXXXX file
            bugId = "1342401";
            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) {
                log.warning("Skipping BeforeSuite assertion that selinux is Enforcing while bug " + bugId + " is open.");
                continue;
            }
            // END OF WORKAROUND
            // TEMPORARY WORKAROUND
            invokeWorkaroundWhileBugIsOpen = true;
            // Bug 1343648 - SELinux label for /etc/udev/hwdb.bin is etc_t instead of systemd_hwdb_etc_t after "#systemd-hwdb update"
            bugId = "1343648";
            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) {
                log.warning("Skipping BeforeSuite assertion that selinux is Enforcing while bug " + bugId + " is open.");
                continue;
            }
            // END OF WORKAROUND
            // TEMPORARY WORKAROUND
            invokeWorkaroundWhileBugIsOpen = true;
            // Bug 1350756 - SELinux label for /etc/udev/hwdb.bin is etc_t instead of systemd_hwdb_etc_t after "#systemd-hwdb update"
            bugId = "1350756";
            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) {
                log.warning("Skipping BeforeSuite assertion that selinux is Enforcing while bug " + bugId + " is open.");
                continue;
            }
            // END OF WORKAROUND
            // assert selinux is Enforcing
            Assert.assertEquals(clienttasks.sshCommandRunner.runCommandAndWait("getenforce").getStdout().trim(), "Enforcing", "SELinux mode is set to enforcing on client " + clienttasks.sshCommandRunner.getConnection().getRemoteHostname());
        }
    }
}
Also used : SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 2 with SubscriptionManagerTasks

use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.

the class SubscriptionManagerCLITestScript method prepareRegisteredConsumerCertsDirectoryBeforeSuite.

@BeforeSuite(groups = { "setup" }, dependsOnMethods = { "setupBeforeSuite" }, description = "Prepare a temporary consumer cert directory where we can track all of the consumers created so we can return their entitlements after the suite.")
public void prepareRegisteredConsumerCertsDirectoryBeforeSuite() {
    for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
        if (clienttasks != null) {
            // /*debugTestSSL*/ if (false)
            clienttasks.sshCommandRunner.runCommandAndWait("rm -rf " + allRegisteredConsumerCertsDir);
            clienttasks.sshCommandRunner.runCommandAndWait("mkdir -p " + allRegisteredConsumerCertsDir);
        }
    }
}
Also used : SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 3 with SubscriptionManagerTasks

use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.

the class SubscriptionManagerCLITestScript method setupBeforeSuite.

// Configuration Methods ***********************************************************************
@BeforeSuite(groups = { "setup" }, description = "subscription manager set up")
public void setupBeforeSuite() throws IOException, JSONException {
    if (isSetupBeforeSuiteComplete)
        return;
    // create SSHCommandRunners to connect to the subscription-manager clients
    File sshKeyPrivateKeyFile = new File(System.getProperty("automation.dir", null) + "/" + sm_sshKeyPrivate);
    if (!sshKeyPrivateKeyFile.exists())
        Assert.fail("Expected to find the private ssh key for automation testing at '" + sshKeyPrivateKeyFile + "'.  Ask the RHSM Automation Administrator for a copy.");
    client1 = new SSHCommandRunner(sm_client1Hostname, sm_client1SSHUser, new File(sm_sshKeyPrivate), sm_sshkeyPassphrase, null);
    if (sm_sshEmergenecyTimeoutMS != null)
        client1.setEmergencyTimeout(Long.valueOf(sm_sshEmergenecyTimeoutMS));
    client1tasks = new SubscriptionManagerTasks(client1);
    client = client1;
    clienttasks = client1tasks;
    // will we be testing multiple clients?
    if (!(sm_client2Hostname.equals(""))) {
        client2 = new SSHCommandRunner(sm_client2Hostname, sm_client2SSHUser, new File(sm_sshKeyPrivate), sm_sshkeyPassphrase, null);
        if (sm_sshEmergenecyTimeoutMS != null)
            client2.setEmergencyTimeout(Long.valueOf(sm_sshEmergenecyTimeoutMS));
        client2tasks = new SubscriptionManagerTasks(client2);
    } else {
        log.info("Multi-client testing will be skipped.");
    }
    // unregister clients in case they are still registered from prior run (DO THIS BEFORE SETTING UP A NEW CANDLEPIN)
    unregisterClientsAfterSuite();
    // Beaker test_log-Setup.log :: [   FAIL   ] :: FIPS on s390 on RHEL <7.1 is not supported (Assert: expected 0, got 1)
    if (client1 != null) {
        Assert.assertEquals(client1.runCommandAndWait("sysctl crypto.fips_enabled").getStdout().trim(), "crypto.fips_enabled = " + (sm_clientFips ? "1" : "0"), "Asserting the expected enablement of FIPS on client '" + sm_client1Hostname + "' before running any tests.");
    }
    if (client2 != null) {
        Assert.assertEquals(client2.runCommandAndWait("sysctl crypto.fips_enabled").getStdout().trim(), "crypto.fips_enabled = " + (sm_clientFips ? "1" : "0"), "Asserting the expected enablement of FIPS on client '" + sm_client2Hostname + "' before running any tests.");
    }
    List<File> generatedProductCertFiles = new ArrayList<File>();
    // can we create an SSHCommandRunner to connect to the candlepin server ?
    if (!sm_serverHostname.equals("") && sm_serverType.equals(CandlepinType.standalone)) {
        server = new SSHCommandRunner(sm_serverHostname, sm_serverSSHUser, new File(sm_sshKeyPrivate), sm_sshkeyPassphrase, null);
        if (sm_sshEmergenecyTimeoutMS != null)
            server.setEmergencyTimeout(Long.valueOf(sm_sshEmergenecyTimeoutMS));
        servertasks = new rhsm.cli.tasks.CandlepinTasks(server, sm_serverInstallDir, sm_serverImportDir, sm_serverType, sm_serverBranch, sm_dbSqlDriver, sm_dbHostname, sm_dbPort, sm_dbName, sm_dbUsername, sm_dbPassword);
    } else {
        log.info("Assuming the server is already setup and running.");
        servertasks = new rhsm.cli.tasks.CandlepinTasks(null, null, null, sm_serverType, sm_serverBranch, sm_dbSqlDriver, sm_dbHostname, sm_dbPort, sm_dbName, sm_dbUsername, sm_dbPassword);
    }
    // setup the candlepin server (only when the candlepin server is standalone)
    if (server != null && sm_serverType.equals(CandlepinType.standalone)) {
        // I suggest manually setting this on hosted and asking calfanso to restart
        if (servertasks.getConfFileParameter("pinsetter.org.fedoraproject.candlepin.pinsetter.tasks.CertificateRevocationListTask.schedule") == null) {
            servertasks.addConfFileParameter("\n# purge the CRL list every 2 min\npinsetter.org.fedoraproject.candlepin.pinsetter.tasks.CertificateRevocationListTask.schedule", "0 0/2 * * * ?");
        } else {
            // every 2 minutes
            servertasks.updateConfFileParameter("pinsetter.org.fedoraproject.candlepin.pinsetter.tasks.CertificateRevocationListTask.schedule", "0 0\\/2 * * * ?");
        }
        servertasks.cleanOutCRL();
        servertasks.deploy();
        server.runCommandAndWait("df -h");
        // log candlepin's starting disk usage (for debugging information only)
        server.runCommandAndWait("sudo " + "ls -Slh " + servertasks.getTomcatLogFile().getParent() + " | head");
        servertasks.setupTranslateToolkitFromTarUrl(sm_translateToolkitTarUrl);
        servertasks.reportAPI();
        // install packages
        SSHCommandResult yumInstallResult = server.runCommandAndWait("sudo " + "yum install -y --quiet hunspell");
        Assert.assertEquals(yumInstallResult.getExitCode(), Integer.valueOf(0), "ExitCode from yum install of packages on server '" + server.getConnection().getRemoteHostname() + "'.");
        // fetch the generated Product Certs
        if (Boolean.valueOf(getProperty("sm.debug.fetchProductCerts", "true"))) {
            log.info("Fetching the generated product certs...");
            // SSHCommandResult result = RemoteFileTasks.runCommandAndAssert(server, "find "+serverInstallDir+servertasks.generatedProductsDir+" -name '*.pem'", 0);
            // SSHCommandResult result = server.runCommandAndWait("find "+sm_serverInstallDir+servertasks.generatedProductsDir+" -name '*.pem'");	// find /root/candlepin/server/generated_certs -name '*.pem'
            // find /home/candlepin/candlepin -name '*.pem' | grep generated_certs
            SSHCommandResult result = server.runCommandAndWait("find " + sm_serverInstallDir + " -name '*.pem' | grep generated_certs");
            String[] remoteFilesAsString = result.getStdout().trim().split("\\n");
            if (remoteFilesAsString.length == 1 && remoteFilesAsString[0].equals(""))
                remoteFilesAsString = new String[] {};
            if (remoteFilesAsString.length == 0)
                log.warning("No generated product certs were found on the candlpin server for use in testing.");
            for (String remoteFileAsString : remoteFilesAsString) {
                File remoteFile = new File(remoteFileAsString);
                File localFile = new File((getProperty("automation.dir", "/tmp") + "/tmp/" + remoteFile.getName()).replace("tmp/tmp", "tmp"));
                // rename the generated productCertFile to help distinguish it from a true RHEL productCertFiles
                File localFileRenamed = new File(localFile.getPath().replace(".pem", "_.pem"));
                RemoteFileTasks.getFile(server, localFile.getParent(), remoteFile.getPath());
                localFile.renameTo(localFileRenamed);
                generatedProductCertFiles.add(localFileRenamed);
            }
        }
    }
    // fetch the candlepin CA Cert
    File serverCaCertFile = serverCaCertFile = fetchServerCaCertFile();
    // setup the client(s) (with the fetched candlepin CA Cert and the generated product certs)
    for (SubscriptionManagerTasks smt : new SubscriptionManagerTasks[] { client2tasks, client1tasks }) {
        if (smt != null)
            setupClient(smt, serverCaCertFile, generatedProductCertFiles);
    }
    // initialize various servertasks instance variables for future reference
    servertasks.initialize(clienttasks.candlepinAdminUsername, clienttasks.candlepinAdminPassword, clienttasks.candlepinUrl);
    // create an artifact to log all the package versions being tested
    // this will be in the automation.dir directory on hudson (workspace/automatjon/sm)
    File file = new File("test-output/version.txt");
    Writer output = new BufferedWriter(new FileWriter(file));
    String infoMsg;
    if (client1 != null) {
        infoMsg = "Client1 System Hostname: " + sm_client1Hostname + "\n";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "Beaker Compose: " + client1tasks.compose + "\n";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "Installed Packages:";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // subscription-manager-0.63-1.el6.i686
        infoMsg = client1.runCommandAndWait("rpm -qa | egrep ^subscription-manager").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // python-rhsm-0.63-1.el6.i686
        infoMsg = client1.runCommandAndWait("rpm -qa | egrep ^python-rhsm").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = client1.runCommandAndWait("rpm -q --whatprovides /etc/redhat-release").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "# cat /etc/redhat-release";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // Red Hat Enterprise Linux Server release 6.1 Beta (Santiago)
        infoMsg = client1.runCommandAndWait("cat /etc/redhat-release").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "# uname -a";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // Linux jsefler-onprem-server.usersys.redhat.com 2.6.32-122.el6.x86_64 #1 SMP Wed Mar 9 23:54:34 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
        infoMsg = client1.runCommandAndWait("uname -a").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "# " + client1tasks.listCommand(null, null, null, true, null, null, null, null, null, null, null, null, null, null);
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = client1.runCommandAndWait(client1tasks.listCommand(null, null, null, true, null, null, null, null, null, null, null, null, null, null)).getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        for (ProductCert productCert : client1tasks.getCurrentProductCerts()) {
            infoMsg = "# rpm -q --whatprovides " + productCert.file;
            log.info(infoMsg);
            output.write(infoMsg + "\n");
            infoMsg = client1.runCommandAndWait("rpm -q --whatprovides " + productCert.file).getStdout();
            log.info(infoMsg);
            output.write(infoMsg + "\n\n");
        }
        infoMsg = "# cat " + client1tasks.productIdJsonFile;
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = client1.runCommandAndWait("cat " + client1tasks.productIdJsonFile).getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n\n");
    }
    if (client2 != null) {
        infoMsg = "Client2 System Hostname: " + sm_client2Hostname + "\n";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "Beaker Compose: " + client2tasks.compose + "\n";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "Installed Packages:";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // subscription-manager-0.63-1.el6.i686
        infoMsg = client2.runCommandAndWait("rpm -qa | egrep ^subscription-manager").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // python-rhsm-0.63-1.el6.i686
        infoMsg = client2.runCommandAndWait("rpm -qa | egrep ^python-rhsm").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = client2.runCommandAndWait("rpm -q --whatprovides /etc/redhat-release").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "# cat /etc/redhat-release";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // Red Hat Enterprise Linux Server release 6.1 Beta (Santiago)
        infoMsg = client2.runCommandAndWait("cat /etc/redhat-release").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "# uname -a";
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        // Linux jsefler-onprem-server.usersys.redhat.com 2.6.32-122.el6.x86_64 #1 SMP Wed Mar 9 23:54:34 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
        infoMsg = client2.runCommandAndWait("uname -a").getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = "# " + client2tasks.listCommand(null, null, null, true, null, null, null, null, null, null, null, null, null, null);
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = client2.runCommandAndWait(client2tasks.listCommand(null, null, null, true, null, null, null, null, null, null, null, null, null, null)).getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        for (ProductCert productCert : client2tasks.getCurrentProductCerts()) {
            infoMsg = "# rpm -q --whatprovides " + productCert.file;
            log.info(infoMsg);
            output.write(infoMsg + "\n");
            infoMsg = client2.runCommandAndWait("rpm -q --whatprovides " + productCert.file).getStdout();
            log.info(infoMsg);
            output.write(infoMsg + "\n\n");
        }
        infoMsg = "# cat " + client2tasks.productIdJsonFile;
        log.info(infoMsg);
        output.write(infoMsg + "\n");
        infoMsg = client2.runCommandAndWait("cat " + client2tasks.productIdJsonFile).getStdout();
        log.info(infoMsg);
        output.write(infoMsg + "\n\n");
    }
    output.close();
    // create an artifact containing package versions that can be uploaded to Polarion Group ID
    String groupId = "";
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "0") != null) {
        groupId += " " + clienttasks.installedPackageVersionMap.get("subscription-manager");
    }
    /* exclude for now since the Polarion Group ID should really be a multi-entry field
		 * RHEL Projects: Use of Group ID and Component for Test Runs
		 * https://projects.engineering.redhat.com/browse/POLARION-1201
		if (clienttasks.isPackageVersion("python-rhsm",">=","0")!=null) {
			groupId += " "+clienttasks.installedPackageVersionMap.get("python-rhsm");
		}
		if (clienttasks.isPackageVersion("subscription-manager-migration-data",">=","0")!=null) {
			groupId += " "+clienttasks.installedPackageVersionMap.get("subscription-manager-migration-data");
		}
		*/
    // strip off .el5
    groupId = groupId.replaceAll("\\.el" + clienttasks.redhatReleaseX, "");
    // strip off .arch
    groupId = groupId.replaceAll("\\." + clienttasks.arch + "|\\.noarch", "");
    groupId = groupId.trim();
    /*File*/
    // this will be in the automation.dir directory on hudson (workspace/automatjon/sm)
    file = new File("test-output/group-id.txt");
    /*Writer*/
    output = new BufferedWriter(new FileWriter(file));
    output.write(groupId);
    output.close();
    isSetupBeforeSuiteComplete = true;
}
Also used : SSHCommandRunner(com.redhat.qe.tools.SSHCommandRunner) FileWriter(java.io.FileWriter) SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) BufferedWriter(java.io.BufferedWriter) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) CandlepinTasks(rhsm.cli.tasks.CandlepinTasks) File(java.io.File) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 4 with SubscriptionManagerTasks

use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.

the class SubscriptionManagerCLITestScript method verifyNoSELinuxDenialsWereLoggedAfterClass.

@AfterClass(groups = { "setup" }, description = "Search the SELinux audit log for denials after running the current class of tests")
public void verifyNoSELinuxDenialsWereLoggedAfterClass() {
    for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
        if (clienttasks != null) {
            String avcRegex;
            String tailFromMarkedFile = RemoteFileTasks.getTailFromMarkedFile(clienttasks.sshCommandRunner, clienttasks.auditLogFile, selinuxClassMarker, "denied").trim();
            // TEMPORARY WORKAROUND
            // [root@jsefler-rhel7 ~]# tail -f /var/log/audit/audit.log | grep AVC
            // type=USER_AVC msg=audit(1470087122.008:24063): pid=693 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc:  denied  { 0x2 } for msgtype=signal interface=org.freedesktop.login1.Manager member=SessionNew dest=org.freedesktop.DBus spid=691 tpid=720 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:system_r:modemmanager_t:s0 tclass=(null)  exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
            // type=USER_AVC msg=audit(1470087122.226:24068): pid=693 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc:  denied  { 0x2 } for msgtype=signal interface=org.freedesktop.login1.Manager member=SessionRemoved dest=org.freedesktop.DBus spid=691 tpid=720 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:system_r:modemmanager_t:s0 tclass=(null)  exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
            avcRegex = "type=USER_AVC .* msgtype=signal interface=org.freedesktop.login1.Manager member=Session(New|Removed) dest=org.freedesktop.DBus .* exe=\"/usr/bin/dbus-daemon\" .*";
            if (!tailFromMarkedFile.isEmpty() && doesStringContainMatches(tailFromMarkedFile, avcRegex)) {
                boolean invokeWorkaroundWhileBugIsOpen = true;
                // Bug 1362273 - avc denied /var/log/audit/audit.log when "systemd: Started Session # of user root." is written to /var/log/messages every two minutes
                String bugId = "1362273";
                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) {
                    log.warning("Ignoring the presence of AVC denials matching '" + avcRegex + "' while bug '" + bugId + "' is open.");
                    tailFromMarkedFile = tailFromMarkedFile.replaceAll(avcRegex, "");
                }
            }
            // END OF WORKAROUND
            Assert.assertTrue(tailFromMarkedFile.trim().isEmpty(), "No SELinux denials found in the audit log '" + clienttasks.auditLogFile + "' on client " + clienttasks.sshCommandRunner.getConnection().getRemoteHostname() + " while executing this test class.");
        }
    }
}
Also used : SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) AfterClass(org.testng.annotations.AfterClass)

Example 5 with SubscriptionManagerTasks

use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.

the class FactsTests method testFactCheckRhelDistribution.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36610", "RHEL7-59318" }, 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: facts and rules: fact check RHEL distribution", groups = { "Tier2Tests", "blockedByBug-666540" }, dependsOnGroups = {}, enabled = true)
@ImplementsNitrateTest(caseId = 56329)
public void testFactCheckRhelDistribution() {
    // skip if client1 and client2 are not a Server and Workstation distributions
    SSHCommandRunner workClient = null, servClient = null;
    SubscriptionManagerTasks workClientTasks = null, servClientTasks = null;
    if (client1 != null && client1tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
        workClient = client1;
        workClientTasks = client1tasks;
    }
    if (client2 != null && client2tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
        workClient = client2;
        workClientTasks = client2tasks;
    }
    if (client1 != null && client1tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Server")) {
        servClient = client1;
        servClientTasks = client1tasks;
    }
    if (client2 != null && client2tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Server")) {
        servClient = client2;
        servClientTasks = client2tasks;
    }
    if (workClient == null || servClient == null) {
        throw new SkipException("This test requires a RHEL Workstation client and a RHEL Server client.");
    }
    // start with fresh registrations using the same clientusername user
    workClientTasks.unregister(null, null, null, null);
    servClientTasks.unregister(null, null, null, null);
    workClientTasks.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);
    servClientTasks.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);
    // get all the pools available to each client
    List<SubscriptionPool> workClientPools = workClientTasks.getCurrentlyAvailableSubscriptionPools();
    List<SubscriptionPool> servClientPools = servClientTasks.getCurrentlyAvailableSubscriptionPools();
    log.info("Verifying that the pools available to the Workstation consumer are not identitcal to those available to the Server consumer...");
    if (!(!workClientPools.containsAll(servClientPools) || !servClientPools.containsAll(workClientPools))) {
        // TODO This testcase needs more work.  Running on different variants of RHEL alone is not enough to assert that the available pools are different.  In fact, then should be the same if the subscriptions are all set with a variant attribute of ALL
        throw new SkipException("The info message above is not accurate... The assertion that the pools available to a Workstation consumer versus a Server consumer is applicable ONLY when the org's subscriptions includes a variant aware subscription.  In fact, if the org's subscriptions are all set with a variant attribute of ALL, then the available pools should be identical.  This automated test needs some work.");
    }
    Assert.assertTrue(!workClientPools.containsAll(servClientPools) || !servClientPools.containsAll(workClientPools), "Because the facts of a system client running RHEL Workstation versus RHEL Server should be different, the available subscription pools to these two systems should not be the same.");
// FIXME TODO Verify with development that these are valid asserts
// log.info("Verifying that the pools available to the Workstation consumer do not contain Server in the ProductName...");
// log.info("Verifying that the pools available to the Server consumer do not contain Workstation in the ProductName...");
}
Also used : SSHCommandRunner(com.redhat.qe.tools.SSHCommandRunner) SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) SkipException(org.testng.SkipException) 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

SubscriptionManagerTasks (rhsm.cli.tasks.SubscriptionManagerTasks)10 Test (org.testng.annotations.Test)4 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)3 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)3 SSHCommandRunner (com.redhat.qe.tools.SSHCommandRunner)3 SkipException (org.testng.SkipException)3 BeforeSuite (org.testng.annotations.BeforeSuite)3 SubscriptionPool (rhsm.data.SubscriptionPool)3 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)2 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)2 AfterSuite (org.testng.annotations.AfterSuite)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1 AfterClass (org.testng.annotations.AfterClass)1 CandlepinTasks (rhsm.cli.tasks.CandlepinTasks)1 ProductCert (rhsm.data.ProductCert)1