knife-google 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +155 -66
- data/knife-google.gemspec +2 -1
- data/lib/chef/knife/google_base.rb +1 -1
- data/lib/chef/knife/google_disk_create.rb +17 -9
- data/lib/chef/knife/google_disk_delete.rb +2 -2
- data/lib/chef/knife/google_disk_list.rb +8 -8
- data/lib/chef/knife/google_project_list.rb +178 -0
- data/lib/chef/knife/google_region_list.rb +125 -0
- data/lib/chef/knife/google_server_create.rb +174 -46
- data/lib/chef/knife/google_server_delete.rb +9 -13
- data/lib/chef/knife/google_server_list.rb +5 -6
- data/lib/chef/knife/google_zone_list.rb +22 -28
- data/lib/google/compute.rb +2 -1
- data/lib/google/compute/client.rb +12 -7
- data/lib/google/compute/creatable_resource_collection.rb +12 -1
- data/lib/google/compute/disk.rb +0 -2
- data/lib/google/compute/image.rb +1 -2
- data/lib/google/compute/project.rb +2 -2
- data/lib/google/compute/{kernel.rb → region.rb} +12 -1
- data/lib/google/compute/region_operation.rb +62 -0
- data/lib/google/compute/server.rb +3 -2
- data/lib/google/compute/server/attached_disk.rb +3 -3
- data/lib/google/compute/zone.rb +6 -4
- data/lib/google/compute/zone_operation.rb +11 -9
- data/lib/knife-google/version.rb +1 -1
- data/spec/chef/knife/google_base_spec.rb +4 -4
- data/spec/chef/knife/google_disk_create_spec.rb +8 -7
- data/spec/chef/knife/google_disk_delete_spec.rb +15 -16
- data/spec/chef/knife/google_disk_list_spec.rb +6 -6
- data/spec/chef/knife/google_region_list_spec.rb +32 -0
- data/spec/chef/knife/google_server_create_spec.rb +78 -44
- data/spec/chef/knife/google_server_delete_spec.rb +37 -37
- data/spec/chef/knife/google_server_list_spec.rb +8 -7
- data/spec/chef/knife/google_setup_spec.rb +1 -2
- data/spec/chef/knife/google_zone_list_spec.rb +4 -4
- data/spec/data/{compute-v1beta15.json → compute-v1.json} +700 -246
- data/spec/data/disk.json +3 -4
- data/spec/data/firewall.json +2 -2
- data/spec/data/global_operation.json +3 -3
- data/spec/data/image.json +2 -2
- data/spec/data/machine_type.json +1 -1
- data/spec/data/network.json +1 -1
- data/spec/data/project.json +1 -1
- data/spec/data/region.json +23 -0
- data/spec/data/serial_port_output.json +1 -1
- data/spec/data/server.json +7 -7
- data/spec/data/snapshot.json +2 -2
- data/spec/data/zone.json +7 -15
- data/spec/data/zone_operation.json +3 -3
- data/spec/google/compute/disk_spec.rb +32 -32
- data/spec/google/compute/firewall_spec.rb +37 -37
- data/spec/google/compute/global_operation_spec.rb +9 -9
- data/spec/google/compute/image_spec.rb +17 -17
- data/spec/google/compute/machine_type_spec.rb +7 -7
- data/spec/google/compute/network_spec.rb +14 -14
- data/spec/google/compute/project_spec.rb +17 -17
- data/spec/google/compute/region_spec.rb +51 -0
- data/spec/google/compute/server_spec.rb +35 -42
- data/spec/google/compute/snapshot_spec.rb +11 -11
- data/spec/google/compute/zone_operation_spec.rb +9 -9
- data/spec/google/compute/zone_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -0
- data/spec/support/mocks.rb +10 -10
- data/spec/support/resource_examples.rb +7 -7
- data/spec/support/spec_google_base.rb +4 -0
- metadata +14 -26
- data/spec/data/kernel.json +0 -15
- data/spec/google/compute/kernel_spec.rb +0 -49
data/lib/google/compute/zone.rb
CHANGED
@@ -12,20 +12,22 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
#require 'google/compute/resource'
|
16
|
+
#require 'google/compute/region'
|
17
|
+
|
15
18
|
module Google
|
16
19
|
module Compute
|
17
20
|
class Zone < Resource
|
18
21
|
|
19
|
-
attr_reader :
|
20
|
-
attr_reader :
|
22
|
+
attr_reader :status, :maintenance_windows
|
23
|
+
attr_reader :deprecated, :region
|
21
24
|
|
22
25
|
def from_hash(zone_data)
|
23
26
|
super(zone_data)
|
24
27
|
@status = zone_data["status"]
|
25
28
|
@maintenance_windows = zone_data["maintenanceWindows"]
|
26
|
-
@available_machine_type = zone_data["availableMachineType"]
|
27
|
-
@quotas = zone_data["quotas"]
|
28
29
|
@deprecated = zone_data["deprecated"]
|
30
|
+
@region = zone_data["region"]
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -20,17 +20,20 @@ module Google
|
|
20
20
|
module Compute
|
21
21
|
class ZoneOperation < Resource
|
22
22
|
|
23
|
-
attr_reader :
|
24
|
-
attr_reader :
|
23
|
+
attr_reader :zone, :client_operation_id, :operation_type
|
24
|
+
attr_reader :target_link, :target_id, :status
|
25
|
+
attr_reader :status_message, :user, :progress
|
25
26
|
attr_reader :insert_time, :start_time, :end_time
|
26
|
-
attr_reader :
|
27
|
-
attr_reader :
|
27
|
+
attr_reader :error, :warnings, :http_error_status_code
|
28
|
+
attr_reader :http_error_message, :region
|
28
29
|
|
29
30
|
def from_hash(data)
|
30
31
|
super(data)
|
32
|
+
@zone = data["zone"]
|
33
|
+
@client_operation_id = data["clientOperationId"]
|
34
|
+
@operation_type = data["operationType"]
|
31
35
|
@target_link= data["targetLink"]
|
32
36
|
@target_id = data["targetId"]
|
33
|
-
@client_operation_id = data["clientOperationId"]
|
34
37
|
@status = data["status"]
|
35
38
|
@status_message = data["statusMessage"]
|
36
39
|
@user = data["user"]
|
@@ -38,12 +41,11 @@ module Google
|
|
38
41
|
@insert_time = Time.parse( data["insertTime"] )
|
39
42
|
@start_time = Time.parse( data["startTime"] )
|
40
43
|
@end_time = Time.parse( data["endTime"] ) if data.key?("endTime")
|
41
|
-
@http_error_status_code = data["httpErrorMessage"]
|
42
|
-
@http_error_message = data["httpErrorMessage"]
|
43
44
|
@error = data["error"]
|
44
45
|
@warnings = data["warnings"]
|
45
|
-
@
|
46
|
-
@
|
46
|
+
@http_error_status_code = data["httpErrorMessage"]
|
47
|
+
@http_error_message = data["httpErrorMessage"]
|
48
|
+
@region = data["region"]
|
47
49
|
end
|
48
50
|
|
49
51
|
def wait_for_completion!(options={})
|
data/lib/knife-google/version.rb
CHANGED
@@ -20,20 +20,20 @@ describe Chef::Knife::GoogleBase do
|
|
20
20
|
|
21
21
|
it "#client should return a Google::Compute::Client" do
|
22
22
|
Google::Compute::Client.should_receive(:from_json).
|
23
|
-
and_return(
|
23
|
+
and_return(double(Google::Compute::Client))
|
24
24
|
knife_plugin.client
|
25
25
|
end
|
26
26
|
|
27
27
|
it "#selflink2name should return name from a seleflink url" do
|
28
28
|
knife_plugin.selflink2name(
|
29
|
-
'https://www.googleapis.com/compute/
|
29
|
+
'https://www.googleapis.com/compute/v1/projects/mock-project/category/resource').
|
30
30
|
should eq('resource')
|
31
31
|
end
|
32
32
|
|
33
|
-
it "#msg_pair should invoke ui.info with
|
33
|
+
it "#msg_pair should invoke ui.info with label : value string" do
|
34
34
|
knife_plugin.ui.should_receive(:info).
|
35
35
|
with("#{knife_plugin.ui.color("label", :cyan)}: value")
|
36
|
-
knife_plugin.msg_pair("label","value")
|
36
|
+
knife_plugin.msg_pair("label", "value")
|
37
37
|
end
|
38
38
|
|
39
39
|
it "#private_ips should extract private ip as an array from a GCE server" do
|
@@ -12,25 +12,26 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
#
|
15
|
+
|
15
16
|
require 'spec_helper'
|
16
17
|
|
17
18
|
describe Chef::Knife::GoogleDiskCreate do
|
18
|
-
|
19
19
|
let(:knife_plugin) do
|
20
20
|
Chef::Knife::GoogleDiskCreate.new(
|
21
|
-
[stored_disk.name, "-Z"+stored_zone.name
|
21
|
+
[stored_disk.name, "-Z"+stored_zone.name])
|
22
22
|
end
|
23
23
|
|
24
24
|
it "#run should invoke compute api to create a disk" do
|
25
|
-
zones =
|
25
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
26
26
|
zones.should_receive(:get).
|
27
27
|
with(stored_zone.name).and_return(stored_zone)
|
28
|
-
disks =
|
28
|
+
disks = double(Google::Compute::CreatableResourceCollection)
|
29
29
|
disks.should_receive(:create).
|
30
|
-
with(:
|
30
|
+
with(:name => stored_disk.name, :sizeGb => 10, :zone => stored_zone.name).
|
31
31
|
and_return(stored_zone_operation)
|
32
|
-
client =
|
33
|
-
Google::Compute::Client.stub
|
32
|
+
client = double(Google::Compute::Client, :zones => zones, :disks => disks)
|
33
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
34
|
+
knife_plugin.config[:disk_size] = 10
|
34
35
|
knife_plugin.run
|
35
36
|
end
|
36
37
|
end
|
@@ -15,51 +15,50 @@
|
|
15
15
|
require 'spec_helper'
|
16
16
|
|
17
17
|
describe Chef::Knife::GoogleDiskDelete do
|
18
|
-
|
19
18
|
let(:knife_plugin) do
|
20
19
|
Chef::Knife::GoogleDiskDelete.new([stored_disk.name, "-Z"+stored_zone.name])
|
21
20
|
end
|
22
21
|
|
23
22
|
it "should print out error message if the disk is not found" do
|
24
|
-
zones =
|
23
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
25
24
|
zones.should_receive(:get).with(stored_zone.name).
|
26
25
|
and_return(stored_zone)
|
27
|
-
disks =
|
26
|
+
disks = double(Google::Compute::DeletableResourceCollection)
|
28
27
|
disks.should_receive(:get).
|
29
|
-
with(:zone=>stored_zone.name, :disk=>stored_disk.name).
|
28
|
+
with(:zone => stored_zone.name, :disk => stored_disk.name).
|
30
29
|
and_raise(Google::Compute::ResourceNotFound)
|
31
30
|
disks.should_not_receive(:delete)
|
32
|
-
client =
|
33
|
-
:disks=>disks, :zones=>zones)
|
34
|
-
Google::Compute::Client.stub
|
31
|
+
client = double(Google::Compute::Client,
|
32
|
+
:disks => disks, :zones => zones)
|
33
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
35
34
|
|
36
35
|
knife_plugin.config[:yes] = true
|
37
36
|
knife_plugin.ui.should_receive(:error).
|
38
37
|
with("Disk '#{stored_zone.name}:#{stored_disk.name}' not found")
|
39
|
-
knife_plugin.stub
|
38
|
+
knife_plugin.stub(:msg_pair)
|
40
39
|
expect {
|
41
40
|
knife_plugin.run
|
42
41
|
}.to raise_error(SystemExit)
|
43
42
|
end
|
44
43
|
|
45
44
|
it "should invoke api delete method when run is called" do
|
46
|
-
zones =
|
45
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
47
46
|
zones.should_receive(:get).with(stored_zone.name).
|
48
47
|
and_return(stored_zone)
|
49
|
-
disks =
|
48
|
+
disks = double(Google::Compute::DeletableResourceCollection)
|
50
49
|
disks.should_receive(:get).
|
51
|
-
with(:zone=>stored_zone.name, :disk=>stored_disk.name).
|
50
|
+
with(:zone => stored_zone.name, :disk => stored_disk.name).
|
52
51
|
and_return(stored_disk)
|
53
52
|
disks.should_receive(:delete).
|
54
|
-
with(:zone=>stored_zone.name, :disk=>stored_disk.name)
|
55
|
-
client =
|
56
|
-
:zones=>zones
|
57
|
-
Google::Compute::Client.stub
|
53
|
+
with(:zone => stored_zone.name, :disk => stored_disk.name)
|
54
|
+
client = double(Google::Compute::Client,
|
55
|
+
:zones => zones, :disks => disks)
|
56
|
+
Google::Compute::Client.stub(:from_json).
|
58
57
|
and_return(client)
|
59
58
|
knife_plugin.config[:yes] = true
|
60
59
|
knife_plugin.ui.should_receive(:warn).
|
61
60
|
with("Disk '#{stored_zone.name}:#{stored_disk.name}' deleted")
|
62
|
-
knife_plugin.stub
|
61
|
+
knife_plugin.stub(:msg_pair)
|
63
62
|
knife_plugin.run
|
64
63
|
end
|
65
64
|
end
|
@@ -12,24 +12,24 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
#
|
15
|
+
|
15
16
|
require 'spec_helper'
|
16
17
|
|
17
18
|
describe Chef::Knife::GoogleDiskList do
|
18
|
-
|
19
19
|
let(:knife_plugin) do
|
20
20
|
Chef::Knife::GoogleDiskList.new(["-Z"+stored_zone.name])
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should enlist all the GCE disks when run invoked" do
|
24
|
-
zones =
|
24
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
25
25
|
zones.should_receive(:get).with(stored_zone.name).
|
26
26
|
and_return(stored_zone)
|
27
|
-
disks =
|
28
|
-
disks.should_receive(:list).with(:zone=>stored_zone.name).
|
27
|
+
disks = double(Google::Compute::ListableResourceCollection)
|
28
|
+
disks.should_receive(:list).with(:zone => stored_zone.name).
|
29
29
|
and_return([stored_disk])
|
30
30
|
|
31
|
-
client =
|
32
|
-
Google::Compute::Client.stub
|
31
|
+
client = double(Google::Compute::Client, :disks => disks, :zones => zones)
|
32
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
33
33
|
$stdout.should_receive(:write).with(kind_of(String))
|
34
34
|
knife_plugin.run
|
35
35
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'spec_helper'
|
17
|
+
|
18
|
+
describe Chef::Knife::GoogleRegionList do
|
19
|
+
let(:knife_plugin) do
|
20
|
+
Chef::Knife::GoogleRegionList.new([])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should enlist all the GCE regions when run invoked" do
|
24
|
+
client = double(Google::Compute::Client)
|
25
|
+
Google::Compute::Client.stub(:from_json).
|
26
|
+
and_return(client)
|
27
|
+
client.should_receive(:regions).
|
28
|
+
and_return(double("region-collection", :list => [stored_region]))
|
29
|
+
$stdout.should_receive(:write).with(kind_of(String))
|
30
|
+
knife_plugin.run
|
31
|
+
end
|
32
|
+
end
|
@@ -12,91 +12,125 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
#
|
15
|
+
|
15
16
|
require 'spec_helper'
|
16
17
|
|
17
18
|
describe Chef::Knife::GoogleServerCreate do
|
18
|
-
|
19
19
|
before(:each) do
|
20
|
-
|
20
|
+
|
21
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
21
22
|
zones.should_receive(:get).with(stored_zone.name).
|
22
23
|
and_return(stored_zone)
|
23
24
|
|
24
|
-
machine_types =
|
25
|
+
machine_types = double(Google::Compute::ListableResourceCollection)
|
25
26
|
machine_types.should_receive(:get).
|
26
|
-
with({:name=>stored_machine_type.name, :zone=>stored_zone.name}).
|
27
|
+
with({:name => stored_machine_type.name, :zone => stored_zone.name}).
|
27
28
|
and_return(stored_machine_type)
|
28
29
|
|
29
|
-
images =
|
30
|
+
images = double(Google::Compute::ListableResourceCollection)
|
30
31
|
images.should_receive(:get).
|
31
|
-
with({:project=>"
|
32
|
+
with({:project => "mock-project", :name => stored_image.name}).
|
32
33
|
and_return(stored_image)
|
33
34
|
|
34
|
-
|
35
|
+
sizeGb = 10
|
36
|
+
disks = double(Google::Compute::ListableResourceCollection)
|
37
|
+
disks.should_receive(:insert).
|
38
|
+
with({:sourceImage => stored_image.self_link, :zone => stored_zone.name,
|
39
|
+
:name => stored_instance.name, :sizeGb => sizeGb}).
|
40
|
+
and_return(stored_disk)
|
41
|
+
|
42
|
+
networks = double(Google::Compute::ListableResourceCollection)
|
35
43
|
networks.should_receive(:get).with(stored_network.name).
|
36
44
|
and_return(stored_network)
|
37
45
|
|
38
|
-
instances =
|
39
|
-
instances.should_receive(:create).with(
|
40
|
-
|
41
|
-
:
|
42
|
-
:
|
43
|
-
|
44
|
-
|
45
|
-
"
|
46
|
-
|
47
|
-
|
46
|
+
instances = double(Google::Compute::ListableResourceCollection)
|
47
|
+
instances.should_receive(:create).with({
|
48
|
+
:name => stored_instance.name,
|
49
|
+
:zone => stored_zone.name,
|
50
|
+
:machineType => stored_machine_type.self_link,
|
51
|
+
#:image => stored_image.self_link,
|
52
|
+
:disks => [{
|
53
|
+
"boot" => true,
|
54
|
+
"type" => "PERSISTENT",
|
55
|
+
"mode" => "READ_WRITE",
|
56
|
+
"deviceName" => "",
|
57
|
+
"source" => nil}],
|
58
|
+
:networkInterfaces => [{
|
59
|
+
"network" => stored_network.self_link,
|
60
|
+
"accessConfigs" => [{
|
61
|
+
"name" => "External NAT",
|
62
|
+
"type" => "ONE_TO_ONE_NAT"}]}],
|
63
|
+
:serviceAccounts => [{
|
64
|
+
"kind" => "compute#serviceAccount",
|
65
|
+
"email" => "123845678986@project.gserviceaccount.com",
|
66
|
+
"scopes" => [
|
67
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
68
|
+
"https://www.googleapis.com/auth/compute",
|
69
|
+
"https://www.googleapis.com/auth/devstorage.full_control"]}],
|
70
|
+
:scheduling=>{
|
71
|
+
"automaticRestart" => "false",
|
72
|
+
"onHostMaintenance" => "TERMINATE"},
|
73
|
+
:metadata => {"items" => []},
|
74
|
+
:tags => {"items" => []}}).and_return(stored_zone_operation)
|
48
75
|
|
49
76
|
instances.should_receive(:get).
|
50
|
-
with(:zone=>stored_zone.name, :name=>stored_instance.name).
|
77
|
+
with(:zone => stored_zone.name, :name => stored_instance.name).
|
51
78
|
and_return(stored_instance)
|
52
79
|
|
53
|
-
client =
|
54
|
-
:images=>images, :zones=>zones,:machine_types=>machine_types,
|
55
|
-
:networks=>networks)
|
56
|
-
Google::Compute::Client.stub
|
80
|
+
client = double(Google::Compute::Client, :instances => instances,
|
81
|
+
:images => images, :zones => zones,:machine_types => machine_types,
|
82
|
+
:networks => networks, :disks => disks)
|
83
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
57
84
|
end
|
58
85
|
|
59
|
-
it "#run should invoke compute api to create an server" do
|
60
|
-
knife_plugin = Chef::Knife::GoogleServerCreate.new([
|
61
|
-
"-
|
86
|
+
it "#run should invoke compute api to create an server with a service account" do
|
87
|
+
knife_plugin = Chef::Knife::GoogleServerCreate.new([
|
88
|
+
"-m"+stored_machine_type.name,
|
89
|
+
"-I"+stored_image.name,
|
62
90
|
"-n"+stored_network.name,
|
63
|
-
"-Z"+stored_zone.name,
|
64
|
-
|
91
|
+
"-Z"+stored_zone.name,
|
92
|
+
stored_instance.name])
|
93
|
+
knife_plugin.config[:service_account_scopes]=["https://www.googleapis.com/auth/userinfo.email","https://www.googleapis.com/auth/compute","https://www.googleapis.com/auth/devstorage.full_control"]
|
94
|
+
knife_plugin.config[:service_account_name]='123845678986@project.gserviceaccount.com'
|
95
|
+
knife_plugin.config[:boot_disk_size]='10'
|
65
96
|
knife_plugin.config[:metadata]=[]
|
97
|
+
knife_plugin.config[:tags]=[]
|
66
98
|
knife_plugin.config[:public_ip]='EPHEMERAL'
|
67
|
-
knife_plugin.ui.stub
|
68
|
-
|
69
|
-
knife_plugin.stub
|
99
|
+
knife_plugin.ui.stub(:info)
|
100
|
+
knife_plugin.stub(:wait_for_disk)
|
101
|
+
knife_plugin.stub(:wait_for_sshd)
|
70
102
|
knife_plugin.should_receive(:bootstrap_for_node).
|
71
103
|
with(stored_instance,'10.100.0.10').
|
72
|
-
and_return(
|
73
|
-
|
104
|
+
and_return(double("Chef::Knife::Bootstrap",:run => true))
|
74
105
|
knife_plugin.run
|
75
106
|
end
|
76
107
|
|
77
108
|
it "should read zone value from knife config file." do
|
78
|
-
Chef::Config[:knife][:
|
79
|
-
knife_plugin = Chef::Knife::GoogleServerCreate.new([
|
80
|
-
"-
|
109
|
+
Chef::Config[:knife][:gce_zone] = stored_zone.name
|
110
|
+
knife_plugin = Chef::Knife::GoogleServerCreate.new([
|
111
|
+
"-m"+stored_machine_type.name,
|
112
|
+
"-I"+stored_image.name,
|
81
113
|
"-n"+stored_network.name,
|
82
|
-
|
83
|
-
knife_plugin.config[:
|
114
|
+
stored_instance.name])
|
115
|
+
knife_plugin.config[:service_account_scopes]=["https://www.googleapis.com/auth/userinfo.email","https://www.googleapis.com/auth/compute","https://www.googleapis.com/auth/devstorage.full_control"]
|
116
|
+
knife_plugin.config[:service_account_name]='123845678986@project.gserviceaccount.com'
|
117
|
+
knife_plugin.config[:boot_disk_size]='10'
|
84
118
|
knife_plugin.config[:metadata]=[]
|
119
|
+
knife_plugin.config[:tags]=[]
|
85
120
|
knife_plugin.config[:public_ip]='EPHEMERAL'
|
86
|
-
knife_plugin.ui.stub
|
87
|
-
|
88
|
-
knife_plugin.stub
|
121
|
+
knife_plugin.ui.stub(:info)
|
122
|
+
knife_plugin.stub(:wait_for_disk)
|
123
|
+
knife_plugin.stub(:wait_for_sshd)
|
89
124
|
knife_plugin.should_receive(:bootstrap_for_node).
|
90
|
-
with(stored_instance,'10.100.0.10').
|
91
|
-
and_return(
|
125
|
+
with(stored_instance, '10.100.0.10').
|
126
|
+
and_return(double("Chef::Knife::Bootstrap", :run => true))
|
92
127
|
knife_plugin.run
|
93
128
|
end
|
94
|
-
|
95
129
|
end
|
96
130
|
|
97
131
|
describe "without appropriate command line options" do
|
98
132
|
it "should throw exception when required params are not passed" do
|
99
|
-
$stdout.stub
|
133
|
+
$stdout.stub(:write) # lets not print those error messages
|
100
134
|
expect {
|
101
135
|
Chef::Knife::GoogleServerCreate.new([ "NAME"])
|
102
136
|
}.to raise_error(SystemExit)
|
@@ -17,84 +17,84 @@
|
|
17
17
|
require 'spec_helper'
|
18
18
|
|
19
19
|
describe Chef::Knife::GoogleServerDelete do
|
20
|
-
|
21
20
|
let(:knife_plugin) do
|
22
21
|
Chef::Knife::GoogleServerDelete.new(
|
23
22
|
[stored_instance.name, "-Z"+stored_zone.name])
|
24
23
|
end
|
25
24
|
|
26
25
|
it "should print out error message if the server is not found" do
|
27
|
-
zones =
|
26
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
28
27
|
zones.should_receive(:get).with(stored_zone.name).
|
29
28
|
and_return(stored_zone)
|
30
29
|
|
31
|
-
instances =
|
30
|
+
instances = double(Google::Compute::DeletableResourceCollection)
|
32
31
|
instances.should_receive(:get).
|
33
|
-
with(:name=>stored_instance.name, :zone=>stored_zone.name).
|
32
|
+
with(:name => stored_instance.name, :zone => stored_zone.name).
|
34
33
|
and_raise(Google::Compute::ResourceNotFound)
|
35
34
|
instances.should_not_receive(:delete)
|
36
35
|
|
37
|
-
client =
|
38
|
-
:instances=>instances, :zones=>zones)
|
39
|
-
Google::Compute::Client.stub
|
36
|
+
client = double(Google::Compute::Client,
|
37
|
+
:instances => instances, :zones => zones)
|
38
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
40
39
|
|
41
40
|
knife_plugin.config[:yes] = true
|
42
41
|
knife_plugin.ui.should_receive(:error).
|
43
42
|
with("Could not locate server '#{stored_zone.name}:#{stored_instance.name}'.")
|
44
|
-
knife_plugin.stub
|
43
|
+
knife_plugin.stub(:msg_pair)
|
45
44
|
knife_plugin.run
|
46
45
|
end
|
47
46
|
|
48
47
|
describe "without purge" do
|
49
48
|
|
50
49
|
it "should invoke api delete method when run is called" do
|
51
|
-
zones =
|
50
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
52
51
|
zones.should_receive(:get).with(stored_zone.name).
|
53
52
|
and_return(stored_zone)
|
54
53
|
|
55
|
-
instances =
|
54
|
+
instances = double(Google::Compute::DeletableResourceCollection)
|
56
55
|
instances.should_receive(:get).
|
57
|
-
with(:name=>stored_instance.name, :zone=>stored_zone.name).
|
56
|
+
with(:name => stored_instance.name, :zone => stored_zone.name).
|
58
57
|
and_return(stored_instance)
|
59
58
|
instances.should_receive(:delete).
|
60
|
-
with(:instance=>stored_instance.name, :zone=>stored_zone.name)
|
59
|
+
with(:instance => stored_instance.name, :zone => stored_zone.name)
|
61
60
|
|
62
|
-
client =
|
63
|
-
:zones=>zones, :instances=>instances)
|
64
|
-
Google::Compute::Client.stub
|
61
|
+
client = double(Google::Compute::Client,
|
62
|
+
:zones => zones, :instances => instances)
|
63
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
64
|
+
knife_plugin.ui.should_receive(:warn)
|
65
65
|
knife_plugin.config[:yes] = true
|
66
66
|
knife_plugin.ui.should_receive(:warn).twice
|
67
|
-
knife_plugin.stub
|
67
|
+
knife_plugin.stub(:msg_pair)
|
68
68
|
knife_plugin.run
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "with purge" do
|
73
73
|
it "should invoke api delete method as well as chef objects destroy when run is called" do
|
74
|
-
chef_client =
|
74
|
+
chef_client = double(Chef::ApiClient)
|
75
75
|
chef_client.should_receive(:destroy)
|
76
|
-
chef_node =
|
76
|
+
chef_node = double(Chef::Node)
|
77
77
|
chef_node.should_receive(:destroy)
|
78
78
|
|
79
|
-
zones =
|
79
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
80
80
|
zones.should_receive(:get).with(stored_zone.name).
|
81
81
|
and_return(stored_zone)
|
82
82
|
|
83
|
-
instances =
|
83
|
+
instances = double(Google::Compute::DeletableResourceCollection)
|
84
84
|
instances.should_receive(:get).
|
85
|
-
with(:name=>stored_instance.name, :zone=>stored_zone.name).
|
85
|
+
with(:name => stored_instance.name, :zone => stored_zone.name).
|
86
86
|
and_return(stored_instance)
|
87
87
|
instances.should_receive(:delete).
|
88
|
-
with(:instance=>stored_instance.name, :zone=>stored_zone.name)
|
88
|
+
with(:instance => stored_instance.name, :zone => stored_zone.name)
|
89
89
|
|
90
|
-
client =
|
91
|
-
:zones=>zones, :instances=>instances)
|
92
|
-
Google::Compute::Client.stub
|
90
|
+
client = double(Google::Compute::Client,
|
91
|
+
:zones => zones, :instances => instances)
|
92
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
93
93
|
|
94
94
|
knife_plugin.config[:yes] = true
|
95
95
|
knife_plugin.config[:purge] = true
|
96
|
-
knife_plugin.ui.stub
|
97
|
-
knife_plugin.stub
|
96
|
+
knife_plugin.ui.stub(:warn)
|
97
|
+
knife_plugin.stub(:msg_pair)
|
98
98
|
Chef::Node.should_receive(:load).with(stored_instance.name).
|
99
99
|
and_return(chef_node)
|
100
100
|
Chef::ApiClient.should_receive(:load).with(stored_instance.name).
|
@@ -106,22 +106,22 @@ end
|
|
106
106
|
|
107
107
|
describe Chef::Knife::GoogleServerDelete do
|
108
108
|
it "should read zone value from knife config file." do
|
109
|
-
Chef::Config[:knife][:
|
109
|
+
Chef::Config[:knife][:gce_zone] = stored_zone.name
|
110
110
|
knife_plugin = Chef::Knife::GoogleServerDelete.new([stored_instance.name])
|
111
|
-
zones =
|
111
|
+
zones = double(Google::Compute::ListableResourceCollection)
|
112
112
|
zones.should_receive(:get).with(stored_zone.name).and_return(stored_zone)
|
113
113
|
|
114
|
-
instances =
|
115
|
-
instances.should_receive(:get).with(:name=>stored_instance.name, :zone=>stored_zone.name).
|
114
|
+
instances = double(Google::Compute::DeletableResourceCollection)
|
115
|
+
instances.should_receive(:get).with(:name => stored_instance.name, :zone => stored_zone.name).
|
116
116
|
and_return(stored_instance)
|
117
|
-
instances.should_receive(:delete).with(:instance=>stored_instance.name, :zone=>stored_zone.name)
|
117
|
+
instances.should_receive(:delete).with(:instance => stored_instance.name, :zone => stored_zone.name)
|
118
118
|
|
119
|
-
client =
|
120
|
-
Google::Compute::Client.stub
|
119
|
+
client = double(Google::Compute::Client, :zones => zones, :instances => instances)
|
120
|
+
Google::Compute::Client.stub(:from_json).and_return(client)
|
121
|
+
knife_plugin.ui.should_receive(:warn)
|
121
122
|
knife_plugin.config[:yes] = true
|
122
123
|
knife_plugin.ui.should_receive(:warn).twice
|
123
|
-
knife_plugin.stub
|
124
|
+
knife_plugin.stub(:msg_pair)
|
124
125
|
knife_plugin.run
|
125
|
-
|
126
126
|
end
|
127
|
-
end
|
127
|
+
end
|