コード例 #1
0
ファイル: test_vm_db_api.py プロジェクト: emonty/healthnmon
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch, modifiedEpoch and deletedEpoch
     """
     vm = Vm()
     vm.set_id('VM1')
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.vm_save(self.admin_context, vm)
     epoch_after = utils.get_current_epoch_ms()
     vm_queried = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                  [vm.get_id()])[0]
     self.assert_(
         test_utils.is_timestamp_between(epoch_before, epoch_after,
                                         vm_queried.get_createEpoch()))
     # Check for lastModifiedEpoch and createEpoch after adding VmGlobalSettings
     vm_modified = vm_queried
     test_utils.unset_timestamp_fields(vm_modified)
     vmGlobalSettings = VmGlobalSettings()
     vmGlobalSettings.set_id('VMGS1')
     vmGlobalSettings.set_autoStartAction(Constants.AUTO_START_ENABLED)
     vm_modified.set_vmGlobalSettings(vmGlobalSettings)
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.vm_save(self.admin_context, vm_modified)
     epoch_after = utils.get_current_epoch_ms()
     vm_queried = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                  [vm.get_id()])[0]
     self.assert_(
         vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             vm_queried.get_vmGlobalSettings().get_createEpoch()))
     # Check for lastModifiedEpoch after modifying vm
     vm_modified = vm_queried
     test_utils.unset_timestamp_fields(vm_modified)
     vm_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.vm_save(self.admin_context, vm_modified)
     epoch_after = utils.get_current_epoch_ms()
     vm_queried = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                  [vm.get_id()])[0]
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             vm_queried.get_vmGlobalSettings().get_lastModifiedEpoch()))
     self.assert_(
         vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
     self.assert_(vm_modified.get_vmGlobalSettings().get_createEpoch() ==
                  vm_queried.get_vmGlobalSettings().get_createEpoch())
コード例 #2
0
    def test_timestamp_columns(self):
        """
            Test the time stamp columns createEpoch,
            modifiedEpoch and deletedEpoch
        """
        vm = Vm()
        vm.set_id('VM1')
        # Check for createEpoch
        epoch_before = utils.get_current_epoch_ms()
        healthnmon_db_api.vm_save(self.admin_context, vm)
        epoch_after = utils.get_current_epoch_ms()
        vm_queried = healthnmon_db_api.vm_get_by_ids(
            self.admin_context, [vm.get_id()])[0]
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after, vm_queried.get_createEpoch()))

        # Check for lastModifiedEpoch and createEpoch
        # after adding VmGlobalSettings
        vm_modified = vm_queried
        test_utils.unset_timestamp_fields(vm_modified)
        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id('VMGS1')
        vmGlobalSettings.set_autoStartAction(Constants.AUTO_START_ENABLED)
        vm_modified.set_vmGlobalSettings(vmGlobalSettings)
        epoch_before = utils.get_current_epoch_ms()
        healthnmon_db_api.vm_save(self.admin_context, vm_modified)
        epoch_after = utils.get_current_epoch_ms()
        vm_queried = healthnmon_db_api.vm_get_by_ids(
            self.admin_context, [vm.get_id()])[0]
        self.assert_(
            vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after,
            vm_queried.get_vmGlobalSettings().get_createEpoch()))
        # Check for lastModifiedEpoch after modifying vm
        vm_modified = vm_queried
        test_utils.unset_timestamp_fields(vm_modified)
        vm_modified.set_name('changed_name')
        epoch_before = utils.get_current_epoch_ms()
        healthnmon_db_api.vm_save(self.admin_context, vm_modified)
        epoch_after = utils.get_current_epoch_ms()
        vm_queried = healthnmon_db_api.vm_get_by_ids(
            self.admin_context, [vm.get_id()])[0]
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after,
            vm_queried.get_vmGlobalSettings().get_lastModifiedEpoch()))
        self.assert_(
            vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
        self.assert_(vm_modified.get_vmGlobalSettings().get_createEpoch() ==
                     vm_queried.get_vmGlobalSettings().get_createEpoch())
コード例 #3
0
    def test_vm_save_update(self):
        '''
        Update an existing object in db
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id(vm.id)
        vmGlobalSettings.set_autoStartAction('autoStartAction')
        vmGlobalSettings.set_autoStopAction('autoStopAction')
        vm.set_vmGlobalSettings(vmGlobalSettings)
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id])
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
        vm = vms[0]
        self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same")
        vmGlobalSets = vm.get_vmGlobalSettings()
        self.assertTrue(vmGlobalSets is not None)
        self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vmGlobalSets.get_autoStartAction(),
                         'autoStartAction', "autoStartAction is not same")
        self.assertEqual(vmGlobalSets.get_autoStopAction(),
                         'autoStopAction', "autoStopAction is not same")
コード例 #4
0
ファイル: test_vm_db_api.py プロジェクト: emonty/healthnmon
    def test_vm_save_update(self):
        '''
        Update an existing object in db
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id(vm.id)
        vmGlobalSettings.set_autoStartAction('autoStartAction')
        vmGlobalSettings.set_autoStopAction('autoStopAction')
        vm.set_vmGlobalSettings(vmGlobalSettings)
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id])
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
        vm = vms[0]
        self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same")
        vmGlobalSets = vm.get_vmGlobalSettings()
        self.assertTrue(vmGlobalSets is not None)
        self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction',
                         "autoStartAction is not same")
        self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction',
                         "autoStopAction is not same")
コード例 #5
0
    def test_vm_host_get_all(self):
        '''
        Inserts more than one host with vms and storage volumes.
        Also validates the data retrieved from the vmhost, vm, storage volumes.
        '''
        vmhost = VmHost()
        vmhost.id = 'VH1-id'
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        vmhost = VmHost()
        vmhost.id = 'VH2-id'
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        vm = Vm()
        vm.id = 'VM1-id'
        vm.set_vmHostId('VH1-id')
        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id(vm.id)
        vmGlobalSettings.set_autoStartAction('autoStartAction')
        vmGlobalSettings.set_autoStopAction('autoStopAction')
        vm.set_vmGlobalSettings(vmGlobalSettings)
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        mntPnt = HostMountPoint()
        mntPnt.set_vmHostId('VH1-id')
        mntPnt.set_path('/path')
        volume = StorageVolume()
        sv_id = 'SV1-id'
        volume.set_id(sv_id)
        volume.add_mountPoints(mntPnt)
        healthnmon_db_api.storage_volume_save(get_admin_context(), volume)

        vmhosts = healthnmon_db_api.vm_host_get_all(get_admin_context())
        self.assertFalse(vmhosts is None,
                         'vm_host_get_all returned a None')
        self.assertTrue(
            len(vmhosts) == 2,
            'vm_host_get_all does not returned expected number of hosts')
        self.assertEqual(vmhosts[0].get_id(),
                         'VH1-id', "VMHost id is not same")
        self.assertEqual(vmhosts[1].get_id(),
                         'VH2-id', "VMHost id is not same")
        vmlist = vmhosts[0].get_virtualMachineIds()
        self.assertFalse(vmlist is None,
                         "virtual machines from the host returned None")
        self.assertTrue(
            len(vmlist) == 1,
            "length of virtual machines list is not returned as expected")
        self.assertTrue(vm.id in vmlist,
                        "VmId is not in host")

        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1-id'])
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
        vm = vms[0]
        self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same")
        vmGlobalSets = vm.get_vmGlobalSettings()
        self.assertTrue(vmGlobalSets is not None)
        self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vmGlobalSets.get_autoStartAction(),
                         'autoStartAction', "autoStartAction is not same")
        self.assertEqual(vmGlobalSets.get_autoStopAction(),
                         'autoStopAction', "autoStopAction is not same")

        svlist = vmhosts[0].get_storageVolumeIds()
        self.assertFalse(svlist is None,
                         "Storage Volumes from the host returned None")
        self.assertTrue(
            len(svlist) >= 1,
            "length of storage volumes list is not returned as expected")
        self.assertTrue(sv_id in svlist,
                        "Storage Volume Id is not host")

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(get_admin_context(),
                                                        ['SV1-id'])
        self.assertFalse(storagevolumes is None,
                         'Storage volume get by id returned a none list')
        self.assertTrue(
            len(storagevolumes) > 0,
            'Storage volume get by id returned invalid number of list')
        self.assertEquals(storagevolumes[0].id,
                          'SV1-id', "Storage volume id is not same")
        hostMountPoints = storagevolumes[0].get_mountPoints()
        self.assertEquals(hostMountPoints[0].get_path(),
                          '/path', "Host mount point path is not same")
        self.assertEquals(
            hostMountPoints[0].get_vmHostId(),
            'VH1-id', "VmHost id is not same for storage volumes")
コード例 #6
0
ファイル: test_api.py プロジェクト: jessegonzalez/healthnmon
class APiTest(test.TestCase):

    ''' TestCase for healthnmon.notifier.api '''

    def setUp(self):
        super(APiTest, self).setUp()
        self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic')
        self.vm = Vm()
        self.vm.set_id('12345')
        self.vm.set_name('TestVm')
        self.flags(healthnmon_notification_drivers=[
            'nova.openstack.common.notifier.test_notifier'])
        test_notifier.NOTIFICATIONS = []

    def testNotify(self):

        scheduler_services = [{'host': 'testhost'}]

        nova_db. \
            service_get_all_by_topic(
                mox.IgnoreArg(),
                mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(events_api.notify(
            event_metadata.EVENT_TYPE_VM_DELETED,
            self.vm), None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'],
                          'testhost.healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'],
                          self.vm.get_id())

    def testNotifyNoneScheduler(self):

        scheduler_services = None

        nova_db. \
            service_get_all_by_topic(
                mox.IgnoreArg(),
                mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(events_api.notify(
            event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'],
                          'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'],
                          self.vm.get_id())

    def testNotifyEmptyScheduler(self):

        scheduler_services = []

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(events_api.notify(
            event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'],
                          'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'],
                          self.vm.get_id())

    def testNotifyMultipleScheduler(self):

        scheduler_services = [{'host': 'testhost'}, {'host': 'testhost2'
                                                     }]

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(events_api.notify(
            event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'],
                          'testhost.healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'],
                          self.vm.get_id())

    def testNotifyNoneSchedulerHost(self):

        scheduler_services = [{'host': None}]

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(events_api.notify(
            event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'],
                          'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'],
                          self.vm.get_id())

    def testNotifyExceptionScheduler(self):
        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg()).AndRaise(Exception())
        self.mox.ReplayAll()
        self.assertEquals(events_api.notify(
            event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = event_metadata.get_EventMetaData(
            event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'],
                          'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'],
                          self.vm.get_id())

    def tearDown(self):
        super(APiTest, self).tearDown()
コード例 #7
0
    def test_vm_host_get_all(self):
        '''
        Inserts more than one host with vms and storage volumes.
        Also validates the data retrieved from the vmhost, vm, storage volumes.
        '''
        vmhost = VmHost()
        vmhost.id = 'VH1-id'
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        vmhost = VmHost()
        vmhost.id = 'VH2-id'
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        vm = Vm()
        vm.id = 'VM1-id'
        vm.set_vmHostId('VH1-id')
        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id(vm.id)
        vmGlobalSettings.set_autoStartAction('autoStartAction')
        vmGlobalSettings.set_autoStopAction('autoStopAction')
        vm.set_vmGlobalSettings(vmGlobalSettings)
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        mntPnt = HostMountPoint()
        mntPnt.set_vmHostId('VH1-id')
        mntPnt.set_path('/path')
        volume = StorageVolume()
        sv_id = 'SV1-id'
        volume.set_id(sv_id)
        volume.add_mountPoints(mntPnt)
        healthnmon_db_api.storage_volume_save(get_admin_context(), volume)

        vmhosts = healthnmon_db_api.vm_host_get_all(get_admin_context())
        self.assertFalse(vmhosts is None, 'vm_host_get_all returned a None')
        self.assertTrue(
            len(vmhosts) == 2,
            'vm_host_get_all does not returned expected number of hosts')
        self.assertEqual(vmhosts[0].get_id(), 'VH1-id',
                         "VMHost id is not same")
        self.assertEqual(vmhosts[1].get_id(), 'VH2-id',
                         "VMHost id is not same")
        vmlist = vmhosts[0].get_virtualMachineIds()
        self.assertFalse(vmlist is None,
                         "virtual machines from the host returned None")
        self.assertTrue(
            len(vmlist) == 1,
            "length of virtual machines list is not returned as expected")
        self.assertTrue(vm.id in vmlist, "VmId is not in host")

        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1-id'])
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
        vm = vms[0]
        self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same")
        vmGlobalSets = vm.get_vmGlobalSettings()
        self.assertTrue(vmGlobalSets is not None)
        self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction',
                         "autoStartAction is not same")
        self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction',
                         "autoStopAction is not same")

        svlist = vmhosts[0].get_storageVolumeIds()
        self.assertFalse(svlist is None,
                         "Storage Volumes from the host returned None")
        self.assertTrue(
            len(svlist) >= 1,
            "length of storage volumes list is not returned as expected")
        self.assertTrue(sv_id in svlist, "Storage Volume Id is not host")

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(get_admin_context(),
                                                        ['SV1-id'])
        self.assertFalse(storagevolumes is None,
                         'Storage volume get by id returned a none list')
        self.assertTrue(
            len(storagevolumes) > 0,
            'Storage volume get by id returned invalid number of list')
        self.assertEquals(storagevolumes[0].id, 'SV1-id',
                          "Storage volume id is not same")
        hostMountPoints = storagevolumes[0].get_mountPoints()
        self.assertEquals(hostMountPoints[0].get_path(), '/path',
                          "Host mount point path is not same")
        self.assertEquals(hostMountPoints[0].get_vmHostId(), 'VH1-id',
                          "VmHost id is not same for storage volumes")
コード例 #8
0
class APiTest(test.TestCase):
    ''' TestCase for healthnmon.notifier.api '''
    def setUp(self):
        super(APiTest, self).setUp()
        self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic')
        self.vm = Vm()
        self.vm.set_id('12345')
        self.vm.set_name('TestVm')
        self.flags(healthnmon_notification_drivers=[
            'nova.openstack.common.notifier.test_notifier'
        ])
        test_notifier.NOTIFICATIONS = []

    def testNotify(self):

        scheduler_services = [{'host': 'testhost'}]

        nova_db. \
            service_get_all_by_topic(
                mox.IgnoreArg(),
                mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(
            events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm),
            None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'], 'testhost.healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], self.vm.get_id())

    def testNotifyNoneScheduler(self):

        scheduler_services = None

        nova_db. \
            service_get_all_by_topic(
                mox.IgnoreArg(),
                mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(
            events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm),
            None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'], 'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], self.vm.get_id())

    def testNotifyEmptyScheduler(self):

        scheduler_services = []

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(
            events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm),
            None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'], 'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], self.vm.get_id())

    def testNotifyMultipleScheduler(self):

        scheduler_services = [{'host': 'testhost'}, {'host': 'testhost2'}]

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(
            events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm),
            None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'], 'testhost.healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], self.vm.get_id())

    def testNotifyNoneSchedulerHost(self):

        scheduler_services = [{'host': None}]

        nova_db.service_get_all_by_topic(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(scheduler_services)
        self.mox.ReplayAll()
        self.assertEquals(
            events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm),
            None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'], 'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], self.vm.get_id())

    def testNotifyExceptionScheduler(self):
        nova_db.service_get_all_by_topic(mox.IgnoreArg(),
                                         mox.IgnoreArg()).AndRaise(Exception())
        self.mox.ReplayAll()
        self.assertEquals(
            events_api.notify(event_metadata.EVENT_TYPE_VM_DELETED, self.vm),
            None)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = event_metadata.get_EventMetaData(
            event_metadata.EVENT_TYPE_VM_DELETED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        self.assertEquals(msg['publisher_id'], 'healthnmon')
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'Vm')
        self.assertEquals(payload['entity_id'], self.vm.get_id())

    def tearDown(self):
        super(APiTest, self).tearDown()