Example #1
0
/*
 * Runs through a bunch of checks common to all jobs, starting with the
 * assertion that the job has completed.  If the job hasn't finished running,
 * then we'll retry this whole process.  Most other errors result an immediate
 * test case failure.
 *
 * To keep the code relatively clean, we fetch everything about the job (its
 * state; the lists of inputs, errors, outputs; output object contents; the list
 * of objects under the job's directory; and metering records) before doing any
 * other verification.  That way, jobTestVerifyResult() has everything it might
 * need handy.
 */
function jobTestVerify(api, testspec, jobid, options, callback)
{
	mod_vasync.pipeline({
	    'arg': {
		'strict': options['strict'],
		'api': api,
		'testspec': testspec,
		'jobid': jobid,
		'job': undefined,
		'objects_found': [],
		'inputs': [],
		'outputs': [],
		'errors': [],
		'content': [],
		'metering': null
	    },
	    'funcs': [
		jobTestVerifyFetchJob,
		jobTestVerifyFetchInputs,
		jobTestVerifyFetchErrors,
		jobTestVerifyFetchOutputs,
		jobTestVerifyFetchOutputContent,
		jobTestVerifyFetchObjectsFound,
		jobTestVerifyFetchMeteringRecords,
		jobTestVerifyResult
	    ]
	}, callback);
}
Example #2
0
setImmediate(function
main()
{
	var log = mod_bunyan.createLogger({
		name: 'fmaweb',
		level: process.env.LOG_LEVEL || mod_bunyan.INFO,
		serializers: mod_bunyan.stdSerializers
	});

	var ctx = {
		ctx_log: log,
		ctx_server: null,
	};

	mod_vasync.pipeline({ arg: ctx, funcs: [
		create_server,

	]}, function (err) {
		if (err) {
			log.fatal(err, 'startup failure');
			process.exit(1);
		}

		log.info('startup ok');
	});
});
Example #3
0
App.prototype.listen = function (callback) {
    var self = this;
    var adminIp = self.getAdminIp();
    var useTls = self.config.useTls;
    var serverPort = useTls ? self.config.port + 1 : self.config.port;
    var serverType = useTls ? 'https' : 'http';

    vasync.pipeline({
        funcs: [
            function startPublicServer(_, next) {
                self.server.listen(serverPort, next);
            },
            function startAdminServer(_, next) {
                self.admin.listen(80, adminIp, next);
            }
        ]
    }, function (err, results) {
        if (err) {
            self.log.error(err, 'Error starting server');
        } else {
            var addr = self.server.address();
            var adminAddr = self.admin.address();
            self.log.info('Started %s docker.js server on <%s://%s:%s>',
                serverType.toUpperCase(), serverType, addr.address, addr.port);
            self.log.info('Started admin server on <http://%s:%s>',
                adminAddr.address, adminAddr.port);
        }
    });
};
Example #4
0
    ]}, function finishUp(err) {
        vasync.pipeline({funcs: [
            function dropLock(_, next) {
                if (!unlock) {
                    return next();
                }
                self.sdcadm.releaseLock({unlock: unlock}, next);
            }
        ]}, function done(finishUpErr) {
            // We shouldn't ever get a `finishUpErr`. Let's be loud if we do.
            if (finishUpErr) {
                self.log.fatal({err: finishUpErr},
                    'unexpected error finishing up update');
            }
            if (err || finishUpErr) {
                return cb(err || finishUpErr);
            }

            if (plan.procs.length === 0) {
                if (opts.just_images) {
                    p('Up-to-date (all images are imported).');
                } else {
                    p('Up-to-date.');
                }
            } else {
                p('Updated successfully (elapsed %ds).',
                    Math.floor((Date.now() - execStart) / 1000));
            }
            cb();
        });
    });
Example #5
0
function loadPwdPolicy(req, entry, callback) {
    // When no specific pwdPolicy is set for the given account, we want
    // the global pwdPolicy. But when we're talking about sub-users, then
    // we want to lookup for account policy before default to global.

    var arg = {
        // Set it to the default first:
        key: 'cn=pwdpolicy, ' + req.suffix
    };

    vasync.pipeline({
        arg: arg,
        funcs: [
            function checkIfAccountKeyExists(ctx, next) {
                if (req._entry && req.suffix !== req._entry._parent[0]) {
                    ctx.account_key = 'cn=pwdpolicy, ' + req._entry._parent[0];
                }

                if (!ctx.account_key) {
                    next();
                    return;
                }
                req.exists(req.bucket, ctx.account_key, function (err, exists) {
                    if (err) {
                        next(err);
                        return;
                    }

                    if (exists) {
                        ctx.key = ctx.account_key;
                    }
                    next();
                });
            },
            function getPolicyByKey(ctx, next) {
                // If it's explicitly overriden, take that value and move
                // forward:
                if (entry.pwdpolicysubentry &&
                    entry.pwdpolicysubentry.length !== 0) {
                    ctx.key = entry.pwdpolicysubentry;
                }

                req.get(req.bucket, ctx.key, function (err, val) {
                    if (err) {
                        next(err);
                        return;
                    }
                    ctx.value = val.value;
                    next();
                });
            }
        ]
    }, function pipeCb(pipeErr) {
        if (pipeErr) {
            callback(pipeErr);
            return;
        }
        callback(null, arg.value);
    });
}
Example #6
0
test('teardown', function (t) {
    vasync.pipeline({
        funcs: [
            function cleanupData(_, cb) {
                helper.cleanup(SUFFIX, function (err) {
                    t.ifError(err);
                    cb(err);
                });
            },
            function destroyClient(_, cb) {
                CAPI.close();
                cb();
            },
            function destroyServer(_, cb) {
                helper.destroyCAPIServer(SERVER, cb);
            },
            function destroyUFDS(_, cb) {
                helper.destroyServer(UFDS_SERVER, cb);
            }
        ]
    }, function (err, result) {
        if (err) {
            t.ifError(err);
        }
        t.end();
    });
});
Example #7
0
AmonAdm.prototype.do_alarm = function do_alarm(_, opts, args, cb) {
    if (!args.length) {
        cb(new Error('At least one alarm id required'));
        return;
    }
    vasync.pipeline({
        funcs: COMMON_FUNCS.concat([
            amonadm.list_alarms,
            amonadm.filter_alarms,
            function print(__, _cb) {
                var alarms = [];
                args.forEach(function (id) {
                    id = parseInt(id, 10);
                    opts.alarms.forEach(function (a) {
                        a.id = parseInt(a.id, 10);
                        if (a.id === id)
                            alarms.push(a);
                    });
                });
                console.log(JSON.stringify(alarms, null, 2));
                _cb();
            }
        ]),
        arg: opts
    }, once(cb));
};
Example #8
0
AmonAdm.prototype.do_probes = function do_probes(_, opts, args, cb) {
    vasync.pipeline({
        funcs: COMMON_FUNCS.concat([
            amonadm.list_probes,
            amonadm.filter_probes,
            function print(__, _cb) {
                var fmt = '%-18s %-8s %-8s %s';
                if (!opts.H) {
                    var h = sprintf(fmt, 'ROLE', 'MACHINE', 'PROBE', 'NAME');
                    console.log(h);
                }

                opts.probes.forEach(function (p) {
                    console.log(sprintf(fmt,
                                        // TODO: make sure we always have a role
                                        p.role || '', // Role can be absent
                                        p.agent.substr(0, 7),
                                        p.uuid.substr(0, 7),
                                        p.name));
                });

                _cb();
            }
        ]),
        arg: opts
    }, once(cb));
};
Example #9
0
test('unknown peer', function (t) {
    var mb;
    var peers = getTopology(2);
    var funcs = [
        function init(_, subcb) {
            mb = new lib.MessageBus({ 'log': LOG, 'peers': peers });
            mb.on('ready', subcb);
        },
        function causeError(_, subcb) {
            var gMessageId;
            function onResponse(err, messageId, from) {
                t.ok(err);
                t.equal('InvalidPeerError', err.name);
                t.equal(0, Object.keys(mb.messages).length);
                t.equal(messageId, gMessageId);
                t.equal('2', from);
                return (subcb());
            }
            gMessageId =
                mb.send('me', '2', { 'operation': 'fake' }, onResponse);
        }
    ];
    vasync.pipeline({
        funcs: funcs
    }, function (err) {
        if (err) {
            t.fail(err);
        }
        t.done();
    });
});
 tt.test('docker compose up should succeed', function (t) {
     vasync.pipeline({arg: {}, funcs: [
         function composeUp(ctx, next) {
             composeCli(COMPOSE_FILE, {
                 args: '-p ' + COMPOSE_PROJECT_NAME + ' up -d',
                 user: ALICE_USER
             }, function onComposeUp(composeUpErr, stdout, stderr) {
                 t.ifErr(composeUpErr,
                     'compose up should not error');
                 next(composeUpErr);
             });
         },
         function checkVolumeExists(ctx, next) {
             VOLAPI_CLIENT.listVolumes({
                 name: volumeName,
                 owner_uuid: ALICE_USER.account.uuid,
                 state: 'ready'
             }, function onListVols(listVolsErr, vols) {
                 t.ifErr(listVolsErr, 'Listing volumes with name '
                     + volumeName + ' should not error');
                 t.ok(vols, 'result should not be empty');
                 if (vols) {
                     t.equal(vols.length, 1,
                             'only one volume should be present');
                 }
                 next(listVolsErr);
             });
         }
     ]}, function onDone(err) {
         t.end();
     });
 });
Example #11
0
 fs.readFile(commentFile, 'utf-8', function addComment(err, data) {
     if (err) {
         cb(new Error('unable to read file: ' + err));
         return;
     }
     vasync.pipeline(
         {
             arg: context,
             funcs: [
                 function commentIssue(ctx, next) {
                     ctx.cli.jirashApi.commentIssue(
                         {
                             issueIdOrKey: key,
                             issueComment: data
                         },
                         function onIssue(ierr, issue) {
                             ctx.issue = issue;
                             next(ierr);
                         }
                     );
                 }
             ]
         },
         cb
     );
 });
Example #12
0
        backend.init(function () {
            // PAPI-2: Create default SDC Packages here
            if (config.first_boot) {
                return vasync.pipeline({
                    funcs: [
                        createSDCPackages,
                        getMetadata,
                        updateMetadata
                    ],
                    arg:  {
                        log: log,
                        url: config.sapi.url,
                        backend: backend
                    }
                }, function (err, results) {
                    if (err) {
                        log.error({ err: err }, 'first_boot');
                    } else {
                        log.info({ results: results }, 'first_boot');
                    }

                    return callback(null, server);
                });
            } else {
                return callback(null, server);
            }
        });
Example #13
0
ZKClient.prototype.put = function put(p, object, options, callback) {
        assert.string(p, 'path');
        assert.object(object, 'object');
        if (typeof (options) === 'function') {
                callback = options;
                options = {};
        }
        assert.object(options, 'options');
        assert.func(callback, 'callback');

        callback = once(callback);

        var exists;
        var log = this.log;
        var _p = path.normalize(p);
        var self = this;
        var tasks = [
                function checkIfExists(_, cb) {
                        cb = once(cb);
                        log.trace('put: checking %s', _p);
                        self.stat(_p, function (err, _stat) {
                                if (err && err.code !== ZK.ZNONODE) {
                                        cb();
                                }
                                exists = _stat ? true : false;
                                log.trace('put: %s exists= ', _p, exists);
                                cb();
                        });
                },

                function putIfNotExists(_, cb) {
                        cb = once(cb);
                        if (exists) {
                                cb();
                        } else {
                                log.trace('put: creating ', _p);
                                self.create(_p, options, cb);
                        }
                },

                function set(_, cb) {
                        self.update(_p, object, once(cb));
                }
        ];

        log.trace({
                path: p,
                object: object,
                options: options
        }, 'put: entered');
        vasync.pipeline({funcs: tasks}, function (err) {
                if (err) {
                        log.error(err, 'put: failed');
                        callback(err);
                } else {
                        log.trace('put: completed');
                        callback(null);
                }
        });
};
Example #14
0
function _getPackage(volumeParams, options, callback) {
    assert.object(volumeParams, 'volumeParams');
    assert.object(options, 'options');
    assert.object(options.log, 'options.log');
    assert.func(callback, 'callback');

    var papiClient = options.papiClient;
    assert.object(papiClient, 'papiClient');

    var context = {};
    vasync.pipeline({
        funcs: [
            function getNfsSharedVolumesPackages(ctx, next) {
                papiClient.list({}, {
                    name: 'nfs_shared_volume*'
                }, function onListDone(err, pkgs, count) {
                    ctx.nfsSharedVolumesPkgs = pkgs;
                    next(err);
                });
            },
            function selectBestPackage(ctx, next) {
                _selectBestPackage(volumeParams, ctx.nfsSharedVolumesPkgs,
                    options, function onBestPackageSelected(err, bestPackage) {
                        ctx.bestPackage = bestPackage;
                        next(err);
                    });
            }
        ],
        arg: context
    }, function onBestPackageSelect(err) {
        callback(err, context.bestPackage);
    });
}
Example #15
0
/*
 * Get a `*DockerEnv` wrapper for a given account, setting it up in the DC
 * if necessary.
 *
 * @params opts
 *      - account {String} Account name to setup.
 */
function getDockerEnv(t, state_, opts, cb) {
    var env;

    vasync.pipeline({arg: state_, funcs: [
        /*
         * Set `state.runningFrom` to 'gz' (from the headnode global zone)
         * or 'remote'.
         */
        function runningFromWhere(state, next) {
            if (os.type() !== 'SunOS') {
                state.runningFrom = 'remote';
                return next();
            }

            common.execPlus({
                command: '/usr/bin/zonename',
                log: state.log
            }, function (err, stdout, stderr) {
                if (err) {
                    return next(err);
                }
                var zonename = stdout.replace(/\s+$/g, '');
                if (zonename !== 'global') {
                    state.runningFrom = 'remote';
                } else {
                    state.runningFrom = 'gz';
                }
                next();
            });
        },

        function getHeadnodeSsh(state, next) {
            if (state.runningFrom !== 'remote') {
                return next();
            }

            // For now assume coal.
            state.headnodeSsh = 'root@10.99.99.7';
            next();
        },


        function getEnv(state, next) {
            var envClass = {
                remote: LocalDockerEnv,
                gz: GzDockerEnv
            }[state.runningFrom];
            env = new envClass(t, state, opts);
            env.init(t, state, next);
        }

    ]}, function (err) {
        if (err) {
            cb(err);
        } else {
            cb(null, env);
        }
    });

}
Example #16
0
    function reserveNicIP(nic, callback) {
        // TODO: Can we have multiple ip per nic?
        var ip = nic.ip;
        var mac = nic.mac;
        var network_uuid = nic.network_uuid;

        if (!mac) {
            callback(new Error('No mac for nic: ' + nic));
            return;
        }

        vasync.pipeline({arg: {}, funcs: [
            function getNetworkUuid(ctx, next) {
                if (ip && network_uuid) {
                    next();
                    return;
                }
                napi.getNic(mac, function _onGetNic(err, nicDetails) {
                    if (err) {
                        next(err);
                        return;
                    }
                    ip = nicDetails.ip;
                    network_uuid = nicDetails.network_uuid;
                });
            },

            function reserveIP(ctx, next) {
                if (!ip || !network_uuid) {
                    next(new Error('No ip or no network_uuid for nic: ' + nic));
                    return;
                }

                // Check if the IP is already reserved.
                napi.getIP(network_uuid, ip, function _onGetIpCb(err, ipObj) {
                    if (err) {
                        next(err);
                        return;
                    }
                    if (ipObj.reserved) {
                        next();
                        return;
                    }

                    // Reserve the IP address.
                    napi.updateIP(network_uuid, ip, {reserved: true},
                            function _onReserveIpCb(updateErr) {
                        if (updateErr) {
                            next(updateErr);
                            return;
                        }
                        // Keep a record of the ip that were reserved.
                        job.migration_reserved_nics.push(
                            {network_uuid: network_uuid, ip: ip});
                        next();
                    });
                });
            }
        ]}, callback);
    }
Example #17
0
    util_common.repeat(function (cb) {
        // Reset opts.{batch,ips} - it is the responsibility for functions in
        // the pipeline to re-add their batch data each time through the loop.
        opts.batch = [];
        opts.ips = [];

        vasync.pipeline({
            arg: opts,
            funcs: [
                // 1. Determine what IPs to provision and batch them.
                runProvisions,

                // 2. Locate the CNs we need to inform of overlay IP changes.
                listVnetCns,

                // 3. Free any addresses we no longer need.
                freeOldIPs,

                // 4. Using our IPs, create the NIC object.
                opts.nicFn,

                // 5. Batch the NIC.
                nicBatch,

                // 6. Commit everything in our batch.
                common.commitBatch
            ]
        }, function (err) {
            if (err) {
                opts.log.warn({ err: err, final: err.stop }, 'error in repeat');
                if (err.stop || retries > constants.NIC_PROVISION_RETRIES) {
                    // No more to be done:
                    cb(err, null, false);
                    return;
                }

                /*
                 * Unfortunately we don't have a great way to classify errors
                 * here, so we can't really tell what's fatal/non-fatal. Most
                 * errors are non-fatal (EtagConflictErrors, errors connecting
                 * to Moray, Moray errors connecting to Postgres, etc.), so we
                 * retry. We limit the number of retries that we do so that we
                 * not only eventually terminate, but also avoid running up the
                 * Postgres sequence that Moray uses on each bucket.
                 */
                retries += 1;

                /*
                 * Save the error so that the pipeline functions can determine
                 * if they need to select new values for the provision.
                 */
                opts.err = err;

                cb(null, null, true);
                return;
            }

            cb(null, opts.nic, false);
        });
    }, function (err, res) {
Example #18
0
            func: function createTreeItem(item, next) {
                log.trace({ item: item }, 'create test tree item');

                switch (item.type) {
                case 'directory':
                    forkExecWait({argv: [MMKDIR, '-p', item.path]}, next);
                    return;

                case 'object':
                    /*
                     * Would like a 'stdin' option to `forkExecWait`. For now
                     * I'll quick hack with a local file. An alternative would
                     * be to use the manta client.
                     */
                    vasync.pipeline({ funcs: [
                        function mkTmpFile(_, next2) {
                            fs.writeFile(tmpFile, item.content, next2);
                        },
                        function mputIt(_, next2) {
                            forkExecWait({
                                argv: [ MPUT, '-f', tmpFile, item.path ]
                            }, next2);
                        },
                        function rmTmpFile(_, next2) {
                            fs.unlink(tmpFile, next2);
                        }
                    ]}, next);
                    return;

                default:
                    t.ifError(new Error('invalid test tree type: '
                        + item.type));
                    return;
                }
            }
Example #19
0
    fs.readdir(SERVER_ROOT, function _onReadDir(err, dirs) {
        var state = {};

        if (err) {
            console.error('FATAL: %s', err.message);
            process.exit(2);
            return;
        }

        vasync.pipeline({
            arg: state,
            funcs: [
                findDatacenterName,
                findDnsDomain,
                findUfdsAdminUuid,
                findZoneAdminIp
            ]
        }, function pipelineComplete(pipelineErr) {
            assert.ifError(pipelineErr);

            vasync.forEachPipeline({
                func: function _runServer(serverUuid, cb) {
                    assert.uuid(serverUuid, 'serverUuid');
                    runServer({
                        ctx: state,
                        log: logger,
                        serverUuid: serverUuid
                    }, cb);
                },
                inputs: dirs
            }, function _forEachPipelineComplete(forEachPipelineErr) {
                logger.info('startup sequence complete');
            });
        });
    });
RegistryClientV1.prototype.getImgId = function getImgId(opts, cb) {
    var self = this;
    assert.object(opts, 'opts');
    assert.string(opts.tag, 'opts.tag');
    assert.func(cb, 'cb');

    var res, imgId;
    vasync.pipeline({arg: this, funcs: [
        ensureSession,
        function call(_, next) {
            self._request({
                path: fmt('/v1/repositories/%s/tags/%s',
                    encodeURI(self.repo.remoteName),
                    encodeURIComponent(opts.tag))
            }, function _afterCall(err, req, res_, imgId_) {
                if (err) {
                    return next(err);
                }
                imgId = imgId_;
                res = res_;
                next();
            });
        }
    ]}, function (err) {
        cb(err, imgId, res);
    });
};
Example #21
0
function do_unset(subcmd, opts, _args, cb) {
    var self = this;
    if (opts.help) {
        this.do_help('help', {}, [subcmd], cb);
        return;
    }

    var progress = self.progress;
    vasync.pipeline({arg: {}, funcs: [
        function ensureSdcApp(_, next) {
            self.sdcadm.ensureSdcApp({}, next);
        },
        function unsetChannel(_, next) {
            self.sdcadm.sapi.updateApplication(self.sdcadm.sdcApp.uuid, {
                metadata: {
                    update_channel: self.sdcadm.sdcApp.metadata.update_channel
                },
                action: 'delete'
            }, function (err) {
                if (err) {
                    next(new errors.SDCClientError(err, 'sapi'));
                    return;
                }
                progress('Update channel has been successfully unset');
                next();
            });
        }
    ]}, function pipeCb(pipeErr) {
        cb(pipeErr);
    });
};
Example #22
0
    ]}, function finishUp(runErr) {
        // Early abort signal.
        if (runErr === true) {
            runErr = null;
        }

        vasync.pipeline({funcs: [
            function dropLock(_, next) {
                if (!context.unlock) {
                    next();
                    return;
                }
                sdcadm.releaseLock({unlock: context.unlock}, next);
            }
        ]}, function cleanedUp(cleanUpErr) {
            // We shouldn't ever get a `cleanUpErr`. Let's be loud if we do.
            if (cleanUpErr) {
                log.fatal({err: cleanUpErr}, 'unexpected error cleaning up');
            }
            if (runErr || cleanUpErr) {
                cb(runErr || cleanUpErr);
                return;
            }

            if (context.execStart) {
                ui.info('Completed successfully (%selapsed %ds).',
                    (opts.dryRun ? 'dry-run, ' : ''),
                    Math.floor((Date.now() - context.execStart) / 1000));
            }
            cb();
        });
    });
RegistryClientV1.prototype.listRepoTags = function listRepoTags(cb) {
    var self = this;
    assert.func(cb, 'cb');

    var res, repoTags;
    vasync.pipeline({arg: this, funcs: [
        ensureSession,
        function call(_, next) {
            self._request({
                path: fmt('/v1/repositories/%s/tags',
                    encodeURI(self.repo.remoteName)),
                followRedirect: true
            }, function _afterCall(err, req, res_, repoTags_) {
                if (err) {
                    return next(err);
                }
                repoTags = repoTags_;
                res = res_;
                next();
            });
        }
    ]}, function (err) {
        cb(err, repoTags, res);
    });
};
Example #24
0
/*
 * Get (or create) and setup the test zone in which we can run the `docker`
 * client.
 *
 * This is an lx zone with the docker clients added.
 */
function stepClientZone(state_, cb) {
    if (state_.clientZone) {
        return cb();
    }

    vasync.pipeline({arg: state_, funcs: [
        stepVmapi,
        function getClientZone(state, next) {
            var filters = {
                state: 'active',
                owner_uuid: state.sdcConfig.ufds_admin_uuid,
                alias: CLIENT_ZONE_PAYLOAD.alias
            };
            state.vmapi.listVms(filters, function (err, vms) {
                if (err) {
                    return next(err);
                }
                if (vms.length) {
                    state.clientZone = vms[0];
                    //p('# Found existing client zone %s (%s)',
                    //    state.clientZone.uuid, state.clientZone.alias);
                }
                next();
            });
        },
        // Create the client zone if necessary.
        _stepCreateClientZone
    ]}, cb);
}
Example #25
0
ZKClient.prototype.update = function update(p, object, options, callback) {
        assert.string(p, 'path');
        assert.object(object, 'object');
        if (typeof (options) === 'function') {
                callback = options;
                options = {};
        }
        assert.object(options, 'options');
        assert.func(callback, 'callback');

        callback = once(callback);

        var data = JSON.stringify(object);
        var log = this.log;
        var _p = path.normalize(p);
        var self = this;
        var tasks = [
                function getVersion(_, cb) {
                        cb = once(cb);
                        if (version !== undefined)
                                return (cb());
                        self.stat(_p, function (err, _stat) {
                                if (err) {
                                        cb(err);
                                } else {
                                        version = _stat.version;
                                        cb();
                                }
                        });
                        return (undefined);
                },
                function write(_, cb) {
                        cb = once(cb);
                        zk.a_set(_p, data, version, function (rc, msg) {
                                if (rc !== 0) {
                                        cb(new ZKError(rc, msg));
                                } else {
                                        cb();
                                }
                        });
                }
        ];
        var version = options.version;
        var zk = this.zk;

        log.trace({
                path: p,
                object: object,
                options: options
        }, 'update: entered');

        vasync.pipeline({funcs: tasks}, function (err) {
                log.trace({
                        path: p,
                        error: err
                }, 'update: %s', err ? 'error' : 'done');
                callback(err || null);
        });
};
Example #26
0
CLI.prototype.do_replace_attr = function (subcmd, opts, args, callback) {
    var self = this;
    if (opts.help) {
        this.do_help('help', {}, [subcmd], callback);
        return;
    } else if (args.length !== 3) {
        return callback(new errors.UsageError(sprintf(
            'incorrect number of arguments: "%s"', args.join(' '))));
    }
    var loginOrUuid = args[0];
    var attr = args[1];
    var value = args[2];

    vasync.pipeline({arg: {}, funcs: [
        /* @field ctx.client */
        function getClient(ctx, next) {
            self.getMasterUfdsClient(function (err, client) {
                if (err) {
                    return next(err);
                }
                ctx.client = client;
                next();
            });
        },
        /* @field ctx.user */
        function getUser(ctx, next) {
            ctx.client.getUser(loginOrUuid, function (err, user) {
                if (err) {
                    next(new errors.APIError(err));
                } else if (!user) {
                    next(new errors.NoSuchUser(user));
                } else {
                    ctx.user = user;
                    next();
                }
            });
        },
        function updateUser(ctx, next) {
            /*
             * <ufdsClient>.updateUser() doesn't support 'add' modification
             * type, so we are skipping using it for the '*-attr' commands.
             */
            var change = {
                type: 'replace',
                modification: {}
            };
            change.modification[attr] = value;
            ctx.client.modify(ctx.user.dn, [change], next);
        },
        function print(ctx, next) {
            p('Replaced attribute on user %s (%s): %s=%s', ctx.user.uuid,
                ctx.user.login, attr, value);
            next();
        },
        function closeClient(ctx, next) {
            ctx.client.close(next);
        }
    ]}, callback);
};
Example #27
0
test('schema array, scalar value (string)', function (t) {
    var k = uuid.v4();
    var cfg = {
        index: {
            name: {
                type: '[string]',
                unique: false
            }
        }
    };
    var data = {
        name: 'foo',
        ignoreme: 'foo'
    };

    vasync.pipeline({
        funcs: [
            function bucket(_, cb) {
                c.putBucket(b, cfg, cb);
            },
            function object(_, cb) {
                c.putObject(b, k, data, cb);
            },
            function find(_, cb) {
                cb = once(cb);

                var found = false;
                var req = c.findObjects(b, '(name=foo)');
                req.once('error', cb);
                req.once('record', function (obj) {
                    t.ok(obj);
                    if (obj) {
                        t.equal(obj.bucket, b);
                        t.equal(obj.key, k);
                        // Moray converts back into an
                        // array...
                        data.name = [data.name];
                        t.deepEqual(obj.value, data);
                        t.ok(obj._id);
                        t.ok(obj._etag);
                        t.ok(obj._mtime);
                        found = true;
                    }
                });
                req.once('end', function () {
                    t.ok(found);
                    cb();
                });
            }
        ],
        arg: null
    }, function (err) {
        t.ifError(err);
        t.end();
    });
});
test('find _txn_snap', function (t) {
    var b = this.bucket;
    var c = this.client;
    var k = uuid.v4();
    var v = {
        str: 'hello',
        str_2: 'world'
    };
    var found = false;

    vasync.pipeline({
        funcs: [ function wait(_, cb) {
            setTimeout(cb, 500);
        }, function put(_, cb) {
            c.putObject(b, k, v, cb);
        }, function getTokens(_, cb) {
            c.getTokens(function (err, res) {
                _.tokens = res.tokens;
                return cb(err);
            });
        }, function find(_, cb) {
            var f = '(&(_txn_snap>=1)(_id>=1))';
            var count = 0;
            _.tokens.forEach(function (token) {
                var req = c.findObjects(b, f, {token: token});
                req.once('error', cb);
                req.once('end', function () {
                    if (++count === _.tokens.length) {
                        return cb();
                    }
                    return (undefined);
                });
                req.once('record', function (obj) {
                    t.ok(obj);
                    if (!obj)
                        return (undefined);

                    t.equal(obj.bucket, b);
                    t.equal(obj.key, k);
                    t.deepEqual(obj.value, v);
                    t.ok(obj._id);
                    t.ok(obj._etag);
                    t.ok(obj._mtime);
                    t.ok(obj._txn_snap);
                    found = true;
                    return (undefined);
                });
            });
        } ],
        arg: {}
    }, function (err) {
        t.ifError(err);
        t.ok(found);
        t.end();
    });
});
Example #29
0
test('append one at a time', function (t) {
    var self = this;
    var funcs = [
        function (_, subcb) {
            self.clog.append({
                'commitIndex': 0,
                'term': 0,
                //No index, so append!
                'entries': memstream([ { 'term': 2,
                                         'command': 'command-1-2' } ])
            }, function (err, entry) {
                if (err) {
                    subcb(err);
                    return;
                }
                t.equal(1, entry.index);
                t.deepEqual(self.clog.last(), entry);
                t.equal(2, self.clog.nextIndex);
                subcb();
            });
        },
        function (_, subcb) {
            self.clog.append({
                'commitIndex': 0,
                'term': 0,
                //No index, so append!
                'entries': memstream([ { 'term': 2,
                                         'command': 'command-2-2' } ])
            }, function (err, entry) {
                t.equal(2, entry.index);
                t.deepEqual(self.clog.last(), entry);
                subcb();
            });
        },
        function (_, subcb) {
            t.equal(3, self.clog.nextIndex);
            t.deepEqual(e(2, 2), self.clog.last());
            readClog(self.clog, function (err, clog) {
                t.ok(clog.length === 3);
                t.deepEqual(e(0, 0), clog[0]);
                t.deepEqual(e(1, 2), clog[1]);
                t.deepEqual(e(2, 2), clog[2]);
                subcb();
            });
        }
    ];
    vasync.pipeline({
        funcs: funcs,
        arg: {}
    }, function (err) {
        if (err) {
            t.fail(err);
        }
        t.done();
    });
});
Example #30
0
 commitEventStream.on('line', function _commitLineCb(event) {
     log.debug('commit: got commit event:', String(event));
     try {
         event = JSON.parse(event);
     } catch (e) {
         log.error('Commit: invalid json: %s - ignoring', event);
         return;
     }
     switch (event.type) {
         case 'end':
             if (event.error) {
                 // Will be passed to callback `cb`.
                 commitError = new Error(event.error);
             }
             break;
         case 'message':
         case 'stdout':
             log.info('Commit event message: %s', event.message);
             break;
         case 'image_create':
             createImage(event.payload, { rat: rat, req: req },
                 function _imageCreateCb(err, result)
             {
                 sendEventResponse(event, err, result);
             });
             break;
         case 'commit_finished':
             finalImageId = event.finalId;
             vasync.pipeline({ funcs: [
                 function _doAddBaseImageHead(_result, next) {
                     addBaseImageHead(baseImageId, finalImageId,
                     {
                         baseImageIndexName: baseImg.index_name,
                         req: req,
                         scratchImage: scratchImage
                     }, next);
                 },
                 function _doTagImage(_result, next) {
                     tagImage({
                             docker_id: finalImageId,
                             name: opts.tag,
                             req: req
                         }, next);
                 }
             ]}, function commitFinishPipeCb(err) {
                 if (!err) {
                     commitFinishedSuccessfully = true;
                 }
                 sendEventResponse(event, err);
             });
             break;
         default:
             log.error('Unhandled commit event: %j', event);
             break;
     }
 });