Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
contrib/ruby/ChangeLog | 16 ++++++++++++++--
contrib/ruby/README | 15 +++++++++------
contrib/ruby/Rakefile | 2 +-
contrib/ruby/TODO | 3 ++-
contrib/ruby/lib/cobbler/system.rb | 7 +++++--
contrib/ruby/rubygem-cobbler.spec | 8 ++++++--
contrib/ruby/test/test_system.rb | 13 +++++++++++++
7 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/contrib/ruby/ChangeLog b/contrib/ruby/ChangeLog
index 81b0104..8b41d45 100644
--- a/contrib/ruby/ChangeLog
+++ b/contrib/ruby/ChangeLog
@@ -1,6 +1,18 @@
-* Wed Aug 13 2008 Darryl Pierce <dpierce(a)redhat.com>
+* Thu Aug 21 2008 Darryl Pierce <dpierce(a)redhat.com> - 0.0.2-1
+- Added a call to update prior to saving or updating a system. If the update
+ fails, then an Exception is raised.
+
+* Wed Aug 13 2008 Darryl Pierce <dpierce(a)redhat.com> - 0.0.1-3
- Added caching for the auth_token to prevent extraneous calls to login.
- Reworked and refined how cobbler_collection fields are processed, adding
support for both array and has properties.
- Rewrote the documentation for Cobbler::Base to make it easier to understand
- how to extend it to support other Cobbler types.
\ No newline at end of file
+ how to extend it to support other Cobbler types.
+- Refactored the examples to clean up the code.
+
+* Wed Aug 13 2008 Darryl Pierce <dpierce(a)redhat.com> - 0.0.1-2
+- Removed markup of cobbler.yml and a config file. Fixed a few small bugs
+ in the code for using it as a gem.
+
+* Mon Aug 04 2008 Darryl Pierce <dpierce(a)redhat.com> - 0.0.1-1
+- Initial package
diff --git a/contrib/ruby/README b/contrib/ruby/README
index 0fda7e2..a91b20c 100644
--- a/contrib/ruby/README
+++ b/contrib/ruby/README
@@ -7,8 +7,8 @@ Ruby bindings for interacting with Cobbler.
USAGE
-----
-To include the code, you must install the ruby gem named "cobbler" and then
-require 'cobbler' in your application.
+To use the code, you must install the ruby gem named "cobbler" and then
+require 'cobbler' in your application.
Minimally you need to provide a server name for your Cobbler machine using:
@@ -23,7 +23,10 @@ Cobbler::Base.password = password
CONFIGURATION
-------------
-By default, Cobbler::Base will load the file config/cobbler.yml, if it exists,
-and use that information for talking to Cobbler. To override where this file
-lives, set the COBBLER_ENV environment variable *before* requiring the 'cobbler'
-file.
\ No newline at end of file
+By default, Cobbler::Base will load the file $SEARCHPATH/config/cobbler.yml,
+if it exists, and use that information for talking to Cobbler. To override
+where this file lives, set the COBBLER_ENV environment variable *before*
+requiring the 'cobbler' file.
+
+However, these values can be overridden afterward by changing the fields in
+Cobbler::Base directly.
\ No newline at end of file
diff --git a/contrib/ruby/Rakefile b/contrib/ruby/Rakefile
index f4d88fe..5970cc3 100644
--- a/contrib/ruby/Rakefile
+++ b/contrib/ruby/Rakefile
@@ -22,7 +22,7 @@ require 'rake/testtask'
require 'rake/gempackagetask'
PKG_NAME='rubygem-cobbler'
-PKG_VERSION='0.0.1'
+PKG_VERSION='0.0.2'
PKG_FILES=FileList[
'Rakefile', 'README', 'ChangeLog', 'COPYING',
'NEWS', 'TODO',
'lib/**/*.rb',
diff --git a/contrib/ruby/TODO b/contrib/ruby/TODO
index e5eddbe..2c74dd7 100644
--- a/contrib/ruby/TODO
+++ b/contrib/ruby/TODO
@@ -1,8 +1,9 @@
This is a list of features to be developed in future.
-* Attempt to detech when a R/W call fails due to expired auth token and
+* Attempt to detect when a R/W call fails due to expired auth token and
retry the previous login.
* Rework the "find_one" method to be "find_by_[field]" instead.
* Add hierarchical relationships, so that a Profile will load it's
Distro, a System will load it's Profile, etc.
+* Perform an update check before saving or updating a system. [DONE: 21 Aug 2008]
* Cache auth tokens to avoid unnecessary logins. [DONE: 13 Aug 2008]
diff --git a/contrib/ruby/lib/cobbler/system.rb b/contrib/ruby/lib/cobbler/system.rb
index 255391c..849ab5d 100644
--- a/contrib/ruby/lib/cobbler/system.rb
+++ b/contrib/ruby/lib/cobbler/system.rb
@@ -55,7 +55,10 @@ module Cobbler
def save
Base.begin_transaction(true)
- token = Base.login
+ token = Base.login
+
+ raise Exception.new('Update failed prior to saving') unless
Base.make_call('update')
+
sysid = Base.make_call('new_system',token)
Base.make_call('modify_system',sysid,'name',self.name,token)
@@ -76,7 +79,7 @@ module Cobbler
end
Base.make_call('save_system',sysid,token)
-
+
Base.end_transaction
end
diff --git a/contrib/ruby/rubygem-cobbler.spec b/contrib/ruby/rubygem-cobbler.spec
index 3843327..51dcd80 100644
--- a/contrib/ruby/rubygem-cobbler.spec
+++ b/contrib/ruby/rubygem-cobbler.spec
@@ -7,8 +7,8 @@
Summary: An interface for interacting with a Cobbler server
Name: rubygem-%{gemname}
-Version: 0.0.1
-Release: 3%{?dist}
+Version: 0.0.2
+Release: 1%{?dist}
Group: Development/Languages
License: LGPLv2+
URL:
http://cobbler.et.redhat.com/
@@ -63,6 +63,10 @@ rm -rf %{buildroot}
%changelog
+* Thu Aug 21 2008 Darryl Pierce <dpierce(a)redhat.com> - 0.0.2-1
+- Added a call to update prior to saving or updating a system. If the update
+ fails, then an Exception is raised.
+
* Wed Aug 13 2008 Darryl Pierce <dpierce(a)redhat.com> - 0.0.1-3
- Added caching for the auth_token to prevent extraneous calls to login.
- Reworked and refined how cobbler_collection fields are processed, adding
diff --git a/contrib/ruby/test/test_system.rb b/contrib/ruby/test/test_system.rb
index e28da8b..53c979b 100644
--- a/contrib/ruby/test/test_system.rb
+++ b/contrib/ruby/test/test_system.rb
@@ -111,10 +111,22 @@ module Cobbler
assert_equal 3, result[0].owners.size, 'Did not parse the owners
correctly.'
end
+ # Ensures that saving stops when an update fails.
+ #
+ def test_save_and_update_fails
+
@connection.should_receive(:call).with('login',@username,@password).once.returns(@auth_token)
+ @connection.should_receive(:call).with('update').once.returns{ false }
+
+ system = System.new(:name => @system_name, :profile => @profile_name)
+
+ assert_raise(Exception) {system.save}
+ end
+
# Ensures that saving a system works as expected.
#
def test_save
@connection.should_receive(:call).with('login',@username,@password).once.returns(@auth_token)
+ @connection.should_receive(:call).with('update').once.returns { true }
@connection.should_receive(:call).with('new_system',@auth_token).once.returns(@system_id)
@connection.should_receive(:call).with('modify_system',@system_id,'name',@system_name,@auth_token).once.returns(true)
@connection.should_receive(:call).with('modify_system',@system_id,'profile',@profile_name,@auth_token).once.returns(true)
@@ -130,6 +142,7 @@ module Cobbler
#
def test_save_with_new_nics
@connection.should_receive(:call).with('login',@username,@password).once.returns(@auth_token)
+ @connection.should_receive(:call).with('update').once.returns { true }
@connection.should_receive(:call).with('new_system',@auth_token).once.returns(@system_id)
@connection.should_receive(:call).with('modify_system',@system_id,'name',@system_name,@auth_token).once.returns(true)
@connection.should_receive(:call).with('modify_system',@system_id,'profile',@profile_name,@auth_token).once.returns(true)
--
1.5.5.1