Skip to content

Commit 0e13d0f

Browse files
committed
Run Windows guest tests against current agent
1 parent 95cf15f commit 0e13d0f

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
135135
- name: Test Windows guest control
136136
run: |
137-
make build-embedded
137+
make build-embedded build-windows-guest-agent
138138
TEST_PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
139139
for attempt in 1 2 3; do
140140
if sudo env \

‎lib/instances/windows_guest_agent_integration_linux_test.go‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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

Comments
 (0)