Ejemplo n.º 1
0
    def test_vm_netadpater_save(self):
        vm = Vm()
        vm.id = 'VM1'
        vmNetAdapter = VmNetAdapter()
        vmNetAdapter.set_id('netAdapter-01')
        vmNetAdapter.set_name('netAdapter-01')
        vmNetAdapter.set_addressType('assigned')
        vmNetAdapter.set_adapterType('E1000')
        vmNetAdapter.set_switchType('vSwitch')
        vmNetAdapter.set_macAddress('00:50:56:81:1c:d0')
        vmNetAdapter.add_ipAddresses('1.1.1.1')
        vmNetAdapter.set_networkName('br100')
        vmNetAdapter.set_vlanId(0)

        vm.add_vmNetAdapters(vmNetAdapter)
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        virual_machines = \
            healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1'
                                                                  ])
        vm_from_db = virual_machines[0]
        netAdapters = vm_from_db.get_vmNetAdapters()
        netAdapter = netAdapters[0]
        self.assertTrue(vmNetAdapter.get_id() == netAdapter.get_id())
        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')
Ejemplo n.º 2
0
    def test_vm_details_xml(self):
        expected_out_xml = \
            '<Vm><id>vm-01</id><name>vm-01</name>\
        <vmDisks><id>disk-01</id><storagevolume xmlns:atom="http://www.w3.org/2005/Atom" id="datastore-939">\
        <atom:link href="http://localhost:8774/v2.0/storagevolumes/datastore-939" rel="self"/>\
        <atom:link href="http://localhost:8774/storagevolumes/datastore-939" rel="bookmark"/>\
        </storagevolume></vmDisks><vmDisks><id>disk-02</id>\
        <storagevolume xmlns:atom="http://www.w3.org/2005/Atom" id="datastore-439">\
        <atom:link href="http://localhost:8774/v2.0/storagevolumes/datastore-439" rel="self"/>\
        <atom:link href="http://localhost:8774/storagevolumes/datastore-439" rel="bookmark"/></storagevolume></vmDisks>\
        <vmhost xmlns:atom="http://www.w3.org/2005/Atom" id="host-329"><atom:link href="http://localhost:8774/v2.0/vmhosts/host-329" rel="self"/>\
        <atom:link href="http://localhost:8774/vmhosts/host-329" rel="bookmark"/></vmhost></Vm>'

        vm_list = self.get_single_vm()
        self.mock.StubOutWithMock(api, 'vm_get_by_ids')

        api.vm_get_by_ids(mox.IgnoreArg(),
                          mox.IgnoreArg()).AndReturn(vm_list)
        self.mock.ReplayAll()
        request = webob.Request.blank('/v2.0/vm/vm-01.xml',
                                      base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VMController().show(request, 'vm-01')
        self.assertNotEqual(resp, None, 'Return xml response for vm-01')
        self.compare_xml(expected_out_xml, resp.body)
        self.mock.stubs.UnsetAll()
Ejemplo n.º 3
0
    def test_vm_netadpater_save(self):
        vm = Vm()
        vm.id = 'VM1'
        vmNetAdapter = VmNetAdapter()
        vmNetAdapter.set_id('netAdapter-01')
        vmNetAdapter.set_name('netAdapter-01')
        vmNetAdapter.set_addressType('assigned')
        vmNetAdapter.set_adapterType('E1000')
        vmNetAdapter.set_switchType('vSwitch')
        vmNetAdapter.set_macAddress('00:50:56:81:1c:d0')
        vmNetAdapter.add_ipAddresses('1.1.1.1')
        vmNetAdapter.set_networkName('br100')
        vmNetAdapter.set_vlanId(0)

        vm.add_vmNetAdapters(vmNetAdapter)
        healthnmon_db_api.vm_save(get_admin_context(), vm)
        virual_machines = \
            healthnmon_db_api.vm_get_by_ids(get_admin_context(), ['VM1'
                                                                  ])
        vm_from_db = virual_machines[0]
        netAdapters = vm_from_db.get_vmNetAdapters()
        netAdapter = netAdapters[0]
        self.assertTrue(vmNetAdapter.get_id() == netAdapter.get_id())
        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')
Ejemplo n.º 4
0
    def test_vm_details_json(self):
        expected_out_json = '{"Vm": {"vmDisks": [{"storagevolumes": \
[{"id": "datastore-939", "links": [{"href": \
"http://localhost:8774/v2.0/storagevolumes/datastore-939", "rel": "self"}, \
{"href": "http://localhost:8774/storagevolumes/datastore-939", \
"rel": "bookmark"}]}], "id": "disk-01"}, \
{"storagevolumes": [{"id": "datastore-439", "links": \
[{"href": "http://localhost:8774/v2.0/storagevolumes/datastore-439", "rel": \
"self"}, {"href": "http://localhost:8774/storagevolumes/datastore-439", \
"rel": "bookmark"}]}], "id": "disk-02"}], \
"vmhosts": [{"id": "host-329", "links": [{"href": \
"http://localhost:8774/v2.0/vmhosts/host-329", "rel": "self"}, \
{"href": "http://localhost:8774/vmhosts/host-329", \
"rel": "bookmark"}]}], "id": "vm-01", "name": "vm-01"}}'

        vm_list = self.get_single_vm()
        self.mock.StubOutWithMock(api, 'vm_get_by_ids')

        api.vm_get_by_ids(mox.IgnoreArg(),
                          mox.IgnoreArg()).AndReturn(vm_list)
        self.mock.ReplayAll()
        request = webob.Request.blank('/v2.0/vm/vm-01.json',
                                      base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VMController().show(request, 'vm-01')
        self.assertNotEqual(resp, None, 'Return json response for vm-01'
                            )
        self.compare_json(expected_out_json, resp.body)
        self.mock.stubs.UnsetAll()
Ejemplo n.º 5
0
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch, modifiedEpoch and deletedEpoch
     """
     vm = Vm()
     vm.set_id('VM1')
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.vm_save(self.admin_context, vm)
     epoch_after = utils.get_current_epoch_ms()
     vm_queried = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                  [vm.get_id()])[0]
     self.assert_(
         test_utils.is_timestamp_between(epoch_before, epoch_after,
                                         vm_queried.get_createEpoch()))
     # Check for lastModifiedEpoch and createEpoch after adding VmGlobalSettings
     vm_modified = vm_queried
     test_utils.unset_timestamp_fields(vm_modified)
     vmGlobalSettings = VmGlobalSettings()
     vmGlobalSettings.set_id('VMGS1')
     vmGlobalSettings.set_autoStartAction(Constants.AUTO_START_ENABLED)
     vm_modified.set_vmGlobalSettings(vmGlobalSettings)
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.vm_save(self.admin_context, vm_modified)
     epoch_after = utils.get_current_epoch_ms()
     vm_queried = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                  [vm.get_id()])[0]
     self.assert_(
         vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             vm_queried.get_vmGlobalSettings().get_createEpoch()))
     # Check for lastModifiedEpoch after modifying vm
     vm_modified = vm_queried
     test_utils.unset_timestamp_fields(vm_modified)
     vm_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.vm_save(self.admin_context, vm_modified)
     epoch_after = utils.get_current_epoch_ms()
     vm_queried = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                  [vm.get_id()])[0]
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             vm_queried.get_vmGlobalSettings().get_lastModifiedEpoch()))
     self.assert_(
         vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
     self.assert_(vm_modified.get_vmGlobalSettings().get_createEpoch() ==
                  vm_queried.get_vmGlobalSettings().get_createEpoch())
Ejemplo n.º 6
0
    def test_timestamp_columns(self):
        """
            Test the time stamp columns createEpoch,
            modifiedEpoch and deletedEpoch
        """
        vm = Vm()
        vm.set_id('VM1')
        # Check for createEpoch
        epoch_before = utils.get_current_epoch_ms()
        healthnmon_db_api.vm_save(self.admin_context, vm)
        epoch_after = utils.get_current_epoch_ms()
        vm_queried = healthnmon_db_api.vm_get_by_ids(
            self.admin_context, [vm.get_id()])[0]
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after, vm_queried.get_createEpoch()))

        # Check for lastModifiedEpoch and createEpoch
        # after adding VmGlobalSettings
        vm_modified = vm_queried
        test_utils.unset_timestamp_fields(vm_modified)
        vmGlobalSettings = VmGlobalSettings()
        vmGlobalSettings.set_id('VMGS1')
        vmGlobalSettings.set_autoStartAction(Constants.AUTO_START_ENABLED)
        vm_modified.set_vmGlobalSettings(vmGlobalSettings)
        epoch_before = utils.get_current_epoch_ms()
        healthnmon_db_api.vm_save(self.admin_context, vm_modified)
        epoch_after = utils.get_current_epoch_ms()
        vm_queried = healthnmon_db_api.vm_get_by_ids(
            self.admin_context, [vm.get_id()])[0]
        self.assert_(
            vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after,
            vm_queried.get_vmGlobalSettings().get_createEpoch()))
        # Check for lastModifiedEpoch after modifying vm
        vm_modified = vm_queried
        test_utils.unset_timestamp_fields(vm_modified)
        vm_modified.set_name('changed_name')
        epoch_before = utils.get_current_epoch_ms()
        healthnmon_db_api.vm_save(self.admin_context, vm_modified)
        epoch_after = utils.get_current_epoch_ms()
        vm_queried = healthnmon_db_api.vm_get_by_ids(
            self.admin_context, [vm.get_id()])[0]
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
        self.assert_(test_utils.is_timestamp_between(
            epoch_before, epoch_after,
            vm_queried.get_vmGlobalSettings().get_lastModifiedEpoch()))
        self.assert_(
            vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
        self.assert_(vm_modified.get_vmGlobalSettings().get_createEpoch() ==
                     vm_queried.get_vmGlobalSettings().get_createEpoch())
Ejemplo n.º 7
0
 def test_vm_details_none_xml(self):
     vm_list = None
     self.mock.StubOutWithMock(api, 'vm_get_by_ids')
     api.vm_get_by_ids(mox.IgnoreArg(),
                       mox.IgnoreArg()).AndReturn(vm_list)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/vm/vm-01.xml',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = VMController().show(request, 'vm-01')
     self.assertNotEqual(resp, None, 'Return xml response for vm-01')
     self.mock.stubs.UnsetAll()
Ejemplo n.º 8
0
    def test_utilization_query(self):
        vm_list = self.get_single_vm()
        self.mock.StubOutWithMock(api, 'vm_get_by_ids')

        api.vm_get_by_ids(mox.IgnoreArg(),
                          mox.IgnoreArg()).AndReturn(vm_list)
        self.mock.StubOutWithMock(rpc, 'call')

        rpc.call(mox.IgnoreArg(), mox.IgnoreArg(),
                 mox.IgnoreArg()).AndReturn(self.get_resource_utilization())
        self.mock.ReplayAll()
        request = webob.Request.blank('/v2.0/vm/vm-01.xml?utilization',
                                      base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VMController().show(request, 'vm-01')
        self.assertNotEqual(resp, None, 'Return xml response for vm-01')
Ejemplo n.º 9
0
    def test_vm_save_update(self):
        '''
        Update an existing object in db
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

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

        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id])
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
        vm = vms[0]
        self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same")
        vmGlobalSets = vm.get_vmGlobalSettings()
        self.assertTrue(vmGlobalSets is not None)
        self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vmGlobalSets.get_autoStartAction(),
                         'autoStartAction', "autoStartAction is not same")
        self.assertEqual(vmGlobalSets.get_autoStopAction(),
                         'autoStopAction', "autoStopAction is not same")
Ejemplo n.º 10
0
 def test_vm_get_all_by_filters_changessince(self):
     # Create Vm
     vm_ids = ('VM1', 'VM2', 'VM3')
     vm_names = ('name1', 'name2', 'name3')
     for i in range(len(vm_ids)):
         self.__create_vm(id=vm_ids[i], name=vm_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second vm and delete third vm
     time.sleep(1)
     second_vm = healthnmon_db_api.vm_get_by_ids(
         self.admin_context, [vm_ids[1]])[0]
     second_vm.name = 'New name'
     healthnmon_db_api.vm_save(self.admin_context, second_vm)
     healthnmon_db_api.vm_delete_by_ids(self.admin_context, [vm_ids[2]])
     # Query with filter
     expected_updated_ids = [vm_ids[1], vm_ids[2]]
     filters = {'changes-since': created_time}
     vms = healthnmon_db_api.vm_get_all_by_filters(
         self.admin_context, filters,
         None, None)
     self.assert_(vms is not None)
     self.assert_(len(vms) == 2)
     for vm in vms:
         self.assert_(vm is not None)
         self.assert_(vm.id in expected_updated_ids)
Ejemplo n.º 11
0
    def test_vm_save_update(self):
        '''
        Update an existing object in db
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        healthnmon_db_api.vm_save(get_admin_context(), vm)

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

        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), [vm.id])
        self.assertTrue(vms is not None)
        self.assertTrue(len(vms) == 1)
        vm = vms[0]
        self.assertEqual(vm.get_id(), 'VM1-id', "VM id is not same")
        vmGlobalSets = vm.get_vmGlobalSettings()
        self.assertTrue(vmGlobalSets is not None)
        self.assertEqual(vmGlobalSets.get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vmGlobalSets.get_autoStartAction(), 'autoStartAction',
                         "autoStartAction is not same")
        self.assertEqual(vmGlobalSets.get_autoStopAction(), 'autoStopAction',
                         "autoStopAction is not same")
Ejemplo n.º 12
0
    def test_vm_save(self):
        '''
        Insert a vm object into db and check
        whether we are getting proper values after retrieval
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        vm.name = 'VM1-Name'
        vmScsiController = VmScsiController()
        vmScsiController.set_id('VM_CTRL_1')
        vmScsiController.set_id('some_type')
        vm.add_vmScsiControllers(vmScsiController)
        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)
        self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM name is not same")
        self.assert_(len(vms[0].get_vmScsiControllers(
        )) == 1, "vmScsiController len mismatch")
        self.assert_(vms[0].get_vmScsiControllers()[0].get_id(
        ) == vmScsiController.get_id(), "vmScsiController id mismatch")
        self.assert_(vms[0].get_vmScsiControllers()[0].get_type() ==
                     vmScsiController.get_type(),
                     "vmScsiController type mismatch")
Ejemplo n.º 13
0
    def test_vm_save(self):
        '''
        Insert a vm object into db and check
        whether we are getting proper values after retrieval
        '''
        vm = Vm()
        vm.id = 'VM1-id'
        vm.name = 'VM1-Name'
        vmScsiController = VmScsiController()
        vmScsiController.set_id('VM_CTRL_1')
        vmScsiController.set_id('some_type')
        vm.add_vmScsiControllers(vmScsiController)
        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)
        self.assertEqual(vms[0].get_id(), 'VM1-id', "VM id is not same")
        self.assertEqual(vms[0].get_name(), 'VM1-Name', "VM name is not same")
        self.assert_(
            len(vms[0].get_vmScsiControllers()) == 1,
            "vmScsiController len mismatch")
        self.assert_(
            vms[0].get_vmScsiControllers()[0].get_id() ==
            vmScsiController.get_id(), "vmScsiController id mismatch")
        self.assert_(
            vms[0].get_vmScsiControllers()[0].get_type() ==
            vmScsiController.get_type(), "vmScsiController type mismatch")
Ejemplo n.º 14
0
    def test_vm_details_json_exception(self):
        vm_list = self.get_single_vm()
        xml_utils = util
        self.mock.StubOutWithMock(xml_utils, 'xml_to_dict')
        xml_utils.xml_to_dict(mox.IgnoreArg()).AndRaise(IndexError('Test index'
                                                                   ))
        self.mock.StubOutWithMock(api, 'vm_get_by_ids')

        api.vm_get_by_ids(mox.IgnoreArg(),
                          mox.IgnoreArg()).AndReturn(vm_list)
        self.mock.ReplayAll()
        request = webob.Request.blank(
            '/v2.0/virtualmachines/vm-01.json',
            base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VMController().show(request, 'vm-01')
        self.assertTrue(isinstance(resp, HTTPNotFound))
Ejemplo n.º 15
0
    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')
Ejemplo n.º 16
0
def vm_get_by_ids(context, vm_ids):
    """ This API will make a call to db layer to fetch a Vm objects which
        corresponds to ids

        Parameters:
            vm_ids - List of Vm ids
            context - nova.context.RequestContext object
    """

    return api.vm_get_by_ids(context, vm_ids)
Ejemplo n.º 17
0
def vm_get_by_ids(context, vm_ids):
    """ This API will make a call to db layer to fetch a Vm objects which
        corresponds to ids

        Parameters:
            vm_ids - List of Vm ids
            context - nova.context.RequestContext object
    """

    return api.vm_get_by_ids(context, vm_ids)
Ejemplo n.º 18
0
    def test_vm_get_by_id(self):
        vm_id = 'VM1'
        vm = Vm()
        vm.id = vm_id
        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')
        self.assertTrue(vms[0].id == 'VM1')
Ejemplo n.º 19
0
    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')
Ejemplo n.º 20
0
    def test_query_field_key(self):
        expected_out_json = \
            '{"Vm": {"id": "vm-01", "name": "vm-01"}}'

        vm_list = self.get_single_vm()
        self.mock.StubOutWithMock(api, 'vm_get_by_ids')

        api.vm_get_by_ids(mox.IgnoreArg(),
                          mox.IgnoreArg()).AndReturn(vm_list)
        self.mock.StubOutWithMock(rpc, 'call')

        rpc.call(mox.IgnoreArg(), mox.IgnoreArg(),
                 mox.IgnoreArg()).AndReturn(self.get_resource_utilization())
        self.mock.ReplayAll()
        request = \
            webob.Request.blank('/v2.0/vm/vm-01.json?fields=id,name',
                                base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VMController().show(request, 'vm-01')
        self.assertNotEqual(resp, None, 'Return xml response for vm-01')
        self.compare_json(expected_out_json, resp.body)
        self.mock.stubs.UnsetAll()
Ejemplo n.º 21
0
    def test_vm_get_by_id(self):
        vm_id = 'VM1'
        vm = Vm()
        vm.id = vm_id
        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')
        self.assertTrue(vms[0].id == 'VM1')
Ejemplo n.º 22
0
 def test_vm_get_all_by_filters_changessince(self):
     # Create Vm
     vm_ids = ('VM1', 'VM2', 'VM3')
     vm_names = ('name1', 'name2', 'name3')
     for i in range(len(vm_ids)):
         self.__create_vm(id=vm_ids[i], name=vm_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second vm and delete third vm
     time.sleep(1)
     second_vm = healthnmon_db_api.vm_get_by_ids(self.admin_context,
                                                 [vm_ids[1]])[0]
     second_vm.name = 'New name'
     healthnmon_db_api.vm_save(self.admin_context, second_vm)
     healthnmon_db_api.vm_delete_by_ids(self.admin_context, [vm_ids[2]])
     # Query with filter
     expected_updated_ids = [vm_ids[1], vm_ids[2]]
     filters = {'changes-since': created_time}
     vms = healthnmon_db_api.vm_get_all_by_filters(self.admin_context,
                                                   filters, None, None)
     self.assert_(vms is not None)
     self.assert_(len(vms) == 2)
     for vm in vms:
         self.assert_(vm is not None)
         self.assert_(vm.id in expected_updated_ids)
Ejemplo n.º 23
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")
Ejemplo n.º 24
0
    def test_vm_get_by_id_none(self):

        # Try to get the vm with Id None and check whether it is returning None
        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), None)
        self.assertTrue(vms is None)
Ejemplo n.º 25
0
    def test_vm_get_by_id_none(self):

        # Try to get the vm with Id None and check whether it is returning None
        vms = healthnmon_db_api.vm_get_by_ids(get_admin_context(), None)
        self.assertTrue(vms is None)
Ejemplo n.º 26
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")