[Ovirt-devel] [PATCH server] BUG#460147 - Deleting a VM based on a Cobbler system does not delete

Darryl L. Pierce dpierce at redhat.com
Fri Oct 24 15:09:25 UTC 2008


This patch addresses this issue, first calling Cobbler and deleting the
system prior to deleting the VM. It also changes ovirt-server's dependence
to since this is new functionality in the rubygem-cobbler package.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 ovirt-server.spec.in                 |    2 +-
 src/app/controllers/vm_controller.rb |    7 ++++++-
 src/app/models/vm.rb                 |    6 ++++++
 src/test/unit/vm_test.rb             |   12 ++++++++++++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/ovirt-server.spec.in b/ovirt-server.spec.in
index 123e280..e2620d1 100644
--- a/ovirt-server.spec.in
+++ b/ovirt-server.spec.in
@@ -17,7 +17,7 @@ Requires: rubygem(activeldap) >= 0.10.0
 Requires: rubygem(rails) >= 2.1.1
 Requires: rubygem(mongrel) >= 1.0.1
 Requires: rubygem(krb5-auth) >= 0.6
-Requires: rubygem(cobbler) >= 0.0.2
+Requires: rubygem(cobbler) >= 0.1.2
 Requires: rubygem(gettext)
 Requires: ruby-flexmock
 Requires: postgresql-server
diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
index 585e524..c7772b5 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -1,4 +1,4 @@
-# 
+#
 # Copyright (C) 2008 Red Hat, Inc.
 # Written by Scott Seago <sseago at redhat.com>
 #
@@ -144,6 +144,11 @@ class VmController < ApplicationController
         vms = Vm.find(:all, :conditions => "id in (#{vm_ids.join(', ')})")
         vms.each do |vm|
           if vm.is_destroyable?
+            # Destroy the Cobbler system first if it's defined
+            if vm.uses_cobbler?
+              system = Cobbler::System.find_one(vm.cobbler_system_name)
+              system.remove if system
+            end
             vm.destroy
           else
             failure_list << vm.description
diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb
index 2eff87a..8f335c9 100644
--- a/src/app/models/vm.rb
+++ b/src/app/models/vm.rb
@@ -277,6 +277,12 @@ class Vm < ActiveRecord::Base
     end
   end
 
+  # Returns the system name in Cobbler for this VM.
+  #
+  def cobbler_system_name
+    self.uuid
+  end
+
   # whether this VM may be validly deleted. running VMs should not be
   # allowed to be deleted. Currently we restrict deletion to VMs that
   # are currently stopped, pending (new without any create_vm tasks having
diff --git a/src/test/unit/vm_test.rb b/src/test/unit/vm_test.rb
index 22164e8..d583286 100644
--- a/src/test/unit/vm_test.rb
+++ b/src/test/unit/vm_test.rb
@@ -76,4 +76,16 @@ class VmTest < Test::Unit::TestCase
       vm.cobbler_name,
       "Wrong name reported."
   end
+
+  # Ensures that the right value is used when requesting the cobbler system
+  # name for a VM backed by Cobbler.
+  #
+  def test_cobbler_system_name
+    @vm = Vm.new
+    @vm.provisioning_and_boot_settings = @cobbler_profile_provisioning
+    @vm.uuid = "oicu812"
+
+    assert_equal @vm.cobbler_system_name, @vm.uuid,
+      "VMs should be using the UUID as their Cobbler system name."
+  end
 end
-- 
1.5.6.5




More information about the ovirt-devel mailing list