def setUp(self): plugin = rw_peas.PeasPlugin("rwmon_mock", 'RwMon-1.0') self.mock = MockAlarmInterface() self.plugin = plugin.get_interface("Monitoring") self.plugin.set_impl(self.mock) self.account = RwcalYang.YangData_RwProject_Project_CloudAccounts_CloudAccountList( ) self.alarm = RwmonYang.YangData_RwProject_Project_Alarm( name='test-alarm') self.vim_id = 'test-vim-id'
def test(self): """ This test uses a simple, mock implementation of the alarm interface to check that create, update, delete, and list work correctly. """ # In the beginning, there were no alarms _, alarms = self.plugin.do_alarm_list(self.account) self.assertEqual(0, len(alarms)) # Create two alarms self.plugin.do_alarm_create( self.account, self.vim_id, RwmonYang.YangData_RwProject_Project_Alarm()) self.plugin.do_alarm_create( self.account, self.vim_id, RwmonYang.YangData_RwProject_Project_Alarm()) _, alarms = self.plugin.do_alarm_list(self.account) self.assertEqual(2, len(alarms)) # The alarms should have no names alarms.sort(key=lambda a: a.alarm_id) self.assertEqual('test-alarm-id-1', alarms[0].alarm_id) self.assertEqual('test-alarm-id-2', alarms[1].alarm_id) self.assertTrue(all(a.name is None for a in alarms)) # Give names to the alarms alarms[0].name = 'test-alarm' alarms[1].name = 'test-alarm' self.plugin.do_alarm_update(self.account, alarms[0]) self.plugin.do_alarm_update(self.account, alarms[1]) self.assertTrue(all(a.name == 'test-alarm' for a in alarms)) # Delete the alarms self.plugin.do_alarm_delete(self.account, alarms[0].alarm_id) self.plugin.do_alarm_delete(self.account, alarms[1].alarm_id) _, alarms = self.plugin.do_alarm_list(self.account) self.assertEqual(0, len(alarms))