[PATCH conductor] fix for BZ #761509: User quota and other stats
Scott Seago
sseago at redhat.com
Fri Dec 9 13:33:28 UTC 2011
The summary page at /pools was giving confusing (and incorrect) stats. Changes are as follows:
Pools:
before: number of pools the user has view permissions on
after: number of pools the user has permission to launch deployments in
Deployments:
before: number of deployments the user has view permission on
after: number of deployments owned (i.e. launched) by the user
Instances:
before: number of instances the user has view permissions on
after: number of instances owned (i.e. launched) by the user
Quota Used:
before: aggregated stats for environment quotas on all environments
that the user has view permisions on. This was the cause
of the BZ report, as by default, non-admin users have no
direct permissions on the default environment -- only on
the contained default pool. So for non-admin users
this showed 0 of 0, since it was an aggregation over
0 environments.
after: user quota stats.
I've also updated the labels for the Overview to show "User Quota Usage" instead of "Quota Usage" and, for the Pool view, "Pool Quota Usage" instead of "Quota Usage" to clarify which quota measurement is being applied.
---
src/app/controllers/pools_controller.rb | 14 ++++++--------
src/app/views/pools/_scoreboard_index.html.haml | 10 ++++++----
src/app/views/pools/_scoreboard_show.html.haml | 4 +++-
src/features/pool.feature | 2 +-
src/features/step_definitions/instance_steps.rb | 6 ++++++
5 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index cc13278..3918d14 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -35,8 +35,7 @@ class PoolsController < ApplicationController
clear_breadcrumbs
save_breadcrumb(pools_path(:viewstate => viewstate_id))
- @user_pools = Pool.list_for_user(current_user, Privilege::VIEW)
- @user_pool_families = PoolFamily.list_for_user(current_user, Privilege::VIEW)
+ @user_pools = Pool.list_for_user(current_user, Privilege::CREATE, Deployment)
if filter_view?
@tabs = [{:name => "#{t'pools.pools'}", :view => 'list', :id => 'pools'},
{:name => "#{t'deployments.deployments'}", :view => 'deployments/list', :id => 'deployments'},
@@ -295,18 +294,17 @@ class PoolsController < ApplicationController
end
def statistics
- instances = Instance.list_for_user(current_user, Privilege::VIEW)
- pf_max_quotas = @user_pool_families.collect {|pf| pf.quota.maximum_running_instances}
+ instances = current_user.owned_instances
@failed_instances = instances.select {|instance| instance.state == Instance::STATE_CREATE_FAILED || instance.state == Instance::STATE_ERROR}
@statistics = {
:pools_in_use => @user_pools.collect { |pool| pool.instances.pending.count > 0 || pool.instances.deployed.count > 0 }.count,
- :deployments => Deployment.list_for_user(current_user, Privilege::VIEW).count,
+ :deployments => current_user.deployments.count,
:instances => instances.count,
:instances_pending => instances.select {|instance| instance.state == Instance::STATE_NEW || instance.state == Instance::STATE_PENDING}.count,
:instances_failed => @failed_instances.count,
- :pf_available_quota => pf_max_quotas.compact.size != @user_pool_families.size ? nil : @user_pool_families.collect{|pf| pf.quota.maximum_running_instances}.inject(0){|sum, n| sum + n},
- :pf_running_instances => @user_pool_families.collect{|pf| pf.quota.running_instances}.inject(0){|sum, n| sum + n},
- :pf_used_percentage => @user_pool_families.collect {|pf| pf.quota.percentage_used}.inject(0){|sum, n| sum + n}
+ :user_available_quota => current_user.quota.maximum_running_instances,
+ :user_running_instances => current_user.quota.running_instances,
+ :user_used_percentage => current_user.quota.percentage_used
}
end
end
diff --git a/src/app/views/pools/_scoreboard_index.html.haml b/src/app/views/pools/_scoreboard_index.html.haml
index 4987850..f264dd5 100644
--- a/src/app/views/pools/_scoreboard_index.html.haml
+++ b/src/app/views/pools/_scoreboard_index.html.haml
@@ -19,9 +19,11 @@
%dt= t("alerts_label")
%dd.count.alert= @statistics[:instances_failed]
%li
- %dt= t("quota_used")
- %dd.percentage.quota= number_to_percentage(@statistics[:pf_used_percentage], :precision => 0)
+ %dt
+ = t("user")
+ = t("quota_used")
+ %dd.percentage.quota= number_to_percentage(@statistics[:user_used_percentage], :precision => 0)
%dd.fraction.instance
- %span.part= @statistics[:pf_running_instances]
+ %span.part= @statistics[:user_running_instances]
%span.divider.label.small.caps of
- %span.total= @statistics[:pf_available_quota].nil? ? raw('∞') : @statistics[:pf_available_quota]
+ %span.total= @statistics[:user_available_quota].nil? ? raw('∞') : @statistics[:user_available_quota]
diff --git a/src/app/views/pools/_scoreboard_show.html.haml b/src/app/views/pools/_scoreboard_show.html.haml
index 86def34..8bba937 100644
--- a/src/app/views/pools/_scoreboard_show.html.haml
+++ b/src/app/views/pools/_scoreboard_show.html.haml
@@ -21,7 +21,9 @@
%dt=t'updates'
%dd.count.update 0
%li
- %dt=t'quota_used'
+ %dt
+ = t("pool")
+ = t("quota_used")
%dd.percentage.quota
= number_to_percentage(@pool.quota.percentage_used, :precision => 0)
%dd.fraction.instance
diff --git a/src/features/pool.feature b/src/features/pool.feature
index c436caf..b52d7f6 100644
--- a/src/features/pool.feature
+++ b/src/features/pool.feature
@@ -168,7 +168,7 @@ Feature: Manage Pools
Then I should see "Your Pools" within "section.pools"
Scenario: Display alerts
- And there is a "fail1" failed instance
+ And there is a "fail1" failed instance owned by "admin"
When I go to the pools page
Then I should see "Alerts"
And I should see "Instance Failure error"
diff --git a/src/features/step_definitions/instance_steps.rb b/src/features/step_definitions/instance_steps.rb
index 3c50c2f..fbad005 100644
--- a/src/features/step_definitions/instance_steps.rb
+++ b/src/features/step_definitions/instance_steps.rb
@@ -68,6 +68,12 @@ Given /^there is a "([^"]*)" failed instance$/ do |name|
FactoryGirl.create :instance, :name => name, :state => Instance::STATE_ERROR
end
+Given /^there is a "([^"]*)" failed instance owned by "([^"]*)"$/ do |name, login|
+ instance = FactoryGirl.create :instance, :name => name, :state => Instance::STATE_ERROR
+ instance.owner = User.find_by_login(login)
+ instance.save
+end
+
Given /^there is a "([^"]*)" running instance$/ do |name|
FactoryGirl.create :instance, :name => name, :state => Instance::STATE_RUNNING
end
--
1.7.6.4
More information about the aeolus-devel
mailing list