-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SQL Power Plan and Remote Connectivity Tests (#798)
* Add power plan and remote auth tests for SQL WIP: Investigating an issue with converting the file output * Change error approach on server db query Fixes unused variable issue doing it the other way * Switching test approach Easier to run/debug * Update to use return from script instead of metadata Much simpler * Update result logic Had it backwards at first
- Loading branch information
Showing
4 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,94 @@ | ||
package sql | ||
|
||
import ( | ||
"embed" | ||
|
||
"github.com/GoogleCloudPlatform/guest-test-infra/imagetest" | ||
) | ||
|
||
// Name is the name of the test package. It must match the directory name. | ||
var Name = "sql" | ||
|
||
// InstanceConfig for setting up test VMs. | ||
type InstanceConfig struct { | ||
name string | ||
ip string | ||
} | ||
|
||
var serverConfig = InstanceConfig{name: "server-vm", ip: "192.168.0.10"} | ||
var clientConfig = InstanceConfig{name: "client-vm", ip: "192.168.0.11"} | ||
|
||
//go:embed * | ||
var scripts embed.FS | ||
|
||
const ( | ||
serverStartupScriptURL = "startupscripts/remote_auth_server_setup.ps1" | ||
clientStartupScriptURL = "startupscripts/remote_auth_client_setup.ps1" | ||
) | ||
|
||
// TestSetup sets up the test workflow. | ||
func TestSetup(t *imagetest.TestWorkflow) error { | ||
vm, err := t.CreateTestVM("vm") | ||
defaultNetwork, err := t.CreateNetwork("default-network", false) | ||
if err != nil { | ||
return err | ||
} | ||
defaultSubnetwork, err := defaultNetwork.CreateSubnetwork("default-subnetwork", "192.168.0.0/24") | ||
if err != nil { | ||
return err | ||
} | ||
if err := defaultNetwork.CreateFirewallRule("allow-sql-tcp", "tcp", []string{"135", "1433", "1434", "4022", "5022"}, []string{"192.168.0.0/24"}); err != nil { | ||
return err | ||
} | ||
if err := defaultNetwork.CreateFirewallRule("allow-sql-udp", "udp", []string{"1434"}, []string{"192.168.0.0/24"}); err != nil { | ||
return err | ||
} | ||
|
||
// Get the startup scripts as byte arrays. | ||
serverStartupByteArr, err := scripts.ReadFile(serverStartupScriptURL) | ||
if err != nil { | ||
return err | ||
} | ||
clientStartupByteArr, err := scripts.ReadFile(clientStartupScriptURL) | ||
if err != nil { | ||
return err | ||
} | ||
serverStartup := string(serverStartupByteArr) | ||
clientStartup := string(clientStartupByteArr) | ||
|
||
serverVM, err := t.CreateTestVM(serverConfig.name) | ||
if err != nil { | ||
return err | ||
} | ||
if err := serverVM.AddCustomNetwork(defaultNetwork, defaultSubnetwork); err != nil { | ||
return err | ||
} | ||
if err := serverVM.SetPrivateIP(defaultNetwork, serverConfig.ip); err != nil { | ||
return err | ||
} | ||
|
||
clientVM, err := t.CreateTestVM(clientConfig.name) | ||
if err != nil { | ||
return err | ||
} | ||
if err := clientVM.AddCustomNetwork(defaultNetwork, defaultSubnetwork); err != nil { | ||
return err | ||
} | ||
if err := clientVM.SetPrivateIP(defaultNetwork, clientConfig.ip); err != nil { | ||
return err | ||
} | ||
clientVM.AddMetadata("enable-guest-attributes", "TRUE") | ||
clientVM.AddMetadata("sqltarget", serverConfig.ip) | ||
|
||
serverVM.AddMetadata("windows-startup-script-ps1", serverStartup) | ||
clientVM.AddMetadata("windows-startup-script-ps1", clientStartup) | ||
|
||
vm1, err := t.CreateTestVM("vm1") | ||
if err != nil { | ||
return err | ||
} | ||
vm.RunTests("TestSqlVersion") | ||
vm1.RunTests("TestSqlVersion|TestPowerPlan") | ||
clientVM.RunTests("TestRemoteConnectivity") | ||
serverVM.RunTests("TestPowerPlan") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
imagetest/test_suites/sql/startupscripts/remote_auth_client_setup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
$sqlservice = Get-Service 'MSSQLSERVER' | ||
$sqlservice.WaitForStatus('Running', '00:10:00') | ||
Write-Host 'MSSQLSERVER is now running.' | ||
|
||
$cn = [ADSI]"WinNT://$env:COMPUTERNAME" | ||
$user = $cn.Create('User', 'SqlTests') | ||
$user.SetPassword('remoting@123') | ||
$user.SetInfo() | ||
$user.description = 'Admin user to install new software' | ||
$user.SetInfo() | ||
$group = [ADSI]"WinNT://$env:COMPUTERNAME/Administrators" | ||
$group.Add($user.Path) |
24 changes: 24 additions & 0 deletions
24
imagetest/test_suites/sql/startupscripts/remote_auth_server_setup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
$sqlservice = Get-Service 'MSSQLSERVER' | ||
$sqlservice.WaitForStatus('Running', '00:10:00') | ||
Write-Host 'MSSQLSERVER is now running.' | ||
|
||
$cn = [ADSI]"WinNT://$env:COMPUTERNAME" | ||
$user = $cn.Create('User', 'SqlTests') | ||
$user.SetPassword('remoting@123') | ||
$user.SetInfo() | ||
$user.description = 'Admin user to install new software' | ||
$user.SetInfo() | ||
$group = [ADSI]"WinNT://$env:COMPUTERNAME/Administrators" | ||
$group.Add($user.Path) | ||
|
||
$AUTH_SCRIPT = 'https://storage.googleapis.com/windows-utils/change_auth.sql' | ||
Invoke-WebRequest -Uri $AUTH_SCRIPT -OutFile c:\\change_auth.sql | ||
|
||
try { | ||
sqlcmd -S localhost -i c:\change_auth.sql | ||
} catch { | ||
Write-Host "Failed to set auth config: $_" | ||
} finally { | ||
Restart-Service MSSQLSERVER | ||
Write-Host "auth config updated" | ||
} |