Skip to content

Commit

Permalink
TRITON-2127 sdc-migrate fails for instances that use deletion_protect…
Browse files Browse the repository at this point in the history
…ion (#31)
  • Loading branch information
twhiteman committed May 7, 2020
1 parent b5210b4 commit bd61250
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 28 deletions.
122 changes: 98 additions & 24 deletions lib/backends/smartos/tasks/machine_migrate.js
Expand Up @@ -5,7 +5,7 @@
*/

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

var child_process = require('child_process');
Expand Down Expand Up @@ -41,7 +41,7 @@ Task.createTask(MachineMigrateTask);

MachineMigrateTask.setStart(start);

function startChildProcess(callback) {
function startChildProcess() {
var self = this;

var payload = this.req.params;
Expand Down Expand Up @@ -130,7 +130,7 @@ function startChildProcess(callback) {
log.debug('child process started - now waiting for child to message back');
}

function killChild(callback) {
function killChild() {
var log = this.log;
var payload = this.req.params;

Expand Down Expand Up @@ -205,7 +205,7 @@ function zfsError(prefixMsg, error, stderr) {
}


function getFilesystemDetails(callback) {
function getFilesystemDetails() {
var self = this;

var log = self.log;
Expand Down Expand Up @@ -248,7 +248,7 @@ function getFilesystemDetails(callback) {
}


function removeZfsQuota(callback) {
function removeZfsQuota() {
var self = this;

var log = self.log;
Expand Down Expand Up @@ -281,7 +281,7 @@ function removeZfsQuota(callback) {
}


function restoreZfsQuota(callback) {
function restoreZfsQuota() {
var self = this;

var log = self.log;
Expand Down Expand Up @@ -356,7 +356,7 @@ function restoreZfsQuota(callback) {
}


function setCreateTimestamp(callback) {
function setCreateTimestamp() {
var self = this;

var log = self.log;
Expand Down Expand Up @@ -425,7 +425,7 @@ function deleteSnapshot(snapshot, log, callback) {
}


function estimate(callback) {
function estimate() {
var self = this;

var log = self.log;
Expand Down Expand Up @@ -544,7 +544,7 @@ function _mountFilesystem(dataset, payload, log, callback) {
callback();
}

function setupFilesystem(callback) {
function setupFilesystem() {
var self = this;
var log = self.log;
var payload = self.req.params;
Expand Down Expand Up @@ -620,7 +620,7 @@ function setupFilesystem(callback) {
}


function removeSyncSnapshots(callback) {
function removeSyncSnapshots() {
var self = this;

var log = self.log;
Expand Down Expand Up @@ -733,7 +733,7 @@ function removeSyncSnapshots(callback) {
}


function setDoNotInventory(callback) {
function setDoNotInventory() {
var log = this.log;
var payload = this.req.params;

Expand Down Expand Up @@ -768,7 +768,7 @@ function setDoNotInventory(callback) {
}


function setAutoboot(callback) {
function setAutoboot() {
var log = this.log;
var payload = this.req.params;

Expand Down Expand Up @@ -803,40 +803,114 @@ function setAutoboot(callback) {
}


function start(callback) {
function setIndestructibleZoneroot() {
var log = this.log;
var payload = this.req.params;

assert.object(payload, 'payload');
assert.uuid(payload.vm_uuid, 'payload.vm_uuid');
assert.string(payload.value, 'payload.value');

var vmUuid = payload.vm_uuid;
var value = payload.value;

// Update using vmadm.
var cmd = '/usr/sbin/vmadm';
var args = [
'update',
vmUuid,
'indestructible_zoneroot=' + value
];

var buf;

log.debug({cmd: cmd, args: args}, 'setIndestructibleZoneroot');

try {
buf = child_process.execFileSync(cmd, args, gExecFileDefaults);
} catch (ex) {
log.warn({cmd: cmd, args: args}, 'Could not run vmadm update:', ex);
this.fatal(String(ex.stderr || buf));
return;
}

this.finish();
}


function setIndestructibleDelegated() {
var log = this.log;
var payload = this.req.params;

assert.object(payload, 'payload');
assert.uuid(payload.vm_uuid, 'payload.vm_uuid');
assert.string(payload.value, 'payload.value');

var vmUuid = payload.vm_uuid;
var value = payload.value;

// Update using vmadm.
var cmd = '/usr/sbin/vmadm';
var args = [
'update',
vmUuid,
'indestructible_delegated=' + value
];

var buf;

log.debug({cmd: cmd, args: args}, 'setIndestructibleDelegated');

try {
buf = child_process.execFileSync(cmd, args, gExecFileDefaults);
} catch (ex) {
log.warn({cmd: cmd, args: args}, 'Could not run vmadm update:', ex);
this.fatal(String(ex.stderr || buf));
return;
}

this.finish();
}


function start() {
var payload = this.req.params;

/* Cleanup */
if (payload.action === 'kill_migration_process') {
killChild.bind(this)(callback);
killChild.bind(this)();

/* Begin */
} else if (payload.action === 'get-filesystem-details') {
getFilesystemDetails.bind(this)(callback);
getFilesystemDetails.bind(this)();
} else if (payload.action === 'set-create-timestamp') {
setCreateTimestamp.bind(this)(callback);
setCreateTimestamp.bind(this)();

/* Sync */
} else if (payload.action === 'sync' || payload.action === 'receive') {
startChildProcess.bind(this)(callback);
startChildProcess.bind(this)();
} else if (payload.action === 'remove-zfs-quota') {
removeZfsQuota.bind(this)(callback);
removeZfsQuota.bind(this)();
} else if (payload.action === 'restore-zfs-quota') {
restoreZfsQuota.bind(this)(callback);
restoreZfsQuota.bind(this)();

/* Estimate */
} else if (payload.action === 'estimate') {
estimate.bind(this)(callback);
estimate.bind(this)();

/* Switch helper functions */
} else if (payload.action === 'remove-sync-snapshots') {
removeSyncSnapshots.bind(this)(callback);
removeSyncSnapshots.bind(this)();
} else if (payload.action === 'setup-filesystem') {
setupFilesystem.bind(this)(callback);
setupFilesystem.bind(this)();
} else if (payload.action === 'set-do-not-inventory') {
setDoNotInventory.bind(this)(callback);
setDoNotInventory.bind(this)();
} else if (payload.action === 'set-autoboot') {
setAutoboot.bind(this)(callback);
setAutoboot.bind(this)();
} else if (payload.action === 'set-indestructible-zoneroot') {
setIndestructibleZoneroot.bind(this)();
} else if (payload.action === 'set-indestructible-delegated') {
setIndestructibleDelegated.bind(this)();
} else {
this.fatal('Unexpected payload.action: ' + payload.action);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/task_agent/task.js
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2020 Joyent, Inc.
*/

var EventEmitter = require('events').EventEmitter;
Expand Down Expand Up @@ -111,12 +111,12 @@ Log.prototype.logMessage = function (level, args) {
};


Task.prototype.start = function (callback) {
Task.prototype.start = function () {
this.finish();
};


Task.prototype.finish = function (value, callback) {
Task.prototype.finish = function (value) {
if (this.progress_ < 100) {
this.progress(100);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "cn-agent",
"description": "Triton Compute Node Agent",
"version": "2.14.0",
"version": "2.14.1",
"author": "Joyent (joyent.com)",
"private": true,
"dependencies": {
Expand Down

0 comments on commit bd61250

Please sign in to comment.