[PATCH aggregator] Added check for Quota before creating instance
by Martyn Taylor
From: martyntaylor <mtaylor(a)redhat.com>
---
src/app/controllers/instance_controller.rb | 24 +++++++++++++++---------
1 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
index ad90404..a81af6a 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -98,16 +98,22 @@ class InstanceController < ApplicationController
Pool.find((a)instance.pool_id))
#FIXME: This should probably be in a transaction
if @instance.save!
-
- @task = InstanceTask.new({:user => current_user,
- :task_target => @instance,
- :action => InstanceTask::ACTION_CREATE})
- if @task.save
- condormatic_instance_create(@task)
- flash[:notice] = "Instance added."
- redirect_to :action => 'index'
+ if Quota.can_start_instance?(@instance, nil)
+ @task = InstanceTask.new({:user => current_user,
+ :task_target => @instance,
+ :action => InstanceTask::ACTION_CREATE})
+ if @task.save
+ condormatic_instance_create(@task)
+ flash[:notice] = "Instance added."
+ redirect_to :action => 'index'
+ else
+ @pool = @instance.pool
+ render :action => 'configure'
+ end
else
- @pool = @instance.pool
+ @instance.destroy
+ flash[:notice] = "Quota Exceeded: Could not create instance"
+ @hardware_profiles = HardwareProfile.all
render :action => 'configure'
end
else
--
1.7.2.3
13 years, 8 months
[PATCH] Crappy rpm workaround
by Ian Main
Since 'make rpms' uses the existing directory to build an rpm from, it's
possible that it can pick up an existing condor plugin .so and install
it even if it's got the wrong prefix set etc.
This patch just adds a 'make clean' before 'make' so that it is forced
to rebuild a new plugin when making the rpm. Clearly however the rpm
needs to be fixed.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
deltacloud-aggregator.spec.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/deltacloud-aggregator.spec.in b/deltacloud-aggregator.spec.in
index dc33036..4f89f23 100644
--- a/deltacloud-aggregator.spec.in
+++ b/deltacloud-aggregator.spec.in
@@ -79,6 +79,7 @@ Documentation and tests for the Deltacloud Aggregator
%build
%configure
+make clean
make
%install
--
1.7.2.3
13 years, 8 months
[PATCH aggregator] BZ 646607: small fix to remove duplicate permissions link
by Mo Morsi
---
src/config/navigation.rb | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/config/navigation.rb b/src/config/navigation.rb
index f814773..fbc4fab 100644
--- a/src/config/navigation.rb
+++ b/src/config/navigation.rb
@@ -22,7 +22,6 @@ SimpleNavigation::Configuration.run do |navigation|
fourth_level.item :new_user, t(:new_user), {:controller => 'users', :action => 'new'}, :highlights_on => /\/users\/new/
fourth_level.item :edit_user, t(:edit_user), {:controller => 'users', :action => 'edit'}, :highlights_on => /\/users\/edit/
end
- third_level.item :define_services, t(:permissions), '#'
third_level.item :general_settings, t(:general_settings), {:controller => 'settings', :action => "general_settings"}
third_level.item :permissions, t(:permissions), { :controller => 'settings', :action => 'self_service'}
end
--
1.7.2.3
13 years, 8 months
[PATCH aggregator] BZ #644448 - Instance Details: please include operating system version
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=644448
---
src/app/views/instance/show.haml | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/app/views/instance/show.haml b/src/app/views/instance/show.haml
index fd69b8c..c751a2e 100644
--- a/src/app/views/instance/show.haml
+++ b/src/app/views/instance/show.haml
@@ -17,6 +17,9 @@
= label_tag :operating_system, 'Operating system'
%span= @instance.template.xml.platform
%li
+ = label_tag :operating_system_version, 'Operating system version'
+ %span= @instance.template.xml.platform_version
+ %li
= label_tag :provider, 'Provider'
%span= @instance.cloud_account.provider.name if @instance.cloud_account
%li
--
1.7.2.3
13 years, 8 months
[PATCH aggregator] Fixing Quota bug when creating user. BZ #644534
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
---
src/app/models/user.rb | 2 +-
src/app/services/registration_service.rb | 45 ++++++------
src/spec/factories/metadata_object.rb | 20 +++++-
src/spec/factories/role.rb | 4 +
src/spec/services/registration_service_spec.rb | 87 ++++++++++++++++++++++++
5 files changed, 133 insertions(+), 25 deletions(-)
create mode 100644 src/spec/factories/role.rb
create mode 100644 src/spec/services/registration_service_spec.rb
diff --git a/src/app/models/user.rb b/src/app/models/user.rb
index dad49c8..fe429bd 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/user.rb
@@ -25,6 +25,6 @@ class User < ActiveRecord::Base
has_many :permissions
has_many :owned_instances, :class_name => "Instance", :foreign_key => "owner_id"
- belongs_to :quota
+ belongs_to :quota, :autosave => true
accepts_nested_attributes_for :quota
end
diff --git a/src/app/services/registration_service.rb b/src/app/services/registration_service.rb
index 0baca83..046fdcd 100644
--- a/src/app/services/registration_service.rb
+++ b/src/app/services/registration_service.rb
@@ -11,31 +11,30 @@ class RegistrationService
return false
end
- begin
User.transaction do
- @user.save!
-
- allow_self_service_logins = MetadataObject.lookup("allow_self_service_logins")
- self_service_default_pool = MetadataObject.lookup("self_service_default_pool")
- self_service_default_role = MetadataObject.lookup("self_service_default_role")
- self_service_default_quota = MetadataObject.lookup("self_service_default_quota")
-
- @user_quota = Quota.new(:maximum_running_instances => self_service_default_quota.maximum_running_instances,
- :maximum_total_instances => self_service_default_quota.maximum_total_instances)
- @user_quota.save!
- @user.quota = @user_quota
- @user.save!
-
- Permission.create!({:user => @user, :role => self_service_default_role, :permission_object => self_service_default_pool})
-
- return true
- end
- rescue
- Rails.logger.error $!.message
- Rails.logger.error $!.backtrace.join("\n ")
- @error = $!.message
- false
+ begin
+ if @user.quota.nil? || @user.quota.invalid?
+ self_service_default_quota = MetadataObject.lookup("self_service_default_quota")
+ @user.quota = Quota.new(
+ :maximum_running_instances => self_service_default_quota.maximum_running_instances,
+ :maximum_total_instances => self_service_default_quota.maximum_total_instances)
+ end
+
+ @user.save!
+
+ self_service_default_role = MetadataObject.lookup("self_service_default_role")
+ self_service_default_pool = MetadataObject.lookup("self_service_default_pool")
+ Permission.create!(:user => @user, :role => self_service_default_role,
+ :permission_object => self_service_default_pool)
+ return true
+ rescue ActiveRecord::RecordInvalid => e
+ Rails.logger.error e.message
+ Rails.logger.error e.backtrace.join("\n ")
+ @error = e.message
+ raise ActiveRecord::Rollback
+ end
end
+ return false
end
def valid?
diff --git a/src/spec/factories/metadata_object.rb b/src/spec/factories/metadata_object.rb
index 31741bf..5735896 100644
--- a/src/spec/factories/metadata_object.rb
+++ b/src/spec/factories/metadata_object.rb
@@ -8,4 +8,22 @@ Factory.define :default_zone_metadata, :parent => :metadata_object do |o|
o.key 'default_zone'
o.value {Factory.create(:zone).id}
o.object_type 'Zone'
-end
\ No newline at end of file
+end
+
+Factory.define :default_quota_metadata, :parent => :metadata_object do |o|
+ o.key 'self_service_default_quota'
+ o.value {Factory.create(:quota).id}
+ o.object_type 'Quota'
+end
+
+Factory.define :default_role_metadata, :parent => :metadata_object do |o|
+ o.key 'self_service_default_role'
+ o.value {Factory.create(:role).id}
+ o.object_type 'Role'
+end
+
+Factory.define :default_pool_metadata, :parent => :metadata_object do |o|
+ o.key 'self_service_default_pool'
+ o.value {Factory.create(:pool).id}
+ o.object_type 'Pool'
+end
diff --git a/src/spec/factories/role.rb b/src/spec/factories/role.rb
new file mode 100644
index 0000000..8fd9cee
--- /dev/null
+++ b/src/spec/factories/role.rb
@@ -0,0 +1,4 @@
+Factory.define :role do |r|
+ r.sequence(:name) {|n| "Role name #{n}" }
+ r.scope 'Pool'
+end
diff --git a/src/spec/services/registration_service_spec.rb b/src/spec/services/registration_service_spec.rb
new file mode 100644
index 0000000..6764715
--- /dev/null
+++ b/src/spec/services/registration_service_spec.rb
@@ -0,0 +1,87 @@
+require 'spec_helper'
+
+describe RegistrationService do
+
+ before(:all) do
+ MetadataObject.delete_all
+ Role.delete_all
+ Factory.create(:default_quota_metadata)
+ Factory.create(:default_role_metadata)
+ Factory.create(:default_pool_metadata)
+ end
+
+ describe "with quota" do
+
+ it "passed via nested attributes to user model" do
+ user_attributes = Factory.attributes_for(:user)
+ user_attributes[:quota_attributes] = {}
+ user_attributes[:quota_attributes][:maximum_running_instances] = 2
+ user_attributes[:quota_attributes][:maximum_total_instances] = 5
+ user = User.new(user_attributes)
+ registration_process = RegistrationService.new(user)
+
+ lambda do
+ lambda do
+ lambda do
+ registration_process.save.should be_true
+ end.should change(Permission, :count).by(1)
+ end.should change(User, :count).by(1)
+ end.should change(Quota, :count).by(1)
+
+ user.new_record?.should be_false
+ user.quota.maximum_running_instances.should == 2
+ user.quota.maximum_total_instances.should == 5
+ end
+
+ it "no quota attributes passed via nested attributes" do
+ user = Factory.build(:user)
+ registration_process = RegistrationService.new(user)
+
+ lambda do
+ registration_process.save.should be_true
+ end.should_not change(Quota, :count)
+
+ user.quota.maximum_running_instances.should == 10
+ user.quota.maximum_total_instances.should == 15
+ end
+ end
+
+ describe "with transaction" do
+
+ before(:all) do
+ ActiveSupport::TestCase.use_transactional_fixtures = false
+ end
+
+ after(:all) do
+ ActiveSupport::TestCase.use_transactional_fixtures = true
+ end
+
+ it "doesn't save user if quota save! raise error and return false if validation failed" do
+ user_attributes = Factory.attributes_for(:user)
+ user = User.new(user_attributes)
+ registration_process = RegistrationService.new(user)
+
+ q = Quota.new(:maximum_total_instances => 'error')
+ Quota.should_receive(:new).and_return(q)
+
+ lambda do
+ registration_process.save.should be_false
+ end.should_not change(User, :count)
+ end
+
+ it "doesn't save quota if user save! raise error" do
+ user_attributes = Factory.attributes_for(:user)
+ user = User.new(user_attributes)
+ user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(user))
+ registration_process = RegistrationService.new(user)
+
+ lambda do
+ lambda do
+ registration_process.save.should be_false
+ end.should_not change(Quota, :count)
+ end.should_not change(User, :count)
+ end
+
+ end
+
+end
--
1.7.3.1
13 years, 8 months
[PATCH aggregator] Delete user alert shown if no user sel. BZ#646396
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
This patch is fixing BZ#646396.
- When deleting user action is triggered and no user selected javascript will
popu alert message "please select any user to delete"
- If user select normal confirm box will appear
---
src/app/views/users/index.haml | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/app/views/users/index.haml b/src/app/views/users/index.haml
index 111375f..d0a5d7e 100644
--- a/src/app/views/users/index.haml
+++ b/src/app/views/users/index.haml
@@ -8,13 +8,13 @@
= submit_tag "edit", :class => "submit linkbutton"
%dd.delete
%span
- = submit_tag "delete", :class => "submit linkbutton", :confirm => "Are you sure you want to delete this user?"
+ = submit_tag "delete", :id => 'delete_button', :class => "submit linkbutton"
%dd.add
%span
= link_to "create", new_user_url
.grid_13
- %table
+ %table{:id => 'users_table'}
%thead
%tr
%th
@@ -39,5 +39,14 @@
:javascript
$(document).ready(function () {
- //$("input[type='checkbox']").buttonSensitivity().change();
+ $('#delete_button').click(function(e) {
+ if ($("#users_table input[@type=radio]:checked").length == 0) {
+ alert('please select any user to be deleted');
+ e.preventDefault();
+ } else {
+ if (!confirm("Are you sure you want to delete this user?")) {
+ e.preventDefault();
+ }
+ }
+ });
});
--
1.7.3.1
13 years, 8 months
[PATCH aggregator] Load rb-inotify only for Linux.
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
---
src/config/environment.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/config/environment.rb b/src/config/environment.rb
index 423f224..4cbc3f9 100644
--- a/src/config/environment.rb
+++ b/src/config/environment.rb
@@ -53,7 +53,7 @@ Rails::Initializer.run do |config|
config.gem "compass-960-plugin", :lib => "ninesixty"
config.gem "simple-navigation"
config.gem "typhoeus"
- config.gem "rb-inotify"
+ config.gem "rb-inotify" if RUBY_PLATFORM.downcase.include?("linux")
config.active_record.observers = :instance_observer, :task_observer
# Only load the plugins named here, in the order given. By default, all plugins
--
1.7.3.1
13 years, 8 months
[PATCH aggregator] BZ#640192 Fixed Validation on Quota Fields
by Martyn Taylor
From: martyntaylor <mtaylor(a)redhat.com>
---
src/app/controllers/settings_controller.rb | 8 ++++++--
src/app/models/quota.rb | 10 ++++++----
src/app/views/settings/self_service.haml | 2 +-
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/app/controllers/settings_controller.rb b/src/app/controllers/settings_controller.rb
index b040f7f..ae20e12 100644
--- a/src/app/controllers/settings_controller.rb
+++ b/src/app/controllers/settings_controller.rb
@@ -53,8 +53,12 @@ class SettingsController < ApplicationController
KEYS.each do |key|
if params[key]
if key == SELF_SERVICE_DEFAULT_QUOTA
- self_service_default_quota = MetadataObject.lookup(key)
- self_service_default_quota.update_attributes(params[key])
+ @self_service_default_quota = MetadataObject.lookup(key)
+ if !(a)self_service_default_quota.update_attributes(params[key])
+ flash[:notice] = "Could not update the default quota"
+ render :self_service
+ return
+ end
elsif key == SELF_SERVICE_DEFAULT_POOL
if Pool.exists?(params[key])
MetadataObject.set(key, Pool.find(params[key]))
diff --git a/src/app/models/quota.rb b/src/app/models/quota.rb
index 83c20c4..cfc4555 100644
--- a/src/app/models/quota.rb
+++ b/src/app/models/quota.rb
@@ -28,14 +28,16 @@ class Quota < ActiveRecord::Base
validates_numericality_of :maximum_total_instances,
:greater_than_or_equal_to => 0,
:less_than_or_equal_to => 2147483647,
- :integer_only => true,
- :allow_nil => true
+ :only_integer => true,
+ :allow_nil => true,
+ :message => "must be a positive whole number less than 2147483647"
validates_numericality_of :maximum_running_instances,
:greater_than_or_equal_to => 0,
:less_than_or_equal_to => 2147483647,
- :integer_only => true,
- :allow_nil => true
+ :only_integer => true,
+ :allow_nil => true,
+ :message => "must be a positive whole number less than 2147483647"
QuotaResource = Struct.new(:name, :used, :max, :available, :unit)
diff --git a/src/app/views/settings/self_service.haml b/src/app/views/settings/self_service.haml
index c1da0ae..8fd9950 100644
--- a/src/app/views/settings/self_service.haml
+++ b/src/app/views/settings/self_service.haml
@@ -8,7 +8,6 @@
.grid_13
= error_messages_for @parent_type
- = error_messages_for 'self_service_default_quota'
%h2
= t('.self_service_default')
- form_for @self_service_default_quota, :url => { :action => 'update' } do |form|
@@ -53,6 +52,7 @@
= t('.quota') + ":"
= text_field :self_service_default_quota, :maximum_running_instances, :class => 'grid_5'
.grid_2.la (instances)
+ = form.error_message_on :maximum_running_instances, 'Maximum Running Instances '
%h3 POOLS
%fieldset.clearfix
%label.grid_2.alpha Permissions:
--
1.7.2.3
13 years, 8 months