From ed163c193c8f54d8c89c3d424a4708846c93e1bc Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Thu, 6 May 2021 16:35:38 +0530 Subject: [PATCH] mgr/dashboard: add Services e2e tests Fixes: https://tracker.ceph.com/issues/50567 Signed-off-by: Avan Thakkar Introducing e2e tests for service creation for Ingress and RGW service types. --- .../integration/cluster/services.po.ts | 86 +++++++++++++++++++ .../orchestrator/05-services.e2e-spec.ts | 29 +++++++ .../service-form/service-form.component.html | 1 + .../cluster/services/services.component.ts | 11 +-- 4 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts create mode 100644 src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/05-services.e2e-spec.ts diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts new file mode 100644 index 0000000000000..18b17c2f23ea4 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts @@ -0,0 +1,86 @@ +import { PageHelper } from '../page-helper.po'; + +const pages = { + index: { url: '#/services', id: 'cd-services' }, + create: { url: '#/services/create', id: 'cd-service-form' } +}; + +export class ServicesPageHelper extends PageHelper { + pages = pages; + + columnIndex = { + service_name: 2, + container_image_name: 3, + container_image_id: 4, + placement: 5, + running: 6, + size: 7, + last_refresh: 8 + }; + + check_for_service() { + this.getTableCount('total').should('not.be.eq', 0); + } + + private selectServiceType(serviceType: string) { + return this.selectOption('service_type', serviceType); + } + + @PageHelper.restrictTo(pages.create.url) + addService(serviceType: string, exist?: boolean) { + cy.get(`${this.pages.create.id}`).within(() => { + this.selectServiceType(serviceType); + if (serviceType === 'rgw') { + cy.get('#service_id').type('rgw.foo'); + cy.get('#count').type('1'); + } else if (serviceType === 'ingress') { + this.selectOption('backend_service', 'rgw.rgw.foo'); + cy.get('#service_id').type('rgw.rgw.foo'); + cy.get('#virtual_ip').type('192.168.20.1/24'); + cy.get('#frontend_port').type('8081'); + cy.get('#monitor_port').type('8082'); + } + + cy.get('cd-submit-button').click(); + }); + if (exist) { + cy.get('#service_id').should('have.class', 'ng-invalid'); + } else { + // back to service list + cy.get(`${this.pages.index.id}`); + } + } + + @PageHelper.restrictTo(pages.index.url) + checkExist(serviceName: string, exist: boolean) { + this.getTableCell(this.columnIndex.service_name, serviceName).should(($elements) => { + const services = $elements.map((_, el) => el.textContent).get(); + if (exist) { + expect(services).to.include(serviceName); + } else { + expect(services).to.not.include(serviceName); + } + }); + } + + @PageHelper.restrictTo(pages.index.url) + deleteService(serviceName: string, wait: number) { + const getRow = this.getTableCell.bind(this, this.columnIndex.service_name); + getRow(serviceName).click(); + + // Clicks on table Delete button + this.clickActionButton('delete'); + + // Confirms deletion + cy.get('cd-modal .custom-control-label').click(); + cy.contains('cd-modal button', 'Delete').click(); + + // Wait for modal to close + cy.get('cd-modal').should('not.exist'); + + // wait for delete operation to complete: tearing down the service daemons + cy.wait(wait); + + this.checkExist(serviceName, false); + } +} diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/05-services.e2e-spec.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/05-services.e2e-spec.ts new file mode 100644 index 0000000000000..dec84d73562d8 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/05-services.e2e-spec.ts @@ -0,0 +1,29 @@ +import { ServicesPageHelper } from '../cluster/services.po'; + +describe('Services page', () => { + const services = new ServicesPageHelper(); + + beforeEach(() => { + cy.login(); + Cypress.Cookies.preserveOnce('token'); + services.navigateTo(); + }); + + describe('when Orchestrator is available', () => { + it('should create an rgw service', () => { + services.navigateTo('create'); + services.addService('rgw'); + + services.checkExist('rgw.rgw.foo', true); + }); + + it('should create and delete an ingress service', () => { + services.navigateTo('create'); + services.addService('ingress'); + + services.checkExist('ingress.rgw.rgw.foo', true); + + services.deleteService('ingress.rgw.rgw.foo', 5000); + }); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 4774299b78d93..a0df3a5d4b0a7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -14,6 +14,7 @@ i18n>Type