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')
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())
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())
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')
def test_portGroup_deleted_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().pop() vmhost.get_virtualSwitches().pop() self.assertEquals(vmhost.get_virtualSwitches(), []) 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_DELETED) 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())
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')
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.connection = LibvirtConnection(False) vmHost = VmHost() vSwitch = VirtualSwitch() vSwitch.set_id('52:54:00:34:14:AE') vSwitch.set_name('default') vSwitch.set_switchType('nat') vmHost.set_virtualSwitches([vSwitch]) InventoryCacheManager.update_object_in_cache('1', vmHost) #self.connection.setUuid('34353438-3934-434e-3738-313630323543') self.connection._wrapped_conn = libvirt.open('qemu:///system') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.LibvirtNetwork = LibvirtNetwork(self.connection, '1') self.mock = mox.Mox() cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier'])
def setUp(self): self.connection = LibvirtConnection(False) vmHost = VmHost() vSwitch = VirtualSwitch() vSwitch.set_id('52:54:00:34:14:AE') vSwitch.set_name('default') vSwitch.set_switchType('nat') vmHost.set_virtualSwitches([vSwitch]) InventoryCacheManager.update_object_in_cache('1', vmHost) #self.connection.setUuid('34353438-3934-434e-3738-313630323543') self.connection._wrapped_conn = libvirt.open('qemu:///system') self.connection.compute_rmcontext = \ ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165', rmUserName='******', rmPassword='******') self.LibvirtNetwork = LibvirtNetwork(self.connection, '1') self.mock = mox.Mox() cfg.CONF.set_override('healthnmon_notification_drivers', ['healthnmon.notifier.log_notifier'])
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 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())
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')