vcloud-core 0.5.0 → 0.6.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 +2 -0
- data/CHANGELOG.md +10 -1
- data/CONTRIBUTING.md +66 -0
- data/README.md +5 -5
- data/Rakefile +1 -1
- data/lib/vcloud/core/config_validator.rb +20 -20
- data/lib/vcloud/core/query_cli.rb +1 -1
- data/lib/vcloud/core/version.rb +1 -1
- data/lib/vcloud/core/vm.rb +2 -39
- data/lib/vcloud/fog/service_interface.rb +10 -5
- data/spec/integration/README.md +1 -1
- data/spec/integration/core/edge_gateway_spec.rb +133 -0
- data/spec/integration/core/query_runner_spec.rb +10 -4
- data/spec/integration/core/vapp_spec.rb +249 -0
- data/spec/integration/core/vdc_spec.rb +6 -4
- data/spec/integration/core/vm_spec.rb +24 -12
- data/spec/spec_helper.rb +21 -10
- data/spec/support/integration_helper.rb +27 -0
- data/spec/vcloud/core/config_loader_spec.rb +10 -10
- data/spec/vcloud/core/config_validator_spec.rb +7 -0
- data/spec/vcloud/core/edge_gateway_spec.rb +10 -10
- data/spec/vcloud/core/metadata_helper_spec.rb +2 -2
- data/spec/vcloud/core/org_vdc_network_spec.rb +15 -15
- data/spec/vcloud/core/query_runner_spec.rb +13 -13
- data/spec/vcloud/core/query_spec.rb +9 -9
- data/spec/vcloud/core/vapp_spec.rb +19 -19
- data/spec/vcloud/core/vapp_template_spec.rb +9 -9
- data/spec/vcloud/core/vdc_spec.rb +6 -6
- data/spec/vcloud/core/vm_spec.rb +50 -118
- data/spec/vcloud/fog/fog_model_interface_spec.rb +3 -3
- data/spec/vcloud/fog/service_interface_spec.rb +9 -9
- data/vcloud-core.gemspec +6 -6
- metadata +36 -35
- data/spec/integration/edge_gateway/configure_edge_gateway_services_spec.rb +0 -55
- data/spec/integration/edge_gateway/edge_gateway_spec.rb +0 -45
@@ -73,6 +73,13 @@ module Vcloud
|
|
73
73
|
expect(v.valid?).to be_true
|
74
74
|
end
|
75
75
|
|
76
|
+
it "should return error for nil value with allowed_empty: true)" do
|
77
|
+
data = nil
|
78
|
+
schema = { type: 'string', allowed_empty: true }
|
79
|
+
v = ConfigValidator.validate(:base, data, schema)
|
80
|
+
expect(v.errors).to eq([ 'base: is not a string'] )
|
81
|
+
end
|
82
|
+
|
76
83
|
it "should validate ok with a :matcher regex specified" do
|
77
84
|
data = "name-1234"
|
78
85
|
schema = { type: 'string', matcher: /^name-\d+$/ }
|
@@ -7,12 +7,12 @@ module Vcloud
|
|
7
7
|
before(:each) do
|
8
8
|
@edgegw_id = '12345678-1234-1234-1234-000000111454'
|
9
9
|
@mock_fog_interface = StubFogInterface.new
|
10
|
-
Vcloud::Fog::ServiceInterface.
|
10
|
+
allow(Vcloud::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
11
11
|
end
|
12
12
|
|
13
13
|
context "Class public interface" do
|
14
|
-
it { EdgeGateway.
|
15
|
-
it { EdgeGateway.
|
14
|
+
it { expect(EdgeGateway).to respond_to(:get_ids_by_name) }
|
15
|
+
it { expect(EdgeGateway).to respond_to(:get_by_name) }
|
16
16
|
end
|
17
17
|
|
18
18
|
context "Instance public interface" do
|
@@ -49,8 +49,8 @@ module Vcloud
|
|
49
49
|
{ :name => 'edgegw-test-1', :href => "/#{@edgegw_id}" }
|
50
50
|
]
|
51
51
|
mock_query = double(:query_runner)
|
52
|
-
Vcloud::Core::QueryRunner.
|
53
|
-
mock_query.
|
52
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
53
|
+
expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
|
54
54
|
@obj = EdgeGateway.get_by_name('edgegw-test-1')
|
55
55
|
expect(@obj.class).to be(Vcloud::Core::EdgeGateway)
|
56
56
|
end
|
@@ -60,8 +60,8 @@ module Vcloud
|
|
60
60
|
{ :name => 'edgegw-test-1', :href => "/#{@edgegw_id}" }
|
61
61
|
]
|
62
62
|
mock_query = double(:query_runner)
|
63
|
-
Vcloud::Core::QueryRunner.
|
64
|
-
mock_query.
|
63
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
64
|
+
expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
|
65
65
|
@obj = EdgeGateway.get_by_name('edgegw-test-1')
|
66
66
|
expect(@obj.id).to eq(@edgegw_id)
|
67
67
|
end
|
@@ -69,8 +69,8 @@ module Vcloud
|
|
69
69
|
it "should raise an error if no edgegw with that name exists" do
|
70
70
|
q_results = [ ]
|
71
71
|
mock_query = double(:query_runner)
|
72
|
-
Vcloud::Core::QueryRunner.
|
73
|
-
mock_query.
|
72
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
73
|
+
expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
|
74
74
|
expect{ EdgeGateway.get_by_name('edgegw-test-1') }.to raise_exception(RuntimeError, "edgeGateway edgegw-test-1 not found")
|
75
75
|
end
|
76
76
|
|
@@ -115,7 +115,7 @@ module Vcloud
|
|
115
115
|
}
|
116
116
|
}
|
117
117
|
}
|
118
|
-
@mock_fog_interface.
|
118
|
+
expect(@mock_fog_interface).to receive(:get_edge_gateway).
|
119
119
|
and_return(edge_gateway_hash)
|
120
120
|
@edgegw = EdgeGateway.new(@edgegw_id)
|
121
121
|
end
|
@@ -55,7 +55,7 @@ module Vcloud
|
|
55
55
|
]
|
56
56
|
metadata = MetadataHelper.extract_metadata(metadata_entries)
|
57
57
|
expect(metadata.count).to eq(1)
|
58
|
-
metadata.keys.
|
58
|
+
expect(metadata.keys).not_to include :untyped_key
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should include unrecognized metadata types" do
|
@@ -76,7 +76,7 @@ module Vcloud
|
|
76
76
|
]
|
77
77
|
metadata = MetadataHelper.extract_metadata(metadata_entries)
|
78
78
|
expect(metadata.count).to eq(2)
|
79
|
-
metadata.keys.
|
79
|
+
expect(metadata.keys).to include :unrecognized_type_key
|
80
80
|
end
|
81
81
|
|
82
82
|
|
@@ -11,14 +11,14 @@ module Vcloud
|
|
11
11
|
@vdc_name = 'test-vdc-1'
|
12
12
|
@net_name = 'test-net-1'
|
13
13
|
@mock_fog_interface = StubFogInterface.new
|
14
|
-
Vcloud::Fog::ServiceInterface.
|
15
|
-
Vdc.
|
14
|
+
allow(Vcloud::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
15
|
+
allow_any_instance_of(Vdc).to receive(:id).and_return(@vdc_id)
|
16
16
|
@mock_vdc = double(:vdc, :id => @vdc_id)
|
17
|
-
Vdc.
|
17
|
+
allow(Vdc).to receive(:get_by_name).and_return(@mock_vdc)
|
18
18
|
end
|
19
19
|
|
20
20
|
context "Class public interface" do
|
21
|
-
it { OrgVdcNetwork.
|
21
|
+
it { expect(OrgVdcNetwork).to respond_to(:provision) }
|
22
22
|
end
|
23
23
|
|
24
24
|
context "Object public interface" do
|
@@ -51,7 +51,7 @@ module Vcloud
|
|
51
51
|
|
52
52
|
context "#delete" do
|
53
53
|
it "should call down to Fog::ServiceInterface.delete_network with the correct id" do
|
54
|
-
@mock_fog_interface.
|
54
|
+
expect(@mock_fog_interface).to receive(:delete_network).with(@net_id)
|
55
55
|
OrgVdcNetwork.new(@net_id).delete
|
56
56
|
end
|
57
57
|
end
|
@@ -65,7 +65,7 @@ module Vcloud
|
|
65
65
|
:href => "/#{@vdc_id}",
|
66
66
|
:name => @vdc_name
|
67
67
|
)
|
68
|
-
Vdc.
|
68
|
+
allow(Vdc).to receive(:get_by_name).and_return(@mock_vdc)
|
69
69
|
end
|
70
70
|
|
71
71
|
context "should fail gracefully on bad input" do
|
@@ -131,8 +131,8 @@ module Vcloud
|
|
131
131
|
}
|
132
132
|
},
|
133
133
|
}
|
134
|
-
Vcloud::Core.logger.
|
135
|
-
@mock_fog_interface.
|
134
|
+
expect(Vcloud::Core.logger).to receive(:info)
|
135
|
+
expect(@mock_fog_interface).to receive(:post_create_org_vdc_network).
|
136
136
|
with(@vdc_id, @config[:name], expected_vcloud_attrs).
|
137
137
|
and_return({ :href => "/#{@net_id}" })
|
138
138
|
obj = Vcloud::Core::OrgVdcNetwork.provision(@config)
|
@@ -161,8 +161,8 @@ module Vcloud
|
|
161
161
|
}
|
162
162
|
}
|
163
163
|
}
|
164
|
-
Vcloud::Core.logger.
|
165
|
-
@mock_fog_interface.
|
164
|
+
expect(Vcloud::Core.logger).to receive(:info)
|
165
|
+
expect(@mock_fog_interface).to receive(:post_create_org_vdc_network).
|
166
166
|
with(@vdc_id, @config[:name], expected_vcloud_attrs).
|
167
167
|
and_return({ :href => "/#{@net_id}" })
|
168
168
|
Vcloud::Core::OrgVdcNetwork.provision(@config)
|
@@ -199,8 +199,8 @@ module Vcloud
|
|
199
199
|
}
|
200
200
|
},
|
201
201
|
}
|
202
|
-
Vcloud::Core.logger.
|
203
|
-
@mock_fog_interface.
|
202
|
+
expect(Vcloud::Core.logger).to receive(:info)
|
203
|
+
expect(@mock_fog_interface).to receive(:post_create_org_vdc_network).
|
204
204
|
with(@vdc_id, @config[:name], expected_vcloud_attrs).
|
205
205
|
and_return({ :href => "/#{@net_id}" })
|
206
206
|
Vcloud::Core::OrgVdcNetwork.provision(@config)
|
@@ -226,7 +226,7 @@ module Vcloud
|
|
226
226
|
it "should handle lack of ip_ranges on natRouted networks" do
|
227
227
|
@config[:edge_gateway] = 'test gateway'
|
228
228
|
mock_edgegw = Vcloud::Core::EdgeGateway.new(@edgegw_id)
|
229
|
-
Vcloud::Core::EdgeGateway.
|
229
|
+
allow(Vcloud::Core::EdgeGateway).to receive(:get_by_name).and_return(mock_edgegw)
|
230
230
|
|
231
231
|
expected_vcloud_attrs = {
|
232
232
|
:IsShared => false,
|
@@ -241,8 +241,8 @@ module Vcloud
|
|
241
241
|
},
|
242
242
|
:EdgeGateway => { :href => "/#{@edgegw_id}" },
|
243
243
|
}
|
244
|
-
Vcloud::Core.logger.
|
245
|
-
@mock_fog_interface.
|
244
|
+
expect(Vcloud::Core.logger).to receive(:info)
|
245
|
+
expect(@mock_fog_interface).to receive(:post_create_org_vdc_network).
|
246
246
|
with(@vdc_id, @config[:name], expected_vcloud_attrs).
|
247
247
|
and_return({ :href => "/#{@net_id}" })
|
248
248
|
Vcloud::Core::OrgVdcNetwork.provision(@config)
|
@@ -3,20 +3,20 @@ require 'spec_helper'
|
|
3
3
|
describe Vcloud::Core::QueryRunner do
|
4
4
|
before(:each) do
|
5
5
|
@mock_fog_interface = StubFogInterface.new
|
6
|
-
Vcloud::Fog::ServiceInterface.
|
6
|
+
allow(Vcloud::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
7
7
|
@query_runner = Vcloud::Core::QueryRunner.new()
|
8
8
|
end
|
9
9
|
|
10
10
|
context '#available_query_types' do
|
11
11
|
|
12
12
|
it 'should return empty array if no query type links are returned from API' do
|
13
|
-
@mock_fog_interface.
|
13
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return({:Link => {}})
|
14
14
|
result = @query_runner.available_query_types
|
15
15
|
expect(result.size).to eq(0)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'returns queriable entity types provided by the API via :href link elements' do
|
19
|
-
@mock_fog_interface.
|
19
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
20
20
|
{:Link => [
|
21
21
|
{:rel => 'down',
|
22
22
|
:href => 'query?type=alice&format=records'},
|
@@ -29,7 +29,7 @@ describe Vcloud::Core::QueryRunner do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should ignore query links with format=references and format=idrecords' do
|
32
|
-
@mock_fog_interface.
|
32
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
33
33
|
{:Link => [
|
34
34
|
{:rel => 'down',
|
35
35
|
:href => 'query?type=alice&format=references'},
|
@@ -51,12 +51,12 @@ describe Vcloud::Core::QueryRunner do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should return no results when fog returns no results' do
|
54
|
-
@mock_fog_interface.
|
54
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return({})
|
55
55
|
expect(@query_runner.run()).to eq([])
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'return no results when fog results do not include a "Record" or a "Reference"' do
|
59
|
-
@mock_fog_interface.
|
59
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
60
60
|
{
|
61
61
|
:WibbleBlob => {:field1 => 'Stuff 1'}
|
62
62
|
}
|
@@ -66,7 +66,7 @@ describe Vcloud::Core::QueryRunner do
|
|
66
66
|
|
67
67
|
it 'should return a single result when fog returns a single record' do
|
68
68
|
fields = {:field1 => 'Stuff 1'}
|
69
|
-
@mock_fog_interface.
|
69
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
70
70
|
{
|
71
71
|
:WibbleRecord => [fields]
|
72
72
|
}
|
@@ -78,7 +78,7 @@ describe Vcloud::Core::QueryRunner do
|
|
78
78
|
|
79
79
|
it 'should return a single result when fog returns a single reference' do
|
80
80
|
fields = {:field1 => 'Stuff 1'}
|
81
|
-
@mock_fog_interface.
|
81
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
82
82
|
{
|
83
83
|
:WibbleReference => [fields]
|
84
84
|
}
|
@@ -90,7 +90,7 @@ describe Vcloud::Core::QueryRunner do
|
|
90
90
|
|
91
91
|
it 'should wrap single result from fog in list' do
|
92
92
|
fields = {:field1 => 'Stuff 1'}
|
93
|
-
@mock_fog_interface.
|
93
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
94
94
|
{
|
95
95
|
:WibbleRecord => fields
|
96
96
|
}
|
@@ -103,7 +103,7 @@ describe Vcloud::Core::QueryRunner do
|
|
103
103
|
it 'should return all results in a record returned by fog' do
|
104
104
|
fields = {:field1 => 'Stuff 1'}
|
105
105
|
more_fields = {:field1 => 'More Stuff 1'}
|
106
|
-
@mock_fog_interface.
|
106
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
107
107
|
{
|
108
108
|
:WibbleRecord => [fields, more_fields]
|
109
109
|
}
|
@@ -117,7 +117,7 @@ describe Vcloud::Core::QueryRunner do
|
|
117
117
|
it 'should return the first item if more than one records provided' do
|
118
118
|
fields1 = {:field1 => 'Stuff 1'}
|
119
119
|
fields2 = {:field1 => 'Stuff 2'}
|
120
|
-
@mock_fog_interface.
|
120
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
121
121
|
{
|
122
122
|
:WibbleRecord => [fields1],
|
123
123
|
:WobbleRecord => [fields2]
|
@@ -129,7 +129,7 @@ describe Vcloud::Core::QueryRunner do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should raise error if lastPage is not an integer' do
|
132
|
-
@mock_fog_interface.
|
132
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
133
133
|
{
|
134
134
|
:lastPage => :qwerty,
|
135
135
|
:WibbleRecord => []
|
@@ -141,7 +141,7 @@ describe Vcloud::Core::QueryRunner do
|
|
141
141
|
|
142
142
|
it 'should get each page and collect the results' do
|
143
143
|
fields = {:field1 => 'Stuff 1'}
|
144
|
-
@mock_fog_interface.
|
144
|
+
allow(@mock_fog_interface).to receive(:get_execute_query).and_return(
|
145
145
|
{
|
146
146
|
:lastPage => 2,
|
147
147
|
:WibbleRecord => [fields]
|
@@ -11,8 +11,8 @@ describe Vcloud::Core::Query do
|
|
11
11
|
|
12
12
|
@query = Vcloud::Core::Query.new(nil, {}, query_runner)
|
13
13
|
|
14
|
-
@query.
|
15
|
-
@query.
|
14
|
+
expect(@query).to receive(:puts).with("alice")
|
15
|
+
expect(@query).to receive(:puts).with("bob")
|
16
16
|
|
17
17
|
@query.run
|
18
18
|
end
|
@@ -29,7 +29,7 @@ describe Vcloud::Core::Query do
|
|
29
29
|
it "should not output when given tsv output_format" do
|
30
30
|
query = Vcloud::Core::Query.new('bob', {:output_format => 'tsv'}, @query_runner)
|
31
31
|
|
32
|
-
query.
|
32
|
+
expect(query).not_to receive(:puts)
|
33
33
|
|
34
34
|
query.run()
|
35
35
|
end
|
@@ -37,7 +37,7 @@ describe Vcloud::Core::Query do
|
|
37
37
|
it "should not output when given csv output_format" do
|
38
38
|
query = Vcloud::Core::Query.new('bob', {:output_format => 'csv'}, @query_runner)
|
39
39
|
|
40
|
-
query.
|
40
|
+
expect(query).not_to receive(:puts)
|
41
41
|
|
42
42
|
query.run()
|
43
43
|
end
|
@@ -59,9 +59,9 @@ describe Vcloud::Core::Query do
|
|
59
59
|
it "should output a query in tsv when run with a type" do
|
60
60
|
@query = Vcloud::Core::Query.new('bob', {:output_format => 'tsv'}, @query_runner)
|
61
61
|
|
62
|
-
@query.
|
63
|
-
@query.
|
64
|
-
@query.
|
62
|
+
expect(@query).to receive(:puts).with("field1\tfield2")
|
63
|
+
expect(@query).to receive(:puts).with("Stuff 1\tStuff 2")
|
64
|
+
expect(@query).to receive(:puts).with("More Stuff 1\tMore Stuff 2")
|
65
65
|
|
66
66
|
@query.run()
|
67
67
|
end
|
@@ -69,8 +69,8 @@ describe Vcloud::Core::Query do
|
|
69
69
|
it "should output a query in csv when run with a type" do
|
70
70
|
@query = Vcloud::Core::Query.new('bob', {:output_format => 'csv'}, @query_runner)
|
71
71
|
|
72
|
-
@query.
|
73
|
-
@query.
|
72
|
+
expect(@query).to receive(:puts).with("field1,field2\n")
|
73
|
+
expect(@query).to receive(:puts).with("Stuff 1,Stuff 2\nMore Stuff 1,More Stuff 2\n")
|
74
74
|
|
75
75
|
@query.run()
|
76
76
|
end
|
@@ -6,13 +6,13 @@ module Vcloud
|
|
6
6
|
before(:each) do
|
7
7
|
@vapp_id = 'vapp-12345678-1234-1234-1234-000000111111'
|
8
8
|
@mock_fog_interface = StubFogInterface.new
|
9
|
-
Vcloud::Fog::ServiceInterface.
|
9
|
+
allow(Vcloud::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
10
10
|
end
|
11
11
|
|
12
12
|
context "Class public interface" do
|
13
|
-
it { Vapp.
|
14
|
-
it { Vapp.
|
15
|
-
it { Vapp.
|
13
|
+
it { expect(Vapp).to respond_to(:instantiate) }
|
14
|
+
it { expect(Vapp).to respond_to(:get_by_name) }
|
15
|
+
it { expect(Vapp).to respond_to(:get_metadata) }
|
16
16
|
end
|
17
17
|
|
18
18
|
context "Instance public interface" do
|
@@ -53,8 +53,8 @@ module Vcloud
|
|
53
53
|
{ :name => 'vapp-test-1', :href => @vapp_id }
|
54
54
|
]
|
55
55
|
mock_query = double(:query)
|
56
|
-
Vcloud::Core::QueryRunner.
|
57
|
-
mock_query.
|
56
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
57
|
+
expect(mock_query).to receive(:run).with('vApp', :filter => "name==vapp-test-1").and_return(q_results)
|
58
58
|
obj = Vapp.get_by_name('vapp-test-1')
|
59
59
|
expect(obj.class).to be(Vcloud::Core::Vapp)
|
60
60
|
end
|
@@ -62,8 +62,8 @@ module Vcloud
|
|
62
62
|
it "should raise an error if no vApp with that name exists" do
|
63
63
|
q_results = [ ]
|
64
64
|
mock_query = double(:query_runner)
|
65
|
-
Vcloud::Core::QueryRunner.
|
66
|
-
mock_query.
|
65
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
66
|
+
expect(mock_query).to receive(:run).with('vApp', :filter => "name==vapp-test-1").and_return(q_results)
|
67
67
|
expect{ Vapp.get_by_name('vapp-test-1') }.to raise_exception(RuntimeError)
|
68
68
|
end
|
69
69
|
|
@@ -73,8 +73,8 @@ module Vcloud
|
|
73
73
|
{ :name => 'vapp-test-1', :href => '/bogus' },
|
74
74
|
]
|
75
75
|
mock_query = double(:query)
|
76
|
-
Vcloud::Core::QueryRunner.
|
77
|
-
mock_query.
|
76
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
77
|
+
expect(mock_query).to receive(:run).with('vApp', :filter => "name==vapp-test-1").and_return(q_results)
|
78
78
|
expect{ Vapp.get_by_name('vapp-test-1') }.to raise_exception(RuntimeError)
|
79
79
|
end
|
80
80
|
|
@@ -92,10 +92,10 @@ module Vcloud
|
|
92
92
|
}],
|
93
93
|
:Children => {:Vm => [{:href => '/vm-123aea1e-a5e9-4dd1-a028-40db8c98d237'}]}
|
94
94
|
}
|
95
|
-
StubFogInterface.
|
95
|
+
allow_any_instance_of(StubFogInterface).to receive(:get_vapp).and_return(@stub_attrs)
|
96
96
|
@vapp = Vapp.new(@vapp_id)
|
97
97
|
}
|
98
|
-
it { @vapp.name.
|
98
|
+
it { expect(@vapp.name).to eq('Webserver vapp-1') }
|
99
99
|
|
100
100
|
context "id" do
|
101
101
|
it "should extract id correctly" do
|
@@ -110,7 +110,7 @@ module Vcloud
|
|
110
110
|
|
111
111
|
it "should raise error if vapp without parent vdc found" do
|
112
112
|
@stub_attrs[:Link] = []
|
113
|
-
|
113
|
+
expect { @vapp.vdc_id }.to raise_error('a vapp without parent vdc found')
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -136,21 +136,21 @@ module Vcloud
|
|
136
136
|
|
137
137
|
it "should power on a vapp that is not powered on" do
|
138
138
|
vapp = Vapp.new(@vapp_id)
|
139
|
-
@mock_fog_interface.
|
139
|
+
expect(@mock_fog_interface).to receive(:get_vapp).twice().and_return(
|
140
140
|
{:status => Vcloud::Core::Vapp::STATUS::POWERED_OFF},
|
141
141
|
{:status => Vcloud::Core::Vapp::STATUS::RUNNING}
|
142
142
|
)
|
143
|
-
@mock_fog_interface.
|
143
|
+
expect(@mock_fog_interface).to receive(:power_on_vapp).with(vapp.id)
|
144
144
|
state = vapp.power_on
|
145
145
|
expect(state).to be_true
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should not power on a vapp that is already powered on, but should return true" do
|
149
149
|
vapp = Vapp.new(@vapp_id)
|
150
|
-
@mock_fog_interface.
|
150
|
+
expect(@mock_fog_interface).to receive(:get_vapp).and_return(
|
151
151
|
{:status => Vcloud::Core::Vapp::STATUS::RUNNING}
|
152
152
|
)
|
153
|
-
@mock_fog_interface.
|
153
|
+
expect(@mock_fog_interface).not_to receive(:power_on_vapp)
|
154
154
|
state = vapp.power_on
|
155
155
|
expect(state).to be_true
|
156
156
|
end
|
@@ -161,14 +161,14 @@ module Vcloud
|
|
161
161
|
context "#get_by_name_and_vdc_name" do
|
162
162
|
|
163
163
|
it "should return nil if fog returns nil" do
|
164
|
-
StubFogInterface.
|
164
|
+
allow_any_instance_of(StubFogInterface).to receive(:get_vapp_by_name_and_vdc_name)
|
165
165
|
.with('vapp_name', 'vdc_name').and_return(nil)
|
166
166
|
expect(Vapp.get_by_name_and_vdc_name('vapp_name', 'vdc_name')).to be_nil
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should return vapp instance if found" do
|
170
170
|
vcloud_attr_vapp = { :href => "/#{@vapp_id}" }
|
171
|
-
StubFogInterface.
|
171
|
+
allow_any_instance_of(StubFogInterface).to receive(:get_vapp_by_name_and_vdc_name)
|
172
172
|
.with('vapp_name', 'vdc_name').and_return(vcloud_attr_vapp)
|
173
173
|
expect(Vapp.get_by_name_and_vdc_name('vapp_name', 'vdc_name').class).to eq(Core::Vapp)
|
174
174
|
end
|