File: 300-migration.t

package info (click to toggle)
libvirt-tck 0.1.0~2.git890d1c-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,128 kB
  • sloc: perl: 2,885; sh: 1,180; xml: 992; makefile: 6
file content (542 lines) | stat: -rw-r--r-- 15,273 bytes parent folder | download
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# -*- perl -*-
#
# Copyright (C) 2011 Red Hat, Inc.
# Copyright (C) 2011 Daniel P. Berrange
#
# This program is free software; You can redistribute it and/or modify
# it under the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any
# later version
#
# The file "LICENSE" distributed along with this file provides full
# details of the terms and conditions
#

=pod

=head1 NAME

domain/300-migration.t - test migration workflows

=head1 DESCRIPTION

The test case validates all the different ways to
invoke migration. There are alot of variables involved
in testing migration

 - Three different control/communication methods

     1. Normal
     2. Peer2peer
     3. Peer2peer + tunnelled

 - 8 Different scenarios of persistent vs transient
   guests

     1. Transient running source, no dest
     2. Transient running source, persistent inactive dest
     3. Persistent running source, no dest
     4. Persistent running source, persistent inactive dest
     5. Transient paused source, no dest
     6. Transient paused source, persistent inactive dest
     7. Persistent paused source, no dest
     8. Persistent paused source, persistent inactive dest

 - With each scenario there are upto 4 flag combinations
   affecting persistent/transient state

     1. No flags
     2. UNDEFINE_SOURCE
     3. PERSIST
     4. UNDEFINE_SOURCE|PERSIST

This gives 96 major functional test cases.

On each test case we validate 10 conditions, giving a
total of 960 tests results

Ideally this test script should be run once for each different
combination of libvirt client & libvirtd source/target, giving
another factor of 8

    1. client < 0.9.2, source < 0.9.2, target < 0.9.2
    2. client >= 0.9.2, source < 0.9.2, target < 0.9.2
    3. client < 0.9.2, source >= 0.9.2, target < 0.9.2
    4. client < 0.9.2, source < 0.9.2, target >= 0.9.2
    5. client >= 0.9.2, source >= 0.9.2, target < 0.9.2
    6. client >= 0.9.2, source < 0.9.2, target >= 0.9.2
    7. client < 0.9.2, source >= 0.9.2, target >= 0.9.2
    8. client >= 0.9.2, source >= 0.9.2, target >= 0.9.2

Finally, this is only testing successful migration cases.

We ought to have another test which validates recovery from
a variety of common migration failure scenarios. This would
add another few 1000 tests :-)

=cut

use strict;
use warnings;

use Test::Exception;

#
# 8 scenarios in @tests
# Each scenario has 4 cases in @tests
#
# Repeated scenarios in 3 ways (normal, p2p, tunnelled)
#
# Each iteration has 10 tests
#
# 8 * 4 * 3 * 10 == 960

use Test::More tests => 960;

use Sys::Virt::TCK;

my $tck = Sys::Virt::TCK->new();
my ($conn, $otherconn) = eval { $tck->setup(dualhost => 1); };
BAIL_OUT "failed to setup test harness: $@" if $@;
END { $tck->cleanup if $tck; }

my $xml = $tck->generic_domain("tck")->uuid("050072e8-7bce-3515-992a-8431d74f371f")->as_xml;

use Sys::Virt::Domain;
use IO::File;


my @tests = (
    # 1. Transient running guest, no dst
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_RUNNING,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

    # 2. Transient running guest, with dst
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_RUNNING,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

    # 3. Persistent running guest, no dst
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_RUNNING,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 0,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 1,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

    # 4. Persistent running guest, with dst
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_RUNNING,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_RUNNING,
	presrcconfig => 1,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_RUNNING,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },



    # 5. Transient paused guest, no dst
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

    # 6. Transient paused guest, with dst
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 0,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

    # 7. Persistent paused guest, no dst
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 0,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 0,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 0,
	postdstconfig => 0,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

    # 8. Persistent paused guest, with dst
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_LIVE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PERSIST_DEST,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 0,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_UNDEFINE_SOURCE,
    },
    {
	prestate => Sys::Virt::Domain::STATE_PAUSED,
	runstate => Sys::Virt::Domain::STATE_PAUSED,
	poststate => Sys::Virt::Domain::STATE_PAUSED,
	presrcconfig => 1,
	postsrcconfig => 1,
	predstconfig => 1,
	postdstconfig => 1,
	flags => Sys::Virt::Domain::MIGRATE_PAUSED,
    },

);

#@tests = ($tests[4]);

my @flags = (0,
	     Sys::Virt::Domain::MIGRATE_PEER2PEER,
	     Sys::Virt::Domain::MIGRATE_PEER2PEER | Sys::Virt::Domain::MIGRATE_TUNNELLED);

#@flags = ($flags[0]);

SKIP: {
    skip "No other URI available", 960 unless $otherconn;

    foreach my $flags (@flags) {
	diag "Protocol flags $flags\n\n";
	foreach my $test (@tests) {
	    my $srcvm;
	    my $dstvm;

	    my $migflags = $flags | $test->{flags};

	    my $s = sprintf "PreState %d PostState %d PreSrcConf %d PostSrcConf %d PreDstConf %d PostDstConf %d Flags %2d (%2d)",
	      $test->{prestate},$test->{poststate},$test->{presrcconfig},
	      $test->{postsrcconfig},$test->{predstconfig},$test->{postdstconfig},
	      $test->{flags}, $flags;
	    diag $s;

	    if ($test->{presrcconfig}) {
		ok_domain(sub { $srcvm = $conn->define_domain($xml) }, "defined initial domain");

		if ($test->{prestate} == Sys::Virt::Domain::STATE_PAUSED) {
		    lives_ok(sub { $srcvm->create(Sys::Virt::Domain::START_PAUSED) }, "started initial domain");
		} else {
		    lives_ok(sub { $srcvm->create() } , "started initial domain");
		}
	    } else {
		ok(1, "no need to define initial domain");
		if ($test->{prestate} == Sys::Virt::Domain::STATE_PAUSED) {
		    ok_domain(sub { $srcvm = $conn->create_domain($xml, Sys::Virt::Domain::START_PAUSED) },
			      "created initial domain");
		} else {
		    ok_domain(sub { $srcvm = $conn->create_domain($xml) }, "created initial domain");
		}
	    }

	    if ($test->{predstconfig}) {
		ok_domain(sub { $dstvm = $otherconn->define_domain($xml)}, "defined target domain");
		$dstvm = undef;
	    } else {
		ok(1, "no need to define target domain");
	    }

	    my $failed = 1;
	    lives_ok(sub {
		if ($migflags & Sys::Virt::Domain::MIGRATE_PEER2PEER) {
		    $srcvm->migrate_to_uri($otherconn->get_uri, $migflags);
		} else {
		    $dstvm = $srcvm->migrate($otherconn, $migflags);
		}

		$srcvm = undef;
		$dstvm = undef;
		$failed = 0;
		     }, "migrated domain");

	  SKIP: {
	      skip "source VM failed migration", 5 if $failed;

	      if ($test->{postsrcconfig}) {
		  $srcvm = $conn->get_domain_by_name("tck");
		  ok(!$srcvm->is_active, "source VM is not still active");
		  ok($srcvm->is_persistent, "source VM config still exists");
	      } else {
		  eval { $srcvm = $conn->get_domain_by_name("tck"); };
		  ok(!$srcvm, "source VM is not still active");
		  ok(1, "source VM config does not still exist");
	      }

	      lives_ok(sub { $dstvm = $otherconn->get_domain_by_name("tck")}, "target VM exists");
	      ok($dstvm->is_active, "target VM is running");

	      ok(!$test->{postdstconfig} || $dstvm->is_persistent, "target VM is persistent");

	      my $state = $dstvm->get_info()->{state};

	      is($state, $test->{poststate}, "target VM state");
	    };

	    $tck->reset_domains($conn);
	    $tck->reset_domains($otherconn);
	}
	print "\n\n";
    }

};