Skip to content

Commit

Permalink
Merge pull request #41 from steve-jansen/service-net
Browse files Browse the repository at this point in the history
Support for using the ServiceNet IP address for SSH connections
  • Loading branch information
hartmantis committed Sep 10, 2014
2 parents b42cd1d + b8f2c8c commit 094aa18
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ for your specified platform. Additional, optional overrides can be provided:

image_id: [SERVER IMAGE ID]
flavor_id: [SERVER FLAVOR ID]
server_name: [A UNIQUE SERVER NAME]
server_name: [A FRIENDLY SERVER NAME]
public_key_path: [PATH TO YOUR PUBLIC SSH KEY]
rackspace_region: [A VALID RACKSPACE DC/REGION]
wait_for: [NUM OF SECONDS TO WAIT BEFORE TIMING OUT, DEFAULT 600]
no_ssh_tcp_check: [DEFAULTS TO false, SKIPS TCP CHECK WHEN true]
no_ssh_tcp_check_sleep: [NUM OF SECONDS TO SLEEP IF no_ssh_tcp_check IS SET]
networks: [LIST OF RACKSPACE NETWORK UUIDS, DEFAULT PUBLICNET AND SERVICE NET]
rackconnect_wait: ['true' IF USING RACKCONNECT TO WAIT FOR IT TO COMPLETE]
servicenet: ['true' IF USING THE SERVICENET IP ADDRESS TO CONNECT]

You also have the option of providing some configs via environment variables:

Expand All @@ -66,7 +67,9 @@ Some configs are also derived based on your .ssh directory, specifically the
## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
2. `bundle install`
3. Create your feature branch (`git checkout -b my-new-feature`)
4. `bundle exec rake` must pass
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
11 changes: 10 additions & 1 deletion lib/kitchen/driver/rackspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Rackspace < Kitchen::Driver::SSHBase
default_config :no_ssh_tcp_check, false
default_config :no_ssh_tcp_check_sleep, 120
default_config :rackconnect_wait, false
default_config :servicenet, false
default_config(:image_id) { |driver| driver.default_image }
default_config(:server_name) { |driver| driver.default_name }
default_config :networks, nil
Expand Down Expand Up @@ -75,7 +76,7 @@ def create(state)
server.wait_for { ready? }
puts '(server ready)'
rackconnect_check(server) if config[:rackconnect_wait]
state[:hostname] = server.public_ip_address
state[:hostname] = hostname(server)
tcp_check(state)
rescue Fog::Errors::Error, Excon::Errors::Error => ex
raise ActionFailed, ex.message
Expand Down Expand Up @@ -156,6 +157,14 @@ def rackconnect_check(server)
server.update # refresh accessIPv4 with new IP
end

def hostname(server)
if config[:servicenet] == false
server.public_ip_address
else
server.private_ip_address
end
end

def networks
base_nets = %w(
00000000-0000-0000-0000-000000000000
Expand Down
108 changes: 107 additions & 1 deletion spec/kitchen/driver/rackspace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
it 'defaults to not waiting for rackconnect' do
expect(driver[:rackconnect_wait]).to eq(false)
end

it 'defaults to the public ip address' do
expect(driver[:servicenet]).to eq(false)
end
end

platforms = {
Expand Down Expand Up @@ -143,7 +147,8 @@
server_name: 'puppy',
rackspace_region: 'ord',
wait_for: 1200,
rackconnect_wait: true
rackconnect_wait: true,
use_private_ip_address: true
}

let(:config) { config }
Expand Down Expand Up @@ -223,7 +228,108 @@
driver.create(state)
end
end
end

describe '#create and rackconnect_wait' do
let(:server) do
double(id: 'test123',
wait_for: true,
public_ip_address: '1.2.3.4',
private_ip_address: '10.9.8.7',
update: nil)
end
let(:driver) do
d = Kitchen::Driver::Rackspace.new(config)
d.instance = instance
allow(d).to receive(:default_name).and_return('a_monkey!')
allow(d).to receive(:create_server).and_return(server)
allow(d).to receive(:tcp_check).and_return(true)
d
end

context 'username and API key only provided' do
let(:config) do
{
rackspace_username: 'hello',
rackspace_api_key: 'world',
wait_for: 1200,
rackconnect_wait: true
}
end

it 'generates a server name in the absence of one' do
driver.create(state)
expect(driver[:server_name]).to eq('a_monkey!')
end

it 'gets a proper server ID' do
driver.create(state)
expect(state[:server_id]).to eq('test123')
end

it 'gets a proper hostname (IP)' do
driver.create(state)
expect(state[:hostname]).to eq('1.2.3.4')
end

it 'calls tcp_check' do
expect(driver).to receive(:tcp_check)
driver.create(state)
end

it 'calls rackconnect_check ' do
expect(driver).to receive(:rackconnect_check)
driver.create(state)
end

it 'rackconnect_check waits for rackconnect_automation' do
expect(server).to receive(:wait_for)
driver.send(:rackconnect_check, server)
end
end
end

describe '#create and use_private_ip_address' do
let(:server) do
double(id: 'test123',
wait_for: true,
public_ip_address: '1.2.3.4',
private_ip_address: '10.9.8.7')
end
let(:driver) do
d = Kitchen::Driver::Rackspace.new(config)
d.instance = instance
allow(d).to receive(:default_name).and_return('a_monkey!')
allow(d).to receive(:create_server).and_return(server)
allow(d).to receive(:tcp_check).and_return(true)
d
end

context 'username and API key only provided' do
let(:config) do
{
rackspace_username: 'hello',
rackspace_api_key: 'world',
wait_for: 1200,
servicenet: true
}
end

it 'generates a server name in the absence of one' do
driver.create(state)
expect(driver[:server_name]).to eq('a_monkey!')
end

it 'gets a proper server ID' do
driver.create(state)
expect(state[:server_id]).to eq('test123')
end

it 'gets a private ip as the hostname' do
driver.create(state)
expect(state[:hostname]).to eq('10.9.8.7')
end
end
end

describe '#destroy' do
Expand Down

0 comments on commit 094aa18

Please sign in to comment.