Skip to content

Commit 5dbe19e

Browse files
authored
Merge branch 'master' into qeng-7604_add_jobid_to_delete
2 parents 51a7eb8 + 5fa9c12 commit 5dbe19e

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

lib/vmfloaty/service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def ssh(verbose, host_os, use_token = true)
9191
STDERR.puts 'Could not get token... requesting vm without a token anyway...'
9292
end
9393
end
94-
Ssh.ssh(verbose, host_os, token_value, url)
94+
Ssh.ssh(verbose, self, host_os, token_value)
9595
end
9696

9797
def pretty_print_running(verbose, hostnames = [])

lib/vmfloaty/ssh.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@ def self.which(cmd)
1414
nil
1515
end
1616

17-
def self.ssh(verbose, host_os, token, url)
17+
def self.command_string(verbose, service, host_os, use_token)
1818
ssh_path = which('ssh')
1919
raise 'Could not determine path to ssh' unless ssh_path
2020

2121
os_types = {}
2222
os_types[host_os] = 1
2323

24-
response = Pooler.retrieve(verbose, os_types, token, url)
25-
raise "Could not get vm from vmpooler:\n #{response}" unless response['ok']
24+
response = service.retrieve(verbose, os_types, use_token)
25+
raise "Could not get vm from #{service.type}:\n #{response}" unless response['ok']
2626

2727
user = /win/.match?(host_os) ? 'Administrator' : 'root'
2828

29-
hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
30-
cmd = "#{ssh_path} #{user}@#{hostname}"
29+
hostname = response[host_os]['hostname']
30+
hostname = response[host_os]['hostname'][0] if response[host_os]['hostname'].is_a?(Array)
31+
hostname = "#{hostname}.#{response['domain']}" unless hostname.end_with?('puppetlabs.net')
3132

33+
"#{ssh_path} #{user}@#{hostname}"
34+
end
35+
36+
def self.ssh(verbose, service, host_os, use_token)
37+
cmd = command_string(verbose, service, host_os, use_token)
3238
# TODO: Should this respect more ssh settings? Can it be configured
3339
# by users ssh config and does this respect those settings?
3440
Kernel.exec(cmd)

spec/vmfloaty/ssh_spec.rb

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'vmfloaty/ssh'
5+
6+
class ServiceStub
7+
def retrieve(_verbose, os_types, _use_token)
8+
if os_types.keys[0] == 'abs_host_string'
9+
return {
10+
os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
11+
'ok' => true,
12+
}
13+
end
14+
15+
{
16+
os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
17+
'domain' => 'delivery.puppetlabs.net',
18+
'ok' => true,
19+
}
20+
end
21+
22+
def type
23+
return 'abs' if os_types == 'abs_host_string'
24+
return 'vmpooler' if os_types == 'vmpooler_host_string'
25+
end
26+
end
27+
28+
describe Ssh do
29+
before :each do
30+
end
31+
32+
it 'gets a hostname string for abs' do
33+
verbose = false
34+
service = ServiceStub.new
35+
host_os = 'abs_host_string'
36+
use_token = false
37+
cmd = Ssh.command_string(verbose, service, host_os, use_token)
38+
expect(cmd).to match(/ssh [email protected]/)
39+
end
40+
41+
it 'gets a hostname string for vmpooler' do
42+
verbose = false
43+
service = ServiceStub.new
44+
host_os = 'vmpooler_host_string'
45+
use_token = false
46+
cmd = Ssh.command_string(verbose, service, host_os, use_token)
47+
expect(cmd).to match(/ssh [email protected]/)
48+
end
49+
end

0 commit comments

Comments
 (0)