<commit_before># Copyright 2015 SUSE LLC

Given(/^this client hostname$/) do
  @this_client_hostname = `hostname -f`.chomp
end

When(/^I get a content of a file "(.*?)"$/) do |filename|
  @output = sshcmd("cat #{filename}")
end

When(/^I delete key of this client$/) do
  sshcmd("yes | salt-key -d #{@this_client_hostname}")
  system("rcsalt-minion restart")
  puts "Waiting for the longest RSA key re-issue (10 secons)"
  # Longest key re-issue is 10 seconds. We sleep here 15.
  sleep(15)
end

When(/^I remove possible Salt Master key "(.*?)"$/) do |filename|
  if File.exist?(filename)
    File.delete(filename)
    puts "File #{filename} has been removed"
  end
end

When(/^when I restart Salt Minion$/) do
  system("rcsalt-minion stop")
  system("rcsalt-minion start")
end

Then(/^the Salt Minion should be running$/) do
  fail if not `rcsalt-minion status | grep Active`.chomp.include? "active (running) since"
end

When(/^I list unaccepted keys at Salt Master$/) do
  @output = sshcmd("salt-key --list unaccepted")
end

When(/^I list accepted keys at Salt Master$/) do
  @output = sshcmd("salt-key --list accepted")
end

Then(/^the list of the keys should contain this client hostname$/) do
  fail if not @output[:stdout].include? @this_client_hostname
end

When(/^I accept all Salt unaccepted keys$/) do
  sshcmd("yes | salt-key -A")
end

When(/^I ping client machine from the Master$/) do
  @output = sshcmd("salt #{@this_client_hostname} test.ping")
end

When(/^I get OS information of the client machine from the Master$/) do
  sleep(15)
  @output = sshcmd("salt #{@this_client_hostname} grains.get os")<commit_msg>simplify checking for running service<commit_after># Copyright 2015 SUSE LLC

Given(/^this client hostname$/) do
  @this_client_hostname = `hostname -f`.chomp
end

When(/^I get a content of a file "(.*?)"$/) do |filename|
  @output = sshcmd("cat #{filename}")
end

When(/^I delete key of this client$/) do
  sshcmd("yes | salt-key -d #{@this_client_hostname}")
  system("rcsalt-minion restart")
  puts "Waiting for the longest RSA key re-issue (10 secons)"
  # Longest key re-issue is 10 seconds. We sleep here 15.
  sleep(15)
end

When(/^I remove possible Salt Master key "(.*?)"$/) do |filename|
  if File.exist?(filename)
    File.delete(filename)
    puts "File #{filename} has been removed"
  end
end

When(/^when I restart Salt Minion$/) do
  system("rcsalt-minion stop")
  system("rcsalt-minion start")
  sleep(2)
end

Then(/^the Salt Minion should be running$/) do
  fail if not system("rcsalt-minion status")
end

When(/^I list unaccepted keys at Salt Master$/) do
  @output = sshcmd("salt-key --list unaccepted")
end

When(/^I list accepted keys at Salt Master$/) do
  @output = sshcmd("salt-key --list accepted")
end

Then(/^the list of the keys should contain this client hostname$/) do
  fail if not @output[:stdout].include? @this_client_hostname
end

When(/^I accept all Salt unaccepted keys$/) do
  sshcmd("yes | salt-key -A")
end

When(/^I ping client machine from the Master$/) do
  @output = sshcmd("salt #{@this_client_hostname} test.ping")
end

When(/^I get OS information of the client machine from the Master$/) do
  sleep(15)
  @output = sshcmd("salt #{@this_client_hostname} grains.get os")
{'fraction_non_alphanumeric': 0.13761184819500155, 'fraction_numerical': 0.008947855600123419, 'mean_word_length': 4.129746835443038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3385426', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1081, 'n_words': 387}