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()))
 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()))
示例#3
0
    def test_storagevolume_details_none_xml(self):
        storagevolumes = None
        self.mock.StubOutWithMock(api, "storage_volume_get_by_ids")

        api.storage_volume_get_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = webob.Request.blank("/v2.0/storagevolumes/datastore-111.xml", base_url="http://localhost:8774/v2.0/")
        request.environ["nova.context"] = self.admin_context
        resp = StorageVolumeController().show(request, "datastore-111")
        self.assertNotEqual(resp, None, "Return xml response for datastore-111")
示例#4
0
    def test_storagevolume_details_json_exception(self):
        storagevolumes = self.get_storagevolume_list()
        xml_utils = util
        self.mock.StubOutWithMock(xml_utils, "xml_to_dict")
        xml_utils.xml_to_dict(mox.IgnoreArg()).AndRaise(Exception("Test Exception"))
        self.mock.StubOutWithMock(api, "storage_volume_get_by_ids")

        api.storage_volume_get_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = webob.Request.blank("/v2.0/storagevolumes/datastore-111.json", base_url="http://localhost:8774/v2.0/")
        request.environ["nova.context"] = self.admin_context
        resp = StorageVolumeController().show(request, "datastore-111")
        self.assertTrue(isinstance(resp, HTTPNotFound))
示例#5
0
    def test_query_field_key(self):
        storagevolumes = self.get_single_storagevolume()
        self.mock.StubOutWithMock(api, "storage_volume_get_by_ids")

        api.storage_volume_get_by_ids(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = webob.Request.blank(
            "/v2.0/storagevolumes/datastore-111.json?fields=id,name", base_url="http://localhost:8774/v2.0/"
        )
        request.environ["nova.context"] = self.admin_context
        resp = StorageVolumeController().show(request, "datastore-111")
        self.assertNotEqual(resp, None, "Return xml response for datastore-111")
        self.mock.stubs.UnsetAll()
示例#6
0
    def test_storagevolume_details_none_xml(self):
        storagevolumes = None
        self.mock.StubOutWithMock(api, 'storage_volume_get_by_ids')

        api.storage_volume_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank('/v2.0/storagevolumes/datastore-111.xml',
                                base_url='http://localhost:8774/v2.0/'
                                )
        request.environ['nova.context'] = self.admin_context
        resp = StorageVolumeController().show(request, 'datastore-111')
        self.assertNotEqual(resp, None,
                            'Return xml response for datastore-111')
 def test_storage_volume_get_all_by_filters_changessince(self):
     # Create StorageVolumes
     vol_ids = ('V1', 'V2', 'V3')
     vol_names = ('name1', 'name2', 'name3')
     for i in range(len(vol_ids)):
         self.__create_volume(id=vol_ids[i], name=vol_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second vol and delete third vol
     time.sleep(1)
     second_vol = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, [vol_ids[1]])[0]
     second_vol.name = 'New name'
     healthnmon_db_api.storage_volume_save(self.admin_context, second_vol)
     healthnmon_db_api.storage_volume_delete_by_ids(
         self.admin_context, [vol_ids[2]])
     # Query with filter
     expected_updated_ids = [vol_ids[1], vol_ids[2]]
     filters = {'changes-since': created_time}
     vols = healthnmon_db_api.storage_volume_get_all_by_filters(
         self.admin_context, filters,
         None, None)
     self.assert_(vols is not None)
     self.assert_(len(vols) == 2)
     for vol in vols:
         self.assert_(vol is not None)
         self.assert_(vol.id in expected_updated_ids)
 def test_storage_volume_get_all_by_filters_changessince(self):
     # Create StorageVolumes
     vol_ids = ('V1', 'V2', 'V3')
     vol_names = ('name1', 'name2', 'name3')
     for i in range(len(vol_ids)):
         self.__create_volume(id=vol_ids[i], name=vol_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second vol and delete third vol
     time.sleep(1)
     second_vol = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, [vol_ids[1]])[0]
     second_vol.name = 'New name'
     healthnmon_db_api.storage_volume_save(self.admin_context, second_vol)
     healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context,
                                                    [vol_ids[2]])
     # Query with filter
     expected_updated_ids = [vol_ids[1], vol_ids[2]]
     filters = {'changes-since': created_time}
     vols = healthnmon_db_api.storage_volume_get_all_by_filters(
         self.admin_context, filters, None, None)
     self.assert_(vols is not None)
     self.assert_(len(vols) == 2)
     for vol in vols:
         self.assert_(vol is not None)
         self.assert_(vol.id in expected_updated_ids)
    def test_storagevolume_details_xml(self):
        storagevolumes = self.get_single_storagevolume()
        self.mock.StubOutWithMock(api, 'storage_volume_get_by_ids')

        api.storage_volume_get_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank('/v2.0/storagevolumes/datastore-111.xml',
                                base_url='http://localhost:8774/v2.0/'
                                )
        request.environ['nova.context'] = self.admin_context
        resp = StorageVolumeController().show(request, 'datastore-111')
        self.assertNotEqual(resp, None,
                            'Return xml response for datastore-111')
        self.assertEqual(self.expected_storage_details_xml, resp.body)
示例#10
0
    def test_query_field_key(self):
        storagevolumes = self.get_single_storagevolume()
        self.mock.StubOutWithMock(api, 'storage_volume_get_by_ids')

        api.storage_volume_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank(
                '/v2.0/storagevolumes/datastore-111.json?fields=id,name',
                base_url='http://localhost:8774/v2.0/'
            )
        request.environ['nova.context'] = self.admin_context
        resp = StorageVolumeController().show(request, 'datastore-111')
        self.assertNotEqual(resp, None,
                            'Return xml response for datastore-111')
        self.mock.stubs.UnsetAll()
示例#11
0
    def test_storagevolume_details_json_exception(self):
        storagevolumes = self.get_storagevolume_list()
        xml_utils = util
        self.mock.StubOutWithMock(xml_utils, 'xml_to_dict')
        xml_utils.xml_to_dict(mox.IgnoreArg()).AndRaise(
            Exception('Test Exception'))
        self.mock.StubOutWithMock(api, 'storage_volume_get_by_ids')

        api.storage_volume_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(storagevolumes)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank('/v2.0/storagevolumes/datastore-111.json',
                                base_url='http://localhost:8774/v2.0/'
                                )
        request.environ['nova.context'] = self.admin_context
        resp = StorageVolumeController().show(request, 'datastore-111')
        self.assertTrue(isinstance(resp, HTTPNotFound))
示例#12
0
def storage_volume_get_by_ids(context, storagevolume_ids):
    """ This API will make a call to db layer to fetch a StorageVolume objects
        which corresponds to ids

        Parameters:
            storagevolume_ids - List of StorageVolume ids
            context - nova.context.RequestContext object
    """

    return api.storage_volume_get_by_ids(context, storagevolume_ids)
示例#13
0
def storage_volume_get_by_ids(context, storagevolume_ids):
    """ This API will make a call to db layer to fetch a StorageVolume objects
        which corresponds to ids

        Parameters:
            storagevolume_ids - List of StorageVolume ids
            context - nova.context.RequestContext object
    """

    return api.storage_volume_get_by_ids(context, storagevolume_ids)
    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_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')
 def test_storagevolume_get_by_id_none(self):
     storageVolumes = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context,
         None)
     self.assertTrue(
         storageVolumes is None, 'Storage Volumes should be an empty list')
示例#19
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")
示例#20
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 test_storagevolume_get_by_id_none(self):
     storageVolumes = healthnmon_db_api.storage_volume_get_by_ids(
         self.admin_context, None)
     self.assertTrue(storageVolumes is None,
                     'Storage Volumes should be an empty list')