Windows Manager
You can view the Javadoc documentation for the Manager.
Overview¶
The Windows Manager provides Galasa tests with access to Windows images. This Manager enables tests to connect to Windows systems, execute commands, access the file system, and manage Windows-based resources.
The Windows Manager provides provisioning capabilities for Windows images through either Developer Supplied Environment (DSE) provisioning or through cloud provisioners like OpenStack.
Annotations¶
The following annotations are available with the Windows Manager.
Windows Image¶
| Annotation: | Windows Image |
|---|---|
| Name: | @WindowsImage |
| Description: | The @WindowsImage annotation requests the Windows Manager to allocate a Windows image to the test. The test can then access the command shell and interact with the Windows system. |
Attribute: imageTag |
The imageTag is used to identify the Windows image to other Managers. If a test is using multiple Windows images, each separate Windows image must have a unique tag. Default is "PRIMARY". |
Attribute: capabilities |
The capabilities attribute specifies any required capabilities of the image, if any, in an array. |
| Syntax: | @WindowsImage(imageTag = "PRIMARY") |
| Notes: | The IWindowsImage interface gives the test access to the Windows image, including command shell access, file system paths, and credentials.See WindowsImage and IWindowsImage to find out more. |
Windows IP Host¶
| Annotation: | Windows IP Host |
|---|---|
| Name: | @WindowsIpHost |
| Description: | The @WindowsIpHost annotation represents an IP Host for a Windows image that has been provisioned for the test. |
Attribute: imageTag |
The imageTag should match the imageTag of the @WindowsImage this variable is to be populated with. |
| Syntax: | @WindowsIpHost(imageTag = "PRIMARY") |
| Notes: | The IIpHost interface gives the test access to the IPv4/6 address and port information for the Windows image.See WindowsIpHost and IIpHost to find out more. |
Code Snippets¶
Connect to a Windows image¶
@WindowsImage(imageTag = "PRIMARY")
public IWindowsImage windowsImage;
@Test
public void testWindowsConnection() throws Exception {
// Get the image ID
String imageId = windowsImage.getImageID();
logger.info("Connected to Windows image: " + imageId);
// Get the IP host
IIpHost ipHost = windowsImage.getIpHost();
logger.info("Windows host: " + ipHost.getHostname());
}
Execute commands on Windows¶
@WindowsImage(imageTag = "PRIMARY")
public IWindowsImage windowsImage;
@Test
public void testExecuteCommand() throws Exception {
ICommandShell shell = windowsImage.getCommandShell();
// Execute a simple command
String response = shell.issueCommand("echo Hello from Windows");
logger.info("Response: " + response);
// Execute a PowerShell command
String psResponse = shell.issueCommand("powershell -Command \"Get-Date\"");
logger.info("Current date: " + psResponse);
}
Access file system paths¶
@WindowsImage(imageTag = "PRIMARY")
public IWindowsImage windowsImage;
@Test
public void testFilePaths() throws Exception {
// Get standard Windows paths
Path root = windowsImage.getRoot(); // C:\
Path home = windowsImage.getHome(); // C:\Users\<user>
Path temp = windowsImage.getTmp(); // C:\Users\<user>\AppData\Local\Temp
Path runDir = windowsImage.getRunDirectory(); // Test-specific run directory
logger.info("Root: " + root);
logger.info("Home: " + home);
logger.info("Temp: " + temp);
logger.info("Run directory: " + runDir);
}
Get Windows credentials¶
@WindowsImage(imageTag = "PRIMARY")
public IWindowsImage windowsImage;
@Test
public void testCredentials() throws Exception {
ICredentials credentials = windowsImage.getDefaultCredentials();
if (credentials instanceof ICredentialsUsernamePassword) {
ICredentialsUsernamePassword userPass = (ICredentialsUsernamePassword) credentials;
String username = userPass.getUsername();
logger.info("Windows username: " + username);
}
}
Work with files¶
@WindowsImage(imageTag = "PRIMARY")
public IWindowsImage windowsImage;
@Test
public void testFileOperations() throws Exception {
ICommandShell shell = windowsImage.getCommandShell();
Path runDir = windowsImage.getRunDirectory();
// Create a file
Path testFile = runDir.resolve("test.txt");
shell.issueCommand("echo Test content > " + testFile.toString());
// Read the file
String content = shell.issueCommand("type " + testFile.toString());
logger.info("File content: " + content);
// Delete the file
shell.issueCommand("del " + testFile.toString());
}
Use multiple Windows images¶
@WindowsImage(imageTag = "PRIMARY")
public IWindowsImage primaryWindows;
@WindowsImage(imageTag = "SECONDARY")
public IWindowsImage secondaryWindows;
@Test
public void testMultipleImages() throws Exception {
// Execute command on primary
ICommandShell primaryShell = primaryWindows.getCommandShell();
String primaryResponse = primaryShell.issueCommand("hostname");
logger.info("Primary hostname: " + primaryResponse);
// Execute command on secondary
ICommandShell secondaryShell = secondaryWindows.getCommandShell();
String secondaryResponse = secondaryShell.issueCommand("hostname");
logger.info("Secondary hostname: " + secondaryResponse);
}