use of rhsm.data.ContentNamespace in project rhsm-qe by RedHatQE.
the class OstreeTests method testOstreeConfigurationsAreSetAfterSubscribingAndUnsubscribing.
// 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-22238", "RHEL7-51753" }, 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 = "Verify that the ostree config and origin files are set after attaching an atomic subscription; attempt an atomic upgrade; unsubscribe and verify ostree config files are unset", groups = { "Tier1Tests", "subscribeAndUnsubscribeTests" }, dataProvider = "getOstreeSubscriptionPools", priority = 10, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testOstreeConfigurationsAreSetAfterSubscribingAndUnsubscribing(Object bugzilla, SubscriptionPool osTreeSubscriptionPool) {
// this test is designed to be entitled to one subscription at a time.
clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
String baseurl = clienttasks.getConfParameter("baseurl");
String repo_ca_cert = clienttasks.getConfParameter("repo_ca_cert");
// get a list of the current Product Certs installed on the system
List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
// get a list of the ostree repos from the ostree repo config file before attaching an ostree subscription
List<OstreeRepo> ostreeReposBefore = getCurrentlyConfiguredOstreeRepos(ostreeRepoConfigFile);
// get the ostree origin refspec before attaching an ostree subscription
// UPDATE: After subscription-manager-plugin-ostree-1.18.5-1 RFE Bug 1378495, the ostree origin refspec file is no longer touched
String ostreeOriginRefspecBefore = ostreeOriginFile == null ? null : clienttasks.getConfFileParameter(ostreeOriginFile.getPath(), "origin", "refspec");
// also setup an old /ostree/repo/config file to test the migration clean up scenario described in https://bugzilla.redhat.com/show_bug.cgi?id=1152734#c5
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.9-1")) {
// post committ 11b377f78dcb06d8dbff5645750791b729e20a0e
if (!clienttasks.isPackageInstalled("ostree")) {
client.runCommandAndWait("mkdir -p " + oldOstreeRepoConfigFile.getParent());
client.runCommandAndWait("echo -e '[core]\nrepo_version=1\nmode=bare\n\n[remote \"REMOTE\"]\nurl=file:///install/ostree\ngpg-verify=false' > " + oldOstreeRepoConfigFile.getPath());
}
}
// attach the subscription that provides ostree content
File file = clienttasks.subscribeToSubscriptionPool(osTreeSubscriptionPool, sm_clientUsername, sm_clientPassword, sm_serverUrl);
EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(file);
// get a list of the ostree repos from the ostree repo config file after attaching an ostree subscription
List<OstreeRepo> ostreeReposAfter = getCurrentlyConfiguredOstreeRepos(ostreeRepoConfigFile);
// get the ostree origin refspec after attaching an ostree subscription
// UPDATE: After subscription-manager-plugin-ostree-1.18.5-1 RFE Bug 1378495, the ostree origin refspec file is no longer touched
String ostreeOriginRefspecAfter = ostreeOriginFile == null ? null : clienttasks.getConfFileParameter(ostreeOriginFile.getPath(), "origin", "refspec");
// also assert the clean up of remotes from the old /ostree/repo/config file
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.9-1")) {
// post committ 11b377f78dcb06d8dbff5645750791b729e20a0e
if (RemoteFileTasks.testExists(client, oldOstreeRepoConfigFile.getPath())) {
Assert.assertTrue(getCurrentlyConfiguredOstreeRepos(oldOstreeRepoConfigFile).isEmpty(), "Subscription-manager should have cleaned out the old remotes from '" + oldOstreeRepoConfigFile + "'.");
}
}
// assert that ostree repos have been added for each ostree content namespace
List<ContentNamespace> osTreeContentNamespaces = ContentNamespace.findAllInstancesWithMatchingFieldFromList("type", "ostree", entitlementCert.contentNamespaces);
List<ContentNamespace> osTreeContentNamespacesMatchingInstalledProducts = new ArrayList<ContentNamespace>();
for (ContentNamespace osTreeContentNamespace : osTreeContentNamespaces) {
log.info("Asserting the following ostree contentNamespace is added to ostree config file '" + ostreeRepoConfigFile + "' : " + osTreeContentNamespace);
// THIS TAGGING DECISION WAS IMPLEMENTED AS A SOLUTION TO https://bugzilla.redhat.com/show_bug.cgi?id=1153366#c5
if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(osTreeContentNamespace, currentProductCerts)) {
OstreeRepo ostreeRepo = OstreeRepo.findFirstInstanceWithMatchingFieldFromList("remote", osTreeContentNamespace.label, ostreeReposAfter);
Assert.assertNotNull(ostreeRepo, "Found an OSTree repo configuration in '" + ostreeRepoConfigFile + "' after attaching subscription '" + osTreeSubscriptionPool.subscriptionName + "' originating from entitlement content: " + osTreeContentNamespace);
Assert.assertEquals(ostreeRepo.url, baseurl + osTreeContentNamespace.downloadUrl, "OSTree repo remote '" + ostreeRepo.remote + "' config for url. (maps to content downloadUrl)");
Assert.assertEquals(ostreeRepo.gpg_verify, Boolean.valueOf(!osTreeContentNamespace.gpgKeyUrl.replaceFirst("https?://", "").trim().isEmpty()), "OSTree repo remote '" + ostreeRepo.remote + "' config for gpg-verify. (maps to TRUE when content contains gpgKeyUrl)");
Assert.assertEquals(ostreeRepo.tls_client_cert_path, entitlementCert.file.getPath(), "OSTree repo remote '" + ostreeRepo.remote + "' config for tls-client-cert-path. (maps to path of the entitlement cert)");
Assert.assertEquals(ostreeRepo.tls_client_key_path, clienttasks.getEntitlementCertKeyFileFromEntitlementCert(entitlementCert).getPath(), "OSTree repo remote '" + ostreeRepo.remote + "' config for tls-client-key-path. (maps to path of the entitlement cert key)");
Assert.assertEquals(ostreeRepo.tls_ca_path, repo_ca_cert, "OSTree repo remote '" + ostreeRepo.remote + "' config for tls-ca-path. (maps to path of the candlepin CA cert)");
if (!osTreeContentNamespacesMatchingInstalledProducts.contains(osTreeContentNamespace))
osTreeContentNamespacesMatchingInstalledProducts.add(osTreeContentNamespace);
} else {
OstreeRepo ostreeRepo = OstreeRepo.findFirstInstanceWithMatchingFieldFromList("remote", osTreeContentNamespace.label, ostreeReposAfter);
Assert.assertNull(ostreeRepo, "Should NOT find an OSTree repo configuration for remote '" + osTreeContentNamespace.label + "' in '" + ostreeRepoConfigFile + "' after attaching subscription '" + osTreeSubscriptionPool.subscriptionName + "' because the Required Tags '" + osTreeContentNamespace.requiredTags + "' from the entitlement content are not found among the current product certs installed.");
}
}
// assert that other ostree repos remain configured
// TEMPORARY WORKAROUND FOR BUG: 1152734 - Update subman ostree content plugin to use ostree cli for manipulating 'remote' configs
boolean invokeWorkaroundWhileBugIsOpen = true;
String bugId = "1152734";
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 the assertion that other remotes in '" + ostreeRepoConfigFile + "' remain unchanged when attaching an atomic subscription.");
} else
// END OF WORKAROUND
for (OstreeRepo ostreeRepoBefore : ostreeReposBefore) {
if (ContentNamespace.findFirstInstanceWithMatchingFieldFromList("label", ostreeRepoBefore.remote, osTreeContentNamespaces) == null) {
OstreeRepo ostreeRepoAfter = OstreeRepo.findFirstInstanceWithMatchingFieldFromList("remote", ostreeRepoBefore.remote, ostreeReposAfter);
Assert.assertNotNull(ostreeRepoAfter, "OSTree repo configuration in '" + ostreeRepoConfigFile + "' remote '" + ostreeRepoBefore.remote + "' remains configured after attaching subscription '" + osTreeSubscriptionPool.subscriptionName + "' (because it was not among the ostree content sets).");
Assert.assertEquals(ostreeRepoAfter.url, ostreeRepoBefore.url, "Remote '" + ostreeRepoBefore.remote + "' url");
Assert.assertEquals(ostreeRepoAfter.gpg_verify, ostreeRepoBefore.gpg_verify, "Remote '" + ostreeRepoBefore.remote + "' gpg-verify");
Assert.assertEquals(ostreeRepoAfter.tls_client_cert_path, ostreeRepoBefore.tls_client_cert_path, "Remote '" + ostreeRepoBefore.remote + "' tls-client-cert-path");
Assert.assertEquals(ostreeRepoAfter.tls_client_key_path, ostreeRepoBefore.tls_client_key_path, "Remote '" + ostreeRepoBefore.remote + "' tls-client-key-path");
Assert.assertEquals(ostreeRepoAfter.tls_ca_path, ostreeRepoBefore.tls_ca_path, "Remote '" + ostreeRepoBefore.remote + "' tls-ca-path");
}
}
/* replacing this with assertion that there is only osTreeContentNamespaceToTest
// throw a failure on the subscription if there is more than one ostree repo
// if there is more than one ostree repo, then it is undefined which repo remote to set in the ostree origin file
Assert.assertEquals(osTreeContentNamespaces.size(), 1, "The number of ostree content sets provided by atomic subscription '"+osTreeSubscriptionPool.subscriptionName+"'. (Greater than 1 is undefined)");
*/
// assert that there is only one entitled osTreeContentNamespaceMatchingInstalledProducts
// TEMPORARY WORKAROUND FOR BUG: 1160771 - Missing provides/requires tags in ostree content sets (not product cert)
invokeWorkaroundWhileBugIsOpen = true;
// Status: MODIFIED
invokeWorkaroundWhileBugIsOpen = false;
bugId = "1160771";
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) {
if (osTreeContentNamespacesMatchingInstalledProducts.size() > 1)
log.warning("Found more than one entitled ostree ContentNamespace whose RequiredTags match the installed productCerts. Blocked by Jira request https://projects.engineering.redhat.com/browse/APPINFRAT-246");
log.warning("Skipping the assertion for more than one entitled ostree ContentNamespace whose RequiredTags match the installed productCerts due to open bug '" + bugId + "'.");
}
// END OF WORKAROUND
if (clienttasks.isPackageVersion("subscription-manager-plugin-ostree", "<", "1.13.9-1")) {
// commit 11b377f78dcb06d8dbff5645750791b729e20a0e
// Bug 1152734 - Update subman ostree content plugin to use ostree cli for manipulating 'remote' configs
Assert.fail("This version of subscription-manager-plugin-ostree is blocked by bug 1152734.");
}
ContentNamespace osTreeContentNamespaceMatchingInstalledProducts = null;
if (osTreeContentNamespacesMatchingInstalledProducts.isEmpty()) {
log.warning("This is probably NOT an atomic system.");
if (ostreeOriginRefspecBefore != null)
Assert.assertEquals(ostreeOriginRefspecAfter, ostreeOriginRefspecBefore, "When there are no installed products whose tags match the ostree ContentNamespace tags, then the ostree origin refspec in file '" + ostreeOriginFile + "' should remain unchanged after attaching subscription '" + osTreeSubscriptionPool.subscriptionName + "'.");
} else {
Assert.assertEquals(osTreeContentNamespacesMatchingInstalledProducts.size(), 1, "At most there should only be one entitled ostree ContentNamespace that matches the installed product certs.");
osTreeContentNamespaceMatchingInstalledProducts = osTreeContentNamespacesMatchingInstalledProducts.get(0);
// UPDATE: After subscription-manager-plugin-ostree-1.18.5-1 RFE Bug 1378495, the ostree origin refspec file is no longer touched
if (ostreeOriginRefspecAfter != null)
Assert.assertEquals(ostreeOriginRefspecAfter.split(":")[1], ostreeOriginRefspecBefore.split(":")[1], "The remote path portion of the refspec in the ostree origin file '" + ostreeOriginFile + "' should remain unchanged after attaching atomic subscription '" + osTreeSubscriptionPool.subscriptionName + "'.");
if (ostreeOriginRefspecAfter != null)
Assert.assertEquals(ostreeOriginRefspecAfter.split(":")[0], osTreeContentNamespaceMatchingInstalledProducts.label, "The remote label portion of the refspec in the ostree origin file '" + ostreeOriginFile + "' should be updated to the newly entitled ostree content label after attaching atomic subscription '" + osTreeSubscriptionPool.subscriptionName + "'.");
}
// attempt to do an atomic upgrade
String pkg = "rpm-ostree-client";
if (!clienttasks.isPackageInstalled(pkg)) {
log.warning("Skipping assertion attempt to do an atomic upgrade after attaching the atomic subscription since package '" + pkg + "' is not installed.");
} else {
SSHCommandResult atomicUpgradeResultAfterSubscribe = client.runCommandAndWait("atomic upgrade");
// -bash-4.2# atomic upgrade
// Updating from: rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
//
// Requesting /content/beta/rhel/atomic/7/x86_64/ostree/repo/refs/heads/rhel-atomic-host/7/x86_64/standard
// Copying /etc changes: 13 modified, 4 removed, 42 added
// Transaction complete; bootconfig swap: no deployment count change: 0
// Changed:
// docker-1.2.0-1.8.el7.x86_64
// kubernetes-0.4+-0.9.git8e1d416.el7.x86_64
// tzdata-2014i-1.el7.noarch
// Updates prepared for next boot; run "systemctl reboot" to start a reboot
// -bash-4.2#
String stdoutStartsWith = "Updating from: " + ostreeOriginRefspecBefore;
String stdoutEndsWith = "Updates prepared for next boot; run \"systemctl reboot\" to start a reboot";
Assert.assertEquals(atomicUpgradeResultAfterSubscribe.getExitCode(), new Integer(0), "Exitcode after attempting to do an atomic upgrade after attaching an atomic subscription.");
Assert.assertTrue(atomicUpgradeResultAfterSubscribe.getStdout().trim().startsWith(stdoutStartsWith), "Stdout starts with '" + stdoutStartsWith + "' after attempting to do an atomic upgrade after attaching an atomic subscription.");
Assert.assertTrue(atomicUpgradeResultAfterSubscribe.getStdout().trim().endsWith(stdoutEndsWith), "Stdout ends with '" + stdoutEndsWith + "' after attempting to do an atomic upgrade after attaching an atomic subscription.");
Assert.assertEquals(atomicUpgradeResultAfterSubscribe.getStderr().trim(), "", "Exitcode after attempting to do an atomic upgrade after attaching an atomic subscription.");
// -bash-4.2# atomic status
// VERSION ID OSNAME REFSPEC
// 7.0.4 0fc676bdec rhel-atomic-host rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
// * 7.0.2 9a0dbc159e rhel-atomic-host rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
// -bash-4.2#
// This sample output shows that rhel-atomic-host 0fc676bdec... will be booted into on the next restart. The version to be booted on
// the next restart is printed first.
// This sample also shows that rhel-atomic-host 9a0dbc159e... is the currently running version. The currently running version is
// marked with an asterisk (*). This output was created just after the atomic upgrade command was executed, therefore a new
// version has been staged to be applied at the next restart.
SSHCommandResult atomicStatusResultAfterSubscribe = client.runCommandAndWait("atomic status | grep -v VERSION");
Assert.assertTrue(!atomicStatusResultAfterSubscribe.getStdout().trim().split("\n")[0].startsWith("*"), "Stdout from atomic status after doing an atomic upgrade indicates that the upgraded version is listed first and will be booted on the next systemctl reboot.");
Assert.assertTrue(atomicStatusResultAfterSubscribe.getStdout().trim().split("\n")[1].startsWith("*"), "Stdout from atomic status after doing an atomic upgrade indicates that the currently running version (listed second) is marked with an asterisk (*)");
}
// MOVED TO SUBSEQUENT TEST
// // randomly choose to remove the ostree subscription and assert...
// if (getRandomBoolean()) {
// MOVED BACK
clienttasks.unsubscribe(null, clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCert.file), null, null, null, null, null);
// after removing the entitlement, assert its corresponding ostree repos are removed
ostreeReposAfter = getCurrentlyConfiguredOstreeRepos(ostreeRepoConfigFile);
for (ContentNamespace osTreeContentNamespace : osTreeContentNamespaces) {
OstreeRepo ostreeRepo = OstreeRepo.findFirstInstanceWithMatchingFieldFromList("remote", osTreeContentNamespace.label, ostreeReposAfter);
Assert.assertNull(ostreeRepo, "Should no longer find an OSTree repo configuration for remote '" + osTreeContentNamespace.label + "' in '" + ostreeRepoConfigFile + "' after removing subscription '" + osTreeSubscriptionPool.subscriptionName + "'.");
}
// TODO: This assertion may be changed by Bug 1193208 - 'atomic host upgrade' gives incorrect error after unregistering with subscription-manager
if (ostreeOriginFile != null)
Assert.assertEquals(clienttasks.getConfFileParameter(ostreeOriginFile.getPath(), "origin", "refspec"), ostreeOriginRefspecAfter, "The OSTree origin refspec in '" + ostreeOriginFile + "' should remain unchanged after removing subscription '" + osTreeSubscriptionPool.subscriptionName + "'.");
// when removing the entitlement, assert that other ostree repos remain configured
// TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1152734
invokeWorkaroundWhileBugIsOpen = true;
bugId = "1152734";
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 the assertion that other remotes in '" + ostreeRepoConfigFile + "' remain unchanged when removing an atomic subscription.");
} else
// END OF WORKAROUND
for (OstreeRepo ostreeRepoBefore : ostreeReposBefore) {
if (ContentNamespace.findFirstInstanceWithMatchingFieldFromList("label", ostreeRepoBefore.remote, osTreeContentNamespaces) == null) {
OstreeRepo ostreeRepoAfter = OstreeRepo.findFirstInstanceWithMatchingFieldFromList("remote", ostreeRepoBefore.remote, ostreeReposAfter);
Assert.assertNotNull(ostreeRepoAfter, "OSTree repo configuration in '" + ostreeRepoConfigFile + "' remote '" + ostreeRepoBefore.remote + "' remains configured after removing subscription '" + osTreeSubscriptionPool.subscriptionName + "' (because it was not among the ostree content sets).");
Assert.assertEquals(ostreeRepoAfter.url, ostreeRepoBefore.url, "Remote '" + ostreeRepoBefore.remote + "' url");
Assert.assertEquals(ostreeRepoAfter.gpg_verify, ostreeRepoBefore.gpg_verify, "Remote '" + ostreeRepoBefore.remote + "' gpg-verify");
Assert.assertEquals(ostreeRepoAfter.tls_client_cert_path, ostreeRepoBefore.tls_client_cert_path, "Remote '" + ostreeRepoBefore.remote + "' tls-client-cert-path");
Assert.assertEquals(ostreeRepoAfter.tls_client_key_path, ostreeRepoBefore.tls_client_key_path, "Remote '" + ostreeRepoBefore.remote + "' tls-client-key-path");
Assert.assertEquals(ostreeRepoAfter.tls_ca_path, ostreeRepoBefore.tls_ca_path, "Remote '" + ostreeRepoBefore.remote + "' tls-ca-path");
}
}
// }
// MOVED BACK
// attempt to run the atomic upgrade without an entitlement
// /usr/bin/atomic is provided by rpm-ostree-client-2014.109-2.atomic.el7.x86_64
pkg = "rpm-ostree-client";
if (!clienttasks.isPackageInstalled(pkg)) {
log.warning("Skipping assertion attempt to do an atomic upgrade after removing the atomic subscription since package '" + pkg + "' is not installed.");
} else {
SSHCommandResult atomicUpgradeResultAfterUnsubscribe = client.runCommandAndWait("atomic upgrade");
// -bash-4.2# atomic upgrade
// Updating from: rhel-atomic-host-beta-ostree:rhel-atomic-host/7/x86_64/standard
//
//
// error: No remote 'remote "rhel-atomic-host-beta-ostree"' found in /etc/ostree/remotes.d
// -bash-4.2#
// TODO: need to be run on Atomic and updated to make a better assert after the changes from subscription-manager-1.18.5-1 Bug 1378495 - [RFE] Do not change OStree origin refspec
String stdoutStartsWith = "Updating from: " + ostreeOriginRefspecAfter;
Assert.assertEquals(atomicUpgradeResultAfterUnsubscribe.getExitCode(), new Integer(1), "Exitcode after attempting to do an atomic upgrade after removing the atomic subscription.");
Assert.assertTrue(atomicUpgradeResultAfterUnsubscribe.getStdout().trim().startsWith(stdoutStartsWith), "Stdout starts with '" + stdoutStartsWith + "' after attempting to do an atomic upgrade after removing the atomic subscription.");
Assert.assertEquals(atomicUpgradeResultAfterUnsubscribe.getStderr().trim(), "error: No remote 'remote \"" + osTreeContentNamespaceMatchingInstalledProducts.label + "\"' found in /etc/ostree/remotes.d", "Exitcode after attempting to do an atomic upgrade after removing the atomic subscription.");
}
}
Aggregations