Skip to content

Commit

Permalink
Replace fog_tracker binary with 'rake track'
Browse files Browse the repository at this point in the history
  • Loading branch information
Benton Roberts committed Mar 21, 2012
1 parent c2451b8 commit 47acc10
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 83 deletions.
73 changes: 0 additions & 73 deletions bin/fog_tracker

This file was deleted.

File renamed without changes.
8 changes: 8 additions & 0 deletions lib/fog_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def self.default_logger(output = nil)
logger
end

# Loads account information defined in account_file.
# @param account_file the path to a YAML file (see accounts.example.yml).
# @return [Hash] the cleaned, validated Hash of account info.
def self.read_accounts(account_file = ENV['ACCOUNT_FILE'])
account_file ||= "./config/accounts.yml"
FogTracker.validate_accounts(YAML::load(File.read account_file))
end

# Performs validation and cleanup on an Array of account Hashes.
# Changes Strings to Symbols for all required keys.
# @param [Hash] account_array an Array of Hash objects.
Expand Down
6 changes: 3 additions & 3 deletions lib/fog_tracker/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module FogTracker
# Tracks one or more Fog accounts and exposes a {#query} on the results
class Tracker

#a Hash of account information (see accounts.yml.example)
#a Hash of account information (see accounts.example.yml)
attr_reader :accounts

# Creates an object for tracking multiple Fog accounts
# @param [Hash] accounts a Hash of account information
# (see accounts.yml.example)
# (see accounts.example.yml)
# @param [Hash] options optional additional parameters:
# - :delay (Integer) - Default time between polling of accounts
# - :callback (Proc) - A Method or Proc to call each time an account is polled.
Expand Down Expand Up @@ -105,7 +105,7 @@ def logger ; @log end
# Sets the account information.
# If any account info has changed, all trackers are restarted.
# @param [Hash] accounts a Hash of account information
# (see accounts.yml.example)
# (see accounts.example.yml)
def accounts=(new_accounts)
old_accounts = @accounts
@accounts = FogTracker.validate_accounts(new_accounts)
Expand Down
15 changes: 15 additions & 0 deletions lib/tasks/track.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
desc "Runs the tracker [LOG_LEVEL=[INFO]]"
task :track do
require File.join(File.dirname(__FILE__), '..', 'fog_tracker')

# Setup logging
log = FogTracker.default_logger(STDOUT)
log.level = ::Logger.const_get((ENV['LOG_LEVEL'] || 'INFO').to_sym)

log.info "Loading account information..."
accounts = FogTracker.read_accounts './config/accounts.yml'

FogTracker::Tracker.new(accounts, {:logger => log}).start
while true do ; sleep 60 end # Loop forever

end
22 changes: 15 additions & 7 deletions spec/lib/fog_tracker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
module FogTracker


describe '#read_accounts' do
it "converts a YAML file into a Hash of account info" do
accounts = FogTracker.read_accounts('./config/accounts.example.yml')
accounts.should be_a Hash
accounts.should_not be_empty
end
end

describe '#validate_accounts' do
it "should raise an exception when no service is specified" do
it "raises an exception when no service is specified" do
(Proc.new { FogTracker.validate_accounts(
FAKE_ACCOUNT_NAME => FAKE_ACCOUNT.merge({:service => nil})
)}).should raise_error
end
it "should raise an exception when no provider is specified" do

it "raises an exception when no provider is specified" do
(Proc.new { FogTracker.validate_accounts(
FAKE_ACCOUNT_NAME => FAKE_ACCOUNT.merge({:provider => nil})
)}).should raise_error
end
it "should raise an exception when no credentials are specified" do

it "raises an exception when no credentials are specified" do
(Proc.new { FogTracker.validate_accounts(
FAKE_ACCOUNT_NAME => FAKE_ACCOUNT.merge({:credentials => nil})
)}).should raise_error
end

it "should symbolize all account keys" do
it "symbolizes all account keys" do
validated_accounts = FogTracker.validate_accounts(
FAKE_ACCOUNT_NAME => {
'provider' => 'AWS',
Expand Down

0 comments on commit 47acc10

Please sign in to comment.