Skip to content

Commit

Permalink
TRITON-2070 booter needs to offer boot module support for linux CNs
Browse files Browse the repository at this point in the history
TRITON-2094 Booter should provide support for custom boot params passed to linux

Co-authored-by: Todd Whiteman <todd.whiteman@joyent.com>
  • Loading branch information
kusor and twhiteman committed Aug 17, 2020
1 parent f49a386 commit e6c9bfa
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 315 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,5 @@
/smf/manifests/*.xml
/bits
/build
config.json
.nyc_output
18 changes: 8 additions & 10 deletions Makefile
Expand Up @@ -20,8 +20,7 @@ TOP := $(shell pwd)
#
# Tools
#
TAPE := ./node_modules/.bin/tape
ISTANBUL := ./node_modules/.bin/istanbul
TAP := ./node_modules/.bin/tap
PACK := ./$(BUILD)/pack-0.0.1.tgz

#
Expand Down Expand Up @@ -76,22 +75,21 @@ include ./deps/eng/tools/mk/Makefile.smf.defs
# Repo-specific targets
#
.PHONY: all
all: $(SMF_MANIFESTS) node_modules | $(TAPE) sdc-scripts
all: $(SMF_MANIFESTS) node_modules | $(TAP) sdc-scripts

node_modules: package.json | $(NPM_EXEC) $(PACK)
$(NPM) install --no-save

$(TAPE): node_modules

$(ISTANBUL): node_modules
$(TAP): | $(NPM_EXEC)
$(NPM) install tap --no-save

.PHONY: test
test: | $(NODE_EXEC) $(TAPE) node_modules
$(NODE) $(TAPE) test/*.test.js
test: $(NODE_EXEC) $(TAP) node_modules
$(NODE) $(TAP) test/unit/*.test.js

.PHONY: coverage
coverage: | $(ISTANBUL) $(TAPE) node_modules
$(ISTANBUL) cover $(TAPE) test/*.test.js
coverage: $(NODE_EXEC) $(TAP) node_modules
$(NODE) $(TAP) test/**/*.test.js --coverage-report=html --no-browser

$(PACK):
$(NPM) pack file:$(TOP)/src/node-pack
Expand Down
3 changes: 1 addition & 2 deletions lib/admin-pool-cache.js
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2020 Joyent, Inc.
*/


Expand All @@ -18,7 +18,6 @@
* specified in the config file.
*/
var assert = require('assert-plus');
var vasync = require('vasync');
var mod_json = require('./json-file');


Expand Down
7 changes: 6 additions & 1 deletion lib/boot-files.js
Expand Up @@ -44,7 +44,8 @@ function extractBootOpts(opts) {
mac: opts.mac,
tftpRoot: opts.config.tftpRoot,
nic_tag: opts.nic_tag,
adminPoolCache: opts.adminPoolCache
adminPoolCache: opts.adminPoolCache,
serverIp: opts.config.serverIp
};

if (opts.mac) {
Expand All @@ -67,6 +68,10 @@ function extractBootOpts(opts) {
bootOpts.datacenterName = opts.config.datacenterName;
}

if (opts.platforms) {
bootOpts.platforms = opts.platforms;
}

return bootOpts;
}

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

/*
* Copyright 2018 Joyent, Inc.
* Copyright 2020 Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -103,11 +103,12 @@ function main() {
console.error('WARNING: boot-gpxe is deprecated; use boot-ipxe');
/* jsl: FALLTHRU */
case 'boot-ipxe':
var mac = getArg('MAC address');
bootparams.getBootParams({
adminUuid: config.adminUuid,
tftpRoot: config.tftpRoot,
cacheDir: config.cache.dir,
mac: getArg('MAC address'),
mac: mac,
napi: napi,
cnapi: cnapi,
log: log,
Expand All @@ -117,6 +118,7 @@ function main() {
return console.error(err.code + ': ' + err.message);
}

res.mac = mac;
menu.buildIpxeCfg(res, function (cfg) {
return console.log(cfg);
});
Expand Down
113 changes: 84 additions & 29 deletions lib/bootparams.js
Expand Up @@ -12,16 +12,16 @@
* Gets information from NAPI and CNAPI for booting SDC compute nodes.
*/

var assert = require('assert-plus');
var jsprim = require('jsprim');
var mod_clients = require('./clients');
var mod_json = require('./json-file');
var util = require('util');
var vasync = require('vasync');
var verror = require('verror');
const assert = require('assert-plus');
const jsprim = require('jsprim');
const mod_clients = require('./clients');
const mod_json = require('./json-file');
const util = require('util');
const vasync = require('vasync');
const verror = require('verror');


var fmt = util.format;
const fmt = util.format;

// --- Internal functions

Expand Down Expand Up @@ -101,7 +101,7 @@ function getBootParams(opts, callback) {
assert.optionalNumber(opts.pipelineTimeoutSeconds,
'opts.pipelineTimeoutSeconds');
assert.object(opts.adminPoolCache, 'opts.adminPoolCache');

assert.optionalObject(opts.platforms, 'opts.platforms');
var cacheDir = opts.cacheDir;
var adminUuid = opts.adminUuid;
var cnapi = opts.cnapi;
Expand Down Expand Up @@ -162,6 +162,10 @@ function getBootParams(opts, callback) {
nic_tag: opts.nic_tag
};

if (opts.platforms) {
vArg.platforms = opts.platforms;
}

vasync.pipeline({
arg: vArg,
funcs: [
Expand Down Expand Up @@ -189,7 +193,6 @@ function getBootParams(opts, callback) {

fArg.adminPool = pool;
cb();
return;
});
},
// Get nic data from NAPI for the given MAC
Expand All @@ -198,16 +201,18 @@ function getBootParams(opts, callback) {
if (err) {
if (err.statusCode === 404) {
log.debug('Did not find nic "%s" in NAPI', mac);
return cb();
cb();
return;
}
log.error(err, 'Error getting nic "%s" from NAPI', mac);
return cb(err);
cb(err);
return;
}

log.debug(res, 'Got nic from NAPI');
fArg.bootNic = res;
fArg.nics = [ fArg.bootNic ];
return cb();
cb();
});
},

Expand Down Expand Up @@ -239,7 +244,6 @@ function getBootParams(opts, callback) {
}

cb();
return;
},

// If the nic exists in NAPI but it doesn't have an IP, give it one
Expand All @@ -261,15 +265,16 @@ function getBootParams(opts, callback) {
if (err) {
log.error({err: err, params: putParams},
'Error adding IP to nic "%s" on NAPI', mac);
return cb(err);
cb(err);
return;
}

log.debug(res, 'Updated nic "%s" with IP "%s" in NAPI',
mac, res.ip);
fArg.bootNic = res;

fArg.nics = [ fArg.bootNic ];
return cb();
cb();
});
},

Expand Down Expand Up @@ -298,23 +303,53 @@ function getBootParams(opts, callback) {
if (err) {
log.error(err,
'Error provisioning admin nic "%s" on NAPI', mac);
return cb(err);
cb(err);
return;
}

log.debug(res, 'Got provisioned nic from NAPI');
fArg.bootNic = res;
fArg.nics = [ fArg.bootNic ];

return cb();
cb();
});
},

// In case we have a server not yet setup, there will be no MAC
// associated to the server UUID, but it'll be present in server's
// sysinfo and the mac with the colons replaced with dashes will be
// the server hostname.
function _getUnsetupServerUUID(fArg, cb) {
fArg.cn_uuid = fArg.bootNic.belongs_to_uuid;
uuid = fArg.bootNic.belongs_to_uuid;
if (fArg.cn_uuid !== adminUuid) {
cb();
return;
}
const mac_dashed = mac.replace(/:/g, '-');

cnapi.listServers({
hostname: mac_dashed
}, function listServersCb(err, servers) {
if (err) {
log.error(err,
'Error getting servers with mac %s from CNAPI',
mac_dashed);
cb(err);
return;
}
if (servers.length) {
log.info({servers: servers}, 'Servers found');
fArg.cn_uuid = servers[0].uuid;
uuid = servers[0].uuid;
}
cb();
});
},
// Get boot params from CNAPI if belongs_to_uuid is set to something
// than the admin UUID
function _bootParams(fArg, cb) {
uuid = fArg.bootNic.belongs_to_uuid;
fArg.cn_uuid = fArg.bootNic.belongs_to_uuid;
if (uuid === adminUuid) {
if (fArg.cn_uuid === adminUuid) {
uuid = 'default';
cb();
return;
Expand All @@ -326,12 +361,14 @@ function getBootParams(opts, callback) {
log.warn('Did not find bootparams for "%s" in '
+ 'CNAPI: continuing anyway', uuid);
uuid = 'default';
return cb();
cb();
return;
}

log.error(err, 'Error getting %s bootparams from CNAPI',
uuid);
return cb(err);
cb(err);
return;
}

log.debug(res, 'Got bootparams from CNAPI');
Expand All @@ -342,10 +379,11 @@ function getBootParams(opts, callback) {
log.warn('empty bootparams: getting default '
+ 'bootparams instead');
uuid = 'default';
return cb();
cb();
return;
}
params = res;
return cb();
cb();
});
},

Expand All @@ -363,20 +401,36 @@ function getBootParams(opts, callback) {
if (err) {
log.error(err,
'Error getting default bootparams from CNAPI');
return cb(err);
cb(err);
return;
}

log.debug(res, 'Got default bootparams from CNAPI');
params = res;
return cb();
cb();
});
},

// If we have a server UUID in belongs_to_uuid, get its nics
// and aggregations from NAPI
mod_clients.napiGetNics,
mod_clients.napiGetAggrs,
mod_clients.napiGetNicTags
mod_clients.napiGetNicTags,

function _getPlatforms(fArg, cb) {
cnapi.listPlatforms({
os: true
}, function onList(err, platforms) {
if (err) {
log.error(err,
'Error getting plaforms from CNAPI');
cb(err);
return;
}
fArg.platforms = platforms;
cb();
});
}
]
}, function (err, res) {
if (pipelineTimedOut) {
Expand Down Expand Up @@ -541,7 +595,8 @@ function getBootParams(opts, callback) {
bootParams: params,
nics: nics,
adminPool: adminPool,
nictags: vArg.nictags
nictags: vArg.nictags,
platforms: vArg.platforms
});
});
});
Expand Down

0 comments on commit e6c9bfa

Please sign in to comment.