lib/kitchen/provisioner/nodes.rb in kitchen-nodes-0.2.0.dev.1 vs lib/kitchen/provisioner/nodes.rb in kitchen-nodes-0.2.0.dev.2

- old
+ new

@@ -16,24 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. require "kitchen" require "kitchen/provisioner/chef_zero" +require "kitchen/provisioner/ip_finder" require "net/ping" module Kitchen - - module Transport - class Winrm < Kitchen::Transport::Base - class Connection < Kitchen::Transport::Base::Connection - def node_session(retry_options = {}) - session(retry_options) - end - end - end - end - module Provisioner # Nodes provisioner for Kitchen. # # @author Matt Wrock <matt@mattwrock.com> @@ -43,16 +33,13 @@ super create_node end def create_node - node_dir = File.join(config[:test_base_path], "nodes") - Dir.mkdir(node_dir) unless Dir.exist?(node_dir) - node_file = File.join(node_dir, "#{instance.name}.json") - state = Kitchen::StateFile.new(config[:kitchen_root], instance.name).read - ipaddress = get_reachable_guest_address(state) || state[:hostname] + ip = state[:hostname] + ipaddress = (ip == "127.0.0.1" || ip == "localhost") ? get_reachable_guest_address(state) : ip node = { :id => instance.name, :automatic => { :ipaddress => ipaddress @@ -63,16 +50,28 @@ File.open(node_file, 'w') do |out| out << JSON.pretty_generate(node) end end + def node_file + node_dir = File.join(config[:test_base_path], "nodes") + Dir.mkdir(node_dir) unless Dir.exist?(node_dir) + File.join(node_dir, "#{instance.name}.json") + end + def get_reachable_guest_address(state) - instance.transport.connection(state).node_session.run_powershell_script("Get-NetIPConfiguration | % { $_.ipv4address.IPAddress}") do |address, _| - address = address.chomp unless address.nil? - next if address.nil? || address == "127.0.0.1" + active_ips(instance.transport, state).each do |address| + next if address == "127.0.0.1" return address if Net::Ping::External.new.ping(address) end return nil - end + end + + def active_ips(transport, state) + # inject creds into state for legacy drivers + state[:password] = instance.driver[:password] if instance.driver[:password] + state[:username] = instance.driver[:username] if instance.driver[:username] + IpFinder.for_transport(transport, state).find_ips + end end end end