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())
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")
def test_vm_delete(self): vm = Vm() vm_id = 'VM1' vm.id = vm_id vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm_id) 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.assertFalse(vms is None, 'VM get by id returned a none list') self.assertTrue( len(vms) > 0, 'VM get by id returned invalid number of list') healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm_id]) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertTrue(vms is None or len(vms) == 0, 'VM not deleted')
def test_vm_delete(self): vm = Vm() vm_id = 'VM1' vm.id = vm_id vmGlobalSettings = VmGlobalSettings() vmGlobalSettings.set_id(vm_id) 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.assertFalse(vms is None, 'VM get by id returned a none list') self.assertTrue(len(vms) > 0, 'VM get by id returned invalid number of list') healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm_id]) vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm_id]) self.assertTrue(vms is None or len(vms) == 0, 'VM 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')
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_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())
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 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")