-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: e2e tests for multi node clusters (#285)
* feat: add script to getting join token adds a script to be used in our e2e tests. this script generates a join token for a controller join token. ```bash scripts: ./generate-controller-join-token.js 192.168.86.6 opening a new tab acessing kotsadm on port 30000 waiting and clickin on the 'Continue to Setup' button waiting and clicking on 'Advanced' to move on with the certificate waiting and clicking on 'Proceed' to move on with the certificate going to the /tls endpoint waiting and clicking on 'Continue' waiting and clicking in the password field typing the password clicking in the Log in button waiting and clicking in the Cluster Management tab waiting and clicking in the Add node button waiting and clicking in the controller role waiting and fetching the node join command sudo ./ec node join 192.168.86.6:30000 59hKbnRkZmAbFFbkZ8WoOGZX scripts: ``` * chore: adding script for worker and controller join tokens * chore: add e2e test for multi node clusters
- Loading branch information
1 parent
04f4f71
commit 2139dea
Showing
5 changed files
with
493 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* this script has been generated with chrome recorder and then pasted here. | ||
* some parts were manually changed, these are flagged with a CUSTOM comment. | ||
* all logging has also been manually added (process.stderr.write() calls). | ||
* this script is meant to be run as an argument to the `puppeteer.sh` script. | ||
* THIS SCRIPT EXPECTS THE STEP TO ENABLE HTTPS ACCESS TO KOTS TO BE ALREADY | ||
* COMPLETED. YOU NEED TO RUN check-app-and-cluster-status.js BEFORE THIS. | ||
*/ | ||
|
||
const puppeteer = require('puppeteer'); // v20.7.4 or later | ||
|
||
(async () => { | ||
const browser = await puppeteer.launch( | ||
{ | ||
headless: 'new', | ||
// CUSTOM: added the following line to fix the "No usable sandbox!" error. | ||
args: ['--no-sandbox', '--disable-setuid-sandbox'], | ||
// CUSTOM: added ignore https errors. | ||
ignoreHTTPSErrors: true | ||
} | ||
); | ||
const page = await browser.newPage(); | ||
const timeout = 5000; | ||
page.setDefaultTimeout(timeout); | ||
const args = process.argv.slice(2); | ||
if (args.length !== 1) { | ||
throw new Error('usage: generate-controller-join-token.js <kotsadm-ip>'); | ||
} | ||
|
||
{ | ||
const targetPage = page; | ||
await targetPage.setViewport({ | ||
width: 1512, | ||
height: 761 | ||
}) | ||
} | ||
{ | ||
process.stderr.write("opening a new tab\n"); | ||
const targetPage = page; | ||
const promises = []; | ||
const startWaitingForEvents = () => { | ||
promises.push(targetPage.waitForNavigation()); | ||
} | ||
startWaitingForEvents(); | ||
await targetPage.goto('chrome://new-tab-page/'); | ||
await Promise.all(promises); | ||
} | ||
{ | ||
process.stderr.write("acessing kotsadm on port 30000 (HTTPS)\n"); | ||
const targetPage = page; | ||
const promises = []; | ||
const startWaitingForEvents = () => { | ||
promises.push(targetPage.waitForNavigation()); | ||
} | ||
startWaitingForEvents(); | ||
// CUSTOM: using the command line argument. | ||
await targetPage.goto(`https://${args[0]}:30000/`); | ||
await Promise.all(promises); | ||
} | ||
{ | ||
process.stderr.write("waiting and clicking in the password field\n"); | ||
const targetPage = page; | ||
await puppeteer.Locator.race([ | ||
targetPage.locator('::-p-aria(password)'), | ||
targetPage.locator('input'), | ||
targetPage.locator('::-p-xpath(//*[@id=\\"app\\"]/div/div[2]/div/div/div/div[2]/div/div/div[1]/input)'), | ||
targetPage.locator(':scope >>> input') | ||
]) | ||
.setTimeout(timeout) | ||
.click({ | ||
offset: { | ||
x: 80, | ||
y: 21.0078125, | ||
}, | ||
}); | ||
} | ||
{ | ||
process.stderr.write("typing the password\n"); | ||
const targetPage = page; | ||
await puppeteer.Locator.race([ | ||
targetPage.locator('::-p-aria(password)'), | ||
targetPage.locator('input'), | ||
targetPage.locator('::-p-xpath(//*[@id=\\"app\\"]/div/div[2]/div/div/div/div[2]/div/div/div[1]/input)'), | ||
targetPage.locator(':scope >>> input') | ||
]) | ||
.setTimeout(timeout) | ||
.fill('password'); | ||
} | ||
{ | ||
process.stderr.write("clicking in the Log in button\n"); | ||
const targetPage = page; | ||
await puppeteer.Locator.race([ | ||
targetPage.locator('::-p-aria(Log in)'), | ||
targetPage.locator('button'), | ||
targetPage.locator('::-p-xpath(//*[@id=\\"app\\"]/div/div[2]/div/div/div/div[2]/div/div/div[2]/button)'), | ||
targetPage.locator(':scope >>> button') | ||
]) | ||
.setTimeout(timeout) | ||
.click({ | ||
offset: { | ||
x: 30, | ||
y: 14.0078125, | ||
}, | ||
}); | ||
} | ||
{ | ||
process.stderr.write("waiting and clicking in the Cluster Management tab\n"); | ||
const targetPage = page; | ||
await puppeteer.Locator.race([ | ||
targetPage.locator('div:nth-of-type(3) > span'), | ||
targetPage.locator('::-p-xpath(//*[@id=\\"app\\"]/div/div[1]/div[1]/div[2]/div[3]/span)'), | ||
targetPage.locator(':scope >>> div:nth-of-type(3) > span'), | ||
targetPage.locator('::-p-text(Cluster Management)') | ||
]) | ||
.setTimeout(timeout) | ||
.click({ | ||
offset: { | ||
x: 108.734375, | ||
y: 28, | ||
}, | ||
}); | ||
} | ||
{ | ||
process.stderr.write("waiting and clicking in the Add node button\n"); | ||
const targetPage = page; | ||
await puppeteer.Locator.race([ | ||
targetPage.locator('::-p-aria(Add node)'), | ||
targetPage.locator('div.tw-flex > button'), | ||
targetPage.locator('::-p-xpath(//*[@id=\\"app\\"]/div/div[2]/div/div/div[1]/button)'), | ||
targetPage.locator(':scope >>> div.tw-flex > button'), | ||
targetPage.locator('::-p-text(Add node)') | ||
]) | ||
.setTimeout(timeout) | ||
.click({ | ||
offset: { | ||
x: 16.328125, | ||
y: 13, | ||
}, | ||
}); | ||
} | ||
{ | ||
process.stderr.write("waiting and clicking in the controller role\n"); | ||
const targetPage = page; | ||
await puppeteer.Locator.race([ | ||
targetPage.locator('div:nth-of-type(1) > label'), | ||
targetPage.locator('::-p-xpath(/html/body/div[5]/div/div/div/div[2]/div[1]/label)'), | ||
targetPage.locator(':scope >>> div:nth-of-type(1) > label') | ||
]) | ||
.setTimeout(timeout) | ||
.click({ | ||
offset: { | ||
x: 110, | ||
y: 27.5, | ||
}, | ||
}); | ||
} | ||
{ | ||
// CUSTOM: finding the element that contains the node join command. | ||
process.stderr.write("waiting and fetching the node join command\n"); | ||
const targetPage = page; | ||
await targetPage.waitForSelector('.react-prism.language-bash'); | ||
let elementContent = await targetPage.evaluate(() => { | ||
const element = document.querySelector('.react-prism.language-bash'); | ||
return element ? element.textContent : null; | ||
}); | ||
if (!elementContent) { | ||
throw new Error("Could not find the node join command"); | ||
} | ||
let result = { command: elementContent }; | ||
console.log(JSON.stringify(result)); | ||
} | ||
|
||
await browser.close(); | ||
|
||
})().catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.