1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace|monitoring] adding model tests for agent_token, check, and entity; added destroy method to agent_token and check models; updated models to retrieve identity from header value 'X-Object-ID'; updated check model to take an entity object or id

This commit is contained in:
Kyle Rames 2013-07-26 14:06:32 -05:00
parent 0f5a91b879
commit faf3a1d5d7
10 changed files with 141 additions and 6 deletions

View file

@ -24,12 +24,17 @@ module Fog
raise NotImplementedError.new "Updating Agent Tokens is not currently implemented"
else
data = service.create_agent_token(params)
self.id = data.headers['X-Object-ID']
end
true
end
end
def destroy
requires :id
service.delete_agent_token(id)
end
end
end
end
end

View file

@ -8,7 +8,6 @@ module Fog
identity :id
attribute :entity
attribute :entity_id
attribute :label
attribute :metadata
@ -22,6 +21,10 @@ module Fog
attribute :disabled
attribute :monitoring_zones_poll
def entity=(obj)
attributes[:entity] = obj.is_a?(String) ? Entity.new(:id => obj) : obj
end
def params(options={})
h = {
'label' => label,
@ -41,15 +44,21 @@ module Fog
def save
if identity
data = service.update_check(entity_id, identity, params)
data = service.update_check(entity.id, identity, params)
else
requires :type
options = params('type' => type)
data = service.create_check(entity_id, options)
data = service.create_check(entity.id, options)
self.id = data.headers['X-Object-ID']
end
true
end
def destroy
requires :id
service.delete_check(entity.id, id)
end
def metrics
@metrics ||= begin
Fog::Rackspace::Monitoring::Metrics.new(

View file

@ -25,12 +25,12 @@ module Fog
end
def new(attributes = {})
requires :entity
requires :entity unless attributes[:entity]
super({ :entity => entity }.merge!(attributes))
end
def create(attributes = {})
requires :entity
requires :entity unless attributes[:entity]
super({ :entity => entity }.merge!(attributes))
end

View file

@ -30,6 +30,7 @@ module Fog
data = service.update_entity(identity, params)
else
data = service.create_entity(params)
self.id = data.headers['X-Object-ID']
end
true
end

View file

@ -0,0 +1,9 @@
Shindo.tests('Fog::Rackspace::Monitoring | agent token', ['rackspace','rackspace_monitoring']) do
service = Fog::Rackspace::Monitoring.new
options = { :label => "fog_#{Time.now.to_i.to_s}" }
model_tests(service.agent_tokens, options, false) do
end
end

View file

@ -0,0 +1,9 @@
Shindo.tests('Fog::Rackspace::Monitoring | agent tokens', ['rackspace','rackspace_monitoring']) do
service = Fog::Rackspace::Monitoring.new
options = { :label => "fog_#{Time.now.to_i.to_s}" }
collection_tests(service.agent_tokens, options, false) do
end
end

View file

@ -0,0 +1,49 @@
Shindo.tests('Fog::Rackspace::Monitoring | check', ['rackspace','rackspace_monitoring']) do
service = Fog::Rackspace::Monitoring.new
tests('#entity=') do
tests('should create new entity if object is a string') do
check = Fog::Rackspace::Monitoring::Check.new
id = "123123"
check.entity = "123123"
returns(Fog::Rackspace::Monitoring::Entity) { check.entity.class }
returns(id) { check.entity.id }
end
tests('should set entity if object is an entity') do
id = "555"
entity = Fog::Rackspace::Monitoring::Entity.new(:id => id)
check = Fog::Rackspace::Monitoring::Check.new
check.entity = entity
returns(Fog::Rackspace::Monitoring::Entity) { check.entity.class }
returns(id) { check.entity.id }
end
end
begin
@entity = service.entities.create :label => "fog_#{Time.now.to_i.to_s}"
options = CHECK_CREATE_OPTIONS.merge(:label => "fog_#{Time.now.to_i.to_s}", :entity => @entity)
collection = service.checks(:entity => @entity)
model_tests(collection, options, false) do
tests('#update').succeeds do
new_label = "new_label_#{Time.now.to_i.to_s}"
@instance.label = new_label
timeout = 2
@instance.timeout = 2
@instance.save
@instance.timeout = -1 # blank out timeout just to make sure
@instance.label = nil # blank out label just to make sure
@instance.reload
returns(timeout) { @instance.timeout }
returns(new_label) { @instance.label}
end
tests('#metrics').succeeds do
@instance.metrics
end
end
ensure
@entity.destroy unless @entity
end
end

View file

@ -0,0 +1,15 @@
Shindo.tests('Fog::Rackspace::Monitoring | checks', ['rackspace','rackspace_monitoring']) do
service = Fog::Rackspace::Monitoring.new
begin
@entity = service.entities.create :label => "fog_#{Time.now.to_i.to_s}"
options = CHECK_CREATE_OPTIONS.merge(:label => "fog_#{Time.now.to_i.to_s}", :entity => @entity)
collection = service.checks(:entity => @entity)
collection_tests(collection, options, false) do
end
ensure
@entity.destroy if @entity
end
end

View file

@ -0,0 +1,13 @@
Shindo.tests('Fog::Rackspace::Monitoring | entities', ['rackspace','rackspace_monitoring']) do
service = Fog::Rackspace::Monitoring.new
options = { :label => "fog_#{Time.now.to_i.to_s}", :ip_addresses => {:default => "127.0.0.1"} }
collection_tests(service.entities, options, false) do
end
tests('overview').succeeds do
service.entities.overview
end
end

View file

@ -0,0 +1,25 @@
Shindo.tests('Fog::Rackspace::Monitoring | entity', ['rackspace','rackspace_monitoring']) do
service = Fog::Rackspace::Monitoring.new
options = { :label => "fog_#{Time.now.to_i.to_s}", :ip_addresses => {:default => "127.0.0.1"} }
model_tests(service.entities, options, false) do
tests('#update').succeeds do
new_label = "new_label_#{Time.now.to_i.to_s}"
@instance.label = new_label
@instance.save
@instance.label = nil # blank out label just to make sure
@instance.reload
returns(new_label) { @instance.label }
end
tests('#checks').succeeds do
@instance.checks
end
tests('#alarms').succeeds do
@instance.alarms
end
end
end