Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use machine reg created in UI instead of the one in test assets #507

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/master-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions cypress/e2e/unit_tests/machine_registration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand Down Expand Up @@ -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'});
});
});
4 changes: 2 additions & 2 deletions cypress/e2e/unit_tests/machine_selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
10 changes: 10 additions & 0 deletions cypress/fixtures/custom_cloud-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config:
cloud-config:
users:
- name: root
passwd: root
elemental:
install:
poweroff: true
device: /dev/sda
debug: true
6 changes: 5 additions & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ declare global {
typeValue(label: string, value: string, noLabel?: boolean, log?: boolean): Chainable<Element>;
typeKeyValue(key: string, value: string,): Chainable<Element>;
getDetail(name: string, type: string, namespace?: string): Chainable<Element>;
createMachReg(machRegName: string, namespace?: string, checkLabels?: boolean, checkAnnotations?: boolean): Chainable<Element>;
createMachReg(machRegName: string, namespace?: string, checkLabels?: boolean, checkAnnotations?: boolean, customCloudConfig?: string): Chainable<Element>;
deleteMachReg(machRegName: string): Chainable<Element>;
deleteAllMachReg():Chainable<Element>;
addMachRegLabel(labelName: string, labelValue: string):Chainable<Element>;
checkMachRegLabel(machRegName: string, labelName: string, labelValue: string):Chainable<Element>;
checkMachRegAnnotation(machRegName: string, annotationName: string, annotationValue: string):Chainable<Element>;
addMachRegAnnotation(annotationName: string, annotationValue: string):Chainable<Element>;
addMachInvLabel(labelName: string, labelValue: string):Chainable<Element>;
checkMachInvLabel(machRegName: string, labelName: string, labelValue: string):Chainable<Element>;
checkMachInvAnnotation(machRegName: string, annotationName: string, annotationValue: string):Chainable<Element>;
addMachInvAnnotation(annotationName: string, annotationValue: string):Chainable<Element>;
editMachReg(machRegName: string, addLabel?: boolean, addAnnotation?: boolean, withYAML?: boolean): Chainable<Element>;
addHelmRepo(repoName: string, repoUrl: string, repoType?: string,): Chainable<Element>;
}
Expand Down
41 changes: 40 additions & 1 deletion cypress/support/functions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'cypress-file-upload';
// Generic functions

// Log into Rancher
Expand Down Expand Up @@ -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") {
Expand All @@ -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'});
}
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 1 addition & 18 deletions tests/e2e/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down