1
1
import logging
2
+ import os
2
3
import pytest
4
+ import time
5
+
6
+ from lib import commands , pxe
7
+ from lib .common import wait_for
8
+ from lib .host import Host
9
+ from lib .pool import Pool
3
10
4
11
class TestInstallNested :
5
12
@pytest .mark .vm_definitions (
@@ -21,5 +28,142 @@ def test_install_nested_821_uefi(self, iso_remaster, create_vms):
21
28
assert len (create_vms ) == 1
22
29
host_vm = create_vms [0 ]
23
30
31
+ vif = host_vm .vifs ()[0 ]
32
+ mac_address = vif .param_get ('MAC' )
33
+ logging .info ("Host VM has MAC %s" , mac_address )
34
+
24
35
host_vm .create_cd_vbd (device = "xvdd" , userdevice = "3" )
25
36
host_vm .insert_cd (iso_remaster )
37
+
38
+ try :
39
+ host_vm .start ()
40
+ wait_for (host_vm .is_running , "Wait for host VM running" )
41
+
42
+ # catch host-vm IP address
43
+ wait_for (lambda : pxe .arp_addresses_for (mac_address ),
44
+ "Wait for DHCP server to see Host VM in ARP tables" ,
45
+ timeout_secs = 10 * 60 )
46
+ ips = pxe .arp_addresses_for (mac_address )
47
+ logging .info ("Host VM has IPs %s" , ips )
48
+ assert len (ips ) == 1
49
+ host_vm .ip = ips [0 ]
50
+
51
+ host_vm .ssh (["ls" ])
52
+ logging .debug ("ssh works" )
53
+
54
+ # wait for "yum install" phase to finish
55
+ wait_for (lambda : host_vm .ssh (["grep" ,
56
+ "'DISPATCH: NEW PHASE: Completing installation'" ,
57
+ "/tmp/install-log" ],
58
+ check = False , simple_output = False ,
59
+ ).returncode == 0 ,
60
+ "Wait for rpm installation to succeed" ,
61
+ timeout_secs = 40 * 60 ) # FIXME too big
62
+
63
+ # wait for install to finish
64
+ wait_for (lambda : host_vm .ssh (["grep" ,
65
+ "'The installation completed successfully'" ,
66
+ "/tmp/install-log" ],
67
+ check = False , simple_output = False ,
68
+ ).returncode == 0 ,
69
+ "Wait for installation to succeed" ,
70
+ timeout_secs = 40 * 60 ) # FIXME too big
71
+
72
+ # powercycle, catch any change of IP
73
+ logging .info ("Rebooting Host VM after successful installation" )
74
+ try :
75
+ # use "poweroff" because "reboot" would cause ARP and
76
+ # SSH to be checked before host is down, and require
77
+ # ssh retries
78
+ host_vm .ssh (["poweroff" ])
79
+ except commands .SSHCommandFailed as e :
80
+ # ignore connection closed by reboot
81
+ if e .returncode == 255 and "closed by remote host" in e .stdout :
82
+ logging .info ("sshd closed the connection" )
83
+ pass
84
+ else :
85
+ raise
86
+ wait_for (host_vm .is_halted , "Wait for host VM halted" )
87
+ host_vm .eject_cd ()
88
+
89
+ # FIXME: make a snapshot here
90
+
91
+ # FIXME: evict MAC from ARP cache first?
92
+ host_vm .start ()
93
+ wait_for (host_vm .is_running , "Wait for host VM running" )
94
+
95
+ ips = pxe .arp_addresses_for (mac_address )
96
+ logging .info ("Host VM has IPs %s" , ips )
97
+ assert len (ips ) == 1
98
+ host_vm .ip = ips [0 ]
99
+
100
+ wait_for (lambda : not os .system (f"nc -zw5 { host_vm .ip } 22" ),
101
+ "Wait for ssh back up on Host VM" , retry_delay_secs = 5 )
102
+
103
+ # pool master must be reachable here
104
+ # FIXME: not sure why we seem to need this, while port 22 has been seen open
105
+ tries = 5
106
+ while True :
107
+ try :
108
+ pool = Pool (host_vm .ip )
109
+ except commands .SSHCommandFailed as e :
110
+ if "Connection refused" not in e .stdout :
111
+ raise
112
+ tries -= 1
113
+ if tries :
114
+ logging .warning ("retrying connection to pool master" )
115
+ time .sleep (2 )
116
+ continue
117
+ # retries failed
118
+ raise
119
+ # it worked!
120
+ break
121
+
122
+ # wait for XAPI
123
+ # FIXME: flaky, must check logs extraction on failure
124
+ for service in ["control-domain-params-init" ,
125
+ "network-init" ,
126
+ "storage-init" ,
127
+ "generate-iscsi-iqn" ,
128
+ "create-guest-templates" ,
129
+ ]:
130
+ try :
131
+ wait_for (lambda : pool .master .ssh (["test" , "-e" , f"/var/lib/misc/ran-{ service } " ],
132
+ check = False , simple_output = False ,
133
+ ).returncode == 0 ,
134
+ f"Wait for ran-{ service } stamp" )
135
+ except TimeoutError :
136
+ logging .warning ("investigating lack of ran-{service} stamp" )
137
+ out = pool .master .ssh (["systemctl" , "status" , service ], check = False )
138
+ logging .warning ("service status: %s" , out )
139
+ out = pool .master .ssh (["grep" , "-r" , service , "/var/log" ], check = False )
140
+ logging .warning ("in logs: %s" , out )
141
+
142
+ wait_for (pool .master .is_enabled , "Wait for XAPI to be ready" , timeout_secs = 30 * 60 )
143
+
144
+ logging .info ("Powering off pool master" )
145
+ try :
146
+ # use "poweroff" because "reboot" would cause ARP and
147
+ # SSH to be checked before host is down, and require
148
+ # ssh retries
149
+ pool .master .ssh (["poweroff" ])
150
+ except commands .SSHCommandFailed as e :
151
+ # ignore connection closed by reboot
152
+ if e .returncode == 255 and "closed by remote host" in e .stdout :
153
+ logging .info ("sshd closed the connection" )
154
+ pass
155
+ else :
156
+ raise
157
+
158
+ wait_for (host_vm .is_halted , "Wait for host VM halted" )
159
+
160
+ except Exception as e :
161
+ logging .critical ("caught exception %s" , e )
162
+ # wait_for(lambda: False, 'Wait "forever"', timeout_secs=100*60)
163
+ host_vm .shutdown (force = True )
164
+ raise
165
+ except KeyboardInterrupt :
166
+ logging .warning ("keyboard interrupt" )
167
+ # wait_for(lambda: False, 'Wait "forever"', timeout_secs=100*60)
168
+ host_vm .shutdown (force = True )
169
+ raise
0 commit comments