You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2013/02/18 14:41:16 UTC
[PATCH core 6/8] Mock: Cleanup in how we create mock 'metrics'
From: Michal Fojtik <mf...@redhat.com>
Moved the code to the Metric model to keep MockDriver
clean.
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/deltacloud/models/metric.rb | 45 ++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/server/lib/deltacloud/models/metric.rb b/server/lib/deltacloud/models/metric.rb
index 7970565..1f7f422 100644
--- a/server/lib/deltacloud/models/metric.rb
+++ b/server/lib/deltacloud/models/metric.rb
@@ -18,6 +18,18 @@ class Metric < BaseModel
attr_accessor :entity
attr_accessor :properties
+ MOCK_METRICS_NAMES = [
+ 'cpuUtilization',
+ 'diskReadRequestCount',
+ 'diskReadSector',
+ 'diskWriteRequestCount',
+ 'diskWriteSector',
+ 'nicInputByte',
+ 'nicInputPacket',
+ 'nicOutputByte',
+ 'nicOutputPacket'
+ ]
+
def unknown?
self.entity == :unknown
end
@@ -51,6 +63,39 @@ class Metric < BaseModel
:values => values
}
end
+
+ def generate_mock_values!
+ generator = lambda { |name, kind|
+ v = {
+ :min => (1+(rand(49))),
+ :max => (50+(rand(50)))
+ }
+ (name == 'cpuUtilization') ? v[kind].to_f/100 : v[kind]
+ }
+ @values = (0..5).map do |v_id|
+ {
+ :minimum => min = generator.call(@name, :min),
+ :maximum => max = generator.call(@name, :max),
+ :average => (min+max)/2,
+ :timestamp => (Time.now-v_id).to_i,
+ :unit => unit_for(@name)
+ }
+ end
+ end
+
+ private
+
+ def unit_for(name)
+ case name
+ when /Utilization/ then 'Percent'
+ when /Byte/ then 'Bytes'
+ when /Sector/ then 'Count'
+ when /Count/ then 'Count'
+ when /Packet/ then 'Count'
+ else 'None'
+ end
+ end
+
end
end
--
1.8.1.2
Re: [PATCH core 6/8] Mock: Cleanup in how we create mock 'metrics'
Posted by David Lutterkort <lu...@redhat.com>.
On Mon, 2013-02-18 at 14:41 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> Moved the code to the Metric model to keep MockDriver
> clean.
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/lib/deltacloud/models/metric.rb | 45 ++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
ACK