Permalink
Browse files

OS-1769 require nic_tag on all NICs when adding

  • Loading branch information...
1 parent 9564b7f commit 3ec1ea2c369fe6e16bfbfe70947dd1cb6d543d63 @joshwilsdon joshwilsdon committed Dec 18, 2012
@@ -25,11 +25,11 @@
* Experimental functions, expect these interfaces to be unstable and
* potentially go away entirely:
*
- * create_snapshot(uuid, snapname, callback)
- * delete_snapshot(uuid, snapname, callback)
+ * create_snapshot(uuid, snapname, options, callback)
+ * delete_snapshot(uuid, snapname, options, callback)
* install(uuid, callback)
* receive(target, options, callback)
- * rollback_snapshot(uuid, snapname, callback)
+ * rollback_snapshot(uuid, snapname, options, callback)
* send(uuid, where, options, callback)
* getSysinfo(args, callback)
* validate(brand, action, payload, callback)
@@ -4351,6 +4351,14 @@ function checkPayloadProperties(payload, vmobj, callback)
return;
}
+ if (field === 'add_nics' && (!n.hasOwnProperty('nic_tag')
+ || !n.nic_tag.match(/^[a-zA-Z0-9\_]+$/))) {
+
+ callback(new Error('invalid or missing .nic_tag option '
+ + 'for NIC: ' + JSON.stringify(n)));
+ return;
+ }
+
if (field === 'update_nics' && n.hasOwnProperty('model')
&& (!n.model || n.model === 'undefined'
|| n.model.length === 0)) {
@@ -4368,6 +4376,14 @@ function checkPayloadProperties(payload, vmobj, callback)
return;
}
+ if (field === 'update_nics' && n.hasOwnProperty('nic_tag')
+ && !n.nic_tag.match(/^[a-zA-Z0-9\_]+$/)) {
+
+ callback(new Error('invalid .nic_tag option for NIC: '
+ + JSON.stringify(n)));
+ return;
+ }
+
if (n.hasOwnProperty('mac')
|| n.hasOwnProperty('vrrp_vrid')) {
mac = n.hasOwnProperty('mac') ? n.mac
@@ -42,29 +42,29 @@ function should_fail_with_conflict(name, payloadA, payloadB)
}
should_fail_with_conflict('KVM with same IP',
- {'brand': 'kvm', 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'netmask': '255.255.255.0', 'model': 'virtio'}]},
- {'brand': 'kvm', 'nics': [{'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'netmask': '255.255.255.0', 'model': 'virtio'}]}
+ {'brand': 'kvm', 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'netmask': '255.255.255.0', 'model': 'virtio'}]},
+ {'brand': 'kvm', 'nics': [{'nic_tag': 'admin', 'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'netmask': '255.255.255.0', 'model': 'virtio'}]}
);
should_fail_with_conflict('OS with same IP',
- {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'netmask': '255.255.255.0'}]},
- {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'netmask': '255.255.255.0'}]}
+ {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'netmask': '255.255.255.0'}]},
+ {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'nic_tag': 'admin', 'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'netmask': '255.255.255.0'}]}
);
should_fail_with_conflict('KVM with same MAC',
- {'brand': 'kvm', 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}]},
- {'brand': 'kvm', 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'}]}
+ {'brand': 'kvm', 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}]},
+ {'brand': 'kvm', 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'}]}
);
should_fail_with_conflict('OS with same MAC',
- {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'netmask': '255.255.255.0'}]},
- {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'netmask': '255.255.255.0'}]}
+ {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'netmask': '255.255.255.0'}]},
+ {'brand': 'joyent-minimal', 'image_uuid': image_uuid, 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'netmask': '255.255.255.0'}]}
);
should_fail_with_conflict('KVM with same IP and MAC',
- {'brand': 'kvm', 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
- {'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'}]},
- {'brand': 'kvm', 'nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}]}
+ {'brand': 'kvm', 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
+ {'nic_tag': 'admin', 'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'}]},
+ {'brand': 'kvm', 'nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}]}
);
// test that we can't have two nics with the same IP or MAC
@@ -75,8 +75,8 @@ test('2 nics with same MAC', {'timeout': 240000}, function(t) {
}
input.brand = 'kvm';
input.nics = [
- {'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
- {'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'},
+ {'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
+ {'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'},
];
state = {'brand': 'kvm', 'expect_create_failure': true};
vmtest.on_new_vm(t, null, input, state, []);
@@ -89,8 +89,8 @@ test('2 nics with same IP', {'timeout': 240000}, function(t) {
}
input.brand = 'kvm';
input.nics = [
- {'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
- {'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
+ {'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
+ {'nic_tag': 'admin', 'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'},
];
state = {'brand': 'kvm', 'expect_create_failure': true};
vmtest.on_new_vm(t, null, input, state, []);
@@ -106,14 +106,14 @@ test('add additional nic with same IP', {'timeout': 240000}, function(t) {
}
input.brand = 'kvm';
input.nics = [
- {'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}
+ {'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}
];
state = {'brand': 'kvm'};
vmtest.on_new_vm(t, null, input, state, [
function (cb) {
VM.update(state.uuid,
{
- 'add_nics': [{'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}]
+ 'add_nics': [{'nic_tag': 'admin', 'mac': '0f:0e:0d:0c:0b:0a', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}]
},
function (err) {
t.ok(err, 'updating to add another NIC with the same IP (should fail): ' + (err.message ? err.message : 'succeeded'));
@@ -134,14 +134,14 @@ test('add additional nic with same MAC', {'timeout': 240000}, function(t) {
}
input.brand = 'kvm';
input.nics = [
- {'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}
+ {'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.172', 'model': 'virtio', 'netmask': '255.255.255.0'}
];
state = {'brand': 'kvm'};
vmtest.on_new_vm(t, null, input, state, [
function (cb) {
VM.update(state.uuid,
{
- 'add_nics': [{'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'}]
+ 'add_nics': [{'nic_tag': 'admin', 'mac': '01:02:03:04:05:06', 'ip': '172.17.2.173', 'model': 'virtio', 'netmask': '255.255.255.0'}]
},
function (err) {
t.ok(err, 'updating to add another NIC with the same MAC (should fail): ' + (err.message ? err.message : 'succeeded'));
@@ -24,6 +24,20 @@ var payload_missing_netmask = {
]
};
+var payload_missing_nic_tag = {
+ 'autoboot': false,
+ 'brand': 'joyent-minimal',
+ 'alias': 'autotest-' + process.pid,
+ 'do_not_inventory': true,
+ 'nics': [
+ {
+ 'ip': '10.99.99.222',
+ 'netmask': '255.255.255.0',
+ 'gateway': '10.99.99.1'
+ }
+ ]
+};
+
var payload_good = {
'autoboot': false,
'brand': 'joyent-minimal',
@@ -200,6 +214,18 @@ test('test create without netmask', {'timeout': 240000}, function(t) {
);
});
+test('test create without nic_tag', {'timeout': 240000}, function(t) {
+
+ p = JSON.parse(JSON.stringify(payload_missing_nic_tag));
+ state = {'brand': p.brand, 'expect_create_failure': true};
+
+ vmtest.on_new_vm(t, vmtest.CURRENT_SMARTOS, p, state, [],
+ function (err) {
+ t.end();
+ }
+ );
+});
+
test('test create KVM without netmask', {'timeout': 240000}, function(t) {
p = JSON.parse(JSON.stringify(payload_kvm_missing_netmask));
@@ -252,6 +278,28 @@ test('test create with netmask then add nic with no netmask', {'timeout': 240000
});
});
+test('test create machine then add nic with no nic_tag', {'timeout': 240000}, function(t) {
+
+ p = JSON.parse(JSON.stringify(payload_good));
+ state = {'brand': p.brand};
+
+ vmtest.on_new_vm(t, vmtest.CURRENT_SMARTOS, p, state, [
+ function (cb) {
+ t.ok(true, 'state: ' + JSON.stringify(state));
+ VM.update(state.uuid, {'add_nics': [{'ip': '10.99.99.223', 'netmask': '255.255.255.0', 'gateway': '10.99.99.1'}]}, function (err) {
+ t.ok(err, 'update VM should fail' + (err ? ': ' + err.message : ''));
+ VM.load(state.uuid, function(err, obj) {
+ t.ok(!err, 'load VM' + state.uuid + (err ? ': ' + err.message : ''));
+ t.ok(obj && obj.nics && obj.nics.length === 1, 'VM should have 1 NIC: ' + obj.nics.length);
+ cb();
+ });
+ });
+ }
+ ], function (err) {
+ t.end();
+ });
+});
+
test('test create good KVM then add nic with no netmask', {'timeout': 240000}, function(t) {
p = JSON.parse(JSON.stringify(payload_kvm_good));
@@ -248,6 +248,7 @@ test('vrrp vnics: updating', TEST_OPTS,
'add_nics': [
{
mac: '52:31:98:52:5d:07:d0',
+ nic_tag: 'external',
ip: 'dhcp',
vrrp_vrid: 4
}
@@ -304,6 +305,7 @@ test('vrrp vnics: updating', TEST_OPTS,
'add_nics': [
{
ip: 'dhcp',
+ nic_tag: 'external',
vrrp_vrid: 15,
vrrp_primary_ip: '172.18.1.101'
}
@@ -322,6 +324,7 @@ test('vrrp vnics: updating', TEST_OPTS,
payload: {
'add_nics': [
{
+ nic_tag: 'external',
ip: '172.18.1.117',
netmask: '255.255.255.0',
vrrp_vrid: 16,
@@ -342,6 +345,7 @@ test('vrrp vnics: updating', TEST_OPTS,
payload: {
'add_nics': [
{
+ nic_tag: 'external',
ip: '172.18.1.118',
netmask: '255.255.255.0',
vrrp_vrid: 17
@@ -560,10 +564,12 @@ test('create with vrrp_primary_ip set to a VRRP nic', TEST_OPTS, function(t) {
expectCreateError({
nics: [
{ 'ip': '172.18.1.110',
+ 'nic_tag': 'external',
'netmask': '255.255.255.0',
'vrrp_vrid': 31
},
{ 'ip': 'dhcp',
+ 'nic_tag': 'external',
'vrrp_vrid': 32,
'vrrp_primary_ip': '172.18.1.110'
}
@@ -598,6 +604,7 @@ test('create with vrrp_primary_ip set to self', TEST_OPTS, function(t) {
expectCreateError({
nics: [
{
+ 'nic_tag': 'external',
'ip': '172.18.1.127',
'netmask': '255.255.255.0',
'vrrp_vrid': 26,
@@ -619,6 +626,7 @@ test('create with vrrp_vrid set but not vrrp_primary_ip', TEST_OPTS,
expectCreateError({
nics: [
{
+ 'nic_tag': 'external',
'ip': '172.18.1.127',
'netmask': '255.255.255.0',
'vrrp_vrid': 27
@@ -639,6 +647,7 @@ test('create with only a VRRP nic', TEST_OPTS,
expectCreateError({
nics: [
{
+ 'nic_tag': 'external',
'ip': '172.18.1.127',
'netmask': '255.255.255.0',
'vrrp_vrid': 27,

0 comments on commit 3ec1ea2

Please sign in to comment.