Skip to content

Commit

Permalink
fix flaky provisioning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonas Berhe authored and Yonas Berhe committed Oct 14, 2024
1 parent 49829da commit df118f7
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 200 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/po/components/sortable-table.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export default class SortableTablePo extends ComponentPo {
* @param expected number of rows shown
* @returns
*/
checkRowCount(isEmpty: boolean, expected: number, hasFilter = false) {
return this.rowElements().should((el) => {
checkRowCount(isEmpty: boolean, expected: number, options?, hasFilter = false) {
return this.rowElements(options).should((el) => {
if (isEmpty) {
expect(el).to.have.length(expected);
expect(el).to.have.text(hasFilter ? 'There are no rows which match your search query.' : 'There are no rows to show.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import ClusterManagerDetailRke1AmazonEc2PagePo from '@/cypress/e2e/po/detail/pro
import PromptRemove from '@/cypress/e2e/po/prompts/promptRemove.po';
import LoadingPo from '@/cypress/e2e/po/components/loading.po';
import EmberBannersPo from '@/cypress/e2e/po/components/ember/ember-banners.po';
import { LONG_TIMEOUT_OPT, MEDIUM_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';

/******
* Running this test will delete node templates and cloud credentials resources from the target cluster
******/

// will only run this in jenkins pipeline where cloud credentials are stored
describe('Provision Node driver RKE1 cluster with AWS', { testIsolation: 'off', tags: ['@manager', '@adminUser', '@standardUser', '@jenkins'] }, () => {
describe('Deploy RKE1 cluster using node driver on Amazon EC2', { testIsolation: 'off', tags: ['@manager', '@adminUser', '@standardUser', '@jenkins'] }, () => {
const clusterList = new ClusterManagerListPagePo();
const createRKE1ClusterPage = new ClusterManagerCreateRke1Amazonec2PagePo();
const loadingPo = new LoadingPo('.loading-indicator');

let removeNodeTemplate = false;
let cloudcredentialId = '';
let nodeTemplateId = '';
let clusterId = '';
const k8sVersions = [];

const homePage = new HomePagePo();
const homeClusterList = homePage.list();
Expand Down Expand Up @@ -65,31 +70,19 @@ describe('Provision Node driver RKE1 cluster with AWS', { testIsolation: 'off',
cy.createE2EResourceName('rke1ec2clusterdesc').as('rke1Ec2ClusterDescription');
cy.createE2EResourceName('template').as('templateName');
cy.createE2EResourceName('node').as('nodeName');
cy.getRancherResource('v3', 'clusters', null, null).then((resp: Cypress.Response<any>) => {
const data = resp.body.data;

data.forEach((item: any) => {
cy.get('@rke1Ec2ClusterName').then((name) => {
if (item.name === name) {
cy.wrap(item['id']).as('clusterId');
} else {
cy.log(`${ name } does not exist`);
}
});
});
});
});

it('can provision a Amazon EC2 rke1 cluster with Amazon cloud provider', function() {
it('can create an RKE1 cluster using Amazon cloud provider', function() {
const addNodeTemplateForm = createRKE1ClusterPage.addNodeTemplateForm();

ClusterManagerListPagePo.navTo();
clusterList.waitForPage();
clusterList.createCluster();
createRKE1ClusterPage.rkeToggle().set('RKE1');
createRKE1ClusterPage.selectCreate(0);
createRKE1ClusterPage.rke2PageTitle().should('include', 'Create Amazon EC2');
createRKE1ClusterPage.waitForPage('type=amazonec2&rkeType=rke1');
loadingPo.checkNotExists();
createRKE1ClusterPage.rke1PageTitle().should('contain', 'Add Cluster - Amazon EC2');
createRKE1ClusterPage.addNodeTemplate();

// create amazon ec2 cloud credential and node template
Expand Down Expand Up @@ -131,59 +124,63 @@ describe('Provision Node driver RKE1 cluster with AWS', { testIsolation: 'off',
createRKE1ClusterPage.nodePoolTable().worker(1).checkOptionSelected();

// Get kubernetes version options and store them in variables
createRKE1ClusterPage.kubernetesOptions().kubernetesVersion().getOptions().each((el, index) => {
cy.wrap(el.text().trim()).as(`k8sVersion${ index }`);
createRKE1ClusterPage.kubernetesOptions().kubernetesVersion().getOptions().each((el) => {
k8sVersions.push(el.text().trim());
})
.then(function() {
createRKE1ClusterPage.kubernetesOptions().kubernetesVersion().selectMenuItemByOption(this.k8sVersion0);
.then(() => {
createRKE1ClusterPage.kubernetesOptions().kubernetesVersion().selectMenuItemByOption(k8sVersions[0]);
});

cy.intercept('POST', 'v3/cluster?_replace=true').as('createRke1Cluster');
createRKE1ClusterPage.createRKE1();
cy.wait('@createRke1Cluster').then(function(req) {
expect(req.response?.statusCode).to.eq(201);
expect(req.response?.body).to.have.property('type', 'cluster');
expect(req.response?.body).to.have.property('name', this.rke1Ec2ClusterName);
expect(req.response?.body.rancherKubernetesEngineConfig).to.have.property('kubernetesVersion', this.k8sVersion0);
cy.wrap(req.response?.body.id).as('clusterId');
cy.wait('@createRke1Cluster').then(({ response }) => {
expect(response?.statusCode).to.eq(201);
expect(response?.body).to.have.property('type', 'cluster');
expect(response?.body).to.have.property('name', this.rke1Ec2ClusterName);
expect(response?.body.rancherKubernetesEngineConfig).to.have.property('kubernetesVersion', k8sVersions[0]);
clusterId = response?.body.id;
});
clusterList.waitForPage();
clusterList.list().state(this.rke1Ec2ClusterName).should('contain.text', 'Provisioning');
});

it('can see details of cluster in cluster list', function() {
ClusterManagerListPagePo.navTo();
clusterList.waitForPage();

// check Architecture
// testing https://github.com/rancher/dashboard/issues/10831
clusterList.list().version(this.rke1Ec2ClusterName).should('contain', '—').and('not.contain', 'Unknown');
clusterList.list().version(this.rke1Ec2ClusterName).should('contain.text', '—').and('not.contain.text', 'Unknown');

// check states
clusterList.list().state(this.rke1Ec2ClusterName).should('contain', 'Provisioning');
clusterList.list().state(this.rke1Ec2ClusterName).contains('Waiting', { timeout: 700000 });
clusterList.list().state(this.rke1Ec2ClusterName).contains('Active', { timeout: 700000 });

// check k8s version
clusterList.sortableTable().rowWithName(this.rke1Ec2ClusterName).column(3).contains('—')
.should('not.exist', { timeout: 5000 });
clusterList.list().version(this.rke1Ec2ClusterName).then(function(el) {
const shortVersion = this.k8sVersion0.split('-');
clusterList.sortableTable().rowWithName(this.rke1Ec2ClusterName).column(3).contains('—', { timeout: 15000 })
.should('not.exist');
clusterList.list().version(this.rke1Ec2ClusterName).then((el) => {
const shortVersion = k8sVersions[0].split('-');

expect(el.text().trim()).contains(shortVersion[0]);
});

// check provider
clusterList.list().provider(this.rke1Ec2ClusterName).should('contain', 'Amazon EC2');
clusterList.list().provider(this.rke1Ec2ClusterName).should('contain', 'RKE1');
clusterList.list().provider(this.rke1Ec2ClusterName).should('contain.text', 'Amazon EC2');
clusterList.list().providerSubType(this.rke1Ec2ClusterName).should('contain.text', 'RKE1');

// check machines
clusterList.list().machines(this.rke1Ec2ClusterName).should('contain', 1);
clusterList.list().machines(this.rke1Ec2ClusterName).should('contain.text', '1');

// check cluster details page > machine pools
cy.get<string>('@clusterId').then(function(clusterId) {
const clusterDetails = new ClusterManagerDetailRke1AmazonEc2PagePo(undefined, clusterId);

clusterList.list().name(this.rke1Ec2ClusterName).click();
clusterDetails.waitForPage(null, 'node-pools');
clusterDetails.resourceDetail().title().should('contain', this.rke1Ec2ClusterName);
clusterDetails.machinePoolsList().resourceTable().sortableTable().groupElementWithName(this.nodeName)
.next('tr.main-row')
.should('contain', 'Active');
});
const clusterDetails = new ClusterManagerDetailRke1AmazonEc2PagePo(undefined, clusterId);

clusterList.list().name(this.rke1Ec2ClusterName).click();
clusterDetails.waitForPage(null, 'node-pools');
clusterDetails.resourceDetail().title().should('contain', this.rke1Ec2ClusterName);
clusterDetails.machinePoolsList().resourceTable().sortableTable().groupElementWithName(this.nodeName)
.next('tr.main-row')
.should('contain.text', 'Active');

// https://github.com/rancher/dashboard/issues/10441 - covering RKE1/ember world descriptions
HomePagePo.navTo();
Expand All @@ -198,14 +195,12 @@ describe('Provision Node driver RKE1 cluster with AWS', { testIsolation: 'off',
clusterList.waitForPage();

// cluster details page
const clusterDetails = new ClusterManagerDetailRke1AmazonEc2PagePo(undefined, this.clusterId);
const clusterDetails = new ClusterManagerDetailRke1AmazonEc2PagePo(undefined, clusterId);

clusterList.list().actionMenu(this.rke1Ec2ClusterName).getMenuItem('Edit Config').click();
clusterDetails.waitForPage('mode=edit');
clusterDetails.resourceDetail().title().should('contain', this.rke1Ec2ClusterName);

const loadingPo = new LoadingPo('.loading-indicator');

loadingPo.checkNotExists();
createRKE1ClusterPage.nodePoolTable().addNodePool();
createRKE1ClusterPage.nodePoolTable().name(1).set(this.nodeName);
Expand All @@ -224,31 +219,29 @@ describe('Provision Node driver RKE1 cluster with AWS', { testIsolation: 'off',
createRKE1ClusterPage.nodePoolTable().worker(1).checkOptionSelected();

// save changes
cy.intercept('PUT', `v3/clusters/${ this.clusterId }?_replace=true`).as('saveRke1Cluster');
cy.intercept('POST', `/v3/nodepool`).as('updateCluster');
createRKE1ClusterPage.saveRKE1();
cy.wait('@saveRke1Cluster').then((req) => {
expect(req.response?.statusCode).to.eq(200);
});
cy.wait('@updateCluster').its('response.statusCode').should('eq', 201);
clusterList.waitForPage();

// check states on cluster details page > machine pools
clusterList.list().name(this.rke1Ec2ClusterName).click();
clusterDetails.waitForPage(null, 'node-pools');
clusterDetails.resourceDetail().title().should('contain', this.rke1Ec2ClusterName);
clusterDetails.machinePoolsList().resourceTable().sortableTable().groupElementWithName(`${ this.nodeName }-2`)
.next('tr.main-row')
.should('contain', 'Provisioning');
.should('contain.text', 'Provisioning');
clusterDetails.machinePoolsList().resourceTable().sortableTable().groupElementWithName(`${ this.nodeName }-2`)
.next('tr.main-row', { timeout: 360000 })
.should('contain', 'Registering');
.should('contain.text', 'Registering');
clusterDetails.machinePoolsList().resourceTable().sortableTable().groupElementWithName(`${ this.nodeName }-2`)
.next('tr.main-row', { timeout: 360000 })
.should('contain', 'Active');
.should('contain.text', 'Active');
});

it('can delete a Amazon EC2 RKE1 cluster', function() {
it('can delete an Amazon EC2 RKE1 cluster', function() {
ClusterManagerListPagePo.navTo();
clusterList.waitForPage();
clusterList.list().state(this.rke1Ec2ClusterName).contains('Active', { timeout: 120000 });
clusterList.list().actionMenu(this.rke1Ec2ClusterName).getMenuItem('Delete').click();

clusterList.sortableTable().rowNames('.cluster-link').then((rows: any) => {
Expand All @@ -258,13 +251,15 @@ describe('Provision Node driver RKE1 cluster with AWS', { testIsolation: 'off',
promptRemove.remove();

clusterList.waitForPage();
clusterList.list().state(this.rke1Ec2ClusterName).should('contain', 'Removing');
clusterList.sortableTable().checkRowCount(false, rows.length - 1);
clusterList.list().state(this.rke1Ec2ClusterName).contains('Removing', LONG_TIMEOUT_OPT);
clusterList.sortableTable().checkRowCount(false, rows.length - 1, MEDIUM_TIMEOUT_OPT);
clusterList.sortableTable().rowNames('.cluster-link').should('not.contain', this.rke1Ec2ClusterName);
});
});

after('clean up', () => {
// delete cluster: needed here in case the delete test fails
cy.deleteRancherResource('v1', 'provisioning.cattle.io.clusters', `fleet-default/${ clusterId }`, false);
if (removeNodeTemplate) {
// delete node template
cy.deleteNodeTemplate(nodeTemplateId).then(() => {
Expand Down
Loading

0 comments on commit df118f7

Please sign in to comment.