def test_event_lifecycle_callback_suspended_migrated_job_failed( self, find_job_type, get_job_info): """Tests the suspended lifecycle event with libvirt with migrated""" hostimpl = mock.MagicMock() conn = mock.MagicMock() fake_dom_xml = """ <domain type='kvm'> <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid> </domain> """ dom = fakelibvirt.Domain(conn, fake_dom_xml, running=True) jobinfo = libvirt_guest.JobInfo(type=fakelibvirt.VIR_DOMAIN_JOB_NONE) get_job_info.return_value = jobinfo # If the job type is VIR_DOMAIN_JOB_NONE we'll attempt to figure out # the actual job status, so in this case we mock it to be a failure. find_job_type.return_value = fakelibvirt.VIR_DOMAIN_JOB_FAILED host.Host._event_lifecycle_callback( conn, dom, fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED, detail=fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED, opaque=hostimpl) expected_event = hostimpl._queue_event.call_args[0][0] self.assertEqual(event.EVENT_LIFECYCLE_PAUSED, expected_event.transition) get_job_info.assert_called_once_with() find_job_type.assert_called_once_with(test.MatchType( libvirt_guest.Guest), instance=None, logging_ok=False)
def test_serial_console_live_migrate(self, mock_file_open, mock_valid_hostname, mock_get_fs_info, mock_create_image, mock_conductor_source_check, mock_path_get_size, mock_get_disk_size, mock_host_get_connection, mock_migrate_to_uri, mock_get_job_info, mock_get_volume_connector, mock_undefine): """Regression test for bug #1595962. If the graphical consoles VNC and SPICE are disabled, the live-migration of an instance will result in an ERROR state. VNC and SPICE are usually disabled on IBM z systems platforms where graphical consoles are not available. The serial console is then enabled and VNC + SPICE are disabled. The error will be raised at https://opendev.org/openstack/nova/src/commit/ 4f33047d07f5a11b208c344fe206aba01cd8e6fe/ nova/virt/libvirt/driver.py#L5842-L5852 """ mock_get_job_info.return_value = libvirt_guest.JobInfo( type=fakelibvirt.VIR_DOMAIN_JOB_COMPLETED) fake_connection = fakelibvirt.Connection('qemu:///system', version=fakelibvirt.FAKE_LIBVIRT_VERSION, hv_version=fakelibvirt.FAKE_QEMU_VERSION) mock_host_get_connection.return_value = fake_connection # We invoke cleanup on source host first which will call undefine # method currently. Since in functional test we make all compute # services linked to the same connection, we need to mock the undefine # method to avoid triggering 'Domain not found' error in subsequent # rpc call post_live_migration_at_destination. mock_undefine.return_value = True server_attr = dict(name='server1', imageRef=self.image_id, flavorRef=self.flavor_id) server = self.api.post_server({'server': server_attr}) server_id = server['id'] self.wait_till_active_or_timeout(server_id) post = {"os-migrateLive": { "block_migration": False, "disk_over_commit": False, "host": "test_compute1" }} try: # This should succeed self.admin_api.post_server_action(server_id, post) self.wait_till_active_or_timeout(server_id) except Exception as ex: self.fail(ex.response.content)
def test_serial_console_live_migrate(self, mock_file_open, mock_valid_hostname, mock_get_fs_info, mock_create_image, mock_conductor_source_check, mock_path_get_size, mock_get_disk_size, mock_host_get_connection, mock_migrate_to_uri, mock_get_job_info, mock_get_volume_connector): """Regression test for bug #1595962. If the graphical consoles VNC and SPICE are disabled, the live-migration of an instance will result in an ERROR state. VNC and SPICE are usually disabled on IBM z systems platforms where graphical consoles are not available. The serial console is then enabled and VNC + SPICE are disabled. The error will be raised at https://github.com/openstack/nova/blob/ 4f33047d07f5a11b208c344fe206aba01cd8e6fe/ nova/virt/libvirt/driver.py#L5842-L5852 """ mock_get_job_info.return_value = libvirt_guest.JobInfo( type=fakelibvirt.VIR_DOMAIN_JOB_COMPLETED) fake_connection = fakelibvirt.Connection('qemu:///system', version=fakelibvirt.FAKE_LIBVIRT_VERSION, hv_version=fakelibvirt.FAKE_QEMU_VERSION) mock_host_get_connection.return_value = fake_connection server_attr = dict(name='server1', imageRef=self.image_id, flavorRef=self.flavor_id) server = self.api.post_server({'server': server_attr}) server_id = server['id'] self.wait_till_active_or_timeout(server_id) post = {"os-migrateLive": { "block_migration": False, "disk_over_commit": False, "host": "test_compute1" }} try: # This should succeed self.admin_api.post_server_action(server_id, post) self.wait_till_active_or_timeout(server_id) except Exception as ex: self.fail(ex.response.content)
def test_live_migration_save_stats(self, mock_isave, mock_msave): mig = objects.Migration() info = libvirt_guest.JobInfo(memory_total=1 * units.Gi, memory_processed=5 * units.Gi, memory_remaining=500 * units.Mi, disk_total=15 * units.Gi, disk_processed=10 * units.Gi, disk_remaining=14 * units.Gi) migration.save_stats(self.instance, mig, info, 75) self.assertEqual(mig.memory_total, 1 * units.Gi) self.assertEqual(mig.memory_processed, 5 * units.Gi) self.assertEqual(mig.memory_remaining, 500 * units.Mi) self.assertEqual(mig.disk_total, 15 * units.Gi) self.assertEqual(mig.disk_processed, 10 * units.Gi) self.assertEqual(mig.disk_remaining, 14 * units.Gi) self.assertEqual(self.instance.progress, 25) mock_msave.assert_called_once_with() mock_isave.assert_called_once_with()
def test_event_lifecycle_callback_suspended_migrated(self, get_job_info): """Tests the suspended lifecycle event with libvirt with migrated""" hostimpl = mock.MagicMock() conn = mock.MagicMock() fake_dom_xml = """ <domain type='kvm'> <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid> </domain> """ dom = fakelibvirt.Domain(conn, fake_dom_xml, running=True) jobinfo = libvirt_guest.JobInfo( type=fakelibvirt.VIR_DOMAIN_JOB_COMPLETED) get_job_info.return_value = jobinfo host.Host._event_lifecycle_callback( conn, dom, fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED, detail=fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED, opaque=hostimpl) expected_event = hostimpl._queue_event.call_args[0][0] self.assertEqual(event.EVENT_LIFECYCLE_MIGRATION_COMPLETED, expected_event.transition) get_job_info.assert_called_once_with()