Skip to content

Commit

Permalink
Vagrant: Add Windows Server 2022 option to VPC (#3257)
Browse files Browse the repository at this point in the history
* Add windows 2022 to VPC

Vagrant performance tweak

Vagrantfile alignments.

Comment fix.

Vagrant update

Vagrantfiles

* Test no warning

* Revert warnings test

* Test

* Update task name
  • Loading branch information
steelhead31 authored Nov 21, 2023
1 parent 43edbd9 commit 5eb5d44
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 26 deletions.
40 changes: 22 additions & 18 deletions ansible/pbTestScripts/vagrantPlaybookCheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ checkVars()
ls -1 ../vagrant/Vagrantfile.* | cut -d. -f4
exit 1
fi
if [[ "$runTest" == true && "$testNativeBuild" == false ]]; then
if [[ "$runTest" == true && "$testNativeBuild" == false ]]; then
echo "Unable to test an unbuilt JDK. Ignoring '--test' argument."
runTest=false
fi
#Sets WORKSPACE to home if WORKSPACE is empty or undefined.
#Sets WORKSPACE to home if WORKSPACE is empty or undefined.
if [ ! -n "${WORKSPACE:-}" ]; then
echo "WORKSPACE not found, setting it as environment variable 'HOME'"
WORKSPACE=$HOME
Expand Down Expand Up @@ -151,15 +151,15 @@ checkVagrantOS()
local vagrantOSList
if [[ "$newVagrantFiles" = "true" ]]; then
cd ${WORKSPACE}/adoptopenjdkPBTests/${gitFork}-${newGitBranch}/ansible/vagrant
else
else
cd ${scriptPath%/*}/../vagrant
fi
vagrantOSList=$(ls -1 Vagrantfile.* | cut -d. -f 2)
if [[ -f "Vagrantfile.${vagrantOS}" ]]; then
echo "Vagrantfile Detected"
elif [[ "$vagrantOS" == "all" ]]; then
vagrantOS=$vagrantOSList
else
else
echo "No Vagrantfile for $vagrantOS available - please select from one of the following"
echo $vagrantOSList
exit 1
Expand Down Expand Up @@ -224,7 +224,7 @@ startVMPlaybook()
rm -f id_rsa.pub id_rsa
ssh-keygen -q -f $PWD/id_rsa -t rsa -N ''

# The BUILD_ID variable is required to stop Jenkins shutting down the wrong VMS
# The BUILD_ID variable is required to stop Jenkins shutting down the wrong VMS
# See https://github.com/adoptium/infrastructure/issues/1287#issuecomment-625142917
BUILD_ID=dontKillMe vagrant up
vagrantPORT=$(vagrant port | grep host | awk '{ print $4 }')
Expand All @@ -235,14 +235,14 @@ startVMPlaybook()
# ssh-keygen -R will fail if the known_hosts file does not exist
[ ! -r $HOME/.ssh/known_hosts ] && touch $HOME/.ssh/known_hosts && chmod 644 $HOME/.ssh/known_hosts
ssh-keygen -R $(cat playbooks/AdoptOpenJDK_Unix_Playbook/hosts.unx)

sed -i -e "s/.*hosts:.*/ hosts: all/g" playbooks/AdoptOpenJDK_Unix_Playbook/main.yml
awk '{print}/^\[defaults\]$/{print "private_key_file = id_rsa"; print "remote_tmp = $HOME/.ansible/tmp"; print "timeout = 60"}' < ansible.cfg > ansible.cfg.tmp && mv ansible.cfg.tmp ansible.cfg

ansible-playbook $verbosity -i playbooks/AdoptOpenJDK_Unix_Playbook/hosts.unx -u vagrant -b --skip-tags adoptopenjdk,jenkins${skipFullSetup} playbooks/AdoptOpenJDK_Unix_Playbook/main.yml 2>&1 | tee $WORKSPACE/adoptopenjdkPBTests/logFiles/$gitFork.$newGitBranch.$OS.log
echo The playbook finished at : `date +%T`
if ! grep -q 'unreachable=0.*failed=0' $pbLogPath; then
echo PLAYBOOK FAILED
echo PLAYBOOK FAILED
exit 1
fi

Expand Down Expand Up @@ -306,7 +306,7 @@ startVMPlaybookWin()
# The BUILD_ID variable is required to stop Jenkins shutting down the wrong VMS
# See https://github.com/adoptium/infrastructure/issues/1287#issuecomment-625142917
BUILD_ID=dontKillMe vagrant up

# Rearm the evaluation license for 180 days to stop the VMs shutting down
# See: https://github.com/adoptium/infrastructure/issues/2056
vagrant winrm --shell cmd -c "slmgr.vbs /rearm //b"
Expand All @@ -317,7 +317,7 @@ startVMPlaybookWin()
vagrantPort=$(vagrant port | awk '/5986/ { print $4 }')
echo "[127.0.0.1]:$vagrantPort" >> playbooks/AdoptOpenJDK_Windows_Playbook/hosts.win
echo "This is the content of hosts.win : " && cat playbooks/AdoptOpenJDK_Windows_Playbook/hosts.win

# Changes the value of "hosts" in main.yml
sed -i'' -e "s/.*hosts:.*/ hosts: all/g" playbooks/AdoptOpenJDK_Windows_Playbook/main.yml
# Uncomments and sets the ansible_password to 'vagrant', in adoptopenjdk_variables.yml
Expand All @@ -328,17 +328,20 @@ startVMPlaybookWin()
# Add the "ansible_winrm_transport" to adoptopenjdk_variables.yml
echo -e "\nansible_winrm_transport: credssp" >> playbooks/AdoptOpenJDK_Windows_Playbook/group_vars/all/adoptopenjdk_variables.yml
fi

# Add The Ansible WinRM TimeOut Values To The Vars file
echo "ansible_winrm_operation_timeout_sec: 600" >> playbooks/AdoptOpenJDK_Windows_Playbook/group_vars/all/adoptopenjdk_variables.yml
echo "ansible_winrm_read_timeout_sec: 630" >> playbooks/AdoptOpenJDK_Windows_Playbook/group_vars/all/adoptopenjdk_variables.yml

gitSha=$(git rev-parse HEAD)

# Run the ansible playbook on the VM & logs the output.
ansible-playbook $verbosity -i playbooks/AdoptOpenJDK_Windows_Playbook/hosts.win -u vagrant --extra-vars "git_sha=${gitSha}" --skip-tags jenkins,adoptopenjdk${skipFullSetup} playbooks/AdoptOpenJDK_Windows_Playbook/main.yml 2>&1 | tee $pbLogPath
echo The playbook finished at : `date +%T`
if ! grep -q 'unreachable=0.*failed=0' $pbLogPath; then
echo PLAYBOOK FAILED
echo PLAYBOOK FAILED
exit 1
fi

if [[ "$testNativeBuild" = true ]]; then
local buildLogPath="$WORKSPACE/adoptopenjdkPBTests/logFiles/${gitFork}.${newGitBranch}.$OS.build_log"

Expand All @@ -356,14 +359,14 @@ startVMPlaybookWin()
echo BUILD FAILED
exit 127
fi

if [[ "$runTest" = true ]]; then
local testLogPath="$WORKSPACE/adoptopenjdkPBTests/logFiles/${gitFork}.${newGitBranch}.$OS.test_log"

# Run a python script to start a test for the built JDK on the Windows VM
python pbTestScripts/startScriptWin.py -i "127.0.0.1:$vagrantPort" -t 2>&1 | tee $testLogPath
echo The test finished at : `date +%T`
if ! grep -q 'FAILED: 0' $testLogPath; then
if ! grep -q 'FAILED: 0' $testLogPath; then
echo TEST FAILED
exit 127
fi
Expand Down Expand Up @@ -409,13 +412,14 @@ checkVagrantOS
echo "Testing on the following OSs: $vagrantOS"
for OS in $vagrantOS
do
if [[ "$OS" == "Win2012" ]] ; then
echo OS = $vagrantOS
if [[ "$OS" == "Win2012" || "$OS" == "Win2022" ]] ; then
startVMPlaybookWin $OS
else
startVMPlaybook $OS
fi
if [[ "$vmHalt" == true ]]; then
vagrant halt
vagrant halt
fi
done
destroyVM
11 changes: 7 additions & 4 deletions ansible/pbTestScripts/vmDestroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ checkOS() {
osToDestroy="Sol10" ;;
"Windows2012" | "Win2012" | "W12" | "w12" )
osToDestroy="W2012";;
"all" )
"Windows2022" | "Win2022" | "W22" | "w22" )
osToDestroy="W2022";;
"all" )
osToDestroy="U16 U18 U20 U21 C6 C7 C8 D8 D10 FBSD12 Sol10 W2012" ;;
"")
echo "No OS detected. Did you miss the '-o' option?" ; usage; exit 1;;
Expand All @@ -85,7 +87,8 @@ listOS() {
- Debian10
- FreeBSD12
- Solaris10
- Win2012"
- Win2012
- Win2022"
echo
}

Expand All @@ -111,8 +114,8 @@ if [[ "$force" == False ]]; then
echo "Cancelling ..."
exit 1;
fi
fi
for OS in $osToDestroy
fi
for OS in $osToDestroy
do
destroyVMs $OS
done
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
when: (not vs2017_installed.stat.exists)
tags: MSVS_2017

- name: Install Visual Studio Community 2017
win_shell: 'C:\temp\vs_community.exe --wait --add Microsoft.VisualStudio.Workload.NativeDesktop;includeRecommended;includeOptional --quiet --norestart'
- name: Run Visual Studio 2017 Installer From Download
win_shell: |
Start-Process -Wait -FilePath 'C:\temp\vs_community.exe' -ArgumentList '--wait --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --includeOptional --quiet --norestart'
args:
executable: cmd
executable: powershell
when: (not vs2017_installed.stat.exists)
register: vs2017_error
failed_when: vs2017_error.rc != 1 and vs2017_error.rc != 0
failed_when: vs2017_error.rc != 0 and vs2017_error.rc != 1
tags: MSVS_2017

- name: Register Visual Studio Community 2017 DIA SDK shared libraries
Expand Down
53 changes: 53 additions & 0 deletions ansible/vagrant/Vagrantfile.Win2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Runs Powershell as an administator and does the following:
# - Gets/executes an Ansible provided script that configures WinRM to allow Ansible to communicate over it.
# - Resizes the disk to ~100GB, in line with the 'disksize.size = 100GB' option in the config below

$script = <<SCRIPT
Start-Process powershell -Verb runAs
wget https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile .\\ConfigureRemotingForAnsible.ps1
.\\ConfigureRemotingForAnsible.ps1 -CertValidityDays 9999
.\\ConfigureRemotingForAnsible.ps1 -EnableCredSSP
.\\ConfigureRemotingForAnsible.ps1 -ForceNewSSLCert
.\\ConfigureRemotingForAnsible.ps1 -SkipNetworkProfileCheck
# Retrieving disk's current size
$currentDiskSize =(Get-Partition -DriveLetter c | select Size)
$currentDiskSize =($currentDiskSize -replace "[^0-9]" , "")
# The size the disk should be, in bytes (130GB)
$diskSizeBoundary = 139586437120
# Changing the disksize to max supported size (~130GB)
if ([long]$currentDiskSize -lt $diskSizeBoundary) {
echo "Resizing disk to max size"
$size = (Get-PartitionSupportedSize -DriveLetter c); Resize-Partition -DriveLetter c -Size $size.SizeMax
}else {
echo "Disk is already at max size"
}
Start-Process cmd -Verb runAs
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
SCRIPT

# 2 = version of configuration file for Vagrant 1.1+ leading up to 2.0.x
Vagrant.configure("2") do |config|

config.vm.define :adoptopenjdkW2022 do |adoptopenjdkW2022|
adoptopenjdkW2022.vm.box = "gusztavvargadr/windows-server-2022-standard"
adoptopenjdkW2022.vm.hostname = "adoptopenjdkW2022"
adoptopenjdkW2022.vm.communicator = "winrm"
adoptopenjdkW2022.vm.synced_folder ".", "/vagrant"
adoptopenjdkW2022.vm.network :private_network, type: "dhcp"
adoptopenjdkW2022.vm.provision "shell", inline: $script, privileged: false
adoptopenjdkW2022.disksize.size = '130GB'
end
config.vm.provider "virtualbox" do |v|
v.gui = false
v.memory = 8192
v.cpus = 2
v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
end
end

0 comments on commit 5eb5d44

Please sign in to comment.