Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions lib/rtoolsHCK.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ def initialize(init_opts)

private

# Actions that can be performed in no_studio mode (client-only actions)
CLIENT_ACTIONS = %i[
start_client_services
get_machine_system_info
machine_shutdown
run_on_machine
upload_to_machine
download_from_machine
exists_on_machine?
delete_on_machine
install_machine_driver_package
close
].freeze

# init_opts initialization defaults
INIT_OPTS_DEFAULTS = {
addr: '192.168.100.1',
Expand All @@ -173,7 +187,8 @@ def initialize(init_opts)
logger: nil,
log_to_stdout: false,
outp_dir: nil,
r_script_file: 'C:\\toolsHCK.ps1'
r_script_file: 'C:\\toolsHCK.ps1',
no_studio: false
}.freeze

def validate_init_opts(init_opts)
Expand Down Expand Up @@ -233,11 +248,15 @@ def start_client_services(machine)
def do_initialize(init_opts)
load_outp_dir(init_opts[:outp_dir])
load_instance_variables(init_opts)
logger('debug', 'initialize') { "#{@user}:#{@pass}@#{@addr}" }
load_winrm_ps
load_winrm_fs
start_studio_services
load_toolshck
if @no_studio
logger('debug', 'initialize') { "no-studio mode: clients=#{@clients_addrs.keys}" }
else
logger('debug', 'initialize') { "#{@user}:#{@pass}@#{@addr}" }
load_winrm_ps
load_winrm_fs
start_studio_services
load_toolshck
end
@closed = false
end

Expand All @@ -263,6 +282,7 @@ def load_instance_variables(init_opts)
@timeout = init_opts[:timeout]
@json = init_opts[:json]
@r_script_file = init_opts[:r_script_file]
@no_studio = init_opts[:no_studio]
end

def winrm_options_factory(addr, port, user, pass)
Expand Down Expand Up @@ -408,6 +428,9 @@ def action_exception_handler(exception)

def handle_action_exceptions(action, &block)
raise RToolsHCKError.new('action'), 'instance is closed.' if @closed
if @no_studio && !CLIENT_ACTIONS.include?(action)
raise RToolsHCKError.new(action.to_s), 'not supported in no_studio mode.'
end

log_action_call(action, block.binding)
handle_exceptions do
Expand Down Expand Up @@ -1176,8 +1199,6 @@ def machine_shutdown(machine, restart: false)
def run_on_machine(machine, cmd)
handle_action_exceptions(__method__) do
ret = machine_run(machine, cmd)
return (@json ? { 'result' => 'Success' } : true) if ret.empty?

@json ? { 'result' => 'Success', 'content' => ret } : true
end
end
Expand Down Expand Up @@ -1465,6 +1486,8 @@ def reconnect
private

def priv_close
return if @no_studio

unload_toolshck
unload_winrm_ps
end
Expand Down
Loading