[PATCH configure] change default aeolus firewall policy from DROP to REJECT
by Mo Morsi
---
.../firewall/files/chain_rules/filter/INPUT.head | 2 +-
.../firewall/files/chain_rules/filter/INPUT.tail | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/recipes/firewall/files/chain_rules/filter/INPUT.head b/recipes/firewall/files/chain_rules/filter/INPUT.head
index e12264a..2ed0a94 100644
--- a/recipes/firewall/files/chain_rules/filter/INPUT.head
+++ b/recipes/firewall/files/chain_rules/filter/INPUT.head
@@ -1,5 +1,5 @@
# INPUT.head
--P INPUT DROP
+-P INPUT ACCEPT
#-i lo -m comment --comment "localhost access" -j ACCEPT
-i lo -j ACCEPT
#-m state --state RELATED,ESTABLISHED -m comment --comment "All established/related" -j ACCEPT
diff --git a/recipes/firewall/files/chain_rules/filter/INPUT.tail b/recipes/firewall/files/chain_rules/filter/INPUT.tail
index d1c2492..1c983ec 100644
--- a/recipes/firewall/files/chain_rules/filter/INPUT.tail
+++ b/recipes/firewall/files/chain_rules/filter/INPUT.tail
@@ -1,3 +1,5 @@
# INPUT.tail
# -m comment --comment "Logging" -m limit --limit 3/minute -j LOG --log-prefix "[IPTABLES] INPUT : "
-m limit --limit 3/minute -j LOG --log-prefix "[IPTABLES] INPUT : "
+
+-j REJECT
--
1.7.2.3
13 years, 2 months
[PATCH] models for Assembly, Deployment, and Deployables
by Scott Seago
This includes models and model rspec tests for Assemblies, Deployments, and Deployables.
Associated role/privilege additions needed for these types are also included.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/assembly.rb | 67 ++++++++++++++++
src/app/models/deployable.rb | 61 ++++++++++++++
src/app/models/deployment.rb | 84 ++++++++++++++++++++
src/app/models/image_warehouse_object.rb | 42 ++++++++++
src/app/models/instance.rb | 24 +++++-
src/app/models/permission.rb | 6 ++
src/app/models/permissioned_object.rb | 2 +-
src/app/models/privilege.rb | 9 ++
src/app/models/template.rb | 23 +-----
src/db/migrate/20110207100700_create_assemblies.rb | 24 ++++++
.../migrate/20110207100800_update_deployables.rb | 24 ++++++
.../migrate/20110207100900_create_deployments.rb | 17 ++++
src/db/migrate/20110207101000_update_instances.rb | 21 +++++
src/db/migrate/20110207101100_deployment_roles.rb | 65 +++++++++++++++
src/db/seeds.rb | 17 +++-
src/spec/factories/assembly.rb | 5 +
src/spec/factories/deployable.rb | 4 +
src/spec/factories/deployment.rb | 6 ++
src/spec/models/assembly_spec.rb | 25 ++++++
src/spec/models/deployable_spec.rb | 25 ++++++
src/spec/models/deployment_spec.rb | 59 ++++++++++++++
src/spec/models/instance_spec.rb | 13 +++-
22 files changed, 591 insertions(+), 32 deletions(-)
create mode 100644 src/app/models/assembly.rb
create mode 100644 src/app/models/deployment.rb
create mode 100644 src/app/models/image_warehouse_object.rb
create mode 100644 src/db/migrate/20110207100700_create_assemblies.rb
create mode 100644 src/db/migrate/20110207100800_update_deployables.rb
create mode 100644 src/db/migrate/20110207100900_create_deployments.rb
create mode 100644 src/db/migrate/20110207101000_update_instances.rb
create mode 100644 src/db/migrate/20110207101100_deployment_roles.rb
create mode 100644 src/spec/factories/assembly.rb
create mode 100644 src/spec/factories/deployable.rb
create mode 100644 src/spec/factories/deployment.rb
create mode 100644 src/spec/models/assembly_spec.rb
create mode 100644 src/spec/models/deployable_spec.rb
create mode 100644 src/spec/models/deployment_spec.rb
diff --git a/src/app/models/assembly.rb b/src/app/models/assembly.rb
new file mode 100644
index 0000000..5a47525
--- /dev/null
+++ b/src/app/models/assembly.rb
@@ -0,0 +1,67 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+require 'sunspot_rails'
+class Assembly < ActiveRecord::Base
+ include PermissionedObject
+ include ImageWarehouseObject
+ searchable do
+ text :name, :as => :code_substring
+ text :architecture, :as => :code_substring
+ text :summary, :as => :code_substring
+ end
+
+ has_and_belongs_to_many :templates
+ has_and_belongs_to_many :deployables
+ has_many :instances
+
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ before_validation :generate_uuid
+ before_save :update_xml
+
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ validates_presence_of :uuid
+ validates_uniqueness_of :uuid
+ validates_presence_of :name
+ validates_uniqueness_of :name
+ validates_length_of :name, :maximum => 255
+ validates_presence_of :architecture
+
+ def self.default_privilege_target_type
+ Template
+ end
+
+ def update_xml
+ xml.name = self.name
+ xml.description = self.summary
+ xml.architecture = self.architecture
+ write_attribute(:xml, xml.to_xml)
+ end
+
+ def self.find_or_create(id)
+ id ? Assembly.find(id) : Assembly.new
+ end
+
+end
diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb
index f4891d8..9ed15ef 100644
--- a/src/app/models/deployable.rb
+++ b/src/app/models/deployable.rb
@@ -1,2 +1,63 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+require 'sunspot_rails'
class Deployable < ActiveRecord::Base
+ include PermissionedObject
+ include ImageWarehouseObject
+ searchable do
+ text :name, :as => :code_substring
+ text :summary, :as => :code_substring
+ end
+
+ has_and_belongs_to_many :assemblies
+ has_many :deployments
+
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ before_validation :generate_uuid
+ before_save :update_xml
+
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ validates_presence_of :uuid
+ validates_uniqueness_of :uuid
+ validates_presence_of :name
+ validates_uniqueness_of :name
+ validates_length_of :name, :maximum => 255
+
+ def self.default_privilege_target_type
+ Template
+ end
+
+ def update_xml
+ xml.name = self.name
+ xml.description = self.summary
+ write_attribute(:xml, xml.to_xml)
+ end
+
+ def self.find_or_create(id)
+ id ? Deployable.find(id) : Deployable.new
+ end
+
end
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
new file mode 100644
index 0000000..1b41871
--- /dev/null
+++ b/src/app/models/deployment.rb
@@ -0,0 +1,84 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+require 'sunspot_rails'
+class Deployment < ActiveRecord::Base
+ include SearchFilter
+ include PermissionedObject
+
+ searchable do
+ text :name, :as => :code_substring
+ end
+
+ belongs_to :pool
+
+ belongs_to :deployable
+ has_many :instances
+
+ belongs_to :realm
+ belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
+
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ validates_presence_of :pool_id
+ validates_presence_of :deployable_id
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => :pool_id
+ validates_length_of :name, :maximum => 1024
+
+ SEARCHABLE_COLUMNS = %w(name)
+
+ def object_list
+ super << pool
+ end
+ class << self
+ alias orig_list_for_user_include list_for_user_include
+ alias orig_list_for_user_conditions list_for_user_conditions
+ end
+
+ def self.list_for_user_include
+ includes = orig_list_for_user_include
+ includes << { :pool => {:permissions => {:role => :privileges}}}
+ includes
+ end
+
+ def self.list_for_user_conditions
+ "(#{orig_list_for_user_conditions}) or
+ (permissions_pools.user_id=:user and
+ privileges_roles.target_type=:target_type and
+ privileges_roles.action=:action)"
+ end
+
+ def get_action_list(user=nil)
+ # FIXME: how do actions and states interact for deployments?
+ # For instances the list comes from the provider based on current state.
+ # Deployments don't currently have an explicit state field, but
+ # something could be calculated from associated instances.
+ ["start", "stop", "reboot"]
+ end
+
+ def valid_action?(action)
+ return get_action_list.include?(action) ? true : false
+ end
+
+
+end
diff --git a/src/app/models/image_warehouse_object.rb b/src/app/models/image_warehouse_object.rb
new file mode 100644
index 0000000..48dd04f
--- /dev/null
+++ b/src/app/models/image_warehouse_object.rb
@@ -0,0 +1,42 @@
+#
+# Copyright (C) 2010 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+module ImageWarehouseObject
+
+ WAREHOUSE_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/image_warehouse.yml")
+
+ def xml
+ @xml ||= ImageDescriptorXML.new(self[:xml].to_s)
+ end
+
+ def upload
+ self.uri = File.join(WAREHOUSE_CONFIG['baseurl'], "#{uuid}")
+ response = Typhoeus::Request.put(self.uri, :body => xml.to_xml, :timeout => 30000)
+ if response.code == 200
+ update_attribute(:uploaded, true)
+ else
+ raise "failed to upload template (code #{response.code}): #{response.body}"
+ end
+ end
+
+ def generate_uuid
+ # TODO: generate real uuid here, e.g. with some ruby uuid generator
+ self.uuid ||= "#{self.name}-#{Time.now.to_f.to_s}"
+ end
+
+end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index b84a596..68c7174 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -37,9 +37,11 @@ class Instance < ActiveRecord::Base
belongs_to :pool
belongs_to :cloud_account
+ belongs_to :deployment
belongs_to :hardware_profile
belongs_to :template
+ belongs_to :assembly
belongs_to :realm
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
belongs_to :instance_hwp
@@ -51,7 +53,8 @@ class Instance < ActiveRecord::Base
validates_presence_of :pool_id
validates_presence_of :hardware_profile_id
- validates_presence_of :template_id
+ validates_presence_of :template_id, :unless => :deployment_id
+ validates_presence_of :assembly_id, :if => :deployment_id
#validates_presence_of :external_key
# TODO: can we do uniqueness validation on indirect association
@@ -79,8 +82,15 @@ class Instance < ActiveRecord::Base
validates_inclusion_of :state,
:in => STATES
+ def validate
+ if assembly and template
+ errors.add(:assembly, "Please specify either template or assembly, but not both")
+ errors.add(:template, "Please specify either template or assembly, but not both")
+ end
+ end
+
def object_list
- super << pool
+ super + [pool, deployment]
end
class << self
alias orig_list_for_user_include list_for_user_include
@@ -89,15 +99,19 @@ class Instance < ActiveRecord::Base
def self.list_for_user_include
includes = orig_list_for_user_include
- includes << { :pool => {:permissions => {:role => :privileges}}}
+ includes << { :pool => {:permissions => {:role => :privileges}},
+ :deployment => {:permissions => {:role => :privileges}}}
includes
end
def self.list_for_user_conditions
"(#{orig_list_for_user_conditions}) or
- (permissions_pools.user_id=:user and
+ (permissions_deployments.user_id=:user and
privileges_roles.target_type=:target_type and
- privileges_roles.action=:action)"
+ privileges_roles.action=:action) or
+ (permissions_pools.user_id=:user and
+ privileges_roles_2.target_type=:target_type and
+ privileges_roles_2.action=:action)"
end
def get_action_list(user=nil)
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
index 22b228a..03f75b7 100644
--- a/src/app/models/permission.rb
+++ b/src/app/models/permission.rb
@@ -35,12 +35,18 @@ class Permission < ActiveRecord::Base
:foreign_key => "permission_object_id"
belongs_to :instance, :class_name => "Instance",
:foreign_key => "permission_object_id"
+ belongs_to :deployment, :class_name => "Deployment",
+ :foreign_key => "permission_object_id"
belongs_to :provider, :class_name => "Provider",
:foreign_key => "permission_object_id"
belongs_to :cloud_account, :class_name => "CloudAccount",
:foreign_key => "permission_object_id"
belongs_to :template, :class_name => "Template",
:foreign_key => "permission_object_id"
+ belongs_to :assembly, :class_name => "Assembly",
+ :foreign_key => "permission_object_id"
+ belongs_to :deployable, :class_name => "Deployable",
+ :foreign_key => "permission_object_id"
belongs_to :base_permission_object, :class_name => "BasePermissionObject",
:foreign_key => "permission_object_id"
diff --git a/src/app/models/permissioned_object.rb b/src/app/models/permissioned_object.rb
index d46ed8f..d2a5878 100644
--- a/src/app/models/permissioned_object.rb
+++ b/src/app/models/permissioned_object.rb
@@ -22,7 +22,7 @@ module PermissionedObject
return false if user.nil? or action.nil?
target_type = self.class.default_privilege_target_type if target_type.nil?
object_list.each do |obj|
- return true if obj.permissions.find(:first,
+ return true if obj and obj.permissions.find(:first,
:include => [:role => :privileges],
:conditions =>
["permissions.user_id=:user and
diff --git a/src/app/models/privilege.rb b/src/app/models/privilege.rb
index f7a61ef..f5a5887 100644
--- a/src/app/models/privilege.rb
+++ b/src/app/models/privilege.rb
@@ -43,6 +43,7 @@ class Privilege < ActiveRecord::Base
Pool => ACTIONS - [USE],
PoolFamily => ACTIONS - [USE],
Instance => ACTIONS,
+ Deployment => ACTIONS,
Quota => [VIEW, MODIFY],
HardwareProfile => ACTIONS - [USE, VIEW],
Realm => ACTIONS - [VIEW],
@@ -99,6 +100,14 @@ class Privilege < ActiveRecord::Base
# view_perms Can view permissions
# set_perms Can set permissions (or can set instance permissions on this pool)
#
+ # Instance This Deployment or deployments within this Pool
+ # view Can view
+ # use Can perform lifecycle actions on and/or view console
+ # modify Can modify
+ # create Can create (within this Pool)
+ # view_perms Can view permissions
+ # set_perms Can set permissions (or can set instance permissions on this pool)
+ #
# Quota The Pool/CloudAccount/PoolFamily/User assigned the quota
# view Can view quota on this obj
# modify Can edit quota on this obj
diff --git a/src/app/models/template.rb b/src/app/models/template.rb
index 4e8ad27..d930294 100644
--- a/src/app/models/template.rb
+++ b/src/app/models/template.rb
@@ -3,6 +3,7 @@ require 'typhoeus'
class Template < ActiveRecord::Base
include PermissionedObject
+ include ImageWarehouseObject
searchable do
text :name, :as => :code_substring
text :platform, :as => :code_substring
@@ -13,6 +14,7 @@ class Template < ActiveRecord::Base
has_many :images, :dependent => :destroy
has_many :instances
+ has_and_belongs_to_many :assemblies
before_validation :generate_uuid
before_save :update_xml
before_destroy :no_instances?
@@ -21,8 +23,6 @@ class Template < ActiveRecord::Base
:include => [:role],
:order => "permissions.id ASC"
- WAREHOUSE_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/image_warehouse.yml")
-
validates_presence_of :uuid
validates_uniqueness_of :uuid
validates_presence_of :name
@@ -41,25 +41,6 @@ class Template < ActiveRecord::Base
true
end
- def xml
- @xml ||= ImageDescriptorXML.new(self[:xml].to_s)
- end
-
- def upload
- self.uri = File.join(WAREHOUSE_CONFIG['baseurl'], "#{uuid}")
- response = Typhoeus::Request.put(self.uri, :body => xml.to_xml, :timeout => 30000)
- if response.code == 200
- update_attribute(:uploaded, true)
- else
- raise "failed to upload template (code #{response.code}): #{response.body}"
- end
- end
-
- def generate_uuid
- # TODO: generate real uuid here, e.g. with some ruby uuid generator
- self.uuid ||= "#{self.name}-#{Time.now.to_f.to_s}"
- end
-
def update_xml
xml.name = self.name
xml.description = self.summary
diff --git a/src/db/migrate/20110207100700_create_assemblies.rb b/src/db/migrate/20110207100700_create_assemblies.rb
new file mode 100644
index 0000000..7e4be57
--- /dev/null
+++ b/src/db/migrate/20110207100700_create_assemblies.rb
@@ -0,0 +1,24 @@
+class CreateAssemblies < ActiveRecord::Migration
+ def self.up
+ create_table :assemblies do |t|
+ t.string :uuid, :null => false
+ t.binary :xml, :null => false
+ t.string :uri
+ t.string :name
+ t.string :architecture
+ t.text :summary
+ t.boolean :uploaded, :default => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ create_table :assemblies_templates, :id => false do |t|
+ t.integer :assembly_id, :null => false
+ t.integer :template_id, :null => false
+ end
+ end
+
+ def self.down
+ drop_table :assemblies_templates
+ drop_table :assemblies
+ end
+end
diff --git a/src/db/migrate/20110207100800_update_deployables.rb b/src/db/migrate/20110207100800_update_deployables.rb
new file mode 100644
index 0000000..4414560
--- /dev/null
+++ b/src/db/migrate/20110207100800_update_deployables.rb
@@ -0,0 +1,24 @@
+class UpdateDeployables < ActiveRecord::Migration
+ def self.up
+ change_table :deployables do |t|
+ t.integer :lock_version, :default => 0
+ t.string :uuid, :null => false
+ t.binary :xml, :null => false
+ t.string :uri
+ t.text :summary
+ t.boolean :uploaded, :default => false
+ end
+
+ create_table :assemblies_deployables, :id => false do |t|
+ t.integer :assembly_id, :null => false
+ t.integer :deployable_id, :null => false
+ end
+ end
+
+ def self.down
+ drop_table :assemblies_deployables
+ change_table :deployables do |t|
+ t.remove :lock_version, :uuid, :xml, :uri, :summary, :uploaded
+ end
+ end
+end
diff --git a/src/db/migrate/20110207100900_create_deployments.rb b/src/db/migrate/20110207100900_create_deployments.rb
new file mode 100644
index 0000000..d026f7b
--- /dev/null
+++ b/src/db/migrate/20110207100900_create_deployments.rb
@@ -0,0 +1,17 @@
+class CreateDeployments < ActiveRecord::Migration
+ def self.up
+ create_table :deployments do |t|
+ t.string :name, :null => false, :limit => 1024
+ t.integer :realm_id
+ t.integer :owner_id
+ t.integer :pool_id, :null => false
+ t.integer :deployable_id, :null => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :deployments
+ end
+end
diff --git a/src/db/migrate/20110207101000_update_instances.rb b/src/db/migrate/20110207101000_update_instances.rb
new file mode 100644
index 0000000..4b758f7
--- /dev/null
+++ b/src/db/migrate/20110207101000_update_instances.rb
@@ -0,0 +1,21 @@
+class UpdateInstances < ActiveRecord::Migration
+ def self.up
+ change_table :instances do |t|
+ t.integer :assembly_id
+ t.integer :deployment_id
+ t.change :template_id, :integer, :null => true
+ end
+
+ create_table :assemblies_instances, :id => false do |t|
+ t.integer :assembly_id, :null => false
+ t.integer :deployable_id, :null => false
+ end
+ end
+
+ def self.down
+ change_table :instances do |t|
+ t.remove :assembly_id, :deployment_id
+ t.change :template_id, :integer, :null => false
+ end
+ end
+end
diff --git a/src/db/migrate/20110207101100_deployment_roles.rb b/src/db/migrate/20110207101100_deployment_roles.rb
new file mode 100644
index 0000000..b63413a
--- /dev/null
+++ b/src/db/migrate/20110207101100_deployment_roles.rb
@@ -0,0 +1,65 @@
+class DeploymentRoles < ActiveRecord::Migration
+ VIEW = "view"
+ USE = "use"
+ MOD = "modify"
+ CRE = "create"
+ VPRM = "view_perms"
+ GPRM = "set_perms"
+ NEW_ROLES = {
+ Deployment =>
+ {"Deployment Controller" => [false, {Deployment => [VIEW,USE],
+ Instance => [VIEW]}],
+ "Deployment Owner" => [true, {Deployment => [VIEW,USE,MOD, VPRM,GPRM],
+ Instance => [VIEW,USE,MOD]}]},
+ Pool =>
+ {"Pool User" => [false, {Pool => [VIEW],
+ Instance => [ CRE],
+ Deployment => [ CRE],
+ Quota => [VIEW]}],
+ "Pool Owner" => [true, {Pool => [VIEW, MOD, VPRM,GPRM],
+ Instance => [VIEW,USE,MOD,CRE],
+ Deployment => [VIEW,USE,MOD,CRE],
+ Quota => [VIEW]}]},
+ BasePermissionObject =>
+ {"Pool Administrator" => [false, {Pool => [VIEW, MOD,CRE,VPRM,GPRM],
+ Instance => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ Deployment => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ Quota => [VIEW, MOD],
+ PoolFamily => [VIEW, MOD,CRE,VPRM,GPRM]}],
+ "Administrator" => [false, {Provider => [VIEW, MOD,CRE,VPRM,GPRM],
+ CloudAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ HardwareProfile => [ MOD,CRE,VPRM,GPRM],
+ Realm => [ USE,MOD,CRE,VPRM,GPRM],
+ User => [VIEW, MOD,CRE],
+ Pool => [VIEW, MOD,CRE,VPRM,GPRM],
+ Instance => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ Deployment => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ Quota => [VIEW, MOD],
+ PoolFamily => [VIEW, MOD,CRE,VPRM,GPRM],
+ Template => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ BasePermissionObject => [ MOD, VPRM,GPRM]}]}}
+ def self.up
+ unless Role.all.size == 0
+ Role.transaction do
+ NEW_ROLES.each do |role_scope, scoped_hash|
+ scoped_hash.each do |role_name, role_def|
+ role = Role.find_or_initialize_by_name(role_name)
+ role.update_attributes({:name => role_name, :scope => role_scope.name,
+ :assign_to_owner => role_def[0]})
+ role.privileges = {}
+ role.save!
+ role_def[1].each do |priv_type, priv_actions|
+ priv_actions.each do |action|
+ Privilege.create!(:role => role, :target_type => priv_type.name,
+ :action => action)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ def self.down
+ end
+end
diff --git a/src/db/seeds.rb b/src/db/seeds.rb
index 71726bf..d0b6477 100644
--- a/src/db/seeds.rb
+++ b/src/db/seeds.rb
@@ -17,6 +17,11 @@ roles =
{Instance =>
{"Instance Controller" => [false, {Instance => [VIEW,USE]}],
"Instance Owner" => [true, {Instance => [VIEW,USE,MOD, VPRM,GPRM]}]},
+ Deployment =>
+ {"Deployment Controller" => [false, {Deployment => [VIEW,USE],
+ Instance => [VIEW]}],
+ "Deployment Owner" => [true, {Deployment => [VIEW,USE,MOD, VPRM,GPRM],
+ Instance => [VIEW,USE,MOD]}]},
PoolFamily =>
{"Pool Family User" => [false, {Pool => [VIEW]}],
"Pool Family Owner" => [true, {PoolFamily => [VIEW, MOD, VPRM,GPRM],
@@ -24,9 +29,11 @@ roles =
Pool =>
{"Pool User" => [false, {Pool => [VIEW],
Instance => [ CRE],
+ Deployment => [ CRE],
Quota => [VIEW]}],
"Pool Owner" => [true, {Pool => [VIEW, MOD, VPRM,GPRM],
Instance => [VIEW,USE,MOD,CRE],
+ Deployment => [VIEW,USE,MOD,CRE],
Quota => [VIEW]}]},
Provider =>
{"Provider Owner" => [true, {Provider => [VIEW, MOD, VPRM,GPRM],
@@ -46,6 +53,7 @@ roles =
"Pool Creator" => [false, {Pool => [ CRE]}],
"Pool Administrator" => [false, {Pool => [VIEW, MOD,CRE,VPRM,GPRM],
Instance => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ Deployment => [VIEW,USE,MOD,CRE,VPRM,GPRM],
Quota => [VIEW, MOD],
PoolFamily => [VIEW, MOD,CRE,VPRM,GPRM]}],
"Template Administrator" => [false, {Template => [VIEW,USE,MOD,CRE,VPRM,GPRM]}],
@@ -56,6 +64,7 @@ roles =
User => [VIEW, MOD,CRE],
Pool => [VIEW, MOD,CRE,VPRM,GPRM],
Instance => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ Deployment => [VIEW,USE,MOD,CRE,VPRM,GPRM],
Quota => [VIEW, MOD],
PoolFamily => [VIEW, MOD,CRE,VPRM,GPRM],
Template => [VIEW,USE,MOD,CRE,VPRM,GPRM],
@@ -63,11 +72,11 @@ roles =
Role.transaction do
roles.each do |role_scope, scoped_hash|
scoped_hash.each do |role_name, role_def|
+ role = Role.find_or_initialize_by_name(role_name)
+ role.update_attributes({:name => role_name, :scope => role_scope.name,
+ :assign_to_owner => role_def[0]})
+ role.save!
role_def[1].each do |priv_type, priv_actions|
- role = Role.find_or_initialize_by_name(role_name)
- role.update_attributes({:name => role_name, :scope => role_scope.name,
- :assign_to_owner => role_def[0]})
- role.save!
priv_actions.each do |action|
Privilege.create!(:role => role, :target_type => priv_type.name,
:action => action)
diff --git a/src/spec/factories/assembly.rb b/src/spec/factories/assembly.rb
new file mode 100644
index 0000000..af290dc
--- /dev/null
+++ b/src/spec/factories/assembly.rb
@@ -0,0 +1,5 @@
+Factory.define :assembly do |a|
+ a.sequence(:name) { |n| "assembly#{n}" }
+ a.architecture 'x86_64'
+ a.templates { |t| [t.association(:template)] }
+end
diff --git a/src/spec/factories/deployable.rb b/src/spec/factories/deployable.rb
new file mode 100644
index 0000000..60b160b
--- /dev/null
+++ b/src/spec/factories/deployable.rb
@@ -0,0 +1,4 @@
+Factory.define :deployable do |a|
+ a.sequence(:name) { |n| "deployable#{n}" }
+ a.assemblies { |t| [t.association(:assembly)] }
+end
diff --git a/src/spec/factories/deployment.rb b/src/spec/factories/deployment.rb
new file mode 100644
index 0000000..f3c0522
--- /dev/null
+++ b/src/spec/factories/deployment.rb
@@ -0,0 +1,6 @@
+Factory.define :deployment do |d|
+ d.sequence(:name) { |n| "deployment#{n}" }
+ d.association :deployable, :factory => :deployable
+ d.association :pool, :factory => :pool
+ d.association :owner, :factory => :user
+end
diff --git a/src/spec/models/assembly_spec.rb b/src/spec/models/assembly_spec.rb
new file mode 100644
index 0000000..2693116
--- /dev/null
+++ b/src/spec/models/assembly_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Assembly do
+
+ it "should have automatically generated uuid after validation" do
+ a = Factory.build(:assembly)
+ a.uuid = nil
+ a.save
+ a.uuid.should_not be_nil
+ end
+
+ it "should not be valid if assembly name is too long" do
+ a = Factory.build(:assembly)
+ a.name = ('a' * 256)
+ a.valid?.should be_false
+ a.errors[:name].should_not be_nil
+ a.errors[:name].should =~ /^is too long.*/
+ end
+
+ it "should have associated template" do
+ a = Factory.build(:assembly)
+ a.templates.size.should eql(1)
+ end
+
+end
diff --git a/src/spec/models/deployable_spec.rb b/src/spec/models/deployable_spec.rb
new file mode 100644
index 0000000..af1fc9f
--- /dev/null
+++ b/src/spec/models/deployable_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Deployable do
+
+ it "should have automatically generated uuid after validation" do
+ d = Factory.build(:deployable)
+ d.uuid = nil
+ d.save
+ d.uuid.should_not be_nil
+ end
+
+ it "should not be valid if deployable name is too long" do
+ d = Factory.build(:deployable)
+ d.name = ('a' * 256)
+ d.valid?.should be_false
+ d.errors[:name].should_not be_nil
+ d.errors[:name].should =~ /^is too long.*/
+ end
+
+ it "should have associated assembly" do
+ d = Factory.build(:deployable)
+ d.assemblies.size.should eql(1)
+ end
+
+end
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
new file mode 100644
index 0000000..c8eda13
--- /dev/null
+++ b/src/spec/models/deployment_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+
+describe Deployment do
+ before(:each) do
+ @quota = Factory :quota
+ @pool = Factory(:pool, :quota_id => @quota.id)
+ @deployment = Factory.build(:deployment, :pool_id => @pool.id)
+ @actions = ['start', 'stop']
+ end
+
+ it "should require pool to be set" do
+ @deployment.pool_id = nil
+ @deployment.should_not be_valid
+
+ @deployment.pool_id = 1
+ @deployment.should be_valid
+ end
+
+ it "should require deployable to be set" do
+ @deployment.deployable_id = nil
+ @deployment.should_not be_valid
+
+ @deployment.deployable_id = 1
+ @deployment.should be_valid
+ end
+
+ it "should have a name of reasonable length" do
+ [nil, '', 'x'*1025].each do |invalid_name|
+ @deployment.name = invalid_name
+ @deployment.should_not be_valid
+ end
+ @deployment.name = 'x'*1024
+ @deployment.should be_valid
+
+ end
+
+ it "should have unique name" do
+ @deployment.save!
+ second_deployment = Factory.build(:deployment,
+ :pool_id => @deployment.pool_id,
+ :name => @deployment.name)
+ second_deployment.should_not be_valid
+
+ second_deployment.name = 'unique name'
+ second_deployment.should be_valid
+ end
+
+ it "should tell apart valid and invalid actions" do
+ @deployment.stub!(:get_action_list).and_return(@actions)
+ @deployment.valid_action?('invalid action').should == false
+ @deployment.valid_action?('start').should == true
+ end
+
+ it "should return action list" do
+ @deployment.get_action_list.should eql(["start", "stop", "reboot"])
+ end
+
+
+end
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 625718d..787c0c5 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -24,14 +24,25 @@ describe Instance do
@instance.should be_valid
end
- it "should require template to be set" do
+ it "should require template to be set if there no deployment" do
@instance.template_id = nil
+ @instance.deployment_id = nil
@instance.should_not be_valid
@instance.template_id = 1
@instance.should be_valid
end
+ it "should not allow template to be set if there's a deployment" do
+ @instance.deployment_id = 1
+ @instance.template_id = 1
+ @instance.should_not be_valid
+
+ @instance.template_id = nil
+ @instance.assembly_id = 1
+ @instance.should be_valid
+ end
+
it "should have a name of reasonable length" do
[nil, '', 'x'*1025].each do |invalid_name|
@instance.name = invalid_name
--
1.7.3.4
13 years, 2 months
[PATCH aeolus] Updated API HWP Match Method
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
Patch update the API matching method, so that the chosen matching HWP is selected and returned, rather than the list of matching hardware profiles. This also decided what property values to select when start an instance.
---
.../admin/hardware_profiles_controller.rb | 11 +++++--
src/app/models/hardware_profile.rb | 32 ++++++++++++++++----
.../hardware_profiles/_matching_profiles.xml.haml | 7 ----
.../views/templates/xml/_hardware_profile.xml.haml | 2 +-
src/config/routes.rb | 2 +
src/features/api.feature | 17 +++-------
src/features/step_definitions/api_steps.rb | 6 ++-
7 files changed, 46 insertions(+), 31 deletions(-)
delete mode 100644 src/app/views/admin/hardware_profiles/_matching_profiles.xml.haml
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb
index dcd9b67..75c6ab1 100644
--- a/src/app/controllers/admin/hardware_profiles_controller.rb
+++ b/src/app/controllers/admin/hardware_profiles_controller.rb
@@ -100,9 +100,14 @@ class Admin::HardwareProfilesController < ApplicationController
def matching_profiles
begin
- hwp = HardwareProfile.find(params[:id])
- @matches = HardwareProfile.matching_hwps(hwp)
- render :partial => 'matching_profiles.xml'
+ hwp = HardwareProfile.find(params[:hardware_profile_id])
+ provider = Provider.find(params[:provider_id])
+ @hardware_profile = HardwareProfile.match_hwp(hwp, provider)
+ if !(a)hardware_profile.nil?
+ render :partial => 'templates/xml/hardware_profile.xml', :locals => { :profile => @hardware_profile }
+ else
+ head :not_found
+ end
rescue ActiveRecord::RecordNotFound
head :not_found
rescue Exception => e
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 7d43a36..864e4ac 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -122,15 +122,36 @@ class HardwareProfile < ActiveRecord::Base
#TODO: This function returns the first hwp in the list of matched hardware profiles
# Better logic should be used here to decide which hardware profile to return.
- def self.match_hwp(hwp)
- hwps = matching_hwps(hwp)
- if hwps.empty?
+ def self.match_hwp(hwp, provider=nil)
+ match_maps = matching_hwps(hwp, provider)
+ if match_maps.empty?
return nil
end
- return hwps[0]
+
+ selected_match = match_maps[0]
+ hwp = selected_match[:hardware_profile]
+ hwp.memory = select_value(selected_match[:memory])
+ hwp.cpu = select_value(selected_match[:cpu])
+ hwp.storage = select_value(selected_match[:storage])
+ hwp.architecture = select_value(selected_match[:architecture])
+ return hwp
end
- def self.matching_hwps(hwp)
+ def self.select_value(property)
+ case property.kind
+ when "range"
+ property.value = property.range_first
+ property.range_first = nil
+ property.range_last = nil
+ when "enum"
+ property.value = property.property_enum_entries[0].value
+ property.property_enum_entries = nil
+ end
+ property.kind = "fixed"
+ return property
+ end
+ def self.matching_hwps(hwp, provider=nil)
+ provider_hwps = provider.nil? ? HardwareProfile.all(:conditions => 'provider_id IS NOT NULL') : HardwareProfile.all(:conditions => { :provider_id => provider.id } )
provider_hwps = HardwareProfile.all(:conditions => 'provider_id IS NOT NULL')
match_maps = []
provider_hwps.each do |phwp|
@@ -142,7 +163,6 @@ class HardwareProfile < ActiveRecord::Base
return match_maps
end
- #TODO: This function returns the first value in hwpp list, better logic is required for for choosing a more appropriate match
private
def self.set_non_default_value(hwpp)
case hwpp.kind
diff --git a/src/app/views/admin/hardware_profiles/_matching_profiles.xml.haml b/src/app/views/admin/hardware_profiles/_matching_profiles.xml.haml
deleted file mode 100644
index 4555898..0000000
--- a/src/app/views/admin/hardware_profiles/_matching_profiles.xml.haml
+++ /dev/null
@@ -1,7 +0,0 @@
-%matching_hardware_profiles<>
- - @matches.each do |match|
- %matching_hardware_profile<>
- = render :partial => 'templates/xml/hardware_profile.xml', :locals => { :profile => match[:hardware_profile] }
- %constraints<>
- - [:memory, :cpu, :storage, :architecture].each do |property|
- = render :partial => 'templates/xml/hardware_profile_property.xml', :locals => { :property => match[property] }
\ No newline at end of file
diff --git a/src/app/views/templates/xml/_hardware_profile.xml.haml b/src/app/views/templates/xml/_hardware_profile.xml.haml
index 1a8324f..6ac533e 100644
--- a/src/app/views/templates/xml/_hardware_profile.xml.haml
+++ b/src/app/views/templates/xml/_hardware_profile.xml.haml
@@ -1,5 +1,5 @@
!!! XML
-%hardware_profile{ :href => admin_hardware_profile_path(profile.id), :id => profile.id }<>
+%hardware_profile{ :href => admin_hardware_profile_path(profile.id), :id => profile.external_key }<>
%name<>
= profile.name
- [profile.memory, profile.cpu, profile.architecture, profile.storage].each do |prop|
diff --git a/src/config/routes.rb b/src/config/routes.rb
index d08689f..883a46d 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -59,6 +59,8 @@ ActionController::Routing::Routes.draw do |map|
r.resources :pool_families, :collection => { :multi_destroy => :delete }
end
+ map.matching_profiles '/admin/hardware_profiles/matching_profiles/:hardware_profile_id/provider/:provider_id', :controller => 'admin/hardware_profiles', :action => 'matching_profiles', :conditions => { :method => :get }
+
map.login 'login', :controller => "user_sessions", :action => "new"
map.logout 'logout', :controller => "user_sessions", :action => "destroy"
map.resource :user_session
diff --git a/src/features/api.feature b/src/features/api.feature
index 64cc183..2b488b3 100644
--- a/src/features/api.feature
+++ b/src/features/api.feature
@@ -7,7 +7,7 @@ Feature: User authentication
Given I am an authorised user
And I am logged in
- Scenario: Get matching profiles via API
+ Scenario: Get matched HardwareProfile
Given I am an authorised user
Given there are the following provider hardware profiles:
| name | memory | cpu |storage | architecture |
@@ -16,24 +16,17 @@ Feature: User authentication
Given there are the following aggregator hardware profiles:
| name | memory | cpu |storage | architecture |
| agg-medium | 4096 | 4 | 850 | x86_64 |
- When a client requests matching hardware profiles for "agg-medium"
- Then the root element should be "matching_hardware_profiles"
- And there should exist the following xpath: "/matching_hardware_profiles/matching_hardware_profile/hardware_profile/name"
+ When a client requests matching hardware profile for "agg-medium"
+ Then the root element should be "hardware_profile"
+ And there should exist the following xpath: "hardware_profile/name"
And this path should have the value "m1-medium"
- And there should exist the following xpath: "/matching_hardware_profiles/matching_hardware_profile/hardware_profile/property"
+ And there should exist the following xpath: "hardware_profile/property"
And this path should contain the following elements:
| element | kind | name | unit | value |
| property | fixed | memory | MB | 4096 |
| property | fixed | cpu | count | 4 |
| property | fixed | architecture | label | x86_64 |
| property | fixed | storage | GB | 850 |
- And there should exist the following xpath: "/matching_hardware_profiles/matching_hardware_profile/constraints/property"
- And this path should contain the following elements:
- | element | kind | name | unit | value |
- | property | fixed | memory | MB | 4096 |
- | property | fixed | cpu | count | 4 |
- | property | fixed | storage | GB | 850 |
- | property | fixed | architecture | label | x86_64 |
Scenario: Check can start instance
Given there is a user "testuser"
diff --git a/src/features/step_definitions/api_steps.rb b/src/features/step_definitions/api_steps.rb
index 8b1f868..d30db70 100644
--- a/src/features/step_definitions/api_steps.rb
+++ b/src/features/step_definitions/api_steps.rb
@@ -7,8 +7,10 @@ Then /^I should see xml element "([^"]*)" with the following properties:$/ do |e
Then %{I should see the following: "#{properties}"}
end
-When /^a client requests matching hardware profiles for "([^"]*)"$/ do |name|
- uri = url_for :action => 'matching_profiles', :controller => 'admin/hardware_profiles', :id => HardwareProfile.find_by_name(name)
+When /^a client requests matching hardware profile for "([^"]*)"$/ do |name|
+ hardware_profile = HardwareProfile.find_by_name(name)
+ provider = HardwareProfile.find_by_name("m1-medium").provider
+ uri = url_for :action => 'matching_profiles', :controller => 'admin/hardware_profiles', :hardware_profile_id => hardware_profile.id, :provider_id => provider.id
send_xml_get(uri)
end
--
1.7.3.4
13 years, 2 months
Acceleration of tests with tmpfs
by Maros Zatko
Dear Conductor developers,
Tired of running endless rspec and cucumber tests and having to wait
almost forever for them to finnish?
Here is (maybe) the solution! :)
As you know, RSpec tests are very database heavy, so it probably does
make sense to put postgresql data directory into a ramdisk-based filesystem.
The same applies to cucumber tests, but there is a difference that
cucumber is much more solr-heavy than db-heavy.
Let's then put a solr data directory into a tmpfs and see what happens.
Here are some "benchmarks" for you to have a picture of what's going on.
RSpec:
With pgsql on tmpfs:
$ rake
Finished in 79.749916 seconds
With pgsql on ext4 (and luks):
$ rake
Finished in 470.17935 seconds
So, rspec is on tmpfs about 489.5 percent faster.
Cucumber:
With solr/data on tmpfs and pgsql on ext4
$ rake cucumber
1m47.025s
With solr/data on tmpfs and pgsql on tmpfs
$ rake cucumber
1m44.647s
This is not a significant improvement compared to last result.
With solr/data on ext4 and pgsql on tmpfs
$ rake cucumber
5m18.378s
Well, it seems that cucumber is really solr-heavy.
And for completness, here are tests with both solr and pgsql on ext4,
which is probably the most common setup:
$ rake cucumber
5m24.583s
Well, it looks like the solr on tmpfs can provide ~156.5 percent speed
improvement.
There are also scripts for automated setup. Please note that these
scripts should be run from cucumber/src directory.
Please, give it a shot and also any feedback would be really appreciated.
Best regards,
Maros Zatko
mzatko(a)redhat.com
13 years, 2 months
[PATCH conductor] Updated rake cucumber to reindex solr
by Tomas Sedovic
From: Tomas Sedovic <tsedovic(a)redhat.com>
---
src/features/support/hooks.rb | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/features/support/hooks.rb b/src/features/support/hooks.rb
index a00ac36..0b3d982 100644
--- a/src/features/support/hooks.rb
+++ b/src/features/support/hooks.rb
@@ -1,2 +1,8 @@
+require 'sunspot'
+
Before do
end
+
+After do
+ Sunspot.remove_all
+end
--
1.7.4
13 years, 2 months
[PATCH conductor] Updated rake cucumber to reindex solr
by Tomas Sedovic
From: Martyn Taylor <mtaylor(a)redhat.com>
---
src/features/support/hooks.rb | 6 ++++++
src/lib/tasks/cucumber.rake | 10 +++++-----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/features/support/hooks.rb b/src/features/support/hooks.rb
index a00ac36..0b3d982 100644
--- a/src/features/support/hooks.rb
+++ b/src/features/support/hooks.rb
@@ -1,2 +1,8 @@
+require 'sunspot'
+
Before do
end
+
+After do
+ Sunspot.remove_all
+end
diff --git a/src/lib/tasks/cucumber.rake b/src/lib/tasks/cucumber.rake
index 453f43c..f3266b4 100644
--- a/src/lib/tasks/cucumber.rake
+++ b/src/lib/tasks/cucumber.rake
@@ -14,19 +14,19 @@ begin
require 'cucumber/rake/task'
namespace :cucumber do
- Cucumber::Rake::Task.new({:ok => ['db:test:prepare','db:seed']}, 'Run features that should pass') do |t|
+ Cucumber::Rake::Task.new({:ok => [ 'db:test:prepare','db:seed', 'sunspot:solr:reindex']}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end
- Cucumber::Rake::Task.new({:wip => ['db:test:prepare','db:seed']}, 'Run features that are being worked on') do |t|
+ Cucumber::Rake::Task.new({:wip => ['db:test:prepare','db:seed', 'sunspot:solr:reindex']}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end
- Cucumber::Rake::Task.new({:rerun => ['db:test:prepare','db:seed']}, 'Record failing features and run only them if any exist') do |t|
+ Cucumber::Rake::Task.new({:rerun => ['db:test:prepare','db:seed', 'sunspot:solr:reindex']}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
@@ -35,6 +35,7 @@ begin
desc 'Run all features'
task :all => [:ok, :wip]
end
+
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'
@@ -66,5 +67,4 @@ begin
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end
-
-end
\ No newline at end of file
+end
--
1.7.4
13 years, 2 months
[PATCH aeolus] Added changes API matching_profile method
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
---
.../admin/hardware_profiles_controller.rb | 24 +++++++++++++--
src/app/models/hardware_profile.rb | 32 ++++++++++++++++----
.../views/templates/xml/_hardware_profile.xml.haml | 2 +-
src/config/routes.rb | 2 +
4 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb
index dcd9b67..be10f17 100644
--- a/src/app/controllers/admin/hardware_profiles_controller.rb
+++ b/src/app/controllers/admin/hardware_profiles_controller.rb
@@ -98,11 +98,29 @@ class Admin::HardwareProfilesController < ApplicationController
redirect_to admin_hardware_profiles_path
end
+# def matching_profiles
+# begin
+# hwp = HardwareProfile.find(params[:id])
+# @matches = HardwareProfile.matching_hwps(hwp)
+# render :partial => 'matching_profiles.xml'
+# rescue ActiveRecord::RecordNotFound
+# head :not_found
+# rescue Exception => e
+# head :internal_server_error
+# end
+# end
+
def matching_profiles
begin
- hwp = HardwareProfile.find(params[:id])
- @matches = HardwareProfile.matching_hwps(hwp)
- render :partial => 'matching_profiles.xml'
+ hwp = HardwareProfile.find(params[:hardware_profile_id])
+ provider = Provider.find(params[:provider_id])
+ #@matches = HardwareProfile.matching_hwps(hwp)
+ @hardware_profile = HardwareProfile.match_hwp(hwp, provider)
+ if !(a)hardware_profile.nil?
+ render :partial => 'templates/xml/hardware_profile.xml', :locals => { :profile => @hardware_profile }
+ else
+ head :not_found
+ end
rescue ActiveRecord::RecordNotFound
head :not_found
rescue Exception => e
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 7d43a36..864e4ac 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -122,15 +122,36 @@ class HardwareProfile < ActiveRecord::Base
#TODO: This function returns the first hwp in the list of matched hardware profiles
# Better logic should be used here to decide which hardware profile to return.
- def self.match_hwp(hwp)
- hwps = matching_hwps(hwp)
- if hwps.empty?
+ def self.match_hwp(hwp, provider=nil)
+ match_maps = matching_hwps(hwp, provider)
+ if match_maps.empty?
return nil
end
- return hwps[0]
+
+ selected_match = match_maps[0]
+ hwp = selected_match[:hardware_profile]
+ hwp.memory = select_value(selected_match[:memory])
+ hwp.cpu = select_value(selected_match[:cpu])
+ hwp.storage = select_value(selected_match[:storage])
+ hwp.architecture = select_value(selected_match[:architecture])
+ return hwp
end
- def self.matching_hwps(hwp)
+ def self.select_value(property)
+ case property.kind
+ when "range"
+ property.value = property.range_first
+ property.range_first = nil
+ property.range_last = nil
+ when "enum"
+ property.value = property.property_enum_entries[0].value
+ property.property_enum_entries = nil
+ end
+ property.kind = "fixed"
+ return property
+ end
+ def self.matching_hwps(hwp, provider=nil)
+ provider_hwps = provider.nil? ? HardwareProfile.all(:conditions => 'provider_id IS NOT NULL') : HardwareProfile.all(:conditions => { :provider_id => provider.id } )
provider_hwps = HardwareProfile.all(:conditions => 'provider_id IS NOT NULL')
match_maps = []
provider_hwps.each do |phwp|
@@ -142,7 +163,6 @@ class HardwareProfile < ActiveRecord::Base
return match_maps
end
- #TODO: This function returns the first value in hwpp list, better logic is required for for choosing a more appropriate match
private
def self.set_non_default_value(hwpp)
case hwpp.kind
diff --git a/src/app/views/templates/xml/_hardware_profile.xml.haml b/src/app/views/templates/xml/_hardware_profile.xml.haml
index 1a8324f..6ac533e 100644
--- a/src/app/views/templates/xml/_hardware_profile.xml.haml
+++ b/src/app/views/templates/xml/_hardware_profile.xml.haml
@@ -1,5 +1,5 @@
!!! XML
-%hardware_profile{ :href => admin_hardware_profile_path(profile.id), :id => profile.id }<>
+%hardware_profile{ :href => admin_hardware_profile_path(profile.id), :id => profile.external_key }<>
%name<>
= profile.name
- [profile.memory, profile.cpu, profile.architecture, profile.storage].each do |prop|
diff --git a/src/config/routes.rb b/src/config/routes.rb
index d08689f..883a46d 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -59,6 +59,8 @@ ActionController::Routing::Routes.draw do |map|
r.resources :pool_families, :collection => { :multi_destroy => :delete }
end
+ map.matching_profiles '/admin/hardware_profiles/matching_profiles/:hardware_profile_id/provider/:provider_id', :controller => 'admin/hardware_profiles', :action => 'matching_profiles', :conditions => { :method => :get }
+
map.login 'login', :controller => "user_sessions", :action => "new"
map.logout 'logout', :controller => "user_sessions", :action => "destroy"
map.resource :user_session
--
1.7.3.4
13 years, 2 months
Instance key (rev. final-final)
by Jan Provazník
If this is not final version, then there is a bug in the universe.
1-3 patches are same, patch 4/4 fixes InstanceKey creation.
13 years, 2 months