diff --git a/.github/workflows/master-e2e.yaml b/.github/workflows/master-e2e.yaml index e8fe0a8ee..960435d29 100644 --- a/.github/workflows/master-e2e.yaml +++ b/.github/workflows/master-e2e.yaml @@ -292,7 +292,7 @@ jobs: if: always() run: | # Remove all VMs - for I in $(sudo virsh list | awk '/node-/ { print $2 }'); do + for I in $(sudo virsh list --all| awk '/node-/ { print $2 }'); do for C in destroy undefine; do [[ "${C}" == "undefine" ]] && OPT="--nvram" || unset OPT sudo virsh ${C} ${OPT} ${I} >/dev/null 2>&1 || true diff --git a/cypress/e2e/unit_tests/machine_registration.spec.ts b/cypress/e2e/unit_tests/machine_registration.spec.ts index 2b5bd02d5..378a3fe2e 100644 --- a/cypress/e2e/unit_tests/machine_registration.spec.ts +++ b/cypress/e2e/unit_tests/machine_registration.spec.ts @@ -45,10 +45,6 @@ describe('Machine registration testing', () => { cy.createMachReg({machRegName: 'labels-annotations-test', checkLabels: true, checkAnnotations: true}); }); - it.skip('Create machine registration with custom cloud-config', () => { - // Cannot be tested yet due to https://github.com/rancher/dashboard/issues/6458 - }); - it('Delete machine registration', () => { cy.createMachReg({machRegName: 'delete-test'}); cy.deleteMachReg({machRegName: 'delete-test'}); @@ -98,4 +94,10 @@ describe('Machine registration testing', () => { cy.verifyDownload('download-yaml-test.yaml'); }); + // This test must stay the last one because we use this machine registration when we test adding a node. + // It also tests using a custom cloud config by using read from file button. + it('Create Machine registration we will use to test adding a node', () => { + cy.createMachReg({machRegName: 'machine-registration', checkInventoryLabels: true, checkInventoryAnnotations: true, customCloudConfig: 'custom_cloud-config.yaml'}); + cy.checkMachInvLabel({machRegName: 'machine-registration', labelName: 'myInvLabel1', labelValue: 'myInvLabelValue1'}); + }); }); diff --git a/cypress/e2e/unit_tests/machine_selector.spec.ts b/cypress/e2e/unit_tests/machine_selector.spec.ts index 20f08be29..59c46709f 100644 --- a/cypress/e2e/unit_tests/machine_selector.spec.ts +++ b/cypress/e2e/unit_tests/machine_selector.spec.ts @@ -42,8 +42,8 @@ describe('Machine selector testing', () => { // TODO: Cannot use the clickButton here, I do not know why yet cy.get('.mt-20 > .btn').contains('Add Rule').click(); cy.get('#vs6__combobox').click() - cy.contains('cypress').click(); - cy.get('[data-testid="input-match-expression-values-0"] > input').click().type('uitesting'); + cy.contains('myInvLabel1').click(); + cy.get('[data-testid="input-match-expression-values-0"] > input').click().type('myInvLabelValue1'); cy.contains('.banner', 'Matches all 1 existing Machine Inventories').should('exist'); }); }); diff --git a/cypress/fixtures/custom_cloud-config.yaml b/cypress/fixtures/custom_cloud-config.yaml new file mode 100644 index 000000000..5ae69077b --- /dev/null +++ b/cypress/fixtures/custom_cloud-config.yaml @@ -0,0 +1,10 @@ +config: + cloud-config: + users: + - name: root + passwd: root + elemental: + install: + poweroff: true + device: /dev/sda + debug: true diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 8c876f61e..db36825da 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -15,13 +15,17 @@ declare global { typeValue(label: string, value: string, noLabel?: boolean, log?: boolean): Chainable; typeKeyValue(key: string, value: string,): Chainable; getDetail(name: string, type: string, namespace?: string): Chainable; - createMachReg(machRegName: string, namespace?: string, checkLabels?: boolean, checkAnnotations?: boolean): Chainable; + createMachReg(machRegName: string, namespace?: string, checkLabels?: boolean, checkAnnotations?: boolean, customCloudConfig?: string): Chainable; deleteMachReg(machRegName: string): Chainable; deleteAllMachReg():Chainable; addMachRegLabel(labelName: string, labelValue: string):Chainable; checkMachRegLabel(machRegName: string, labelName: string, labelValue: string):Chainable; checkMachRegAnnotation(machRegName: string, annotationName: string, annotationValue: string):Chainable; addMachRegAnnotation(annotationName: string, annotationValue: string):Chainable; + addMachInvLabel(labelName: string, labelValue: string):Chainable; + checkMachInvLabel(machRegName: string, labelName: string, labelValue: string):Chainable; + checkMachInvAnnotation(machRegName: string, annotationName: string, annotationValue: string):Chainable; + addMachInvAnnotation(annotationName: string, annotationValue: string):Chainable; editMachReg(machRegName: string, addLabel?: boolean, addAnnotation?: boolean, withYAML?: boolean): Chainable; addHelmRepo(repoName: string, repoUrl: string, repoType?: string,): Chainable; } diff --git a/cypress/support/functions.ts b/cypress/support/functions.ts index 56955c9e8..c9ba2a7cb 100644 --- a/cypress/support/functions.ts +++ b/cypress/support/functions.ts @@ -1,3 +1,4 @@ +import 'cypress-file-upload'; // Generic functions // Log into Rancher @@ -118,7 +119,7 @@ Cypress.Commands.add('addHelmRepo', ({repoName, repoUrl, repoType}) => { // Machine registration functions // Create a machine registration -Cypress.Commands.add('createMachReg', ({machRegName, namespace='fleet-default', checkLabels=false, checkAnnotations=false}) => { +Cypress.Commands.add('createMachReg', ({machRegName, namespace='fleet-default', checkLabels=false, checkAnnotations=false, checkInventoryLabels=false, checkInventoryAnnotations=false, customCloudConfig=''}) => { cy.clickNavMenu(["Dashboard"]); cy.clickButton("Create Machine Registration"); if (namespace != "fleet-default") { @@ -130,6 +131,10 @@ Cypress.Commands.add('createMachReg', ({machRegName, namespace='fleet-default', cy.typeValue({label: 'Name', value: machRegName}); } + if (customCloudConfig != '') { + cy.get('input[type="file"]').attachFile({filePath: customCloudConfig}); + } + if (checkLabels) { cy.addMachRegLabel({labelName: 'myLabel1', labelValue: 'myLabelValue1'}); } @@ -138,6 +143,14 @@ Cypress.Commands.add('createMachReg', ({machRegName, namespace='fleet-default', cy.addMachRegAnnotation({annotationName: 'myAnnotation1', annotationValue: 'myAnnotationValue1'}); } + if (checkInventoryLabels) { + cy.addMachInvLabel({labelName: 'myInvLabel1', labelValue: 'myInvLabelValue1'}); + } + + if (checkInventoryAnnotations) { + cy.addMachInvAnnotation({annotationName: 'myInvAnnotation1', annotationValue: 'myInvAnnotationValue1'}); + } + cy.clickButton("Create"); // Make sure the machine registration is created and active @@ -181,6 +194,32 @@ Cypress.Commands.add('addMachRegAnnotation', ({annotationName, annotationValue}) cy.get('#machine-reg > .mb-10 > .key-value > .kv-container > .kv-item.value').type(annotationValue); }); +// Add Label to machine inventory +Cypress.Commands.add('addMachInvLabel', ({labelName, labelValue}) => { + cy.get('#machine-inventory').contains('Machine Inventories').click(); + cy.clickButton('Add Label'); + cy.get('#machine-inventory > .mb-30 > .key-value > .kv-container > .kv-item.key').type(labelName); + cy.get('#machine-inventory > .mb-30 > .key-value > .kv-container > .kv-item.value').type(labelValue); +}); + +// Add Annotation to machine inventory +Cypress.Commands.add('addMachInvAnnotation', ({annotationName, annotationValue}) => { + cy.get('#machine-inventory').contains('Machine Inventories').click(); + cy.clickButton('Add Annotation'); + cy.get('#machine-inventory > .mb-10 > .key-value > .kv-container > .kv-item.key').type(annotationName); + cy.get('#machine-inventory > .mb-10 > .key-value > .kv-container > .kv-item.value').type(annotationValue); +}); + +// Check machine inventory label in YAML +Cypress.Commands.add('checkMachInvLabel', ({machRegName, labelName, labelValue}) => { + cy.contains(machRegName).click(); + cy.get('div.actions > .role-multi-action').click() + cy.contains('li', 'Edit YAML').click(); + cy.contains('Machine Registration: '+ machRegName).should('exist'); + cy.contains(labelName + ': ' + labelValue); + cy.clickButton('Cancel'); +}); + // Check machine registration label in YAML Cypress.Commands.add('checkMachRegLabel', ({machRegName, labelName, labelValue}) => { cy.contains(machRegName).click(); diff --git a/tests/e2e/ui_test.go b/tests/e2e/ui_test.go index 37a347c57..599ca5e85 100644 --- a/tests/e2e/ui_test.go +++ b/tests/e2e/ui_test.go @@ -33,24 +33,7 @@ var _ = Describe("E2E - Bootstrap node for UI", Label("ui"), func() { ) It("Configure libvirt and bootstrap a node", func() { - By("Adding MachineRegistration", func() { - registrationYaml := "../assets/machineregistration.yaml" - - err := tools.Sed("%VM_NAME%", vmNameRoot, registrationYaml) - Expect(err).To(Not(HaveOccurred())) - - err = tools.Sed("%USER%", userName, registrationYaml) - Expect(err).To(Not(HaveOccurred())) - - err = tools.Sed("%PASSWORD%", userPassword, registrationYaml) - Expect(err).To(Not(HaveOccurred())) - - err = tools.Sed("%CLUSTER_NAME%", clusterName, registrationYaml) - Expect(err).To(Not(HaveOccurred())) - - err = kubectl.Apply(clusterNS, registrationYaml) - Expect(err).To(Not(HaveOccurred())) - + By("Downloading MachineRegistration", func() { tokenURL, err := kubectl.Run("get", "MachineRegistration", "--namespace", clusterNS, "machine-registration", "-o", "jsonpath={.status.registrationURL}")