ACK with two notes:
- cpus/memory/storage left in "reset" method of quota controller and 
"View Pool's Quota Usage" scenario of pool cuke test. Tests passed after 
removing it.
- quota is not checked when creating/starting instance in condormatic 
util, but it's not part of this patch (will be added by condor guys)

Dne 26.8.2010 12:43, mtay...@redhat.com napsal(a):
> From: martyntaylor<mtay...@redhat.com>
>
> ---
>   src/app/models/instance_observer.rb                |    8 +---
>   src/app/models/quota.rb                            |   42 
> +++++++-------------
>   src/app/services/data_service_active_record.rb     |    6 ---
>   src/app/views/quota/edit.html.erb                  |    3 -
>   src/db/migrate/20090802000000_create_quotas.rb     |    6 ---
>   src/spec/factories/quota.rb                        |    6 ---
>   src/spec/models/instance_observer_spec.rb          |   14 -------
>   .../services/data_service_active_record_spec.rb    |   21 +--------
>   8 files changed, 18 insertions(+), 88 deletions(-)
>
> diff --git a/src/app/models/instance_observer.rb 
> b/src/app/models/instance_observer.rb
> index 610d742..70537ac 100644
> --- a/src/app/models/instance_observer.rb
> +++ b/src/app/models/instance_observer.rb
> @@ -43,20 +43,14 @@ class InstanceObserver<  ActiveRecord::Observer
>           if quota
>         if state_to == Instance::STATE_RUNNING
>           quota.running_instances += 1
> -         quota.running_memory =  quota.running_memory.to_f + 
> hwp.memory.value.to_f
> -         quota.running_cpus = quota.running_cpus.to_f + hwp.cpu.value.to_f
>         elsif state_from == Instance::STATE_RUNNING
>           quota.running_instances -= 1
> -         quota.running_memory = quota.running_memory.to_f - 
> hwp.memory.value.to_f
> -         quota.running_cpus = quota.running_cpus.to_f - hwp.cpu.value.to_f
>         end
>
>         if state_from != nil
>           if !ACTIVE_STATES.include?(state_from)&&  
> ACTIVE_STATES.include?(state_to)
> -           quota.total_storage = quota.total_storage.to_f + 
> hwp.storage.value.to_f
>             quota.total_instances += 1
> -            elsif ACTIVE_STATES.include?(state_from)&&  
> !ACTIVE_STATES.include?(state_to)
> -           quota.total_storage = quota.total_storage.to_f - 
> hwp.storage.value.to_f
> +      elsif ACTIVE_STATES.include?(state_from)&&  
> !ACTIVE_STATES.include?(state_to)
>             quota.total_instances -= 1
>           end
>             end
> diff --git a/src/app/models/quota.rb b/src/app/models/quota.rb
> index bd228b3..f882878 100644
> --- a/src/app/models/quota.rb
> +++ b/src/app/models/quota.rb
> @@ -21,63 +21,49 @@
>
>   class Quota<  ActiveRecord::Base
>
> +  has_one :pool
> +  has_one :cloud_account
> +
>     QuotaResource = Struct.new(:name, :used, :max, :available, :unit)
>
>     NO_LIMIT = nil
>
>     RESOURCE_RUNNING_INSTANCES = "running_instances"
> -  RESOURCE_RUNNING_MEMORY = "running_memory"
> -  RESOURCE_RUNNING_CPUS = "running_cpus"
>     RESOURCE_TOTAL_INSTANCES = "total_instances"
> -  RESOURCE_TOTAL_STORAGE = "total_storage"
>     RESOURCE_OVERALL = "overall"
>
> -  RESOURCE_NAMES = [ RESOURCE_RUNNING_INSTANCES, RESOURCE_RUNNING_MEMORY, 
> RESOURCE_RUNNING_CPUS,
> -                RESOURCE_TOTAL_INSTANCES, RESOURCE_TOTAL_STORAGE ]
> -
> -  has_one :pool
> -  has_one :cloud_account
> +  RESOURCE_NAMES = [ RESOURCE_RUNNING_INSTANCES, RESOURCE_TOTAL_INSTANCES ]
>
>     def can_create_instance?(instance)
> -    hwp = instance.hardware_profile
> -
> -    potential_total_storage = total_storage.to_f + hwp.storage.value.to_f
>       potential_total_instances = total_instances + 1
> -
> -    # check for no quota
> -    if (Quota.no_limit(maximum_total_instances) || maximum_total_instances>= 
> potential_total_instances)&&
> -       (Quota.no_limit(maximum_total_storage) || 
> maximum_total_storage.to_f>= potential_total_storage.to_f)
> +    if (Quota.no_limit(maximum_total_instances) || maximum_total_instances>= 
> potential_total_instances)
>            return true
>       end
>       return false
>     end
>
>     def can_start_instance?(instance)
> -    hwp = instance.hardware_profile
> -
>       potential_running_instances = running_instances + 1
> -    potential_running_memory = running_memory.to_f + hwp.memory.value.to_f
> -    potential_running_cpus = running_cpus.to_f + hwp.cpu.value.to_f
> -
> -    if (Quota.no_limit(maximum_running_instances) || 
> maximum_running_instances>= potential_running_instances)&&
> -       (Quota.no_limit(maximum_running_memory) || 
> maximum_running_memory.to_f>= potential_running_memory)&&
> -       (Quota.no_limit(maximum_running_cpus) || maximum_running_cpus.to_f>= 
> potential_running_cpus)
> +    if (Quota.no_limit(maximum_running_instances) || 
> maximum_running_instances>= potential_running_instances)
>            return true
>       end
>       return false
>     end
>
>     def quota_resources()
> -    quota_resources =  {"running_instances" =>  QuotaResource.new("Running 
> Instances", running_instances, maximum_running_instances, 
> maximum_running_instances.to_f - running_instances.to_f, ""),
> -            "running_memory" =>  QuotaResource.new("Running Memory", 
> running_memory, maximum_running_memory, maximum_running_memory.to_f - 
> running_memory.to_f, "MB"),
> -            "running_cpus" =>  QuotaResource.new("Running CPUs", 
> running_cpus, maximum_running_cpus, maximum_running_cpus.to_f - 
> running_cpus.to_f, ""),
> -            "total_instances" =>  QuotaResource.new("Total Instances", 
> total_instances, maximum_total_instances, maximum_total_instances.to_f - 
> total_instances.to_f, ""),
> -            "total_storage" =>  QuotaResource.new("Total Storage", 
> total_storage, maximum_total_storage, maximum_total_storage.to_f - 
> total_storage.to_f, "GB")}
> +    quota_resources =  {"running_instances" =>  QuotaResource.new("Running 
> Instances", running_instances, maximum_running_instances, nil, ""),
> +            "total_instances" =>  QuotaResource.new("Total Instances", 
> total_instances, maximum_total_instances, nil, "")}
>
>       quota_resources.each_value do |quota_resource|
>         if Quota.no_limit(quota_resource.max)
>           quota_resource.max = "No Limit"
>           quota_resource.available = "N\A"
> +      else
> +        quota_resource.available = quota_resource.max - quota_resource.used
> +        if quota_resource.available<  0
> +          quota_resource.available = quota_resource.available * -1
> +          quota_resource.available = "OverLimit By: " + 
> quota_resource.available.to_s
> +        end
>         end
>       end
>
> diff --git a/src/app/services/data_service_active_record.rb 
> b/src/app/services/data_service_active_record.rb
> index 1165621..68769ab 100644
> --- a/src/app/services/data_service_active_record.rb
> +++ b/src/app/services/data_service_active_record.rb
> @@ -55,14 +55,8 @@ class DataServiceActiveRecord
>           case resource_name
>             when Quota::RESOURCE_RUNNING_INSTANCES
>               return QuotaUsagePoint.new(quota.running_instances, 
> quota.maximum_running_instances)
> -          when Quota::RESOURCE_RUNNING_MEMORY
> -            return QuotaUsagePoint.new(quota.running_memory.to_f, 
> quota.maximum_running_memory.to_f)
> -          when Quota::RESOURCE_RUNNING_CPUS
> -            return QuotaUsagePoint.new(quota.running_cpus.to_f, 
> quota.maximum_running_cpus.to_f)
>             when Quota::RESOURCE_TOTAL_INSTANCES
>               return QuotaUsagePoint.new(quota.total_instances, 
> quota.maximum_total_instances)
> -          when Quota::RESOURCE_TOTAL_STORAGE
> -            return QuotaUsagePoint.new(quota.total_storage.to_f, 
> quota.maximum_total_storage.to_f)
>             when Quota::RESOURCE_OVERALL
>               return self.overall_usage(parent)
>             else
> diff --git a/src/app/views/quota/edit.html.erb 
> b/src/app/views/quota/edit.html.erb
> index 5e742bb..8d9ae97 100644
> --- a/src/app/views/quota/edit.html.erb
> +++ b/src/app/views/quota/edit.html.erb
> @@ -10,10 +10,7 @@
>
>       <ul>
>         <li><label>Max Running Instances</label><%= text_field :quota, 
> :maximum_running_instances %></li>
> -     <li><label>Max Running Memory</label><%= text_field :quota, 
> :maximum_running_memory %></li>
> -     <li><label>Max Running CPUs</label><%= text_field :quota, 
> :maximum_running_cpus %></li>
>       <li><label>Max Total Instances</label><%= text_field :quota, 
> :maximum_total_instances %></li>
> -     <li><label>Max Total Storage</label><%= text_field :quota, 
> :maximum_total_storage %></li>
>       </ul>
>       </fieldset>
>       <%= submit_tag "Save", :class =>  "submit" %>
> diff --git a/src/db/migrate/20090802000000_create_quotas.rb 
> b/src/db/migrate/20090802000000_create_quotas.rb
> index bfd195b..6456ff2 100644
> --- a/src/db/migrate/20090802000000_create_quotas.rb
> +++ b/src/db/migrate/20090802000000_create_quotas.rb
> @@ -20,15 +20,9 @@
>   class CreateQuotas<  ActiveRecord::Migration
>     def self.up
>       create_table :quotas do |t|
> -      t.string :running_cpus, :default =>  0
> -      t.string  :running_memory, :default =>  0
>         t.integer :running_instances, :default =>  0
> -      t.string  :total_storage, :default =>  0
>         t.integer :total_instances, :default =>  0
> -      t.string :maximum_running_cpus, :default =>  nil
> -      t.string  :maximum_running_memory, :default =>  nil
>         t.integer :maximum_running_instances, :default =>  nil
> -      t.string  :maximum_total_storage, :default =>  nil
>         t.integer :maximum_total_instances, :default =>  nil
>         t.integer :lock_version, :default =>  0
>         t.timestamps
> diff --git a/src/spec/factories/quota.rb b/src/spec/factories/quota.rb
> index 3f519ca..92c832f 100644
> --- a/src/spec/factories/quota.rb
> +++ b/src/spec/factories/quota.rb
> @@ -1,15 +1,9 @@
>   Factory.define :quota do |f|
>     f.maximum_running_instances 10
> -  f.maximum_running_memory "10240"
> -  f.maximum_running_cpus 20
>     f.maximum_total_instances 15
> -  f.maximum_total_storage "8500"
>   end
>
>   Factory.define :full_quota, :parent =>  :quota do |f|
>     f.running_instances 10
> -  f.running_memory "10240"
> -  f.running_cpus 20
>     f.total_instances 15
> -  f.total_storage "8500"
>   end
> \ No newline at end of file
> diff --git a/src/spec/models/instance_observer_spec.rb 
> b/src/spec/models/instance_observer_spec.rb
> index 6bcb4d0..ae5ee0d 100644
> --- a/src/spec/models/instance_observer_spec.rb
> +++ b/src/spec/models/instance_observer_spec.rb
> @@ -98,9 +98,7 @@ describe InstanceObserver do
>     it "should not update quota on pool and cloud account when an instance is 
> state new" do
>       [...@cloud_account_quota, @pool_quota].each do |quota|
>         quota = Quota.find(quota)
> -
>         quota.total_instances.should == 0
> -      quota.total_storage.to_f.should == 0.to_f
>       end
>     end
>
> @@ -110,9 +108,7 @@ describe InstanceObserver do
>         @instance.save
>
>         quota = Quota.find(quota)
> -
>         quota.total_instances.should == 1
> -      quota.total_storage.to_f.should == @hwp.storage.value.to_f
>       end
>     end
>
> @@ -122,9 +118,7 @@ describe InstanceObserver do
>
>       [...@cloud_account_quota, @pool_quota].each do |quota|
>         quota = Quota.find(quota)
> -
>         quota.total_instances.should == 0
> -      quota.total_storage.to_f.should == 0.to_f
>       end
>     end
>
> @@ -135,10 +129,6 @@ describe InstanceObserver do
>       [...@cloud_account_quota, @pool_quota].each do |quota|
>         quota = Quota.find(quota.id)
>         quota.running_instances.should == 1
> -      quota.running_memory.to_f.should == @hwp.memory.value.to_f
> -      quota.running_cpus.to_f.should == @hwp.cpu.value.to_f
> -
> -      quota.total_storage.to_f.should == @hwp.storage.value.to_f
>         quota.total_instances.should == 1
>       end
>     end
> @@ -153,11 +143,7 @@ describe InstanceObserver do
>       [...@cloud_account_quota, @pool_quota].each do |quota|
>         quota = Quota.find(quota.id)
>
> -      #TODO test for cpus
>         quota.running_instances.should == 0
> -      quota.running_memory.to_f.should == 0.to_f
> -
> -      quota.total_storage.to_f.should == @hwp.storage.value.to_f
>         quota.total_instances.should == 1
>       end
>     end
> diff --git a/src/spec/services/data_service_active_record_spec.rb 
> b/src/spec/services/data_service_active_record_spec.rb
> index 7dd6b50..9842146 100644
> --- a/src/spec/services/data_service_active_record_spec.rb
> +++ b/src/spec/services/data_service_active_record_spec.rb
> @@ -42,34 +42,19 @@ describe DataServiceActiveRecord do
>
>       quota = Factory(:quota,
>                       :maximum_running_instances =>  40,
> -                    :maximum_running_memory =>  10240,
> -                    :maximum_running_cpus =>  10,
>                       :maximum_total_instances =>  50,
> -                    :maximum_total_storage =>  500,
>                       :running_instances =>  20,
> -                    :running_memory =>  4096,
> -                    :running_cpus =>  7,
> -                    :total_instances =>  20,
> -                    :total_storage =>  499)
> +                    :total_instances =>  20)
>       cloud_account.quota_id = quota.id
>
>       data_point = DataServiceActiveRecord.quota_usage(cloud_account, 
> Quota::RESOURCE_RUNNING_INSTANCES)
>       data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(20, 
> 40)
>
> -    data_point = DataServiceActiveRecord.quota_usage(cloud_account, 
> Quota::RESOURCE_RUNNING_MEMORY)
> -    data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(4096, 
> 10240)
> -
> -    data_point = DataServiceActiveRecord.quota_usage(cloud_account, 
> Quota::RESOURCE_RUNNING_CPUS)
> -    data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(7, 10)
> -
>       data_point = DataServiceActiveRecord.quota_usage(cloud_account, 
> Quota::RESOURCE_TOTAL_INSTANCES)
>       data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(20, 
> 50)
>
> -    data_point = DataServiceActiveRecord.quota_usage(cloud_account, 
> Quota::RESOURCE_TOTAL_STORAGE)
> -    data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(499, 
> 500)
> -
>       data_point = DataServiceActiveRecord.quota_usage(cloud_account, 
> Quota::RESOURCE_OVERALL)
> -    data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(499, 
> 500)
> +    data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(20, 40)
>     end
>
>     it "should calculate the average, max and min task submission times" do
> @@ -367,4 +352,4 @@ describe DataServiceActiveRecord do
>         interval_time += interval_length
>       end
>     end
> -end
> \ No newline at end of file
> +end

_______________________________________________
deltacloud-devel mailing list
deltacloud-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to