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