diff --git a/Gemfile b/Gemfile index f9e8404c..971911b2 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'httpclient' gem 'mono_logger' gem 'octokit' gem 'openssl', require: false -gem 'rtoolsHCK', git: 'https://github.com/HCK-CI/rtoolsHCK.git', ref: 'v0.6.1' +gem 'rtoolsHCK', git: 'https://github.com/HCK-CI/rtoolsHCK.git', ref: 'VIRTWINKVM-1865' gem 'rubyzip' gem 'sentry-ruby' gem 'sorbet-runtime' diff --git a/Gemfile.lock b/Gemfile.lock index 5f6a54ff..5c87651e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/HCK-CI/rtoolsHCK.git - revision: c59b7e6f7366d630313111fd0ad380a235b8b2ef - ref: v0.6.1 + revision: f59ae987141d8d7192ede862802dbf3d9d0d9105 + ref: VIRTWINKVM-1865 specs: rtoolsHCK (0.6.1) bundler @@ -132,7 +132,7 @@ GEM sorbet-runtime (>= 0.5.9204) rbs (3.9.2) logger - rdoc (6.15.1) + rdoc (6.17.0) erb psych (>= 4.0.0) tsort @@ -189,7 +189,7 @@ GEM rbi (>= 0.2.3) sorbet-static-and-runtime (>= 0.5.10187) thor (>= 0.19.2) - stringio (3.1.8) + stringio (3.1.9) tapioca (0.16.11) benchmark bundler (>= 2.2.25) diff --git a/bin/ns b/bin/ns index 7befb5c2..3bccbed3 100755 --- a/bin/ns +++ b/bin/ns @@ -28,6 +28,6 @@ module AutoHCK workspace_path = File.absolute_path(workspace_path, chdir) end - QemuHCK::Ns.enter workspace_path, chdir, *argv + QemuHCK::Ns.enter workspace_path, chdir, {}, *argv end end diff --git a/bin/ns_unshared b/bin/ns_unshared index 0b9dd40e..de181634 100755 --- a/bin/ns_unshared +++ b/bin/ns_unshared @@ -16,6 +16,7 @@ module AutoHCK '/proc/sys/net/bridge/bridge-nf-call-ip6tables', '/proc/sys/net/bridge/bridge-nf-call-iptables' ].each do |file| + $stderr.write "[ns_unshared] Writing '0' to #{file}\n" File.write file, '0' rescue Errno::ENOENT # br_netfilter is not loaded @@ -50,6 +51,7 @@ module AutoHCK %w[ip link add br_debug type bridge], %w[ip link set br_debug up] ].each do |cmd| + $stderr.write "[ns_unshared] Running (wait spawn): #{cmd.join(' ')}\n" Process.wait spawn(*cmd, out: :err) raise $CHILD_STATUS.to_s unless $CHILD_STATUS.success? rescue StandardError diff --git a/bin/ns_veth b/bin/ns_veth new file mode 100755 index 00000000..23ef0b24 --- /dev/null +++ b/bin/ns_veth @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require_relative '../lib/auto_hck' + +module AutoHCK + run do + require 'English' + require 'fileutils' + + side = ARGV[0] + case side + when 'host' + pid = ARGV[1] + run_id = ARGV[2] + veth_bridge = ARGV[3] + + command = [ + # *veth* pair for *control* *external* communication bridge + # one end (vce_#{run_id}) in host connected to veth_bridge + # other in namespace (ctrl_ext_ns) connected to br_ctrl_ext + %W[ip link add vce_#{run_id} type veth peer ctrl_ext_ns netns #{pid}], + %W[ip link set vce_#{run_id} master #{veth_bridge}], + %W[ip link set vce_#{run_id} up] + ] + when 'ns' + command = [ + # External control bridge for communication with Controller / Studio PCs in lab + %w[ip link set ctrl_ext_ns up], + %w[ip link add br_ctrl_ext type bridge], + %w[ip link set ctrl_ext_ns master br_ctrl_ext], + %w[ip link set br_ctrl_ext up] + ] + else + raise "Unknown side: #{side}" + end + + command.each do |cmd| + $stderr.write "[ns_veth #{side}] Running (wait spawn): #{cmd.join(' ')}\n" + Process.wait spawn(*cmd, out: :err) + raise $CHILD_STATUS.to_s unless $CHILD_STATUS.success? + rescue StandardError + raise "#{cmd}: command failed" + end + end +end diff --git a/bin/nsd b/bin/nsd index a0e90fda..1e21cf72 100755 --- a/bin/nsd +++ b/bin/nsd @@ -33,8 +33,11 @@ module AutoHCK argv << File.join(__dir__, 'ns_unshared') e_read, e_write = IO.pipe + $stderr.write "[nsd] Running (e pipe): #{e_read.fileno} => #{e_write.fileno}\n" r_read, r_write = IO.pipe + $stderr.write "[nsd] Running (r pipe): #{r_read.fileno} => #{r_write.fileno}\n" parent = Process.pid.to_s + $stderr.write "[nsd] Parent PID: #{parent}\n" fork do e_write.close @@ -60,19 +63,24 @@ module AutoHCK # Call newgidmap so that virtiofsd can use setgroups() to drop subgroups. # unshare command in util-linux 2.38 can call newgidmap by its own, but # unfortunately it is not available on some supported systems. - system 'newgidmap', parent, '0', Process.gid.to_s, '1', - subid_start, subid_start, subid_count, exception: true, out: :err + command = ['newgidmap', parent, '0', Process.gid.to_s, '1', subid_start, subid_start, subid_count] + $stderr.write "[nsd child] Running (system): #{command.join(' ')}\n" + system(*command, exception: true, out: :err) end e_read.close_on_exec = false r_write.close_on_exec = false - exec 'slirp4netns', '-e', e_read.fileno.to_s, '-r', r_write.fileno.to_s, - '-a', 'slirp.sock', parent, 'tap_host', out: :err + + command = ['slirp4netns', '-e', e_read.fileno.to_s, '-r', r_write.fileno.to_s, + '-a', 'slirp.sock', parent, 'tap_host'] + $stderr.write "[nsd child] Running (exec): #{command.join(' ')}\n" + exec(*command, out: :err) end e_read.close r_write.close + $stderr.write "[nsd] Running (exec, 3 => #{e_write.fileno}, 4 => #{r_read.fileno}): #{argv.join(' ')}\n" exec(*argv, 3 => e_write, 4 => r_read) end end diff --git a/bin/run_dump b/bin/run_dump index 2deaf410..657bdbc7 100755 --- a/bin/run_dump +++ b/bin/run_dump @@ -8,6 +8,6 @@ module AutoHCK workspace = File.dirname(ARGV[0]) chdir = File.dirname(__dir__) program = File.join(__dir__, 'run_dump_unshared') - QemuHCK::Ns.enter workspace, chdir, program, *ARGV + QemuHCK::Ns.enter workspace, chdir, {}, program, *ARGV end end diff --git a/lib/cli.rb b/lib/cli.rb index 96a993fe..ace16e26 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -22,7 +22,7 @@ def initialize # class CommonOptions class CommonOptions attr_accessor :verbose, :config, :client_world_net, :id, :share_on_host_path, :workspace_path, - :client_ctrl_net_dev, :attach_debug_net + :client_ctrl_net_dev, :attach_debug_net, :control_bridge_external def create_parser(sub_parser) OptionParser.new do |parser| @@ -47,6 +47,7 @@ def define_options(parser) @id = 2 @share_on_host_path = nil @attach_debug_net = false + @control_bridge_external = nil parser.on('--share-on-host-path ', String, 'For using Transfer Network specify the directory to share on host machine') do |share_on_host_path| @@ -83,6 +84,13 @@ def define_options(parser) exit end + parser.on('--control-bridge-external ', String, + 'External control bridge name.', + 'This bridge will be used to connect clients VM to ', + 'external Controller / Studio PC network.', + 'This is part of dedicated studio feature. (experimental)', + &method(:control_bridge_external=)) + parser.on('-w ', String, 'Internal use only', &method(:workspace_path=)) diff --git a/lib/engines/hcktest/platforms/Win10_2004x64.json b/lib/engines/hcktest/platforms/Win10_2004x64.json index a7b33e13..307772aa 100644 --- a/lib/engines/hcktest/platforms/Win10_2004x64.json +++ b/lib/engines/hcktest/platforms/Win10_2004x64.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 4, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2004-C1-Win10_2004x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 4, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2004-C2-Win10_2004x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win10_2004x86.json b/lib/engines/hcktest/platforms/Win10_2004x86.json index 37939162..9cc7797a 100644 --- a/lib/engines/hcktest/platforms/Win10_2004x86.json +++ b/lib/engines/hcktest/platforms/Win10_2004x86.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 4, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2004-C1-Win10_2004x86.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 4, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2004-C2-Win10_2004x86.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win10_22H2x64.json b/lib/engines/hcktest/platforms/Win10_22H2x64.json index 5c3c68c2..ec161572 100644 --- a/lib/engines/hcktest/platforms/Win10_22H2x64.json +++ b/lib/engines/hcktest/platforms/Win10_22H2x64.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 4, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2004-C1-Win10_22H2x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 4, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2004-C2-Win10_22H2x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11_22H2x64_host_viommu.json b/lib/engines/hcktest/platforms/Win11_22H2x64_host_viommu.json index 8c8f0a81..44301134 100644 --- a/lib/engines/hcktest/platforms/Win11_22H2x64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win11_22H2x64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_22H2-C1-Win11_22H2x64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_22H2-C2-Win11_22H2x64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11_23H2x64_host_viommu.json b/lib/engines/hcktest/platforms/Win11_23H2x64_host_viommu.json index f978bda4..041b1222 100644 --- a/lib/engines/hcktest/platforms/Win11_23H2x64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win11_23H2x64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_23H2-C1-Win11_23H2x64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_23H2-C2-Win11_23H2x64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11_24H2x64_host.json b/lib/engines/hcktest/platforms/Win11_24H2x64_host.json index ef06fac7..85ddf221 100644 --- a/lib/engines/hcktest/platforms/Win11_24H2x64_host.json +++ b/lib/engines/hcktest/platforms/Win11_24H2x64_host.json @@ -11,14 +11,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_24H2-C1-Win11_24H2x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_24H2-C2-Win11_24H2x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11_24H2x64_host_viommu.json b/lib/engines/hcktest/platforms/Win11_24H2x64_host_viommu.json index 95602968..87af1430 100644 --- a/lib/engines/hcktest/platforms/Win11_24H2x64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win11_24H2x64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_24H2-C1-Win11_24H2x64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_24H2-C2-Win11_24H2x64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11_25H2x64_host.json b/lib/engines/hcktest/platforms/Win11_25H2x64_host.json index c23cdac9..77b919f4 100644 --- a/lib/engines/hcktest/platforms/Win11_25H2x64_host.json +++ b/lib/engines/hcktest/platforms/Win11_25H2x64_host.json @@ -11,14 +11,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_25H2-C1-Win11_25H2x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_25H2-C2-Win11_25H2x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11_25H2x64_host_viommu.json b/lib/engines/hcktest/platforms/Win11_25H2x64_host_viommu.json index 91028c86..b8440911 100644 --- a/lib/engines/hcktest/platforms/Win11_25H2x64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win11_25H2x64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_25H2-C1-Win11_25H2x64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_25H2-C2-Win11_25H2x64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win11nextx64_host_viommu.json b/lib/engines/hcktest/platforms/Win11nextx64_host_viommu.json index c3b0b185..f76dcf98 100644 --- a/lib/engines/hcktest/platforms/Win11nextx64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win11nextx64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK11_next-C1-Win11nextx64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK11_next-C2-Win11nextx64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2016x64.json b/lib/engines/hcktest/platforms/Win2016x64.json index 56c9d499..2c93c5cf 100644 --- a/lib/engines/hcktest/platforms/Win2016x64.json +++ b/lib/engines/hcktest/platforms/Win2016x64.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 2, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK1607-C1-Win2016x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 2, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK1607-C2-Win2016x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2016x64_bios.json b/lib/engines/hcktest/platforms/Win2016x64_bios.json index e1b7ac3c..bcb59f9b 100644 --- a/lib/engines/hcktest/platforms/Win2016x64_bios.json +++ b/lib/engines/hcktest/platforms/Win2016x64_bios.json @@ -10,14 +10,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 2, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK1607-C1-Win2016x64-bios.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 2, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK1607-C2-Win2016x64-bios.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2019x64.json b/lib/engines/hcktest/platforms/Win2019x64.json index 4583e2ee..cf03d81e 100644 --- a/lib/engines/hcktest/platforms/Win2019x64.json +++ b/lib/engines/hcktest/platforms/Win2019x64.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK1809-C1-Win2019x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK1809-C2-Win2019x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2019x64_bios.json b/lib/engines/hcktest/platforms/Win2019x64_bios.json index d87f864b..28a7a7fb 100644 --- a/lib/engines/hcktest/platforms/Win2019x64_bios.json +++ b/lib/engines/hcktest/platforms/Win2019x64_bios.json @@ -10,14 +10,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK1809-C1-Win2019x64-bios.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK1809-C2-Win2019x64-bios.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2022nextx64_host_viommu.json b/lib/engines/hcktest/platforms/Win2022nextx64_host_viommu.json index 690d78d0..8a001d4d 100644 --- a/lib/engines/hcktest/platforms/Win2022nextx64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win2022nextx64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2022_next-C1-Win2022nextx64-host-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2022_next-C2-Win2022nextx64-host-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2022x64.json b/lib/engines/hcktest/platforms/Win2022x64.json index 1b21d90d..7711b599 100644 --- a/lib/engines/hcktest/platforms/Win2022x64.json +++ b/lib/engines/hcktest/platforms/Win2022x64.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2022-C1-Win2022x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2022-C2-Win2022x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2022x64_bios.json b/lib/engines/hcktest/platforms/Win2022x64_bios.json index a47a305d..346cb1e0 100644 --- a/lib/engines/hcktest/platforms/Win2022x64_bios.json +++ b/lib/engines/hcktest/platforms/Win2022x64_bios.json @@ -10,14 +10,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2022-C1-Win2022x64-bios.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2022-C2-Win2022x64-bios.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2022x64_gui.json b/lib/engines/hcktest/platforms/Win2022x64_gui.json index 7333f16c..e519e1d0 100644 --- a/lib/engines/hcktest/platforms/Win2022x64_gui.json +++ b/lib/engines/hcktest/platforms/Win2022x64_gui.json @@ -9,14 +9,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2022-C1-Win2022x64-gui.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2022-C2-Win2022x64-gui.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2022x64_host_viommu.json b/lib/engines/hcktest/platforms/Win2022x64_host_viommu.json index c046641d..46dc7824 100644 --- a/lib/engines/hcktest/platforms/Win2022x64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win2022x64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2022-C1-Win2022x64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2022-C2-Win2022x64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2025x64_host.json b/lib/engines/hcktest/platforms/Win2025x64_host.json index 51b84d09..2fb11a7b 100644 --- a/lib/engines/hcktest/platforms/Win2025x64_host.json +++ b/lib/engines/hcktest/platforms/Win2025x64_host.json @@ -11,14 +11,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2025-C1-Win2025x64.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2025-C2-Win2025x64.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2025x64_host_gui.json b/lib/engines/hcktest/platforms/Win2025x64_host_gui.json index 70c45e9e..3add3397 100644 --- a/lib/engines/hcktest/platforms/Win2025x64_host_gui.json +++ b/lib/engines/hcktest/platforms/Win2025x64_host_gui.json @@ -11,14 +11,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2025-C1-Win2025x64-gui.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2025-C2-Win2025x64-gui.qcow2" } } diff --git a/lib/engines/hcktest/platforms/Win2025x64_host_viommu.json b/lib/engines/hcktest/platforms/Win2025x64_host_viommu.json index 55dc1329..cede9f3b 100644 --- a/lib/engines/hcktest/platforms/Win2025x64_host_viommu.json +++ b/lib/engines/hcktest/platforms/Win2025x64_host_viommu.json @@ -14,14 +14,14 @@ "name": "CL1", "cpus": 4, "memory_gb": 8, - "winrm_port": 4002, + "winrm_addr": "192.168.100.2", "image": "HLK2025-C1-Win2025x64-viommu.qcow2" }, "c2": { "name": "CL2", "cpus": 4, "memory_gb": 8, - "winrm_port": 4003, + "winrm_addr": "192.168.100.3", "image": "HLK2025-C2-Win2025x64-viommu.qcow2" } } diff --git a/lib/engines/hcktest/tools.rb b/lib/engines/hcktest/tools.rb index 90fdbbe8..636ba792 100644 --- a/lib/engines/hcktest/tools.rb +++ b/lib/engines/hcktest/tools.rb @@ -14,7 +14,7 @@ def initialize(project, ip_addr, clients) connect(addr: ip_addr, user: @config['windows_username'], pass: @config['windows_password'], - winrm_ports: config_winrm_ports, + clients_addrs: config_clients_addrs, timeout: 120, logger: @logger, outp_dir: project.workspace_path) @@ -72,12 +72,15 @@ def connect(conn) @tools = ThreadSafe.new(RToolsHCK.new(conn), Mutex.new) end - def config_winrm_ports - winrm_ports = {} + def config_clients_addrs + clients_addrs = {} @clients.each_value do |client| - winrm_ports[client['name']] = client['winrm_port'] + clients_addrs[client['name']] = { + addr: client['winrm_addr'], + port: client['winrm_port'] + } end - winrm_ports + clients_addrs end def prep_stream_for_log(stream) diff --git a/lib/project.rb b/lib/project.rb index 92241d81..c12919dd 100644 --- a/lib/project.rb +++ b/lib/project.rb @@ -189,7 +189,7 @@ def init_workspace end File.symlink(@workspace_path, "#{@config['workspace_path']}/latest") - @setup_manager_type&.enter @workspace_path + @setup_manager_type&.enter @workspace_path, @options end def handle_cancel diff --git a/lib/setupmanagers/qemuhck/ns.rb b/lib/setupmanagers/qemuhck/ns.rb index ad074cef..0b4de7cd 100644 --- a/lib/setupmanagers/qemuhck/ns.rb +++ b/lib/setupmanagers/qemuhck/ns.rb @@ -9,7 +9,7 @@ module Ns autoload_relative :Nsd, 'ns/nsd' autoload_relative :PidFile, 'ns/pid_file' - def self.enter(workspace, chdir, *argv) + def self.enter(workspace, chdir, config, *argv) Signal.trap 'INT', 'IGNORE' Thread.handle_interrupt Object => :never do @@ -18,8 +18,7 @@ def self.enter(workspace, chdir, *argv) pid = pid_file.acquire begin Thread.handle_interrupt Object => :immediate do - system(*nsenter_argv(pid, chdir), '--', *argv) - exit $CHILD_STATUS.exitstatus + perform(pid, chdir, config, *argv) end ensure begin @@ -36,13 +35,44 @@ def self.enter(workspace, chdir, *argv) end end + def self.perform(pid, chdir, config, *argv) + ext_bridge = config['control_bridge_external'] + run_id = config['run_id'] + + unless ext_bridge.nil? || run_id.nil? + # You need to configure system to allow passwordless sudo for ns_veth + sudo = Process.euid.zero? ? [] : ['sudo'] + cmd = %W[#{sudo} #{chdir}/bin/ns_veth host #{pid} #{run_id} #{ext_bridge}] + system(cmd.join(' ')) + raise "[ns.rb] #{cmd.join(' ')}: command failed" unless $CHILD_STATUS.success? + + nsexec(pid, chdir, 'bin/ns_veth', 'ns') + end + + nsenter(pid, chdir, *argv) + end + def self.nsenter_argv(pid, chdir) argv = %W[nsenter -m -n --preserve-credentials -t #{pid} -w#{chdir}] argv << '-U' unless Process.euid.zero? argv end - private_class_method :nsenter_argv + def self.nsexec(pid, chdir, *argv) + command = [*nsenter_argv(pid, chdir), '--', *argv] + $stderr.write "[ns.rb] Running (system): #{command.join(' ')}\n" + system(*command) + raise "[ns.rb] #{command.join(' ')}: command failed" unless $CHILD_STATUS.success? + end + + def self.nsenter(pid, chdir, *argv) + command = [*nsenter_argv(pid, chdir), '--', *argv] + $stderr.write "[ns.rb] Running (system): #{command.join(' ')}\n" + system(*command) + exit $CHILD_STATUS.exitstatus + end + + private_class_method :nsenter_argv, :nsenter, :nsexec, :perform end end end diff --git a/lib/setupmanagers/qemuhck/qemuhck.rb b/lib/setupmanagers/qemuhck/qemuhck.rb index 4687738f..e72082f6 100644 --- a/lib/setupmanagers/qemuhck/qemuhck.rb +++ b/lib/setupmanagers/qemuhck/qemuhck.rb @@ -200,8 +200,13 @@ def run_hck_client(scope, studio, name, run_opts) HCKClient.new(self, scope, studio, name, run_opts) end - def self.enter(workspace_path) - Ns.enter workspace_path, Dir.pwd, 'bin/auto_hck', '-w', + def self.enter(workspace_path, options) + $stderr.write "[qemuhck.rb] Entering namespace: #{workspace_path}\n" + config = { + 'control_bridge_external' => options.common.control_bridge_external, + 'run_id' => options.common.id + } + Ns.enter workspace_path, Dir.pwd, config, 'bin/auto_hck', '-w', workspace_path, *ARGV end end