Skip to content

Commit

Permalink
ZAPI-751 add-nics workflow should set the cn_uuid of the new NIC
Browse files Browse the repository at this point in the history
ZAPI-764 Provisioning fabric NATs broken by VMAPI initialization changes
Reviewed by: Julien Gilli <julien.gilli@joyent.com>
Approved by: Josh Wilsdon <jwilsdon@joyent.com>
  • Loading branch information
melloc committed Jan 30, 2017
1 parent 47bd9f6 commit 69ea66d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 34 deletions.
2 changes: 1 addition & 1 deletion deps/javascriptlint
2 changes: 1 addition & 1 deletion deps/jsstyle
18 changes: 9 additions & 9 deletions lib/common/validation.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2016, Joyent, Inc.
* Copyright 2017, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -2276,15 +2276,15 @@ exports.validateMacs = function (params) {
* RAM or disk for example
*/
exports.setDefaultValues = function (params, options) {
var config = {};
var i;
assert.object(options, 'options');
assert.object(options.config, 'options.config');
assert.optionalObject(options.config.overlay, 'options.config.overlay');

if (options && options.config) {
config = options.config;
var config = options.config;
var i;

if (config.overlay.natPool) {
params.sdc_nat_pool = config.overlay.natPool;
}
if (config.overlay && config.overlay.enabled) {
params.sdc_nat_pool = config.overlay.natPool;
}

if (params.uuid === undefined) {
Expand Down Expand Up @@ -2337,7 +2337,7 @@ exports.setDefaultValues = function (params, options) {
// Set a default refreservation for i > 0 disks
for (i = 1; i < params.disks.length; i++) {
if (params.disks[i].refreservation === undefined) {
if (config && config.reserveKvmStorage === false) {
if (config.reserveKvmStorage === false) {
params.disks[i].refreservation = 0;
} else {
params.disks[i].refreservation = params.disks[i].size;
Expand Down
12 changes: 11 additions & 1 deletion lib/vmapi.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2016, Joyent, Inc.
* Copyright 2017, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -52,6 +52,15 @@ function VMAPI(options) {
assert.object(options, 'options');
assert.optionalObject(options.log, 'options.log');

// Fabric options
assert.optionalObject(options.overlay, 'options.overlay');
if (options.overlay) {
assert.bool(options.overlay.enabled, 'options.overlay.enabled');
if (options.overlay.enabled) {
assert.uuid(options.overlay.natPool, 'options.overlay.natPool');
}
}

assert.optionalObject(options.apiClients, 'options.apiClients');
if (options.apiClients) {
assert.optionalObject(options.apiClients.wfapi,
Expand Down Expand Up @@ -90,6 +99,7 @@ function VMAPI(options) {
this.log = options.log;
}

this.options = options;
this.changefeedOptions = options.changefeed;

validations.init(options);
Expand Down
4 changes: 2 additions & 2 deletions lib/workflows/add-nics.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright 2016, Joyent, Inc.
* Copyright 2017, Joyent, Inc.
*/

/*
Expand All @@ -21,7 +21,7 @@

var async; // stub to keep jsl happy
var common = require('./job-common');
var VERSION = '7.0.11';
var VERSION = '7.1.0';


/*
Expand Down
6 changes: 3 additions & 3 deletions lib/workflows/fabric-common.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2015, Joyent, Inc.
* Copyright 2017, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -143,7 +143,7 @@ function acquireFabricTickets(job, cb) {
if (sErr) {
cb(sErr);
} else {
cb(null, 'Fabric nat tickets acquired');
cb(null, 'Fabric NAT tickets acquired');
}
});
});
Expand All @@ -163,7 +163,7 @@ function provisionFabricNats(job, cb) {
}

if (!job.params.sdc_nat_pool) {
return cb(null, 'No fabric NAT pool configured for provisioning');
return cb(new Error('No fabric NAT pool configured for provisioning'));
}

var cnapi = new sdcClients.CNAPI({
Expand Down
43 changes: 30 additions & 13 deletions lib/workflows/job-common.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright 2016, Joyent, Inc.
* Copyright 2017, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -675,6 +675,9 @@ function validateNetworks(job, cb) {
* don't provision any new NICs.
*/
function provisionNics(job, cb) {
var inst_uuid = job.params.uuid || job.params.vm_uuid;
var owner_uuid = job.params.owner_uuid;

var networks = job.params.networks;
if (networks === undefined) {
cb('Networks are required');
Expand Down Expand Up @@ -706,9 +709,10 @@ function provisionNics(job, cb) {
// accidentally reusing an object
function nicParams() {
return {
owner_uuid: job.params.owner_uuid,
belongs_to_uuid: job.params.uuid || job.params.vm_uuid,
belongs_to_type: 'zone'
owner_uuid: owner_uuid,
belongs_to_uuid: inst_uuid,
belongs_to_type: 'zone',
cn_uuid: job.params.server_uuid
};
}

Expand All @@ -721,16 +725,30 @@ function provisionNics(job, cb) {
}
}

// Get current list of NICs that might have been provisioned ahead of time
napi.listNics(nicParams(), function (err, res) {
var antiSpoofParams = [
'allow_dhcp_spoofing',
'allow_ip_spoofing',
'allow_mac_spoofing',
'allow_restricted_traffic'
];

/*
* Get current list of NICs that might have been provisioned ahead of time.
* This is done in some places when an IP address needs to be known ahead
* of time. For example, Zookeeper instances in Manta have their NICs
* created before provisioning instances, so that they can be configured
* to know each other's addresses before booting.
*/
napi.listNics({
owner_uuid: owner_uuid,
belongs_to_uuid: inst_uuid,
belongs_to_type: 'zone'
}, function asyncProvisionNics(err, currentNics) {
if (err) {
cb(err);
return;
}
return asyncProvisionNics(res);
});

function asyncProvisionNics(currentNics) {
async.mapSeries(networks, function (network, next) {
// If there is at least one provisioned NIC in one of the networks
// provided, skip napi.provisionNic for this network
Expand All @@ -745,10 +763,7 @@ function provisionNics(job, cb) {
return;
}

var antiSpoofParams = ['allow_dhcp_spoofing', 'allow_ip_spoofing',
'allow_mac_spoofing', 'allow_restricted_traffic'];
var params = nicParams();
params.cn_uuid = job.params.server_uuid;
if (network.ipv4_ips !== undefined)
params.ip = network.ipv4_ips[0];
if (network.primary !== undefined)
Expand Down Expand Up @@ -780,7 +795,8 @@ function provisionNics(job, cb) {
cb(null, 'NICs allocated');
}
});
}
});

}


Expand Down Expand Up @@ -836,6 +852,7 @@ function addNics(job, cb) {
owner_uuid: job.params.owner_uuid,
belongs_to_uuid: job.params.uuid || job.params.vm_uuid,
belongs_to_type: 'zone',
cn_uuid: job.params.server_uuid,
state: 'provisioning'
};

Expand Down
4 changes: 2 additions & 2 deletions lib/workflows/provision.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2016, Joyent, Inc.
* Copyright 2017, Joyent, Inc.
*/

/*
Expand All @@ -19,7 +19,7 @@ var common = require('./job-common');
var childProcess = require('child_process');
var wfapiUrl;

var VERSION = '7.3.1';
var VERSION = '7.4.0';


/*
Expand Down
4 changes: 4 additions & 0 deletions sapi_manifests/vmapi/template
Expand Up @@ -18,7 +18,11 @@
},
"overlay": {
{{#fabric_cfg}}
"enabled": true,
"natPool": "{{{sdc_nat_pool}}}"
{{/fabric_cfg}}
{{^fabric_cfg}}
"enabled": false
{{/fabric_cfg}}
},
"wfapi": {
Expand Down
2 changes: 1 addition & 1 deletion server.js
Expand Up @@ -145,7 +145,7 @@ function startVmapiService() {
}
]}, function dependenciesInitDone(err) {
if (err) {
vmapi.log.error({
vmapiLog.error({
error: err
}, 'failed to initialize VMAPI\'s dependencies');

Expand Down
2 changes: 1 addition & 1 deletion test/lib/vm.js
Expand Up @@ -35,7 +35,7 @@ function createTestVm(moray, options, vmParams, callback) {
var log = options.log || new BunyanNoopLogger();

vmParams = common.clone(vmParams);
common.setDefaultValues(vmParams, {});
common.setDefaultValues(vmParams, { config: {} });

// Prefix the VM alias with a prefix that identifies
// it as a test VM.
Expand Down

0 comments on commit 69ea66d

Please sign in to comment.