Skip to content

Commit 5eb5d44

Browse files
authored
Vagrant: Add Windows Server 2022 option to VPC (adoptium#3257)
* 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
1 parent 43edbd9 commit 5eb5d44

File tree

4 files changed

+87
-26
lines changed

4 files changed

+87
-26
lines changed

ansible/pbTestScripts/vagrantPlaybookCheck.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ checkVars()
9898
ls -1 ../vagrant/Vagrantfile.* | cut -d. -f4
9999
exit 1
100100
fi
101-
if [[ "$runTest" == true && "$testNativeBuild" == false ]]; then
101+
if [[ "$runTest" == true && "$testNativeBuild" == false ]]; then
102102
echo "Unable to test an unbuilt JDK. Ignoring '--test' argument."
103103
runTest=false
104104
fi
105-
#Sets WORKSPACE to home if WORKSPACE is empty or undefined.
105+
#Sets WORKSPACE to home if WORKSPACE is empty or undefined.
106106
if [ ! -n "${WORKSPACE:-}" ]; then
107107
echo "WORKSPACE not found, setting it as environment variable 'HOME'"
108108
WORKSPACE=$HOME
@@ -151,15 +151,15 @@ checkVagrantOS()
151151
local vagrantOSList
152152
if [[ "$newVagrantFiles" = "true" ]]; then
153153
cd ${WORKSPACE}/adoptopenjdkPBTests/${gitFork}-${newGitBranch}/ansible/vagrant
154-
else
154+
else
155155
cd ${scriptPath%/*}/../vagrant
156156
fi
157157
vagrantOSList=$(ls -1 Vagrantfile.* | cut -d. -f 2)
158158
if [[ -f "Vagrantfile.${vagrantOS}" ]]; then
159159
echo "Vagrantfile Detected"
160160
elif [[ "$vagrantOS" == "all" ]]; then
161161
vagrantOS=$vagrantOSList
162-
else
162+
else
163163
echo "No Vagrantfile for $vagrantOS available - please select from one of the following"
164164
echo $vagrantOSList
165165
exit 1
@@ -224,7 +224,7 @@ startVMPlaybook()
224224
rm -f id_rsa.pub id_rsa
225225
ssh-keygen -q -f $PWD/id_rsa -t rsa -N ''
226226

227-
# The BUILD_ID variable is required to stop Jenkins shutting down the wrong VMS
227+
# The BUILD_ID variable is required to stop Jenkins shutting down the wrong VMS
228228
# See https://github.com/adoptium/infrastructure/issues/1287#issuecomment-625142917
229229
BUILD_ID=dontKillMe vagrant up
230230
vagrantPORT=$(vagrant port | grep host | awk '{ print $4 }')
@@ -235,14 +235,14 @@ startVMPlaybook()
235235
# ssh-keygen -R will fail if the known_hosts file does not exist
236236
[ ! -r $HOME/.ssh/known_hosts ] && touch $HOME/.ssh/known_hosts && chmod 644 $HOME/.ssh/known_hosts
237237
ssh-keygen -R $(cat playbooks/AdoptOpenJDK_Unix_Playbook/hosts.unx)
238-
238+
239239
sed -i -e "s/.*hosts:.*/ hosts: all/g" playbooks/AdoptOpenJDK_Unix_Playbook/main.yml
240240
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
241-
241+
242242
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
243243
echo The playbook finished at : `date +%T`
244244
if ! grep -q 'unreachable=0.*failed=0' $pbLogPath; then
245-
echo PLAYBOOK FAILED
245+
echo PLAYBOOK FAILED
246246
exit 1
247247
fi
248248

@@ -306,7 +306,7 @@ startVMPlaybookWin()
306306
# The BUILD_ID variable is required to stop Jenkins shutting down the wrong VMS
307307
# See https://github.com/adoptium/infrastructure/issues/1287#issuecomment-625142917
308308
BUILD_ID=dontKillMe vagrant up
309-
309+
310310
# Rearm the evaluation license for 180 days to stop the VMs shutting down
311311
# See: https://github.com/adoptium/infrastructure/issues/2056
312312
vagrant winrm --shell cmd -c "slmgr.vbs /rearm //b"
@@ -317,7 +317,7 @@ startVMPlaybookWin()
317317
vagrantPort=$(vagrant port | awk '/5986/ { print $4 }')
318318
echo "[127.0.0.1]:$vagrantPort" >> playbooks/AdoptOpenJDK_Windows_Playbook/hosts.win
319319
echo "This is the content of hosts.win : " && cat playbooks/AdoptOpenJDK_Windows_Playbook/hosts.win
320-
320+
321321
# Changes the value of "hosts" in main.yml
322322
sed -i'' -e "s/.*hosts:.*/ hosts: all/g" playbooks/AdoptOpenJDK_Windows_Playbook/main.yml
323323
# Uncomments and sets the ansible_password to 'vagrant', in adoptopenjdk_variables.yml
@@ -328,17 +328,20 @@ startVMPlaybookWin()
328328
# Add the "ansible_winrm_transport" to adoptopenjdk_variables.yml
329329
echo -e "\nansible_winrm_transport: credssp" >> playbooks/AdoptOpenJDK_Windows_Playbook/group_vars/all/adoptopenjdk_variables.yml
330330
fi
331-
331+
# Add The Ansible WinRM TimeOut Values To The Vars file
332+
echo "ansible_winrm_operation_timeout_sec: 600" >> playbooks/AdoptOpenJDK_Windows_Playbook/group_vars/all/adoptopenjdk_variables.yml
333+
echo "ansible_winrm_read_timeout_sec: 630" >> playbooks/AdoptOpenJDK_Windows_Playbook/group_vars/all/adoptopenjdk_variables.yml
334+
332335
gitSha=$(git rev-parse HEAD)
333336

334337
# Run the ansible playbook on the VM & logs the output.
335338
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
336339
echo The playbook finished at : `date +%T`
337340
if ! grep -q 'unreachable=0.*failed=0' $pbLogPath; then
338-
echo PLAYBOOK FAILED
341+
echo PLAYBOOK FAILED
339342
exit 1
340343
fi
341-
344+
342345
if [[ "$testNativeBuild" = true ]]; then
343346
local buildLogPath="$WORKSPACE/adoptopenjdkPBTests/logFiles/${gitFork}.${newGitBranch}.$OS.build_log"
344347

@@ -356,14 +359,14 @@ startVMPlaybookWin()
356359
echo BUILD FAILED
357360
exit 127
358361
fi
359-
362+
360363
if [[ "$runTest" = true ]]; then
361364
local testLogPath="$WORKSPACE/adoptopenjdkPBTests/logFiles/${gitFork}.${newGitBranch}.$OS.test_log"
362-
365+
363366
# Run a python script to start a test for the built JDK on the Windows VM
364367
python pbTestScripts/startScriptWin.py -i "127.0.0.1:$vagrantPort" -t 2>&1 | tee $testLogPath
365368
echo The test finished at : `date +%T`
366-
if ! grep -q 'FAILED: 0' $testLogPath; then
369+
if ! grep -q 'FAILED: 0' $testLogPath; then
367370
echo TEST FAILED
368371
exit 127
369372
fi
@@ -409,13 +412,14 @@ checkVagrantOS
409412
echo "Testing on the following OSs: $vagrantOS"
410413
for OS in $vagrantOS
411414
do
412-
if [[ "$OS" == "Win2012" ]] ; then
415+
echo OS = $vagrantOS
416+
if [[ "$OS" == "Win2012" || "$OS" == "Win2022" ]] ; then
413417
startVMPlaybookWin $OS
414418
else
415419
startVMPlaybook $OS
416420
fi
417421
if [[ "$vmHalt" == true ]]; then
418-
vagrant halt
422+
vagrant halt
419423
fi
420424
done
421425
destroyVM

ansible/pbTestScripts/vmDestroy.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ checkOS() {
6363
osToDestroy="Sol10" ;;
6464
"Windows2012" | "Win2012" | "W12" | "w12" )
6565
osToDestroy="W2012";;
66-
"all" )
66+
"Windows2022" | "Win2022" | "W22" | "w22" )
67+
osToDestroy="W2022";;
68+
"all" )
6769
osToDestroy="U16 U18 U20 U21 C6 C7 C8 D8 D10 FBSD12 Sol10 W2012" ;;
6870
"")
6971
echo "No OS detected. Did you miss the '-o' option?" ; usage; exit 1;;
@@ -85,7 +87,8 @@ listOS() {
8587
- Debian10
8688
- FreeBSD12
8789
- Solaris10
88-
- Win2012"
90+
- Win2012
91+
- Win2022"
8992
echo
9093
}
9194

@@ -111,8 +114,8 @@ if [[ "$force" == False ]]; then
111114
echo "Cancelling ..."
112115
exit 1;
113116
fi
114-
fi
115-
for OS in $osToDestroy
117+
fi
118+
for OS in $osToDestroy
116119
do
117120
destroyVMs $OS
118121
done

ansible/playbooks/AdoptOpenJDK_Windows_Playbook/roles/MSVS_2017/tasks/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
when: (not vs2017_installed.stat.exists)
2121
tags: MSVS_2017
2222

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

3233
- name: Register Visual Studio Community 2017 DIA SDK shared libraries

ansible/vagrant/Vagrantfile.Win2022

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Runs Powershell as an administator and does the following:
5+
# - Gets/executes an Ansible provided script that configures WinRM to allow Ansible to communicate over it.
6+
# - Resizes the disk to ~100GB, in line with the 'disksize.size = 100GB' option in the config below
7+
8+
$script = <<SCRIPT
9+
Start-Process powershell -Verb runAs
10+
11+
12+
wget https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile .\\ConfigureRemotingForAnsible.ps1
13+
.\\ConfigureRemotingForAnsible.ps1 -CertValidityDays 9999
14+
.\\ConfigureRemotingForAnsible.ps1 -EnableCredSSP
15+
.\\ConfigureRemotingForAnsible.ps1 -ForceNewSSLCert
16+
.\\ConfigureRemotingForAnsible.ps1 -SkipNetworkProfileCheck
17+
18+
# Retrieving disk's current size
19+
$currentDiskSize =(Get-Partition -DriveLetter c | select Size)
20+
$currentDiskSize =($currentDiskSize -replace "[^0-9]" , "")
21+
# The size the disk should be, in bytes (130GB)
22+
$diskSizeBoundary = 139586437120
23+
# Changing the disksize to max supported size (~130GB)
24+
if ([long]$currentDiskSize -lt $diskSizeBoundary) {
25+
echo "Resizing disk to max size"
26+
$size = (Get-PartitionSupportedSize -DriveLetter c); Resize-Partition -DriveLetter c -Size $size.SizeMax
27+
}else {
28+
echo "Disk is already at max size"
29+
}
30+
31+
Start-Process cmd -Verb runAs
32+
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
33+
SCRIPT
34+
35+
# 2 = version of configuration file for Vagrant 1.1+ leading up to 2.0.x
36+
Vagrant.configure("2") do |config|
37+
38+
config.vm.define :adoptopenjdkW2022 do |adoptopenjdkW2022|
39+
adoptopenjdkW2022.vm.box = "gusztavvargadr/windows-server-2022-standard"
40+
adoptopenjdkW2022.vm.hostname = "adoptopenjdkW2022"
41+
adoptopenjdkW2022.vm.communicator = "winrm"
42+
adoptopenjdkW2022.vm.synced_folder ".", "/vagrant"
43+
adoptopenjdkW2022.vm.network :private_network, type: "dhcp"
44+
adoptopenjdkW2022.vm.provision "shell", inline: $script, privileged: false
45+
adoptopenjdkW2022.disksize.size = '130GB'
46+
end
47+
config.vm.provider "virtualbox" do |v|
48+
v.gui = false
49+
v.memory = 8192
50+
v.cpus = 2
51+
v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
52+
end
53+
end

0 commit comments

Comments
 (0)