diff --git a/cypress/e2e/tests/pages/fleet/fleet-clusters.spec.ts b/cypress/e2e/tests/pages/fleet/fleet-clusters.spec.ts index 57ab18cb541..564f27a07f2 100644 --- a/cypress/e2e/tests/pages/fleet/fleet-clusters.spec.ts +++ b/cypress/e2e/tests/pages/fleet/fleet-clusters.spec.ts @@ -29,6 +29,7 @@ describe('Fleet Clusters - bundle manifests are deployed from the BundleDeployme let removeWorkspace = false; let disableFeature = false; let clusterName = ''; + let cloudcredentialId = ''; let gitRepo = ''; let customWorkspace = ''; const feature = 'provisioningv2-fleet-workspace-back-population'; @@ -69,7 +70,9 @@ describe('Fleet Clusters - bundle manifests are deployed from the BundleDeployme namespace, }, metadata: { labels: { foo: 'bar' } } - }).then(() => { + }).then((req) => { + cloudcredentialId = req.body.spec.cloudCredentialSecretName; + removeCluster = true; }); }); @@ -365,6 +368,11 @@ describe('Fleet Clusters - bundle manifests are deployed from the BundleDeployme featureFlagsPage.clickCardActionButtonAndWait('Deactivate', feature, false, { waitForModal: true, waitForRequest: true }); featureFlagsPage.list().details(feature, 0).should('include.text', 'Disabled'); } + + if (cloudcredentialId) { + // delete cloud credential + cy.deleteRancherResource('v3', 'cloudCredentials', cloudcredentialId, false); + } }); }); diff --git a/cypress/e2e/tests/pages/manager/cloud-credential.spec.ts b/cypress/e2e/tests/pages/manager/cloud-credential.spec.ts index 83aa7dbc135..76c560601ba 100644 --- a/cypress/e2e/tests/pages/manager/cloud-credential.spec.ts +++ b/cypress/e2e/tests/pages/manager/cloud-credential.spec.ts @@ -9,11 +9,34 @@ import ClusterManagerCreatePagePo from '@/cypress/e2e/po/edit/provisioning.cattl import LoadingPo from '@/cypress/e2e/po/components/loading.po'; import HomePagePo from '@/cypress/e2e/po/pages/home.po'; +/****** +* Running this test will delete all Amazon cloud credentials from the target cluster +******/ describe('Cloud Credential', { tags: ['@manager', '@adminUser'] }, () => { const clusterList = new ClusterManagerListPagePo(); const doCreatedCloudCredsIds = []; const azCreatedCloudCredsIds = []; + before(() => { + cy.login(); + // Clean up any orphaned Amazon cloud credentials from previous test runs to ensure tests start with a clean state + cy.getRancherResource('v3', 'cloudcredentials', null, null).then((resp: Cypress.Response) => { + const body = resp.body; + + if (body.pagination['total'] > 0) { + body.data.forEach((item: any) => { + if (item.amazonec2credentialConfig) { + const id = item.id; + + cy.deleteRancherResource('v3', 'cloudcredentials', id, false); + } else { + cy.log('There are no existing amazon cloud credentials to delete'); + } + }); + } + }); + }); + beforeEach(() => { cy.login(); HomePagePo.goTo(); // this is needed to ensure we have a valid authentication session