[DRE-commits] [vagrant-libvirt] 158/163: cleaning, tests preparation

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Apr 24 13:57:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag 0.0.26
in repository vagrant-libvirt.

commit 0e2c26a33fc54ebb73a718772496fcf058ee9f54
Author: dima <pronix.service at gmail.com>
Date:   Wed Apr 15 09:45:29 2015 +0200

    cleaning,tests preparation
---
 Gemfile                                            |  1 +
 lib/vagrant-libvirt/action/create_domain.rb        | 36 ++++++++++------------
 spec/support/environment_helper.rb                 | 14 +++++++++
 .../action/set_name_of_domain_spec.rb              |  4 +--
 4 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/Gemfile b/Gemfile
index 1c69fb4..e4d5772 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,6 +8,7 @@ group :development do
   # gem dependency because we expect to be installed within the
   # Vagrant environment itself using `vagrant plugin`.
   gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
+  gem 'pry'
 end
 
 group :plugins do
diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb
index acf5e18..620d66e 100644
--- a/lib/vagrant-libvirt/action/create_domain.rb
+++ b/lib/vagrant-libvirt/action/create_domain.rb
@@ -3,7 +3,6 @@ require 'log4r'
 module VagrantPlugins
   module ProviderLibvirt
     module Action
-
       class CreateDomain
         include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
 
@@ -13,15 +12,17 @@ module VagrantPlugins
         end
 
         def _disk_name(name, disk)
-          return "#{name}-#{disk[:device]}.#{disk[:type]}"	# disk name
+          "#{name}-#{disk[:device]}.#{disk[:type]}"	# disk name
         end
 
         def _disks_print(disks)
-          return disks.collect{ |x| x[:device]+'('+x[:type]+','+x[:size]+')' }.join(', ')
+          disks.collect do |x|
+            x[:device] + '(' + x[:type] + ',' + x[:size] + ')'
+          end.join(', ')
         end
 
         def _cdroms_print(cdroms)
-          return cdroms.collect{ |x| x[:dev] }.join(', ')
+          cdroms.collect { |x| x[:dev] }.join(', ')
         end
 
         def call(env)
@@ -35,7 +36,7 @@ module VagrantPlugins
           @machine_type = config.machine_type
           @disk_bus = config.disk_bus
           @nested = config.nested
-          @memory_size = config.memory.to_i*1024
+          @memory_size = config.memory.to_i * 1024
           @domain_volume_cache = config.volume_cache
           @kernel = config.kernel
           @cmd_line = config.cmd_line
@@ -70,10 +71,9 @@ module VagrantPlugins
           @domain_volume_path = domain_volume.path
 
           # the default storage prefix is typically: /var/lib/libvirt/images/
-          storage_prefix = File.dirname(@domain_volume_path)+'/'	# steal
+          storage_prefix = File.dirname(@domain_volume_path) + '/'	# steal
 
           @disks.each do |disk|
-
             disk[:path] ||= _disk_name(@name, disk)
 
             # On volume creation, the <path> element inside <target>
@@ -88,15 +88,15 @@ module VagrantPlugins
             # qemu-img create -f qcow2 <path> 5g
             begin
               domain_volume_disk = env[:libvirt_compute].volumes.create(
-                :name => disk[:name],
-                :format_type => disk[:type],
-                :path => disk[:absolute_path],
-                :capacity => disk[:size],
+                name: disk[:name],
+                format_type: disk[:type],
+                path: disk[:absolute_path],
+                capacity: disk[:size],
                 #:allocation => ?,
-                :pool_name => @storage_pool_name)
+                pool_name: @storage_pool_name)
             rescue Fog::Errors::Error => e
               raise Errors::FogDomainVolumeCreateError,
-                :error_message => e.message
+                  error_message:  e.message
             end
           end
 
@@ -105,7 +105,7 @@ module VagrantPlugins
           env[:ui].info(" -- Name:              #{@name}")
           env[:ui].info(" -- Domain type:       #{@domain_type}")
           env[:ui].info(" -- Cpus:              #{@cpus}")
-          env[:ui].info(" -- Memory:            #{@memory_size/1024}M")
+          env[:ui].info(" -- Memory:            #{@memory_size / 1024}M")
           env[:ui].info(" -- Base box:          #{env[:machine].box.name}")
           env[:ui].info(" -- Storage pool:      #{@storage_pool_name}")
           env[:ui].info(" -- Image:             #{@domain_volume_path}")
@@ -115,7 +115,7 @@ module VagrantPlugins
           env[:ui].info(" -- Graphics Type:     #{@graphics_type}")
           env[:ui].info(" -- Graphics Port:     #{@graphics_port}")
           env[:ui].info(" -- Graphics IP:       #{@graphics_ip}")
-          env[:ui].info(" -- Graphics Password: #{@graphics_passwd.empty? ? 'Not defined': 'Defined'}")
+          env[:ui].info(" -- Graphics Password: #{@graphics_passwd.empty? ? 'Not defined' : 'Defined'}")
           env[:ui].info(" -- Video Type:        #{@video_type}")
           env[:ui].info(" -- Video VRAM:        #{@video_vram}")
           env[:ui].info(" -- Keymap:            #{@keymap}")
@@ -140,10 +140,9 @@ module VagrantPlugins
           # existing volume? Use domain creation from template..
           begin
             server = env[:libvirt_compute].servers.create(
-              :xml => to_xml('domain'))
+              xml: to_xml('domain'))
           rescue Fog::Errors::Error => e
-            raise Errors::FogCreateServerError,
-              :error_message => e.message
+            raise Errors::FogCreateServerError, error_message:  e.message
           end
 
           # Immediately save the ID since it is created at this point.
@@ -152,7 +151,6 @@ module VagrantPlugins
           @app.call(env)
         end
       end
-
     end
   end
 end
diff --git a/spec/support/environment_helper.rb b/spec/support/environment_helper.rb
index f49db85..c6e73d1 100644
--- a/spec/support/environment_helper.rb
+++ b/spec/support/environment_helper.rb
@@ -11,6 +11,20 @@ class EnvironmentHelper
     self.send(value.to_sym)
   end
 
+  def cpus
+    4
+  end
+
+  def memory
+    1024
+  end
+
+  %w(cpus cpu_mode machine_type disk_bus nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name|
+    define_method(name.to_sym) do
+      nil
+    end
+  end
+
   def machine
     self
   end
diff --git a/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb b/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb
index 69d3319..838910a 100644
--- a/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb
+++ b/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb
@@ -10,12 +10,12 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
     dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
     first  = dmn.build_domain_name(@env)
     second = dmn.build_domain_name(@env)
-    first.should_not eq(second) 
+    first.should_not eq(second)
   end
 
   it "builds simple domain name" do
     @env.default_prefix= 'pre'
     dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
-    dmn.build_domain_name(@env).should eq('pre_') 
+    dmn.build_domain_name(@env).should eq('pre_')
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git



More information about the Pkg-ruby-extras-commits mailing list