From cad05257f3fd7b4d1d3aac58aa27ab718acceed9 Mon Sep 17 00:00:00 2001 From: mlincoln Date: Wed, 29 May 2013 16:29:35 -0500 Subject: [PATCH] Refactor to share tests --- .gitignore | 2 +- .../{v1_api => v1}/should_list_images.yml | 16 +-- .../should_list_server_flavors.yml | 72 +++++------ .../{v2_api => v2}/should_list_images.yml | 14 +-- .../should_list_server_flavors.yml | 42 +++---- spec/integration/v1_integration_spec.rb | 35 ------ spec/integration/v2_integration_spec.rb | 118 ++++++++++-------- spec/integration_spec_helper.rb | 16 ++- 8 files changed, 152 insertions(+), 163 deletions(-) rename spec/cassettes/{v1_api => v1}/should_list_images.yml (95%) rename spec/cassettes/{v1_api => v1}/should_list_server_flavors.yml (90%) rename spec/cassettes/{v2_api => v2}/should_list_images.yml (99%) rename spec/cassettes/{v2_api => v2}/should_list_server_flavors.yml (93%) delete mode 100644 spec/integration/v1_integration_spec.rb diff --git a/.gitignore b/.gitignore index 6add70c..5e3cbac 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ spec/reports .config InstalledFiles .bundle -.rackspace_cloud_credentials +.rackspace_cloud_credentials* *.lock # YARD artifacts diff --git a/spec/cassettes/v1_api/should_list_images.yml b/spec/cassettes/v1/should_list_images.yml similarity index 95% rename from spec/cassettes/v1_api/should_list_images.yml rename to spec/cassettes/v1/should_list_images.yml index 86df210..8b887ee 100644 --- a/spec/cassettes/v1_api/should_list_images.yml +++ b/spec/cassettes/v1/should_list_images.yml @@ -26,21 +26,21 @@ http_interactions: X-Storage-Url: - https://storage101.dfw1.clouddrive.com/v1/{CDN-TENANT-NAME} Cache-Control: - - s-maxage=62006 + - s-maxage=65356 X-Cloud-Auth: - 'true' Date: - - Tue, 28 May 2013 22:11:20 GMT + - Wed, 29 May 2013 21:19:03 GMT Front-End-Https: - 'on' X-Auth-Token: ! '{ONE-TIME-TOKEN}' - response-source: - - cloud-auth X-Storage-Token: ! '{ONE-TIME-TOKEN}' X-Server-Management-Url: - https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID} VIA: - 1.0 Repose (Repose/2.3.5) + X-Global-Auth: + - 'true' Connection: - keep-alive X-CDN-Management-Url: @@ -49,7 +49,7 @@ http_interactions: encoding: UTF-8 string: '' http_version: - recorded_at: Tue, 28 May 2013 22:11:20 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/images/detail.json @@ -82,10 +82,10 @@ http_interactions: Content-Length: - '2547' Date: - - Tue, 28 May 2013 22:11:20 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '754' + - '1561' Via: - 1.1 varnish Connection: @@ -119,5 +119,5 @@ http_interactions: 5.8"},{"id":89,"status":"ACTIVE","updated":"2011-10-04T08:39:34-05:00","name":"Windows Server 2008 R2 x64 + SQL Server 2008 R2 Web"}]}' http_version: - recorded_at: Tue, 28 May 2013 22:11:20 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT recorded_with: VCR 2.5.0 diff --git a/spec/cassettes/v1_api/should_list_server_flavors.yml b/spec/cassettes/v1/should_list_server_flavors.yml similarity index 90% rename from spec/cassettes/v1_api/should_list_server_flavors.yml rename to spec/cassettes/v1/should_list_server_flavors.yml index 4f6cbe4..e632146 100644 --- a/spec/cassettes/v1_api/should_list_server_flavors.yml +++ b/spec/cassettes/v1/should_list_server_flavors.yml @@ -26,21 +26,21 @@ http_interactions: X-Storage-Url: - https://storage101.dfw1.clouddrive.com/v1/{CDN-TENANT-NAME} Cache-Control: - - s-maxage=62008 + - s-maxage=65356 X-Cloud-Auth: - 'true' Date: - - Tue, 28 May 2013 22:11:18 GMT + - Wed, 29 May 2013 21:19:03 GMT Front-End-Https: - 'on' X-Auth-Token: ! '{ONE-TIME-TOKEN}' - response-source: - - cloud-auth X-Storage-Token: ! '{ONE-TIME-TOKEN}' X-Server-Management-Url: - https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID} VIA: - 1.0 Repose (Repose/2.3.5) + X-Global-Auth: + - 'true' Connection: - keep-alive X-CDN-Management-Url: @@ -49,7 +49,7 @@ http_interactions: encoding: UTF-8 string: '' http_version: - recorded_at: Tue, 28 May 2013 22:11:18 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/detail.json @@ -64,7 +64,7 @@ http_interactions: X-Auth-Token: ! '{ONE-TIME-TOKEN}' response: status: - code: 200 + code: 203 message: headers: Server: @@ -82,10 +82,10 @@ http_interactions: Content-Length: - '422' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '0' + - '1613' Via: - 1.1 varnish Connection: @@ -98,7 +98,7 @@ http_interactions: server"},{"id":7,"ram":15872,"disk":620,"name":"15.5GB server"},{"id":8,"ram":30720,"disk":1200,"name":"30GB server"}]}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/1.json @@ -131,10 +131,10 @@ http_interactions: Content-Length: - '59' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '755' + - '1613' Via: - 1.1 varnish Connection: @@ -143,7 +143,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":1,"ram":256,"disk":10,"name":"256 server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/2.json @@ -158,7 +158,7 @@ http_interactions: X-Auth-Token: ! '{ONE-TIME-TOKEN}' response: status: - code: 200 + code: 203 message: headers: Server: @@ -176,10 +176,10 @@ http_interactions: Content-Length: - '59' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '0' + - '1469' Via: - 1.1 varnish Connection: @@ -188,7 +188,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":2,"ram":512,"disk":20,"name":"512 server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/3.json @@ -221,10 +221,10 @@ http_interactions: Content-Length: - '60' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '755' + - '1612' Via: - 1.1 varnish Connection: @@ -233,7 +233,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":3,"ram":1024,"disk":40,"name":"1GB server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/4.json @@ -266,10 +266,10 @@ http_interactions: Content-Length: - '60' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '754' + - '1562' Via: - 1.1 varnish Connection: @@ -278,7 +278,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":4,"ram":2048,"disk":80,"name":"2GB server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/5.json @@ -293,7 +293,7 @@ http_interactions: X-Auth-Token: ! '{ONE-TIME-TOKEN}' response: status: - code: 200 + code: 203 message: headers: Server: @@ -311,10 +311,10 @@ http_interactions: Content-Length: - '61' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '0' + - '1612' Via: - 1.1 varnish Connection: @@ -323,7 +323,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":5,"ram":4096,"disk":160,"name":"4GB server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/6.json @@ -356,10 +356,10 @@ http_interactions: Content-Length: - '61' Date: - - Tue, 28 May 2013 22:11:19 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '754' + - '738' Via: - 1.1 varnish Connection: @@ -368,7 +368,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":6,"ram":8192,"disk":320,"name":"8GB server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:19 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/7.json @@ -401,10 +401,10 @@ http_interactions: Content-Length: - '65' Date: - - Tue, 28 May 2013 22:11:20 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '754' + - '1561' Via: - 1.1 varnish Connection: @@ -413,7 +413,7 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":7,"ram":15872,"disk":620,"name":"15.5GB server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:20 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT - request: method: get uri: https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID}/flavors/8.json @@ -428,7 +428,7 @@ http_interactions: X-Auth-Token: ! '{ONE-TIME-TOKEN}' response: status: - code: 200 + code: 203 message: headers: Server: @@ -446,10 +446,10 @@ http_interactions: Content-Length: - '64' Date: - - Tue, 28 May 2013 22:11:20 GMT + - Wed, 29 May 2013 21:19:03 GMT X-Varnish: ! '{VARNISH-REQUEST-ID}' Age: - - '0' + - '1611' Via: - 1.1 varnish Connection: @@ -458,5 +458,5 @@ http_interactions: encoding: UTF-8 string: ! '{"flavor":{"id":8,"ram":30720,"disk":1200,"name":"30GB server"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:20 GMT + recorded_at: Wed, 29 May 2013 21:19:04 GMT recorded_with: VCR 2.5.0 diff --git a/spec/cassettes/v2_api/should_list_images.yml b/spec/cassettes/v2/should_list_images.yml similarity index 99% rename from spec/cassettes/v2_api/should_list_images.yml rename to spec/cassettes/v2/should_list_images.yml index f5887cd..edee897 100644 --- a/spec/cassettes/v2_api/should_list_images.yml +++ b/spec/cassettes/v2/should_list_images.yml @@ -26,21 +26,21 @@ http_interactions: X-Storage-Url: - https://storage101.dfw1.clouddrive.com/v1/{CDN-TENANT-NAME} Cache-Control: - - s-maxage=61017 + - s-maxage=65353 X-Cloud-Auth: - 'true' Date: - - Tue, 28 May 2013 22:27:49 GMT + - Wed, 29 May 2013 21:19:06 GMT Front-End-Https: - 'on' X-Auth-Token: ! '{ONE-TIME-TOKEN}' - response-source: - - cloud-auth X-Storage-Token: ! '{ONE-TIME-TOKEN}' X-Server-Management-Url: - https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID} VIA: - 1.0 Repose (Repose/2.3.5) + X-Global-Auth: + - 'true' Connection: - keep-alive X-CDN-Management-Url: @@ -49,7 +49,7 @@ http_interactions: encoding: UTF-8 string: '' http_version: - recorded_at: Tue, 28 May 2013 22:27:49 GMT + recorded_at: Wed, 29 May 2013 21:19:07 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/images @@ -70,7 +70,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:27:52 GMT + - Wed, 29 May 2013 21:19:08 GMT Content-Length: - '22207' Content-Type: @@ -285,5 +285,5 @@ http_interactions: "type": "application/vnd.openstack.image", "rel": "alternate"}], "name": "openSUSE 12.1"}]}' http_version: - recorded_at: Tue, 28 May 2013 22:27:52 GMT + recorded_at: Wed, 29 May 2013 21:19:09 GMT recorded_with: VCR 2.5.0 diff --git a/spec/cassettes/v2_api/should_list_server_flavors.yml b/spec/cassettes/v2/should_list_server_flavors.yml similarity index 93% rename from spec/cassettes/v2_api/should_list_server_flavors.yml rename to spec/cassettes/v2/should_list_server_flavors.yml index 4a32752..d7cb49a 100644 --- a/spec/cassettes/v2_api/should_list_server_flavors.yml +++ b/spec/cassettes/v2/should_list_server_flavors.yml @@ -26,21 +26,21 @@ http_interactions: X-Storage-Url: - https://storage101.dfw1.clouddrive.com/v1/{CDN-TENANT-NAME} Cache-Control: - - s-maxage=62005 + - s-maxage=65355 X-Cloud-Auth: - 'true' Date: - - Tue, 28 May 2013 22:11:21 GMT + - Wed, 29 May 2013 21:19:04 GMT Front-End-Https: - 'on' X-Auth-Token: ! '{ONE-TIME-TOKEN}' - response-source: - - cloud-auth X-Storage-Token: ! '{ONE-TIME-TOKEN}' X-Server-Management-Url: - https://servers.api.rackspacecloud.com/v1.0/{TENANT-ID} VIA: - 1.0 Repose (Repose/2.3.5) + X-Global-Auth: + - 'true' Connection: - keep-alive X-CDN-Management-Url: @@ -49,7 +49,7 @@ http_interactions: encoding: UTF-8 string: '' http_version: - recorded_at: Tue, 28 May 2013 22:11:21 GMT + recorded_at: Wed, 29 May 2013 21:19:05 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors @@ -70,7 +70,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:21 GMT + - Wed, 29 May 2013 21:19:04 GMT Content-Length: - '1697' Content-Type: @@ -102,7 +102,7 @@ http_interactions: "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/{TENANT-ID}/flavors/8", "rel": "bookmark"}], "name": "30GB Standard Instance"}]}' http_version: - recorded_at: Tue, 28 May 2013 22:11:21 GMT + recorded_at: Wed, 29 May 2013 21:19:05 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/2 @@ -123,7 +123,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:21 GMT + - Wed, 29 May 2013 21:19:04 GMT Content-Length: - '353' Content-Type: @@ -139,7 +139,7 @@ http_interactions: "rel": "bookmark"}], "ram": 512, "vcpus": 1, "swap": 512, "rxtx_factor": 2.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 20, "id": "2"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:21 GMT + recorded_at: Wed, 29 May 2013 21:19:05 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/3 @@ -160,7 +160,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:22 GMT + - Wed, 29 May 2013 21:19:05 GMT Content-Length: - '353' Content-Type: @@ -175,7 +175,7 @@ http_interactions: "rel": "bookmark"}], "ram": 1024, "vcpus": 1, "swap": 1024, "rxtx_factor": 3.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 40, "id": "3"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:22 GMT + recorded_at: Wed, 29 May 2013 21:19:06 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/4 @@ -196,7 +196,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:22 GMT + - Wed, 29 May 2013 21:19:05 GMT Content-Length: - '353' Content-Type: @@ -211,7 +211,7 @@ http_interactions: "rel": "bookmark"}], "ram": 2048, "vcpus": 2, "swap": 2048, "rxtx_factor": 6.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 80, "id": "4"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:22 GMT + recorded_at: Wed, 29 May 2013 21:19:06 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/5 @@ -232,7 +232,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:22 GMT + - Wed, 29 May 2013 21:19:05 GMT Content-Length: - '355' Content-Type: @@ -247,7 +247,7 @@ http_interactions: "rel": "bookmark"}], "ram": 4096, "vcpus": 2, "swap": 2048, "rxtx_factor": 10.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 160, "id": "5"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:22 GMT + recorded_at: Wed, 29 May 2013 21:19:06 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/6 @@ -268,7 +268,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:23 GMT + - Wed, 29 May 2013 21:19:05 GMT Content-Length: - '355' Content-Type: @@ -283,7 +283,7 @@ http_interactions: "rel": "bookmark"}], "ram": 8192, "vcpus": 4, "swap": 2048, "rxtx_factor": 15.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 320, "id": "6"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:23 GMT + recorded_at: Wed, 29 May 2013 21:19:06 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/7 @@ -304,7 +304,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:23 GMT + - Wed, 29 May 2013 21:19:06 GMT Content-Length: - '357' Content-Type: @@ -320,7 +320,7 @@ http_interactions: "rel": "bookmark"}], "ram": 15360, "vcpus": 6, "swap": 2048, "rxtx_factor": 20.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 620, "id": "7"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:23 GMT + recorded_at: Wed, 29 May 2013 21:19:06 GMT - request: method: get uri: https://dfw.servers.api.rackspacecloud.com/v2/{TENANT-ID}/flavors/8 @@ -341,7 +341,7 @@ http_interactions: message: headers: Date: - - Tue, 28 May 2013 22:11:23 GMT + - Wed, 29 May 2013 21:19:06 GMT Content-Length: - '358' Content-Type: @@ -357,5 +357,5 @@ http_interactions: "rel": "bookmark"}], "ram": 30720, "vcpus": 8, "swap": 2048, "rxtx_factor": 30.0, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 1200, "id": "8"}}' http_version: - recorded_at: Tue, 28 May 2013 22:11:23 GMT + recorded_at: Wed, 29 May 2013 21:19:07 GMT recorded_with: VCR 2.5.0 diff --git a/spec/integration/v1_integration_spec.rb b/spec/integration/v1_integration_spec.rb deleted file mode 100644 index a8f08a5..0000000 --- a/spec/integration/v1_integration_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'integration_spec_helper' -require 'fog' -require 'knife/dsl' - -include Chef::Knife::DSL - -describe 'v1_api' do - before do - Chef::Config[:knife][:rackspace_version] = 'v1' - end - - it 'should list server flavors', :vcr do - stdout, stderr, status = knife_capture('rackspace flavor list') - status.should == 0 - stdout.should match_output(""" -ID Name Architecture RAM Disk -1 256 server 64-bit 256 10 GB -2 512 server 64-bit 512 20 GB -3 1GB server 64-bit 1024 40 GB -4 2GB server 64-bit 2048 80 GB -5 4GB server 64-bit 4096 160 GB -6 8GB server 64-bit 8192 320 GB -7 15.5GB server 64-bit 15872 620 GB -8 30GB server 64-bit 30720 1200 GB -""") - end - - it 'should list images', :vcr do - stdout, stderr, status = knife_capture('rackspace image list') - status.should == 0 - stdout = ANSI.unansi stdout - stdout.should match /^ID\s*Name\s*$/ - stdout.should include 'Ubuntu 12.04 LTS' - end -end diff --git a/spec/integration/v2_integration_spec.rb b/spec/integration/v2_integration_spec.rb index 54e3fa6..84f86e6 100644 --- a/spec/integration/v2_integration_spec.rb +++ b/spec/integration/v2_integration_spec.rb @@ -4,23 +4,32 @@ require 'chef/knife/rackspace_server_create' include Chef::Knife::DSL -describe 'v2_api' do - def server_list - stdout, stderr, status = knife_capture('rackspace server list') - status == 0 ? stdout : stderr - end +[:v1, :v2].each do |api| + describe api do + before(:each) do + Chef::Config[:knife][:rackspace_version] = api.to_s #v2 by default - before(:each) do - Chef::Config[:knife][:rackspace_version] = nil #v2 by default + Chef::Knife::Bootstrap.any_instance.stub(:run) + Chef::Knife::RackspaceServerCreate.any_instance.stub(:tcp_test_ssh).with(anything).and_return(true) + end - Chef::Knife::Bootstrap.any_instance.stub(:run) - Chef::Knife::RackspaceServerCreate.any_instance.stub(:tcp_test_ssh).with(anything).and_return(true) - end + it 'should list server flavors', :vcr do + stdout, stderr, status = knife_capture('rackspace flavor list') + status.should == 0 - it 'should list server flavors', :vcr do - stdout, stderr, status = knife_capture('rackspace flavor list') - status.should == 0 - stdout.should match_output(""" + expected_output = { + :v1 => """ +ID Name Architecture RAM Disk +1 256 server 64-bit 256 10 GB +2 512 server 64-bit 512 20 GB +3 1GB server 64-bit 1024 40 GB +4 2GB server 64-bit 2048 80 GB +5 4GB server 64-bit 4096 160 GB +6 8GB server 64-bit 8192 320 GB +7 15.5GB server 64-bit 15872 620 GB +8 30GB server 64-bit 30720 1200 GB +""", + :v2 => """ ID Name VCPUs RAM Disk 2 512MB Standard Instance 1 512 20 GB 3 1GB Standard Instance 1 1024 40 GB @@ -29,52 +38,53 @@ def server_list 6 8GB Standard Instance 4 8192 320 GB 7 15GB Standard Instance 6 15360 620 GB 8 30GB Standard Instance 8 30720 1200 GB -""") - end + """} + stdout = ANSI.unansi stdout + stdout.should match_output(expected_output[api]) + end - it 'should list images', :vcr do - stdout, stderr, status = knife_capture('rackspace image list') - status.should == 0 - stdout = ANSI.unansi stdout - stdout.should match /^ID\s*Name\s*$/ - stdout.should include 'Ubuntu 12.10 (Quantal Quetzal)' - end + it 'should list images', :vcr do + sample_image = { + :v1 => 'Ubuntu 12.04 LTS', + :v2 => 'Ubuntu 12.04 LTS (Precise Pangolin)' + } - it 'should manage servers', :vcr do - # image = '112' # v1 - image = '9922a7c7-5a42-4a56-bc6a-93f857ae2346' - # Faster? flavor 4, image 88130782-11ec-4795-b85f-b55a297ba446 - flavor = '2' - role = 'role[dummy_server_for_integration_test]' - server_list.should_not include 'test-node' + stdout, stderr, status = knife_capture('rackspace image list') + status.should == 0 + stdout = ANSI.unansi stdout + stdout.should match /^ID\s*Name\s*$/ + stdout.should include sample_image[api] + end - args = %W{rackspace server create -I #{image} -f #{flavor} -r 'role[webserver]' -N test-node -S test-server} - stdout, stderr, status = knife_capture(args) - status.should == 0 - instance_data = capture_instance_data(stdout, { - :name => 'Name', - :instance_id => 'Instance ID', - :public_ip => 'Public IP Address', - :private_ip => 'Private IP Address' - }) + it 'should manage servers', :vcr do + pending "The test works, but I'm in the process of cleaning up sensitive data in the cassettes" - # Wanted to assert active state, but got build during test - server_list.should match /#{instance_data[:instance_id]}\s*#{instance_data[:name]}\s*#{instance_data[:public_ip]}\s*#{instance_data[:private_ip]}\s*#{flavor}\s*#{image}/ + image = { + :v1 => '112', + :v2 => 'e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce' + } + flavor = 2 + server_list.should_not include 'test-node' - args = %W{rackspace server delete #{instance_data[:instance_id]} -y} - stdout, stderr, status = knife_capture(args) - status.should == 0 + args = %W{rackspace server create -I #{image[api]} -f #{flavor} -N test-node -S test-server} + stdout, stderr, status = knife_capture(args) + status.should == 0 + instance_data = capture_instance_data(stdout, { + :name => 'Name', + :instance_id => 'Instance ID', + :public_ip => 'Public IP Address', + :private_ip => 'Private IP Address' + }) - # Need to deal with deleting vs deleted states before we can check this - # server_list.should_not match /#{instance_data[:instance_id]}\s*#{instance_data[:name]}\s*#{instance_data[:public_ip]}\s*#{instance_data[:private_ip]}\s*#{flavor}\s*#{image}/ - end + # Wanted to assert active state, but got build during test + server_list.should match /#{instance_data[:instance_id]}\s*#{instance_data[:name]}\s*#{instance_data[:public_ip]}\s*#{instance_data[:private_ip]}\s*#{flavor}\s*#{image}/ - def capture_instance_data(stdout, labels = {}) - result = {} - labels.each do | key, label | - result[key] = clean_output(stdout).match(/^#{label}: (.*)$/)[1] + args = %W{rackspace server delete #{instance_data[:instance_id]} -y} + stdout, stderr, status = knife_capture(args) + status.should == 0 + + # Need to deal with deleting vs deleted states before we can check this + # server_list.should_not match /#{instance_data[:instance_id]}\s*#{instance_data[:name]}\s*#{instance_data[:public_ip]}\s*#{instance_data[:private_ip]}\s*#{flavor}\s*#{image}/ end - result end - -end +end \ No newline at end of file diff --git a/spec/integration_spec_helper.rb b/spec/integration_spec_helper.rb index 95743bd..c5e0dee 100644 --- a/spec/integration_spec_helper.rb +++ b/spec/integration_spec_helper.rb @@ -13,6 +13,7 @@ c.hook_into :excon c.configure_rspec_metadata! + # Sensitive data c.filter_sensitive_data('{RAX_USERNAME}') { Chef::Config[:knife][:rackspace_api_username] } c.filter_sensitive_data('{RAX_PASSWORD}') { Chef::Config[:knife][:rackspace_api_key] } c.filter_sensitive_data('{CDN-TENANT-NAME}') { ENV['RS_CDN_TENANT_NAME'] } @@ -78,4 +79,17 @@ def clean_output(output) description do 'Compare actual and expected output, ignoring ansi color and trailing whitespace' end -end \ No newline at end of file +end + +def server_list + stdout, stderr, status = knife_capture('rackspace server list') + status == 0 ? stdout : stderr +end + +def capture_instance_data(stdout, labels = {}) + result = {} + labels.each do | key, label | + result[key] = clean_output(stdout).match(/^#{label}: (.*)$/)[1] + end + result +end