-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathguest_installation_and_configuration_base.pm
executable file
·3318 lines (2748 loc) · 155 KB
/
guest_installation_and_configuration_base.pm
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# VIRTUAL MACHINE INSTALLATION AND CONFIGURATION BASE MODULE
#
# Copyright SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Summary: This module provides framework and APIs to install virtual
# machine by using virt-install comman line.It supports configuration
# and modification to virtualation,platform,name,memory,cpu,metadata,
# xml,installation method,network selection,storage types,boot settings,
# graphics,videos,consoles,power management and other features of vm.
# It also provides installation monitoring,power cycle,results recording,
# environment cleanup,logs collecting and etc.
# Please refer to %guest_params for detailed parameters usage and
# description before each subroutine for its purpose.
#
# Maintainer: Wayne Chen <[email protected]> or <[email protected]>
package guest_installation_and_configuration_base;
use base "opensusebasetest";
use strict;
use warnings;
use POSIX;
use File::Basename;
use Net::SSH2;
use File::Copy 'copy';
use File::Path 'make_path';
use Data::Dumper;
use XML::Writer;
use IO::File;
use List::Util;
use Carp;
use IO::Scalar;
use List::Util qw(first);
use testapi;
use utils;
use ipmi_backend_utils qw(reconnect_when_ssh_console_broken);
use virt_utils;
use virt_autotest::utils;
use virt_autotest::virtual_network_utils;
use version_utils;
use Utils::Systemd;
use mm_network;
use guest_installation_and_configuration_metadata;
our $AUTOLOAD;
our $common_log_folder = '/var/log/guest_installation_and_configuration';
our $common_environment_prepared = 'false';
=head2 reveal_myself
reveal_myself($self)
Any subroutine calls this subroutine announces its identity and it is being executed.
=cut
sub reveal_myself {
my $self = shift;
my $_my_identity = (caller(1))[3];
diag("Test execution inside $_my_identity.");
return $self;
}
=head2 create
create($self)
Create guest instance by assigning values to its parameters but do no install it.
=cut
sub create {
my $self = shift;
$self->reveal_myself;
$self->initialize_guest_params;
$self->config_guest_params(@_);
$self->print_guest_params;
return $self;
}
=head2 initialize_guest_params
initialize_guest_params($self)
Initialize all guest parameters to avoid uninitialized parameters.
=cut
sub initialize_guest_params {
my $self = shift;
$self->reveal_myself;
$self->{$_} //= '' foreach (keys %guest_installation_and_configuration_metadata::guest_params);
$self->{start_run} = time();
return $self;
}
=head2 config_guest_params
config_guest_params($self, %_guest_params)
Assign real values to guest instance parameters. Reset [guest_name] to guest name
used in [guest_metadata] if they are different. The subroutine can be called
mainly in two different ways: Firstly, config_guest_params can be called in
another subroutine, for example, create which takes a hash/dictionary as argument.
my %testhash = ('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'),
$self->create(%testhash) which calls $self->config_guest_params(@_). Secondly,
config_guest_params can also be called direcly, for example,
$self->config_guest_params(%testhash). Call revise_guest_version_and_build to
correct guest version and build parameters to avoid mismatch if necessary.
=cut
sub config_guest_params {
my $self = shift;
my %_guest_params = @_;
$self->reveal_myself;
if ((scalar(@_) % 2 eq 0) and (scalar(@_) gt 0)) {
record_info("Configuring guest instance by using following parameters:", Dumper(\%_guest_params));
map { $self->{$_} = $_guest_params{$_} } keys %_guest_params;
}
else {
record_info("Can not configure guest instance with empty or odd number of arguments.Mark it as failed.", Dumper(\%_guest_params), result => 'fail');
$self->record_guest_installation_result('FAILED') if ($self->{guest_installation_result} eq '');
return $self;
}
if ((defined $self->{guest_metadata}) and (grep { /name=/ } split(',', $self->{guest_metadata}))) {
my $_guest_name_in_metadata = grep { /name=(.*)/ } split(',', $self->{guest_metadata});
if (($self->{guest_name} ne $_guest_name_in_metadata) and ($self->{guest_installation_result} eq '')) {
record_info("The guest instance has a different name $_guest_name_in_metadata in metadata than $self->{guest_name}.", "Reset guest name to $_guest_name_in_metadata.");
$self->{guest_name} = $_guest_name_in_metadata;
}
}
$self->revise_guest_version_and_build;
return $self;
}
=head2 revise_guest_version_and_build
revise_guest_version_and_build($self, %_guest_params)
Correct [guest_version], [guest_version_major], [guest_version_minor] and
[guest_build] if they are not set correctly or mismatch with each other. Set
[guest_version] to the developing product version if it is not given. Set
[guest_version_major] and [guest_version_minor] from [guest_version] it they do
not match with [guest_version]. Set [guest_build] to get_required_var('BUILD')
if it is empty and developing [guest_version], or 'GM' if non-developing
[guest_version]. This subroutine help make things better and life easier but
the end user should always pay attention and use meaningful and correct guest
parameter and profile.
=cut
sub revise_guest_version_and_build {
my $self = shift;
my %_guest_params = @_;
$self->reveal_myself;
if ($self->{guest_version} eq '') {
$self->{guest_version} = (get_var('REPO_0_TO_INSTALL', '') eq '' ? lc get_required_var('VERSION') : lc get_required_var('TARGET_DEVELOPING_VERSION'));
record_info("Guest $self->{guest_name} does not have guest_version set.Set it to test suite setting VERSION", "Please pay attention ! It is now $self->{guest_version}");
}
if ($self->{guest_os_name} =~ /sles|oraclelinux|slem|slm/im) {
if (($self->{guest_version_major} eq '') or (!($self->{guest_version} =~ /^(r)?$self->{guest_version_major}((-|\.)?(sp|u)?(\d*))?$/im))) {
($self->{guest_version_major}) = $self->{guest_version} =~ /(\d+)[-|\.]?.*$/im;
record_info("Guest $self->{guest_name} does not have guest_version_major set or it does not match with guest_version.Set it from guest_version", "Please pay attention ! It is now $self->{guest_version_major}");
}
if (($self->{guest_version_minor} eq '') or (!($self->{guest_version} =~ /^(r)?(\d+)(-|\.)?(sp|u)?$self->{guest_version_minor}$/im))) {
$self->{guest_version} =~ /^.*(-|\.)(sp|u)?(\d*)$/im;
$self->{guest_version_minor} = ($3 eq '' ? 0 : $3);
record_info("Guest $self->{guest_name} does not have guest_version_minor set or it does not match with guest_version.Set it from guest_version", "Please pay attention ! It is now $self->{guest_version_minor}");
}
}
if ($self->{guest_build} eq '') {
if ((!get_var('REPO_0_TO_INSTALL') and ($self->{guest_version} eq lc get_required_var('VERSION'))) or (get_var('REPO_0_TO_INSTALL') and ($self->{guest_version} eq lc get_required_var('TARGET_DEVELOPING_VERSION')))) {
# BUILD is not the only parameter to indicate real build numbe of installation media,
# for example, openQA SLE Micro group use BUILD_ISO to do this and the BUILD is being
# used for grouping all relevant test suites together under the same goup. Thus it is
# necessary to have BUILD_ISO here as well to generate correct build number for guest.
$self->{guest_build} = lc get_var('BUILD_ISO', get_required_var('BUILD'));
}
else {
$self->{guest_build} = 'gm';
}
record_info("Guest $self->{guest_name} does not have guest_build set.Set it to test suite setting BUILD or GM according to guest_version", "Please pay attention ! It is now $self->{guest_build}");
}
return $self;
}
=head2 print_guest_params
print_guest_params($self)
Print out guest instance parameters.
=cut
sub print_guest_params {
my $self = shift;
$self->reveal_myself;
diag("The guest instance $self->{guest_name} created is as below:");
foreach (keys %{$self}) {
if (defined $self->{$_}) {
if (ref($self->{$_}) eq 'HASH') {
diag $_ . ' => ' . Dumper(\%{$self->{$_}});
}
elsif (ref($self->{$_}) eq 'ARRAY') {
diag $_ . ' => ' . @{$self->{$_}};
}
else {
diag $_ . ' => ' . $self->{$_};
}
}
else {
diag $_ . ' => ' . 'undef';
}
}
return $self;
}
=head2 prepare_common_environment
prepare_common_environment($self)
Install necessary packages, patterns, setup ssh config, create [common_log_folder].
These are common environment affairs which will be used for all guest instances.
=cut
sub prepare_common_environment {
my $self = shift;
$self->reveal_myself;
if ($common_environment_prepared eq 'false') {
$self->clean_up_all_guests;
disable_and_stop_service('named.service', ignore_failure => 1);
script_run("rm -f -r $common_log_folder");
assert_script_run("mkdir -p $common_log_folder");
my @stuff_to_backup = ('/root/.ssh/config', '/etc/ssh/ssh_config', '/etc/hosts');
virt_autotest::utils::backup_file(\@stuff_to_backup);
script_run("rm -f -r /root/.ssh/config");
virt_autotest::utils::setup_common_ssh_config('/root/.ssh/config');
script_run("[ -f /etc/ssh/ssh_config ] && sed -i -r -n \'s/^.*IdentityFile.*\$/#&/\' /etc/ssh/ssh_config");
enable_debug_logging;
$guest_installation_and_configuration_metadata::host_params{host_sutip} = get_required_var('SUT_IP');
my $_default_route = script_output("ip route show default | grep -i dhcp | grep -vE br[[:digit:]]+", proceed_on_failure => 1);
my $_default_device = (!$_default_route) ? 'br0' : (split(' ', script_output("ip route show default | grep -i dhcp | grep -vE br[[:digit:]]+ | head -1")))[4];
$guest_installation_and_configuration_metadata::host_params{host_ipaddr} = (split('/', (split(' ', script_output("ip addr show dev $_default_device | grep \"inet \"")))[1]))[0];
$guest_installation_and_configuration_metadata::host_params{host_name} = script_output("hostname");
# For SUTs with multiple interfaces, `dnsdomainname` sometimes does not work
$guest_installation_and_configuration_metadata::host_params{host_domain_name} = script_output("dnsdomainname", proceed_on_failure => 1);
($guest_installation_and_configuration_metadata::host_params{host_version_major},
$guest_installation_and_configuration_metadata::host_params{host_version_minor},
$guest_installation_and_configuration_metadata::host_params{host_version_id}) = get_os_release;
record_info("Host running $guest_installation_and_configuration_metadata::host_params{host_version_id} "
. "with version major $guest_installation_and_configuration_metadata::host_params{host_version_major} "
. "minor $guest_installation_and_configuration_metadata::host_params{host_version_minor}", script_output("cat /etc/os-release"));
$self->prepare_ssh_key;
$self->prepare_non_transactional_environment;
$common_environment_prepared = 'true';
diag("Common environment preparation is done now.");
}
else {
diag("Common environment preparation had already been done.");
}
return $self;
}
=head2 prepare_ssh_key
prepare_ssh_key($self)
Prepare ssh key [ssh_public_key] and [ssh_private_key] for passwordless ssh login
from host to guest. [ssh_command] stores options and username to be used with ssh
login.
=cut
sub prepare_ssh_key {
my $self = shift;
$self->reveal_myself;
if (!((script_run("[[ -f /root/.ssh/id_rsa.pub ]] && [[ -f /root/.ssh/id_rsa.pub.bak ]]") == 0) and (script_run("cmp /root/.ssh/id_rsa.pub /root/.ssh/id_rsa.pub.bak") == 0))) {
assert_script_run("rm -f -r /root/.ssh/id_rsa*");
assert_script_run("ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -P \"\" <<<y");
assert_script_run("cp /root/.ssh/id_rsa.pub /root/.ssh/id_rsa.pub.bak");
}
$guest_installation_and_configuration_metadata::host_params{ssh_public_key} = script_output("cat /root/.ssh/id_rsa.pub");
$guest_installation_and_configuration_metadata::host_params{ssh_private_key} = script_output("cat /root/.ssh/id_rsa");
$guest_installation_and_configuration_metadata::host_params{ssh_command} = "ssh -vvv -o HostKeyAlgorithms=+ssh-rsa ";
if ($guest_installation_and_configuration_metadata::host_params{host_version_id} eq 'sles' and
is_sle("<=15-sp5", "$guest_installation_and_configuration_metadata::host_params{host_version_major}-SP$guest_installation_and_configuration_metadata::host_params{host_version_minor}")) {
$guest_installation_and_configuration_metadata::host_params{ssh_command} .= "-o PubkeyAcceptedKeyTypes=+ssh-rsa ";
}
else {
$guest_installation_and_configuration_metadata::host_params{ssh_command} .= "-o PubkeyAcceptedAlgorithms=+ssh-rsa ";
}
$guest_installation_and_configuration_metadata::host_params{ssh_command} .= "-i /root/.ssh/id_rsa root";
return $self;
}
=head2 prepare_non_transactional_environment
prepare_non_transactional_environment($self)
Do preparation on non-transactional server.
=cut
sub prepare_non_transactional_environment {
my $self = shift;
$self->reveal_myself;
if (!is_transactional) {
virt_autotest::utils::setup_rsyslog_host($common_log_folder) if (is_sle('<16'));
my $_packages_to_check = 'wget curl screen dnsmasq xmlstarlet python3 nmap';
$_packages_to_check .= ' yast2-schema' if (is_sle('<16'));
zypper_call("install -y $_packages_to_check");
# There is already the highest version for kvm/xen packages on TW
if (is_sle) {
my $_patterns_to_check = is_sle('<16') ? "$self->{host_virt_type}_server $self->{host_virt_type}_tools" : "$self->{host_virt_type}_host";
zypper_call("install -y -t pattern $_patterns_to_check");
}
}
return $self;
}
=head2 clean_up_all_guests
clean_up_all_guests($self)
Remove all existing guests and affecting storage files.
=cut
sub clean_up_all_guests {
my $self = shift;
$self->reveal_myself;
my @_guests_to_clean_up = split(/\n/, script_output("virsh list --all --name | grep -v Domain-0", proceed_on_failure => 1));
# Clean up all guests
if (scalar(@_guests_to_clean_up) gt 0) {
diag("Going to clean up all guests on $guest_installation_and_configuration_metadata::host_params{host_name}");
foreach (@_guests_to_clean_up) {
script_run("virsh destroy $_");
script_run("virsh undefine $_ --nvram") if (script_run("virsh undefine $_") ne 0);
}
save_screenshot;
record_info("Cleaned all existing vms.");
}
else {
diag("No guests reside on this host $guest_installation_and_configuration_metadata::host_params{host_name}");
}
# Clean up all guest images
foreach (split(/,/, get_required_var('UNIFIED_GUEST_LIST'))) {
script_run("rm -f -r /var/lib/libvirt/images/$self->{guest_name}.*");
script_run("rm -f -r /var/lib/libvirt/images/$self->{guest_name}");
}
save_screenshot;
record_info("Cleaned all potential affecting disk files.");
return $self;
}
=head2 prepare_guest_environment
prepare_guest_environment($self)
Create individual guest log folder using its name and remove existing entry in /etc/hosts.
=cut
sub prepare_guest_environment {
my $self = shift;
$self->reveal_myself;
$self->{guest_image_folder} = '/var/lib/libvirt/images/' . $self->{guest_name};
$self->{guest_log_folder} = $common_log_folder . '/' . $self->{guest_name};
script_run("rm -f -r $self->{guest_image_folder} $self->{guest_log_folder}");
assert_script_run("mkdir -p $self->{guest_image_folder} $self->{guest_log_folder}");
script_run("sed -i -r \'/^.*$self->{guest_name}.*\$/d\' /etc/hosts");
return $self;
}
=head2 config_guest_name
config_guest_name($self, @_)
Configure [guest_domain_name] and [guest_name_options].User can still change
[guest_name] and [guest_domain_name] by passing non-empty arguments using hash.
=cut
sub config_guest_name {
my $self = shift;
$self->reveal_myself;
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_installation_result} eq '') {
$self->{guest_domain_name} = 'testvirt.net' if ($self->{guest_domain_name} eq '');
if ($self->{guest_network_type} eq 'bridge' and $self->{guest_network_mode} eq 'host') {
$self->{guest_domain_name} = $guest_installation_and_configuration_metadata::host_params{host_domain_name};
}
$self->{guest_name_options} = "--name $self->{guest_name}";
}
return $self;
}
=head2 config_guest_metadata
config_guest_metadata($self[, guest_metadata => 'metadata'])
Configure [guest_metadata_options]. User can still change [guest_metadata] by
assing non-empty arguments using hash. If installation already passes,
modify_guest_params will be called to modify [guest_metadata] using already
modified [guest_metadata_options].
=cut
sub config_guest_metadata {
my $self = shift;
$self->reveal_myself;
my $_current_metadata_options = $self->{guest_metadata_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_metadata} ne '') {
$self->{guest_metadata_options} = "--metadata $self->{guest_metadata}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_metadata_options ne $self->{guest_metadata_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_metadata_options');
}
}
return $self;
}
=head2 config_guest_vcpus
config_guest_vcpus($self[, guest_vcpus => 'vcpus'])
Configure [guest_vcpus_options].User can still change [guest_vcpus] by passing
non-empty arguments using hash. If installations already passes,modify_guest_params
will be called to modify [guest_vcpus] using already modified [guest_vcpus_options].
=cut
sub config_guest_vcpus {
my $self = shift;
$self->reveal_myself;
my $_current_vcpus_options = $self->{guest_vcpus_options};
my $_current_cpumodel_options = $self->{guest_cpumodel_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_vcpus} = 2 if ($self->{guest_vcpus} eq '');
$self->{guest_vcpus_options} = "--vcpus $self->{guest_vcpus}";
$self->{guest_cpumodel_options} = "--cpu $self->{guest_cpumodel}" if ($self->{guest_cpumodel} ne '');
if ($self->{guest_installation_result} eq 'PASSED') {
$self->modify_guest_params($self->{guest_name}, 'guest_vcpus_options') if ($_current_vcpus_options ne $self->{guest_vcpus_options});
$self->modify_guest_params($self->{guest_name}, 'guest_cpumodel_options') if ($_current_cpumodel_options ne $self->{guest_cpumodel_options});
}
return $self;
}
=head2 config_guest_memory
config_guest_memory($self[, guest_memory => 'memory'])
Configure [guest_memory_options]. User can still change [guest_memory],
[guest_memballoon], [guest_memdev], [guest_memtune] and [guest_memorybacking] by
passing non-empty arguments using hash. If installation already passes,
modify_guest_params will be called to modify [guest_memory], [guest_memballoon],
[guest_memdev], [guest_memtune] and [guest_memorybacking] using already modified
[guest_memory_options].
=cut
sub config_guest_memory {
my $self = shift;
$self->reveal_myself;
my $_current_memory_options = $self->{guest_memory_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_memory} = 2048 if ($self->{guest_memory} eq '');
$self->{guest_memory_options} = "--memory $self->{guest_memory}";
$self->{guest_memory_options} .= " --memballoon $self->{guest_memballoon}" if ($self->{guest_memballoon} ne '');
$self->{guest_memory_options} .= " --memdev $self->{guest_memdev}" if ($self->{guest_memdev} ne '');
$self->{guest_memory_options} .= " --memtune $self->{guest_memtune}" if ($self->{guest_memtune} ne '');
$self->{guest_memory_options} .= " --memorybacking $self->{guest_memorybacking}" if ($self->{guest_memorybacking} ne '');
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_memory_options ne $self->{guest_memory_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_memory_options');
}
return $self;
}
=head2 config_guest_virtualization
config_guest_virtualization($self[, host_hypervisor_uri => 'uri', host_virt_type => 'type'])
Configure [guest_virt_options].User can still change [host_hypervisor_uri],
[host_virt_type] and [guest_virt_options] by passing non-empty arguments using
hash.
=cut
sub config_guest_virtualization {
my $self = shift;
$self->reveal_myself;
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_installation_result} eq '') {
$self->{guest_virt_options} = "--connect $self->{host_hypervisor_uri} " if ($self->{host_hypervisor_uri} ne '');
if ($self->{host_virt_type} eq '') {
$self->{host_virt_type} = 'kvm';
$self->{host_virt_type} = 'xen' if (script_output("journalctl -b | grep -i \"Hypervisor detected.*Xen\"", proceed_on_failure => 1) ne '');
}
$self->{guest_virt_options} = $self->{guest_virt_options} . "--virt-type $self->{host_virt_type} ";
$self->{guest_virt_type} = 'hvm' if ($self->{guest_virt_type} eq '');
$self->{guest_virt_options} = $self->{guest_virt_options} . "--$self->{guest_virt_type}";
}
return $self;
}
=head2 config_guest_platform
config_guest_platform($self[, guest_arch => 'arch', guest_machine_type => 'type'])
Configure [guest_platform_options].User can still change [guest_arch] and
[guest_machine_type] by passing non-empty arguments using hash.
=cut
sub config_guest_platform {
my $self = shift;
$self->reveal_myself;
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_installation_result} eq '') {
$self->{guest_platform_options} = "--arch $self->{guest_arch}" if ($self->{guest_arch} ne '');
$self->{guest_platform_options} = $self->{guest_platform_options} . " --machine $self->{guest_machine_type}" if ($self->{guest_machine_type} ne '');
}
return $self;
}
=head2 config_guest_os_variant
config_guest_os_variant($self[, guest_os_variant => 'os'])
Configure [guest_os_variant_options]. User can still change [guest_os_variant]
by passing non-empty arguments using hash. If installations already passes,
modify_guest_params will be called to modify [guest_os_variant] using already
modified [guest_os_variant_options].
=cut
sub config_guest_os_variant {
my $self = shift;
$self->reveal_myself;
my $_current_os_variant_options = $self->{guest_os_variant_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_os_variant} ne '') {
$self->{guest_os_variant_options} = "--os-variant $self->{guest_os_variant}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_os_variant_options ne $self->{guest_os_variant_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_os_variant_options');
}
}
return $self;
}
=head2 config_guest_graphics_and_video
config_guest_graphics_and_video($self[, guest_video => 'video', guest_graphics => 'graphics'])
Configure [guest_graphics_and_video_options]. User can still change [guest_video]
and [guest_graphics] by passing non-empty arguments using hash. If installations
already passes,modify_guest_params will be called to modify [guest_video] and
[guest_graphics] using already modified [guest_graphics_and_video_options].
=cut
sub config_guest_graphics_and_video {
my $self = shift;
$self->reveal_myself;
my $_current_graphics_and_video_options = $self->{guest_graphics_and_video_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_graphics_and_video_options} = ($self->{guest_video} eq '' ? '' : "--video $self->{guest_video}");
$self->{guest_graphics_and_video_options} = ($self->{guest_graphics} eq '' ? $self->{guest_graphics_and_video_options} : "$self->{guest_graphics_and_video_options} --graphics $self->{guest_graphics}");
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_graphics_and_video_options ne $self->{guest_graphics_and_video_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_graphics_and_video_options');
}
return $self;
}
=head2 config_guest_channels
config_guest_channels($self[, guest_channel => 'channel'])
Configure [guest_channel_options]. User can still change [guest_channel] by passing
non-empty arguments using hash. If installations already passes, modify_guest_params
will be called to modify [guest_channel] using already modified [guest_channel_options].
Multiple channels are allowd for a single guest, they should be passed in with hash
symbol '#' as separator, for example, 'type=unix#spicevmc'.
=cut
sub config_guest_channels {
my $self = shift;
$self->reveal_myself;
my $_current_channel_options = $self->{guest_channel_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_channel} ne '') {
foreach (split('#', $self->{guest_channel})) {
$self->{guest_channel_options} .= " --channel $_";
}
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_channel_options ne $self->{guest_channel_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_channel_options');
}
}
return $self;
}
=head2 config_guest_consoles
config_guest_consoles($self[, guest_console => 'console', guest_serial => 'serial'])
Configure [guest_console_options] and [guest_serial_options]. User can still
change [guest_console] and [guest_serial] by passing non-empty arguments using
hash. If installations already passes, modify_guest_params will be called to
modify [guest_console] and [guest_serial] using already modified [guest_console_options]
and [guest_serial_options].
=cut
sub config_guest_consoles {
my $self = shift;
$self->reveal_myself;
my $_current_console_options = $self->{guest_console_options};
my $_current_serial_options = $self->{guest_serial_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_console} ne '') {
$self->{guest_console_options} = "--console $self->{guest_console}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_console_options ne $self->{guest_console_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_console_options');
}
}
if ($self->{guest_serial} ne '') {
$self->{guest_serial_options} = "--serial $self->{guest_serial}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_serial_options ne $self->{guest_serial_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_serial_options');
}
}
return $self;
}
=head2 config_guest_features
config_guest_features($self[, guest_features => 'features'])
Configure [guest_features_options]. User can still change [guest_features] by
passing non-empty arguments using hash. If installations already passes,
modify_guest_params will be called to modify [guest_features] using already
modified [guest_features_options].
=cut
sub config_guest_features {
my $self = shift;
$self->reveal_myself;
my $_current_features_options = $self->{guest_features_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_features} ne '') {
$self->{guest_features_options} = "--features $self->{guest_features}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_features_options = $self->{guest_features_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_features_options');
}
}
return $self;
}
=head2 config_guest_events
config_guest_events($self[, guest_events => 'events'])
Configure [guest_events_options]. User can still change [guest_events] by passing
non-empty arguments using hash. If installations already passes,modify_guest_params
will be called to modify [guest_events] using already modified [guest_events_options].
=cut
sub config_guest_events {
my $self = shift;
$self->reveal_myself;
my $_current_events_options = $self->{guest_events_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_events} ne '') {
$self->{guest_events_options} = "--events $self->{guest_events}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_events_options ne $self->{guest_events_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_events_options');
}
}
return $self;
}
=head2 config_guest_boot_settings
config_guest_boot_settings($self[, guest_boot_settings => 'settings'])
Configure [guest_boot_options]. User can still change [guest_boot_settings] by
passing non-empty arguments using hash. If installations already passes,
modify_guest_params will be called to modify [guest_boot_settings] using already
modified [guest_boot_options].
=cut
sub config_guest_boot_settings {
my $self = shift;
$self->reveal_myself;
my $_current_boot_options = $self->{guest_boot_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_boot_settings} ne '') {
$self->{guest_boot_options} = "--boot $self->{guest_boot_settings}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_boot_options ne $self->{guest_boot_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_boot_options');
}
}
return $self;
}
=head2 config_guest_power_management
config_guest_power_management($self[, guest_power_management => 'power'])
Configure [guest_power_management_options]. User can still change [guest_power_management]
by passing non-empty arguments using hash. If installations already passes,
modify_guest_params will be called to modify [guest_power_management] using already
modified [guest_power_management_options].
=cut
sub config_guest_power_management {
my $self = shift;
$self->reveal_myself;
my $_current_power_management_options = $self->{guest_power_management_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_power_management} ne '') {
$self->{guest_power_management_options} = "--pm $self->{guest_power_management}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_power_management_options ne $self->{guest_power_management_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_power_management_options');
}
}
return $self;
}
=head2 config_guest_xpath
config_guest_xpath($self[, guest_xpath => 'xpath'])
Configure [guest_xpath_options]. User can still change [guest_xpath] by passing
non-empty arguments using hash. If installations already passes, modify_guest_params
will be called to modify [guest_xpath] using already modified [guest_xpath_options].
=cut
sub config_guest_xpath {
my $self = shift;
$self->reveal_myself;
my $_current_xpath_options = $self->{guest_xpath_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_xpath} ne '') {
my @_guest_xpath = split(/#/, $self->{guest_xpath});
$self->{guest_xpath_options} = $self->{guest_xpath_options} . "--xml $_ " foreach (@_guest_xpath);
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_xpath_options ne $self->{guest_xpath_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_xpath_options');
}
}
return $self;
}
=head2 config_guest_qemu_command
config_guest_qemu_command($self[, guest_qemu_command => 'command'])
Configure [guest_qemu_command_options]. User can still change [guest_qemu_command]
by passing non-empty arguments using hash. If installations already passes,
modify_guest_params will be called to modify [guest_qemu_command] using already
modified [guest_qemu_command_options].
=cut
sub config_guest_qemu_command {
my $self = shift;
$self->reveal_myself;
my $_current_qemu_command_options = $self->{guest_qemu_command_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_qemu_command} ne '') {
$self->{guest_qemu_command_options} = "--qemu-commandline $self->{guest_qemu_command}";
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_qemu_command_options ne $self->{guest_qemu_command_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_qemu_command_options');
}
}
return $self;
}
=head2 config_guest_security
config_guest_security($self [, guest_seclabel => 'seclabel'] [, guest_launchsecurity => 'launchsecurity'])
Configure [guest_security_options]. User can still change [guest_security] and
[guest_launchsecurity] by passing non-empty arguments using hash. If installation
already passes, modify_guest_params will be called to modify guest_security] and
[guest_launchsecurity] using already modified [guest_security_options].
=cut
sub config_guest_security {
my $self = shift;
$self->reveal_myself;
my $_current_security_options = $self->{guest_security_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_security_options} = "--seclabel $self->{guest_seclabel}" if ($self->{guest_seclabel} ne '');
$self->{guest_security_options} .= " --launchSecurity $self->{guest_launchsecurity}" if ($self->{guest_launchsecurity} ne '');
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_security_options ne $self->{guest_security_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_security_options');
}
return $self;
}
=head2 config_guest_controller
config_guest_controller($self [, guest_controller => 'controller'])
Configure [guest_controller_options]. User can still change [guest_controller] by
passing non-empty arguments using hash. [guest_controller] can have more than one
type controller which should be separated by hash symbol, for example, 'controller1
_config#controller2_config#controller3_config'. Then it will be splitted and
passed to individual '--controller' argument to form [guest_controller_options]
= '--controller controller1_config --controller controller2_config --controller
controller3_config'. If installation already passes, modify_guest_params will be
called to modify [guest_controller] using already modified [guest_controller_options].
=cut
sub config_guest_controller {
my $self = shift;
$self->reveal_myself;
my $_current_controller_options = $self->{guest_controller_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_controller} ne '') {
my @_guest_controller = split(/#/, $self->{guest_controller});
$self->{guest_controller_options} = $self->{guest_controller_options} . "--controller $_ " foreach (@_guest_controller);
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_controller_options ne $self->{guest_controller_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_controller_options');
}
}
return $self;
}
=head2 config_guest_tpm
config_guest_tpm($self [, guest_tpm => 'tpm'])
Configure [guest_tpm_options]. User can still change [guest_tpm] by passing
non-empty arguments using hash. If installations already passes, modify_guest_params
will be called to modify [guest_tpm] using already modified [guest_tpm_options].
=cut
sub config_guest_tpm {
my $self = shift;
$self->reveal_myself;
my $_current_tpm_options = $self->{guest_tpm_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_tpm_options} = "--tpm $self->{guest_tpm}" if ($self->{guest_tpm} ne '');
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_tpm_options ne $self->{guest_tpm_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_tpm_options');
}
return $self;
}
=head2 config_guest_rng
config_guest_rng($self [, guest_rng => 'rng'])
Configure [guest_rng_options]. User can still change [guest_rng] by passing
non-empty arguments using hash. If installations already passes, modify_guest_params
will be called to modify [guest_rng] using already modified [guest_rng_options].
=cut
sub config_guest_rng {
my $self = shift;
$self->reveal_myself;
my $_current_rng_options = $self->{guest_rng_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_rng_options} = "--rng $self->{guest_rng}" if ($self->{guest_rng} ne '');
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_rng_options ne $self->{guest_rng_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_rng_options');
}
return $self;
}
=head2 config_guest_sysinfo
config_guest_sysinfo($self[, guest_sysinfo => 'sysinfo'])
Configure [guest_sysinfo_options]. User can still change [guest_sysinfo] by passing
non-empty arguments using hash. Multiple sysinfos are allowd for a single guest,
they should be passed in with hash symbol '#' as separator, for example, 'sysinfo1#
sysinfo2'. If installation already passes, modify_guest_params will be called to
modify [guest_sysinfo] using already modified [guest_sysinfo_options].
=cut
sub config_guest_sysinfo {
my $self = shift;
$self->reveal_myself;
my $_current_sysinfo_options = $self->{guest_sysinfo_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
if ($self->{guest_sysinfo} ne '') {
foreach (split('#', $self->{guest_sysinfo})) {
$self->{guest_sysinfo_options} .= " --sysinfo $_";
}
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_sysinfo_options ne $self->{guest_sysinfo_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_sysinfo_options');
}
}
return $self;
}
=head2 config_guest_storage
config_guest_rng($self [, key-value pairs of guest storage arguments])
Configure [guest_storage_options]. User can still change [guest_storage_type],
[guest_storage_size], [guest_storage_format], [guest_storage_label], [guest_storage_path]
and [guest_storage_others] by passing non-empty arguments using hash. If installations
already passes, modify_guest_params will be called to modify [guest_storage_type],
[guest_storage_size], [guest_storage_format], [guest_storage_path] and
[guest_storage_others] using already modified [guest_storage_options].
=cut
sub config_guest_storage {
my $self = shift;
$self->reveal_myself;
my $_current_storage_options = $self->{guest_storage_options};
$self->config_guest_params(@_) if (scalar(@_) gt 0);
$self->{guest_storage_size} = '16' if ($self->{guest_storage_size} eq '');
$self->{guest_storage_format} = 'qcow2' if ($self->{guest_storage_format} eq '');
$self->{guest_storage_label} = 'gpt' if ($self->{guest_storage_label} eq '');
if ($self->{guest_storage_path} eq '') {
$self->{guest_storage_path} = "$self->{guest_image_folder}/$self->{guest_name}.$self->{guest_storage_format}";
}
else {
$self->{guest_storage_path} = "$self->{guest_storage_path}/$self->{guest_name}.$self->{guest_storage_format}";
}
if ($self->{guest_storage_type} eq 'disk') {
if ($self->{guest_installation_method} eq 'location') {
$self->{guest_storage_options} = "--disk path=$self->{guest_storage_path},size=$self->{guest_storage_size},format=$self->{guest_storage_format}";
}
elsif ($self->{guest_installation_method} eq 'import') {
if ($self->{guest_storage_backing_path} eq '') {
$self->{guest_storage_backing_path} = "$self->{guest_image_folder}/$self->{guest_name}_" . (split('/', $self->{guest_installation_media}))[-1];
}
$self->{guest_storage_backing_path} =~ s/12345/$self->{guest_build}/g if ($self->{guest_build} ne 'gm');
$self->{guest_storage_backing_path} =~ s/\.xz$//i;
$self->{guest_storage_backing_path} =~ /\.([\w]{1,})$/i;
$self->{guest_storage_backing_format} = $1;
$self->{guest_storage_options} = "--disk type=file,device=disk,source.file=$self->{guest_storage_path},size=$self->{guest_storage_size},format=$self->{guest_storage_format},driver.type=$self->{guest_storage_format}";
$self->{guest_storage_options} = $self->{guest_storage_options} . ",backing_store=$self->{guest_storage_backing_path},backing_format=$self->{guest_storage_backing_format}";
$self->{guest_storage_options} = $self->{guest_storage_options} . ",target.dev=vda,target.bus=virtio";
}
}
$self->{guest_storage_options} = $self->{guest_storage_options} . ",$self->{guest_storage_others}" if ($self->{guest_storage_others} ne '');
if (($self->{guest_installation_result} eq 'PASSED') and ($_current_storage_options = $self->{guest_storage_options})) {
$self->modify_guest_params($self->{guest_name}, 'guest_storage_options');
}