vcloud-core 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +56 -2
- data/Rakefile +2 -2
- data/bin/vcloud-query +0 -4
- data/jenkins.sh +1 -0
- data/jenkins_integration_tests.sh +4 -0
- data/lib/vcloud/core/query.rb +2 -23
- data/lib/vcloud/core/query_runner.rb +22 -7
- data/lib/vcloud/core/version.rb +1 -1
- data/lib/vcloud/core/vm.rb +1 -2
- data/spec/integration/edge_gateway/configure_edge_gateway_services_spec.rb +14 -0
- data/spec/integration/edge_gateway/edge_gateway_spec.rb +16 -0
- data/spec/integration/query/query_runner_spec.rb +225 -0
- data/spec/vcloud/core/query_runner_spec.rb +21 -17
- data/spec/vcloud/core/query_spec.rb +4 -10
- data/tools/fog_credentials.rb +17 -0
- metadata +7 -3
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,44 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install vcloud-core
|
20
20
|
|
21
|
+
## Credentials
|
22
|
+
|
23
|
+
vCloud Core is based around [fog](http://fog.io/). To use it you'll need to give it
|
24
|
+
credentials that allow it to talk to a vCloud Director environment.
|
25
|
+
|
26
|
+
1. Create a '.fog' file in your home directory.
|
27
|
+
|
28
|
+
For example:
|
29
|
+
|
30
|
+
test_credentials:
|
31
|
+
vcloud_director_host: 'host.api.example.com'
|
32
|
+
vcloud_director_username: 'username@org_name'
|
33
|
+
vcloud_director_password: ''
|
34
|
+
|
35
|
+
2. Obtain a session token. First, curl the API:
|
36
|
+
|
37
|
+
curl -D- -d '' \
|
38
|
+
-H 'Accept: application/*+xml;version=5.1' -u '<username>@<org_name>' \
|
39
|
+
https://<host.api.example.com>/api/sessions
|
40
|
+
|
41
|
+
This will prompt for your password.
|
42
|
+
|
43
|
+
From the headers returned, the value of the `x-vcloud-authorization` header is your
|
44
|
+
session token, and this will be valid for 30 minutes idle - any activity will extend
|
45
|
+
its life by another 30 minutes.
|
46
|
+
|
47
|
+
3. Specify your credentials and session token at the beginning of the command. For example:
|
48
|
+
|
49
|
+
FOG_CREDENTIAL=test_credentials \
|
50
|
+
FOG_VCLOUD_TOKEN=AAAABBBBBCCCCCCDDDDDDEEEEEEFFFFF= \
|
51
|
+
vcloud-query
|
52
|
+
|
53
|
+
You may find it easier to export one or both of the values as environment variables.
|
54
|
+
|
55
|
+
**NB** It is also possible to sidestep the need for the session token by saving your
|
56
|
+
password in the fog file. This is **not recommended**.
|
57
|
+
|
58
|
+
|
21
59
|
## VCloud Query
|
22
60
|
|
23
61
|
### Get results from the vCloud Query API
|
@@ -49,7 +87,7 @@ NB: examples assume FOG_CREDENTIAL or FOG_VCLOUD_TOKEN has been set accordingly.
|
|
49
87
|
# Get general usage info
|
50
88
|
vcloud-query --help
|
51
89
|
|
52
|
-
# Get a list of all queriable types
|
90
|
+
# Get a list of all queriable entity types
|
53
91
|
vcloud-query
|
54
92
|
|
55
93
|
# Get all VMs with VMware Tools less than 9282, that are not a vApp Template:
|
@@ -89,13 +127,29 @@ Entity metadata queries have their own subsyntax incorporating the value types:
|
|
89
127
|
|
90
128
|
See http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.doc_51/GUID-4FD71B6D-6797-4B8E-B9F0-618F4ACBEFAC.html for details.
|
91
129
|
|
130
|
+
## The vCloud API
|
131
|
+
|
132
|
+
vCloud Tools currently use version 5.1 of the [vCloud API](http://pubs.vmware.com/vcd-51/index.jsp?topic=%2Fcom.vmware.vcloud.api.doc_51%2FGUID-F4BF9D5D-EF66-4D36-A6EB-2086703F6E37.html). Version 5.5 may work but is not currently supported. You should be able to access the 5.1 API in a 5.5 environment, and this *is* currently supported.
|
133
|
+
|
134
|
+
The default version is defined in [Fog](https://github.com/fog/fog/blob/244a049918604eadbcebd3a8eaaf433424fe4617/lib/fog/vcloud_director/compute.rb#L32).
|
135
|
+
|
136
|
+
If you want to be sure you are pinning to 5.1, or use 5.5, you can set the API version to use in your fog file, e.g.
|
137
|
+
|
138
|
+
`vcloud_director_api_version: 5.1`
|
139
|
+
|
140
|
+
## Debugging
|
141
|
+
|
142
|
+
`export EXCON_DEBUG=true` - this will print out the API requests and responses.
|
143
|
+
|
144
|
+
`export DEBUG=true` - this will show you the stack trace when there is an exception instead of just the message.
|
145
|
+
|
92
146
|
## Testing
|
93
147
|
|
94
148
|
Default target: `bundle exec rake`
|
95
149
|
Runs the unit tests and feature tests.
|
96
150
|
|
97
151
|
* Unit tests only: `bundle exec rake spec`
|
98
|
-
* Feature tests only: `bundle exec rake
|
152
|
+
* Feature tests only: `bundle exec rake features`
|
99
153
|
* Integration tests: `bundle exec rake integration`
|
100
154
|
|
101
155
|
### setting up and describing your environment for test runs
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rspec/core/rake_task'
|
2
2
|
require 'cucumber/rake/task'
|
3
3
|
|
4
|
-
task :default => [:spec, :
|
4
|
+
task :default => [:spec, :features]
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
7
|
# Set a bogus Fog credential, otherwise it's possible for the unit
|
@@ -12,7 +12,7 @@ RSpec::Core::RakeTask.new(:spec) do |task|
|
|
12
12
|
task.pattern = FileList['spec/vcloud/**/*_spec.rb']
|
13
13
|
end
|
14
14
|
|
15
|
-
Cucumber::Rake::Task.new(:
|
15
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
16
16
|
t.cucumber_opts = "--format pretty --no-source"
|
17
17
|
t.fork = false
|
18
18
|
end
|
data/bin/vcloud-query
CHANGED
@@ -29,10 +29,6 @@ class App
|
|
29
29
|
options[:fields] = v
|
30
30
|
end
|
31
31
|
|
32
|
-
on('--format', '=ATTRIBUTE', 'Data format to retrieve: records, idrecords, references') do |v|
|
33
|
-
options[:format] = v
|
34
|
-
end
|
35
|
-
|
36
32
|
on('--filter', '=FILTER', 'Filter expression') do |v|
|
37
33
|
options[:filter] = v
|
38
34
|
end
|
data/jenkins.sh
CHANGED
data/lib/vcloud/core/query.rb
CHANGED
@@ -32,32 +32,11 @@ module Vcloud
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def output_available_query_types
|
35
|
-
|
36
|
-
|
37
|
-
print_query_types(available_queries)
|
38
|
-
end
|
39
|
-
|
40
|
-
def collate_formats_for_types(available_queries)
|
41
|
-
queries = Hash.new { |h, k| h[k]=[] }
|
42
|
-
available_queries.each do |type, format|
|
43
|
-
queries[type] << format
|
44
|
-
end
|
45
|
-
queries
|
46
|
-
end
|
47
|
-
|
48
|
-
def print_query_types(queries)
|
49
|
-
type_width = longest_query_type(queries)
|
50
|
-
|
51
|
-
queries.keys.sort.each do |type|
|
52
|
-
puts "%-#{type_width}s %s" % [type, queries[type].sort.join(',')]
|
35
|
+
@query_runner.available_query_types.each do |entity_type|
|
36
|
+
puts entity_type
|
53
37
|
end
|
54
38
|
end
|
55
39
|
|
56
|
-
def longest_query_type(queries)
|
57
|
-
return 0 if queries.keys.empty?
|
58
|
-
queries.keys.max_by{|key| key.length}.length
|
59
|
-
end
|
60
|
-
|
61
40
|
def output_header(results)
|
62
41
|
return if results.size == 0
|
63
42
|
case @options[:output_format]
|
@@ -6,21 +6,36 @@ module Vcloud
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def run(type=nil, options={})
|
9
|
+
raise ArgumentError, "Query API :format option is not supported" if options[:format]
|
9
10
|
get_all_results(type, options)
|
10
11
|
end
|
11
12
|
|
12
13
|
def available_query_types
|
13
|
-
|
14
|
-
|
14
|
+
query_body = @fsi.get_execute_query()
|
15
|
+
get_entity_types_in_record_format(query_body)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_entity_types_in_record_format(query_body)
|
21
|
+
query_links = query_body.fetch(:Link).select do |link|
|
15
22
|
link[:rel] == 'down'
|
16
|
-
end.map do |link|
|
17
|
-
href = Nokogiri::XML.fragment(link[:href])
|
18
|
-
query = CGI.parse(URI.parse(href.text).query)
|
19
|
-
[query['type'].first, query['format'].first]
|
20
23
|
end
|
24
|
+
entity_types = []
|
25
|
+
query_links.each do |link|
|
26
|
+
(entity_type, query_format) = extract_query_type_and_format_from_link(link)
|
27
|
+
entity_types << entity_type if query_format == 'records'
|
28
|
+
end
|
29
|
+
entity_types
|
21
30
|
end
|
22
31
|
|
23
|
-
|
32
|
+
def extract_query_type_and_format_from_link(link)
|
33
|
+
href = Nokogiri::XML.fragment(link[:href])
|
34
|
+
query = CGI.parse(URI.parse(href.text).query)
|
35
|
+
query_format = query['format'].first
|
36
|
+
query_type = query['type'].first
|
37
|
+
[query_type, query_format]
|
38
|
+
end
|
24
39
|
|
25
40
|
def get_all_results(type, options)
|
26
41
|
results = []
|
data/lib/vcloud/core/version.rb
CHANGED
data/lib/vcloud/core/vm.rb
CHANGED
@@ -114,8 +114,7 @@ module Vcloud
|
|
114
114
|
|
115
115
|
def generate_preamble(script_path, script_post_processor, vars)
|
116
116
|
vapp_name = @vapp.name
|
117
|
-
script = ERB.new(File.read(File.expand_path(script_path)), nil, '>-')
|
118
|
-
.result(binding)
|
117
|
+
script = ERB.new(File.read(File.expand_path(script_path)), nil, '>-').result(binding)
|
119
118
|
if script_post_processor
|
120
119
|
script = Open3.capture2(File.expand_path(script_post_processor),
|
121
120
|
stdin_data: script).first
|
@@ -3,6 +3,20 @@ require 'spec_helper'
|
|
3
3
|
module Vcloud
|
4
4
|
module Core
|
5
5
|
describe EdgeGateway do
|
6
|
+
|
7
|
+
required_env = {
|
8
|
+
'VCLOUD_EDGE_GATEWAY' => 'to name of VSE',
|
9
|
+
}
|
10
|
+
|
11
|
+
error = false
|
12
|
+
required_env.each do |var,message|
|
13
|
+
unless ENV[var]
|
14
|
+
puts "Must set #{var} #{message}" unless ENV[var]
|
15
|
+
error = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
Kernel.exit(2) if error
|
19
|
+
|
6
20
|
it "configure firewall service" do
|
7
21
|
configuration = {
|
8
22
|
:FirewallService =>
|
@@ -3,6 +3,22 @@ require 'spec_helper'
|
|
3
3
|
module Vcloud
|
4
4
|
module Core
|
5
5
|
describe EdgeGateway do
|
6
|
+
|
7
|
+
required_env = {
|
8
|
+
'VCLOUD_EDGE_GATEWAY' => 'to name of VSE',
|
9
|
+
'VCLOUD_PROVIDER_NETWORK_ID' => 'to ID of VSE external network',
|
10
|
+
'VCLOUD_NETWORK1_ID' => 'to the ID of a VSE internal network',
|
11
|
+
}
|
12
|
+
|
13
|
+
error = false
|
14
|
+
required_env.each do |var,message|
|
15
|
+
unless ENV[var]
|
16
|
+
puts "Must set #{var} #{message}" unless ENV[var]
|
17
|
+
error = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
Kernel.exit(2) if error
|
21
|
+
|
6
22
|
context "get vcloud attributes for given gateway interface id " do
|
7
23
|
before(:all) do
|
8
24
|
@edge_gateway = EdgeGateway.get_by_name(ENV['VCLOUD_EDGE_GATEWAY'])
|
@@ -0,0 +1,225 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Vcloud
|
4
|
+
module Core
|
5
|
+
describe QueryRunner do
|
6
|
+
|
7
|
+
required_env = {
|
8
|
+
'VCLOUD_VDC_NAME' =>
|
9
|
+
'to the name of an orgVdc to use to instantiate vApps into',
|
10
|
+
'VCLOUD_TEMPLATE_NAME' =>
|
11
|
+
'to the name of a vAppTemplate to use create vApps in tests',
|
12
|
+
'VCLOUD_CATALOG_NAME' =>
|
13
|
+
'to the name of the catalog that VCLOUD_VAPP_TEMPLATE_NAME is stored in',
|
14
|
+
}
|
15
|
+
|
16
|
+
error = false
|
17
|
+
required_env.each do |var,message|
|
18
|
+
unless ENV[var]
|
19
|
+
puts "Must set #{var} #{message}" unless ENV[var]
|
20
|
+
error = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
Kernel.exit(2) if error
|
24
|
+
|
25
|
+
before(:all) do
|
26
|
+
@vapp_template_name = ENV['VCLOUD_TEMPLATE_NAME']
|
27
|
+
@vapp_template_catalog_name = ENV['VCLOUD_CATALOG_NAME']
|
28
|
+
@vdc_name = ENV['VCLOUD_VDC_NAME']
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#available_query_types" do
|
32
|
+
|
33
|
+
before(:all) do
|
34
|
+
@query_types = QueryRunner.new.available_query_types
|
35
|
+
end
|
36
|
+
|
37
|
+
context "confirm accessing the query API is functional" do
|
38
|
+
|
39
|
+
it "returns an Array of available query types" do
|
40
|
+
expect(@query_types.class).to eq(Array)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns at least one query type" do
|
44
|
+
expect(@query_types.size).to be >= 1
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "it supports all the vCloud entity types our tools need" do
|
50
|
+
|
51
|
+
it "supports the vApp entity type" do
|
52
|
+
expect(@query_types.include?("vApp")).to be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "supports the vm entity type" do
|
56
|
+
expect(@query_types.include?("vm")).to be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "supports the orgVdc entity type" do
|
60
|
+
expect(@query_types.include?("orgVdc")).to be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "supports the orgVdcNetwork entity type" do
|
64
|
+
expect(@query_types.include?("orgVdcNetwork")).to be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "supports the edgeGateway entity type" do
|
68
|
+
expect(@query_types.include?("edgeGateway")).to be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "supports the task entity type" do
|
72
|
+
expect(@query_types.include?("task")).to be_true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "supports the catalog entity type" do
|
76
|
+
expect(@query_types.include?("catalog")).to be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "supports the catalogItem entity type" do
|
80
|
+
expect(@query_types.include?("catalogItem")).to be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "supports the vAppTemplate entity type" do
|
84
|
+
expect(@query_types.include?("vAppTemplate")).to be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
context "#run" do
|
92
|
+
|
93
|
+
before(:all) do
|
94
|
+
@number_of_vapps_to_create = 2
|
95
|
+
@test_case_vapps = create_test_case_vapps(
|
96
|
+
@number_of_vapps_to_create,
|
97
|
+
@vdc_name,
|
98
|
+
@vapp_template_catalog_name,
|
99
|
+
@vapp_template_name,
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
context "vApps are queriable with no options specified" do
|
104
|
+
|
105
|
+
before(:all) do
|
106
|
+
@all_vapps = QueryRunner.new.run('vApp')
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns an Array" do
|
110
|
+
expect(@all_vapps.class).to eq(Array)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns at least the number of vApps that we created" do
|
114
|
+
expect(@all_vapps.size).to be >= @number_of_vapps_to_create
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns a record with a defined :name field" do
|
118
|
+
expect(@all_vapps.first[:name]).not_to be_empty
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns a record with a defined :href field" do
|
122
|
+
expect(@all_vapps.first[:href]).not_to be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns a record with a defined :vdcName field" do
|
126
|
+
expect(@all_vapps.first[:vdcName]).not_to be_empty
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns a record with a defined :status field" do
|
130
|
+
expect(@all_vapps.first[:status]).not_to be_empty
|
131
|
+
end
|
132
|
+
|
133
|
+
it "does not return a 'bogusElement' element" do
|
134
|
+
expect(@all_vapps.first.key?(:bogusElement)).to be false
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
context "Query output fields can be limited by supplying a comma-separated :fields list" do
|
140
|
+
|
141
|
+
before(:all) do
|
142
|
+
@results = QueryRunner.new.run('vApp', fields: "name,vdcName")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "returns a record with a defined name element" do
|
146
|
+
expect(@results.first[:name]).not_to be_empty
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns a record with a defined vdcName element" do
|
150
|
+
expect(@results.first[:vdcName]).not_to be_empty
|
151
|
+
end
|
152
|
+
|
153
|
+
it "does not return a 'status' record, which we know is available for our vApp type" do
|
154
|
+
expect(@results.first.key?(:status)).to be false
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "Query API does not support an empty :fields list" do
|
160
|
+
|
161
|
+
it "raises a BadRequest exception, if empty string is supplied for :fields" do
|
162
|
+
expect { QueryRunner.new.run('vApp', fields: "") }.
|
163
|
+
to raise_exception(::Fog::Compute::VcloudDirector::BadRequest)
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
context "Query API returns href field regardless of filter :fields selected" do
|
169
|
+
|
170
|
+
it "returns href as well as name, if just 'name' is asked for" do
|
171
|
+
results = QueryRunner.new.run('vApp', fields: "name")
|
172
|
+
expect(results.first.keys.sort).to eq([:href, :name])
|
173
|
+
end
|
174
|
+
|
175
|
+
it "returns href, name, vdcName if 'name,vdcName' is asked for" do
|
176
|
+
results = QueryRunner.new.run('vApp', fields: "name,vdcName")
|
177
|
+
expect(results.first.keys.sort).to eq([:href, :name, :vdcName])
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
context "query output can be restricted by a filter expression on name" do
|
183
|
+
|
184
|
+
before(:all) do
|
185
|
+
@vapp_name = @test_case_vapps.last.name
|
186
|
+
@filtered_results = QueryRunner.new.run('vApp', filter: "name==#{@vapp_name}")
|
187
|
+
end
|
188
|
+
|
189
|
+
it "returns a single record matching our filter on name" do
|
190
|
+
expect(@filtered_results.size).to be(1)
|
191
|
+
expect(@filtered_results.first.fetch(:name)).to eq(@vapp_name)
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
after(:all) do
|
197
|
+
fsi = Vcloud::Fog::ServiceInterface.new()
|
198
|
+
@test_case_vapps.each do |vapp|
|
199
|
+
fsi.delete_vapp(vapp.id)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def create_test_case_vapps(quantity, vdc_name, catalog_name, vapp_template_name)
|
204
|
+
vapp_template = VappTemplate.get(catalog_name, vapp_template_name)
|
205
|
+
timestamp_in_s = Time.new.to_i
|
206
|
+
base_vapp_name = "vcloud-core-query-tests-#{timestamp_in_s}-"
|
207
|
+
network_names = []
|
208
|
+
vapp_list = []
|
209
|
+
quantity.times do |index|
|
210
|
+
vapp_list << Vapp.instantiate(
|
211
|
+
base_vapp_name + index.to_s,
|
212
|
+
network_names,
|
213
|
+
vapp_template.id,
|
214
|
+
vdc_name
|
215
|
+
)
|
216
|
+
end
|
217
|
+
vapp_list
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
@@ -8,44 +8,48 @@ describe Vcloud::QueryRunner do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
context '#available_query_types' do
|
11
|
-
it 'should return empty array if no data' do
|
12
|
-
@mock_fog_interface.stub(:get_execute_query).and_return({:Link => {}})
|
13
11
|
|
12
|
+
it 'should return empty array if no query type links are returned from API' do
|
13
|
+
@mock_fog_interface.stub(:get_execute_query).and_return({:Link => {}})
|
14
14
|
result = @query_runner.available_query_types
|
15
|
-
|
16
15
|
result.size.should == 0
|
17
16
|
end
|
18
17
|
|
19
|
-
it 'should parse the query types
|
18
|
+
it 'should parse the format=records query hrefs into a list of entity types' do
|
20
19
|
@mock_fog_interface.stub(:get_execute_query).and_return(
|
21
20
|
{:Link => [
|
22
21
|
{:rel => 'down',
|
23
|
-
:href => 'query?type=alice&format=
|
22
|
+
:href => 'query?type=alice&format=records'},
|
23
|
+
{:rel => 'down',
|
24
|
+
:href => 'query?type=bob&format=records'},
|
25
|
+
{:rel => 'down',
|
26
|
+
:href => 'query?type=charlie&format=records'},
|
24
27
|
]})
|
25
|
-
|
26
|
-
result = @query_runner.available_query_types
|
27
|
-
|
28
|
-
result.size.should == 1
|
29
|
-
result[0][0].should == 'alice'
|
30
|
-
result[0][1].should == 'references'
|
28
|
+
expect(@query_runner.available_query_types).to eq(['alice', 'bob', 'charlie'])
|
31
29
|
end
|
32
30
|
|
33
|
-
it 'should
|
31
|
+
it 'should ignore query links with format=references and format=idrecords' do
|
34
32
|
@mock_fog_interface.stub(:get_execute_query).and_return(
|
35
33
|
{:Link => [
|
36
34
|
{:rel => 'down',
|
37
35
|
:href => 'query?type=alice&format=references'},
|
38
36
|
{:rel => 'down',
|
39
|
-
:href => 'query?type=bob&format=
|
37
|
+
:href => 'query?type=bob&format=idrecords'},
|
38
|
+
{:rel => 'down',
|
39
|
+
:href => 'query?type=charlie&format=records'},
|
40
40
|
]})
|
41
|
-
|
42
|
-
result = @query_runner.available_query_types
|
43
|
-
|
44
|
-
result.size.should == 2
|
41
|
+
expect(@query_runner.available_query_types).to eq(['charlie'])
|
45
42
|
end
|
43
|
+
|
46
44
|
end
|
47
45
|
|
48
46
|
context '#run' do
|
47
|
+
|
48
|
+
it "should raise an error if a :format option is supplied" do
|
49
|
+
expect { @query_runner.run('vApp', :format => 'references') }.
|
50
|
+
to raise_error(ArgumentError, "Query API :format option is not supported")
|
51
|
+
end
|
52
|
+
|
49
53
|
it 'should return no results when fog returns no results' do
|
50
54
|
@mock_fog_interface.stub(:get_execute_query).and_return({})
|
51
55
|
|
@@ -5,20 +5,14 @@ describe Vcloud::Query do
|
|
5
5
|
|
6
6
|
context "#run called with no type set on construction" do
|
7
7
|
|
8
|
-
it "should
|
8
|
+
it "should output all types that are available" do
|
9
9
|
query_runner = double(Vcloud::QueryRunner)
|
10
|
-
allow(query_runner).to receive(:available_query_types) {
|
11
|
-
[
|
12
|
-
['alice', 'references'],
|
13
|
-
['alice', 'records'],
|
14
|
-
['bob', 'records']
|
15
|
-
]
|
16
|
-
}
|
10
|
+
allow(query_runner).to receive(:available_query_types) { [ 'alice', 'bob' ] }
|
17
11
|
|
18
12
|
@query = Vcloud::Query.new(nil, {}, query_runner)
|
19
13
|
|
20
|
-
@query.should_receive(:puts).with("alice
|
21
|
-
@query.should_receive(:puts).with("bob
|
14
|
+
@query.should_receive(:puts).with("alice")
|
15
|
+
@query.should_receive(:puts).with("bob")
|
22
16
|
|
23
17
|
@query.run
|
24
18
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Initialiser for getting vCloud credentials into Fog from Jenkins build
|
2
|
+
# parameters, without needing to write them to disk. To be used with:
|
3
|
+
#
|
4
|
+
# RUBYOPT="-r ./tools/fog_credentials" bundle exec integration
|
5
|
+
#
|
6
|
+
# Replace with FOG_VCLOUD_TOKEN support when we have a tool:
|
7
|
+
#
|
8
|
+
# https://www.pivotaltracker.com/story/show/68989754
|
9
|
+
#
|
10
|
+
require 'bundler/setup'
|
11
|
+
require 'fog'
|
12
|
+
|
13
|
+
Fog.credentials = {
|
14
|
+
:vcloud_director_host => ENV['API_HOST'],
|
15
|
+
:vcloud_director_username => ENV['API_USERNAME'],
|
16
|
+
:vcloud_director_password => ENV['API_PASSWORD'],
|
17
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcloud-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- features/support/env.rb
|
159
159
|
- features/vcloud-query.feature
|
160
160
|
- jenkins.sh
|
161
|
+
- jenkins_integration_tests.sh
|
161
162
|
- lib/vcloud/core.rb
|
162
163
|
- lib/vcloud/core/compute_metadata.rb
|
163
164
|
- lib/vcloud/core/config_loader.rb
|
@@ -181,6 +182,7 @@ files:
|
|
181
182
|
- lib/vcloud/fog/service_interface.rb
|
182
183
|
- spec/integration/edge_gateway/configure_edge_gateway_services_spec.rb
|
183
184
|
- spec/integration/edge_gateway/edge_gateway_spec.rb
|
185
|
+
- spec/integration/query/query_runner_spec.rb
|
184
186
|
- spec/spec_helper.rb
|
185
187
|
- spec/support/stub_fog_interface.rb
|
186
188
|
- spec/vcloud/core/config_loader_spec.rb
|
@@ -202,6 +204,7 @@ files:
|
|
202
204
|
- spec/vcloud/core/vm_spec.rb
|
203
205
|
- spec/vcloud/fog/fog_model_interface_spec.rb
|
204
206
|
- spec/vcloud/fog/service_interface_spec.rb
|
207
|
+
- tools/fog_credentials.rb
|
205
208
|
- vcloud-core.gemspec
|
206
209
|
homepage: http://github.com/alphagov/vcloud-core
|
207
210
|
licenses:
|
@@ -224,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
227
|
version: '0'
|
225
228
|
segments:
|
226
229
|
- 0
|
227
|
-
hash:
|
230
|
+
hash: 4282482764039593007
|
228
231
|
requirements: []
|
229
232
|
rubyforge_project:
|
230
233
|
rubygems_version: 1.8.23
|
@@ -236,6 +239,7 @@ test_files:
|
|
236
239
|
- features/vcloud-query.feature
|
237
240
|
- spec/integration/edge_gateway/configure_edge_gateway_services_spec.rb
|
238
241
|
- spec/integration/edge_gateway/edge_gateway_spec.rb
|
242
|
+
- spec/integration/query/query_runner_spec.rb
|
239
243
|
- spec/spec_helper.rb
|
240
244
|
- spec/support/stub_fog_interface.rb
|
241
245
|
- spec/vcloud/core/config_loader_spec.rb
|