From: Tomas Sedovic <tsedovic(a)redhat.com>
The latest update of the Deltacloud client in Fedora made a change that broke
our current code:
When getting a Hardware Profile Property that a given Hardware Profile object
didn't have, the old client returned `nil` while the new one raises
`NoMethodError`.
Example of where this happens is the Mock driver. It has a Hardware Profile
called "Opaque" which doesn't have any properties defined.
This change of behaviour caused our test to fail and made it impossible to add
the Mock provider via the UI.
This fixes the Conductor code so that it's compatible with both versions of
the Deltacloud client. Later we may want to deprecate the older clients and
simplify the code somewhat.
---
src/app/models/hardware_profile.rb | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 06461c4..c9a4a14 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -96,10 +96,19 @@ class HardwareProfile < ActiveRecord::Base
end
def add_properties(api_profile)
- self.memory = new_property(api_profile.memory || default_profile(:memory))
- self.storage = new_property(api_profile.storage || default_profile(:storage))
- self.cpu = new_property(api_profile.cpu || default_profile(:cpu))
- self.architecture = new_property(api_profile.architecture ||
default_profile(:architecture))
+ self.memory = property_from_api_or_default(api_profile, :memory)
+ self.storage = property_from_api_or_default(api_profile, :storage)
+ self.cpu = property_from_api_or_default(api_profile, :cpu)
+ self.architecture = property_from_api_or_default(api_profile, :architecture)
+ end
+
+ def property_from_api_or_default(api_profile, attribute)
+ prop = nil
+ begin
+ prop = api_profile.send(attribute)
+ rescue NoMethodError
+ end
+ new_property(prop || default_profile(attribute))
end
# If there is no property (nil on the API), create a default
--
1.7.4.4