abiquo-etk 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Fetching resource collections" do
4
+
5
+ scenario "Fetch collection" do
6
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters").to_return(:body => <<-XML)
7
+ <datacenters>
8
+ <datacenter>
9
+ <link rel='edit' href='http://abiquo.example.com/api/admin/datacenters/1'/>
10
+ <name>Resource 1</name>
11
+ </datacenter>
12
+ <datacenter>
13
+ <link rel='edit' href='http://abiquo.example.com/api/admin/datacenters/2'/>
14
+ <name>Resource 2</name>
15
+ </datacenter>
16
+ </datacenters>
17
+ XML
18
+
19
+ resources = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters", auth)
20
+
21
+ resources.map(&:name).should == ["Resource 1", "Resource 2"]
22
+ resources.size.should == 2
23
+ resources.first.name.should == "Resource 1"
24
+ resources.last.name.should == "Resource 2"
25
+ end
26
+
27
+ scenario "Inspecting a collection" do
28
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters").to_return(:body => %q{
29
+ <datacenters><datacenter><name>Resource 1</name></datacenter></datacenters>
30
+ })
31
+
32
+ resources = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters", auth)
33
+
34
+ resources.inspect.should == "[#{resources.first.inspect}]"
35
+ end
36
+
37
+ scenario 'Fetch service document' do
38
+ stub_auth_request(:get, 'http://admin:admin@abiquo.example.com/api').to_return(:body => <<-XML)
39
+ <ns2:service xmlns="http://www.w3.org/2005/Atom" xmlns:ns2="http://www.w3.org/2007/app" xmlns:ns3="http://a9.com/-/spec/opensearch/1.1/" xmlns:ns4="http://www.w3.org/1999/xhtml">
40
+ <ns2:workspace>
41
+ <title>Abiquo administration workspace</title>
42
+ <ns2:collection href="http://localhost:8080/api/admin/datacenters">
43
+ <title>Datacenters</title>
44
+ <ns2:accept/>
45
+ </ns2:collection>
46
+ </ns2:workspace>
47
+ </ns2:service>
48
+ XML
49
+
50
+ resources = Abiquo::Resource('http://abiquo.example.com/api', auth)
51
+
52
+ lambda { resources.datacenters }.should_not raise_error
53
+ end
54
+
55
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ feature "Fetching individual resources" do
4
+
5
+ scenario "Fetching untyped attributes" do
6
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").to_return(:body => <<-XML)
7
+ <datacenter>
8
+ <name>Resource Name</name>
9
+ <id>12345</id>
10
+ </datacenter>
11
+ XML
12
+
13
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
14
+ datacenter.name.should == "Resource Name"
15
+ datacenter.id.should == "12345"
16
+
17
+ expect { datacenter.wadus }.to raise_error(NoMethodError)
18
+ end
19
+
20
+ scenario "Fetching typed attributes" do
21
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").to_return(:body => <<-XML)
22
+ <datacenter>
23
+ <id>12345</id>
24
+ <name>Resource Name</name>
25
+ </datacenter>
26
+ XML
27
+
28
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
29
+
30
+ datacenter.id.should == "12345"
31
+ end
32
+
33
+ scenario "Inspecting a resource" do
34
+ xml = %q{
35
+ <datacenter>
36
+ <id>12345</id>
37
+ <name>Resource Name</name>
38
+ </datacenter>
39
+ }
40
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").to_return(:body => xml)
41
+
42
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
43
+
44
+ Nokogiri.parse(datacenter.inspect).to_xml.should == Nokogiri.parse(xml).to_xml
45
+ end
46
+
47
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ feature "Instantiate resources from xml" do
4
+
5
+ it "should instantiate the resource without HTTP calls" do
6
+ xml = %q{
7
+ <datacenter>
8
+ <name>Resource 1</name>
9
+ </datacenter>
10
+ }
11
+ datacenter = Abiquo::Resource.from_xml(xml)
12
+
13
+ datacenter.name.should == "Resource 1"
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Navigating linked resources" do
4
+ scenario "Link to a collection of resources" do
5
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").to_return(:body => <<-XML)
6
+ <datacenter>
7
+ <link rel="racks" href="http://abiquo.example.com/api/admin/datacenters/1/racks"/>
8
+ </datacenter>
9
+ XML
10
+
11
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
12
+
13
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1/racks").to_return(:body => <<-XML)
14
+ <racks>
15
+ <rack>
16
+ <name>Rack 1</name>
17
+ </rack>
18
+ <rack>
19
+ <name>Rack 2</name>
20
+ </rack>
21
+ </racks>
22
+ XML
23
+
24
+ datacenter.racks.size.should == 2
25
+ datacenter.racks.first.name.should == 'Rack 1'
26
+ datacenter.racks.last.name.should == 'Rack 2'
27
+ end
28
+
29
+ scenario "Link to a collection of resources with params" do
30
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").to_return(:body => <<-XML)
31
+ <datacenter>
32
+ <link rel="racks" href="http://abiquo.example.com/api/admin/datacenters/1/racks"/>
33
+ </datacenter>
34
+ XML
35
+
36
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
37
+
38
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1/racks").to_return(:body => <<-XML)
39
+ <racks>
40
+ <rack>
41
+ <name>Rack 1</name>
42
+ </rack>
43
+ </racks>
44
+ XML
45
+
46
+ datacenter.racks.size.should == 1
47
+ datacenter.racks.first.name.should == 'Rack 1'
48
+ end
49
+
50
+ scenario "Link to self" do
51
+ stub_auth_request(:get, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").to_return(:body => <<-XML)
52
+ <datacenter>
53
+ <link rel="edit" href="http://abiquo.example.com/datacenters/1"/>
54
+ </datacenter>
55
+ XML
56
+
57
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
58
+
59
+ datacenter.url.should == "http://abiquo.example.com/api/admin/datacenters/1"
60
+ end
61
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Updating resources" do
4
+
5
+ scenario "Updating a resource" do
6
+ datacenter = Abiquo::Resource("http://abiquo.example.com/api/admin/datacenters/1", auth)
7
+
8
+ stub_auth_request(:options, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").
9
+ to_return(:headers => {'Allow' => 'GET, PUT, OPTIONS'})
10
+
11
+ stub_auth_request(:put, "http://admin:admin@abiquo.example.com/api/admin/datacenters/1").with do |req|
12
+ req.body == {:name => "Wadus Wadus"}.to_xml(:root => "datacenter")
13
+ end.to_return(:body => <<-XML)
14
+ <datacenter>
15
+ <name>Wadus Wadus</name>
16
+ <link rel="edit" href="http://abiquo.example.com/api/admin/datacenters/1"/>
17
+ </datacenter>
18
+ XML
19
+
20
+
21
+ datacenter.update(:name => "Wadus Wadus")
22
+
23
+ datacenter.name.should == "Wadus Wadus"
24
+ end
25
+
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'steak'
3
+ require 'webmock/rspec'
4
+ require "abiquo"
5
+
6
+ module Helpers
7
+
8
+ def stub_auth_request(*args)
9
+ stub_request(*args)
10
+ end
11
+
12
+ def auth_request(*args)
13
+ request(*args)
14
+ end
15
+
16
+ def auth
17
+ Abiquo::BasicAuth.new("Abiquo", "admin", "admin")
18
+ end
19
+ end
20
+
21
+ Spec::Runner.configure do |config|
22
+ config.include Helpers
23
+ config.include WebMock
24
+ config.before(:each) do
25
+ stub_request(:any, //).with { |request| !request.headers.has_key?("Authorization") }.
26
+ to_return(
27
+ :status => 401, :headers => {
28
+ "WWW-Authenticate" => 'Basic realm="Abiquo"'
29
+ })
30
+ end
31
+ config.after(:each) { reset_webmock }
32
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+
5
+ describe "to_xml" do
6
+
7
+ it "should convert the nested resources into 'link' tags if the :convert_links option is present" do
8
+ xml = Nokogiri.parse({"name" => "Almodovar", "tasks" => [{"name" => "Wadus"}]}.to_xml(:root => "project", :convert_links => true))
9
+
10
+ # <project>
11
+ # <name>Almodovar</name>
12
+ # <link rel="tasks">
13
+ # <tasks type="array">
14
+ # <task>
15
+ # <name>Wadus</name>
16
+ # </task>
17
+ # </tasks>
18
+ # </link>
19
+ # </project>
20
+ xml.at_xpath("/project/name").text.should == "Almodovar"
21
+ xml.at_xpath("/project/tasks").should be_nil
22
+ xml.at_xpath("/project/link[@rel='tasks']/tasks[@type='array']/task/name").text.should == "Wadus"
23
+ end
24
+
25
+ it "should not convert the nested resources into 'link' tags if the :convert_links option is not present" do
26
+ xml = Nokogiri.parse({"name" => "Almodovar", "tasks" => [{"name" => "Wadus"}]}.to_xml(:root => "project", :convert_links => false))
27
+
28
+ # <project>
29
+ # <name>Almodovar</name>
30
+ # <tasks type="array">
31
+ # <task>
32
+ # <name>Wadus</name>
33
+ # </task>
34
+ # </tasks>
35
+ # </project>
36
+ xml.at_xpath("/project/name").text.should == "Almodovar"
37
+ xml.at_xpath("//link").should be_nil
38
+ xml.at_xpath("/project/tasks[@type='array']/task/name").text.should == "Wadus"
39
+ end
40
+
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe Array do
47
+
48
+ describe "to_xml" do
49
+
50
+ it "should convert an array into xml" do
51
+ [].to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<nil-classes type=\"array\"/>\n"
52
+ end
53
+
54
+ end
55
+
56
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abiquo-etk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Rubio
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-10 00:00:00 Z
18
+ date: 2012-05-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: nokogiri
@@ -93,28 +93,12 @@ dependencies:
93
93
  version: 1.1.4
94
94
  type: :runtime
95
95
  version_requirements: *id005
96
- - !ruby/object:Gem::Dependency
97
- name: abiquo
98
- prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
100
- none: false
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: 31
105
- segments:
106
- - 0
107
- - 1
108
- - 2
109
- version: 0.1.2
110
- type: :runtime
111
- version_requirements: *id006
112
96
  description: Tools to troubleshoot and manage your Abiquo installation
113
97
  email: srubio@abiquo.com
114
98
  executables:
115
99
  - abiquo-check-install
116
- - abiquo-check-16-install
117
100
  - ciab-setup
101
+ - abiquo-check-16-install
118
102
  - abicli
119
103
  extensions: []
120
104
 
@@ -187,6 +171,30 @@ files:
187
171
  - lib/upgrades/17-nuclear-launch
188
172
  - scripts/setup_rs
189
173
  - scripts/setup_v2v
174
+ - vendor/abiquo-0.1.2/.bundle/config
175
+ - vendor/abiquo-0.1.2/Gemfile
176
+ - vendor/abiquo-0.1.2/LICENSE
177
+ - vendor/abiquo-0.1.2/README
178
+ - vendor/abiquo-0.1.2/Rakefile
179
+ - vendor/abiquo-0.1.2/abiquo.gemspec
180
+ - vendor/abiquo-0.1.2/examples/add_hypervisor.rb
181
+ - vendor/abiquo-0.1.2/examples/create_dc_and_hv.rb
182
+ - vendor/abiquo-0.1.2/examples/hypervisor_resource.rb
183
+ - vendor/abiquo-0.1.2/examples/rack_resource.rb
184
+ - vendor/abiquo-0.1.2/lib/abiquo.rb
185
+ - vendor/abiquo-0.1.2/lib/active_support/inflections.rb
186
+ - vendor/abiquo-0.1.2/lib/active_support/inflector.rb
187
+ - vendor/abiquo-0.1.2/lib/core_ext.rb
188
+ - vendor/abiquo-0.1.2/lib/to_xml.rb
189
+ - vendor/abiquo-0.1.2/spec/acceptance/create_resource_spec.rb
190
+ - vendor/abiquo-0.1.2/spec/acceptance/delete_resource_spec.rb
191
+ - vendor/abiquo-0.1.2/spec/acceptance/fetch_resource_collections_spec.rb
192
+ - vendor/abiquo-0.1.2/spec/acceptance/fetch_single_resources_spec.rb
193
+ - vendor/abiquo-0.1.2/spec/acceptance/from_xml_spec.rb
194
+ - vendor/abiquo-0.1.2/spec/acceptance/navigate_linked_resources_spec.rb
195
+ - vendor/abiquo-0.1.2/spec/acceptance/update_resource_spec.rb
196
+ - vendor/abiquo-0.1.2/spec/spec_helper.rb
197
+ - vendor/abiquo-0.1.2/spec/unit/to_xml_spec.rb
190
198
  - vendor/activesupport-2.3.8/CHANGELOG
191
199
  - vendor/activesupport-2.3.8/README
192
200
  - vendor/activesupport-2.3.8/lib/active_support.rb