ovirt 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/README.md +1 -1
- data/lib/ovirt/api.rb +3 -4
- data/lib/ovirt/base.rb +47 -44
- data/lib/ovirt/cluster.rb +1 -1
- data/lib/ovirt/data_center.rb +1 -1
- data/lib/ovirt/event.rb +424 -424
- data/lib/ovirt/exception.rb +2 -2
- data/lib/ovirt/inventory.rb +7 -7
- data/lib/ovirt/logging.rb +5 -0
- data/lib/ovirt/null_logger.rb +11 -0
- data/lib/ovirt/service.rb +35 -45
- data/lib/ovirt/snapshot.rb +2 -2
- data/lib/ovirt/statistic.rb +4 -5
- data/lib/ovirt/storage_domain.rb +1 -1
- data/lib/ovirt/template.rb +28 -31
- data/lib/ovirt/user.rb +1 -1
- data/lib/ovirt/version.rb +1 -1
- data/lib/ovirt/vm.rb +18 -24
- data/lib/ovirt.rb +12 -0
- data/spec/base_spec.rb +7 -9
- data/spec/event_spec.rb +3 -13
- data/spec/factories/template.rb +37 -0
- data/spec/factories/vm.rb +1 -3
- data/spec/service_spec.rb +22 -23
- data/spec/spec_helper.rb +89 -9
- data/spec/template_spec.rb +23 -54
- data/spec/vm_spec.rb +47 -49
- metadata +9 -5
@@ -0,0 +1,37 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :template, :class => "Ovirt::Template" do
|
3
|
+
initialize_with { new(service, {}) }
|
4
|
+
service { build(:service) }
|
5
|
+
end
|
6
|
+
|
7
|
+
factory :template_full, :parent => :template do
|
8
|
+
initialize_with do
|
9
|
+
new(service,
|
10
|
+
:id => "128f9ffd-b82c-41e4-8c00-9742ed173bac",
|
11
|
+
:href => "/api/vms/128f9ffd-b82c-41e4-8c00-9742ed173bac",
|
12
|
+
:cluster => {
|
13
|
+
:id => "5be5d08a-a60b-11e2-bee6-005056a217db",
|
14
|
+
:href => "/api/clusters/5be5d08a-a60b-11e2-bee6-005056a217db"},
|
15
|
+
:template => {
|
16
|
+
:id => "00000000-0000-0000-0000-000000000000",
|
17
|
+
:href => "/api/templates/00000000-0000-0000-0000-000000000000"},
|
18
|
+
:name => "bd-skeletal-clone-from-template",
|
19
|
+
:origin => "rhev",
|
20
|
+
:type => "server",
|
21
|
+
:memory => 536_870_912,
|
22
|
+
:stateless => false,
|
23
|
+
:creation_time => "2013-09-04 16:24:20 -0400",
|
24
|
+
:status => {:state => "down"},
|
25
|
+
:display => {:type => "spice", :monitors => 1},
|
26
|
+
:usb => {:enabled => false},
|
27
|
+
:cpu => {:topology => {:sockets => 1, :cores => 1}},
|
28
|
+
:high_availability => {:priority => 1, :enabled => false},
|
29
|
+
:os => {:type => "rhel5_64", :boot_order => [{:dev => "hd"}]},
|
30
|
+
:custom_attributes => [],
|
31
|
+
:placement_policy => {:affinity => "migratable", :host => {}},
|
32
|
+
:memory_policy => {:guaranteed => 536_870_912},
|
33
|
+
:guest_info => {}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/factories/vm.rb
CHANGED
@@ -7,7 +7,6 @@ FactoryGirl.define do
|
|
7
7
|
factory :vm_full, :parent => :vm do
|
8
8
|
initialize_with do
|
9
9
|
new(service,
|
10
|
-
{
|
11
10
|
:actions => {:stop => '/api/vms/128f9ffd-b82c-41e4-8c00-9742ed173bac/stop'},
|
12
11
|
:id => "128f9ffd-b82c-41e4-8c00-9742ed173bac",
|
13
12
|
:href => "/api/vms/128f9ffd-b82c-41e4-8c00-9742ed173bac",
|
@@ -33,8 +32,7 @@ FactoryGirl.define do
|
|
33
32
|
:placement_policy => {:affinity => "migratable", :host => {}},
|
34
33
|
:memory_policy => {:guaranteed => 536_870_912},
|
35
34
|
:guest_info => {}
|
36
|
-
|
37
|
-
)
|
35
|
+
)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
data/spec/service_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'rest-client'
|
3
2
|
|
4
3
|
describe Ovirt::Service do
|
@@ -7,7 +6,7 @@ describe Ovirt::Service do
|
|
7
6
|
context "#resource_post" do
|
8
7
|
it "raises Ovirt::Error if HTTP 409 response code received" do
|
9
8
|
error_detail = "API error"
|
10
|
-
return_data
|
9
|
+
return_data = <<-EOX.chomp
|
11
10
|
<action>
|
12
11
|
<fault>
|
13
12
|
<detail>#{error_detail}</detail>
|
@@ -16,90 +15,90 @@ describe Ovirt::Service do
|
|
16
15
|
EOX
|
17
16
|
|
18
17
|
rest_client = double('rest_client').as_null_object
|
19
|
-
rest_client.
|
20
|
-
return_data.
|
18
|
+
expect(rest_client).to receive(:post) do |&block|
|
19
|
+
allow(return_data).to receive(:code).and_return(409)
|
21
20
|
block.call(return_data)
|
22
21
|
end
|
23
22
|
|
24
|
-
service.
|
23
|
+
allow(service).to receive(:create_resource).and_return(rest_client)
|
25
24
|
expect { service.resource_post('uri', 'data') }.to raise_error(Ovirt::Error, error_detail)
|
26
25
|
end
|
27
26
|
|
28
27
|
it "raises Ovirt::Error if HTTP 409 response code received" do
|
29
28
|
error_detail = "Usage message"
|
30
|
-
return_data
|
29
|
+
return_data = <<-EOX.chomp
|
31
30
|
<usage_message>
|
32
31
|
<message>#{error_detail}</message>
|
33
32
|
</usage_message>
|
34
33
|
EOX
|
35
34
|
|
36
35
|
rest_client = double('rest_client').as_null_object
|
37
|
-
rest_client.
|
38
|
-
return_data.
|
36
|
+
expect(rest_client).to receive(:post) do |&block|
|
37
|
+
allow(return_data).to receive(:code).and_return(409)
|
39
38
|
block.call(return_data)
|
40
39
|
end
|
41
40
|
|
42
|
-
service.
|
41
|
+
allow(service).to receive(:create_resource).and_return(rest_client)
|
43
42
|
expect { service.resource_post('uri', 'data') }.to raise_error(Ovirt::UsageError, error_detail)
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
46
|
it "#resource_get on exception" do
|
48
|
-
service.
|
47
|
+
allow(service).to receive(:create_resource).and_raise(Exception, "BLAH")
|
49
48
|
expect { service.resource_get('api') }.to raise_error(Exception, "BLAH")
|
50
49
|
end
|
51
50
|
|
52
51
|
context ".ovirt?" do
|
53
52
|
it "false when ResourceNotFound" do
|
54
|
-
described_class.
|
55
|
-
described_class.ovirt?(:server => "127.0.0.1").
|
53
|
+
expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_raise(RestClient::ResourceNotFound)
|
54
|
+
expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
|
56
55
|
end
|
57
56
|
|
58
57
|
it "true when key non-empty" do
|
59
58
|
fake_key = "ssh-rsa " + ("A" * 372) + " ovirt-engine\n"
|
60
|
-
described_class.
|
61
|
-
described_class.ovirt?(:server => "127.0.0.1").
|
59
|
+
expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_return(fake_key)
|
60
|
+
expect(described_class.ovirt?(:server => "127.0.0.1")).to be true
|
62
61
|
end
|
63
62
|
|
64
63
|
it "false when key empty" do
|
65
64
|
fake_key = "\n"
|
66
|
-
described_class.
|
67
|
-
described_class.ovirt?(:server => "127.0.0.1").
|
65
|
+
expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_return(fake_key)
|
66
|
+
expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
70
|
context "#base_uri" do
|
72
|
-
let(:defaults) { {:username => nil, :password => nil}}
|
71
|
+
let(:defaults) { {:username => nil, :password => nil} }
|
73
72
|
subject { described_class.new(defaults.merge(@options)).send(:base_uri) }
|
74
73
|
|
75
74
|
it "ipv4" do
|
76
75
|
@options = {:server => "127.0.0.1"}
|
77
|
-
subject.
|
76
|
+
expect(subject).to eq("https://127.0.0.1:443")
|
78
77
|
end
|
79
78
|
|
80
79
|
it "ipv6" do
|
81
80
|
@options = {:server => "::1"}
|
82
|
-
subject.
|
81
|
+
expect(subject).to eq("https://[::1]:443")
|
83
82
|
end
|
84
83
|
|
85
84
|
it "hostname" do
|
86
85
|
@options = {:server => "nobody.com"}
|
87
|
-
subject.
|
86
|
+
expect(subject).to eq("https://nobody.com:443")
|
88
87
|
end
|
89
88
|
|
90
89
|
it "port 4443" do
|
91
90
|
@options = {:server => "nobody.com", :port => 4443}
|
92
|
-
subject.
|
91
|
+
expect(subject).to eq("https://nobody.com:4443")
|
93
92
|
end
|
94
93
|
|
95
94
|
it "blank port" do
|
96
95
|
@options = {:server => "nobody.com", :port => ""}
|
97
|
-
subject.
|
96
|
+
expect(subject).to eq("https://nobody.com")
|
98
97
|
end
|
99
98
|
|
100
99
|
it "nil port uses defaults" do
|
101
100
|
@options = {:server => "nobody.com", :port => nil}
|
102
|
-
subject.
|
101
|
+
expect(subject).to eq("https://nobody.com:443")
|
103
102
|
end
|
104
103
|
end
|
105
104
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,19 +3,99 @@ FactoryGirl.find_definitions
|
|
3
3
|
|
4
4
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
5
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
-
#
|
7
|
-
# loaded
|
6
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
7
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
8
|
+
# files.
|
9
|
+
#
|
10
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
11
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
12
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
13
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
14
|
+
# a separate helper file that requires the additional dependencies and performs
|
15
|
+
# the additional setup, and require it from the spec files that actually need
|
16
|
+
# it.
|
17
|
+
#
|
18
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
19
|
+
# users commonly want.
|
8
20
|
#
|
9
21
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
22
|
RSpec.configure do |config|
|
11
|
-
config.
|
12
|
-
|
23
|
+
# rspec-expectations config goes here. You can use an alternate
|
24
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
25
|
+
# assertions if you prefer.
|
26
|
+
config.expect_with :rspec do |expectations|
|
27
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
28
|
+
# and `failure_message` of custom matchers include text for helper methods
|
29
|
+
# defined using `chain`, e.g.:
|
30
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
31
|
+
# # => "be bigger than 2 and smaller than 4"
|
32
|
+
# ...rather than:
|
33
|
+
# # => "be bigger than 2"
|
34
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
35
|
+
end
|
36
|
+
|
37
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
38
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
39
|
+
config.mock_with :rspec do |mocks|
|
40
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
41
|
+
# a real object. This is generally recommended, and will default to
|
42
|
+
# `true` in RSpec 4.
|
43
|
+
# TODO: Enable this and fix related failures
|
44
|
+
# mocks.verify_partial_doubles = true
|
45
|
+
end
|
13
46
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
# # These two settings work together to allow you to limit a spec run
|
50
|
+
# # to individual examples or groups you care about by tagging them with
|
51
|
+
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
52
|
+
# # get run.
|
53
|
+
# config.filter_run :focus
|
54
|
+
# config.run_all_when_everything_filtered = true
|
55
|
+
#
|
56
|
+
# # Allows RSpec to persist some state between runs in order to support
|
57
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
58
|
+
# # you configure your source control system to ignore this file.
|
59
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
60
|
+
#
|
61
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
62
|
+
# # recommended. For more details, see:
|
63
|
+
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
64
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
65
|
+
# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
66
|
+
# config.disable_monkey_patching!
|
67
|
+
#
|
68
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
69
|
+
# # be too noisy due to issues in dependencies.
|
70
|
+
# config.warnings = true
|
71
|
+
#
|
72
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
73
|
+
# # file, and it's useful to allow more verbose output when running an
|
74
|
+
# # individual spec file.
|
75
|
+
# if config.files_to_run.one?
|
76
|
+
# # Use the documentation formatter for detailed output,
|
77
|
+
# # unless a formatter has already been configured
|
78
|
+
# # (e.g. via a command-line flag).
|
79
|
+
# config.default_formatter = 'doc'
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# # Print the 10 slowest examples and example groups at the
|
83
|
+
# # end of the spec run, to help surface which specs are running
|
84
|
+
# # particularly slow.
|
85
|
+
# config.profile_examples = 10
|
86
|
+
#
|
87
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
88
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
89
|
+
# # the seed, which is printed after each run.
|
90
|
+
# # --seed 1234
|
91
|
+
# config.order = :random
|
92
|
+
#
|
93
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
94
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
95
|
+
# # test failures related to randomization by passing the same `--seed` value
|
96
|
+
# # as the one that triggered the failure.
|
97
|
+
# Kernel.srand config.seed
|
98
|
+
config.order = :random
|
19
99
|
config.include FactoryGirl::Syntax::Methods
|
20
100
|
end
|
21
101
|
|
data/spec/template_spec.rb
CHANGED
@@ -1,42 +1,13 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Ovirt::Template do
|
4
|
-
let(:service)
|
5
|
-
|
6
|
-
@template = Ovirt::Template.new(service, {
|
7
|
-
:id => "128f9ffd-b82c-41e4-8c00-9742ed173bac",
|
8
|
-
:href => "/api/vms/128f9ffd-b82c-41e4-8c00-9742ed173bac",
|
9
|
-
:cluster => {
|
10
|
-
:id => "5be5d08a-a60b-11e2-bee6-005056a217db",
|
11
|
-
:href => "/api/clusters/5be5d08a-a60b-11e2-bee6-005056a217db"},
|
12
|
-
:template => {
|
13
|
-
:id => "00000000-0000-0000-0000-000000000000",
|
14
|
-
:href => "/api/templates/00000000-0000-0000-0000-000000000000"},
|
15
|
-
:name => "bd-skeletal-clone-from-template",
|
16
|
-
:origin => "rhev",
|
17
|
-
:type => "server",
|
18
|
-
:memory => 536870912,
|
19
|
-
:stateless => false,
|
20
|
-
:creation_time => "2013-09-04 16:24:20 -0400",
|
21
|
-
:status => {:state => "down"},
|
22
|
-
:display => {:type => "spice", :monitors => 1},
|
23
|
-
:usb => {:enabled => false},
|
24
|
-
:cpu => {:topology => {:sockets => 1, :cores => 1}},
|
25
|
-
:high_availability => {:priority => 1, :enabled => false},
|
26
|
-
:os => {:type => "rhel5_64", :boot_order => [{:dev => "hd"}]},
|
27
|
-
:custom_attributes => [],
|
28
|
-
:placement_policy => {:affinity => "migratable", :host => {}},
|
29
|
-
:memory_policy => {:guaranteed => 536870912},
|
30
|
-
:guest_info => {}
|
31
|
-
})
|
32
|
-
end
|
2
|
+
let(:service) { template.service }
|
3
|
+
let(:template) { build(:template_full) }
|
33
4
|
|
34
5
|
context "#create_vm" do
|
35
6
|
it "clones properties for skeletal clones" do
|
36
|
-
options
|
7
|
+
options = {:clone_type => :skeletal}
|
37
8
|
expected_data = {
|
38
9
|
:clone_type => :linked,
|
39
|
-
:memory =>
|
10
|
+
:memory => 536_870_912,
|
40
11
|
:stateless => false,
|
41
12
|
:type => "server",
|
42
13
|
:display => {:type => "spice", :monitors => 1},
|
@@ -44,11 +15,11 @@ describe Ovirt::Template do
|
|
44
15
|
:cpu => {:topology => {:sockets => 1, :cores => 1}},
|
45
16
|
:high_availability => {:priority => 1, :enabled => false},
|
46
17
|
:os_type => "rhel5_64"}
|
47
|
-
|
48
|
-
|
49
|
-
service.
|
50
|
-
service.blank_template.
|
51
|
-
|
18
|
+
allow(template).to receive(:nics).and_return([])
|
19
|
+
allow(template).to receive(:disks).and_return([])
|
20
|
+
allow(service).to receive(:blank_template).and_return(double('blank template'))
|
21
|
+
expect(service.blank_template).to receive(:create_vm).once.with(expected_data)
|
22
|
+
template.create_vm(options)
|
52
23
|
end
|
53
24
|
|
54
25
|
it "overrides properties for linked clones" do
|
@@ -90,19 +61,17 @@ EOX
|
|
90
61
|
:name => 'new name',
|
91
62
|
:cluster => 'fb27f9a0-cb75-4e0f-8c07-8dec0c5ab483',
|
92
63
|
:os_type => 'test'}
|
93
|
-
service.
|
94
|
-
|
64
|
+
expect(service).to receive(:resource_post).once.with(:vms, expected_data).and_return(response_xml)
|
65
|
+
template.create_vm(options)
|
95
66
|
end
|
96
67
|
|
97
68
|
context "#create_new_disks_from_template" do
|
98
69
|
before do
|
99
|
-
@disk = Ovirt::Disk.new(service,
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
})
|
105
|
-
@template.stub(:disks).and_return([@disk])
|
70
|
+
@disk = Ovirt::Disk.new(service, :id => "01eae62b-90df-424d-978c-beaa7eb2f7f6",
|
71
|
+
:href => "/api/templates/54f1b9f4-0e89-4c72-9a26-f94dcb857264/disks/01eae62b-90df-424d-978c-beaa7eb2f7f6",
|
72
|
+
:name => "clone_Disk1",
|
73
|
+
:storage_domains => [{:id => "aa7e70e5-40d0-43e2-a605-92ce6ba652a8"}])
|
74
|
+
allow(template).to receive(:disks).and_return([@disk])
|
106
75
|
|
107
76
|
@vm = double('rhevm_vm')
|
108
77
|
end
|
@@ -111,24 +80,24 @@ EOX
|
|
111
80
|
expected_data = @disk.attributes.dup
|
112
81
|
expected_data[:storage] = expected_data[:storage_domains].first[:id]
|
113
82
|
|
114
|
-
@vm.
|
115
|
-
|
83
|
+
expect(@vm).to receive(:create_disk).once.with(expected_data)
|
84
|
+
template.send(:create_new_disks_from_template, @vm, {})
|
116
85
|
end
|
117
86
|
|
118
87
|
it "with a storage override" do
|
119
88
|
expected_data = @disk.attributes.dup
|
120
|
-
options
|
89
|
+
options = {:storage => "xxxxxxxx-40d0-43e2-a605-92ce6ba652a8"}
|
121
90
|
expected_data.merge!(options)
|
122
91
|
|
123
|
-
@vm.
|
124
|
-
|
92
|
+
expect(@vm).to receive(:create_disk).once.with(expected_data)
|
93
|
+
template.send(:create_new_disks_from_template, @vm, options)
|
125
94
|
end
|
126
95
|
end
|
127
96
|
|
128
97
|
context "build_clone_xml" do
|
129
98
|
it "Properly sets vm/cpu/topology attributes" do
|
130
|
-
Ovirt::Base.
|
131
|
-
xml =
|
99
|
+
allow(Ovirt::Base).to receive(:object_to_id)
|
100
|
+
xml = template.send(:build_clone_xml, :name => "Blank", :cluster => "6b8f1c1e-3eb0-11e4-8420-56847afe9799")
|
132
101
|
nodeset = Nokogiri::XML.parse(xml).xpath("//vm/cpu/topology")
|
133
102
|
node = nodeset.first
|
134
103
|
|
data/spec/vm_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Ovirt::Vm do
|
4
2
|
let(:service) { vm.service }
|
5
3
|
let(:vm) { build(:vm_full) }
|
@@ -8,23 +6,23 @@ describe Ovirt::Vm do
|
|
8
6
|
before do
|
9
7
|
@resource_url = "#{vm.attributes[:href]}/disks"
|
10
8
|
@base_options = {
|
11
|
-
:storage
|
12
|
-
:id
|
13
|
-
:href
|
14
|
-
:name
|
15
|
-
:interface
|
16
|
-
:format
|
17
|
-
:image_id
|
18
|
-
:size
|
19
|
-
:provisioned_size
|
20
|
-
:actual_size
|
21
|
-
:sparse
|
22
|
-
:bootable
|
23
|
-
:wipe_after_delete
|
24
|
-
:propagate_errors
|
25
|
-
:status
|
26
|
-
:storage_domains
|
27
|
-
:storage_domain_id
|
9
|
+
:storage => "aa7e70e5-abcd-1234-a605-92ce6ba652a8",
|
10
|
+
:id => "01eae62b-90df-424d-978c-beaa7eb2f7f6",
|
11
|
+
:href => "/api/templates/54f1b9f4-0e89-4c72-9a26-f94dcb857264/disks/01eae62b-90df-424d-978c-beaa7eb2f7f6",
|
12
|
+
:name => "bd-clone_Disk1",
|
13
|
+
:interface => "virtio",
|
14
|
+
:format => "raw",
|
15
|
+
:image_id => "a791ba77-8cc1-44de-9945-69f0a291cc47",
|
16
|
+
:size => 10_737_418_240,
|
17
|
+
:provisioned_size => 10_737_418_240,
|
18
|
+
:actual_size => 1_316_855_808,
|
19
|
+
:sparse => true,
|
20
|
+
:bootable => true,
|
21
|
+
:wipe_after_delete => true,
|
22
|
+
:propagate_errors => true,
|
23
|
+
:status => {:state => "ok"},
|
24
|
+
:storage_domains => [{:id => "aa7e70e5-40d0-43e2-a605-92ce6ba652a8"}],
|
25
|
+
:storage_domain_id => "aa7e70e5-40d0-43e2-a605-92ce6ba652a8"
|
28
26
|
}
|
29
27
|
@base_data = <<-EOX.chomp
|
30
28
|
<disk>
|
@@ -44,29 +42,29 @@ EOX
|
|
44
42
|
end
|
45
43
|
|
46
44
|
[:sparse, :bootable, :wipe_after_delete, :propagate_errors].each do |boolean_key|
|
47
|
-
context "xml #{boolean_key
|
45
|
+
context "xml #{boolean_key} value" do
|
48
46
|
it "set to true" do
|
49
47
|
expected_data = @base_data
|
50
|
-
options
|
48
|
+
options = @base_options.merge(boolean_key => true)
|
51
49
|
|
52
|
-
service.
|
50
|
+
expect(service).to receive(:resource_post).once.with(@resource_url, expected_data)
|
53
51
|
vm.create_disk(options)
|
54
52
|
end
|
55
53
|
|
56
54
|
it "set to false" do
|
57
|
-
expected_data = @base_data.gsub("<#{boolean_key
|
58
|
-
options
|
55
|
+
expected_data = @base_data.gsub("<#{boolean_key}>true</#{boolean_key}>", "<#{boolean_key}>false</#{boolean_key}>")
|
56
|
+
options = @base_options.merge(boolean_key => false)
|
59
57
|
|
60
|
-
service.
|
58
|
+
expect(service).to receive(:resource_post).once.with(@resource_url, expected_data)
|
61
59
|
vm.create_disk(options)
|
62
60
|
end
|
63
61
|
|
64
62
|
it "unset" do
|
65
|
-
expected_data = @base_data.gsub(" <#{boolean_key
|
66
|
-
options
|
63
|
+
expected_data = @base_data.gsub(" <#{boolean_key}>true</#{boolean_key}>\n", "")
|
64
|
+
options = @base_options.dup
|
67
65
|
options.delete(boolean_key)
|
68
66
|
|
69
|
-
service.
|
67
|
+
expect(service).to receive(:resource_post).once.with(@resource_url, expected_data)
|
70
68
|
vm.create_disk(options)
|
71
69
|
end
|
72
70
|
end
|
@@ -81,7 +79,7 @@ EOX
|
|
81
79
|
end
|
82
80
|
|
83
81
|
def expected_data(element)
|
84
|
-
|
82
|
+
<<-EOX.chomp
|
85
83
|
<nic>
|
86
84
|
<name>#{@name}</name>
|
87
85
|
#{element}
|
@@ -91,30 +89,30 @@ EOX
|
|
91
89
|
|
92
90
|
it "populates the interface" do
|
93
91
|
interface = 'interface'
|
94
|
-
service.
|
95
|
-
|
96
|
-
vm.create_nic(@base_options.merge(
|
92
|
+
expect(service).to receive(:resource_post).once.with(
|
93
|
+
@resource_url, expected_data("<interface>#{interface}</interface>"))
|
94
|
+
vm.create_nic(@base_options.merge(:interface => interface))
|
97
95
|
end
|
98
96
|
|
99
97
|
it "populates the network id" do
|
100
98
|
network_id = 'network_id'
|
101
|
-
service.
|
102
|
-
|
103
|
-
vm.create_nic(@base_options.merge(
|
99
|
+
expect(service).to receive(:resource_post).once.with(
|
100
|
+
@resource_url, expected_data("<network id=\"#{network_id}\"/>"))
|
101
|
+
vm.create_nic(@base_options.merge(:network_id => network_id))
|
104
102
|
end
|
105
103
|
|
106
104
|
it "populates the MAC address" do
|
107
105
|
mac_address = 'mac_address'
|
108
|
-
service.
|
109
|
-
|
110
|
-
vm.create_nic(@base_options.merge(
|
106
|
+
expect(service).to receive(:resource_post).once.with(
|
107
|
+
@resource_url, expected_data("<mac address=\"#{mac_address}\"/>"))
|
108
|
+
vm.create_nic(@base_options.merge(:mac_address => mac_address))
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
114
112
|
context "#memory_reserve" do
|
115
113
|
it "updates the memory policy guarantee" do
|
116
114
|
memory_reserve = 1.gigabyte
|
117
|
-
expected_data
|
115
|
+
expected_data = <<-EOX.chomp
|
118
116
|
<vm>
|
119
117
|
<memory_policy>
|
120
118
|
<guaranteed>#{memory_reserve}</guaranteed>
|
@@ -131,9 +129,9 @@ EOX
|
|
131
129
|
</vm>
|
132
130
|
EOX
|
133
131
|
|
134
|
-
service.
|
135
|
-
|
136
|
-
|
132
|
+
expect(service).to receive(:resource_put).once.with(
|
133
|
+
vm.attributes[:href],
|
134
|
+
expected_data).and_return(return_data)
|
137
135
|
vm.memory_reserve = memory_reserve
|
138
136
|
end
|
139
137
|
end
|
@@ -149,12 +147,12 @@ EOX
|
|
149
147
|
EOX
|
150
148
|
|
151
149
|
rest_client = double('rest_client').as_null_object
|
152
|
-
rest_client.
|
153
|
-
return_data.
|
150
|
+
expect(rest_client).to receive(:post) do |&block|
|
151
|
+
allow(return_data).to receive(:code).and_return(409)
|
154
152
|
block.call(return_data)
|
155
153
|
end
|
156
154
|
|
157
|
-
service.
|
155
|
+
allow(service).to receive(:create_resource).and_return(rest_client)
|
158
156
|
expect { vm.stop }.to raise_error Ovirt::VmIsNotRunning
|
159
157
|
end
|
160
158
|
end
|
@@ -194,8 +192,8 @@ EOX
|
|
194
192
|
</memory_policy>
|
195
193
|
</vm>
|
196
194
|
EOX
|
197
|
-
service.
|
198
|
-
service.
|
195
|
+
expect(service).to receive(:version).twice.and_return(:major => "3", :minor => "0", :build => "0", :revision => "0")
|
196
|
+
expect(service).to receive(:resource_put).once.with(vm.attributes[:href], expected_data).and_return(return_data)
|
199
197
|
vm.detach_floppy
|
200
198
|
end
|
201
199
|
|
@@ -224,8 +222,8 @@ EOX
|
|
224
222
|
</memory_policy>
|
225
223
|
</vm>
|
226
224
|
EOX
|
227
|
-
service.
|
228
|
-
service.
|
225
|
+
expect(service).to receive(:version).and_return(:major => "3", :minor => "3", :build => "0", :revision => "0")
|
226
|
+
expect(service).to receive(:resource_put).once.with(vm.attributes[:href], expected_data).and_return(return_data)
|
229
227
|
vm.detach_floppy
|
230
228
|
end
|
231
229
|
end
|