summaryrefslogtreecommitdiff
path: root/tests/uitests/test_manager.py
blob: b01c3691fd5a28aaa705052629f92fce5407c164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.

import tests.utils
from . import lib


#############################################################
# UI tests for manager window, and basic VM lifecycle stuff #
#############################################################

def _testVMLifecycle(app):
    """
    Basic VM lifecycle test, shared between standard and no-events
    testing
    """
    manager = app.topwin
    shutdown = manager.find("Shut Down", "push button")
    pause = manager.find("Pause", "toggle button")
    run = manager.find("Run", "push button")
    force = manager.find("Force Off", "menu item")
    smenu = manager.find("Menu", "toggle button")
    save = manager.find("Save", "menu item")

    c = manager.find("test-many-devices", "table cell")
    c.click()
    smenu.click()
    force.click()
    app.click_alert_button("Are you sure you want", "Yes")
    lib.utils.check(lambda: run.sensitive, timeout=5)

    run.click()
    lib.utils.check(lambda: not run.sensitive, timeout=5)
    pause.click()
    lib.utils.check(lambda: pause.checked, timeout=5)
    pause.click()
    lib.utils.check(lambda: not pause.checked, timeout=5)
    smenu.click()
    save.click()
    lib.utils.check(lambda: run.sensitive, timeout=5)
    lib.utils.check(lambda: "Saved" in c.text)
    run.click()
    lib.utils.check(lambda: shutdown.sensitive, timeout=5)


def testVMLifecycle(app):
    # qemu hits some different domain code paths for setTime
    app.uri = tests.utils.URIs.kvm_x86
    _testVMLifecycle(app)


def testVMNoEventsLifecycle(app):
    app.open(extra_opts=["--test-options=no-events",
                         "--test-options=short-poll"])
    _testVMLifecycle(app)


def testVMLifecycleExtra(app):
    """
    Test vmmenu lifecycle options
    """
    app.open(keyfile="confirm-all.ini")
    manager = app.topwin
    run = manager.find("Run", "push button")
    shutdown = manager.find("Shut Down", "push button")
    pause = manager.find("Pause", "toggle button")

    def confirm_is_running():
        lib.utils.check(lambda: not run.sensitive)

    def confirm_is_shutdown():
        lib.utils.check(lambda: not shutdown.sensitive)

    def confirm_is_paused():
        lib.utils.check(lambda: pause.checked)

    def confirm_not_paused():
        lib.utils.check(lambda: not pause.checked)

    def test_action(**kwargs):
        app.manager_vm_action("test", confirm_click_no=True, **kwargs)

    confirm_is_running()
    test_action(reset=True)
    confirm_is_running()
    test_action(reboot=True)
    confirm_is_running()
    test_action(shutdown=True)
    confirm_is_shutdown()
    test_action(run=True)
    confirm_is_running()
    test_action(destroy=True)
    confirm_is_shutdown()
    test_action(run=True)
    confirm_is_running()
    test_action(pause=True)
    confirm_is_paused()
    test_action(resume=True)
    confirm_not_paused()
    test_action(save=True)
    confirm_is_shutdown()
    test_action(restore=True)
    confirm_is_running()


def testManagerSaveCancelError(app):
    """
    Test managed save special behavior
    """
    app.open(extra_opts=["--test-options=test-managed-save"])

    manager = app.topwin
    run = manager.find("Run", "push button")
    smenu = manager.find("Menu", "toggle button")
    save = manager.find("Save", "menu item")

    c = manager.find("test-many-devices", "table cell")
    c.click()

    # Save it, attempt a cancel operation
    smenu.click()
    save.click()
    progwin = app.find_window("Saving Virtual Machine")
    # Attempt cancel which will fail, then find the error message
    progwin.find("Cancel", "push button").click()
    progwin.find("Error cancelling save job")
    lib.utils.check(lambda: not progwin.showing, timeout=5)
    lib.utils.check(lambda: run.sensitive)

    # Restore will fail and offer to remove managed save
    run.click()
    app.click_alert_button("remove the saved state", "No")
    lib.utils.check(lambda: run.sensitive)
    run.click()
    app.click_alert_button("remove the saved state", "Yes")
    lib.utils.check(lambda: not run.sensitive)


def testManagerQEMUSetTime(app):
    """
    Fake qemu setTime behavior for code coverage
    """
    app.uri = tests.utils.URIs.kvm_x86
    manager = app.topwin
    run = manager.find("Run", "push button")
    smenu = manager.find("Menu", "toggle button")
    save = manager.find("Save", "menu item")

    c = manager.find("test alternate devs title", "table cell")
    c.click()

    # Save -> resume -> save
    smenu.click()
    save.click()
    lib.utils.check(lambda: run.sensitive)
    app.sleep(1)  # give settime thread time to run
    run.click()
    lib.utils.check(lambda: not run.sensitive)
    app.sleep(1)  # give settime thread time to run
    smenu.click()
    save.click()
    lib.utils.check(lambda: run.sensitive)
    app.sleep(1)  # give settime thread time to run


def testManagerVMRunFail(app):
    # Force VM startup to fail so we can test the error path
    app.open(extra_opts=["--test-options=test-vm-run-fail"])

    manager = app.topwin

    c = manager.find("test-clone-simple", "table cell")
    c.click()
    manager.find("Run", "push button").click()
    app.click_alert_button("fake error", "Close")



def testManagerColumns(app):
    # Enable all stat options
    # Need to expand the window size so all columns are onscreen
    app.open(keyfile="winsize.ini")
    app.root.find("Edit", "menu").click()
    app.root.find("Preferences", "menu item").click()
    win = app.find_window("Preferences")
    win.find("Polling", "page tab").click()
    win.find_fuzzy("Poll Disk", "check").click()
    win.find_fuzzy("Poll Network", "check").click()
    win.find_fuzzy("Poll Memory", "check").click()
    win.find("Close", "push button").click()

    manager = app.topwin
    def _test_sort(name):
        col = manager.find(name, "table column header")
        col.check_onscreen()
        # Trigger sorting
        col.click()
        col.click()

    def _click_column_menu(name):
        manager.find("View", "menu").click()
        menu = manager.find("Graph", "menu")
        menu.point()
        menu.find_fuzzy(name, "check menu item").click()

    def _test_column(name):
        _click_column_menu(name)
        _test_sort(name)

    _test_sort("Name")
    _click_column_menu("Guest CPU")
    _click_column_menu("Guest CPU")
    _test_sort("CPU usage")
    _test_column("Host CPU")
    _test_column("Memory")
    _test_column("Disk I/O")
    _test_column("Network I/O")


def testManagerWindowReposition(app):
    """
    Restore previous position when window is reopened
    """
    manager = app.topwin
    host = app.manager_open_host("Storage")
    fmenu = host.find("File", "menu")
    fmenu.click()
    fmenu.find("View Manager", "menu item").click()
    lib.utils.check(lambda: manager.active)

    curxy = manager.title_coordinates()
    newxy = curxy[0] + 200, curxy[1] + 200
    import dogtail.rawinput
    dogtail.rawinput.dragWithTrajectory(curxy, newxy)
    checkxy = manager.position
    manager.window_close()
    host.click_title()
    host.find("File", "menu").click()
    host.find("View Manager", "menu item").click()
    lib.utils.check(lambda: manager.showing)
    assert manager.position == checkxy



def testManagerWindowCleanup(app):
    """
    Open migrate, clone, delete, newvm, details, host windows, close the
    connection, make sure they all disappear
    """
    manager = app.topwin
    manager.window_maximize()

    # Open delete window hitting a special code path, then close it
    manager.find("test-many-devices", "table cell").click()
    manager.find("Edit", "menu").click()
    manager.find("Delete", "menu item").click()
    delete = app.root.find_fuzzy("Delete", "frame")
    delete.find("storage-list").grab_focus()
    delete.window_close()

    # Open Clone window hitting a special code path, then close it
    manager.find("test-clone", "table cell").click()
    app.rawinput.pressKey("Menu")
    app.root.find("Clone...", "menu item").click()
    clone = app.find_window("Clone Virtual Machine")
    clone.window_close()

    # Open host
    manager.grab_focus()
    c = manager.find_fuzzy("testdriver.xml", "table cell")
    c.doubleClick()
    host = app.find_window("test testdriver.xml - Connection Details")

    # Open details
    manager.grab_focus()
    c = manager.find("test-many-devices", "table cell")
    c.doubleClick()
    details = app.find_details_window("test-many-devices")

    # Close the connection
    manager.grab_focus()
    app.manager_conn_disconnect("test testdriver.xml")

    # Ensure all those windows aren't showing
    lib.utils.check(lambda: not details.showing)

    # Delete the connection, ensure the host dialog disappears
    app.manager_conn_delete("test testdriver.xml")
    lib.utils.check(lambda: not host.showing)


def testManagerDefaultStartup(app):
    app.open(use_uri=False)
    manager = app.topwin
    errlabel = manager.find("error-label")
    lib.utils.check(
            lambda: "Checking for virtualization" in errlabel.text)
    lib.utils.check(
            lambda: "File->Add Connection" in errlabel.text)
    lib.utils.check(
            lambda: "appropriate QEMU/KVM" in errlabel.text)

    manager.find("File", "menu").click()
    manager.find("Quit", "menu item").click()


def testManagerConnOpenFail(app):
    app.open(keyfile="baduri.ini")
    manager = app.topwin
    manager.find_fuzzy("bad uri", "table cell").doubleClick()
    lib.utils.check(lambda: not manager.active)
    app.click_alert_button("Unable to connect", "Close")
    lib.utils.check(lambda: manager.active)