libvirt-ruby 0.0.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +5 -0
- data/README.rdoc +5 -12
- data/Rakefile +10 -1
- data/lib/libvirt-ruby.rb +28 -6
- data/lib/libvirt-ruby/exceptions.rb +2 -0
- data/lib/libvirt-ruby/exceptions/no_return_parameter.rb +11 -0
- data/lib/libvirt-ruby/exceptions/wrong_call.rb +11 -0
- data/lib/libvirt-ruby/version.rb +1 -1
- data/spec/libvirt-ruby_spec.rb +60 -0
- metadata +14 -21
- data/lib/libvirt-ruby/connect.rb +0 -9
- data/lib/libvirt-ruby/domain.rb +0 -9
- data/lib/libvirt-ruby/network.rb +0 -9
- data/lib/libvirt-ruby/storage_pool.rb +0 -9
- data/lib/libvirt-ruby/storage_vol.rb +0 -9
- data/lib/libvirt-ruby/util.rb +0 -34
- data/spec/libvirt-ruby/connect_spec.rb +0 -122
- data/spec/libvirt-ruby/domain_spec.rb +0 -122
- data/spec/libvirt-ruby/network_spec.rb +0 -122
- data/spec/libvirt-ruby/storage_pool_spec.rb +0 -122
- data/spec/libvirt-ruby/storage_vol_spec.rb +0 -122
data/README.rdoc
CHANGED
@@ -8,21 +8,15 @@ gem install libvirt-ruby
|
|
8
8
|
|
9
9
|
== Dependencies
|
10
10
|
|
11
|
-
This gem has as a
|
11
|
+
This gem has as a dependency the libvirt package. Google it and u will find how to install it on your distro.
|
12
12
|
|
13
13
|
== Usage
|
14
14
|
|
15
|
-
You should
|
16
|
-
Libvirt::Ruby
|
15
|
+
You should call the c function directly on the module with the sanem name:
|
16
|
+
Libvirt::Ruby.virConnectClose([:int])
|
17
17
|
|
18
18
|
The parameter of the function should be an array where the last instance is the return of the C function.
|
19
19
|
|
20
|
-
|
21
|
-
The old method dispatcher still can be called, but is now deprecated. Call dispatcher passing as parameters:
|
22
|
-
first -> the method just like the one from Libvirt in C as a string except the vir and the name of the Class just like 'Close' from 'virConnectClose'
|
23
|
-
second -> the args of the function in C in the same order
|
24
|
-
third -> a symbol of the retun of the function.
|
25
|
-
|
26
20
|
== Experimental
|
27
21
|
|
28
22
|
This Gem still experimental, so if you have some problem, feel free to create a new issue.
|
@@ -36,11 +30,10 @@ Give it a try in another distro and let me know if it works.
|
|
36
30
|
|
37
31
|
Add Support for a ton of thigs. =D
|
38
32
|
Improve a lot of things:
|
39
|
-
* Remove all classes and make gem wotk without them. Using Just one class: Libvirt::Ruby
|
40
|
-
* Create more Exceptions for another type of errors.
|
41
33
|
* Create pages on Wiki teaching how to install libvirt on several distros.
|
42
34
|
...
|
43
35
|
|
44
36
|
== Contribute
|
45
37
|
|
46
|
-
Fork the project and send me a Pull Request.
|
38
|
+
Fork the project and send me a Pull Request. Your code must be well tested against at least the versions im testing: 1.8.7, 1.9.2 and 1.9.3
|
39
|
+
I already have created rake tasks to test on each ruby version. For more info just look inside Rakefile.
|
data/Rakefile
CHANGED
@@ -4,4 +4,13 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new
|
5
5
|
|
6
6
|
desc "Default Task"
|
7
|
-
task :default => [ :spec ]
|
7
|
+
task :default => [ :spec ]
|
8
|
+
|
9
|
+
rubies = %w(1.8.7@libvirt-ruby 1.9.2@libvirt-ruby 1.9.3@libvirt-ruby)
|
10
|
+
rubies.each do |ruby|
|
11
|
+
desc "Run the test suite against: #{ruby.split('@')[0]}"
|
12
|
+
task "spec-#{ruby.split('@')[0]}" do
|
13
|
+
puts "Running test suite against: #{ruby.split('@')[0]}"
|
14
|
+
exec("rvm #{ruby} do rspec spec")
|
15
|
+
end
|
16
|
+
end
|
data/lib/libvirt-ruby.rb
CHANGED
@@ -3,12 +3,34 @@ require "ffi"
|
|
3
3
|
|
4
4
|
module Libvirt
|
5
5
|
module Ruby
|
6
|
-
autoload :Connect, 'libvirt-ruby/connect'
|
7
|
-
autoload :Domain, 'libvirt-ruby/domain'
|
8
6
|
autoload :Exceptions, 'libvirt-ruby/exceptions'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
|
8
|
+
extend FFI::Library
|
9
|
+
|
10
|
+
def self.method_missing(method, *args)
|
11
|
+
args.flatten!
|
12
|
+
return_type = args.delete(args.last)
|
13
|
+
raise Libvirt::Ruby::Exceptions::NoReturnParameter unless return_type
|
14
|
+
dispatcher(method, args, return_type)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.dispatcher(method, args = [], return_type = nil)
|
20
|
+
raise Libvirt::Ruby::Exceptions::WrongCall unless not_direct_call?
|
21
|
+
begin
|
22
|
+
ffi_lib "libvirt"
|
23
|
+
attach_function method.to_s, method.to_s, args, return_type
|
24
|
+
send method.to_s, args
|
25
|
+
rescue FFI::NotFoundError
|
26
|
+
raise Libvirt::Ruby::Exceptions::InvalidFunction.new(method.to_s)
|
27
|
+
rescue LoadError
|
28
|
+
raise Libvirt::Ruby::Exceptions::MissingLib
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.not_direct_call?
|
33
|
+
caller[1][/`.*'/] and caller[1][/`.*'/][1..-2] == 'method_missing'
|
34
|
+
end
|
13
35
|
end
|
14
36
|
end
|
@@ -3,6 +3,8 @@ module Libvirt
|
|
3
3
|
module Exceptions
|
4
4
|
autoload :MissingLib, 'libvirt-ruby/exceptions/missing_lib'
|
5
5
|
autoload :InvalidFunction, 'libvirt-ruby/exceptions/invalid_function'
|
6
|
+
autoload :NoReturnParameter, 'libvirt-ruby/exceptions/no_return_parameter'
|
7
|
+
autoload :WrongCall, 'libvirt-ruby/exceptions/wrong_call'
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
data/lib/libvirt-ruby/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Libvirt::Ruby do
|
4
|
+
let(:libvirt) { Libvirt::Ruby }
|
5
|
+
|
6
|
+
context "when calling any libvirt function directly" do
|
7
|
+
context "without a return type specified" do
|
8
|
+
it "should raise an error" do
|
9
|
+
lambda { libvirt.virConnectClose }.should raise_error(Libvirt::Ruby::Exceptions::NoReturnParameter)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with libvirt installed" do
|
14
|
+
before :each do
|
15
|
+
libvirt.stub(:ffi_lib).with("libvirt")
|
16
|
+
end
|
17
|
+
|
18
|
+
context "and the function is a valid one" do
|
19
|
+
before :each do
|
20
|
+
libvirt.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
21
|
+
libvirt.stub(:send).with("virConnectClose", [])
|
22
|
+
end
|
23
|
+
|
24
|
+
after :each do
|
25
|
+
libvirt.virConnectClose([:int])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should attach it as a binding for C's function" do
|
29
|
+
libvirt.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should call the new attached method" do
|
33
|
+
libvirt.should_receive(:send).with("virConnectClose", [])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "and the function is not a valid one" do
|
38
|
+
before :each do
|
39
|
+
libvirt.stub(:attach_function).with("virConnectAbc", "virConnectAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise an exception" do
|
43
|
+
lambda { libvirt.virConnectAbc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "without libvirt installed" do
|
49
|
+
it "should raise an exception" do
|
50
|
+
lambda { libvirt.virConnectAbc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when calling method #dispatcher directly" do
|
56
|
+
it "should raise an exception" do
|
57
|
+
lambda { libvirt.dispatcher('virConnectClose', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::WrongCall)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libvirt-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &7272040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *7272040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &7271500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *7271500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &7270500 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *7270500
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fakefs
|
49
|
-
requirement: &
|
49
|
+
requirement: &7269940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *7269940
|
58
58
|
description: Access Libvirt's C Library through ruby classes and methods
|
59
59
|
email: plribeiro3000@gmail.com
|
60
60
|
executables: []
|
@@ -64,27 +64,20 @@ files:
|
|
64
64
|
- .gitignore
|
65
65
|
- .rspec
|
66
66
|
- .rvmrc
|
67
|
+
- .travis.yml
|
67
68
|
- Gemfile
|
68
69
|
- LICENSE
|
69
70
|
- README.rdoc
|
70
71
|
- Rakefile
|
71
72
|
- lib/libvirt-ruby.rb
|
72
|
-
- lib/libvirt-ruby/connect.rb
|
73
|
-
- lib/libvirt-ruby/domain.rb
|
74
73
|
- lib/libvirt-ruby/exceptions.rb
|
75
74
|
- lib/libvirt-ruby/exceptions/invalid_function.rb
|
76
75
|
- lib/libvirt-ruby/exceptions/missing_lib.rb
|
77
|
-
- lib/libvirt-ruby/
|
78
|
-
- lib/libvirt-ruby/
|
79
|
-
- lib/libvirt-ruby/storage_vol.rb
|
80
|
-
- lib/libvirt-ruby/util.rb
|
76
|
+
- lib/libvirt-ruby/exceptions/no_return_parameter.rb
|
77
|
+
- lib/libvirt-ruby/exceptions/wrong_call.rb
|
81
78
|
- lib/libvirt-ruby/version.rb
|
82
79
|
- libvirt-ruby.gemspec
|
83
|
-
- spec/libvirt-
|
84
|
-
- spec/libvirt-ruby/domain_spec.rb
|
85
|
-
- spec/libvirt-ruby/network_spec.rb
|
86
|
-
- spec/libvirt-ruby/storage_pool_spec.rb
|
87
|
-
- spec/libvirt-ruby/storage_vol_spec.rb
|
80
|
+
- spec/libvirt-ruby_spec.rb
|
88
81
|
- spec/spec_helper.rb
|
89
82
|
homepage: ''
|
90
83
|
licenses: []
|
data/lib/libvirt-ruby/connect.rb
DELETED
data/lib/libvirt-ruby/domain.rb
DELETED
data/lib/libvirt-ruby/network.rb
DELETED
data/lib/libvirt-ruby/util.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Libvirt
|
2
|
-
module Ruby
|
3
|
-
class Util
|
4
|
-
extend FFI::Library
|
5
|
-
|
6
|
-
def self.method_missing(method, *args)
|
7
|
-
args.flatten!
|
8
|
-
return_type = args.delete(args.last)
|
9
|
-
dispatcher(method, args, return_type)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.dispatcher(method, args = [], return_type = nil)
|
13
|
-
unless not_direct_call?
|
14
|
-
warn "[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead."
|
15
|
-
end
|
16
|
-
begin
|
17
|
-
ffi_lib "libvirt"
|
18
|
-
attach_function (self.klass + method.to_s), (self.klass + method.to_s), args, return_type
|
19
|
-
send (self.klass + method.to_s), args
|
20
|
-
rescue FFI::NotFoundError
|
21
|
-
raise Libvirt::Ruby::Exceptions::InvalidFunction.new(self.klass + method.to_s)
|
22
|
-
rescue LoadError
|
23
|
-
raise Libvirt::Ruby::Exceptions::MissingLib
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def self.not_direct_call?
|
30
|
-
caller[1][/`.*'/] and caller[1][/`.*'/][1..-2] == 'method_missing'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Libvirt::Ruby::Connect do
|
4
|
-
let(:connect) { Libvirt::Ruby::Connect }
|
5
|
-
|
6
|
-
context "when calling method #dispatcher" do
|
7
|
-
context "that is now deprecated" do
|
8
|
-
before :each do
|
9
|
-
connect.stub(:ffi_lib).with("libvirt")
|
10
|
-
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
11
|
-
connect.stub(:send).with("virConnectClose", [])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should raise a deprecated method warning" do
|
15
|
-
connect.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
-
connect.dispatcher('Close', [], :int)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with libvirt installed" do
|
21
|
-
before :each do
|
22
|
-
connect.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
23
|
-
connect.stub(:ffi_lib).with("libvirt")
|
24
|
-
end
|
25
|
-
|
26
|
-
context "and a valid libvirt function" do
|
27
|
-
before :each do
|
28
|
-
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
29
|
-
connect.stub(:send).with("virConnectClose", [])
|
30
|
-
end
|
31
|
-
|
32
|
-
after :each do
|
33
|
-
connect.dispatcher('Close', [], :int)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should attach it as a binding for C's function" do
|
37
|
-
connect.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should call the new attached method" do
|
41
|
-
connect.should_receive(:send).with("virConnectClose", [])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and an invalid libvirt function" do
|
46
|
-
before :each do
|
47
|
-
connect.stub(:attach_function).with("virConnectAbc", "virConnectAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise an exception" do
|
51
|
-
lambda { connect.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "without libvirt installed" do
|
57
|
-
before :each do
|
58
|
-
connect.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise an exception" do
|
62
|
-
lambda { connect.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when calling any libvirt function directly" do
|
68
|
-
context "that is the new way" do
|
69
|
-
before :each do
|
70
|
-
connect.stub(:ffi_lib).with("libvirt")
|
71
|
-
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int)
|
72
|
-
connect.stub(:send).with("virConnectClose", [])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not raise a deprecated method warning" do
|
76
|
-
connect.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
-
connect.Close([:int])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with libvirt installed" do
|
82
|
-
before :each do
|
83
|
-
connect.stub(:ffi_lib).with("libvirt")
|
84
|
-
end
|
85
|
-
|
86
|
-
context "and the function is a valid one" do
|
87
|
-
before :each do
|
88
|
-
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
89
|
-
connect.stub(:send).with("virConnectClose", [])
|
90
|
-
end
|
91
|
-
|
92
|
-
after :each do
|
93
|
-
connect.Close([:int])
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should attach it as a binding for C's function" do
|
97
|
-
connect.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should call the new attached method" do
|
101
|
-
connect.should_receive(:send).with("virConnectClose", [])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "and the function is not a valid one" do
|
106
|
-
before :each do
|
107
|
-
connect.stub(:attach_function).with("virConnectAbc", "virConnectAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should raise an exception" do
|
111
|
-
lambda { connect.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "without libvirt installed" do
|
117
|
-
it "should raise an exception" do
|
118
|
-
lambda { connect.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Libvirt::Ruby::Domain do
|
4
|
-
let(:domain) { Libvirt::Ruby::Domain }
|
5
|
-
|
6
|
-
context "when calling method #dispatcher" do
|
7
|
-
context "that is now deprecated" do
|
8
|
-
before :each do
|
9
|
-
domain.stub(:ffi_lib).with("libvirt")
|
10
|
-
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int)
|
11
|
-
domain.stub(:send).with("virDomainCreate", [])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should raise a deprecated method warning" do
|
15
|
-
domain.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
-
domain.dispatcher('Create', [], :int)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with libvirt installed" do
|
21
|
-
before :each do
|
22
|
-
domain.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
23
|
-
domain.stub(:ffi_lib).with("libvirt")
|
24
|
-
end
|
25
|
-
|
26
|
-
context "and a valid libvirt function" do
|
27
|
-
before :each do
|
28
|
-
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
29
|
-
domain.stub(:send).with("virDomainCreate", [])
|
30
|
-
end
|
31
|
-
|
32
|
-
after :each do
|
33
|
-
domain.dispatcher('Create', [], :int)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should attach it as a binding for C's function" do
|
37
|
-
domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should call the new attached method" do
|
41
|
-
domain.should_receive(:send).with("virDomainCreate", [])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and an invalid libvirt function" do
|
46
|
-
before :each do
|
47
|
-
domain.stub(:attach_function).with("virDomainAbc", "virDomainAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise an exception" do
|
51
|
-
lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "without libvirt installed" do
|
57
|
-
before :each do
|
58
|
-
domain.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise an exception" do
|
62
|
-
lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when calling any libvirt function directly" do
|
68
|
-
context "that is the new way" do
|
69
|
-
before :each do
|
70
|
-
domain.stub(:ffi_lib).with("libvirt")
|
71
|
-
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int)
|
72
|
-
domain.stub(:send).with("virDomainCreate", [])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not raise a deprecated method warning" do
|
76
|
-
domain.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
-
domain.Create([:int])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with libvirt installed" do
|
82
|
-
before :each do
|
83
|
-
domain.stub(:ffi_lib).with("libvirt")
|
84
|
-
end
|
85
|
-
|
86
|
-
context "and the function is a valid one" do
|
87
|
-
before :each do
|
88
|
-
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
89
|
-
domain.stub(:send).with("virDomainCreate", [])
|
90
|
-
end
|
91
|
-
|
92
|
-
after :each do
|
93
|
-
domain.Create([:int])
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should attach it as a binding for C's function" do
|
97
|
-
domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should call the new attached method" do
|
101
|
-
domain.should_receive(:send).with("virDomainCreate", [])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "and the function is not a valid one" do
|
106
|
-
before :each do
|
107
|
-
domain.stub(:attach_function).with("virDomainAbc", "virDomainAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should raise an exception" do
|
111
|
-
lambda { domain.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "without libvirt installed" do
|
117
|
-
it "should raise an exception" do
|
118
|
-
lambda { domain.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Libvirt::Ruby::Network do
|
4
|
-
let(:network) { Libvirt::Ruby::Network }
|
5
|
-
|
6
|
-
context "when calling method #dispatcher" do
|
7
|
-
context "that is now deprecated" do
|
8
|
-
before :each do
|
9
|
-
network.stub(:ffi_lib).with("libvirt")
|
10
|
-
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int)
|
11
|
-
network.stub(:send).with("virNetworkRef", [])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should raise a deprecated method warning" do
|
15
|
-
network.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
-
network.dispatcher('Ref', [], :int)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with libvirt installed" do
|
21
|
-
before :each do
|
22
|
-
network.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
23
|
-
network.stub(:ffi_lib).with("libvirt")
|
24
|
-
end
|
25
|
-
|
26
|
-
context "and a valid libvirt function" do
|
27
|
-
before :each do
|
28
|
-
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
29
|
-
network.stub(:send).with("virNetworkRef", [])
|
30
|
-
end
|
31
|
-
|
32
|
-
after :each do
|
33
|
-
network.dispatcher('Ref', [], :int)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should attach it as a binding for C's function" do
|
37
|
-
network.should_receive(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should call the new attached method" do
|
41
|
-
network.should_receive(:send).with("virNetworkRef", [])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and an invalid libvirt function" do
|
46
|
-
before :each do
|
47
|
-
network.stub(:attach_function).with("virNetworkAbc", "virNetworkAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise an exception" do
|
51
|
-
lambda { network.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "without libvirt installed" do
|
57
|
-
before :each do
|
58
|
-
network.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise an exception" do
|
62
|
-
lambda { network.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when calling any libvirt function directly" do
|
68
|
-
context "that is the new way" do
|
69
|
-
before :each do
|
70
|
-
network.stub(:ffi_lib).with("libvirt")
|
71
|
-
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int)
|
72
|
-
network.stub(:send).with("virNetworkRef", [])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not raise a deprecated method warning" do
|
76
|
-
network.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
-
network.Ref([:int])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with libvirt installed" do
|
82
|
-
before :each do
|
83
|
-
network.stub(:ffi_lib).with("libvirt")
|
84
|
-
end
|
85
|
-
|
86
|
-
context "and the function is a valid one" do
|
87
|
-
before :each do
|
88
|
-
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
89
|
-
network.stub(:send).with("virNetworkRef", [])
|
90
|
-
end
|
91
|
-
|
92
|
-
after :each do
|
93
|
-
network.Ref([:int])
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should attach it as a binding for C's function" do
|
97
|
-
network.should_receive(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should call the new attached method" do
|
101
|
-
network.should_receive(:send).with("virNetworkRef", [])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "and the function is not a valid one" do
|
106
|
-
before :each do
|
107
|
-
network.stub(:attach_function).with("virNetworkAbc", "virNetworkAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should raise an exception" do
|
111
|
-
lambda { network.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "without libvirt installed" do
|
117
|
-
it "should raise an exception" do
|
118
|
-
lambda { network.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Libvirt::Ruby::StoragePool do
|
4
|
-
let(:storage_pool) { Libvirt::Ruby::StoragePool }
|
5
|
-
|
6
|
-
context "when calling method #dispatcher" do
|
7
|
-
context "that is now deprecated" do
|
8
|
-
before :each do
|
9
|
-
storage_pool.stub(:ffi_lib).with("libvirt")
|
10
|
-
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int)
|
11
|
-
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should raise a deprecated method warning" do
|
15
|
-
storage_pool.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
-
storage_pool.dispatcher('Refresh', [], :int)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with libvirt installed" do
|
21
|
-
before :each do
|
22
|
-
storage_pool.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
23
|
-
storage_pool.stub(:ffi_lib).with("libvirt")
|
24
|
-
end
|
25
|
-
|
26
|
-
context "and a valid libvirt function" do
|
27
|
-
before :each do
|
28
|
-
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
29
|
-
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
30
|
-
end
|
31
|
-
|
32
|
-
after :each do
|
33
|
-
storage_pool.dispatcher('Refresh', [], :int)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should attach it as a binding for C's function" do
|
37
|
-
storage_pool.should_receive(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should call the new attached method" do
|
41
|
-
storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and an invalid libvirt function" do
|
46
|
-
before :each do
|
47
|
-
storage_pool.stub(:attach_function).with("virStoragePoolAbc", "virStoragePoolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise an exception" do
|
51
|
-
lambda { storage_pool.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "without libvirt installed" do
|
57
|
-
before :each do
|
58
|
-
storage_pool.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise an exception" do
|
62
|
-
lambda { storage_pool.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when calling any libvirt function directly" do
|
68
|
-
context "that is the new way" do
|
69
|
-
before :each do
|
70
|
-
storage_pool.stub(:ffi_lib).with("libvirt")
|
71
|
-
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int)
|
72
|
-
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not raise a deprecated method warning" do
|
76
|
-
storage_pool.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
-
storage_pool.Refresh([:int])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with libvirt installed" do
|
82
|
-
before :each do
|
83
|
-
storage_pool.stub(:ffi_lib).with("libvirt")
|
84
|
-
end
|
85
|
-
|
86
|
-
context "and the function is a valid one" do
|
87
|
-
before :each do
|
88
|
-
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
89
|
-
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
90
|
-
end
|
91
|
-
|
92
|
-
after :each do
|
93
|
-
storage_pool.Refresh([:int])
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should attach it as a binding for C's function" do
|
97
|
-
storage_pool.should_receive(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should call the new attached method" do
|
101
|
-
storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "and the function is not a valid one" do
|
106
|
-
before :each do
|
107
|
-
storage_pool.stub(:attach_function).with("virStoragePoolAbc", "virStoragePoolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should raise an exception" do
|
111
|
-
lambda { storage_pool.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "without libvirt installed" do
|
117
|
-
it "should raise an exception" do
|
118
|
-
lambda { storage_pool.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Libvirt::Ruby::StorageVol do
|
4
|
-
let(:storage_vol) { Libvirt::Ruby::StorageVol }
|
5
|
-
|
6
|
-
context "when calling method #dispatcher" do
|
7
|
-
context "that is now deprecated" do
|
8
|
-
before :each do
|
9
|
-
storage_vol.stub(:ffi_lib).with("libvirt")
|
10
|
-
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int)
|
11
|
-
storage_vol.stub(:send).with("virStorageVolResize", [])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should raise a deprecated method warning" do
|
15
|
-
storage_vol.should_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
16
|
-
storage_vol.dispatcher('Resize', [], :int)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with libvirt installed" do
|
21
|
-
before :each do
|
22
|
-
storage_vol.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
23
|
-
storage_vol.stub(:ffi_lib).with("libvirt")
|
24
|
-
end
|
25
|
-
|
26
|
-
context "and a valid libvirt function" do
|
27
|
-
before :each do
|
28
|
-
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
29
|
-
storage_vol.stub(:send).with("virStorageVolResize", [])
|
30
|
-
end
|
31
|
-
|
32
|
-
after :each do
|
33
|
-
storage_vol.dispatcher('Resize', [], :int)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should attach it as a binding for C's function" do
|
37
|
-
storage_vol.should_receive(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should call the new attached method" do
|
41
|
-
storage_vol.should_receive(:send).with("virStorageVolResize", [])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and an invalid libvirt function" do
|
46
|
-
before :each do
|
47
|
-
storage_vol.stub(:attach_function).with("virStorageVolAbc", "virStorageVolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise an exception" do
|
51
|
-
lambda { storage_vol.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "without libvirt installed" do
|
57
|
-
before :each do
|
58
|
-
storage_vol.stub(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should raise an exception" do
|
62
|
-
lambda { storage_vol.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when calling method #dispatcher" do
|
68
|
-
context "that is the new way" do
|
69
|
-
before :each do
|
70
|
-
storage_vol.stub(:ffi_lib).with("libvirt")
|
71
|
-
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int)
|
72
|
-
storage_vol.stub(:send).with("virStorageVolResize", [])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not raise a deprecated method warning" do
|
76
|
-
storage_vol.should_not_receive(:warn).with("[DEPRECATION] `dispatcher` is deprecated. Please call the function directly instead.")
|
77
|
-
storage_vol.Resize([:int])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with libvirt installed" do
|
82
|
-
before :each do
|
83
|
-
storage_vol.stub(:ffi_lib).with("libvirt")
|
84
|
-
end
|
85
|
-
|
86
|
-
context "and the function is a valid one" do
|
87
|
-
before :each do
|
88
|
-
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
89
|
-
storage_vol.stub(:send).with("virStorageVolResize", [])
|
90
|
-
end
|
91
|
-
|
92
|
-
after :each do
|
93
|
-
storage_vol.Resize([:int])
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should attach it as a binding for C's function" do
|
97
|
-
storage_vol.should_receive(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should call the new attached method" do
|
101
|
-
storage_vol.should_receive(:send).with("virStorageVolResize", [])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "and the function is not a valid one" do
|
106
|
-
before :each do
|
107
|
-
storage_vol.stub(:attach_function).with("virStorageVolAbc", "virStorageVolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should raise an exception" do
|
111
|
-
lambda { storage_vol.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "without libvirt installed" do
|
117
|
-
it "should raise an exception" do
|
118
|
-
lambda { storage_vol.Abc([:int]) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|