Skip to content

Commit

Permalink
OS-2363 keep disk_driver and nic_driver properties and use .model fro…
Browse files Browse the repository at this point in the history
…m first disk/nic if missing.
  • Loading branch information
joshwilsdon committed Jul 10, 2013
1 parent e034be2 commit 68e2f09
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 19 deletions.
31 changes: 25 additions & 6 deletions src/vm/node_modules/VM.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/vm/tests/test-required-nic-props.js
Expand Up @@ -371,7 +371,7 @@ test('test create good KVM then add nic with no model', {'timeout': 240000}, fun
vmtest.on_new_vm(t, vmtest.CURRENT_UBUNTU_UUID, p, state, [
function (cb) {
VM.update(state.uuid, {'add_nics': [{'ip': '10.99.99.223', 'netmask': '255.255.255.0', 'nic_tag': 'admin', 'gateway': '10.99.99.1'}]}, function (err) {
t.ok(err, 'update VM should fail' + (err ? ': ' + err.message : ''));
t.ok(!err, 'update VM should succeed: ' + (err ? ': ' + err.message : ''));
VM.load(state.uuid, function(err, obj) {
t.ok(!err, 'load VM' + state.uuid + (err ? ': ' + err.message : ''));
if (obj && obj.nics) {
Expand Down
157 changes: 145 additions & 12 deletions src/vm/tests/test-update-kvm.js
Expand Up @@ -5,6 +5,7 @@ var async = require('/usr/node/node_modules/async');
var execFile = require('child_process').execFile;
var test = require('tap').test;
var VM = require('/usr/vm/node_modules/VM');
var vmtest = require('../common/vmtest.js');

VM.loglevel = 'DEBUG';

Expand All @@ -28,12 +29,28 @@ var PAYLOADS = {
"interface": "net0",
"vlan_id": 0,
"gateway": "10.254.254.1",
"mac": "01:02:03:04:05:06"
"mac": "00:02:03:04:05:06"
}
]
}, "add_net1": {
"add_nics": [
{
"ip": "10.254.254.253",
"netmask": "255.255.255.0",
"nic_tag": "external",
"interface": "net1",
"vlan_id": 0,
"gateway": "10.254.254.1",
"mac": "02:03:04:05:06:07"
}
]
}, "remove_net0": {
"remove_nics": [
"01:02:03:04:05:06"
"00:02:03:04:05:06"
]
}, "remove_net1": {
"remove_nics": [
"02:03:04:05:06:07"
]
}, "add_net0_and_net1": {
"add_nics": [
Expand All @@ -45,7 +62,7 @@ var PAYLOADS = {
"interface": "net0",
"vlan_id": 0,
"gateway": "10.254.254.1",
"mac": "01:02:03:04:05:06"
"mac": "00:02:03:04:05:06"
}, {
"model": "virtio",
"ip": "10.254.254.253",
Expand All @@ -59,9 +76,31 @@ var PAYLOADS = {
]
}, "remove_net0_and_net1": {
"remove_nics": [
"01:02:03:04:05:06",
"00:02:03:04:05:06",
"02:03:04:05:06:07"
]
}, "add_disk1": {
"add_disks": [
{"size": 1024}
]
}, "create_w_drivers": {
"brand": "kvm",
"ram": 256,
"autoboot": false,
"nic_driver": "e1000",
"disk_driver": "ide",
"alias": "autotest-vm" + process.pid,
"nics": [
{
"ip": "10.254.254.254",
"netmask": "255.255.255.0",
"nic_tag": "external",
"gateway": "10.254.254.1",
"mac": "00:02:03:04:05:06"
}
],
"disks": [{"size": 1024}],
"do_not_inventory": true
}
};

Expand Down Expand Up @@ -123,6 +162,27 @@ test('update disk model', {'timeout': 60000}, function(t) {
});
});

// Add disk1 w/o model and ensure it gets same model as disk0 (See OS-2363)
test('add disk1', {'timeout': 60000}, function(t) {
VM.update(vm_uuid, PAYLOADS.add_disk1, function (err) {
if (err) {
t.ok(false, 'error updating VM: ' + err.message);
t.end();
} else {
VM.load(vm_uuid, function (err, obj) {
if (err) {
t.ok(false, 'failed reloading VM');
} else if (obj.disks.length !== 2) {
t.ok(false, 'VM has ' + obj.disks.length + ' != 2 disks');
} else {
t.ok(obj.disks[0].model === obj.disks[1].model, 'models of disk0 and disk1 match [' + obj.disks[0].model + ',' + obj.disks[1].model + ']');
}
t.end();
});
}
});
});

test('boot zone', function(t) {
VM.start(vm_uuid, {}, function (err) {
t.ok(!err, 'error starting VM' + (err ? ': ' + err.message : ''));
Expand Down Expand Up @@ -205,8 +265,49 @@ test('update nic model', {'timeout': 60000}, function(t) {
});
});

// Add net1 w/o model and ensure it gets same model as net0 (See OS-2363)
test('add net1', {'timeout': 60000}, function(t) {
VM.update(vm_uuid, PAYLOADS.add_net1, function (err) {
if (err) {
t.ok(false, 'error updating VM: ' + err.message);
t.end();
} else {
VM.load(vm_uuid, function (err, obj) {
if (err) {
t.ok(false, 'failed reloading VM');
} else if (obj.nics.length !== 2) {
t.ok(false, 'VM has ' + obj.nics.length + ' != 2 nics');
} else {
t.ok(obj.nics[0].model === obj.nics[1].model, 'models of net0 and net1 match [' + obj.nics[0].model + ',' + obj.nics[1].model + ']');
}
t.end();
});
}
});
});

test('remove net0', function(t) {
VM.update(vm_uuid, PAYLOADS.remove_net0, function(err) {
if (err) {
t.ok(false, 'error updating VM: ' + err.message);
t.end();
} else {
VM.load(vm_uuid, function (err, obj) {
if (err) {
t.ok(false, 'failed reloading VM');
} else if (obj.nics.length !== 1) {
t.ok(false, 'VM has ' + obj.nics.length + ' != 1 nics');
} else {
t.ok(true, 'Successfully removed net0 from VM');
}
t.end();
});
}
});
});

test('remove net1', function(t) {
VM.update(vm_uuid, PAYLOADS.remove_net1, function(err) {
if (err) {
t.ok(false, 'error updating VM: ' + err.message);
t.end();
Expand Down Expand Up @@ -710,9 +811,10 @@ function zfs(args, callback)
// VM should at this point be running, so removing the disk should fail.
// Stopping and removing should succeed.
// Adding should also succeed at that point.
test('remove disk', function(t) {
test('remove disks', function(t) {
VM.load(vm_uuid, function (err, vmobj) {
var disk;
var disk0;
var disk1;

if (err) {
t.ok(false, 'error loading VM: ' + err.message);
Expand All @@ -724,14 +826,16 @@ test('remove disk', function(t) {
t.end();
return;
}
if (!vmobj.hasOwnProperty('disks') || vmobj.disks.length !== 1) {
if (!vmobj.hasOwnProperty('disks') || vmobj.disks.length !== 2) {
t.ok(false, 'cannot find disk: ' + vmobj.disks);
t.end();
return;
}
disk = vmobj.disks[0];
t.ok(disk.hasOwnProperty('path'), 'disk has a path: ' + disk.path);
VM.update(vmobj.uuid, {'remove_disks': [disk.path]}, function (err) {
disk0 = vmobj.disks[0];
disk1 = vmobj.disks[1];
t.ok(disk0.hasOwnProperty('path'), 'disk0 has a path: ' + disk0.path);
t.ok(disk1.hasOwnProperty('path'), 'disk1 has a path: ' + disk1.path);
VM.update(vmobj.uuid, {'remove_disks': [disk0.path, disk1.path]}, function (err) {
// expect an error
t.ok(err, 'VM.update failed to remove disks: ' + (err ? err.message : err));
if (!err) {
Expand All @@ -746,11 +850,11 @@ test('remove disk', function(t) {
t.ok(obj.state === 'stopped', 'VM is stopped.');
if (obj.state === 'stopped') {
// same update
VM.update(vmobj.uuid, {'remove_disks': [disk.path]}, function (err) {
VM.update(vmobj.uuid, {'remove_disks': [disk0.path, disk1.path]}, function (err) {
t.ok(!err, 'removed disk: ' + (err ? err.message : err));
// check that zfs filesystem is gone, also
// reload and check that disk is no longer in list
zfs(['list', disk.zfs_filesystem], function (err, fds) {
zfs(['list', disk0.zfs_filesystem], function (err, fds) {
t.ok(err
&& err.hasOwnProperty('message')
&& err.message.match('dataset does not exist'),
Expand Down Expand Up @@ -790,3 +894,32 @@ test('delete zone', function(t) {
t.end();
}
});

test('create KVM VM w/ *_drivers', {'timeout': 240000}, function(t) {
var state = {'brand': 'kvm'};
vmtest.on_new_vm(t, null, PAYLOADS['create_w_drivers'], state, [
function (cb) {
VM.load(state.uuid, function(err, obj) {
var has_primary = 0;
var n;

if (err) {
t.ok(false, 'load obj from new VM: ' + err.message);
return cb(err);
}

// ensure nic_driver + disk_driver properties are set
t.ok(obj.nic_driver === 'e1000', 'VM has nic_driver');
t.ok(obj.disk_driver === 'ide', 'VM has disk_driver');
t.ok(obj.nics[0].model === 'e1000', 'VM has correct nic.model');
t.ok(obj.disks[0].model === 'ide', 'VM has correct disk.model');

// TODO: add a disk and a nic and ensure they've also got the correct.model

cb();
});
}
], function (err) {
t.end();
});
});

0 comments on commit 68e2f09

Please sign in to comment.