The interface is stored in a module named Cobbler. Examples for using the interface are stored in ./examples.
With this I'm looking for feedback on the general direction of the code. I plan to change the list and get methods to eventually work like ActiveRecord::Base and treat hashes as fields. Signed-off-by: Darryl L. Pierce <[EMAIL PROTECTED]> --- ruby/rubygem-cobbler/examples/create_system.rb | 51 +++++++ ruby/rubygem-cobbler/examples/has_profile.rb | 41 +++++ ruby/rubygem-cobbler/examples/has_system.rb | 39 +++++ ruby/rubygem-cobbler/examples/list_distros.rb | 48 ++++++ ruby/rubygem-cobbler/examples/list_profiles.rb | 49 ++++++ ruby/rubygem-cobbler/examples/list_systems.rb | 49 ++++++ ruby/rubygem-cobbler/examples/remove_system.rb | 43 ++++++ ruby/rubygem-cobbler/lib/cobbler.rb | 25 +++ ruby/rubygem-cobbler/lib/cobbler/system.rb | 131 ++++++++++++++++ .../nbproject/private/private.properties | 3 + ruby/rubygem-cobbler/nbproject/project.properties | 10 ++ ruby/rubygem-cobbler/nbproject/project.xml | 16 ++ ruby/rubygem-cobbler/test/test_system.rb | 159 ++++++++++++++++++++ 13 files changed, 664 insertions(+), 0 deletions(-) create mode 100755 ruby/rubygem-cobbler/examples/create_system.rb create mode 100755 ruby/rubygem-cobbler/examples/has_profile.rb create mode 100755 ruby/rubygem-cobbler/examples/has_system.rb create mode 100755 ruby/rubygem-cobbler/examples/list_distros.rb create mode 100755 ruby/rubygem-cobbler/examples/list_profiles.rb create mode 100755 ruby/rubygem-cobbler/examples/list_systems.rb create mode 100755 ruby/rubygem-cobbler/examples/remove_system.rb create mode 100644 ruby/rubygem-cobbler/lib/cobbler.rb create mode 100644 ruby/rubygem-cobbler/lib/cobbler/system.rb create mode 100644 ruby/rubygem-cobbler/nbproject/private/private.properties create mode 100644 ruby/rubygem-cobbler/nbproject/project.properties create mode 100644 ruby/rubygem-cobbler/nbproject/project.xml create mode 100755 ruby/rubygem-cobbler/test/test_system.rb diff --git a/ruby/rubygem-cobbler/examples/create_system.rb b/ruby/rubygem-cobbler/examples/create_system.rb new file mode 100755 index 0000000..93e86e9 --- /dev/null +++ b/ruby/rubygem-cobbler/examples/create_system.rb @@ -0,0 +1,51 @@ +#!/usr/bin/ruby -W0 +# +# create_system.rb - example of using rubygem-cobbler to create a system. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? || ARGV.size < 5 + puts "Usage: #{$0} hostname system-name profile-name username password" + exit 1 +end + +hostname = ARGV[0] +system_name = ARGV[1] +profile_name = ARGV[2] +username = ARGV[3] +password = ARGV[4] + +puts "Attempting to create a new system named #{system_name} based on profile #{profile_name}" + +system = Cobbler::System.new(hostname) +system.username = username +system.password = password + +unless system.has_profile?(profile_name) + puts "No such profile: #{profile_name}" + exit 1 +end + +system.create_system(system_name,profile_name,'00:11:22:33:44:55:66:77') diff --git a/ruby/rubygem-cobbler/examples/has_profile.rb b/ruby/rubygem-cobbler/examples/has_profile.rb new file mode 100755 index 0000000..80a3054 --- /dev/null +++ b/ruby/rubygem-cobbler/examples/has_profile.rb @@ -0,0 +1,41 @@ +#!/usr/bin/ruby -W0 +# +# has_profile.rb - example of using rubygem-cobbler to chekc if a profile exists. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? || ARGV.size < 2 + puts "Usage: #{$0} hostname profile-name" + exit 1 +end + +hostname = ARGV[0] +profile_name = ARGV[1] + +puts "Connecting to #{hostname}" + +system = Cobbler::System.new(hostname) + +puts "Does #{profile_name} exist? #{system.has_profile?(profile_name)}" \ No newline at end of file diff --git a/ruby/rubygem-cobbler/examples/has_system.rb b/ruby/rubygem-cobbler/examples/has_system.rb new file mode 100755 index 0000000..ae62255 --- /dev/null +++ b/ruby/rubygem-cobbler/examples/has_system.rb @@ -0,0 +1,39 @@ +#!/usr/bin/ruby -W0 +# +# has_system.rb - example of using rubygem-cobbler to check if a system exists. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? || ARGV.size < 2 + puts "Usage: #{$0} hostname system-name" + exit 1 +end + +hostname = ARGV[0] +system_name = ARGV[1] + +system = Cobbler::System.new(hostname) + +puts "Does #{system_name} exist? #{system.has_system?(system_name)}" \ No newline at end of file diff --git a/ruby/rubygem-cobbler/examples/list_distros.rb b/ruby/rubygem-cobbler/examples/list_distros.rb new file mode 100755 index 0000000..be99ef8 --- /dev/null +++ b/ruby/rubygem-cobbler/examples/list_distros.rb @@ -0,0 +1,48 @@ +#!/usr/bin/ruby -W0 +# list_distros.rb - example of using rubygem-cobbler to list distros. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? + puts "Usage: #{$0} hostname" + exit 1 +end + +hostname = ARGV[0] + +puts "Connecting to #{hostname}" + +system = Cobbler::System.new(hostname) + +system.distros.each do |distro| + puts "[Distro: #{distro['name']}]" + + distro.keys.each do |key| + puts "#{key}: #{distro[key]}" unless key == 'name' + end + + puts "\n" +end + diff --git a/ruby/rubygem-cobbler/examples/list_profiles.rb b/ruby/rubygem-cobbler/examples/list_profiles.rb new file mode 100755 index 0000000..18c2783 --- /dev/null +++ b/ruby/rubygem-cobbler/examples/list_profiles.rb @@ -0,0 +1,49 @@ +#!/usr/bin/ruby -W0 +# +# list_profiles.rb - example of using rubygem-cobbler to list profiles. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? + puts "Usage: #{$0} hostname" + exit 1 +end + +hostname = ARGV[0] + +puts "Connecting to #{hostname}" + +system = Cobbler::System.new(hostname) + +system.profiles.each do |profile| + puts "[Profile: #{profile['name']}]" + + profile.keys.each do |key| + puts "#{key}: #{profile[key]}" unless key == 'name' + end + + puts "\n" +end + diff --git a/ruby/rubygem-cobbler/examples/list_systems.rb b/ruby/rubygem-cobbler/examples/list_systems.rb new file mode 100755 index 0000000..f82913e --- /dev/null +++ b/ruby/rubygem-cobbler/examples/list_systems.rb @@ -0,0 +1,49 @@ +#!/usr/bin/ruby -W0 +# +# list_systems.rb - example of using rubygem-cobbler to list systems. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? + puts "Usage: #{$0} hostname" + exit 1 +end + +hostname = ARGV[0] + +puts "Connecting to #{hostname}" + +system = Cobbler::System.new(hostname) + +system.systems.each do |system| + puts "[System: #{system['name']}]" + + system.keys.each do |key| + puts "#{key}: #{system[key]}" unless key == 'name' + end + + puts "\n" +end + diff --git a/ruby/rubygem-cobbler/examples/remove_system.rb b/ruby/rubygem-cobbler/examples/remove_system.rb new file mode 100755 index 0000000..21e77bf --- /dev/null +++ b/ruby/rubygem-cobbler/examples/remove_system.rb @@ -0,0 +1,43 @@ +#!/usr/bin/ruby -W0 +# +# remove_system.rb - example of using rubygem-cobbler to remove a system. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + +base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +$LOAD_PATH << File.join(base, "lib") +$LOAD_PATH << File.join(base, "examples") + +require 'cobbler' + +if ARGV.empty? || ARGV.size < 4 + puts "Usage: #{$0} hostname system-name username password" + exit 1 +end + +hostname = ARGV[0] +system_name = ARGV[1] +username = ARGV[2] +password = ARGV[3] + +system = Cobbler::System.new(hostname) +system.username = username +system.password = password + +system.remove_system(system_name) \ No newline at end of file diff --git a/ruby/rubygem-cobbler/lib/cobbler.rb b/ruby/rubygem-cobbler/lib/cobbler.rb new file mode 100644 index 0000000..df78813 --- /dev/null +++ b/ruby/rubygem-cobbler/lib/cobbler.rb @@ -0,0 +1,25 @@ +# cobbler.rb - Cobbler module declaration. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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 'cobbler/system' + +module Cobbler + +end diff --git a/ruby/rubygem-cobbler/lib/cobbler/system.rb b/ruby/rubygem-cobbler/lib/cobbler/system.rb new file mode 100644 index 0000000..2792be5 --- /dev/null +++ b/ruby/rubygem-cobbler/lib/cobbler/system.rb @@ -0,0 +1,131 @@ +# system.rb - Allows a remote client to interact with a Cobbler server. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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 'xmlrpc/client' +require 'pp' + +module Cobbler + include XMLRPC + + # +System+ represents a remote Cobbler server. + # + class System + + attr_accessor :hostname + attr_accessor :username, :password + attr_writer :connection + + def initialize(hostname) + @hostname = hostname + + @writing = false + end + + # Returns the list of distros in Cobbler. + # + def distros + @writing = false + connect.call('get_distros') + end + + # Returns the list of profiles in Cobbler. + # + def profiles + @writing = false + connect.call('get_profiles') + end + + # Returns whether a profile exists in Cobbler. + # + def has_profile?(name) + raise Exception.new("No profile name specified") if name == nil or name.empty? + + @writing = false + + profiles.each do |profile| + return true if profile['name'] == name + end + + return false + end + + # Returns the list of systems in Cobbler. + # + def systems + @writing = false + connect.call('get_systems') + end + + # Returns whether the given system exists. + # + def has_system?(name) + @writing = false + + raise Exception.new('Expected a system name') if (name == nil) || name.empty? + systems.each do |system| + return true if system['name'] == name + end + + return false + end + + # Creates a new system record in Cobbler. + # + def create_system(name, profile, mac) + @writing = true + + raise Exception.new("System already exists: #{name}") if has_system? name + + token = login + system_id = connect.call('new_system',token) + + connect.call('modify_system',system_id,'name',name,token) + connect.call('modify_system',system_id,'profile',profile,token) + #connect.call('modify_system',system_id,'mac',mac,token) + connect.call('save_system',system_id,token) + + return system_id + end + + # Removes the system with the given name. + # + def remove_system(name) + raise Exception.new('System name expected') if (name == nil) || name.empty? + raise Exception.new("No such system: #{name}") if !has_system? name + + token = login + + @writing = true + + connect.call('remove_system',name,token) + end + + private + + def login + @writing = true + connect.call('login',@username, @password) + end + + def connect(use_ssl = false) + (@connection || XMLRPC::Client.new2("[EMAIL PROTECTED] ? 'https' : 'http'}://#{hostname}/[EMAIL PROTECTED] ? 'api_rw' : 'api'}")) + end + end +end diff --git a/ruby/rubygem-cobbler/nbproject/private/private.properties b/ruby/rubygem-cobbler/nbproject/private/private.properties new file mode 100644 index 0000000..33ea747 --- /dev/null +++ b/ruby/rubygem-cobbler/nbproject/private/private.properties @@ -0,0 +1,3 @@ +file.reference.rubygem-cobbler-lib=/home/mcpierce/Programming/cobbler/ruby/rubygem-cobbler/lib +file.reference.rubygem-cobbler-test=/home/mcpierce/Programming/cobbler/ruby/rubygem-cobbler/test +platform.active=Ruby diff --git a/ruby/rubygem-cobbler/nbproject/project.properties b/ruby/rubygem-cobbler/nbproject/project.properties new file mode 100644 index 0000000..b30fbd8 --- /dev/null +++ b/ruby/rubygem-cobbler/nbproject/project.properties @@ -0,0 +1,10 @@ +file.reference.rubygem-cobbler-lib=lib +file.reference.rubygem-cobbler-test=test +javac.classpath= +main.file= +platform.active=Ruby +ruby.includejava=false +source.encoding=UTF-8 +src.dir=${file.reference.rubygem-cobbler-lib} +src.examples.dir=examples +test.src.dir=${file.reference.rubygem-cobbler-test} diff --git a/ruby/rubygem-cobbler/nbproject/project.xml b/ruby/rubygem-cobbler/nbproject/project.xml new file mode 100644 index 0000000..3ea391e --- /dev/null +++ b/ruby/rubygem-cobbler/nbproject/project.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.ruby.rubyproject</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/ruby-project/1"> + <name>rubygem-cobbler</name> + <source-roots> + <root id="src.examples.dir"/> + <root id="src.dir"/> + </source-roots> + <test-roots> + <root id="test.src.dir"/> + </test-roots> + </data> + </configuration> +</project> diff --git a/ruby/rubygem-cobbler/test/test_system.rb b/ruby/rubygem-cobbler/test/test_system.rb new file mode 100755 index 0000000..2eec238 --- /dev/null +++ b/ruby/rubygem-cobbler/test/test_system.rb @@ -0,0 +1,159 @@ +# test_system.rb - Unit tests. +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <[EMAIL PROTECTED]> +# +# 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. + + +$:.unshift File.join(File.dirname(__FILE__),'..','lib') + +require 'test/unit' +require 'flexmock/test_unit' +require 'cobbler/system' + +module Cobbler + class TestSystem < Test::Unit::TestCase + def setup + @system = System.new('cobbler.server') + @system.username = 'testuser' + @system.password = 'testpassword' + + # create a mock connection so we can control it during testing + @connection = flexmock('connection') + @system.connection = @connection + + # test results from API calls + @distros = ['distro1', 'distro2'] + + @profiles = Array.new + @profiles[0] = Hash.new + @profiles[0]['name'] = 'profile1' + @profiles[1] = Hash.new + @profiles[1]['name'] = 'profile2' + + @systems = Array.new + @systems[0] = Hash.new + @systems[0]['name'] = 'system1' + @systems[1] = Hash.new + @systems[1]['name'] = 'system2' + + @auth_token = 'authtoken' + @system_id = 717 + end + + # Ensures that the call to get distributions works as expected. + # + def test_distros + @connection.should_receive(:call).with('get_distros').once.returns(@distros) + + result = @system.distros + + assert result, 'Missing result.' + assert_same @distros, result, 'Did not get the correct result.' + end + + # Ensures that the call to get profiles works as expected. + # + def test_profiles + @connection.should_receive(:call).with('get_profiles').once.returns(@profiles) + + result = @system.profiles + + assert result, 'Missing result.' + assert_same @profiles, result, 'Did not get the correct result.' + end + + # Ensures that the call to check if a profile exists works as expected. + # + def test_has_profile + @connection.should_receive(:call).with('get_profiles').once.returns(@profiles) + + assert @system.has_profile?(@profiles[0]['name']),'Got a false negative' + + @connection.should_receive(:call).with('get_profiles').once.returns(@profiles) + + assert @system.has_profile?('farkle') == false, 'Got a false positive' + end + + # Ensures that the call to get systems works as expected. + # + def test_systems + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + + result = @system.systems + + assert result, 'Missing result.' + assert_same @systems, result, 'Did not get the correct result.' + end + + # Ensures that the call to check if a system exists works as expected. + # + def test_has_system + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + + assert @system.has_system?(@systems[0]['name']), 'Got a false negative.' + + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + + assert @system.has_system?('farkle') == false, 'Got a false positive.' + end + + # Ensures that trying to create a system with an existing name raises an exception. + # + def test_create_with_used_name + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + + assert_raise(Exception) [EMAIL PROTECTED](@systems[0]['name'],'profile1','00:11:22:33:44:55:66:77')} + end + + # Ensures that creating a new system record works as expected. + # + def test_create_system + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + @connection.should_receive(:call).with('login','testuser','testpassword').once.returns(@auth_token) + @connection.should_receive(:call).with('new_system',@auth_token).once.returns(@system_id) + @connection.should_receive(:call).with('modify_system',@system_id,'name','testsystem',@auth_token) + @connection.should_receive(:call).with('modify_system',@system_id,'profile','profile1',@auth_token) + @connection.should_receive(:call).with('modify_system',@system_id,'mac','00:01:02:03:04:05:06:07',@auth_token) + @connection.should_receive(:call).with('save_system',@system_id,@auth_token) + + result = @system.create_system('testsystem', 'profile1','00:01:02:03:04:05:06:07') + + assert_equal @system_id, result, 'Did not receive the system id' + end + + # Ensures that deleting a system which doesn't exist raises an exception + # + def test_remove_system_with_invalid_name + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + + assert_raises(Exception) { @system.remove_system('farkle')} + end + + # Ensures that deleting a system works as expected. + # + def test_remove_system + @connection.should_receive(:call).with('get_systems').once.returns(@systems) + + @connection.should_receive(:call).with('login','testuser','testpassword').once.returns(@auth_token) + @connection.should_receive(:call).with('remove_system',@systems[0]['name'],@auth_token).once + + result = @system.remove_system(@systems[0]['name']) + + end + end +end -- 1.5.5.1 _______________________________________________ cobbler mailing list [email protected] https://fedorahosted.org/mailman/listinfo/cobbler
