mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
Merge pull request #61 from mikkergimenez/fix_ssh_command_breaking
SSH Command respects ABS now and tests should fail if the API changes…
This commit is contained in:
commit
5fa9c12a85
3 changed files with 61 additions and 6 deletions
|
|
@ -91,7 +91,7 @@ class Service
|
||||||
STDERR.puts 'Could not get token... requesting vm without a token anyway...'
|
STDERR.puts 'Could not get token... requesting vm without a token anyway...'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Ssh.ssh(verbose, host_os, token_value, url)
|
Ssh.ssh(verbose, self, host_os, token_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_print_running(verbose, hostnames = [])
|
def pretty_print_running(verbose, hostnames = [])
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,27 @@ class Ssh
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ssh(verbose, host_os, token, url)
|
def self.command_string(verbose, service, host_os, use_token)
|
||||||
ssh_path = which('ssh')
|
ssh_path = which('ssh')
|
||||||
raise 'Could not determine path to ssh' unless ssh_path
|
raise 'Could not determine path to ssh' unless ssh_path
|
||||||
|
|
||||||
os_types = {}
|
os_types = {}
|
||||||
os_types[host_os] = 1
|
os_types[host_os] = 1
|
||||||
|
|
||||||
response = Pooler.retrieve(verbose, os_types, token, url)
|
response = service.retrieve(verbose, os_types, use_token)
|
||||||
raise "Could not get vm from vmpooler:\n #{response}" unless response['ok']
|
raise "Could not get vm from #{service.type}:\n #{response}" unless response['ok']
|
||||||
|
|
||||||
user = /win/.match?(host_os) ? 'Administrator' : 'root'
|
user = /win/.match?(host_os) ? 'Administrator' : 'root'
|
||||||
|
|
||||||
hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
|
hostname = response[host_os]['hostname']
|
||||||
cmd = "#{ssh_path} #{user}@#{hostname}"
|
hostname = response[host_os]['hostname'][0] if response[host_os]['hostname'].is_a?(Array)
|
||||||
|
hostname = "#{hostname}.#{response['domain']}" unless hostname.end_with?('puppetlabs.net')
|
||||||
|
|
||||||
|
"#{ssh_path} #{user}@#{hostname}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ssh(verbose, service, host_os, use_token)
|
||||||
|
cmd = command_string(verbose, service, host_os, use_token)
|
||||||
# TODO: Should this respect more ssh settings? Can it be configured
|
# TODO: Should this respect more ssh settings? Can it be configured
|
||||||
# by users ssh config and does this respect those settings?
|
# by users ssh config and does this respect those settings?
|
||||||
Kernel.exec(cmd)
|
Kernel.exec(cmd)
|
||||||
|
|
|
||||||
49
spec/vmfloaty/ssh_spec.rb
Normal file
49
spec/vmfloaty/ssh_spec.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'vmfloaty/ssh'
|
||||||
|
|
||||||
|
class ServiceStub
|
||||||
|
def retrieve(_verbose, os_types, _use_token)
|
||||||
|
if os_types.keys[0] == 'abs_host_string'
|
||||||
|
return {
|
||||||
|
os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
|
||||||
|
'ok' => true,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
{
|
||||||
|
os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
|
||||||
|
'domain' => 'delivery.puppetlabs.net',
|
||||||
|
'ok' => true,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def type
|
||||||
|
return 'abs' if os_types == 'abs_host_string'
|
||||||
|
return 'vmpooler' if os_types == 'vmpooler_host_string'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe Ssh do
|
||||||
|
before :each do
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'gets a hostname string for abs' do
|
||||||
|
verbose = false
|
||||||
|
service = ServiceStub.new
|
||||||
|
host_os = 'abs_host_string'
|
||||||
|
use_token = false
|
||||||
|
cmd = Ssh.command_string(verbose, service, host_os, use_token)
|
||||||
|
expect(cmd).to match(/ssh root@abs-hostname.delivery.puppetlabs.net/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'gets a hostname string for vmpooler' do
|
||||||
|
verbose = false
|
||||||
|
service = ServiceStub.new
|
||||||
|
host_os = 'vmpooler_host_string'
|
||||||
|
use_token = false
|
||||||
|
cmd = Ssh.command_string(verbose, service, host_os, use_token)
|
||||||
|
expect(cmd).to match(/ssh root@vmpooler-hostname.delivery.puppetlabs.net/)
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue