Skip to content
This repository
Browse code

OS-1753 / joyent/smartos-live#147 fixed update to nics.*.model

  • Loading branch information...
commit 9a713533372779b53b5ab2e9d9f1d41c3ec9e720 1 parent ff0982e
joshwilsdon authored December 09, 2012
8  src/vm/node_modules/VM.js
@@ -912,7 +912,7 @@ var BRAND_OPTIONS = {
912 912
             'nics.*.interface': ['add', 'update'],
913 913
             'nics.*.ip': ['add', 'update'],
914 914
             'nics.*.mac': ['add', 'update'],
915  
-            'nics.*.model': ['add'],
  915
+            'nics.*.model': ['add', 'update'],
916 916
             'nics.*.netmask': ['add', 'update'],
917 917
             'nics.*.nic_tag': ['add', 'update'],
918 918
             'nics.*.primary': ['add', 'update'],
@@ -7832,6 +7832,8 @@ exports.start = function (uuid, extra, callback)
7832 7832
 {
7833 7833
     var zoneobj;
7834 7834
 
  7835
+    assert(callback, 'undefined callback!');
  7836
+
7835 7837
     ensureLogging('start', true);
7836 7838
     VM.log.info('Starting VM ' + uuid);
7837 7839
 
@@ -8190,6 +8192,7 @@ function applyUpdates(oldobj, newobj, payload, callback)
8190 8192
     var changed_datasets = false;
8191 8193
 
8192 8194
     // Note: oldobj is the VM *before* the update, newobj *after*
  8195
+    VM.log.debug('applying updates to ' + oldobj.uuid);
8193 8196
 
8194 8197
     async.series([
8195 8198
         function (cb) {
@@ -8319,6 +8322,8 @@ function applyUpdates(oldobj, newobj, payload, callback)
8319 8322
 
8320 8323
                                 c(err);
8321 8324
                             });
  8325
+                        } else {
  8326
+                            c();
8322 8327
                         }
8323 8328
                     }
8324 8329
                 }, cb);
@@ -8490,6 +8495,7 @@ function applyUpdates(oldobj, newobj, payload, callback)
8490 8495
         }
8491 8496
 
8492 8497
     ], function (err, res) {
  8498
+        VM.log.debug('done applying updates to ' + oldobj.uuid);
8493 8499
         callback(err);
8494 8500
     });
8495 8501
 }
91  src/vm/tests/test-update-kvm.js
@@ -14,13 +14,14 @@ var PAYLOADS = {
14 14
     "create": {
15 15
         "brand": "kvm",
16 16
         "ram": 256,
  17
+        "autoboot": false,
17 18
         "alias": "autotest-vm" + process.pid,
18  
-        "disks": [{"size": 1024, "model": "virtio"}],
  19
+        "disks": [{"size": 1024, "model": "ide"}],
19 20
         "do_not_inventory": true
20 21
     }, "add_net0": {
21 22
         "add_nics": [
22 23
             {
23  
-                "model": "virtio",
  24
+                "model": "e1000",
24 25
                 "ip": "10.254.254.254",
25 26
                 "netmask": "255.255.255.0",
26 27
                 "nic_tag": "external",
@@ -89,7 +90,48 @@ test('create zone', {'timeout': 240000}, function(t) {
89 90
     });
90 91
 });
91 92
 
92  
-test('add net0', function(t) {
  93
+test('update disk model', {'timeout': 60000}, function(t) {
  94
+
  95
+    VM.load(vm_uuid, function (err, before_obj) {
  96
+        var path;
  97
+
  98
+        if (err) {
  99
+            t.ok(false, 'error loading existing VM: ' + err.message);
  100
+            t.end();
  101
+            return;
  102
+        }
  103
+
  104
+        path = before_obj.disks[0].path;
  105
+
  106
+        VM.update(vm_uuid, {'update_disks': [{'path': path, 'model': 'virtio'}]}, function(err) {
  107
+            if (err) {
  108
+                t.ok(false, 'error updating VM: ' + err.message);
  109
+                t.end();
  110
+            } else {
  111
+                VM.load(vm_uuid, function (err, obj) {
  112
+                    if (err) {
  113
+                        t.ok(false, 'failed reloading VM');
  114
+                        t.end();
  115
+                        return;
  116
+                    }
  117
+                    t.ok((obj.disks[0].model === 'virtio'), 'obj.disks[0].model: '
  118
+                        + obj.disks[0].model + ' expected: virtio');
  119
+                    t.end();
  120
+                });
  121
+            }
  122
+        });
  123
+    });
  124
+});
  125
+
  126
+test('boot zone', function(t) {
  127
+    VM.start(vm_uuid, {}, function (err) {
  128
+        t.ok(!err, 'error starting VM' + (err ? ': ' + err.message : ''));
  129
+        t.end();
  130
+    });
  131
+});
  132
+
  133
+test('add net0', {'timeout': 60000}, function(t) {
  134
+    console.log('boarg');
93 135
     VM.update(vm_uuid, PAYLOADS.add_net0, function (err) {
94 136
         if (err) {
95 137
             t.ok(false, 'error updating VM: ' + err.message);
@@ -123,6 +165,47 @@ test('add net0', function(t) {
123 165
     });
124 166
 });
125 167
 
  168
+test('update nic model', {'timeout': 60000}, function(t) {
  169
+
  170
+    VM.load(vm_uuid, function (err, before_obj) {
  171
+        var mac;
  172
+
  173
+        if (err) {
  174
+            t.ok(false, 'error loading existing VM: ' + err.message);
  175
+            t.end();
  176
+            return;
  177
+        }
  178
+
  179
+        if (!before_obj || !before_obj.hasOwnProperty('nics')
  180
+            || before_obj.nics.length < 1) {
  181
+
  182
+            t.ok(false, 'VM is in a broken state before NIC update');
  183
+            t.end();
  184
+            return;
  185
+        }
  186
+
  187
+        mac = before_obj.nics[0].mac;
  188
+
  189
+        VM.update(vm_uuid, {'update_nics': [{'mac': mac, 'model': 'virtio'}]}, function(err) {
  190
+            if (err) {
  191
+                t.ok(false, 'error updating VM: ' + err.message);
  192
+                t.end();
  193
+            } else {
  194
+                VM.load(vm_uuid, function (err, obj) {
  195
+                    if (err) {
  196
+                        t.ok(false, 'failed reloading VM');
  197
+                        t.end();
  198
+                        return;
  199
+                    }
  200
+                    t.ok((obj.nics[0].model === 'virtio'), 'obj.nics[0].model: '
  201
+                        + obj.nics[0].model + ' expected: virtio');
  202
+                    t.end();
  203
+                });
  204
+            }
  205
+        });
  206
+    });
  207
+});
  208
+
126 209
 test('remove net0', function(t) {
127 210
     VM.update(vm_uuid, PAYLOADS.remove_net0, function(err) {
128 211
         if (err) {
@@ -199,7 +282,7 @@ test('remove net0 and net1', function(t) {
199 282
     });
200 283
 });
201 284
 
202  
-test('set then unset simple properties', function(t) {
  285
+test('set then unset simple properties', {'timeout': 240000}, function(t) {
203 286
     async.forEachSeries(simple_properties,
204 287
         function (item, cb) {
205 288
             var prop = item[0];

0 notes on commit 9a71353

Please sign in to comment.
Something went wrong with that request. Please try again.