Skip to content

Commit

Permalink
feat(checks): Capability check for virtualization, local connector POC
Browse files Browse the repository at this point in the history
  • Loading branch information
ssmirr committed Dec 29, 2018
1 parent 90e156c commit be4cea2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 21 additions & 0 deletions lib/harness/local.js
@@ -1,5 +1,6 @@
const child_process = require('child_process');
const fs = require('fs-extra');
const os = require('os');

class LocalConnector {
async getContainerIp() {
Expand Down Expand Up @@ -74,6 +75,26 @@ class LocalConnector {
}
throw Error('file doesn\'t exist');
}

checkVT() {
let status = null;
if (os.platform() === 'win32') {
let output = child_process.execSync('systeminfo');
if (output && output.toString().indexOf('Virtualization Enabled In Firmware: Yes') !== -1) {
status = true;
} else {
status = false;
}
} else if (os.platform() === 'darwin') {
let output = child_process.execSync('sysctl -a | grep machdep.cpu.features');
if (output && output.toString().indexOf('VMX') !== -1) {
status = true;
} else {
status = false;
}
}
return status;
}
}

// Export factory class
Expand Down
4 changes: 4 additions & 0 deletions lib/harness/ssh.js
Expand Up @@ -139,6 +139,10 @@ class SSHConnector {

return contains === expect;
}

checkVT() {
return 'TODO'; // TODO: add shell command for checking virtualization.
}
}

// Export factory class
Expand Down
12 changes: 10 additions & 2 deletions lib/inspect/checks/capability.js
Expand Up @@ -7,10 +7,10 @@ class CapabilityCheck extends Check {
}

async check(context, args) {
return this.getCapability(context, args.cores, args.memory, args.disks || args.disk);
return this.getCapability(context, args.cores, args.memory, args.disks || args.disk, args.virtualization || args.vt);
}

async getCapability(context, expectedCores, expectedMemory, expectedDisks) {
async getCapability(context, expectedCores, expectedMemory, expectedDisks, expectedVT) {
let results = {
cores: {
expected: expectedCores,
Expand All @@ -22,6 +22,9 @@ class CapabilityCheck extends Check {
expected: expectedDisks && expectedDisks[0].size,
location: expectedDisks && expectedDisks[0].location,
},
vt: {
expected: expectedVT,
},
};

if (expectedCores) {
Expand All @@ -36,9 +39,14 @@ class CapabilityCheck extends Check {
results.disks.actual = await this.connector.exec(context, `df --output=avail -h ${expectedDisks[0].location} | grep -P '\\d+.\\d+' -o`);
}

if (expectedVT !== undefined) {
results.vt.actual = this.connector.checkVT();
}

results.cores.status = results.cores.expected <= results.cores.actual;
results.memory.status = results.memory.expected <= parseFloat(results.memory.actual) + 500;
results.disks.status = results.disks.expected <= parseFloat(results.disks.actual) + 0.5;
results.vt.status = results.vt.expected === results.vt.actual;

return results;
}
Expand Down

0 comments on commit be4cea2

Please sign in to comment.