Skip to content
This repository was archived by the owner on Aug 30, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions LICENSE.avg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MIT LICENSE

Copyright (c) 2015 AVG Technologies CZ, s.r.o.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
File renamed without changes.
19 changes: 19 additions & 0 deletions config/worker.example.static_machine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
env: linux
queue: builds.linux.static
linux:
amqp:
host: localhost
port: 5672
username: travisci_worker
password: travisci_worker_password
virtual_host: travisci.development
vms:
provider: static_machine
count: 2
static_machine:
username: travis
private_key_path: /path/to/kay/id_rsa
ip: [192.168.1.100, 192.168.1.101]
port: 22
language_mappings:
haskell: jvm
80 changes: 80 additions & 0 deletions lib/travis/worker/virtual_machine/static_machine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'travis/support'
require 'travis/worker/ssh/session'

module Travis
module Worker
module VirtualMachine
class StaticMachine
include Logging

class << self
def vm_count
Travis::Worker.config.vms.count
end

def vm_names
vm_count.times.map { |num| "#{Travis::Worker.config.vms.name_prefix}-#{num + 1}" }
end
end

log_header { "#{name}:worker:virtual_machine:static_machine" }

attr_reader :name, :ip

def initialize(name)
@name = name
end

def prepare
info "static_machine API adapter prepared"
end

def sandboxed(opts = {})
create_server(opts)
yield
ensure
session.close if @session
destroy_server(opts)
end

def create_server(opts = {})
@ips = Array(Travis::Worker.config.static_machine.ip)
raise "The static_machine provider requires the static_machine.ip field in config file!" unless @ips
raise "Defined count of static_machine.ip differ form vms.count" if @ips.size != Travis::Worker.config.vms.count
end

def destroy_server(opts = {})
@session = nil
end

def session
#create_server unless clone
@session ||= Ssh::Session.new(name,
:host => ip_address,
:port => Travis::Worker.config.static_machine.port || 22,
:username => Travis::Worker.config.static_machine.username,
:private_key_path => Travis::Worker.config.static_machine.private_key_path,
:buffer => Travis::Worker.config.shell.buffer,
:timeouts => Travis::Worker.config.timeouts,
)
end

def full_name
"#{Travis::Worker.config.host}:travis-#{name}-#{ip}"
end

private

def worker_number
/\w+-(\d+)/.match(name)[1].to_i
end

def ip_address
@ips[worker_number - 1]
end


end
end
end
end
29 changes: 29 additions & 0 deletions spec/virtual_machine/static_machine_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'travis/worker/virtual_machine/static_machine'
require 'travis/worker/ssh/session'
require 'travis/worker'
require 'pp'
require 'hashr'

module Travis::Worker::VirtualMachine
describe StaticMachine do
before do
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')
Travis::Worker.config.vms.count = 2
end

let(:static_machine1) {described_class.new('foo-1')}
let(:static_machine2) {described_class.new('foo-2')}

it 'assigns righe IP according to worker number' do

static_machine1.sandboxed({}) do
static_machine1.session
expect(static_machine1.send(:ip_address)).to eq('192.168.0.1')
end
static_machine2.sandboxed({}) do
static_machine2.session
expect(static_machine2.send(:ip_address)).to eq('192.168.0.2')
end
end
end
end