Skip to content
This repository was archived by the owner on Aug 30, 2018. It is now read-only.

Commit 61c7ec6

Browse files
committed
feature: Static machine support
Support tests on real machinge (no vm provisoring). See config/worker.example.static_machine.yml
1 parent fb3fd63 commit 61c7ec6

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
env: linux
2+
queue: builds.linux.static
3+
linux:
4+
amqp:
5+
host: localhost
6+
port: 5672
7+
username: travisci_worker
8+
password: travisci_worker_password
9+
virtual_host: travisci.development
10+
vms:
11+
provider: static_machine
12+
count: 2
13+
static_machine:
14+
username: travis
15+
private_key_path: /path/to/kay/id_rsa
16+
ip: [192.168.1.100, 192.168.1.101]
17+
port: 22
18+
language_mappings:
19+
haskell: jvm
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
require 'travis/support'
2+
require 'travis/worker/ssh/session'
3+
4+
module Travis
5+
module Worker
6+
module VirtualMachine
7+
class StaticMachine
8+
include Logging
9+
10+
class << self
11+
def vm_count
12+
Travis::Worker.config.vms.count
13+
end
14+
15+
def vm_names
16+
vm_count.times.map { |num| "#{Travis::Worker.config.vms.name_prefix}-#{num + 1}" }
17+
end
18+
end
19+
20+
log_header { "#{name}:worker:virtual_machine:static_machine" }
21+
22+
attr_reader :name, :ip
23+
24+
def initialize(name)
25+
@name = name
26+
end
27+
28+
def prepare
29+
info "static_machine API adapter prepared"
30+
end
31+
32+
def sandboxed(opts = {})
33+
create_server(opts)
34+
yield
35+
ensure
36+
session.close if @session
37+
destroy_server(opts)
38+
end
39+
40+
def create_server(opts = {})
41+
@ips = Array(Travis::Worker.config.static_machine.ip)
42+
raise "The static_machine provider requires the static_machine.ip field in config file!" unless @ips
43+
raise "Defined count of static_machine.ip differ form vms.count" if @ips.size != Travis::Worker.config.vms.count
44+
end
45+
46+
def destroy_server(opts = {})
47+
@session = nil
48+
end
49+
50+
def session
51+
#create_server unless clone
52+
@session ||= Ssh::Session.new(name,
53+
:host => ip_address,
54+
:port => Travis::Worker.config.static_machine.port || 22,
55+
:username => Travis::Worker.config.static_machine.username,
56+
:private_key_path => Travis::Worker.config.static_machine.private_key_path,
57+
:buffer => Travis::Worker.config.shell.buffer,
58+
:timeouts => Travis::Worker.config.timeouts,
59+
)
60+
end
61+
62+
def full_name
63+
"#{Travis::Worker.config.host}:travis-#{name}-#{ip}"
64+
end
65+
66+
private
67+
68+
def worker_number
69+
/\w+-(\d+)/.match(name)[1].to_i
70+
end
71+
72+
def ip_address
73+
@ips[worker_number - 1]
74+
end
75+
76+
77+
end
78+
end
79+
end
80+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'travis/worker/virtual_machine/static_machine'
2+
require 'travis/worker/ssh/session'
3+
require 'travis/worker'
4+
require 'pp'
5+
require 'hashr'
6+
7+
module Travis::Worker::VirtualMachine
8+
describe StaticMachine do
9+
before do
10+
Travis::Worker.config.static_machine = Struct.new(nil, :ip, :port, :username, :private_key_path).new(['192.168.0.1', '192.168.0.2'], 22, 'travis')
11+
Travis::Worker.config.vms.count = 2
12+
end
13+
14+
let(:static_machine1) {described_class.new('foo-1')}
15+
let(:static_machine2) {described_class.new('foo-2')}
16+
17+
it 'assigns righe IP according to worker number' do
18+
19+
static_machine1.sandboxed({}) do
20+
static_machine1.session
21+
expect(static_machine1.send(:ip_address)).to eq('192.168.0.1')
22+
end
23+
static_machine2.sandboxed({}) do
24+
static_machine2.session
25+
expect(static_machine2.send(:ip_address)).to eq('192.168.0.2')
26+
end
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)