Esempio n. 1
0
 def test_portGroup_added_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vmhost = VmHost()
     vmhost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     portGroup = PortGroup()
     portGroup.set_id("PortGroup_" + vswitch.get_id())
     portGroup.set_name(vswitch.get_name())
     portGroup.set_virtualSwitchId(vswitch.get_id())
     vswitch.set_portGroups([portGroup])
     vmhost.set_virtualSwitches([vswitch])
     vmhost.set_portGroups([portGroup])
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 2)
     msg = test_notifier.NOTIFICATIONS[1]
     self.assertEquals(msg['priority'], notifier_api.INFO)
     event_type = event_metadata.get_EventMetaData(
         event_metadata.EVENT_TYPE_PORTGROUP_ADDED)
     self.assertEquals(msg['event_type'],
                       event_type.get_event_fully_qal_name())
     payload = msg['payload']
     self.assertEquals(payload['entity_type'], 'PortGroup')
     self.assertEquals(payload['entity_id'], portGroup.get_id())
Esempio n. 2
0
 def test_portGroup_added_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vmhost = VmHost()
     vmhost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     portGroup = PortGroup()
     portGroup.set_id("PortGroup_" + vswitch.get_id())
     portGroup.set_name(vswitch.get_name())
     portGroup.set_virtualSwitchId(vswitch.get_id())
     vswitch.set_portGroups([portGroup])
     vmhost.set_virtualSwitches([vswitch])
     vmhost.set_portGroups([portGroup])
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 2)
     msg = test_notifier.NOTIFICATIONS[1]
     self.assertEquals(msg['priority'], notifier_api.INFO)
     event_type = event_metadata.get_EventMetaData(
         event_metadata.EVENT_TYPE_PORTGROUP_ADDED)
     self.assertEquals(msg['event_type'],
                       event_type.get_event_fully_qal_name())
     payload = msg['payload']
     self.assertEquals(payload['entity_type'], 'PortGroup')
     self.assertEquals(payload['entity_id'], portGroup.get_id())
Esempio n. 3
0
    def test_host_disconnected_event(self):
        self.__mock_service_get_all_by_topic()
        backedUp_libvirt = connection.libvirt
        connection.libvirt = libvirt
        try:
            compute_id = '1'
            virtConnection = LibvirtConnection(False)
            vmHost = VmHost()
            vmHost.id = compute_id
            vmHost.set_virtualMachineIds([])
            InventoryCacheManager.update_object_in_cache(compute_id, vmHost)
#            virtConnection.setUuid('34353438-3934-434e-3738-313630323543'
#                                   )
            virtConnection._wrapped_conn = None
            virtConnection.compute_rmcontext = \
                ComputeRMContext(rmType='KVM',
                                 rmIpAddress='10.10.155.165',
                                 rmUserName='******',
                                 rmPassword='******')
            cachedHost = VmHost()
            cachedHost.id = compute_id
            cachedHost.connectionState = Constants.VMHOST_CONNECTED
            self.mox.StubOutWithMock(InventoryCacheManager,
                                     'get_object_from_cache')
            self.mox.StubOutWithMock(
                InventoryCacheManager, 'get_compute_conn_driver')

            InventoryCacheManager.get_compute_conn_driver(
                self.libvirtVmHost.compute_id,
                Constants.VmHost).AndReturn(fake.get_connection())

            InventoryCacheManager.get_object_from_cache(
                compute_id,
                Constants.VmHost).AndReturn(cachedHost)
            self.mox.StubOutWithMock(api, 'vm_host_save')

            api.vm_host_save(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
            self.mox.ReplayAll()
            libvirtEvents = LibvirtEvents()
            libvirtVmHost = LibvirtVmHost(
                virtConnection._wrapped_conn, compute_id, libvirtEvents)
            libvirtVmHost.processUpdates()
            self.assertEquals(libvirtVmHost.vmHost.get_connectionState(),
                              Constants.VMHOST_DISCONNECTED)
            self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
            msg = test_notifier.NOTIFICATIONS[0]
            self.assertEquals(msg['priority'], notifier_api.CRITICAL)
            event_type = \
                event_metadata.get_EventMetaData(
                    event_metadata.EVENT_TYPE_HOST_DISCONNECTED)
            self.assertEquals(msg['event_type'],
                              event_type.get_event_fully_qal_name())
            payload = msg['payload']
            self.assertEquals(payload['entity_type'], 'VmHost')
            self.assertEquals(payload['entity_id'],
                              libvirtVmHost.compute_id)
        finally:
            connection.libvirt = backedUp_libvirt
Esempio n. 4
0
    def test_host_disconnected_event(self):
        self.__mock_service_get_all_by_topic()
        backedUp_libvirt = connection.libvirt
        connection.libvirt = libvirt
        try:
            compute_id = '1'
            virtConnection = LibvirtConnection(False)
            vmHost = VmHost()
            vmHost.id = compute_id
            vmHost.set_virtualMachineIds([])
            InventoryCacheManager.update_object_in_cache(compute_id, vmHost)
            #            virtConnection.setUuid('34353438-3934-434e-3738-313630323543'
            #                                   )
            virtConnection._wrapped_conn = None
            virtConnection.compute_rmcontext = \
                ComputeRMContext(rmType='KVM',
                                 rmIpAddress='10.10.155.165',
                                 rmUserName='******',
                                 rmPassword='******')
            cachedHost = VmHost()
            cachedHost.id = compute_id
            cachedHost.connectionState = Constants.VMHOST_CONNECTED
            self.mox.StubOutWithMock(InventoryCacheManager,
                                     'get_object_from_cache')
            self.mox.StubOutWithMock(InventoryCacheManager,
                                     'get_compute_conn_driver')

            InventoryCacheManager.get_compute_conn_driver(
                self.libvirtVmHost.compute_id,
                Constants.VmHost).AndReturn(fake.get_connection())

            InventoryCacheManager.get_object_from_cache(
                compute_id, Constants.VmHost).AndReturn(cachedHost)
            self.mox.StubOutWithMock(api, 'vm_host_save')

            api.vm_host_save(mox.IgnoreArg(),
                             mox.IgnoreArg()).MultipleTimes().AndReturn(None)
            self.mox.ReplayAll()
            libvirtEvents = LibvirtEvents()
            libvirtVmHost = LibvirtVmHost(virtConnection._wrapped_conn,
                                          compute_id, libvirtEvents)
            libvirtVmHost.processUpdates()
            self.assertEquals(libvirtVmHost.vmHost.get_connectionState(),
                              Constants.VMHOST_DISCONNECTED)
            self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
            msg = test_notifier.NOTIFICATIONS[0]
            self.assertEquals(msg['priority'], notifier_api.CRITICAL)
            event_type = \
                event_metadata.get_EventMetaData(
                    event_metadata.EVENT_TYPE_HOST_DISCONNECTED)
            self.assertEquals(msg['event_type'],
                              event_type.get_event_fully_qal_name())
            payload = msg['payload']
            self.assertEquals(payload['entity_type'], 'VmHost')
            self.assertEquals(payload['entity_id'], libvirtVmHost.compute_id)
        finally:
            connection.libvirt = backedUp_libvirt
    def test_diff_test_diff_resourcemodel_virtualSwitch_withdelete(self):
        cachedHost = VmHost()
        cachedHost.id = '1'
        vswitch = VirtualSwitch()
        vswitch.set_id("11")
        vswitch.set_name("vs1")
        cachedHost.set_virtualSwitches([vswitch])
        vmhost = copy.deepcopy(cachedHost)
        vmhost.get_virtualSwitches().pop()
        diff = ResourceModelDiff(cachedHost, vmhost)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)
        self.assertTrue(self.update in diff_res)
        virtualSwitches = 'virtualSwitches'
        self.assertTrue(virtualSwitches in diff_res[self.update])
        self.assertTrue(self.delete in diff_res[self.update][virtualSwitches])

        key = diff_res[self.update][virtualSwitches][self.delete].keys()[0]
        self.assertTrue(
            isinstance(
                diff_res[self.update][virtualSwitches][self.delete][key],
                VirtualSwitch))
        delVirSwitch = diff_res[self.update][virtualSwitches][self.delete][key]
        self.assertEquals(delVirSwitch.id, '11')
        self.assertEquals(delVirSwitch.name, 'vs1')
Esempio n. 6
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))
Esempio n. 7
0
 def test_vm_host_get_all_for_vm(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)
     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)
     vmids = vmhosts[0].get_virtualMachineIds()
     self.assert_(vmids is not None)
     self.assert_(len(vmids) == 1)
     self.assert_(vm.id in vmids)
     healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm.id])
     vmhosts = \
         healthnmon_db_api.vm_host_get_all(get_admin_context())
     self.assertTrue(vmhosts[0].id == host_id)
     vmids = vmhosts[0].get_virtualMachineIds()
     self.assert_((vmids is None) or (len(vmids) == 0))
 def test_PortGroup_Reconfigured_Event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     portGroup = PortGroup()
     portGroup.set_id("PortGroup_" + vswitch.get_id())
     portGroup.set_name(vswitch.get_name())
     portGroup.set_virtualSwitchId(vswitch.get_id())
     vswitch.set_portGroups([portGroup])
     cachedHost.set_virtualSwitches([vswitch])
     cachedHost.set_portGroups([portGroup])
     vmhost = copy.deepcopy(cachedHost)
     vmhost.get_portGroups()[0].set_name("vs11")
     vmhost.get_virtualSwitches()[0].set_name("vs11")
     vmhost.get_virtualSwitches()[0].get_portGroups()[0].set_name("vs11")
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     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_PORTGROUP_RECONFIGURED)
     self.assertEquals(msg["event_type"], event_type.get_event_fully_qal_name())
     payload = msg["payload"]
     self.assertEquals(payload["entity_type"], "PortGroup")
     self.assertEquals(payload["entity_id"], portGroup.get_id())
Esempio n. 9
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))
Esempio n. 10
0
 def test_network_enabled_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     vswitch.set_connectionState("Inactive")
     cachedHost.set_virtualSwitches([vswitch])
     vmhost = copy.deepcopy(cachedHost)
     vmhost.get_virtualSwitches()[0].set_connectionState("Active")
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     self.assertEquals(vmhost.get_virtualSwitches()[0].
                       get_connectionState(),
                       Constants.VIRSWITCH_STATE_ACTIVE)
     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_NETWORK_ENABLED)
     self.assertEquals(msg['event_type'],
                       event_type.get_event_fully_qal_name())
     payload = msg['payload']
     self.assertEquals(payload['entity_type'], 'VirtualSwitch')
     self.assertEquals(payload['entity_id'], vswitch.get_id())
     self.assertEquals(payload["state"], 'Active')
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
0
 def test_network_enabled_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     vswitch.set_connectionState("Inactive")
     cachedHost.set_virtualSwitches([vswitch])
     vmhost = copy.deepcopy(cachedHost)
     vmhost.get_virtualSwitches()[0].set_connectionState("Active")
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     self.assertEquals(
         vmhost.get_virtualSwitches()[0].get_connectionState(),
         Constants.VIRSWITCH_STATE_ACTIVE)
     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_NETWORK_ENABLED)
     self.assertEquals(msg['event_type'],
                       event_type.get_event_fully_qal_name())
     payload = msg['payload']
     self.assertEquals(payload['entity_type'], 'VirtualSwitch')
     self.assertEquals(payload['entity_id'], vswitch.get_id())
     self.assertEquals(payload["state"], 'Active')
Esempio n. 14
0
 def test_vm_host_get_all_for_vm(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)
     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)
     vmids = vmhosts[0].get_virtualMachineIds()
     self.assert_(vmids is not None)
     self.assert_(len(vmids) == 1)
     self.assert_(vm.id in vmids)
     healthnmon_db_api.vm_delete_by_ids(get_admin_context(), [vm.id])
     vmhosts = \
         healthnmon_db_api.vm_host_get_all(get_admin_context())
     self.assertTrue(vmhosts[0].id == host_id)
     vmids = vmhosts[0].get_virtualMachineIds()
     self.assert_((vmids is None) or (len(vmids) == 0))
Esempio n. 15
0
    def test_vm_host_save_update_with_new_vSwitch(self):
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_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)

        vSwitch_new = VirtualSwitch()
        vSwitch_new.set_id('vSwitch-02')
        vSwitch_new.set_name('vSwitch-02')
        vSwitch_new.set_resourceManagerId('rmId')
        vSwitch_new.set_switchType('vSwitch')

        portGroup_new = PortGroup()
        portGroup_new.set_id('pg-02')
        portGroup_new.set_name('pg-02')
        portGroup_new.set_resourceManagerId('rmId')
        portGroup_new.set_type('portgroup_type')
        vSwitch.add_portGroups(portGroup_new)
        vmhost.add_virtualSwitches(vSwitch_new)
        vmhost.add_portGroups(portGroup_new)
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)

        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(
            len(vmhosts[0].get_virtualSwitches()) > 0,
            'Host get by virtual switch returned invalid number of list')
        self.assertTrue(
            len(vmhosts[0].get_portGroups()) > 0,
            'Host get by port group returned invalid number of list')
        self.assertTrue(vmhosts[0].id == host_id)
Esempio n. 16
0
    def test_vm_host_save_update_with_new_vSwitch(self):
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_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)

        vSwitch_new = VirtualSwitch()
        vSwitch_new.set_id('vSwitch-02')
        vSwitch_new.set_name('vSwitch-02')
        vSwitch_new.set_resourceManagerId('rmId')
        vSwitch_new.set_switchType('vSwitch')

        portGroup_new = PortGroup()
        portGroup_new.set_id('pg-02')
        portGroup_new.set_name('pg-02')
        portGroup_new.set_resourceManagerId('rmId')
        portGroup_new.set_type('portgroup_type')
        vSwitch.add_portGroups(portGroup_new)
        vmhost.add_virtualSwitches(vSwitch_new)
        vmhost.add_portGroups(portGroup_new)
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)

        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(
            len(vmhosts[0].get_virtualSwitches()) > 0,
            'Host get by virtual switch returned invalid number of list')
        self.assertTrue(
            len(vmhosts[0].get_portGroups()) > 0,
            'Host get by port group returned invalid number of list')
        self.assertTrue(vmhosts[0].id == host_id)
 def test_network_added_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vmhost = VmHost()
     vmhost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     vmhost.set_virtualSwitches([vswitch])
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     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_NETWORK_ADDED)
     self.assertEquals(msg["event_type"], event_type.get_event_fully_qal_name())
     payload = msg["payload"]
     self.assertEquals(payload["entity_type"], "VirtualSwitch")
     self.assertEquals(payload["entity_id"], vswitch.get_id())
Esempio n. 18
0
 def test_network_added_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vmhost = VmHost()
     vmhost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     vmhost.set_virtualSwitches([vswitch])
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     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_NETWORK_ADDED)
     self.assertEquals(msg['event_type'],
                       event_type.get_event_fully_qal_name())
     payload = msg['payload']
     self.assertEquals(payload['entity_type'], 'VirtualSwitch')
     self.assertEquals(payload['entity_id'], vswitch.get_id())
 def setUp(self):
     self.fakeConn = libvirt.open('qemu:///system')
     self.libvirt_connection_cls = connection.LibvirtConnection
     super(Test_virt_connection, self).setUp()
     self.flags(
         healthnmon_notification_drivers=[
             'healthnmon.notifier.log_notifier']
     )
     vmHost = VmHost()
     vmHost.id = '1'
     vmHost.uuid = '1'
     InventoryCacheManager.update_object_in_cache('1', vmHost)
Esempio n. 20
0
 def test_filtered_ordered_query_sort_no_field(self):
     # Create VmHost
     vmhost = VmHost()
     vmhost.id = 'VH1'
     healthnmon_db_api.vm_host_save(self.admin_context, vmhost)
     # Query with invalid sort key
     vmhosts = healthnmon_db_api.vm_host_get_all_by_filters(
         self.admin_context, None,
         'invalidSortField', DbConstants.ORDER_ASC)
     self.assert_(vmhosts is not None)
     self.assert_(len(vmhosts) == 1)
     self.assert_(vmhosts[0] is not None)
     self.assert_(vmhosts[0].id == vmhost.id)
Esempio n. 21
0
 def test_filtered_ordered_query_sort_no_field(self):
     # Create VmHost
     vmhost = VmHost()
     vmhost.id = 'VH1'
     healthnmon_db_api.vm_host_save(self.admin_context, vmhost)
     # Query with invalid sort key
     vmhosts = healthnmon_db_api.vm_host_get_all_by_filters(
         self.admin_context, None, 'invalidSortField',
         DbConstants.ORDER_ASC)
     self.assert_(vmhosts is not None)
     self.assert_(len(vmhosts) == 1)
     self.assert_(vmhosts[0] is not None)
     self.assert_(vmhosts[0].id == vmhost.id)
Esempio n. 22
0
 def test_filtered_ordered_query_changessince_invalid_value(self):
     # Create VmHost
     vmhost = VmHost()
     vmhost.id = 'VH1'
     healthnmon_db_api.vm_host_save(self.admin_context, vmhost)
     # Query with invalid changes-since
     filters = {'changes-since': 'invalid-value'}
     vmhosts = healthnmon_db_api.vm_host_get_all_by_filters(
         self.admin_context, filters, None, None)
     self.assert_(vmhosts is not None)
     self.assert_(len(vmhosts) == 1)
     self.assert_(vmhosts[0] is not None)
     self.assert_(vmhosts[0].id == vmhost.id)
Esempio n. 23
0
    def test_diff_resourcemodel_virtualSwitch_withadd(self):
        cachedHost = VmHost()
        cachedHost.id = '1'
        vmhost = VmHost()
        vmhost.id = '1'
        vswitch = VirtualSwitch()
        vswitch.set_id("11")
        vswitch.set_name("vs1")
        vmhost.set_virtualSwitches([vswitch])
        diff = ResourceModelDiff(cachedHost, vmhost)
        diff_res = diff.diff_resourcemodel()
        self.assertTrue(len(diff_res) > 0)
        self.assertTrue(self.update in diff_res)
        virtualSwitches = 'virtualSwitches'
        self.assertTrue(virtualSwitches in diff_res[self.update])
        self.assertTrue(self.add in diff_res[self.update][virtualSwitches])

        key = diff_res[self.update][virtualSwitches][self.add].keys()[0]
        self.assertTrue(isinstance(diff_res[self.update][virtualSwitches][
                        self.add][key], VirtualSwitch))
        addVirSwitch = diff_res[self.update][virtualSwitches][self.add][key]
        self.assertEquals(addVirSwitch.id, '11')
        self.assertEquals(addVirSwitch.name, 'vs1')
Esempio n. 24
0
 def test_filtered_ordered_query_changessince_invalid_value(self):
     # Create VmHost
     vmhost = VmHost()
     vmhost.id = 'VH1'
     healthnmon_db_api.vm_host_save(self.admin_context, vmhost)
     # Query with invalid changes-since
     filters = {'changes-since': 'invalid-value'}
     vmhosts = healthnmon_db_api.vm_host_get_all_by_filters(
         self.admin_context, filters,
         None, None)
     self.assert_(vmhosts is not None)
     self.assert_(len(vmhosts) == 1)
     self.assert_(vmhosts[0] is not None)
     self.assert_(vmhosts[0].id == vmhost.id)
Esempio n. 25
0
    def test_host_connected_event(self):
        self.__mock_service_get_all_by_topic()
        cachedHost = VmHost()
        cachedHost.id = self.libvirtVmHost.compute_id
        cachedHost.connectionState = 'Disconnected'
        self.mox.StubOutWithMock(
            InventoryCacheManager, 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(cachedHost)

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

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.StubOutWithMock(
            self.libvirtVmHost, '_get_compute_running_status')
        self.libvirtVmHost._get_compute_running_status().AndReturn(
            (True, 'host'))
        self.mox.StubOutWithMock(
            self.libvirtVmHost, '_get_network_running_status')
        self.libvirtVmHost._get_network_running_status(
            mox.IgnoreArg()).AndReturn(True)
        self.mox.ReplayAll()
        self.libvirtVmHost.processUpdates()
        self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(),
                          Constants.VMHOST_CONNECTED)
        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_HOST_CONNECTED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'VmHost')
        self.assertEquals(payload['entity_id'],
                          self.libvirtVmHost.compute_id)
Esempio n. 26
0
 def test_vm_host_save_none(self):
     '''
     check the vm_host_save api with none object
     '''
     vmhost = VmHost()
     vmhost.id = 'VH1-id'
     healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
     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) == 1,
                     'vm_host_get_all does not returned expected number of hosts')
     #Now tries to put None object in the db
     healthnmon_db_api.vm_host_save(get_admin_context(), None)
     #Again tries to retrieve the vmhost from db and
     #check it is same as before
     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) == 1,
                     'vm_host_get_all does not returned expected number of hosts')
Esempio n. 27
0
 def test_vm_host_delete_none(self):
     '''
     Check the vm_host_delete_by_ids by passing None as id
     '''
     vmhost = VmHost()
     vmhost.id = 'VH1-id'
     healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
     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) == 1,
                     'vm_host_get_all does not returned expected number of hosts')
     #Now call the delete api by passing the id as None
     healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(), None)
     #Again try to retrieve the vmhost and check whether its intact
     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) == 1,
                     'vm_host_get_all does not returned expected number of hosts')
Esempio n. 28
0
 def test_vm_host_delete_none(self):
     '''
     Check the vm_host_delete_by_ids by passing None as id
     '''
     vmhost = VmHost()
     vmhost.id = 'VH1-id'
     healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
     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) == 1,
         'vm_host_get_all does not returned expected number of hosts')
     #Now call the delete api by passing the id as None
     healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(), None)
     #Again try to retrieve the vmhost and check whether its intact
     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) == 1,
         'vm_host_get_all does not returned expected number of hosts')
Esempio n. 29
0
 def test_vm_host_save_none(self):
     '''
     check the vm_host_save api with none object
     '''
     vmhost = VmHost()
     vmhost.id = 'VH1-id'
     healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
     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) == 1,
         'vm_host_get_all does not returned expected number of hosts')
     #Now tries to put None object in the db
     healthnmon_db_api.vm_host_save(get_admin_context(), None)
     #Again tries to retrieve the vmhost from db and
     #check it is same as before
     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) == 1,
         'vm_host_get_all does not returned expected number of hosts')
Esempio n. 30
0
 def test_network_deleted_event(self):
     cachedHost = VmHost()
     cachedHost.id = self.libvirtNetwork.compute_id
     vswitch = VirtualSwitch()
     vswitch.set_id("11")
     vswitch.set_name("vs1")
     cachedHost.set_virtualSwitches([vswitch])
     vmhost = copy.deepcopy(cachedHost)
     vmhost.get_virtualSwitches().pop()
     self.assertEquals(vmhost.get_virtualSwitches(), [])
     self.libvirtNetwork._processNetworkEvents(cachedHost, vmhost)
     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_NETWORK_DELETED)
     self.assertEquals(msg['event_type'],
                       event_type.get_event_fully_qal_name())
     payload = msg['payload']
     self.assertEquals(payload['entity_type'], 'VirtualSwitch')
     self.assertEquals(payload['entity_id'], vswitch.get_id())
Esempio n. 31
0
    def test_host_connected_event(self):
        self.__mock_service_get_all_by_topic()
        cachedHost = VmHost()
        cachedHost.id = self.libvirtVmHost.compute_id
        cachedHost.connectionState = 'Disconnected'
        self.mox.StubOutWithMock(InventoryCacheManager,
                                 'get_object_from_cache')

        InventoryCacheManager.get_object_from_cache(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(cachedHost)

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

        InventoryCacheManager.get_compute_conn_driver(
            self.libvirtVmHost.compute_id,
            Constants.VmHost).AndReturn(fake.get_connection())
        self.mox.StubOutWithMock(api, 'vm_host_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mox.ReplayAll()
        self.libvirtVmHost.processUpdates()
        self.assertEquals(self.libvirtVmHost.vmHost.get_connectionState(),
                          Constants.VMHOST_CONNECTED)
        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_HOST_CONNECTED)
        self.assertEquals(msg['event_type'],
                          event_type.get_event_fully_qal_name())
        payload = msg['payload']
        self.assertEquals(payload['entity_type'], 'VmHost')
        self.assertEquals(payload['entity_id'], self.libvirtVmHost.compute_id)
Esempio n. 32
0
 def test_no_event_generated(self):
     vmhost = VmHost()
     vmhost.id = self.libvirtNetwork.compute_id
     self.libvirtNetwork._processNetworkEvents(None, vmhost)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
Esempio n. 33
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. 34
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')
Esempio n. 35
0
    def test_vmhost_save_modify_delete_with_vSwitch_pGroup(self):
        """Test case for filter deleted virtual switch and port group
        1. Create host with 2 virtual switch and port groups.
        2. Assert for the above point.
        3. Save VmHost by removing one virtualwitch and one port group.
        4. Assert for deleted virtual switch and port group.
        5. Delete the host.
        6. Use filter_by api to assert for deleted host,
        virtual switch and port group.
        """
        "Test for  points 1 and 2"
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_id
        cost = self._create_cost()
        vSwitch1 = self._create_switch(host_id + '_vSwitch-01')
        vSwitch1.set_cost(cost)
        portGroup1 = self._create_port_group(host_id + '_pGroup-01')
        portGroup1.set_cost(cost)
        vSwitch1.add_portGroups(portGroup1)
        vmhost.add_virtualSwitches(vSwitch1)
        vmhost.add_portGroups(portGroup1)

        "Add the second vswitch and portgroup"
        vSwitch2 = self._create_switch(host_id + '_vSwitch-02')
        vSwitch2.set_cost(cost)
        portGroup2 = self._create_port_group(host_id + '_pGroup-02')
        portGroup2.set_cost(cost)
        vSwitch2.add_portGroups(portGroup2)
        vmhost.add_virtualSwitches(vSwitch2)
        vmhost.add_portGroups(portGroup2)

        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        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].get_virtualSwitches()) > 0,
            'Host get by virtual switch returned invalid number of list')
        vss = vmhosts[0].get_virtualSwitches()
        vs_ids = []
        for vs in vss:
            vs_ids.append(vs.get_id())
        self.assertTrue(
            vSwitch1.get_id() in vs_ids,
            "Added virtual switch1 does not appears in the host api")
        self.assertTrue(
            vSwitch2.get_id() in vs_ids,
            "Added virtual switch2 does not appears in the host api")
        pgs = vmhosts[0].get_portGroups()
        pg_ids = []
        for pg in pgs:
            pg_ids.append(pg.get_id())
        self.assertTrue(portGroup1.get_id(
        ) in pg_ids, "Added port group1 does not appears in the host api")
        self.assertTrue(portGroup2.get_id(
        ) in pg_ids, "Added port group2 does not appears in the host api")

        # Points 3 and 4 - Remove the second vswitch and
        # portgroup from the vmhost and the save the vmhost"
        vmhost = VmHost()
        vmhost.id = host_id
        cost = self._create_cost()
        vSwitch = self._create_switch(host_id + '_vSwitch-01')
        vSwitch.set_cost(cost)
        portGroup = self._create_port_group(host_id + '_pGroup-01')
        portGroup.set_cost(cost)
        vSwitch.add_portGroups(portGroup)
        vmhost.add_virtualSwitches(vSwitch)
        vmhost.add_portGroups(portGroup)
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)

        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')
        vss = vmhosts[0].get_virtualSwitches()
        vs_ids = []
        for vs in vss:
            vs_ids.append(vs.get_id())
        self.assertTrue(
            vSwitch.get_id() in vs_ids,
            "Modified virtual switch1 not appearing in the host api")
        self.assertTrue(vSwitch2.get_id() not in vs_ids,
                        "Deleted virtual switch2 appears in the host api")
        pgs = vmhosts[0].get_portGroups()
        pg_ids = []
        for pg in pgs:
            pg_ids.append(pg.get_id())
        self.assertTrue(portGroup.get_id(
        ) in pg_ids, "Modified port group1 not appearing in the host api")
        self.assertTrue(portGroup2.get_id(
        ) not in pg_ids, "Deleted port group2 appears in the host api")

        # Points 5 and 6 - Delete the host and
        # assert for deletion using filter-by api"
        filters = {'id': host_id, 'deleted': 'true'}
        healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(), [host_id])
        del_vmhosts = healthnmon_db_api.vm_host_get_all_by_filters(
            get_admin_context(), filters, 'id', 'asc')
        self.assertFalse(
            del_vmhosts is None, 'Host get by filters returned a none list')
        vss = del_vmhosts[0].get_virtualSwitches()
        vs_ids = []
        for vs in vss:
            vs_ids.append(vs.get_id())
        self.assertTrue(
            vSwitch1.get_id() in vs_ids,
            "Deleted virtual switch1 not appearing in the host filter api")
        self.assertTrue(
            vSwitch2.get_id() in vs_ids,
            "Deleted virtual switch2 not appears in the host filter api")
        pgs = del_vmhosts[0].get_portGroups()
        pg_ids = []
        for pg in pgs:
            pg_ids.append(pg.get_id())
        self.assertTrue(
            portGroup1.get_id() in pg_ids,
            "Deleted port group1 not appearing in the host filter api")
        self.assertTrue(
            portGroup2.get_id() in pg_ids,
            "Deleted port group2 not appears in the host filter api")
Esempio n. 36
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. 37
0
    def test_vmhost_save_modify_delete_with_vSwitch_pGroup(self):
        """Test case for filter deleted virtual switch and port group
        1. Create host with 2 virtual switch and port groups.
        2. Assert for the above point.
        3. Save VmHost by removing one virtualwitch and one port group.
        4. Assert for deleted virtual switch and port group.
        5. Delete the host.
        6. Use filter_by api to assert for deleted host, virtual switch and port group.
        """
        "Test for  points 1 and 2"
        host_id = 'VH1'
        vmhost = VmHost()
        vmhost.id = host_id
        cost = self._create_cost()
        vSwitch1 = self._create_switch(host_id + '_vSwitch-01')
        vSwitch1.set_cost(cost)
        portGroup1 = self._create_port_group(host_id + '_pGroup-01')
        portGroup1.set_cost(cost)
        vSwitch1.add_portGroups(portGroup1)
        vmhost.add_virtualSwitches(vSwitch1)
        vmhost.add_portGroups(portGroup1)

        "Add the second vswitch and portgroup"
        vSwitch2 = self._create_switch(host_id + '_vSwitch-02')
        vSwitch2.set_cost(cost)
        portGroup2 = self._create_port_group(host_id + '_pGroup-02')
        portGroup2.set_cost(cost)
        vSwitch2.add_portGroups(portGroup2)
        vmhost.add_virtualSwitches(vSwitch2)
        vmhost.add_portGroups(portGroup2)

        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
        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].get_virtualSwitches()) > 0,
            'Host get by virtual switch returned invalid number of list')
        vss = vmhosts[0].get_virtualSwitches()
        vs_ids = []
        for vs in vss:
            vs_ids.append(vs.get_id())
        self.assertTrue(
            vSwitch1.get_id() in vs_ids,
            "Added virtual switch1 does not appears in the host api")
        self.assertTrue(
            vSwitch2.get_id() in vs_ids,
            "Added virtual switch2 does not appears in the host api")
        pgs = vmhosts[0].get_portGroups()
        pg_ids = []
        for pg in pgs:
            pg_ids.append(pg.get_id())
        self.assertTrue(portGroup1.get_id() in pg_ids,
                        "Added port group1 does not appears in the host api")
        self.assertTrue(portGroup2.get_id() in pg_ids,
                        "Added port group2 does not appears in the host api")

        "Points 3 and 4 - Remove the second vswitch and portgroup from the vmhost and the save the vmhost"
        vmhost = VmHost()
        vmhost.id = host_id
        cost = self._create_cost()
        vSwitch = self._create_switch(host_id + '_vSwitch-01')
        vSwitch.set_cost(cost)
        portGroup = self._create_port_group(host_id + '_pGroup-01')
        portGroup.set_cost(cost)
        vSwitch.add_portGroups(portGroup)
        vmhost.add_virtualSwitches(vSwitch)
        vmhost.add_portGroups(portGroup)
        healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)

        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')
        vss = vmhosts[0].get_virtualSwitches()
        vs_ids = []
        for vs in vss:
            vs_ids.append(vs.get_id())
        self.assertTrue(
            vSwitch.get_id() in vs_ids,
            "Modified virtual switch1 not appearing in the host api")
        self.assertTrue(vSwitch2.get_id() not in vs_ids,
                        "Deleted virtual switch2 appears in the host api")
        pgs = vmhosts[0].get_portGroups()
        pg_ids = []
        for pg in pgs:
            pg_ids.append(pg.get_id())
        self.assertTrue(portGroup.get_id() in pg_ids,
                        "Modified port group1 not appearing in the host api")
        self.assertTrue(portGroup2.get_id() not in pg_ids,
                        "Deleted port group2 appears in the host api")

        "Points 5 and 6 - Delete the host and assert for deletion using filter-by api"
        filters = {'id': host_id, 'deleted': 'true'}
        healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(), [host_id])
        del_vmhosts = healthnmon_db_api.vm_host_get_all_by_filters(
            get_admin_context(), filters, 'id', 'asc')
        self.assertFalse(del_vmhosts is None,
                         'Host get by filters returned a none list')
        vss = del_vmhosts[0].get_virtualSwitches()
        vs_ids = []
        for vs in vss:
            vs_ids.append(vs.get_id())
        self.assertTrue(
            vSwitch1.get_id() in vs_ids,
            "Deleted virtual switch1 not appearing in the host filter api")
        self.assertTrue(
            vSwitch2.get_id() in vs_ids,
            "Deleted virtual switch2 not appears in the host filter api")
        pgs = del_vmhosts[0].get_portGroups()
        pg_ids = []
        for pg in pgs:
            pg_ids.append(pg.get_id())
        self.assertTrue(
            portGroup1.get_id() in pg_ids,
            "Deleted port group1 not appearing in the host filter api")
        self.assertTrue(
            portGroup2.get_id() in pg_ids,
            "Deleted port group2 not appears in the host filter api")
Esempio n. 38
0
 def test_no_event_generated(self):
     vmhost = VmHost()
     vmhost.id = self.libvirtNetwork.compute_id
     self.libvirtNetwork._processNetworkEvents(None, vmhost)
     self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
Esempio n. 39
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")