mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
add worker file push command
This commit is contained in:
parent
a23e4732b6
commit
01a8b2771a
@ -33,6 +33,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"angular-mocks": "~1.6.6",
|
||||
"archiver": "^2.1.1",
|
||||
"axios": "^0.16.2",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-istanbul": "^0.12.2",
|
||||
|
57
awx/ui/test/e2e/commands/pushFileToWorker.js
Normal file
57
awx/ui/test/e2e/commands/pushFileToWorker.js
Normal file
@ -0,0 +1,57 @@
|
||||
import { basename } from 'path';
|
||||
import { EventEmitter } from 'events';
|
||||
import { inherits } from 'util';
|
||||
|
||||
import archiver from 'archiver';
|
||||
|
||||
function pushFileToWorker (localFilePath, callback) {
|
||||
const name = basename(localFilePath);
|
||||
|
||||
const push = handler => {
|
||||
const archive = archiver('zip');
|
||||
|
||||
const buffers = [];
|
||||
|
||||
archive
|
||||
.on('data', data => buffers.push(data))
|
||||
.on('error', err => { throw err; })
|
||||
.on('finish', () => {
|
||||
const file = Buffer.concat(buffers).toString('base64');
|
||||
|
||||
this.api.session(session => {
|
||||
const params = {
|
||||
path: `/session/${session.sessionId}/file`,
|
||||
method: 'POST',
|
||||
data: { file },
|
||||
};
|
||||
|
||||
this.client.runProtocolAction(params, handler).send();
|
||||
});
|
||||
});
|
||||
|
||||
archive.file(localFilePath, { name });
|
||||
archive.finalize();
|
||||
};
|
||||
|
||||
push(({ status, value }) => {
|
||||
if (status !== 0) {
|
||||
throw new Error(value.message);
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback.call(this, value);
|
||||
}
|
||||
|
||||
this.emit('complete');
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
function PushFileToWorker () { EventEmitter.call(this); }
|
||||
|
||||
inherits(PushFileToWorker, EventEmitter);
|
||||
|
||||
PushFileToWorker.prototype.command = pushFileToWorker;
|
||||
|
||||
module.exports = PushFileToWorker;
|
@ -64,7 +64,9 @@ module.exports = {
|
||||
const { details } = credentials.section.add.section;
|
||||
const { gce } = details.section;
|
||||
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE);
|
||||
client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE, file => {
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', file);
|
||||
});
|
||||
|
||||
gce.expect.element('@email').not.enabled;
|
||||
gce.expect.element('@sshKeyData').not.enabled;
|
||||
@ -100,7 +102,9 @@ module.exports = {
|
||||
const { details } = credentials.section.add.section;
|
||||
const { gce } = details.section;
|
||||
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE_MISSING);
|
||||
client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE_MISSING, file => {
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', file);
|
||||
});
|
||||
|
||||
gce.expect.element('@email').not.enabled;
|
||||
gce.expect.element('@sshKeyData').not.enabled;
|
||||
@ -142,7 +146,9 @@ module.exports = {
|
||||
const { details } = credentials.section.add.section;
|
||||
const { gce } = details.section;
|
||||
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE_INVALID);
|
||||
client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE_INVALID, file => {
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', file);
|
||||
});
|
||||
|
||||
gce.expect.element('@email').not.enabled;
|
||||
gce.expect.element('@sshKeyData').not.enabled;
|
||||
@ -184,7 +190,9 @@ module.exports = {
|
||||
const add = credentials.section.add.section.details;
|
||||
const edit = credentials.section.edit.section.details;
|
||||
|
||||
add.section.gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE);
|
||||
client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE, file => {
|
||||
add.section.gce.section.serviceAccountFile.setValue('form input[type="file"]', file);
|
||||
});
|
||||
|
||||
add.section.gce.expect.element('@email').not.enabled;
|
||||
add.section.gce.expect.element('@sshKeyData').not.enabled;
|
||||
@ -224,7 +232,9 @@ module.exports = {
|
||||
gce.section.project.expect.element('@error').not.present;
|
||||
gce.section.serviceAccountFile.expect.element('@error').not.present;
|
||||
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE_ALT);
|
||||
client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE_ALT, file => {
|
||||
gce.section.serviceAccountFile.setValue('form input[type="file"]', file);
|
||||
});
|
||||
|
||||
gce.expect.element('@serviceAccountFile').enabled;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user