Esempio n. 1
0
 def _createCache(self):
     self.mox.StubOutWithMock(api, 'vm_host_get_all')
     vmhost = VmHost()
     vmhost.set_id('vmhost1')
     vmhost1 = VmHost()
     vmhost1.set_id('vmhost2')
     vm = Vm()
     vm.set_id('vm1')
     vm.set_powerState(Constants.VM_POWER_STATES[1])
     vm.set_vmHostId('vmhost1')
     vm1 = Vm()
     vm1.set_id('vm2')
     vm1.set_powerState(Constants.VM_POWER_STATES[1])
     vm1.set_vmHostId('vmhost2')
     vmhost.set_virtualMachineIds(['vm1', 'vm2'])
     stPool = StorageVolume()
     stPool.set_id('stpool1')
     subNet = Subnet()
     subNet.set_id('net1')
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1])
     self.mox.StubOutWithMock(api, 'vm_get_all')
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1])
     self.mox.StubOutWithMock(api, 'storage_volume_get_all')
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, 'subnet_get_all')
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
Esempio n. 2
0
    def test_storage_no_state_change(self):
        storagePool = libvirt.virStoragePool()
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(mox.IgnoreArg(),
                                mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        cachedStorageVolume = StorageVolume()
        cachedStorageVolume.id = storagePool.UUIDString()
        cachedStorageVolume.size = 0
        cachedStorageVolume.free = 0
        cachedStorageVolume.connectionState = \
            Constants.STORAGE_STATE_ACTIVE
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(storagePool.UUIDString(),
                                                    Constants.StorageVolume).AndReturn(cachedStorageVolume)
#        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
#
#        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
#                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        nova_db.service_get_all_by_topic(None, None)
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
Esempio n. 3
0
    def test_vm_host_get_by_id(self):
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_id
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        vm = Vm()
        vm.id = 'VM11'
        vm.set_vmHostId(host_id)
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        mntPnt = HostMountPoint()
        mntPnt.set_vmHostId(host_id)
        mntPnt.set_path('/path')
        volume = StorageVolume()
        volume.set_id('SV11')
        volume.add_mountPoints(mntPnt)
        healthnmon_db_api.storage_volume_save(get_admin_context(),
                                              volume)

        vmhosts = \
            healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
                                                 [host_id])
        self.assertFalse(vmhosts is None,
                         'Host get by id returned a none list')
        self.assertTrue(len(vmhosts) > 0,
                        'Host get by id returned invalid number of list'
                        )
        self.assertTrue(vmhosts[0].id == host_id)
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch,
         modifiedEpoch and deletedEpoch
     """
     vol = StorageVolume()
     vol.set_id('vol-01')
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.storage_volume_save(self.admin_context, vol)
     epoch_after = utils.get_current_epoch_ms()
     vol_queried = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, [vol.get_id()])[0]
     self.assert_(test_utils.is_timestamp_between(
         epoch_before, epoch_after, vol_queried.get_createEpoch()))
     # Check for lastModifiedEpoch
     vol_modified = vol_queried
     test_utils.unset_timestamp_fields(vol_modified)
     vol_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.storage_volume_save(self.admin_context, vol_modified)
     epoch_after = utils.get_current_epoch_ms()
     vol_queried = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, [vol.get_id()])[0]
     self.assert_(
         vol_modified.get_createEpoch() == vol_queried.get_createEpoch())
     self.assert_(test_utils.is_timestamp_between(
         epoch_before, epoch_after, vol_queried.get_lastModifiedEpoch()))
Esempio n. 5
0
    def test_storage_deleted_event(self):
        self.mox.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')
        deleted_storage_id = '3fbfbefb-17dd-07aa-2dac-13afbedf3be3'
        deleted_storage = StorageVolume()
        deleted_storage.id = deleted_storage_id

        InventoryCacheManager.get_object_from_cache(
            deleted_storage_id,
            Constants.StorageVolume).AndReturn(deleted_storage)
        self.mox.ReplayAll()
        cachedList = [deleted_storage_id,
                      '3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        self.mox.ReplayAll()
        self.LibvirtStorageVolume.processStorageDeletes(cachedList,
                                                        updatedList)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        eventMetaData = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DELETED)
        event_type = eventMetaData.get_event_fully_qal_name()
        self.assertEquals(msg['event_type'], event_type)
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], deleted_storage_id)
 def _createCache(self):
     self.mox.StubOutWithMock(api, "vm_host_get_all")
     vmhost = VmHost()
     vmhost.set_id("vmhost1")
     vmhost1 = VmHost()
     vmhost1.set_id("vmhost2")
     vm = Vm()
     vm.set_id("vm1")
     vm.set_powerState(Constants.VM_POWER_STATES[1])
     vm.set_vmHostId("vmhost1")
     vm1 = Vm()
     vm1.set_id("vm2")
     vm1.set_powerState(Constants.VM_POWER_STATES[1])
     vm1.set_vmHostId("vmhost2")
     vmhost.set_virtualMachineIds(["vm1", "vm2"])
     stPool = StorageVolume()
     stPool.set_id("stpool1")
     subNet = Subnet()
     subNet.set_id("net1")
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1])
     self.mox.StubOutWithMock(api, "vm_get_all")
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1])
     self.mox.StubOutWithMock(api, "storage_volume_get_all")
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, "subnet_get_all")
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
 def test_storagevolume_save(self):
     storagevolume = StorageVolume()
     storagevolume.id = 'SV1'
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
Esempio n. 8
0
    def test_storage_deleted_event(self):
        self.mox.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')
        deleted_storage_id = '3fbfbefb-17dd-07aa-2dac-13afbedf3be3'
        deleted_storage = StorageVolume()
        deleted_storage.id = deleted_storage_id

        InventoryCacheManager.get_object_from_cache(
            deleted_storage_id,
            Constants.StorageVolume).AndReturn(deleted_storage)
        self.mox.ReplayAll()
        cachedList = [
            deleted_storage_id, '3fbfbefb-17dd-07aa-2dac-13afbedf1234'
        ]
        updatedList = ['3fbfbefb-17dd-07aa-2dac-13afbedf1234']
        self.mox.ReplayAll()
        self.LibvirtStorageVolume.processStorageDeletes(
            cachedList, updatedList)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        eventMetaData = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DELETED)
        event_type = eventMetaData.get_event_fully_qal_name()
        self.assertEquals(msg['event_type'], event_type)
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], deleted_storage_id)
 def test_storagevolume_save(self):
     storagevolume = StorageVolume()
     storagevolume.id = 'SV1'
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
Esempio n. 10
0
    def test_storage_enabled_event(self):
        storagePool = libvirt.virStoragePool()
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        cachedStorageVolume = StorageVolume()
        cachedStorageVolume.id = storagePool.UUIDString()
        cachedStorageVolume.size = 0
        cachedStorageVolume.free = 0
        cachedStorageVolume.connectionState = \
            Constants.STORAGE_STATE_INACTIVE
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(),
            Constants.StorageVolume).AndReturn(cachedStorageVolume)
        self.mox.ReplayAll()
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.INFO)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_ENABLED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'],
                          storagePool.UUIDString())
        self.assertEquals(payload['state'],
                          Constants.STORAGE_STATE_ACTIVE)
Esempio n. 11
0
    def test_vm_host_get_all_for_sv(self):
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_id
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        mntPnt = HostMountPoint()
        mntPnt.set_vmHostId(host_id)
        mntPnt.set_path('/path')
        volume = StorageVolume()
        volume.set_id('SV11')
        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,
                         'Host get by id returned a none list')
        self.assertTrue(
            len(vmhosts) > 0, 'Host get by id returned invalid number of list')
        self.assertTrue(vmhosts[0].id == host_id)
        svlist = vmhosts[0].get_storageVolumeIds()
        self.assert_(svlist is not None)
        self.assert_(len(svlist) == 1)
        self.assert_(volume.get_id() in svlist)

        healthnmon_db_api.storage_volume_delete_by_ids(get_admin_context(),
                                                       [volume.get_id()])
        vmhosts = \
            healthnmon_db_api.vm_host_get_all(get_admin_context())
        self.assertTrue(vmhosts[0].id == host_id)
        svids = vmhosts[0].get_storageVolumeIds()
        self.assert_((svids is None) or (len(svids) == 0))
 def __create_volume(self, **kwargs):
     vol = StorageVolume()
     if kwargs is not None:
         for field in kwargs:
             setattr(vol, field, kwargs[field])
     healthnmon_db_api.storage_volume_save(self.admin_context, vol)
     return vol
    def test_storagevolume_get_by_id(self):
        storagevolume_id = 'SV1'
        storagevolume = StorageVolume()
        storagevolume.id = storagevolume_id
        healthnmon_db_api.storage_volume_save(self.admin_context,
                                              storagevolume)

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
                                                        [storagevolume_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.assertTrue(storagevolumes[0].id == 'SV1')
    def test_storagevolume_get_by_id(self):
        storagevolume_id = 'SV1'
        storagevolume = StorageVolume()
        storagevolume.id = storagevolume_id
        healthnmon_db_api.storage_volume_save(self.admin_context,
                                              storagevolume)

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
                                                        [storagevolume_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.assertTrue(storagevolumes[0].id == 'SV1')
Esempio n. 15
0
 def _createCache(self):
     self.mox.StubOutWithMock(api, 'vm_host_get_all')
     vmhost = VmHost()
     vmhost.set_id('vmhost1')
     vm = Vm()
     vm.set_id('vm1')
     stPool = StorageVolume()
     stPool.set_id('stpool1')
     subnet = Subnet()
     subnet.set_id('bridge0')
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost])
     self.mox.StubOutWithMock(api, 'vm_get_all')
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm])
     self.mox.StubOutWithMock(api, 'storage_volume_get_all')
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, 'subnet_get_all')
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subnet])
Esempio n. 16
0
 def _createCache(self):
     self.mox.StubOutWithMock(api, 'vm_host_get_all')
     vmhost = VmHost()
     vmhost.set_id('vmhost1')
     vm = Vm()
     vm.set_id('vm1')
     stPool = StorageVolume()
     stPool.set_id('stpool1')
     subnet = Subnet()
     subnet.set_id('bridge0')
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost])
     self.mox.StubOutWithMock(api, 'vm_get_all')
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm])
     self.mox.StubOutWithMock(api, 'storage_volume_get_all')
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, 'subnet_get_all')
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subnet])
Esempio n. 17
0
 def test_diff_getAllMembers_emptyDict(self):
     storagevolume = StorageVolume()
     storagevolume1 = StorageVolume()
     self.mox.StubOutWithMock(StorageVolume, 'get_all_members')
     storagevolume.get_all_members().AndReturn({})
     storagevolume1.get_all_members().AndReturn({})
     self.mox.ReplayAll()
     diff = ResourceModelDiff(storagevolume, storagevolume1)
     diff_res = diff.diff_resourcemodel()
     self.assertTrue(len(diff_res) == 0)
Esempio n. 18
0
 def test_diff_dict_emptyDict(self):
     storagevolume = StorageVolume()
     hostMountPoint = HostMountPoint({})
     storagevolume.add_mountPoints(hostMountPoint)
     storagevolume1 = StorageVolume()
     hostMountPoint1 = HostMountPoint({})
     storagevolume1.add_mountPoints(hostMountPoint1)
     diff = ResourceModelDiff(storagevolume, storagevolume1)
     diff_res = diff.diff_resourcemodel()
     self.assertTrue(len(diff_res) == 0)
Esempio n. 19
0
    def test_vm_host_get_all_for_sv(self):
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_id
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        mntPnt = HostMountPoint()
        mntPnt.set_vmHostId(host_id)
        mntPnt.set_path('/path')
        volume = StorageVolume()
        volume.set_id('SV11')
        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,
                         'Host get by id returned a none list')
        self.assertTrue(len(vmhosts) > 0,
                        'Host get by id returned invalid number of list'
                        )
        self.assertTrue(vmhosts[0].id == host_id)
        svlist = vmhosts[0].get_storageVolumeIds()
        self.assert_(svlist is not None)
        self.assert_(len(svlist) == 1)
        self.assert_(volume.get_id() in svlist)

        healthnmon_db_api.storage_volume_delete_by_ids(
            get_admin_context(), [volume.get_id()])
        vmhosts = \
            healthnmon_db_api.vm_host_get_all(get_admin_context())
        self.assertTrue(vmhosts[0].id == host_id)
        svids = vmhosts[0].get_storageVolumeIds()
        self.assert_((svids is None) or (len(svids) == 0))
 def test_storagevolume_get_all(self):
     storagevolume = StorageVolume()
     storagevolume.id = 'SV1'
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
     storagevolume = StorageVolume()
     storagevolume.id = 'SV2'
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
     storagevolumes = \
         healthnmon_db_api.storage_volume_get_all(self.admin_context)
     self.assertFalse(storagevolumes is None,
                      'storage volume all returned a none list')
     self.assertTrue(len(storagevolumes) == 2,
                     'storage volume all returned invalid number of list'
                     )
     self.assertTrue(
         storagevolumes[0].id == 'SV1', 'Storage volume id mismatch')
     self.assertTrue(
         storagevolumes[1].id == 'SV2', 'Storage volume id mismatch')
Esempio n. 21
0
    def test_vm_host_get_by_id(self):
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_id
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        vm = Vm()
        vm.id = 'VM11'
        vm.set_vmHostId(host_id)
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        mntPnt = HostMountPoint()
        mntPnt.set_vmHostId(host_id)
        mntPnt.set_path('/path')
        volume = StorageVolume()
        volume.set_id('SV11')
        volume.add_mountPoints(mntPnt)
        healthnmon_db_api.storage_volume_save(get_admin_context(), volume)

        vmhosts = \
            healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
                                                 [host_id])
        self.assertFalse(vmhosts is None,
                         'Host get by id returned a none list')
        self.assertTrue(
            len(vmhosts) > 0, 'Host get by id returned invalid number of list')
        self.assertTrue(vmhosts[0].id == host_id)
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch, modifiedEpoch and deletedEpoch
     """
     vol = StorageVolume()
     vol.set_id('vol-01')
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.storage_volume_save(self.admin_context, vol)
     epoch_after = utils.get_current_epoch_ms()
     vol_queried = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, [vol.get_id()])[0]
     self.assert_(
         test_utils.is_timestamp_between(epoch_before, epoch_after,
                                         vol_queried.get_createEpoch()))
     # Check for lastModifiedEpoch
     vol_modified = vol_queried
     test_utils.unset_timestamp_fields(vol_modified)
     vol_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.storage_volume_save(self.admin_context, vol_modified)
     epoch_after = utils.get_current_epoch_ms()
     vol_queried = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, [vol.get_id()])[0]
     self.assert_(
         vol_modified.get_createEpoch() == vol_queried.get_createEpoch())
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             vol_queried.get_lastModifiedEpoch()))
Esempio n. 23
0
    def test_storage_no_state_change(self):
        storagePool = libvirt.virStoragePool()
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        cachedStorageVolume = StorageVolume()
        cachedStorageVolume.id = storagePool.UUIDString()
        cachedStorageVolume.size = 0
        cachedStorageVolume.free = 0
        cachedStorageVolume.connectionState = \
            Constants.STORAGE_STATE_ACTIVE
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(),
            Constants.StorageVolume).AndReturn(cachedStorageVolume)
        #        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
        #
        #        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
        #                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        nova_db.service_get_all_by_topic(None, None)
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
    def test_storagevolume_delete(self):
        storagevolume = StorageVolume()
        storagevolume_id = 'SV1'
        storagevolume.id = storagevolume_id
        vm = Vm()
        vm.set_id('vm-01')
        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id('vm_01')
        vm.set_vmGlobalSettings(vmGlobalSettings)
        vmDisk = VmDisk()
        vmDisk.set_id('disk-01')
        vmDisk.set_storageVolumeId(storagevolume_id)
        vm.add_vmDisks(vmDisk)
        vmDisk = VmDisk()
        vmDisk.set_id('disk-02')
        vmDisk.set_storageVolumeId('SV2')
        vm.add_vmDisks(vmDisk)
        healthnmon_db_api.vm_save(self.admin_context, vm)

        healthnmon_db_api.storage_volume_save(self.admin_context,
                                              storagevolume)

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
                                                        [storagevolume_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')

        healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context,
                                                       [storagevolume_id])

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
                                                        [storagevolume_id])
        self.assertTrue(storagevolumes is None or len(storagevolumes)
                        == 0, 'Storage volume not deleted')
    def test_storagevolume_delete(self):
        storagevolume = StorageVolume()
        storagevolume_id = 'SV1'
        storagevolume.id = storagevolume_id
        vm = Vm()
        vm.set_id('vm-01')
        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id('vm_01')
        vm.set_vmGlobalSettings(vmGlobalSettings)
        vmDisk = VmDisk()
        vmDisk.set_id('disk-01')
        vmDisk.set_storageVolumeId(storagevolume_id)
        vm.add_vmDisks(vmDisk)
        vmDisk = VmDisk()
        vmDisk.set_id('disk-02')
        vmDisk.set_storageVolumeId('SV2')
        vm.add_vmDisks(vmDisk)
        healthnmon_db_api.vm_save(self.admin_context, vm)

        healthnmon_db_api.storage_volume_save(self.admin_context,
                                              storagevolume)

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
                                                        [storagevolume_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')

        healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context,
                                                       [storagevolume_id])

        storagevolumes = \
            healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
                                                        [storagevolume_id])
        self.assertTrue(storagevolumes is None or len(storagevolumes) == 0,
                        'Storage volume not deleted')
Esempio n. 26
0
    def test_processUpdates_hostupdate_event(self):
        defaultInstancesPath = cfg.CONF.instances_path
        cfg.CONF.set_override('instances_path', '/var/lib/libvirt/images')
        storagePool = libvirt.virStoragePool()
        self.mock.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(mox.IgnoreArg(),
                                mox.IgnoreArg()).MultipleTimes().\
            AndReturn(None)
        cachedStorageVolume = StorageVolume()
        cachedStorageVolume.id = storagePool.UUIDString()
        cachedStorageVolume.size = 0
        cachedStorageVolume.free = 0
        cachedStorageVolume.connectionState = \
            Constants.STORAGE_STATE_INACTIVE
        InventoryCacheManager.update_object_in_cache(
            '95f7101b-892c-c388-867a-8340e5fea27x', cachedStorageVolume)

        self.mock.StubOutWithMock(api, 'storage_volume_delete_by_ids')

        api.storage_volume_delete_by_ids(mox.IgnoreArg(),
                                         mox.IgnoreArg()).MultipleTimes().\
            AndReturn(None)

        self.mock.StubOutWithMock(
            InventoryCacheManager, 'get_compute_conn_driver')

        InventoryCacheManager.get_compute_conn_driver(None,
                                                      Constants.VmHost).\
            AndReturn(fake.
                      get_connection())

        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtStorageVolume.processUpdates(),
                          None)
        self.assertEquals(self.LibvirtStorageVolume._createNovaPool(),
                          None)
        cfg.CONF.set_override('instances_path', defaultInstancesPath)
        self.mock.stubs.UnsetAll()
Esempio n. 27
0
 def test_diff_dict_emptyDict(self):
     storagevolume = StorageVolume()
     hostMountPoint = HostMountPoint({})
     storagevolume.add_mountPoints(hostMountPoint)
     storagevolume1 = StorageVolume()
     hostMountPoint1 = HostMountPoint({})
     storagevolume1.add_mountPoints(hostMountPoint1)
     diff = ResourceModelDiff(storagevolume, storagevolume1)
     diff_res = diff.diff_resourcemodel()
     self.assertTrue(len(diff_res) == 0)
Esempio n. 28
0
 def test_diff_getAllMembers_emptyDict(self):
     storagevolume = StorageVolume()
     storagevolume1 = StorageVolume()
     self.mox.StubOutWithMock(StorageVolume, 'get_all_members')
     storagevolume.get_all_members().AndReturn({})
     storagevolume1.get_all_members().AndReturn({})
     self.mox.ReplayAll()
     diff = ResourceModelDiff(storagevolume, storagevolume1)
     diff_res = diff.diff_resourcemodel()
     self.assertTrue(len(diff_res) == 0)
 def test_storagevolume_get_all(self):
     storagevolume = StorageVolume()
     storagevolume.id = 'SV1'
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
     storagevolume = StorageVolume()
     storagevolume.id = 'SV2'
     healthnmon_db_api.storage_volume_save(self.admin_context,
                                           storagevolume)
     storagevolumes = \
         healthnmon_db_api.storage_volume_get_all(self.admin_context)
     self.assertFalse(storagevolumes is None,
                      'storage volume all returned a none list')
     self.assertTrue(
         len(storagevolumes) == 2,
         'storage volume all returned invalid number of list')
     self.assertTrue(storagevolumes[0].id == 'SV1',
                     'Storage volume id mismatch')
     self.assertTrue(storagevolumes[1].id == 'SV2',
                     'Storage volume id mismatch')
Esempio n. 30
0
    def test_storage_disabled_event(self):
        storagePool = libvirt.virStoragePool()
        self.mox.StubOutWithMock(api, 'storage_volume_save')

        api.storage_volume_save(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        cachedStorageVolume = StorageVolume()
        cachedStorageVolume.id = storagePool.UUIDString()
        cachedStorageVolume.size = 0
        cachedStorageVolume.free = 0
        cachedStorageVolume.connectionState = \
            Constants.STORAGE_STATE_ACTIVE
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            storagePool.UUIDString(),
            Constants.StorageVolume).AndReturn(cachedStorageVolume)
        self.mox.StubOutWithMock(storagePool, 'isActive')
        storagePool.isActive().AndReturn(0)

        #        self.mox.StubOutWithMock(InventoryCacheManager, 'get_compute_conn_driver')
        #
        #        InventoryCacheManager.get_compute_conn_driver(self.LibvirtStorageVolume.compute_id,
        #                Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.ReplayAll()
        self.LibvirtStorageVolume._processStorage(storagePool)
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], notifier_api.WARN)
        event_type = \
            event_metadata.get_EventMetaData(
                event_metadata.EVENT_TYPE_STORAGE_DISABLED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'StorageVolume')
        self.assertEquals(payload['entity_id'], storagePool.UUIDString())
        self.assertEquals(payload['state'], Constants.STORAGE_STATE_INACTIVE)
Esempio n. 31
0
    def test_diff_resourcemodel_storagevolume_withupdate(self):
        """Unit Test to test for resource model comparison with some change """

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-9')
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-112')
        storagevolume1.set_name('datastore-112')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint1 = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-19')
        storagevolume1.add_mountPoints(hostMountPoint1)

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)
        self.assertTrue(self.update in diff_res)
        mountPoints = 'mountPoints'
        vmHostId = 'vmHostId'
        self.assertTrue(mountPoints in diff_res[self.update])
        self.assertTrue(self.update in diff_res[self.update][mountPoints])
        key = diff_res[self.update][mountPoints][self.update].keys()[0]
        self.assertTrue(self.update in diff_res[self.update][mountPoints][
            self.update][key])
        self.assertTrue(vmHostId in diff_res[self.update][mountPoints][
            self.update][key][self.update])
        self.assertEquals(diff_res[self.update][mountPoints][self.update][
            key][self.update][vmHostId], 'host-19')
Esempio n. 32
0
    def test_diff_resourcemodel_storagevolume_withdelete_withDict(self):
        """Unit Test to test for resource model comparison with some change """

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint = \
            HostMountPoint(
                {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                 '2': 'host-9'})
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-114')
        storagevolume1.set_name('datastore-114')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'})

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)

        self.assertTrue(self.update in diff_res)
        mountPoints = 'mountPoints'
        self.assertTrue(mountPoints in diff_res[self.update])
        self.assertTrue(self.delete in diff_res[self.update][mountPoints])

        key = diff_res[self.update][mountPoints][self.delete].keys()[0]
        self.assertTrue(
            isinstance(diff_res[self.update][mountPoints][self.delete][key],
                       HostMountPoint))
        delMount = diff_res[self.update][mountPoints][self.delete][key]
        self.assertEquals(
            delMount.pathProp, {
                '1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                '2': 'host-9'
            })

        self.assertTrue('id' in diff_res[self.update])
        self.assertEquals(diff_res[self.update]['id'], 'datastore-114')

        self.assertTrue('name' in diff_res[self.update])
        self.assertEquals(diff_res[self.update]['name'], 'datastore-114')

        self.assertTrue('volumeId' in diff_res[self.update])
        self.assertEquals(
            diff_res[self.update]['volumeId'],
            {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'})
Esempio n. 33
0
    def test_diff_differentDict(self):
        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint = \
            HostMountPoint(
                {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                 '2': 'host-9'})
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-112')
        storagevolume1.set_name('datastore-112')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint1 = \
            HostMountPoint(
                {'3': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                 '4': 'host-19'})
        storagevolume1.add_mountPoints(hostMountPoint1)

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)
        self.assertTrue(self.update in diff_res)
        mountPoints = 'mountPoints'

        self.assertTrue(mountPoints in diff_res[self.update])
        self.assertTrue(self.update in diff_res[self.update][mountPoints])

        key = diff_res[self.update][mountPoints][self.update].keys()[0]

        self.assertTrue(self.update in diff_res[self.update][mountPoints][
            self.update][key])
        self.assertTrue('path' in diff_res[self.update][mountPoints][
            self.update][key][self.update])
        self.assertTrue(self.add in diff_res[self.update][mountPoints][
            self.update][key][self.update]['path'])
        self.assertTrue('3' in diff_res[self.update][mountPoints][
                        self.update][key][self.update]['path'][self.add])
        self.assertEquals(diff_res[self.update][mountPoints][self.update][
            key][self.update]['path'][self.add]['3'],
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        self.assertTrue('4' in diff_res[self.update][mountPoints][
                        self.update][key][self.update]['path'][self.add])
        self.assertEquals(diff_res[self.update][mountPoints][self.update][
            key][self.update]['path'][self.add]['4'], 'host-19')

        self.assertTrue(self.delete in diff_res[self.update][mountPoints][
            self.update][key][self.update]['path'])
        self.assertTrue('1' in diff_res[self.update][mountPoints][
                        self.update][key][self.update]['path'][self.delete])
        self.assertEquals(diff_res[self.update][mountPoints][self.update][
            key][self.update]['path'][self.delete]['1'],
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        self.assertTrue('2' in diff_res[self.update][mountPoints][
                        self.update][key][self.update]['path'][self.delete])
        self.assertEquals(diff_res[self.update][mountPoints][self.update][
            key][self.update]['path'][self.delete]['2'], 'host-9')
Esempio n. 34
0
    def test_diff_resourcemodel_storagevolume_withdelete_withDict(self):
        """Unit Test to test for resource model comparison with some change """

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint = \
            HostMountPoint(
                {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                 '2': 'host-9'})
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-114')
        storagevolume1.set_name('datastore-114')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'})

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)

        self.assertTrue(self.update in diff_res)
        mountPoints = 'mountPoints'
        self.assertTrue(mountPoints in diff_res[self.update])
        self.assertTrue(self.delete in diff_res[self.update][mountPoints])

        key = diff_res[self.update][mountPoints][self.delete].keys()[0]
        self.assertTrue(isinstance(diff_res[self.update][mountPoints][
                        self.delete][key], HostMountPoint))
        delMount = diff_res[self.update][mountPoints][self.delete][key]
        self.assertEquals(
            delMount.pathProp,
            {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
             '2': 'host-9'})

        self.assertTrue('id' in diff_res[self.update])
        self.assertEquals(diff_res[self.update]['id'], 'datastore-114')

        self.assertTrue('name' in diff_res[self.update])
        self.assertEquals(diff_res[self.update]['name'], 'datastore-114')

        self.assertTrue('volumeId' in diff_res[self.update])
        self.assertEquals(
            diff_res[self.update]['volumeId'],
            {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'})
Esempio n. 35
0
 def test_diff_differentResources(self):
     storagevolume = StorageVolume()
     vm = Vm()
     diff = ResourceModelDiff(storagevolume, vm)
     diff_res = diff.diff_resourcemodel()
     self.assertTrue(len(diff_res) > 0)
 def test_storagevolume_save_throw_exception(self):
     self.assertRaises(Exception, healthnmon_db_api.storage_volume_save,
                       self.admin_context, StorageVolume())
Esempio n. 37
0
 def testStorageVolumePayloadGenerator(self):
     metadata = \
         event_metadata.get_EventMetaData(
             event_metadata.EVENT_TYPE_STORAGE_ADDED)
     obj = StorageVolume()
     obj.name = 'TestStorageVolume'
     obj.connectionState = 'ACTIVE'
     obj.size = 200
     obj.volumeType = 'DIR'
     obj.volumeId = 'TestVolumeId'
     obj.createEpoch = long(time.time() * 1000)
     obj.lastModifiedEpoch = long(time.time() * 1000)
     mount_point = HostMountPoint()
     mount_point.set_path('/root/storage/1')
     mount_point.set_vmHostId('HOST1')
     obj.add_mountPoints(mount_point)
     mount_point = HostMountPoint()
     mount_point.set_path('/root/storage/2')
     mount_point.set_vmHostId('HOST2')
     obj.add_mountPoints(mount_point)
     payload = payload_generator.generate_payload(metadata, obj)
     self.assertEquals(payload['entity_type'],
                       obj.__class__.__name__)
     self.assertEquals(payload['name'], obj.name)
     self.assertEquals(payload['state'], obj.connectionState)
     self.assertTrue(obj.mountPoints[0].path
                     in payload['mount_points'])
Esempio n. 38
0
    def test_diff_resourcemodel_storagevolume_withupdate(self):
        """Unit Test to test for resource model comparison with some change """

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-9')
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-112')
        storagevolume1.set_name('datastore-112')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint1 = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-19')
        storagevolume1.add_mountPoints(hostMountPoint1)

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)
        self.assertTrue(self.update in diff_res)
        mountPoints = 'mountPoints'
        vmHostId = 'vmHostId'
        self.assertTrue(mountPoints in diff_res[self.update])
        self.assertTrue(self.update in diff_res[self.update][mountPoints])
        key = diff_res[self.update][mountPoints][self.update].keys()[0]
        self.assertTrue(self.update in diff_res[self.update][mountPoints][
            self.update][key])
        self.assertTrue(vmHostId in diff_res[self.update][mountPoints][
            self.update][key][self.update])
        self.assertEquals(
            diff_res[self.update][mountPoints][self.update][key][self.update]
            [vmHostId], 'host-19')
Esempio n. 39
0
    def test_diff_differentDict(self):
        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint = \
            HostMountPoint(
                {'1': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                 '2': 'host-9'})
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-112')
        storagevolume1.set_name('datastore-112')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint1 = \
            HostMountPoint(
                {'3': '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                 '4': 'host-19'})
        storagevolume1.add_mountPoints(hostMountPoint1)

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)
        self.assertTrue(self.update in diff_res)
        mountPoints = 'mountPoints'

        self.assertTrue(mountPoints in diff_res[self.update])
        self.assertTrue(self.update in diff_res[self.update][mountPoints])

        key = diff_res[self.update][mountPoints][self.update].keys()[0]

        self.assertTrue(self.update in diff_res[self.update][mountPoints][
            self.update][key])
        self.assertTrue('path' in diff_res[self.update][mountPoints][
            self.update][key][self.update])
        self.assertTrue(self.add in diff_res[self.update][mountPoints][
            self.update][key][self.update]['path'])
        self.assertTrue('3' in diff_res[self.update][mountPoints][self.update]
                        [key][self.update]['path'][self.add])
        self.assertEquals(
            diff_res[self.update][mountPoints][self.update][key][
                self.update]['path'][self.add]['3'],
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        self.assertTrue('4' in diff_res[self.update][mountPoints][self.update]
                        [key][self.update]['path'][self.add])
        self.assertEquals(
            diff_res[self.update][mountPoints][self.update][key][self.update]
            ['path'][self.add]['4'], 'host-19')

        self.assertTrue(self.delete in diff_res[self.update][mountPoints][
            self.update][key][self.update]['path'])
        self.assertTrue('1' in diff_res[self.update][mountPoints][self.update]
                        [key][self.update]['path'][self.delete])
        self.assertEquals(
            diff_res[self.update][mountPoints][self.update][key][
                self.update]['path'][self.delete]['1'],
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        self.assertTrue('2' in diff_res[self.update][mountPoints][self.update]
                        [key][self.update]['path'][self.delete])
        self.assertEquals(
            diff_res[self.update][mountPoints][self.update][key][self.update]
            ['path'][self.delete]['2'], 'host-9')
Esempio n. 40
0
 def testStorageVolumePayloadGenerator(self):
     metadata = \
         event_metadata.get_EventMetaData(
             event_metadata.EVENT_TYPE_STORAGE_ADDED)
     obj = StorageVolume()
     obj.name = 'TestStorageVolume'
     obj.connectionState = 'ACTIVE'
     obj.size = 200
     obj.volumeType = 'DIR'
     obj.volumeId = 'TestVolumeId'
     obj.createEpoch = long(time.time() * 1000)
     obj.lastModifiedEpoch = long(time.time() * 1000)
     mount_point = HostMountPoint()
     mount_point.set_path('/root/storage/1')
     mount_point.set_vmHostId('HOST1')
     obj.add_mountPoints(mount_point)
     mount_point = HostMountPoint()
     mount_point.set_path('/root/storage/2')
     mount_point.set_vmHostId('HOST2')
     obj.add_mountPoints(mount_point)
     payload = payload_generator.generate_payload(metadata, obj)
     self.assertEquals(payload['entity_type'], obj.__class__.__name__)
     self.assertEquals(payload['name'], obj.name)
     self.assertEquals(payload['state'], obj.connectionState)
     self.assertTrue(obj.mountPoints[0].path in payload['mount_points'])
Esempio n. 41
0
    def get_storagevolume_list(self, storageId=None):
        storagevolume_dict = {}
        storagevolume_list = []
        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-111')
        storagevolume.set_name('datastore-111')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(True)
        storagevolume.set_shared(True)
        storagevolume.set_assignedServerCount(2)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5da')
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5da', 'host-9')
        storagevolume.add_mountPoints(hostMountPoint)
        storagevolume_list.append(storagevolume)
        storagevolume_dict[storagevolume.get_id()] = storagevolume

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db', 'host-9')
        storagevolume.add_mountPoints(hostMountPoint)
        storagevolume_list.append(storagevolume)
        storagevolume_dict[storagevolume.get_id()] = storagevolume
        if storageId is not None:
            return [storagevolume_dict[storageId]]
        return storagevolume_list
Esempio n. 42
0
 def testVmHostPayload_with_storage_size(self):
     self.flags(instances_path="/var/lib/nova/instances")
     metadata = \
         event_metadata.get_EventMetaData(
             event_metadata.EVENT_TYPE_HOST_ADDED)
     obj = VmHost()
     obj.name = 'TestVmHost'
     ipProfile = IpProfile()
     ipProfile.ipAddress = '10.10.10.1'
     obj.add_ipAddresses(ipProfile)
     storage_obj = StorageVolume()
     storage_obj.id = "storage_id"
     storage_obj.name = 'TestStorageVolume'
     storage_obj.connectionState = 'ACTIVE'
     storage_obj.size = 200
     storage_obj.free = 100
     storage_obj.volumeType = 'DIR'
     storage_obj.volumeId = 'TestVolumeId'
     storage_obj.createEpoch = long(time.time() * 1000)
     storage_obj.lastModifiedEpoch = long(time.time() * 1000)
     mount_point = HostMountPoint()
     mount_point.set_path('/var/lib/nova/instances')
     mount_point.set_vmHostId('TestVmHost')
     storage_obj.add_mountPoints(mount_point)
     obj.add_storageVolumeIds("storage_id")
     self.mox.StubOutWithMock(InventoryCacheManager,
                              'get_object_from_cache')
     InventoryCacheManager.get_object_from_cache(
         storage_obj.id, Constants.StorageVolume).AndReturn(storage_obj)
     self.mox.ReplayAll()
     payload = payload_generator.generate_payload(metadata, obj)
     self.assertEquals(payload['entity_type'], obj.__class__.__name__)
     self.assertEquals(payload['name'], obj.name)
     self.assertEquals(payload['ipAddresses'], ipProfile.ipAddress)
     self.assertEquals(payload['totalStorageSize'], storage_obj.size)
     self.assertEquals(payload['storageUsed'], storage_obj.free)
Esempio n. 43
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")
Esempio n. 44
0
 def testVmHostPayload_with_storage_size(self):
     self.flags(instances_path="/var/lib/nova/instances")
     metadata = \
         event_metadata.get_EventMetaData(
             event_metadata.EVENT_TYPE_HOST_ADDED)
     obj = VmHost()
     obj.name = 'TestVmHost'
     ipProfile = IpProfile()
     ipProfile.ipAddress = '10.10.10.1'
     obj.add_ipAddresses(ipProfile)
     storage_obj = StorageVolume()
     storage_obj.id = "storage_id"
     storage_obj.name = 'TestStorageVolume'
     storage_obj.connectionState = 'ACTIVE'
     storage_obj.size = 200
     storage_obj.free = 100
     storage_obj.volumeType = 'DIR'
     storage_obj.volumeId = 'TestVolumeId'
     storage_obj.createEpoch = long(time.time() * 1000)
     storage_obj.lastModifiedEpoch = long(time.time() * 1000)
     mount_point = HostMountPoint()
     mount_point.set_path('/var/lib/nova/instances')
     mount_point.set_vmHostId('TestVmHost')
     storage_obj.add_mountPoints(mount_point)
     obj.add_storageVolumeIds("storage_id")
     self.mox.StubOutWithMock(
         InventoryCacheManager, 'get_object_from_cache')
     InventoryCacheManager.get_object_from_cache(
         storage_obj.id,
         Constants.StorageVolume).AndReturn(storage_obj)
     self.mox.ReplayAll()
     payload = payload_generator.generate_payload(metadata, obj)
     self.assertEquals(payload['entity_type'],
                       obj.__class__.__name__)
     self.assertEquals(payload['name'], obj.name)
     self.assertEquals(payload['ipAddresses'],
                       ipProfile.ipAddress)
     self.assertEquals(payload['totalStorageSize'],
                       storage_obj.size)
     self.assertEquals(payload['storageUsed'],
                       storage_obj.free)
Esempio n. 45
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")
    def get_storagevolume_list(self, storageId=None):
        storagevolume_dict = {}
        storagevolume_list = []
        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-111')
        storagevolume.set_name('datastore-111')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(True)
        storagevolume.set_shared(True)
        storagevolume.set_assignedServerCount(2)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5da')
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5da', 'host-9')
        storagevolume.add_mountPoints(hostMountPoint)
        storagevolume_list.append(storagevolume)
        storagevolume_dict[storagevolume.get_id()] = storagevolume

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db', 'host-9')
        storagevolume.add_mountPoints(hostMountPoint)
        storagevolume_list.append(storagevolume)
        storagevolume_dict[storagevolume.get_id()] = storagevolume
        if storageId is not None:
            return [storagevolume_dict[storageId]]
        return storagevolume_list
Esempio n. 47
0
    def test_diff_resourcemodel_storagevolume_nochange(self):
        """Unit Test to test for resource model comparison with no change """

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-9')
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-112')
        storagevolume1.set_name('datastore-112')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2')
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db')
        hostMountPoint1 = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-9')
        storagevolume1.add_mountPoints(hostMountPoint1)

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()

        self.assertTrue(len(diff_res) == 0)
Esempio n. 48
0
    def test_diff_resourcemodel_storagevolume_nochange(self):
        """Unit Test to test for resource model comparison with no change """

        storagevolume = StorageVolume()
        storagevolume.set_id('datastore-112')
        storagevolume.set_name('datastore-112')
        storagevolume.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume.set_size(107105746944)
        storagevolume.set_free(32256294912)
        storagevolume.set_vmfsVolume(False)
        storagevolume.set_shared(False)
        storagevolume.set_assignedServerCount(1)
        storagevolume.set_volumeType('VMFS')
        storagevolume.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-9')
        storagevolume.add_mountPoints(hostMountPoint)

        storagevolume1 = StorageVolume()
        storagevolume1.set_id('datastore-112')
        storagevolume1.set_name('datastore-112')
        storagevolume1.set_resourceManagerId(
            '13274325-BFD6-464F-A9D1-61332573B5E2'
        )
        storagevolume1.set_size(107105746944)
        storagevolume1.set_free(32256294912)
        storagevolume1.set_vmfsVolume(False)
        storagevolume1.set_shared(False)
        storagevolume1.set_assignedServerCount(1)
        storagevolume1.set_volumeType('VMFS')
        storagevolume1.set_volumeId(
            '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db'
        )
        hostMountPoint1 = \
            HostMountPoint(
                '/vmfs/volumes/4e374cf3-328f8064-aa2c-78acc0fcb5db',
                'host-9')
        storagevolume1.add_mountPoints(hostMountPoint1)

        diff = ResourceModelDiff(storagevolume, storagevolume1)
        diff_res = diff.diff_resourcemodel()

        self.assertTrue(len(diff_res) == 0)
Esempio n. 49
0
    def test_vm_host_delete(self):
        vmhost_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = vmhost_id
        vSwitch = VirtualSwitch()
        vSwitch.set_id('vSwitch-01')
        vSwitch.set_name('vSwitch-01')
        vSwitch.set_resourceManagerId('rmId')
        vSwitch.set_switchType('vSwitch')

        cost1 = Cost()
        cost1.set_value(100)
        cost1.set_units('USD')
        vSwitch.set_cost(cost1)

        portGroup = PortGroup()
        portGroup.set_id('pg-01')
        portGroup.set_name('pg-01')
        portGroup.set_resourceManagerId('rmId')
        portGroup.set_type('portgroup_type')
        portGroup.set_cost(cost1)
        vSwitch.add_portGroups(portGroup)
        vmhost.add_virtualSwitches(vSwitch)
        vmhost.add_portGroups(portGroup)
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)

        vmhost2 = VmHost()
        vmhost2.set_id('VH2')
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost2)

        storage = StorageVolume()
        storage.set_id('sv-01')
        storage.set_name('storage-01')
        storage.set_resourceManagerId('rmId')
        storage.set_size(1234)
        storage.set_free(2345)
        storage.set_vmfsVolume(True)
        storage.set_shared(True)
        storage.set_assignedServerCount(1)
        storage.set_volumeType('VMFS')
        storage.set_volumeId('101')

        hostMount1 = HostMountPoint()
        hostMount1.set_path('test_path1')
        hostMount1.set_vmHostId('VH1')
        storage.add_mountPoints(hostMount1)
        hostMount2 = HostMountPoint()
        hostMount2.set_path('test_path2')
        hostMount2.set_vmHostId('VH2')
        storage.add_mountPoints(hostMount2)
        healthnmon_db_api.storage_volume_save(get_admin_context(),
                                              storage)

        vm = Vm()
        vm.set_id('vm-01')
        vm.set_name('vm-01')
        vm.set_vmHostId('VH1')
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vmhosts = \
            healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
                                                 [vmhost_id])
        self.assertFalse(vmhosts is None,
                         'host get by id returned a none list')
        self.assertTrue(len(vmhosts) > 0,
                        'host get by id returned invalid number of list'
                        )

        healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(),
                                                [vmhost_id])

        vmhosts = \
            healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
                                                 [vmhost_id])
        self.assertTrue(vmhosts is None or len(vmhosts) == 0,
                        'host not deleted')
Esempio n. 50
0
    def test_vm_host_delete(self):
        vmhost_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = vmhost_id
        vSwitch = VirtualSwitch()
        vSwitch.set_id('vSwitch-01')
        vSwitch.set_name('vSwitch-01')
        vSwitch.set_resourceManagerId('rmId')
        vSwitch.set_switchType('vSwitch')

        cost1 = Cost()
        cost1.set_value(100)
        cost1.set_units('USD')
        vSwitch.set_cost(cost1)

        portGroup = PortGroup()
        portGroup.set_id('pg-01')
        portGroup.set_name('pg-01')
        portGroup.set_resourceManagerId('rmId')
        portGroup.set_type('portgroup_type')
        portGroup.set_cost(cost1)
        vSwitch.add_portGroups(portGroup)
        vmhost.add_virtualSwitches(vSwitch)
        vmhost.add_portGroups(portGroup)
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)

        vmhost2 = VmHost()
        vmhost2.set_id('VH2')
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost2)

        storage = StorageVolume()
        storage.set_id('sv-01')
        storage.set_name('storage-01')
        storage.set_resourceManagerId('rmId')
        storage.set_size(1234)
        storage.set_free(2345)
        storage.set_vmfsVolume(True)
        storage.set_shared(True)
        storage.set_assignedServerCount(1)
        storage.set_volumeType('VMFS')
        storage.set_volumeId('101')

        hostMount1 = HostMountPoint()
        hostMount1.set_path('test_path1')
        hostMount1.set_vmHostId('VH1')
        storage.add_mountPoints(hostMount1)
        hostMount2 = HostMountPoint()
        hostMount2.set_path('test_path2')
        hostMount2.set_vmHostId('VH2')
        storage.add_mountPoints(hostMount2)
        healthnmon_db_api.storage_volume_save(get_admin_context(), storage)

        vm = Vm()
        vm.set_id('vm-01')
        vm.set_name('vm-01')
        vm.set_vmHostId('VH1')
        healthnmon_db_api.vm_save(get_admin_context(), vm)

        vmhosts = \
            healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
                                                 [vmhost_id])
        self.assertFalse(vmhosts is None,
                         'host get by id returned a none list')
        self.assertTrue(
            len(vmhosts) > 0, 'host get by id returned invalid number of list')

        #        self.assertRaises(Exception, healthnmon_db_api.vm_host_delete_by_ids,([vmhost_id]))

        healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(),
                                                [vmhost_id])

        vmhosts = \
            healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
                                                 [vmhost_id])
        self.assertTrue(vmhosts is None or len(vmhosts) == 0,
                        'host not deleted')