puppet-virt icon indicating copy to clipboard operation
puppet-virt copied to clipboard

fails to create openvz vm

Open leftys opened this issue 10 years ago • 3 comments

I tried to create a VM:

        virt { guest-openvz2:
          id => 102,
          virt_type   => 'openvz',
          ensure      => 'installed',
          os_template => 'debian-7.0-x86_64-minimal',
          memory      => 512,
          autoboot    => true,
          interfaces  => ["br0"]
        } 

and somehow, the agent tries to obtain the value of memory size before creating the vm and the config file. I obtained the following backtrace:

Debug: Executing '/usr/sbin/vzlist -1 -a -N guest-openvz2'
Debug: Executing '/usr/sbin/vzctl status 102'
Debug: Executing '/usr/sbin/vzlist -1 -a -N guest-openvz2'
Debug: Executing '/usr/sbin/vzctl status 102'
Debug: Virt[guest-openvz2](provider=openvz): Getting parameter PRIVVMPAGES value
/var/lib/puppet/lib/puppet/provider/virt/openvz.rb:197: warning: class variable access from toplevel
Debug: Executing '/usr/sbin/vzlist -1 -a -N guest-openvz2'
Error: /Virt[guest-openvz2]: Could not evaluate: No such file or directory - /etc/vz/conf/102.conf
/usr/lib/ruby/1.9.1/open-uri.rb:35:in `initialize'
/usr/lib/ruby/1.9.1/open-uri.rb:35:in `open'
/usr/lib/ruby/1.9.1/open-uri.rb:35:in `open'
/var/lib/puppet/lib/puppet/provider/virt/openvz.rb:198:in `get_value'
/var/lib/puppet/lib/puppet/provider/virt/openvz.rb:233:in `memory'
/usr/lib/ruby/vendor_ruby/puppet/property.rb:471:in `retrieve'
/usr/lib/ruby/vendor_ruby/puppet/type.rb:1058:in `block in retrieve'
/usr/lib/ruby/vendor_ruby/puppet/type.rb:1053:in `each'
/usr/lib/ruby/vendor_ruby/puppet/type.rb:1053:in `retrieve'
/usr/lib/ruby/vendor_ruby/puppet/type.rb:1076:in `retrieve_resource'
/usr/lib/ruby/vendor_ruby/puppet/transaction/resource_harness.rb:236:in `from_resource'
/usr/lib/ruby/vendor_ruby/puppet/transaction/resource_harness.rb:19:in `evaluate'
/usr/lib/ruby/vendor_ruby/puppet/transaction.rb:204:in `apply'
/usr/lib/ruby/vendor_ruby/puppet/transaction.rb:217:in `eval_resource'
/usr/lib/ruby/vendor_ruby/puppet/transaction.rb:147:in `call'
/usr/lib/ruby/vendor_ruby/puppet/transaction.rb:147:in `block (2 levels) in evaluate'
/usr/lib/ruby/vendor_ruby/puppet/util.rb:327:in `block in thinmark'
/usr/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/usr/lib/ruby/vendor_ruby/puppet/util.rb:326:in `thinmark'
/usr/lib/ruby/vendor_ruby/puppet/transaction.rb:147:in `block in evaluate'
/usr/lib/ruby/vendor_ruby/puppet/graph/relationship_graph.rb:118:in `traverse'
/usr/lib/ruby/vendor_ruby/puppet/transaction.rb:138:in `evaluate'
/usr/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:169:in `block in apply'
/usr/lib/ruby/vendor_ruby/puppet/util/log.rb:149:in `with_destination'
/usr/lib/ruby/vendor_ruby/puppet/transaction/report.rb:112:in `as_logging_destination'
/usr/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:168:in `apply'
/usr/lib/ruby/vendor_ruby/puppet/configurer.rb:118:in `block in apply_catalog'
/usr/lib/ruby/vendor_ruby/puppet/util.rb:161:in `block in benchmark'
/usr/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/usr/lib/ruby/vendor_ruby/puppet/util.rb:160:in `benchmark'
/usr/lib/ruby/vendor_ruby/puppet/configurer.rb:117:in `apply_catalog'
/usr/lib/ruby/vendor_ruby/puppet/configurer.rb:224:in `run_internal'
/usr/lib/ruby/vendor_ruby/puppet/configurer.rb:132:in `block in run'
/usr/lib/ruby/vendor_ruby/puppet/context.rb:64:in `override'
/usr/lib/ruby/vendor_ruby/puppet.rb:244:in `override'
/usr/lib/ruby/vendor_ruby/puppet/configurer.rb:131:in `run'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:47:in `block (4 levels) in run'
/usr/lib/ruby/vendor_ruby/puppet/agent/locker.rb:20:in `lock'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:47:in `block (3 levels) in run'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:117:in `with_client'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:44:in `block (2 levels) in run'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:82:in `run_in_fork'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:43:in `block in run'
/usr/lib/ruby/vendor_ruby/puppet/application.rb:179:in `call'
/usr/lib/ruby/vendor_ruby/puppet/application.rb:179:in `controlled_run'
/usr/lib/ruby/vendor_ruby/puppet/agent.rb:41:in `run'
/usr/lib/ruby/vendor_ruby/puppet/application/agent.rb:356:in `onetime'
/usr/lib/ruby/vendor_ruby/puppet/application/agent.rb:322:in `run_command'
/usr/lib/ruby/vendor_ruby/puppet/application.rb:381:in `block (2 levels) in run'
/usr/lib/ruby/vendor_ruby/puppet/application.rb:507:in `plugin_hook'
/usr/lib/ruby/vendor_ruby/puppet/application.rb:381:in `block in run'
/usr/lib/ruby/vendor_ruby/puppet/util.rb:488:in `exit_on_fail'
/usr/lib/ruby/vendor_ruby/puppet/application.rb:381:in `run'
/usr/lib/ruby/vendor_ruby/puppet/util/command_line.rb:146:in `run'
/usr/lib/ruby/vendor_ruby/puppet/util/command_line.rb:92:in `execute'
/usr/bin/puppet:8:in `<main>'

leftys avatar Jan 10 '15 21:01 leftys

Can you check if you're able to reproduce the error by removing the id => 102 parameter?

carlasouza avatar Jan 11 '15 03:01 carlasouza

Yes,

I have solved it by:

index 66c4b09..2771c1b 100644
--- a/modules/virt/lib/puppet/provider/virt/openvz.rb
+++ b/modules/virt/lib/puppet/provider/virt/openvz.rb
@@ -140,10 +141,16 @@ Puppet::Type.type(:virt).provide(:openvz) do
   end

   def exists?
+    conf = @@vzconf + ctid.to_s + '.conf'
+    if !File.exists?(conf)
+        return false
+    end
     stat = vzctl('status', ctid).split(" ")
     if stat.nil? || stat[2] == "deleted"
       return false
     else
       return true
     end
   end
@@ -194,7 +201,10 @@ Puppet::Type.type(:virt).provide(:openvz) do
   private
   def get_value(arg)
     debug "Getting parameter #{arg} value"
-    conf = @@vzconf + ctid + '.conf'
+    conf = @@vzconf + ctid.to_s + '.conf'
+    if !File.exists?(conf)
+        return :absent
+    end
     value = open(conf).grep(/^#{arg.upcase}/)
     result = value.size == 0 ? '' : value[0].split('"')[1].downcase
     result

Maybe puppet behavior changed in v3 and it queries the values before creating the resource virt? I encountered a lot more problems, so I will do a pull request after I resolve them. (Now ip addreses are not assigned.)

leftys avatar Jan 11 '15 09:01 leftys

Ehm. I had used the much older forge version. Now everything works. It would be nice to upgrade or delete it there, it didn't work for me at all...

leftys avatar Jan 11 '15 09:01 leftys