Skip to content

Commit c125348

Browse files
committed
remove legacy SSH_Base driver
Signed-off-by: Corey Hemminger <[email protected]>
1 parent 3cb706d commit c125348

File tree

3 files changed

+142
-129
lines changed

3 files changed

+142
-129
lines changed

.github/workflows/integration.yml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,37 @@ jobs:
5050
# export LOGNAME=$USER
5151
# bundle exec kitchen test almalinux-9
5252
#
53-
# integration-windows:
54-
# name: Windows Integration Tests
55-
# env:
56-
# BUNDLE_without: integration
57-
# machine_user: test_user
58-
# machine_pass: Pass@word1
59-
# machine_port: 5985
60-
# SPEC_OPTS: --format progress
61-
# KITCHEN_LOCAL_YAML: kitchen.windows.yml
62-
# runs-on: windows-latest
63-
# timeout-minutes: 600
64-
# strategy:
65-
# fail-fast: false
66-
# matrix:
67-
# ruby: ["3.3"]
68-
# steps:
69-
# - uses: actions/checkout@v4
70-
# - uses: ruby/setup-ruby@v1
71-
# with:
72-
# ruby-version: ${{ matrix.ruby }}
73-
# bundler-cache: true
74-
# - name: Unit Tests
75-
# run: bundle exec rake unit
76-
# - name: Quality Tests
77-
# run: bundle exec rake quality
78-
# - name: Setup Machine
79-
# run: |
80-
# winrm.cmd quickconfig -q
81-
# net user /add ${{ env.machine_user }} ${{ env.machine_pass }}
82-
# net localgroup administrators ${{ env.machine_user }} /add
83-
# bundle config set --local with 'integration'
84-
# bundle install
85-
# - name: Verify Windows
86-
# run: bundle exec kitchen verify windows
53+
integration-windows:
54+
name: Windows Integration Tests
55+
env:
56+
BUNDLE_without: integration
57+
machine_user: test_user
58+
machine_pass: Pass@word1
59+
machine_port: 5985
60+
SPEC_OPTS: --format progress
61+
KITCHEN_LOCAL_YAML: kitchen.windows.yml
62+
runs-on: windows-latest
63+
timeout-minutes: 600
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
ruby: ["3.3"]
68+
steps:
69+
- uses: actions/checkout@v4
70+
- uses: ruby/setup-ruby@v1
71+
with:
72+
ruby-version: ${{ matrix.ruby }}
73+
bundler-cache: true
74+
- name: Unit Tests
75+
run: bundle exec rake unit
76+
- name: Quality Tests
77+
run: bundle exec rake quality
78+
- name: Setup Machine
79+
run: |
80+
winrm.cmd quickconfig -q
81+
net user /add ${{ env.machine_user }} ${{ env.machine_pass }}
82+
net localgroup administrators ${{ env.machine_user }} /add
83+
bundle config set --local with 'integration'
84+
bundle install
85+
- name: Verify Windows
86+
run: bundle exec kitchen verify windows

lib/kitchen/driver/proxy.rb

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# limitations under the License.
1818
#
1919

20-
require_relative "ssh_base"
20+
require_relative "base"
2121
require_relative "../version"
2222

2323
module Kitchen
@@ -29,21 +29,91 @@ module Driver
2929
# the driver was created.
3030
#
3131
# @author Seth Chisamore <[email protected]>
32-
class Proxy < Kitchen::Driver::SSHBase
32+
class Proxy < Kitchen::Driver::Base
33+
include ShellOut
34+
include Configurable
35+
include Logging
36+
3337
plugin_version Kitchen::VERSION
3438

3539
required_config :host
3640
default_config :reset_command, nil
3741

3842
no_parallel_for :create, :destroy
3943

44+
# Creates a new Driver object using the provided configuration data
45+
# which will be merged with any default configuration.
46+
#
47+
# @param config [Hash] provided driver configuration
48+
def initialize(config = {})
49+
init_config(config)
50+
end
51+
4052
# (see Base#create)
4153
def create(state)
42-
# TODO: Once this isn't using SSHBase, it should call `super` to support pre_create_command.
54+
super
4355
state[:hostname] = config[:host]
4456
reset_instance(state)
4557
end
4658

59+
# (see Base#converge)
60+
def converge(state) # rubocop:disable Metrics/AbcSize
61+
provisioner = instance.provisioner
62+
provisioner.create_sandbox
63+
sandbox_dirs = provisioner.sandbox_dirs
64+
65+
instance.transport.connection(state) do |conn|
66+
conn.execute(env_cmd(provisioner.install_command))
67+
conn.execute(env_cmd(provisioner.init_command))
68+
info("Transferring files to #{instance.to_str}")
69+
conn.upload(sandbox_dirs, provisioner[:root_path])
70+
info("Transfer complete")
71+
conn.execute(env_cmd(provisioner.prepare_command))
72+
conn.execute(env_cmd(provisioner.run_command))
73+
info("Downloading files from #{instance.to_str}")
74+
provisioner[:downloads].to_h.each do |remotes, local|
75+
debug("Downloading #{Array(remotes).join(", ")} to #{local}")
76+
conn.download(remotes, local)
77+
end
78+
debug("Download complete")
79+
end
80+
rescue Kitchen::Transport::TransportFailed => ex
81+
raise ActionFailed, ex.message
82+
ensure
83+
instance.provisioner.cleanup_sandbox
84+
end
85+
86+
# (see Base#setup)
87+
def setup(state)
88+
verifier = instance.verifier
89+
90+
instance.transport.connection(state) do |conn|
91+
conn.execute(env_cmd(verifier.install_command))
92+
end
93+
rescue Kitchen::Transport::TransportFailed => ex
94+
raise ActionFailed, ex.message
95+
end
96+
97+
# (see Base#verify)
98+
def verify(state) # rubocop:disable Metrics/AbcSize
99+
verifier = instance.verifier
100+
verifier.create_sandbox
101+
sandbox_dirs = Util.list_directory(verifier.sandbox_path)
102+
103+
instance.transport.connection(state) do |conn|
104+
conn.execute(env_cmd(verifier.init_command))
105+
info("Transferring files to #{instance.to_str}")
106+
conn.upload(sandbox_dirs, verifier[:root_path])
107+
debug("Transfer complete")
108+
conn.execute(env_cmd(verifier.prepare_command))
109+
conn.execute(env_cmd(verifier.run_command))
110+
end
111+
rescue Kitchen::Transport::TransportFailed => ex
112+
raise ActionFailed, ex.message
113+
ensure
114+
instance.verifier.cleanup_sandbox
115+
end
116+
47117
# (see Base#destroy)
48118
def destroy(state)
49119
return if state[:hostname].nil?
@@ -65,6 +135,36 @@ def reset_instance(state)
65135
ssh(build_ssh_args(state), cmd)
66136
end
67137
end
138+
139+
# Adds http, https and ftp proxy environment variables to a command, if
140+
# set in configuration data or on local workstation.
141+
#
142+
# @param cmd [String] command string
143+
# @return [String] command string
144+
# @api private
145+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize
146+
def env_cmd(cmd)
147+
return if cmd.nil?
148+
149+
env = String.new("env")
150+
http_proxy = config[:http_proxy] || ENV["http_proxy"] ||
151+
ENV["HTTP_PROXY"]
152+
https_proxy = config[:https_proxy] || ENV["https_proxy"] ||
153+
ENV["HTTPS_PROXY"]
154+
ftp_proxy = config[:ftp_proxy] || ENV["ftp_proxy"] ||
155+
ENV["FTP_PROXY"]
156+
no_proxy = if (!config[:http_proxy] && http_proxy) ||
157+
(!config[:https_proxy] && https_proxy) ||
158+
(!config[:ftp_proxy] && ftp_proxy)
159+
ENV["no_proxy"] || ENV["NO_PROXY"]
160+
end
161+
env << " http_proxy=#{http_proxy}" if http_proxy
162+
env << " https_proxy=#{https_proxy}" if https_proxy
163+
env << " ftp_proxy=#{ftp_proxy}" if ftp_proxy
164+
env << " no_proxy=#{no_proxy}" if no_proxy
165+
166+
env == "env" ? cmd : "#{env} #{cmd}"
167+
end
68168
end
69169
end
70170
end

lib/kitchen/instance.rb

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ def login
210210
raise UserError, "Instance #{to_str} has not yet been created"
211211
end
212212

213-
lc = if legacy_ssh_base_driver?
214-
legacy_ssh_base_login(state)
215-
else
216-
transport.connection(state).login_command
217-
end
213+
lc = transport.connection(state).login_command
218214

219215
debug(%{Login command: #{lc.command} #{lc.arguments.join(" ")} } \
220216
"(Options: #{lc.options})")
@@ -412,12 +408,8 @@ def create_action
412408
def converge_action
413409
banner "Converging #{to_str}..."
414410
elapsed = action(:converge) do |state|
415-
if legacy_ssh_base_driver?
416-
legacy_ssh_base_converge(state)
417-
else
418-
provisioner.check_license
419-
provisioner.call(state)
420-
end
411+
provisioner.check_license
412+
provisioner.call(state)
421413
end
422414
info("Finished converging #{to_str} #{Util.duration(elapsed.real)}.")
423415
self
@@ -430,9 +422,7 @@ def converge_action
430422
# @api private
431423
def setup_action
432424
banner "Setting up #{to_str}..."
433-
elapsed = action(:setup) do |state|
434-
legacy_ssh_base_setup(state) if legacy_ssh_base_driver?
435-
end
425+
elapsed = action(:setup)
436426
info("Finished setting up #{to_str} #{Util.duration(elapsed.real)}.")
437427
self
438428
end
@@ -447,10 +437,6 @@ def verifier_dummy?(verifier)
447437
!defined?(Kitchen::Verifier::Dummy).nil? && verifier.is_a?(Kitchen::Verifier::Dummy)
448438
end
449439

450-
def use_legacy_ssh_verifier?(verifier)
451-
verifier_busser?(verifier) || verifier_dummy?(verifier)
452-
end
453-
454440
# Perform the verify action.
455441
#
456442
# @see Driver::Base#verify
@@ -459,15 +445,7 @@ def use_legacy_ssh_verifier?(verifier)
459445
def verify_action
460446
banner "Verifying #{to_str}..."
461447
elapsed = action(:verify) do |state|
462-
# use special handling for legacy driver
463-
if legacy_ssh_base_driver? && use_legacy_ssh_verifier?(verifier)
464-
legacy_ssh_base_verify(state)
465-
elsif legacy_ssh_base_driver?
466-
# read ssh options from legacy driver
467-
verifier.call(driver.legacy_state(state))
468-
else
469-
verifier.call(state)
470-
end
448+
verifier.call(state)
471449
end
472450
info("Finished verifying #{to_str} #{Util.duration(elapsed.real)}.")
473451
self
@@ -616,71 +594,6 @@ def failure_message(what)
616594
"#{what.capitalize} failed on instance #{to_str}."
617595
end
618596

619-
# Invokes `Driver#converge` on a legacy Driver, which inherits from
620-
# `Kitchen::Driver::SSHBase`.
621-
#
622-
# @param state [Hash] mutable instance state
623-
# @deprecated When legacy Driver::SSHBase support is removed, the
624-
# `#converge` method will no longer be called on the Driver.
625-
# @api private
626-
def legacy_ssh_base_converge(state)
627-
warn("Running legacy converge for '#{driver.name}' Driver")
628-
# TODO: Document upgrade path and provide link
629-
# warn("Driver authors: please read http://example.com for more details.")
630-
driver.converge(state)
631-
end
632-
633-
# @return [TrueClass,FalseClass] whether or not the Driver inherits from
634-
# `Kitchen::Driver::SSHBase`
635-
# @deprecated When legacy Driver::SSHBase support is removed, the
636-
# `#converge` method will no longer be called on the Driver.
637-
# @api private
638-
def legacy_ssh_base_driver?
639-
driver.class < Kitchen::Driver::SSHBase
640-
end
641-
642-
# Invokes `Driver#login_command` on a legacy Driver, which inherits from
643-
# `Kitchen::Driver::SSHBase`.
644-
#
645-
# @param state [Hash] mutable instance state
646-
# @deprecated When legacy Driver::SSHBase support is removed, the
647-
# `#login_command` method will no longer be called on the Driver.
648-
# @api private
649-
def legacy_ssh_base_login(state)
650-
warn("Running legacy login for '#{driver.name}' Driver")
651-
# TODO: Document upgrade path and provide link
652-
# warn("Driver authors: please read http://example.com for more details.")
653-
driver.login_command(state)
654-
end
655-
656-
# Invokes `Driver#setup` on a legacy Driver, which inherits from
657-
# `Kitchen::Driver::SSHBase`.
658-
#
659-
# @param state [Hash] mutable instance state
660-
# @deprecated When legacy Driver::SSHBase support is removed, the
661-
# `#setup` method will no longer be called on the Driver.
662-
# @api private
663-
def legacy_ssh_base_setup(state)
664-
warn("Running legacy setup for '#{driver.name}' Driver")
665-
# TODO: Document upgrade path and provide link
666-
# warn("Driver authors: please read http://example.com for more details.")
667-
driver.setup(state)
668-
end
669-
670-
# Invokes `Driver#verify` on a legacy Driver, which inherits from
671-
# `Kitchen::Driver::SSHBase`.
672-
#
673-
# @param state [Hash] mutable instance state
674-
# @deprecated When legacy Driver::SSHBase support is removed, the
675-
# `#verify` method will no longer be called on the Driver.
676-
# @api private
677-
def legacy_ssh_base_verify(state)
678-
warn("Running legacy verify for '#{driver.name}' Driver")
679-
# TODO: Document upgrade path and provide link
680-
# warn("Driver authors: please read http://example.com for more details.")
681-
driver.verify(state)
682-
end
683-
684597
# The simplest finite state machine pseudo-implementation needed to manage
685598
# an Instance.
686599
#

0 commit comments

Comments
 (0)