This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for AzVMExtensionEvent
Added test cases for `AzVMExtensionEvent` event plugin. A few minor changes have been made to `AzVMExtensionEvent` to take care of few corner cases.
- Loading branch information
1 parent
264cfaa
commit cdb9456
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
"""Tests for AzVMExtensionEvent plugin.""" | ||
|
||
|
||
import copy | ||
import unittest | ||
|
||
from cloudmarker.events import azvmextensionevent | ||
|
||
base_record = { | ||
'ext': { | ||
'record_type': 'vm_instance_view', | ||
'extensions': [] | ||
}, | ||
'com': { | ||
'cloud_type': 'azure' | ||
} | ||
} | ||
|
||
|
||
class AzVMExtensionEventTest(unittest.TestCase): | ||
"""Tests for AzVMExtensionEvent plugin.""" | ||
|
||
def test_com_bucket_missing(self): | ||
record = copy.deepcopy(base_record) | ||
record['com'] = None | ||
plugin = azvmextensionevent.AzVMExtensionEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_cloud_type_non_azure(self): | ||
record = copy.deepcopy(base_record) | ||
record['com']['cloud_type'] = 'non_azure' | ||
plugin = azvmextensionevent.AzVMExtensionEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_ext_bucket_missing(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext'] = None | ||
plugin = azvmextensionevent.AzVMExtensionEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_record_type_non_vm_instance_view(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['record_type'] = 'non_vm_instance_view' | ||
plugin = azvmextensionevent.AzVMExtensionEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_blacklisted_extensions(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['extensions'] = ['ext01', 'ext02'] | ||
plugin = azvmextensionevent.AzVMExtensionEvent(blacklisted=['ext01']) | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 1) | ||
self.assertEqual(events[0]['ext']['record_type'], | ||
'vm_blacklisted_extension_event') | ||
self.assertEqual(events[0]['com']['cloud_type'], | ||
'azure') | ||
self.assertEqual(events[0]['com']['record_type'], | ||
'vm_blacklisted_extension_event') | ||
self.assertTrue('reference' in events[0]['com']) | ||
self.assertIsNotNone(events[0]['com']['description']) | ||
self.assertIsNotNone(events[0]['com']['recommendation']) | ||
|
||
def test_no_blacklisted_extensions(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['extensions'] = ['ext01', 'ext02'] | ||
plugin = azvmextensionevent.AzVMExtensionEvent(blacklisted=['ext03']) | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 0) | ||
|
||
def test_whitelisted_extensions(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['extensions'] = ['ext01', 'ext02'] | ||
plugin = azvmextensionevent.AzVMExtensionEvent(whitelisted=['w_ext01']) | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 1) | ||
self.assertEqual(events[0]['ext']['record_type'], | ||
'vm_unapproved_extension_event') | ||
self.assertEqual(events[0]['com']['cloud_type'], | ||
'azure') | ||
self.assertEqual(events[0]['com']['record_type'], | ||
'vm_unapproved_extension_event') | ||
self.assertTrue('reference' in events[0]['com']) | ||
self.assertIsNotNone(events[0]['com']['description']) | ||
self.assertIsNotNone(events[0]['com']['recommendation']) | ||
|
||
def test_all_whitelisted_extensions(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['extensions'] = ['ext01', 'ext02'] | ||
plugin = azvmextensionevent. \ | ||
AzVMExtensionEvent(whitelisted=['ext01', 'ext02']) | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 0) | ||
|
||
def test_required_extensions(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['extensions'] = ['ext01', 'ext02'] | ||
plugin = azvmextensionevent. \ | ||
AzVMExtensionEvent(required=['r_ext01']) | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 1) | ||
self.assertEqual(events[0]['ext']['record_type'], | ||
'vm_required_extension_event') | ||
self.assertEqual(events[0]['com']['cloud_type'], | ||
'azure') | ||
self.assertEqual(events[0]['com']['record_type'], | ||
'vm_required_extension_event') | ||
self.assertTrue('reference' in events[0]['com']) | ||
self.assertIsNotNone(events[0]['com']['description']) | ||
self.assertIsNotNone(events[0]['com']['recommendation']) | ||
|
||
def test_all_required_extensions(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['extensions'] = ['ext01', 'ext02'] | ||
plugin = azvmextensionevent. \ | ||
AzVMExtensionEvent(required=['ext01', 'ext02']) | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 0) |