77 "context"
88 "os"
99 "path/filepath"
10+ "strings"
1011 "testing"
1112 "time"
1213
@@ -76,6 +77,7 @@ func TestWindowsGuestAgentIntegration(t *testing.T) {
7677
7778 dialer , err := manager .GetVsockDialer (ctx , instance .Id )
7879 require .NoError (t , err )
80+ upgradeWindowsGuestAgent (t , ctx , dialer )
7981
8082 var stdout , stderr bytes.Buffer
8183 jobStart := time .Now ()
@@ -168,14 +170,6 @@ public static class DesktopIdentity {
168170 require .Equal (t , 0 , exit .Code )
169171 assert .Equal (t , `WinSta0\Default` , stdout .String ())
170172
171- _ , err = guest .ExecIntoInstance (ctx , dialer , guest.ExecOptions {
172- Command : []string {"cmd.exe" },
173- TTY : true ,
174- Session : guest .ExecSession_EXEC_SESSION_DESKTOP ,
175- Timeout : 30 ,
176- })
177- assert .ErrorContains (t , err , "desktop ConPTY sessions are not supported" )
178-
179173 source := filepath .Join (t .TempDir (), "roundtrip.txt" )
180174 require .NoError (t , os .WriteFile (source , []byte ("HYPEMAN_COPY_OK" ), 0644 ))
181175 require .NoError (t , guest .CopyToInstance (ctx , dialer , guest.CopyToInstanceOptions {
@@ -191,3 +185,40 @@ public static class DesktopIdentity {
191185 require .NoError (t , err )
192186 assert .Equal (t , "HYPEMAN_COPY_OK" , string (contents ))
193187}
188+
189+ func upgradeWindowsGuestAgent (t * testing.T , ctx context.Context , dialer hypervisor.VsockDialer ) {
190+ t .Helper ()
191+
192+ source := filepath .Join (".." , "system" , "guest_agent" , "hypeman-guest-agent.exe" )
193+ require .FileExists (t , source )
194+ const destination = `C:\ProgramData\Hypeman\hypeman-guest-agent-current.exe`
195+ require .NoError (t , guest .CopyToInstance (ctx , dialer , guest.CopyToInstanceOptions {
196+ SrcPath : source ,
197+ DstPath : destination ,
198+ }))
199+
200+ var stderr bytes.Buffer
201+ exit , err := guest .ExecIntoInstance (ctx , dialer , guest.ExecOptions {
202+ Command : []string {"sc.exe" , "config" , "HypemanGuestAgent" , "binPath=" , destination },
203+ Stderr : & stderr ,
204+ Timeout : 15 ,
205+ })
206+ require .NoError (t , err , stderr .String ())
207+ require .Equal (t , 0 , exit .Code , stderr .String ())
208+
209+ const restartScript = `$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -NonInteractive -Command "Start-Sleep -Milliseconds 500; Restart-Service -Name HypemanGuestAgent -Force"'; Register-ScheduledTask -TaskName HypemanGuestAgentUpgrade -Action $action -User SYSTEM -RunLevel Highest -Force | Out-Null; Start-ScheduledTask -TaskName HypemanGuestAgentUpgrade`
210+ _ , _ = guest .ExecIntoInstance (ctx , dialer , guest.ExecOptions {
211+ Command : []string {"powershell.exe" , "-NoProfile" , "-NonInteractive" , "-Command" , restartScript },
212+ Timeout : 15 ,
213+ })
214+
215+ require .Eventually (t , func () bool {
216+ _ , err := guest .ExecIntoInstance (ctx , dialer , guest.ExecOptions {
217+ Command : []string {"cmd.exe" , "/d" , "/c" , "exit" , "0" },
218+ TTY : true ,
219+ Session : guest .ExecSession_EXEC_SESSION_DESKTOP ,
220+ Timeout : 5 ,
221+ })
222+ return err != nil && strings .Contains (err .Error (), "desktop ConPTY sessions are not supported" )
223+ }, 20 * time .Second , 250 * time .Millisecond , "updated Windows guest agent did not become ready" )
224+ }
0 commit comments