Skip to content

Commit

Permalink
Use real image building API to build image
Browse files Browse the repository at this point in the history
1. move image building test to a separate file. So the tier-x test
can ignore this test by excluding this file.
2. add all configurable settings before build image to increase
test coverage
  • Loading branch information
henrywang authored and martinpitt committed Jun 3, 2019
1 parent 2ce93c6 commit ee8f3d4
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 70 deletions.
17 changes: 15 additions & 2 deletions test/end-to-end/pages/ViewBlueprint.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,14 @@ class ViewBlueprintPage {
}

get completeLebel() {
// image building needs times to complete, so increase timeout to 40 minutes
// and checking interval to 2 seconds
const selector = "span=Complete";
browser.waitUntil(
() => browser.isExisting(selector),
timeout,
`Complete label under Images tab in View Blueprint page cannot be found by selector ${selector}`
timeout * 20,
`Complete label under Images tab in View Blueprint page cannot be found by selector ${selector}`,
2000
);
return $(selector);
}
Expand All @@ -376,6 +379,16 @@ class ViewBlueprintPage {
return $(selector);
}

get imageDownloadButton() {
const selector = '.list-pf-actions [download=""]';
browser.waitUntil(
() => browser.isExisting(selector),
timeout,
`Download button under Images tab in View Blueprint page cannot be found by selector ${selector}`
);
return $(selector);
}

get stopButton() {
const selector = "span=Stop";
browser.waitUntil(
Expand Down
135 changes: 135 additions & 0 deletions test/end-to-end/specs/imageBuilding.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
const faker = require("faker");
const commands = require("../utils/commands");

const Blueprint = require("../components/Blueprint.component");
const blueprintsPage = require("../pages/blueprints.page");
const ViewBlueprintPage = require("../pages/ViewBlueprint.page");
const createUserAccount = require("../pages/createUserAccount.page");
const CreateImagePage = require("../pages/CreateImage.page");
const ToastNotificationPage = require("../pages/ToastNotification.page");
const deleteImagePage = require("../pages/deleteImage.page");

describe("View Blueprint Page", function() {
const name = faker.lorem.slug();
const description = faker.lorem.sentence();
const blueprintComponent = new Blueprint(name);
const viewBlueprintPage = new ViewBlueprintPage(name, description);
const createImagePage = new CreateImagePage(name);
const toastNotificationPage = new ToastNotificationPage("imageWaiting");

before(function() {
commands.login();
commands.startLoraxIfItDoesNotStart();

// create new blueprint with openssh-server installed
commands.newBlueprint(name, description);
blueprintComponent.blueprintNameLink.click();
viewBlueprintPage.loading();

// set hostname
const hostname = faker.lorem.slug();
viewBlueprintPage.editHostnameButton.click();
viewBlueprintPage.hostnameInputBox.setValue(hostname);
viewBlueprintPage.okHostnameButton.click();

// add user admin with password and public key configured
const username = "admin";
const password = "123qwe!@#QWE";
const sshKey =
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhbIOLUndK2150PwjZqxEmYC/b0z1isMFUXyJ0n2Pl0gJoFk28WDJ4tNMBraqAGyxqHv2YyqaJEY54ne0Pb085b9+0bOiBWp7rRhzRUwOdYrMRYE6zAow4lPPKVu0cY/a2uIzXmGz6meK7nSZ3g+0cfsfs2z6vJ/ip/tgbNM6XCSmI63N0QezEUy8dxDLrA0C4PrTq3QPMF+lvi8njt6B/k6f3AzqcsIldN0MULBI3Hp98cjBkmhFS4ZFZ/EAe6ePPOezVorAxC/C/X/76mcbsJpEke9Cn0EPPbCODIa+tVXyZRYCK0l4pU4h5ShinQI0yvYA9Y3NcFyChRk25RAuR [email protected]";
viewBlueprintPage.createUserAccountButton.click();
createUserAccount.loading();
createUserAccount.userNameBox.setValue(username);
createUserAccount.fullNameBox.setValue(username);
createUserAccount.roleCheckbox.click();
createUserAccount.passwordBox.setValue(password);
createUserAccount.confirmPasswordBox.setValue(password);
createUserAccount.sshKeyBox.setValue(sshKey);
createUserAccount.createButton.click();
browser.waitForExist(createUserAccount.containerSelector, timeout, true);
browser.waitForExist(`[data-tr=${username}] [data-td=username]`);

// create tar image
viewBlueprintPage.createImageButton.click();
createImagePage.loading();
createImagePage.imageTypeSelect.selectByValue("tar");
createImagePage.createButton.waitForEnabled(timeout);
createImagePage.createButton.click();
browser.waitForExist(createImagePage.containerSelector, timeout, true);
toastNotificationPage.loadingInfoNotification();
toastNotificationPage.close();
viewBlueprintPage.imagesTab.click();
});

after(function() {
// delete image
viewBlueprintPage.imageMoreButton.click();
browser.keys("ArrowDown");
browser.keys("Enter");
deleteImagePage.loading();
deleteImagePage.deleteImageButton.click();
browser.waitForExist(deleteImagePage.containerSelector, timeout, true);

// delete blueprint
viewBlueprintPage.backToBlueprintsLink.click();
blueprintsPage.loading();
commands.deleteBlueprint(name);
blueprintsPage.loading();
});

it(`image name should contain blueprint name "${name}" and type "tar"`, function() {
expect(viewBlueprintPage.imageNameLabel.getText())
.to.include(name)
.and.include("tar");
});

it("image type should be tar", function() {
expect(viewBlueprintPage.imageTypeLabel("tar").getText()).to.equal("tar");
});

it('should show "Complete"', function() {
// set test timeout to 40 minutes for image building case ONLY
this.timeout(timeout * 20);
expect(viewBlueprintPage.completeLebel.getText()).to.equal("Complete");
});

it("should show correct Complete icon", function() {
expect(viewBlueprintPage.completeIcon.getAttribute("class")).to.include("pficon-ok");
});

it("should show correct download API in download link", function() {
const link = viewBlueprintPage.imageDownloadButton.getAttribute("href");
console.log(link);
const jsonStr = link.split("?")[1];

// decode base64 to json
const jsonObj = JSON.parse(Buffer.from(jsonStr, "base64").toString("ascii"));

// get blueprint info from API
const endpoint = `/api/v0/compose/status/*?blueprint=${name}`;
const result = commands.apiFetchTest(endpoint).value;
// result looks like:
// https://github.com/weldr/lorax/blob/b57de934681056aa4f9bd480a34136cf340f510a/src/pylorax/api/v0.py#L819
const uuid = JSON.parse(result.data).uuids[0].id;

expect(jsonObj.path).to.equal(`/api/v0/compose/image/${uuid}`);
expect(jsonObj.unix).to.equal("/run/weldr/api.socket");
});

describe("Delete Image Page", function() {
before(function() {
viewBlueprintPage.imageMoreButton.click();
browser.keys("ArrowDown");
browser.keys("Enter");
deleteImagePage.loading();
});

after(function() {
deleteImagePage.cancelButton.click();
browser.waitForExist(deleteImagePage.containerSelector, timeout, true);
});
it("Delete Image page should show correct blueprint name", function() {
expect(deleteImagePage.messageLabel.getText()).to.include(name);
});
});
});
64 changes: 0 additions & 64 deletions test/end-to-end/specs/viewBlueprint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,69 +182,5 @@ describe("View Blueprint Page", function() {
expect(viewBlueprintPage.selectedComponentFilter.getValue()).to.equal(blueprintManifest);
});
});

describe("Create Image", function() {
const CreateImagePage = require("../pages/CreateImage.page");
const ToastNotificationPage = require("../pages/ToastNotification.page");
const deleteImagePage = require("../pages/deleteImage.page");
const createImagePage = new CreateImagePage(name);
const toastNotificationPage = new ToastNotificationPage("imageWaiting");

before(function() {
viewBlueprintPage.createImageButton.click();
createImagePage.loading();
createImagePage.imageTypeSelect.selectByValue("tar");
createImagePage.createButton.waitForEnabled(timeout);
createImagePage.createButton.click();
browser.waitForExist(createImagePage.containerSelector, timeout, true);
toastNotificationPage.loadingInfoNotification();
toastNotificationPage.close();
viewBlueprintPage.imagesTab.click();
});

after(function() {
viewBlueprintPage.imageMoreButton.click();
browser.keys("ArrowDown");
browser.keys("Enter");
deleteImagePage.loading();
deleteImagePage.deleteImageButton.click();
browser.waitForExist(deleteImagePage.containerSelector, timeout, true);
});

it(`image name should contain blueprint name "${name}" and type "tar"`, function() {
expect(viewBlueprintPage.imageNameLabel.getText())
.to.include(name)
.and.include("tar");
});

it("image type should be tar", function() {
expect(viewBlueprintPage.imageTypeLabel("tar").getText()).to.equal("tar");
});

it('should show "Complete"', function() {
expect(viewBlueprintPage.completeLebel.getText()).to.equal("Complete");
});

it("should show correct Complete icon", function() {
expect(viewBlueprintPage.completeIcon.getAttribute("class")).to.include("pficon-ok");
});

describe("Delete Image Page", function() {
before(function() {
viewBlueprintPage.imageMoreButton.click();
browser.keys("ArrowDown");
browser.keys("Enter");
deleteImagePage.loading();
});

after(function() {
deleteImagePage.cancelButton.click();
browser.waitForExist(deleteImagePage.containerSelector, timeout, true);
});
it("Delete Image page should show correct blueprint name", function() {
expect(deleteImagePage.messageLabel.getText()).to.include(name);
});
});
});
});
});
2 changes: 1 addition & 1 deletion test/end-to-end/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
browser.keys("Enter");
// make sure new availabe components for new page loaded
editBlueprintPage.loading();
const filterContent = "httpd";
const filterContent = "openssh-server";
editBlueprintPage.filterBox.setValue(filterContent);
browser.keys("Enter");
browser.waitForExist(editBlueprintPage.filterContentLabel, timeout);
Expand Down
3 changes: 0 additions & 3 deletions test/vm.install
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ fi
# Install nodejs if it does not exist
which node > /dev/null 2>&1 || yum install -y nodejs

# mock compose creation calls to backend for testing purposes
sed -i "s|\"/api/v0/compose\"|\"/api/v0/compose?test=2\"|" /usr/share/cockpit/welder/main.js

# disable https in cockpit and use http instead
printf "[WebService]\\nAllowUnencrypted=true\\n" > /etc/cockpit/cockpit.conf

Expand Down

0 comments on commit ee8f3d4

Please sign in to comment.