lib/cucumber/chef/steps/ssh_steps.rb in cucumber-chef-3.0.5 vs lib/cucumber/chef/steps/ssh_steps.rb in cucumber-chef-3.0.6

- old
+ new

@@ -10,12 +10,12 @@ 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 = $cc_client.test_lab.ip - @ssh_sessions[id].config.proxy_user = Cucumber::Chef.lab_user - @ssh_sessions[id].config.proxy_keys = Cucumber::Chef.lab_identity + @ssh_sessions[id].config.proxy_user = Cucumber::Chef.lab_user + @ssh_sessions[id].config.proxy_keys = Cucumber::Chef.lab_identity 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']) @@ -31,13 +31,13 @@ @connection and @connection.ssh.shutdown! @connection = ZTK::SSH.new(:timeout => 120, :ignore_exit_status => true) @connection.config.proxy_host_name = $cc_client.test_lab.ip - @connection.config.proxy_port = $cc_client.test_lab.port - @connection.config.proxy_user = Cucumber::Chef.lab_user - @connection.config.proxy_keys = Cucumber::Chef.lab_identity + @connection.config.proxy_port = $cc_client.test_lab.port + @connection.config.proxy_user = Cucumber::Chef.lab_user + @connection.config.proxy_keys = Cucumber::Chef.lab_identity hostname and (@connection.config.host_name = hostname) session["password"] and (@connection.config.password = session["password"]) if username = session["username"] @@ -58,12 +58,12 @@ }.should_not raise_error end And /^I run "([^\"]*)"$/ do |command| - @result = @connection.exec(command, :silence => true) - @output = @result.output + @result = @connection.exec(command, :silence => true) + @output = @result.output @exit_code = @result.exit_code end Then /^I should( not)? see "([^\"]*)" in the output$/ do |boolean, string| if (!boolean) @@ -83,57 +83,63 @@ Then /^the exit code should be "([^\"]*)"$/ do |exit_code| @exit_code.to_i.should == exit_code.to_i end -Then /^(path|directory|file|symlink) "([^\"]*)" should exist$/ do |type, path| - parent = File.dirname path - child = File.basename path - command = "ls %s" % [ - parent +Then /^(path|directory|file|symlink) "([^\"]*)" should( not)? exist$/ do |type, path, boolean| + parent = File.dirname path + child = File.basename path + command = "ls -a %s" % [ + parent ] @output = @connection.exec(command, :silence => true).output - @output.should =~ /#{child}/ + if (!boolean) + @output.should =~ /#{child}/ + else + @output.should_not =~ /#{child}/ + end # if a specific type (directory|file) was specified, test for it command = "stat -c %%F %s" % [ - path + path ] @output = @connection.exec(command, :silence => true).output - types = { - "file" => /regular file/, - "directory" => /directory/, - "symlink" => /symbolic link/ + types = { + "file" => /regular file/, + "directory" => /directory/, + "symlink" => /symbolic link/ } if types.keys.include? type - @output.should =~ types[type] + if (!boolean) + @output.should =~ types[type] + end end end Then /^(?:path|directory|file) "([^\"]*)" should be owned by "([^\"]*)"$/ do |path, owner| command = "stat -c %%U:%%G %s" % [ - path + path ] - @output = @connection.exec(command).output + @output = @connection.exec(command, :silence => true).output @output.should =~ /#{owner}/ end # we can now match multi-line strings. We want to match *contiguous lines* Then /^file "([^\"]*)" should( not)? contain/ do |path, boolean, content| command = "cat %s" % [ - path + path ] # turn the command-line output and the expectation string into Arrays and strip # leading and trailing cruft from members - @output = @connection.exec(command).output.split("\n").map{ |i| i.strip } - content = content.split("\n").map{ |i| i.strip } + @output = @connection.exec(command, :silence => true).output.split("\n").map { |i| i.strip } + content = content.split("\n").map { |i| i.strip } # assume no match - match = false - count = 0 + match = false + count = 0 # step through the command output array while count < @output.length current = @output[count] @@ -170,10 +176,16 @@ @result = @connection.exec(command, :silence => true) @result.output.should =~ /#{package}/ end +Then /^"mod_([^ ]*)" should be enabled$/ do |mod| + command = "apache2ctl -t -D DUMP_MODULES" + @result = @connection.exec(command, :silence => true) + @result.output.should =~ /#{mod}_module/ +end + # This regex is a little ugly, but it's so we can accept any of these # # * "foo" is running # * service "foo" is running # * application "foo" is running @@ -184,10 +196,10 @@ # TiL that in Ruby regexes, "?:" marks a non-capturing group, which is how this # works Then /^(?:(?:service|application|process)? )?"([^\"]*)" should( not)? be running$/ do |service, boolean| command = "ps ax" - @output = @connection.exec(command).output + @output = @connection.exec(command, :silence => true).output if (!boolean) @output.should =~ /#{service}/ else @output.should_not =~ /#{service}/ end