-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nocloud: enable network config testing #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ if ($ENV:TEST_ARCHITECTURE -eq "x86") { | |
$REG_KEY_FOLDER = $REG_KEY_WOW_FOLDER | ||
} | ||
$global:CLOUDBASE_INIT_REGISTRY_PATH = "HKLM:\SOFTWARE\${REG_KEY_FOLDER}Cloudbase Solutions\Cloudbase-Init\b9517879-4e93-4a1a-9073-4ae0ddfac27c\Plugins" | ||
|
||
$global:CLOUDBASE_INIT_NET_NAME = "cbs_init_eth0" | ||
$global:CLOUDBASE_INIT_NET_STATIC_IP = "10.196.59.2" | ||
|
||
function before.cloudbaseinit.plugins.common.mtu.MTUPlugin { | ||
# NOOP | ||
|
@@ -230,9 +231,24 @@ function after.cloudbaseinit.plugins.windows.winrmcertificateauth.ConfigWinRMCer | |
} | ||
function before.cloudbaseinit.plugins.common.networkconfig.NetworkConfigPlugin { | ||
|
||
It "a network adapter should not exist" { | ||
{ | ||
# if the functional test has been already run before, | ||
# we need to rename the net adapter name to a different name. | ||
Rename-NetAdapter -Name $global:CLOUDBASE_INIT_NET_NAME -NewName "not_cbs_init0" -ErrorAction SilentlyContinue | ||
} | Should -Not -Throw | ||
} | ||
|
||
} | ||
function after.cloudbaseinit.plugins.common.networkconfig.NetworkConfigPlugin { | ||
|
||
It "a network adapter should exist and have a proper name" { | ||
{ | ||
Get-NetAdapter -Name $global:CLOUDBASE_INIT_NET_NAME | ||
if (!($global:CLOUDBASE_INIT_NET_STATIC_IP -in (Get-NetIPAddress -InterfaceAlias $global:CLOUDBASE_INIT_NET_NAME).IPAddress)) { | ||
throw "Failed to set ip address on net adapter" | ||
} | ||
} | Should -Not -Throw | ||
} | ||
} | ||
|
||
function prepare.empty { | ||
|
@@ -287,6 +303,38 @@ function after.cloudbaseinit.plugins.windows.bootconfig.BootStatusPolicyPlugin { | |
|
||
function prepare.nocloud { | ||
pushd "$here/../$($env:CLOUD)" | ||
|
||
# Use OpenVPN to create a TAP Windows Adapter to be configured. | ||
# On Github Actions, we cannot use the existing network adapter for verifying the | ||
# NetworkConfigPlugin, as resetting the same static network config breaks the worker | ||
# connection to the Github Actions manager, and the action will lose context and | ||
# timeout. | ||
$openVpnUrl = "https://build.openvpn.net/downloads/releases/OpenVPN-2.5.10-I601-amd64.msi" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need OpenVPN or can we just install the tap driver from here? https://github.com/OpenVPN/tap-windows6/releases We should add an inline comment, saying why we need OpenVPN. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need OpenVPN. Installing the driver only does not do anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can simply unzip the archive and then manually create the tap device like so:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to leave the MSI installation, as it is only 4MB and requires one liner (simplicity ++). Also, if the internal ZIP contents change, a fix would be required. Hopefully, the MSI installation will be good for a long time. |
||
$wc = New-Object System.Net.WebClient | ||
$msiFilePath = Join-Path $(pwd) "openvpn.msi" | ||
$wc.DownloadFile($openVpnUrl, $msiFilePath) | ||
cmd /c "msiexec.exe -i ${msiFilePath} /qn /norestart /l*v test.log" | ||
if ($LASTEXITCODE) { throw "Failed to install openvpn" } | ||
|
||
# Refresh the network adapter list to make sure it is properly updated (Windows quirk) | ||
Get-NetAdapter | Out-Null | ||
$adapter = Get-NetAdapter -InterfaceDescription "TAP-Windows Adapter V9" | Select-Object -First 1 | ||
ader1990 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!$adapter) { throw "Failed to find adapter"} | ||
|
||
# Windows quirk to be able to set static IPs to disconnected network adapters | ||
Set-ItemProperty -Path "HKLM:\\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\$($adapter.DeviceID)" -Name EnableDHCP -Value 0 | ||
|
||
# A tap device gets created by default after installing OpenVPN. | ||
# We'll update the network-config template with the according MAC address. | ||
$currentMacAddress = $adapter.macaddress.Replace("-",":") | ||
$networkTemplateFile = "cloudbase-init-metadata\network-config.template" | ||
if (Test-path $networkTemplateFile) { | ||
$networkTemplateFileContent = (Get-Content -Raw $networkTemplateFile) | ||
$networkTemplateFileContent = $networkTemplateFileContent.Replace("REPLACE_MAC_ADDRESS", $currentMacAddress) | ||
$networkTemplateFileContent | Set-Content "cloudbase-init-metadata\network-config" -Encoding Ascii | ||
Write-Host $networkTemplateFileContent | ||
} | ||
|
||
try { | ||
Dismount-DiskImage -ErrorAction SilentlyContinue (Resolve-Path "../cloudbase-init-config-drive.iso") | ||
Remove-Item -Force -ErrorAction SilentlyContinue "../cloudbase-init-config-drive.iso" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
config: | ||
- mac_address: REPLACE_MAC_ADDRESS | ||
name: cbs_init_eth0 | ||
type: physical | ||
subnets: | ||
- address: 10.196.59.2/24 | ||
dns_nameservers: | ||
- 1.1.1.1 | ||
- 8.8.8.8 | ||
gateway: 10.196.59.1 | ||
type: static | ||
version: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this renames the "cbs_init_eth0" adapter to "not_cbs_init0" before executing NetworkConfigPlugin, probably to verify that the plugin changes the adapter name back to "cbs_init_eth0".
If the plugin hasn't run yet, it won't find the given adapter and silently ignore the error.
I guess it's worth adding an inline comment.