Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/AKD-132: Added Azure 'Premium SSD Disabled' plugin and test cases #640

Merged
merged 6 commits into from
Jun 1, 2021
1 change: 1 addition & 0 deletions exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ module.exports = {
'scaleSetMultiAz' : require(__dirname + '/plugins/azure/virtualmachines/scaleSetMultiAz.js'),
'scaleSetAutoscaleEnabled' : require(__dirname + '/plugins/azure/virtualmachines/scaleSetAutoscaleEnabled.js'),
'vmAvailabilitySetLimit' : require(__dirname + '/plugins/azure/virtualmachines/vmAvailabilitySetLimit.js'),
'premiumSsdDisabled' : require(__dirname + '/plugins/azure/virtualmachines/premiumSsdDisabled.js'),
'autoOsUpgradesEnabled' : require(__dirname + '/plugins/azure/virtualmachines/autoOsUpgradesEnabled.js'),
'noUnattachedDisks' : require(__dirname + '/plugins/azure/virtualmachines/noUnattachedDisks.js'),

Expand Down
61 changes: 61 additions & 0 deletions plugins/azure/virtualmachines/premiumSsdDisabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var async = require('async');

var helpers = require('../../../helpers/azure/');

module.exports = {
title: 'Premium SSD Disabled',
category: 'Virtual Machines',
description: 'Ensures that the Azure virtual machines are configured to use standard SSD disk volumes instead of premium SSD disk volumes.',
ali-imran7 marked this conversation as resolved.
Show resolved Hide resolved
more_info: 'Azure standard SSD disks store data on solid state drives (SSDs), like Azure\'s existing premium storage disks. Standard SSD disks are a cost-effective storage option optimized for workloads that need consistent performance at lower IOPS levels.',
recommended_action: 'Modify virtual machines disks to use standard SSD disk volumes instead of premium SSD disk volumes',
link: 'https://docs.microsoft.com/en-us/azure/virtual-machines/disks-types',
apis: ['virtualMachines:listAll'],

run: function(cache, settings, callback) {
var results = [];
var source = {};
var locations = helpers.locations(settings.govcloud);

async.each(locations.virtualMachines, function(location, rcb){
const virtualMachines = helpers.addSource(cache, source, ['virtualMachines', 'listAll', location]);

if (!virtualMachines) return rcb();

if (virtualMachines.err || !virtualMachines.data) {
helpers.addResult(results, 3, 'Unable to query for virtual machines: ' + helpers.addError(virtualMachines), location);
return rcb();
}
if (!virtualMachines.data.length) {
helpers.addResult(results, 0, 'No existing virtual machines found', location);
return rcb();
}

virtualMachines.data.forEach(virtualMachine => {
if (virtualMachine.storageProfile && virtualMachine.storageProfile.osDisk &&
virtualMachine.storageProfile.osDisk.managedDisk &&
virtualMachine.storageProfile.osDisk.managedDisk.storageAccountType &&
virtualMachine.storageProfile.osDisk.managedDisk.storageAccountType.toLowerCase() === 'premium_lrs') {
helpers.addResult(results, 2, 'Attached OS disk volume is of Premium SSD type', location, virtualMachine.id);
} else {
helpers.addResult(results, 0, 'Attached OS disk volume is not of Premium SSD type', location, virtualMachine.id);
}

const dataDisks = (virtualMachine.storageProfile && virtualMachine.storageProfile.dataDisks) ? virtualMachine.storageProfile.dataDisks : [];

for (const dataDisk of dataDisks) {
if (dataDisk.managedDisk && dataDisk.managedDisk.storageAccountType &&
dataDisk.managedDisk.storageAccountType.toLowerCase() === 'premium_lrs') {
helpers.addResult(results, 2, 'Attached data disk volume is of Premium SSD type', location, virtualMachine.id);
ali-imran7 marked this conversation as resolved.
Show resolved Hide resolved
} else {
helpers.addResult(results, 0, 'Attached data disk volume is not of Premium SSD type', location, virtualMachine.id);
}
}
});

rcb();
}, function() {
// Global checking goes here
callback(null, results, source);
});
}
};
169 changes: 169 additions & 0 deletions plugins/azure/virtualmachines/premiumSsdDisabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
var expect = require('chai').expect;
var premiumSsdDisabled = require('./premiumSsdDisabled');

const virtualMachines = [
{
'name': 'test-vm',
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachines/test-vm',
'type': 'Microsoft.Compute/virtualMachines',
'storageProfile': {
'osDisk': {
'managedDisk': {
'storageAccountType': 'StandardSSD_LRS',
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Compute/disks/test-vm_OsDisk_1_d88ee8681dbe4bd3bbbd52a1f8e46d7f'
}
},
'dataDisks': []
}
},
{
'name': 'test-vm',
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachines/test-vm',
'type': 'Microsoft.Compute/virtualMachines',
'storageProfile': {
'osDisk': {
'managedDisk': {
'storageAccountType': 'Premium_LRS',
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Compute/disks/test-vm_OsDisk_1_d88ee8681dbe4bd3bbbd52a1f8e46d7f'
}
},
'dataDisks': []
}
},
{
'name': 'test-vm',
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachines/test-vm',
'type': 'Microsoft.Compute/virtualMachines',
'storageProfile': {
'osDisk': {
'managedDisk': {
'storageAccountType': 'StandardSSD_LRS',
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Compute/disks/test-vm_OsDisk_1_d88ee8681dbe4bd3bbbd52a1f8e46d7f'
}
},
'dataDisks': [
{
'managedDisk': {
'storageAccountType': 'StandardSSD_LRS',
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Compute/disks/test-disk'
}
}
]
}
},
{
'name': 'test-vm',
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachines/test-vm',
'type': 'Microsoft.Compute/virtualMachines',
'storageProfile': {
'osDisk': {
'managedDisk': {
'storageAccountType': 'Premium_LRS',
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Compute/disks/test-vm_OsDisk_1_d88ee8681dbe4bd3bbbd52a1f8e46d7f'
}
},
'dataDisks': [
{
'managedDisk': {
'storageAccountType': 'Premium_LRS',
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Compute/disks/test-disk'
}
}
]
}
}
];

const createCache = (virtualMachines) => {
const machine = {};
if (virtualMachines) {
machine['data'] = virtualMachines;
}
return {
virtualMachines: {
listAll: {
'eastus': machine
}
}
};
};

describe('premiumSsdDisabled', function() {
describe('run', function() {
it('should give passing result if no virtual machines found', function(done) {
const cache = createCache([]);
premiumSsdDisabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No existing virtual machines found');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if unable to query for virtual machines', function(done) {
const cache = createCache(null);
premiumSsdDisabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].message).to.include('Unable to query for virtual machines');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if OS disk volume is not of Premium SSD type', function(done) {
const cache = createCache([virtualMachines[0]]);
premiumSsdDisabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('Attached OS disk volume is not of Premium SSD type');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing result if OS disk volume is of Premium SSD type', function(done) {
const cache = createCache([virtualMachines[1]]);
premiumSsdDisabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('Attached OS disk volume is of Premium SSD type');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing results if OS and data disk volumes is not of Premium SSD type', function(done) {
const cache = createCache([virtualMachines[2]]);
premiumSsdDisabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(2);

expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('Attached OS disk volume is not of Premium SSD type');

expect(results[1].status).to.equal(0);
expect(results[1].message).to.include('Attached data disk volume is not of Premium SSD type');

expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing results if OS and data disk volume is of Premium SSD type', function(done) {
const cache = createCache([virtualMachines[3]]);
premiumSsdDisabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(2);

expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('Attached OS disk volume is of Premium SSD type');

expect(results[1].status).to.equal(2);
expect(results[1].message).to.include('Attached data disk volume is of Premium SSD type');

expect(results[0].region).to.equal('eastus');
done();
});
});
});
});