From: Martyn Taylor mtaylor@redhat.com
--- .../admin/hardware_profiles_controller.rb | 26 +----- src/app/views/admin/hardware_profiles/_form.haml | 20 +---- src/app/views/admin/hardware_profiles/_list.haml | 5 +- .../views/admin/hardware_profiles/_properties.haml | 13 +--- src/features/hardware_profile.feature | 86 ++++++++++---------- 5 files changed, 56 insertions(+), 94 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb index 75c6ab1..04e291f 100644 --- a/src/app/controllers/admin/hardware_profiles_controller.rb +++ b/src/app/controllers/admin/hardware_profiles_controller.rb @@ -133,13 +133,8 @@ class Admin::HardwareProfilesController < ApplicationController def properties @properties_header = [ { :name => "Name", :sort_attr => :name}, - { :name => "Kind", :sort_attr => :kind }, - { :name => "Range First", :sort_attr => :range_first}, - { :name => "Range Last", :sort_attr => :range_last }, - { :name => "Enum Entries", :sort_attr => :false }, - { :name => "Default Value", :sort_attr => :value}, - { :name => "Unit", :sort_attr => :unit} - ] + { :name => "Unit", :sort_attr => :unit}, + { :name => "Minimum Value", :sort_attr => :value}] @hwp_properties = [@hardware_profile.memory, @hardware_profile.cpu, @hardware_profile.storage, @hardware_profile.architecture] end
@@ -168,11 +163,7 @@ class Admin::HardwareProfilesController < ApplicationController @header = [ { :name => "Name", :sort_attr => :name}, { :name => "Unit", :sort_attr => :unit}, - { :name => "Kind", :sort_attr => :kind }, - { :name => "Value (Default)", :sort_attr => :value}, - { :name => "Enum Entries", :sort_attr => :false }, - { :name => "Range First", :sort_attr => :range_first}, - { :name => "Range Last", :sort_attr => :range_last }] + { :name => "Minimum Value", :sort_attr => :value}] end
def set_params_and_header @@ -210,17 +201,10 @@ class Admin::HardwareProfilesController < ApplicationController hwpp.nil? ? hardwareProfileProperty = HardwareProfileProperty.new : hardwareProfileProperty = hwpp
hardwareProfileProperty.name = params[:name] - hardwareProfileProperty.kind = params[:kind] + hardwareProfileProperty.kind = "fixed" hardwareProfileProperty.value = params[:value] hardwareProfileProperty.unit = params[:unit] - case hardwareProfileProperty.kind - when "range" - hardwareProfileProperty.range_first = params[:range_first] - hardwareProfileProperty.range_last = params[:range_last] - when "enum" - hardwareProfileProperty.property_enum_entries = params[:property_enum_entries].split(%r{,\s*}).map { |value| PropertyEnumEntry.new(:value => value, :hardware_profile_property => hardwareProfileProperty) } - end - hardwareProfileProperty + return hardwareProfileProperty end
end diff --git a/src/app/views/admin/hardware_profiles/_form.haml b/src/app/views/admin/hardware_profiles/_form.haml index 4327007..70c982b 100644 --- a/src/app/views/admin/hardware_profiles/_form.haml +++ b/src/app/views/admin/hardware_profiles/_form.haml @@ -10,21 +10,9 @@ %td =hwpp_form.text_field(:unit, :size => 5, :readonly => "readonly") %td - -unless type == :architecture - =hwpp_form.select("kind", ["fixed", "range", "enum"], {}) + -if type == :architecture + =hwpp_form.select("value", ["i386", "x86_64"], {}) -else - =hwpp_form.select("kind", ["fixed"], {}) - %td - =hwpp_form.text_field(:value) - %td - -unless type == :architecture - =hwpp_form.text_field(:property_enum_entries) - %td - -unless type == :architecture - =hwpp_form.text_field(:range_first) - %td - -unless type == :architecture - =hwpp_form.text_field(:range_last) + =hwpp_form.text_field(:value) = hwp_form.submit 'Check Matches', :class => "submit formbutton" -<!-- Disabled until condor can support new HWP model --> -<!-- = hwp_form.submit 'Save', :class => 'submit formbutton', :disabled => 'disabled' --> \ No newline at end of file += hwp_form.submit 'Save', :class => 'submit formbutton' \ No newline at end of file diff --git a/src/app/views/admin/hardware_profiles/_list.haml b/src/app/views/admin/hardware_profiles/_list.haml index 621f53b..eee5ff1 100644 --- a/src/app/views/admin/hardware_profiles/_list.haml +++ b/src/app/views/admin/hardware_profiles/_list.haml @@ -1,8 +1,7 @@ - form_tag do #object-actions - <!-- Disabled until condor can support new HWP model --> - <!-- = link_to "New Hardware Profile", new_admin_hardware_profile_path, :class => 'button' --> - <!-- = restful_submit_tag "Delete", "destroy", multi_destroy_admin_hardware_profiles_path --> + = link_to "New Hardware Profile", new_admin_hardware_profile_path, :class => 'button' + = restful_submit_tag "Delete", 'destroy', multi_destroy_admin_hardware_profiles_path, 'DELETE', :id => 'delete_button' #selections %p Select: diff --git a/src/app/views/admin/hardware_profiles/_properties.haml b/src/app/views/admin/hardware_profiles/_properties.haml index 04517bf..0739b84 100644 --- a/src/app/views/admin/hardware_profiles/_properties.haml +++ b/src/app/views/admin/hardware_profiles/_properties.haml @@ -1,7 +1,6 @@ %h3 = @hardware_profile.name + "(" + (@hardware_profile.provider_id.nil? ? "Front End" : "Provider" ) + ")" -<!-- Disabled until condor can support new HWP model --> -<!-- = link_to 'Edit', edit_admin_hardware_profile_path(@hardware_profile), :class => 'button' --> + = link_to 'Edit', edit_admin_hardware_profile_path(@hardware_profile), :class => 'button' %table = sortable_table_header @properties_header - @hwp_properties.each do |hwpp| @@ -9,14 +8,6 @@ %td =hwpp.name.nil? ? "n/a" : hwpp.name %td - =hwpp.kind.nil? ? "n/a" : hwpp.kind - %td - =hwpp.range_first.nil? ? "n/a" : hwpp.range_first - %td - =hwpp.range_last.nil? ? "n/a" : hwpp.range_last - %td - =hwpp.property_enum_entries.empty? ? "n/a" : (hwpp.property_enum_entries.collect { |enum| enum.value.to_s }).join(", ") + =hwpp.unit.nil? ? "n/a" : hwpp.unit %td =hwpp.value.nil? ? "n/a" : hwpp.value - %td - =hwpp.unit.nil? ? "n/a" : hwpp.unit diff --git a/src/features/hardware_profile.feature b/src/features/hardware_profile.feature index ce06e1f..e35e9a3 100644 --- a/src/features/hardware_profile.feature +++ b/src/features/hardware_profile.feature @@ -20,7 +20,7 @@ Feature: Manage Pools | m1-large | 4096 | 4 | 850 | x86_64 | | m1-xlarge | 8192 | 8 | 1690 | x86_64 |
- Scenario: View a Hardware Profiles Properties + Scenario: View a Front End Hardware Profiles Properties Given there are the following conductor hardware profiles: | name | memory | cpu |storage | architecture | | m1-small | 1740 | 2 | 160 | i386 | @@ -29,11 +29,11 @@ Feature: Manage Pools And I am on the the hardware profiles page When I follow "m1-small" Then I should see the following: - | Name | Kind | Range First | Range Last | Enum Entries | Default Value | Unit | - | memory | fixed | n/a | n/a | n/a | 1740 | MB | - | cpu | fixed | n/a | n/a | n/a | 2 | count | - | storage | fixed | n/a | n/a | n/a | 160 | GB | - | architecture | fixed | n/a | n/a | n/a | i386 | label | + | Name | Minimum Value | Unit | + | memory | 1740 | MB | + | cpu | 2 | count | + | storage | 160 | GB | + | architecture | i386 | label |
Scenario: View a Front End Hardware Profiles Matching Provider Hardware Profiles Given there are the following conductor hardware profiles: @@ -84,22 +84,22 @@ Feature: Manage Pools When I follow "mock1" Then I should see "mock1(Front End)"
-# Scenario: Create a new Hardware Profile -# Given I am an authorised user -# And I am on the hardware profiles page -# When I follow "New Hardware Profile" -# Then I should be on the new hardware profile page -# When I fill in "name" with "Test Hardware Profile" -# And I enter the following details for the Hardware Profile Properties -# | name | kind | range_first | range_last | property_enum_entries | value | unit | -# | memory | fixed | | | | 1740 | MB | -# | cpu | range | 1 | 4 | | 2 | count | -# | storage | enum | | | 250, 300, 350 | 300 | GB | -# | architecture | fixed | | | | i386 | label | -# And I press "Save" -# Then I should be on the hardware profiles page -# And I should see the following: -# | Test Hardware Profile | 1740 | 1 - 4 | 250, 300, 350 | i386 | + Scenario: Create a new Hardware Profile + Given I am an authorised user + And I am on the hardware profiles page + When I follow "New Hardware Profile" + Then I should be on the new hardware profile page + When I fill in "name" with "Test Hardware Profile" + And I enter the following details for the Hardware Profile Properties + | name | value | unit | + | memory | 1740 | MB | + | cpu | 2 | count | + | storage | 250 | GB | + | architecture | i386 | label | + And I press "Save" + Then I should be on the hardware profiles page + And I should see the following: + | Test Hardware Profile | 1740 | 2 | 250 | i386 |
# Scenario: Check New Hardware Profile matching Provider Hardware Profiles # Given I am an authorised user @@ -122,24 +122,24 @@ Feature: Manage Pools # | m1-small | 1740 | 1 | 250 | i386 | # | m1-medium | 1740 | 2 | 500 | i386 |
-# Scenario: Update a HardwareProfile -# Given I am an authorised user -# And there are the following aggregator hardware profiles: -# | name | memory | cpu |storage | architecture | -# | m1-small | 1740 | 2 | 160 | i386 | -# And I am on the hardware profiles page -# When I follow "m1-small" -# Then I should see "Properties" -# When I follow "edit" -# Then I should be on the edit hardware profiles page -# When I enter the following details for the Hardware Profile Properties -# | name | kind | range_first | range_last | property_enum_entries | value | -# | memory | fixed | | | | 1740 | -# | cpu | range | 1 | 4 | | 1 | -# | storage | range | 250 | 500 | | 300 | -# | architecture | fixed | | | | i386 | -# And I press "Save" -# Then I should be on the hardware profiles page -# Then I should see the following: -# | Name | Memory | CPU | Storage | Architecture | -# | m1-small | 1740 | 1 - 4 | 250 - 500 | i386 | + Scenario: Update a HardwareProfile + Given I am an authorised user + And there are the following conductor hardware profiles: + | name | memory | cpu |storage | architecture | + | m1-small | 2048 | 4 | 160 | x86_64 | + And I am on the hardware profiles page + When I follow "m1-small" + Then I should see "Properties" + When I follow "edit" + Then I should be on the edit hardware profiles page + When I enter the following details for the Hardware Profile Properties + | name | value | unit | + | memory | 1740 | MB | + | cpu | 2 | count | + | storage | 250 | GB | + | architecture | i386 | label | + And I press "Save" + Then I should be on the hardware profiles page + Then I should see the following: + | Name | Memory | CPU | Storage | Architecture | + | m1-small | 1740 | 2 | 250 | i386 |
From: Martyn Taylor mtaylor@redhat.com
--- .../admin/hardware_profiles_controller.rb | 4 +- src/app/models/hardware_profile.rb | 184 +++++------- .../_matching_provider_hardware_profiles.haml | 40 ++- src/features/hardware_profile.feature | 47 ++-- .../step_definitions/hardware_profile_steps.rb | 15 +- src/spec/models/hardware_profile_spec.rb | 332 ++++++-------------- 6 files changed, 233 insertions(+), 389 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb index 04e291f..8c3cf75 100644 --- a/src/app/controllers/admin/hardware_profiles_controller.rb +++ b/src/app/controllers/admin/hardware_profiles_controller.rb @@ -150,8 +150,8 @@ class Admin::HardwareProfilesController < ApplicationController ]
begin - @matching_hwps = HardwareProfile.matching_hwps(@hardware_profile).map { |hwp| hwp[:hardware_profile] } - rescue + @matching_hwps = HardwareProfile.matching_hardware_profiles(@hardware_profile) + rescue Exception => e @matching_hwps = [] end end diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb index f481213..daa66e7 100644 --- a/src/app/models/hardware_profile.rb +++ b/src/app/models/hardware_profile.rb @@ -138,136 +138,96 @@ class HardwareProfile < ActiveRecord::Base the_property end
- #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, provider=nil) - match_maps = matching_hwps(hwp, provider) - if match_maps.empty? - return nil - end - - 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 + def self.matching_hardware_profiles(hardware_profile) + hardware_profiles = Provider.find(:all).map { |provider| match_provider_hardware_profile(provider, hardware_profile)} + hardware_profiles.select {|hwp| hwp != nil } end
- 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| - match_map = check_properties(hwp, phwp) - if match_map - match_maps << match_map + def self.match_provider_hardware_profile(provider, hardware_profile) + hardware_profiles = match_hardware_profiles(provider, hardware_profile) + matched_hwp = hardware_profiles.first + value = '99999999' + hardware_profiles.each do |hwp| + case hwp.memory.kind + when "fixed" + if BigDecimal.new(hwp.memory.value.to_s) < BigDecimal.new(value.to_s) + value = hwp.memory.value + matched_hwp = hwp + end + when "range" + if BigDecimal.new(hwp.memory.range_last.to_s) < BigDecimal.new(value.to_s) + value = hwp.memory.range_last + matched_hwp = hwp + end + when "enum" + values = create_array_from_property(hwp.memory.to_s).sort + if BigDecimal.new(value.last) < BigDecimal.new(value.to_s) + value = values.last + matched_hwp = hwp + end end end - return match_maps + return matched_hwp end
- private - def self.set_non_default_value(hwpp) - case hwpp.kind - when 'range' - hwpp.value = hwpp.range_first - when 'enum' - hwpp.value = hwpp.property_enum_entries[0] - when 'fixed' - hwpp.value = hwpp.value - end - hwpp.save - end - - def self.check_properties(hwp1, hwp2) - if [hwp1.memory, hwp1.cpu, hwp1.storage, hwp1.architecture, hwp2.memory, hwp2.cpu, hwp2.storage, hwp2.architecture].include?(nil) - return nil - end - - hwpp_mem = check_hwp_property(hwp1.memory, hwp2.memory) - hwpp_cpu = check_hwp_property(hwp1.cpu, hwp2.cpu) - hwpp_storage = check_hwp_property(hwp1.storage, hwp2.storage) - hwpp_arch = check_hwp_property(hwp1.architecture, hwp2.architecture) - hwpps = [hwpp_mem, hwpp_cpu, hwpp_storage, hwpp_arch] - - if hwpps.include?(nil) - return nil - else - hwpps.each do |hwpp| - set_non_default_value(hwpp) - end - return { :memory => hwpp_mem, :cpu => hwpp_cpu, :storage => hwpp_storage, :architecture => hwpp_arch, :hardware_profile => hwp2} - end + def self.generate_override_property_values(front_end_hwp, back_end_hwp) + property_overrides = {} + property_overrides[:memory] = generate_override_property_value(front_end_hwp.memory, back_end_hwp.memory) + property_overrides[:storage] = generate_override_property_value(front_end_hwp.storage, back_end_hwp.storage) + property_overrides[:cpu] = generate_override_property_value(front_end_hwp.cpu, back_end_hwp.cpu) + property_overrides[:architecture] = front_end_hwp.architecture.value + return property_overrides end
- def self.check_hwp_property(p1, p2) - if p1.kind == 'range' - calculate_range_match(p1, p2) - elsif p2.kind == 'range' - calculate_range_match(p2, p1) - else - matched_values = (create_array_from_property(p1) & create_array_from_property(p2)) - if !matched_values.empty? - if p1.kind == 'fixed' || p2.kind == 'fixed' - HardwareProfileProperty.new(:kind => 'fixed', :value => matched_values[0], :name => p1.name, :unit => p1.unit) - else - hwpp = HardwareProfileProperty.new(:kind => 'enum') - matched_values.each do |enum_value| - hwpp.property_enum_entries << PropertyEnumEntry.new(:hardware_profile_property => hwpp, :value => enum_value) + private + def self.generate_override_property_value(front_end_property, back_end_property) + case back_end_property.kind + when "fixed" + return back_end_property.value + when "range" + return front_end_property.value + when "enum" + create_array_from_property(back_end_property).sort!.each do |value| + if BigDecimal.new(value) >= BigDecimal.new(front_end_property.value) + return value end - return hwpp end - else - return nil - end end + return nil end
- def self.calculate_range_match(p1, p2) - case p2.kind - when 'range' - if !(BigDecimal.new(p1.range_first) > BigDecimal.new(p2.range_last) || BigDecimal.new(p1.range_last) < BigDecimal.new(p2.range_first)) - hwpp = HardwareProfileProperty.new(:kind => 'range', :unit => p1.unit, :name => p1.name) + def self.match_hardware_profiles(provider, hardware_profile) + back_end_profiles = provider.hardware_profiles + back_end_profiles.select { |hwp| match_hardware_profile(hardware_profile, hwp)} + end
- hwpp.range_first = BigDecimal.new(p1.range_first) >= BigDecimal.new(p2.range_first) ? p1.range_first : p2.range_first - hwpp.range_last = BigDecimal.new(p1.range_last) <= BigDecimal.new(p2.range_last) ? p1.range_last : p2.range_last + def self.match_hardware_profile(front_end_hwp, back_end_hwp) + if back_end_hwp.name == "opaque" + return false + end
- return hwpp - else - return nil - end + match_hardware_profile_property(front_end_hwp.memory, back_end_hwp.memory) && + match_hardware_profile_property(front_end_hwp.cpu, back_end_hwp.cpu) && + match_hardware_profile_property(front_end_hwp.storage, back_end_hwp.storage) && + front_end_hwp.architecture.value == back_end_hwp.architecture.value + end
- when 'enum' - hwpp = HardwareProfileProperty.new(:kind => 'enum', :unit => p1.unit, :name => p1.name) - p2.property_enum_entries.each do |enum| - if (BigDecimal.new(p1.range_first)..BigDecimal.new(p1.range_last)) === BigDecimal.new(enum.value) - hwpp.property_enum_entries << PropertyEnumEntry.new(:hardware_profile_property => hwpp, :value => enum.value) + def self.match_hardware_profile_property(front_end_property, back_end_property) + match = false + case back_end_property.kind + when "fixed" + match = BigDecimal.new(back_end_property.value.to_s) >= BigDecimal.new(front_end_property.value.to_s) ? true : false + when "range" + match = BigDecimal.new(back_end_property.range_last.to_s) >= BigDecimal.new(front_end_property.value.to_s) && + BigDecimal.new(back_end_property.range_first.to_s) <= BigDecimal.new(front_end_property.value.to_s) ? true : false + when "enum" + create_array_from_property(back_end_property).each do |value| + if BigDecimal.new(value) >= BigDecimal.new(front_end_property.value.to_s) + match = true + end end - end - return hwpp.property_enum_entries.empty? ? nil : hwpp - - when 'fixed' - return (BigDecimal.new(p1.range_first)..BigDecimal.new(p1.range_last)) === BigDecimal.new(p2.value) ? HardwareProfileProperty.new(:kind => 'fixed', :value => p2.value, :name => p2.name, :unit => p2.unit) : nil - - else - return nil - end + return match end
def self.create_array_from_property(p) diff --git a/src/app/views/admin/hardware_profiles/_matching_provider_hardware_profiles.haml b/src/app/views/admin/hardware_profiles/_matching_provider_hardware_profiles.haml index 0f4ba7b..49c45e3 100644 --- a/src/app/views/admin/hardware_profiles/_matching_provider_hardware_profiles.haml +++ b/src/app/views/admin/hardware_profiles/_matching_provider_hardware_profiles.haml @@ -1,20 +1,24 @@ - if @hardware_profile - %h3 + %h2 =@hardware_profile.name -%table - = sortable_table_header @provider_hwps_header - - @matching_hwps.each do |hwp| - %tr - %td - - if hwp.provider - = link_to hwp.provider.name, admin_provider_path(hwp.provider) - %td - = link_to hwp.name, admin_hardware_profile_path(hwp) - %td - =hwp.architecture.to_s - %td - =hwp.memory.to_s - %td - =hwp.storage.to_s - %td - =hwp.cpu.to_s \ No newline at end of file +- if @matching_hwps.size > 0 + %table + = sortable_table_header @provider_hwps_header + - @matching_hwps.each do |hwp| + %tr + %td + - if hwp.provider + = link_to hwp.provider.name, admin_provider_path(hwp.provider) + %td + = link_to hwp.name, admin_hardware_profile_path(hwp) + %td + =hwp.architecture.to_s + %td + =hwp.memory.to_s + %td + =hwp.storage.to_s + %td + =hwp.cpu.to_s +- else + %h3 + No Matching Provider Hardware Profiles Could be found \ No newline at end of file diff --git a/src/features/hardware_profile.feature b/src/features/hardware_profile.feature index e35e9a3..0094ac1 100644 --- a/src/features/hardware_profile.feature +++ b/src/features/hardware_profile.feature @@ -101,26 +101,33 @@ Feature: Manage Pools And I should see the following: | Test Hardware Profile | 1740 | 2 | 250 | i386 |
-# Scenario: Check New Hardware Profile matching Provider Hardware Profiles -# Given I am an authorised user -# And there are the following provider hardware profiles: -# | name | memory | cpu |storage | architecture | -# | m1-small | 1740 | 1 | 250 | i386 | -# | m1-medium | 1740 | 2 | 500 | i386 | -# | m1-large | 2048 | 4 | 850 | x86_64 | -# And I am on the new hardware profile page -# When I fill in "name" with "Test Hardware Profile" -# And I enter the following details for the Hardware Profile Properties -# | name | kind | range_first | range_last | property_enum_entries | value | unit | -# | memory | fixed | | | | 1740 | MB | -# | cpu | range | 1 | 4 | | 2 | count | -# | storage | range | 250 | 500 | | 300 | GB | -# | architecture | fixed | | | | i386 | label | -# And I press "Check Matches" -# Then I should see the following: -# | Name | Memory | CPU | Storage | Architecture | -# | m1-small | 1740 | 1 | 250 | i386 | -# | m1-medium | 1740 | 2 | 500 | i386 | + Scenario: Check New Hardware Profile matching Provider Hardware Profiles + Given I am an authorised user + And there is a provider named "provider1" + And there is a provider named "provider2" + And "provider1" has the following hardware profiles: + | name | memory | cpu |storage | architecture | + | m1-small | 1740 | 1 | 250 | i386 | + | m1-medium | 1740 | 2 | 500 | i386 | + | m1-large | 2048 | 4 | 850 | x86_64 | + And "provider2" has the following hardware profiles: + | name | memory | cpu |storage | architecture | + | m1-small | 4048 | 4 | 500 | i386 | + | m1-medium | 8192 | 4 | 500 | i386 | + | m1-large | 2048 | 4 | 850 | x86_64 | + And I am on the new hardware profile page + When I fill in "name" with "Test Hardware Profile" + And I enter the following details for the Hardware Profile Properties + | name | value | unit | + | memory | 1740 | MB | + | cpu | 2 | count | + | storage | 300 | GB | + | architecture | i386 | label | + And I press "Check Matches" + Then I should see the following: + | Provider | Name | Memory | CPU | Storage | Architecture | + | provider1 | m1-medium | 1740 | 2 | 500 | i386 | + | provider2 | m1-small | 4048 | 4 | 500 | i386 |
Scenario: Update a HardwareProfile Given I am an authorised user diff --git a/src/features/step_definitions/hardware_profile_steps.rb b/src/features/step_definitions/hardware_profile_steps.rb index 3b4c382..c014cf9 100644 --- a/src/features/step_definitions/hardware_profile_steps.rb +++ b/src/features/step_definitions/hardware_profile_steps.rb @@ -37,9 +37,7 @@ end
Given /^there are the following provider hardware profiles:$/ do |table| provider = Factory :mock_provider - table.hashes.each do |hash| - create_hwp(hash, provider) - end + create_provider_hardware_profiles(provider, table) end
Given /^there are (\d+) hardware profiles$/ do |count| @@ -47,3 +45,14 @@ Given /^there are (\d+) hardware profiles$/ do |count| Factory(:mock_hwp1, :name => "hwprofile#{i}") end end + +Given /^"([^"]*)" has the following hardware profiles:$/ do |provider_name, table| + provider = Provider.find_by_name(provider_name) + create_provider_hardware_profiles(provider, table) +end + +def create_provider_hardware_profiles(provider, table) + table.hashes.each do |hash| + create_hwp(hash, provider) + end +end \ No newline at end of file diff --git a/src/spec/models/hardware_profile_spec.rb b/src/spec/models/hardware_profile_spec.rb index b25712e..6ca8ca6 100644 --- a/src/spec/models/hardware_profile_spec.rb +++ b/src/spec/models/hardware_profile_spec.rb @@ -86,261 +86,125 @@ describe HardwareProfile do @hp.memory.kind.should equal(@hp.memory.kind.to_s) end
- it "should calculate all the correct matches of provider hardware profiles against a given hardware profile" do - provider = Factory(:mock_provider) - HardwareProfile.find(:all, :conditions => {:provider_id => provider.id}).each do |hwp| - hwp.destroy - end - - # hwpp memory - hwpp_mem_match_all = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :range_first => '1', :range_last => '4096', :value => '256') - hwpp_mem_match_none = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '8192') - hwpp_mem_match_2 = create_hwpp_enum(['256', '1024'], {:name => 'memory', :unit => 'MB'}) - - hwpp_mem_range = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :range_first => '256', :range_last => '512', :value => '256') - hwpp_mem_fixed = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '4096') - hwpp_mem_enum = create_hwpp_enum(['1024', '3072', '4096'], {:name => 'memory', :unit => 'MB'}) - - # hwpp cpu - hwpp_cpu_match_all = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :range_first => '1', :range_last => '32', :value => '2') - hwpp_cpu_match_none = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '64') - hwpp_cpu_match_2 = create_hwpp_enum(['8', '16'], {:name => 'cpu', :unit => 'count'}) - - hwpp_cpu_range = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :range_first => '1', :range_last => '16', :value => '4') - hwpp_cpu_fixed = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '32') - hwpp_cpu_enum = create_hwpp_enum(['16', '32'], {:name => 'cpu', :unit => 'count'}) - - # hwpp storage - hwpp_storage_match_all = Factory(:hwpp_range, :name => 'storage', :unit => 'GB', :range_first => '100', :range_last => '4000', :value => '250') - hwpp_storage_match_none = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '4000') - hwpp_storage_match_2 = create_hwpp_enum(['1000', '2000'], {:name => 'storage', :unit => 'GB'}) - - hwpp_storage_range = Factory(:hwpp_range, :name => 'storage', :unit => 'GB', :range_first => '100', :range_last => '1000', :value => '250') - hwpp_storage_fixed = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '3000') - hwpp_storage_enum = create_hwpp_enum(['2000', '4000'], {:name => 'storage', :unit => 'GB'}) - - # hwpp arch - hwpp_arch_i386 = Factory(:hwpp_arch, :value => 'i386') - hwpp_arch_i386_enum = create_hwpp_enum(['i386', 'x86_64'], {:name => 'architecture', :unit => 'label'}) - - hwp_match_all = Factory(:hardware_profile, :memory => hwpp_mem_match_all, - :cpu => hwpp_cpu_match_all, - :storage => hwpp_storage_match_all, - :architecture => hwpp_arch_i386) - - hwp_match_none = Factory(:hardware_profile, :memory => hwpp_mem_match_none, - :cpu => hwpp_cpu_match_none, - :storage => hwpp_storage_match_none, - :architecture => hwpp_arch_i386) - - hwp_match_2 = Factory(:hardware_profile, :memory => hwpp_mem_match_2, - :cpu => hwpp_cpu_match_2, - :storage => hwpp_storage_match_2, - :architecture => hwpp_arch_i386) - - hwp1 = Factory(:hardware_profile, :memory => hwpp_mem_range, - :cpu => hwpp_cpu_range, - :storage => hwpp_storage_range, - :architecture => hwpp_arch_i386, - :provider => provider) - - hwp2 = Factory(:hardware_profile, :memory => hwpp_mem_fixed, - :cpu => hwpp_cpu_fixed, - :storage => hwpp_storage_fixed, - :architecture => hwpp_arch_i386, - :provider => provider) - - hwp3 = Factory(:hardware_profile, :memory => hwpp_mem_enum, - :cpu => hwpp_cpu_enum, - :storage => hwpp_storage_enum, - :architecture => hwpp_arch_i386_enum, - :provider => provider) - - hwp4 = Factory(:hardware_profile, :memory => hwpp_mem_enum, - :cpu => nil, - :storage => hwpp_storage_enum, - :architecture => hwpp_arch_i386, - :provider => provider) - - HardwareProfile.matching_hwps(hwp_match_all).size.should == 3 - HardwareProfile.matching_hwps(hwp_match_none).empty?.should == true - HardwareProfile.matching_hwps(hwp_match_2).size.should == 2 - - end + it "should match the correct back end hardware profile for a given provider" do + provider = Factory :mock_provider + + front_end_memory = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '2048') + front_end_storage = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '850') + front_end_cpu = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '2') + front_end_architecture = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64') + + back_end_memory1 = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '1024', :range_last => '4048') + back_end_storage1 = create_hwpp_enum(['500', '1500', '2000'], {:name => 'storage', :unit => 'GB', :value => '1500'}) + back_end_cpu1 = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '1', :range_last => '4') + back_end_architecture1 = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64') + + back_end_memory2 = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '1024', :range_last => '8192') + back_end_storage2 = create_hwpp_enum(['1500', '2000', '2500'], {:name => 'storage', :unit => 'GB', :value => '1500'}) + back_end_cpu2 = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '1', :range_last => '8') + back_end_architecture2 = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64') + + back_end_memory3 = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '1024', :range_last => '16384') + back_end_storage3 = create_hwpp_enum(['2000', '2500', '3000'], {:name => 'storage', :unit => 'GB', :value => '2000'}) + back_end_cpu3 = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '1', :range_last => '16') + back_end_architecture3 = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
- it "should calculate the correct array for hardware profile properties of kind: 'fixed' and 'enum'" do - hwp_fixed = Factory(:hwpp_fixed, :value => '256') + front_end_hardware_profile = Factory(:hardware_profile, :memory => front_end_memory, + :cpu => front_end_cpu, + :storage => front_end_storage, + :architecture => front_end_architecture)
- enum_array = ['256', '512', '1024', '2048'] - hwp_enum = create_hwpp_enum(enum_array) + back_end_hardware_profile1 = Factory(:hardware_profile, :memory => back_end_memory1, + :cpu => back_end_cpu1, + :storage => back_end_storage1, + :architecture => back_end_architecture1)
- HardwareProfile.create_array_from_property(hwp_fixed).should == ['256'] - (HardwareProfile.create_array_from_property(hwp_enum) & enum_array).should == enum_array - end - - it "should determine match for 2 hardware profiles" do - hwpp_mem_range = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :range_first => '256', :range_last => '512', :value => '256') - hwpp_mem_fixed = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '1024') - hwpp_mem_enum = create_hwpp_enum(['2048', '3072', '4096'], {:name => 'memory', :unit => 'MB'}) + back_end_hardware_profile2 = Factory(:hardware_profile, :memory => back_end_memory2, + :cpu => back_end_cpu2, + :storage => back_end_storage2, + :architecture => back_end_architecture2)
- hwpp_cpu_range = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :range_first => '1', :range_last => '4', :value => '2') - hwpp_cpu_fixed = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '8') - hwpp_cpu_enum = create_hwpp_enum(['16', '32'], {:name => 'cpu', :unit => 'count'}) + back_end_hardware_profile3 = Factory(:hardware_profile, :memory => back_end_memory3, + :cpu => back_end_cpu3, + :storage => back_end_storage3, + :architecture => back_end_architecture3)
- hwpp_storage_range = Factory(:hwpp_range, :name => 'storage', :unit => 'GB', :range_first => '100', :range_last => '500', :value => '250') - hwpp_storage_fixed = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '1000') - hwpp_storage_enum = create_hwpp_enum(['2000', '4000'], {:name => 'storage', :unit => 'GB'}) + provider.hardware_profiles << [back_end_hardware_profile1, back_end_hardware_profile2, back_end_hardware_profile3]
- hwpp_arch_i386 = Factory(:hwpp_arch, :value => 'i386') - hwpp_arch_x86_64 = Factory(:hwpp_arch, :value => 'x86_64') - - hwp1 = Factory(:hardware_profile, :memory => hwpp_mem_range, :cpu => hwpp_cpu_range, :storage => hwpp_storage_range, :architecture => hwpp_arch_i386) - hwp2 = Factory(:hardware_profile, :memory => hwpp_mem_fixed, :cpu => hwpp_cpu_fixed, :storage => hwpp_storage_fixed, :architecture => hwpp_arch_i386) - hwp3 = Factory(:hardware_profile, :memory => hwpp_mem_enum, :cpu => hwpp_cpu_enum, :storage => hwpp_storage_enum, :architecture => hwpp_arch_i386) - hwp4 = Factory(:hardware_profile, :memory => hwpp_mem_enum, :cpu => hwpp_cpu_enum, :storage => hwpp_storage_enum, :architecture => hwpp_arch_x86_64) - hwp5 = Factory(:hardware_profile, :memory => hwpp_mem_enum, :cpu => hwpp_cpu_enum, :storage => nil, :architecture => hwpp_arch_x86_64) + HardwareProfile.match_provider_hardware_profile(provider, front_end_hardware_profile).should == back_end_hardware_profile1 + end
- # Check memory match - match_map = HardwareProfile.check_properties(hwp1, hwp1) - match_map[:memory].kind.should == 'range' - match_map[:memory].range_first.should == '256' - match_map[:memory].range_last.should == '512' + it "should generate the correct override property values for a given property" do + front_end_memory = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '2048') + front_end_storage = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '850') + front_end_cpu = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '2') + front_end_architecture = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
- match_map[:cpu].kind.should == 'range' - match_map[:cpu].range_first.should == '1' - match_map[:cpu].range_last.should == '4' + back_end_memory = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '1024', :range_last => '4048') + back_end_storage = create_hwpp_enum(['500', '1500', '2000'], {:name => 'storage', :unit => 'GB', :value => '1500'}) + back_end_cpu = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '1', :range_last => '8') + back_end_architecture = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
- match_map[:storage].kind.should == 'range' - match_map[:storage].range_first.should == '100' - match_map[:storage].range_last.should == '500' + HardwareProfile.generate_override_property_value(front_end_memory, back_end_memory).should == '2048' + HardwareProfile.generate_override_property_value(front_end_storage, back_end_storage).should == '1500' + HardwareProfile.generate_override_property_value(front_end_cpu, back_end_cpu).should == '2' + end
- # Check fixed match - match_map = HardwareProfile.check_properties(hwp2, hwp2) - match_map[:memory].kind.should == 'fixed' - match_map[:memory].value.should == '1024' + it "should correctly match a front end hardware profile with a back end hardware profile" do + front_end_memory = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '2048') + front_end_storage = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '850') + front_end_cpu = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '2') + front_end_architecture = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
- match_map[:cpu].kind.should == 'fixed' - match_map[:cpu].value.should == '8' + back_end_memory_match = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '1024', :range_last => '4048') + back_end_storage_match = create_hwpp_enum(['850', '1500', '2000'], {:name => 'storage', :unit => 'GB', :value => '1500'}) + back_end_cpu_match = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '1', :range_last => '8') + back_end_architecture_match = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
- match_map[:storage].kind.should == 'fixed' - match_map[:storage].value.should == '1000' + back_end_memory_fail = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '4048', :range_last => '8192') + back_end_storage_fail = create_hwpp_enum(['1000', '1500', '2000'], {:name => 'storage', :unit => 'GB', :value => '1500'}) + back_end_cpu_fail = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '4', :range_last => '8') + back_end_architecture_fail = Factory(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
- # Check enums match - match_map = HardwareProfile.check_properties(hwp3, hwp3) - match_map[:memory].kind.should == 'enum' - check_enum_entries_match(match_map[:memory], ['2048', '3072', '4096']) + front_end_hardware_profile = Factory(:hardware_profile, :memory => front_end_memory, + :cpu => front_end_cpu, + :storage => front_end_storage, + :architecture => front_end_architecture)
- match_map[:cpu].kind.should == 'enum' - check_enum_entries_match(match_map[:cpu], ['16', '32']) + back_end_hardware_profile_match = Factory(:hardware_profile, :memory => back_end_memory_match, + :cpu => back_end_cpu_match, + :storage => back_end_storage_match, + :architecture => back_end_architecture_match)
- match_map[:storage].kind.should == 'enum' - check_enum_entries_match(match_map[:storage], ['2000', '4000']) + back_end_hardware_profile_fail = Factory(:hardware_profile, :memory => back_end_memory_fail, + :cpu => back_end_cpu_fail, + :storage => back_end_storage_fail, + :architecture => back_end_architecture_fail)
- HardwareProfile.check_properties(hwp1, hwp2).should == nil - HardwareProfile.check_properties(hwp2, hwp3).should == nil - HardwareProfile.check_properties(hwp3, hwp4).should == nil - HardwareProfile.check_properties(hwp4, hwp5).should == nil + HardwareProfile.match_hardware_profile(front_end_hardware_profile, back_end_hardware_profile_match).should == true + HardwareProfile.match_hardware_profile(front_end_hardware_profile, back_end_hardware_profile_fail).should == false end
- it "should calculate matches for range on hardware profile properties" do - hwp_range = Factory(:hwpp_range, :range_first => '256', :range_last => '512', :value => '256') - - hwp_range_match = Factory(:hwpp_range, :range_first => '512', :range_last => '1024', :value => '512') - hwp_range_fail = Factory(:hwpp_range, :range_first => '2048', :range_last => '2048', :value => '8192') - - hwp_fixed_match = Factory(:hwpp_fixed, :value => '256') - hwp_fixed_fail = Factory(:hwpp_fixed, :value => '4096') - - hwp_enum_match = create_hwpp_enum(['256', '512', '1024', '2048']) - hwp_enum_fail = create_hwpp_enum(['2048', '4096', '8192', '16384']) + it "should correctly match front end hardware profile properties with back end hardware profile properties" do + front_end_memory = Factory(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '2048') + front_end_storage = Factory(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '850') + front_end_cpu = Factory(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '2')
- hwpp = HardwareProfile.calculate_range_match(hwp_range, hwp_range_match) - hwpp.kind.should == 'range' - hwpp.range_first.should == '512' - hwpp.range_last.should == '512' + back_end_memory_match = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '1024', :range_last => '4048') + back_end_storage_match = create_hwpp_enum(['850', '1500', '2000'], {:name => 'storage', :unit => 'GB', :value => '1500'}) + back_end_cpu_match = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '1', :range_last => '8')
- hwpp = HardwareProfile.calculate_range_match(hwp_range, hwp_fixed_match) - hwpp.kind.should == 'fixed' - hwpp.value.should == '256' + back_end_memory_fail = Factory(:hwpp_range, :name => 'memory', :unit => 'MB', :value => '4048', :range_first => '4048', :range_last => '8192') + back_end_storage_fail = create_hwpp_enum(['250', '500', '750'], {:name => 'storage', :unit => 'GB', :value => '500'}) + back_end_cpu_fail = Factory(:hwpp_range, :name => 'cpu', :unit => 'count', :value => '4', :range_first => '4', :range_last => '8')
- hwpp = HardwareProfile.calculate_range_match(hwp_range, hwp_enum_match) - check_enum_entries_match(hwpp, ['256', '512']) - - [hwp_range_fail, hwp_fixed_fail, hwp_enum_fail].each do |hwpp| - HardwareProfile.calculate_range_match(hwp_range, hwpp).should == nil - end - end + HardwareProfile.match_hardware_profile_property(front_end_memory, back_end_memory_match).should == true + HardwareProfile.match_hardware_profile_property(front_end_storage, back_end_storage_match).should == true + HardwareProfile.match_hardware_profile_property(front_end_cpu, back_end_cpu_match).should == true
- it "should calculate correct matches for each hwp property" do - hwp_range1 = Factory(:hwpp_range, :range_first => '256', :range_last => '512', :value => '512') - hwp_range2 = Factory(:hwpp_range, :range_first => '512', :range_last => '1024', :value => '768') - hwp_range3 = Factory(:hwpp_range, :range_first => '2048', :range_last => '4096', :value => '3072') - - hwp_fixed1 = Factory(:hwpp_fixed, :value => '256') - hwp_fixed2 = Factory(:hwpp_fixed, :value => '4096') - hwp_fixed3 = Factory(:hwpp_fixed, :value => '8192') - - hwp_enum1 = create_hwpp_enum(['256', '512', '1024']) - hwp_enum2 = create_hwpp_enum(['1024', '2048', '3072']) - hwp_enum3 = create_hwpp_enum(['8192', '16384', '32768']) - - # == Test HWPP against Ranges == - # -- Expected Matches - hwpp = HardwareProfile.check_hwp_property(hwp_range1, hwp_range2) - hwpp.kind.should == 'range' - hwpp.range_first.should == '512' - hwpp.range_last.should == '512' - - hwpp = HardwareProfile.check_hwp_property(hwp_range1, hwp_fixed1) - hwpp.kind.should == 'fixed' - hwpp.value.should == '256' - - hwpp = HardwareProfile.check_hwp_property(hwp_range1, hwp_enum1) - hwpp.kind.should == 'enum' - check_enum_entries_match(hwpp, ['256', '512']) - - # -- Expected Failures - HardwareProfile.check_hwp_property(hwp_range1, hwp_enum3).should == nil - HardwareProfile.check_hwp_property(hwp_range1, hwp_range3).should == nil - HardwareProfile.check_hwp_property(hwp_range1, hwp_fixed3).should == nil - - # == Test HWPP Against Fixed == - # -- Expected Matches - hwpp = HardwareProfile.check_hwp_property(hwp_fixed1, hwp_range1) - hwpp.kind.should == 'fixed' - hwpp.value.should == '256' - - hwpp = HardwareProfile.check_hwp_property(hwp_fixed1, hwp_fixed1) - hwpp.kind.should == 'fixed' - hwpp.value.should == '256' - - hwpp = HardwareProfile.check_hwp_property(hwp_fixed1, hwp_enum1) - hwpp.kind.should == 'fixed' - hwpp.value == '512' - - # -- Expected Failures - HardwareProfile.check_hwp_property(hwp_fixed1, hwp_range3).should == nil - HardwareProfile.check_hwp_property(hwp_fixed1, hwp_fixed2).should == nil - HardwareProfile.check_hwp_property(hwp_fixed1, hwp_enum3).should == nil - - # == Test HWPP Aginsts Enums == - # --Expected Matches - hwpp = HardwareProfile.check_hwp_property(hwp_enum1, hwp_range1) - hwpp.kind.should == 'enum' - check_enum_entries_match(hwpp, ['256', '512']) - - hwpp = HardwareProfile.check_hwp_property(hwp_enum1, hwp_fixed1) - hwpp.kind.should == 'fixed' - hwpp.value.should == '256' - - hwpp = HardwareProfile.check_hwp_property(hwp_enum1, hwp_enum2) - hwpp.kind.should == 'enum' - check_enum_entries_match(hwpp, ['1024']) - - # -- Expected Failures - HardwareProfile.check_hwp_property(hwp_enum1, hwp_range3).should == nil - HardwareProfile.check_hwp_property(hwp_enum1, hwp_fixed2).should == nil - HardwareProfile.check_hwp_property(hwp_enum1, hwp_enum3).should == nil + HardwareProfile.match_hardware_profile_property(front_end_memory, back_end_memory_fail).should == false + HardwareProfile.match_hardware_profile_property(front_end_storage, back_end_storage_fail).should == false + HardwareProfile.match_hardware_profile_property(front_end_cpu, back_end_cpu_fail).should == false end
def create_hwpp_enum(value_array, properties = {}) @@ -358,4 +222,4 @@ describe HardwareProfile do end enum_set.should == value_array end -end +end \ No newline at end of file
From: Martyn Taylor mtaylor@redhat.com
--- .../admin/hardware_profiles_controller.rb | 17 ---------------- src/features/api.feature | 21 -------------------- 2 files changed, 0 insertions(+), 38 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb index 8c3cf75..c56658f 100644 --- a/src/app/controllers/admin/hardware_profiles_controller.rb +++ b/src/app/controllers/admin/hardware_profiles_controller.rb @@ -98,23 +98,6 @@ class Admin::HardwareProfilesController < ApplicationController redirect_to admin_hardware_profiles_path end
- def matching_profiles - begin - hwp = HardwareProfile.find(params[:hardware_profile_id]) - provider = Provider.find(params[:provider_id]) - @hardware_profile = HardwareProfile.match_hwp(hwp, provider) - if !@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 - head :internal_server_error - end - end - private def setup_new_hardware_profile if params[:hardware_profile] diff --git a/src/features/api.feature b/src/features/api.feature index 0642eb7..4ff624a 100644 --- a/src/features/api.feature +++ b/src/features/api.feature @@ -7,27 +7,6 @@ Feature: User authentication Given I am an authorised user And I am logged in
- Scenario: Get matched HardwareProfile - Given I am an authorised user - Given there are the following provider hardware profiles: - | name | memory | cpu |storage | architecture | - | m1-small | 1740 | 1 | 250 | i386 | - | m1-medium | 4096 | 4 | 850 | x86_64 | - Given there are the following conductor hardware profiles: - | name | memory | cpu |storage | architecture | - | agg-medium | 4096 | 4 | 850 | x86_64 | - 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: "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 | - Scenario: Check can start instance Given there is a user "testuser" And there is a provider named "testprovider"
ACK to the series.
On 03/02/2011 10:57 AM, mtaylor@redhat.com wrote:
From: Martyn Taylormtaylor@redhat.com
.../admin/hardware_profiles_controller.rb | 26 +----- src/app/views/admin/hardware_profiles/_form.haml | 20 +---- src/app/views/admin/hardware_profiles/_list.haml | 5 +- .../views/admin/hardware_profiles/_properties.haml | 13 +--- src/features/hardware_profile.feature | 86 ++++++++++---------- 5 files changed, 56 insertions(+), 94 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb b/src/app/controllers/admin/hardware_profiles_controller.rb index 75c6ab1..04e291f 100644 --- a/src/app/controllers/admin/hardware_profiles_controller.rb +++ b/src/app/controllers/admin/hardware_profiles_controller.rb @@ -133,13 +133,8 @@ class Admin::HardwareProfilesController< ApplicationController def properties @properties_header = [ { :name => "Name", :sort_attr => :name},
{ :name => "Kind", :sort_attr => :kind },
{ :name => "Range First", :sort_attr => :range_first},
{ :name => "Range Last", :sort_attr => :range_last },
{ :name => "Enum Entries", :sort_attr => :false },
{ :name => "Default Value", :sort_attr => :value},
{ :name => "Unit", :sort_attr => :unit}
]
{ :name => "Unit", :sort_attr => :unit},
end{ :name => "Minimum Value", :sort_attr => :value}] @hwp_properties = [@hardware_profile.memory, @hardware_profile.cpu, @hardware_profile.storage, @hardware_profile.architecture]
@@ -168,11 +163,7 @@ class Admin::HardwareProfilesController< ApplicationController @header = [ { :name => "Name", :sort_attr => :name}, { :name => "Unit", :sort_attr => :unit},
{ :name => "Kind", :sort_attr => :kind },
{ :name => "Value (Default)", :sort_attr => :value},
{ :name => "Enum Entries", :sort_attr => :false },
{ :name => "Range First", :sort_attr => :range_first},
{ :name => "Range Last", :sort_attr => :range_last }]
{ :name => "Minimum Value", :sort_attr => :value}]
end
def set_params_and_header
@@ -210,17 +201,10 @@ class Admin::HardwareProfilesController< ApplicationController hwpp.nil? ? hardwareProfileProperty = HardwareProfileProperty.new : hardwareProfileProperty = hwpp
hardwareProfileProperty.name = params[:name]
- hardwareProfileProperty.kind = params[:kind]
- hardwareProfileProperty.kind = "fixed" hardwareProfileProperty.value = params[:value] hardwareProfileProperty.unit = params[:unit]
- case hardwareProfileProperty.kind
when "range"
hardwareProfileProperty.range_first = params[:range_first]
hardwareProfileProperty.range_last = params[:range_last]
when "enum"
hardwareProfileProperty.property_enum_entries = params[:property_enum_entries].split(%r{,\s*}).map { |value| PropertyEnumEntry.new(:value => value, :hardware_profile_property => hardwareProfileProperty) }
- end
- hardwareProfileProperty
return hardwareProfileProperty end
end
diff --git a/src/app/views/admin/hardware_profiles/_form.haml b/src/app/views/admin/hardware_profiles/_form.haml index 4327007..70c982b 100644 --- a/src/app/views/admin/hardware_profiles/_form.haml +++ b/src/app/views/admin/hardware_profiles/_form.haml @@ -10,21 +10,9 @@ %td =hwpp_form.text_field(:unit, :size => 5, :readonly => "readonly") %td
-unless type == :architecture
=hwpp_form.select("kind", ["fixed", "range", "enum"], {})
-if type == :architecture
=hwpp_form.select("value", ["i386", "x86_64"], {}) -else
=hwpp_form.select("kind", ["fixed"], {})
%td
=hwpp_form.text_field(:value)
%td
-unless type == :architecture
=hwpp_form.text_field(:property_enum_entries)
%td
-unless type == :architecture
=hwpp_form.text_field(:range_first)
%td
-unless type == :architecture
=hwpp_form.text_field(:range_last)
= hwp_form.submit 'Check Matches', :class => "submit formbutton"=hwpp_form.text_field(:value)
-<!-- Disabled until condor can support new HWP model --> -<!-- = hwp_form.submit 'Save', :class => 'submit formbutton', :disabled => 'disabled' --> \ No newline at end of file += hwp_form.submit 'Save', :class => 'submit formbutton' \ No newline at end of file diff --git a/src/app/views/admin/hardware_profiles/_list.haml b/src/app/views/admin/hardware_profiles/_list.haml index 621f53b..eee5ff1 100644 --- a/src/app/views/admin/hardware_profiles/_list.haml +++ b/src/app/views/admin/hardware_profiles/_list.haml @@ -1,8 +1,7 @@
- form_tag do #object-actions
-<!-- Disabled until condor can support new HWP model --> -<!-- = link_to "New Hardware Profile", new_admin_hardware_profile_path, :class => 'button' --> -<!-- = restful_submit_tag "Delete", "destroy", multi_destroy_admin_hardware_profiles_path -->
- = link_to "New Hardware Profile", new_admin_hardware_profile_path, :class => 'button'
- = restful_submit_tag "Delete", 'destroy', multi_destroy_admin_hardware_profiles_path, 'DELETE', :id => 'delete_button' #selections %p Select:
diff --git a/src/app/views/admin/hardware_profiles/_properties.haml b/src/app/views/admin/hardware_profiles/_properties.haml index 04517bf..0739b84 100644 --- a/src/app/views/admin/hardware_profiles/_properties.haml +++ b/src/app/views/admin/hardware_profiles/_properties.haml @@ -1,7 +1,6 @@ %h3 = @hardware_profile.name + "(" + (@hardware_profile.provider_id.nil? ? "Front End" : "Provider" ) + ")" -<!-- Disabled until condor can support new HWP model --> -<!-- = link_to 'Edit', edit_admin_hardware_profile_path(@hardware_profile), :class => 'button' -->
- = link_to 'Edit', edit_admin_hardware_profile_path(@hardware_profile), :class => 'button' %table = sortable_table_header @properties_header
- @hwp_properties.each do |hwpp|
@@ -9,14 +8,6 @@ %td =hwpp.name.nil? ? "n/a" : hwpp.name %td
=hwpp.kind.nil? ? "n/a" : hwpp.kind
%td
=hwpp.range_first.nil? ? "n/a" : hwpp.range_first
%td
=hwpp.range_last.nil? ? "n/a" : hwpp.range_last
%td
=hwpp.property_enum_entries.empty? ? "n/a" : (hwpp.property_enum_entries.collect { |enum| enum.value.to_s }).join(", ")
=hwpp.unit.nil? ? "n/a" : hwpp.unit %td =hwpp.value.nil? ? "n/a" : hwpp.value
%td
=hwpp.unit.nil? ? "n/a" : hwpp.unit
diff --git a/src/features/hardware_profile.feature b/src/features/hardware_profile.feature index ce06e1f..e35e9a3 100644 --- a/src/features/hardware_profile.feature +++ b/src/features/hardware_profile.feature @@ -20,7 +20,7 @@ Feature: Manage Pools | m1-large | 4096 | 4 | 850 | x86_64 | | m1-xlarge | 8192 | 8 | 1690 | x86_64 |
- Scenario: View a Hardware Profiles Properties
- Scenario: View a Front End Hardware Profiles Properties Given there are the following conductor hardware profiles: | name | memory | cpu |storage | architecture | | m1-small | 1740 | 2 | 160 | i386 |
@@ -29,11 +29,11 @@ Feature: Manage Pools And I am on the the hardware profiles page When I follow "m1-small" Then I should see the following:
- | Name | Kind | Range First | Range Last | Enum Entries | Default Value | Unit |
- | memory | fixed | n/a | n/a | n/a | 1740 | MB |
- | cpu | fixed | n/a | n/a | n/a | 2 | count |
- | storage | fixed | n/a | n/a | n/a | 160 | GB |
- | architecture | fixed | n/a | n/a | n/a | i386 | label |
| Name | Minimum Value | Unit |
| memory | 1740 | MB |
| cpu | 2 | count |
| storage | 160 | GB |
| architecture | i386 | label |
Scenario: View a Front End Hardware Profiles Matching Provider Hardware Profiles Given there are the following conductor hardware profiles:
@@ -84,22 +84,22 @@ Feature: Manage Pools When I follow "mock1" Then I should see "mock1(Front End)"
-# Scenario: Create a new Hardware Profile -# Given I am an authorised user -# And I am on the hardware profiles page -# When I follow "New Hardware Profile" -# Then I should be on the new hardware profile page -# When I fill in "name" with "Test Hardware Profile" -# And I enter the following details for the Hardware Profile Properties -# | name | kind | range_first | range_last | property_enum_entries | value | unit | -# | memory | fixed | | | | 1740 | MB | -# | cpu | range | 1 | 4 | | 2 | count | -# | storage | enum | | | 250, 300, 350 | 300 | GB | -# | architecture | fixed | | | | i386 | label | -# And I press "Save" -# Then I should be on the hardware profiles page -# And I should see the following: -# | Test Hardware Profile | 1740 | 1 - 4 | 250, 300, 350 | i386 |
Scenario: Create a new Hardware Profile
Given I am an authorised user
And I am on the hardware profiles page
When I follow "New Hardware Profile"
Then I should be on the new hardware profile page
When I fill in "name" with "Test Hardware Profile"
And I enter the following details for the Hardware Profile Properties
| name | value | unit |
| memory | 1740 | MB |
| cpu | 2 | count |
| storage | 250 | GB |
| architecture | i386 | label |
And I press "Save"
Then I should be on the hardware profiles page
And I should see the following:
| Test Hardware Profile | 1740 | 2 | 250 | i386 |
# Scenario: Check New Hardware Profile matching Provider Hardware Profiles # Given I am an authorised user
@@ -122,24 +122,24 @@ Feature: Manage Pools # | m1-small | 1740 | 1 | 250 | i386 | # | m1-medium | 1740 | 2 | 500 | i386 |
-# Scenario: Update a HardwareProfile -# Given I am an authorised user -# And there are the following aggregator hardware profiles: -# | name | memory | cpu |storage | architecture | -# | m1-small | 1740 | 2 | 160 | i386 | -# And I am on the hardware profiles page -# When I follow "m1-small" -# Then I should see "Properties" -# When I follow "edit" -# Then I should be on the edit hardware profiles page -# When I enter the following details for the Hardware Profile Properties -# | name | kind | range_first | range_last | property_enum_entries | value | -# | memory | fixed | | | | 1740 | -# | cpu | range | 1 | 4 | | 1 | -# | storage | range | 250 | 500 | | 300 | -# | architecture | fixed | | | | i386 | -# And I press "Save" -# Then I should be on the hardware profiles page -# Then I should see the following: -# | Name | Memory | CPU | Storage | Architecture | -# | m1-small | 1740 | 1 - 4 | 250 - 500 | i386 |
- Scenario: Update a HardwareProfile
Given I am an authorised user
And there are the following conductor hardware profiles:
| name | memory | cpu |storage | architecture |
| m1-small | 2048 | 4 | 160 | x86_64 |
And I am on the hardware profiles page
When I follow "m1-small"
Then I should see "Properties"
When I follow "edit"
Then I should be on the edit hardware profiles page
When I enter the following details for the Hardware Profile Properties
| name | value | unit |
| memory | 1740 | MB |
| cpu | 2 | count |
| storage | 250 | GB |
| architecture | i386 | label |
And I press "Save"
Then I should be on the hardware profiles page
Then I should see the following:
| Name | Memory | CPU | Storage | Architecture |
| m1-small | 1740 | 2 | 250 | i386 |
aeolus-devel@lists.fedorahosted.org