lib/cucumber/chef/steps/ssh_steps.rb in cucumber-chef-2.0.7 vs lib/cucumber/chef/steps/ssh_steps.rb in cucumber-chef-2.1.0.rc.0

- old
+ new

@@ -1,9 +1,37 @@ +################################################################################ + +# | id | hostname | username | keyfile | +# | root | chef-client | root | keyfile | + +When /^I have the following SSH sessions:$/ do |table| + lambda { + @ssh_sessions ||= Hash.new + table.hashes.each do |hash| + id = hash["id"] + @ssh_sessions[id] and !@ssh_sessions[id].closed? and @ssh_sessions[id].close + @ssh_sessions[id] = ZTK::SSH.new + + @ssh_sessions[id].config.proxy_host_name = $test_lab.labs_running.first.public_ip_address + @ssh_sessions[id].config.proxy_user = "ubuntu" + @ssh_sessions[id].config.proxy_keys = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{@ssh_sessions[id].config.proxy_user}") + + hash['hostname'] and (@ssh_sessions[id].config.host_name = hash['hostname']) + hash['username'] and (@ssh_sessions[id].config.user = hash['username']) + hash['password'] and (@ssh_sessions[id].config.password = hash['password']) + hash['keyfile'] and (@ssh_sessions[id].config.keys = hash['keyfile']) + end + }.should_not raise_error +end + +################################################################################ + When /^I ssh to "([^\"]*)" with the following credentials:$/ do |hostname, table| session = table.hashes.first lambda { + @connection and !@connection.ssh.closed? and @connection.ssh.close @connection = ZTK::SSH.new @connection.config.proxy_host_name = $test_lab.labs_running.first.public_ip_address @connection.config.proxy_user = "ubuntu" @connection.config.proxy_keys = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{@connection.config.proxy_user}") @@ -16,10 +44,11 @@ }.should_not raise_error end And /^I run "([^\"]*)"$/ do |command| @output = @connection.exec(command, :silence => true).output + Cucumber::Chef.logger.info { @output.chomp } end Then /^I should( not)? see "([^\"]*)" in the output$/ do |boolean, string| if (!boolean) @output.should =~ /#{string}/ @@ -28,12 +57,12 @@ end end Then /^I should( not)? see the "([^\"]*)" of "([^\"]*)" in the output$/ do |boolean, key, name| if (!boolean) - @output.should =~ /#{$drb_test_lab.servers[name][key.downcase.to_sym]}/i + @output.should =~ /#{$test_lab.drb.servers[name][key.downcase.to_sym]}/i else - @output.should_not =~ /#{$drb_test_lab.servers[name][key.downcase.to_sym]}/i + @output.should_not =~ /#{$test_lab.drb.servers[name][key.downcase.to_sym]}/i end end Then /^(path|directory|file|symlink) "([^\"]*)" should exist$/ do |type, path| parent = File.dirname path