bosh_cli 0.19.6 → 1.0.rc1
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/bin/bosh +3 -0
- data/lib/cli.rb +15 -5
- data/lib/cli/{commands/base.rb → base_command.rb} +38 -44
- data/lib/cli/command_discovery.rb +40 -0
- data/lib/cli/command_handler.rb +135 -0
- data/lib/cli/commands/biff.rb +16 -12
- data/lib/cli/commands/blob_management.rb +10 -3
- data/lib/cli/commands/cloudcheck.rb +13 -11
- data/lib/cli/commands/complete.rb +29 -0
- data/lib/cli/commands/deployment.rb +137 -28
- data/lib/cli/commands/help.rb +96 -0
- data/lib/cli/commands/job.rb +4 -1
- data/lib/cli/commands/job_management.rb +36 -23
- data/lib/cli/commands/job_rename.rb +11 -12
- data/lib/cli/commands/log_management.rb +28 -32
- data/lib/cli/commands/maintenance.rb +6 -1
- data/lib/cli/commands/misc.rb +129 -87
- data/lib/cli/commands/package.rb +6 -65
- data/lib/cli/commands/property_management.rb +20 -8
- data/lib/cli/commands/release.rb +211 -206
- data/lib/cli/commands/ssh.rb +178 -188
- data/lib/cli/commands/stemcell.rb +114 -51
- data/lib/cli/commands/task.rb +74 -56
- data/lib/cli/commands/user.rb +6 -3
- data/lib/cli/commands/vms.rb +17 -15
- data/lib/cli/config.rb +27 -1
- data/lib/cli/core_ext.rb +27 -1
- data/lib/cli/deployment_helper.rb +47 -0
- data/lib/cli/director.rb +18 -9
- data/lib/cli/errors.rb +6 -0
- data/lib/cli/job_builder.rb +75 -23
- data/lib/cli/job_property_collection.rb +87 -0
- data/lib/cli/job_property_validator.rb +130 -0
- data/lib/cli/package_builder.rb +32 -5
- data/lib/cli/release.rb +2 -0
- data/lib/cli/release_builder.rb +9 -13
- data/lib/cli/release_compiler.rb +5 -34
- data/lib/cli/release_tarball.rb +4 -19
- data/lib/cli/runner.rb +118 -694
- data/lib/cli/version.rb +1 -1
- data/spec/assets/config/swift-hp/config/final.yml +6 -0
- data/spec/assets/config/swift-hp/config/private.yml +7 -0
- data/spec/assets/config/swift-rackspace/config/final.yml +6 -0
- data/spec/assets/config/swift-rackspace/config/private.yml +6 -0
- data/spec/spec_helper.rb +0 -5
- data/spec/unit/base_command_spec.rb +32 -37
- data/spec/unit/biff_spec.rb +11 -10
- data/spec/unit/cli_commands_spec.rb +96 -88
- data/spec/unit/core_ext_spec.rb +1 -1
- data/spec/unit/deployment_manifest_spec.rb +36 -0
- data/spec/unit/director_spec.rb +17 -3
- data/spec/unit/job_builder_spec.rb +2 -2
- data/spec/unit/job_property_collection_spec.rb +111 -0
- data/spec/unit/job_property_validator_spec.rb +7 -0
- data/spec/unit/job_rename_spec.rb +7 -6
- data/spec/unit/package_builder_spec.rb +2 -2
- data/spec/unit/release_builder_spec.rb +33 -0
- data/spec/unit/release_spec.rb +54 -0
- data/spec/unit/release_tarball_spec.rb +2 -7
- data/spec/unit/runner_spec.rb +1 -151
- data/spec/unit/ssh_spec.rb +15 -9
- metadata +41 -12
- data/lib/cli/command_definition.rb +0 -52
- data/lib/cli/templates/help_message.erb +0 -80
data/spec/unit/core_ext_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe Object do
|
|
67
67
|
it "raises a special exception to signal a premature exit" do
|
68
68
|
lambda {
|
69
69
|
err("Done")
|
70
|
-
}.should raise_error(Bosh::Cli::
|
70
|
+
}.should raise_error(Bosh::Cli::CliError, "Done")
|
71
71
|
end
|
72
72
|
|
73
73
|
it "can tell if object is blank" do
|
@@ -114,4 +114,40 @@ describe Bosh::Cli::DeploymentHelper do
|
|
114
114
|
}.to raise_error(/manifest has both `release' and `releases'/i)
|
115
115
|
end
|
116
116
|
|
117
|
+
it "resolves 'latest' release alias for multiple stemcells" do
|
118
|
+
cmd = make_cmd
|
119
|
+
manifest = {
|
120
|
+
"name" => "mycloud",
|
121
|
+
"director_uuid" => "deadbeef",
|
122
|
+
"release" => {"name" => "appcloud", "version" => 42},
|
123
|
+
"resource_pools" => [
|
124
|
+
{"stemcell" => {"name" => "foo", "version" => "latest"}},
|
125
|
+
{"stemcell" => {"name" => "foo", "version" => 22}},
|
126
|
+
{"stemcell" => {"name" => "bar", "version" => "latest"}},
|
127
|
+
]
|
128
|
+
}
|
129
|
+
|
130
|
+
manifest_file = Tempfile.new("manifest")
|
131
|
+
YAML.dump(manifest, manifest_file)
|
132
|
+
manifest_file.close
|
133
|
+
director = mock(Bosh::Cli::Director, :uuid => "deadbeef")
|
134
|
+
|
135
|
+
cmd.stub!(:deployment).and_return(manifest_file.path)
|
136
|
+
cmd.stub!(:director).and_return(director)
|
137
|
+
|
138
|
+
stemcells = [
|
139
|
+
{"name" => "foo", "version" => "22.6.4"},
|
140
|
+
{"name" => "foo", "version" => "22"},
|
141
|
+
{"name" => "bar", "version" => "4.0.8"},
|
142
|
+
{"name" => "bar", "version" => "4.1"}
|
143
|
+
]
|
144
|
+
|
145
|
+
director.should_receive(:list_stemcells).and_return(stemcells)
|
146
|
+
|
147
|
+
manifest = cmd.prepare_deployment_manifest
|
148
|
+
manifest["resource_pools"][0]["stemcell"]["version"].should == "22.6.4"
|
149
|
+
manifest["resource_pools"][1]["stemcell"]["version"].should == 22
|
150
|
+
manifest["resource_pools"][2]["stemcell"]["version"].should == 4.1
|
151
|
+
end
|
152
|
+
|
117
153
|
end
|
data/spec/unit/director_spec.rb
CHANGED
@@ -99,21 +99,27 @@ describe Bosh::Cli::Director do
|
|
99
99
|
with("/info", "application/json").
|
100
100
|
and_return([200, JSON.generate({ :version => "0.3.5"})])
|
101
101
|
@director.should_receive(:get).
|
102
|
-
with("/tasks?state=processing,cancelling,queued",
|
102
|
+
with("/tasks?state=processing,cancelling,queued&verbose=1",
|
103
|
+
"application/json").
|
103
104
|
and_return([200, JSON.generate([]), {}])
|
104
105
|
@director.list_running_tasks
|
105
106
|
end
|
106
107
|
|
107
108
|
it "lists recent tasks" do
|
108
109
|
@director.should_receive(:get).
|
109
|
-
with("/tasks?limit=30", "application/json").
|
110
|
+
with("/tasks?limit=30&verbose=1", "application/json").
|
110
111
|
and_return([200, JSON.generate([]), {}])
|
111
112
|
@director.list_recent_tasks
|
112
113
|
|
113
114
|
@director.should_receive(:get).
|
114
|
-
with("/tasks?limit=100", "application/json").
|
115
|
+
with("/tasks?limit=100&verbose=1", "application/json").
|
115
116
|
and_return([200, JSON.generate([]), {}])
|
116
117
|
@director.list_recent_tasks(100000)
|
118
|
+
|
119
|
+
@director.should_receive(:get).
|
120
|
+
with("/tasks?limit=50&verbose=2", "application/json").
|
121
|
+
and_return([200, JSON.generate([]), {}])
|
122
|
+
@director.list_recent_tasks(50, 2)
|
117
123
|
end
|
118
124
|
|
119
125
|
it "uploads release" do
|
@@ -124,6 +130,14 @@ describe Bosh::Cli::Director do
|
|
124
130
|
@director.upload_release("/path")
|
125
131
|
end
|
126
132
|
|
133
|
+
it "uploads release (with rebase)" do
|
134
|
+
@director.should_receive(:upload_and_track).
|
135
|
+
with(:post, "/releases?rebase=true", "/path",
|
136
|
+
{:content_type => "application/x-compressed"}).
|
137
|
+
and_return(true)
|
138
|
+
@director.rebase_release("/path")
|
139
|
+
end
|
140
|
+
|
127
141
|
it "gets release info" do
|
128
142
|
@director.should_receive(:get).
|
129
143
|
with("/releases/foo", "application/json").
|
@@ -375,7 +375,7 @@ describe Bosh::Cli::JobBuilder do
|
|
375
375
|
[], true, true, blobstore)
|
376
376
|
lambda {
|
377
377
|
final_builder.build
|
378
|
-
}.should raise_error(Bosh::Cli::
|
378
|
+
}.should raise_error(Bosh::Cli::CliError)
|
379
379
|
|
380
380
|
dev_builder = new_builder("foo", [], ["bar", "baz"],
|
381
381
|
[], true, false, blobstore)
|
@@ -392,7 +392,7 @@ describe Bosh::Cli::JobBuilder do
|
|
392
392
|
|
393
393
|
lambda {
|
394
394
|
final_builder3.build
|
395
|
-
}.should raise_error(Bosh::Cli::
|
395
|
+
}.should raise_error(Bosh::Cli::CliError)
|
396
396
|
end
|
397
397
|
|
398
398
|
it "allows template subdirectories" do
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Bosh::Cli::JobPropertyCollection do
|
6
|
+
|
7
|
+
def make_job(properties)
|
8
|
+
mock(Bosh::Cli::JobBuilder, :properties => properties)
|
9
|
+
end
|
10
|
+
|
11
|
+
def make(job_builder, global_properties, job_properties = {}, mappings = {})
|
12
|
+
Bosh::Cli::JobPropertyCollection.new(
|
13
|
+
job_builder, global_properties, job_properties, mappings)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "copies all properties from the manifest if no properties are defined" do
|
17
|
+
manifest_properties = {
|
18
|
+
"cc" => {
|
19
|
+
"token" => "deadbeef",
|
20
|
+
"foo" => %w(bar baz zaz)
|
21
|
+
},
|
22
|
+
"router" => {
|
23
|
+
"token" => "zbb"
|
24
|
+
},
|
25
|
+
"empty" => {}
|
26
|
+
}
|
27
|
+
|
28
|
+
job_properties = {
|
29
|
+
"cc" => {
|
30
|
+
"secret" => "22"
|
31
|
+
},
|
32
|
+
"foo" => "bar"
|
33
|
+
}
|
34
|
+
|
35
|
+
pc = make(make_job({}), manifest_properties, job_properties)
|
36
|
+
|
37
|
+
pc.to_hash.should == {
|
38
|
+
"cc" => {
|
39
|
+
"token" => "deadbeef",
|
40
|
+
"foo" => %w(bar baz zaz),
|
41
|
+
"secret" => "22"
|
42
|
+
},
|
43
|
+
"router" => {
|
44
|
+
"token" => "zbb"
|
45
|
+
},
|
46
|
+
"empty" => {},
|
47
|
+
"foo" => "bar"
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "copies only needed properties if job properties are defined" do
|
52
|
+
property_defs = {
|
53
|
+
"cc.foo" => {},
|
54
|
+
"router.token" => {},
|
55
|
+
"router.user" => {"default" => "admin"}
|
56
|
+
}
|
57
|
+
|
58
|
+
manifest_properties = {
|
59
|
+
"cc" => {
|
60
|
+
"token" => "deadbeef",
|
61
|
+
"foo" => %w(bar baz zaz)
|
62
|
+
},
|
63
|
+
"router" => {
|
64
|
+
"token" => "zbb"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
job_properties = {
|
69
|
+
"cc" => {"foo" => "bar"}
|
70
|
+
}
|
71
|
+
|
72
|
+
pc = make(make_job(property_defs), manifest_properties, job_properties)
|
73
|
+
|
74
|
+
pc.to_hash.should == {
|
75
|
+
"cc" => {"foo" => "bar"},
|
76
|
+
"router" => {"token" => "zbb", "user" => "admin"}
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "supports property mappings" do
|
81
|
+
property_defs = {
|
82
|
+
"db.user" => {},
|
83
|
+
"db.password" => {},
|
84
|
+
"token" => {}
|
85
|
+
}
|
86
|
+
|
87
|
+
properties = {
|
88
|
+
"ccdb" => {
|
89
|
+
"user" => "admin",
|
90
|
+
"password" => "secret"
|
91
|
+
},
|
92
|
+
"router" => {"token" => "deadbeef"}
|
93
|
+
}
|
94
|
+
|
95
|
+
mappings = {
|
96
|
+
"db" => "ccdb",
|
97
|
+
"token" => "router.token"
|
98
|
+
}
|
99
|
+
|
100
|
+
pc = make(make_job(property_defs), properties, {}, mappings)
|
101
|
+
|
102
|
+
pc.to_hash.should == {
|
103
|
+
"db" => {
|
104
|
+
"user" => "admin",
|
105
|
+
"password" => "secret"
|
106
|
+
},
|
107
|
+
"token" => "deadbeef"
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -29,8 +29,9 @@ describe Bosh::Cli::Command::Base do
|
|
29
29
|
job_rename = Bosh::Cli::Command::JobRename.new
|
30
30
|
|
31
31
|
lambda {
|
32
|
-
job_rename.sanity_check_job_rename(
|
33
|
-
|
32
|
+
job_rename.sanity_check_job_rename(
|
33
|
+
new_extra_changes_manifest, "old_job", "new_job")
|
34
|
+
}.should raise_error(Bosh::Cli::CliError, /cannot have any other changes/)
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should raise exception if new manifest removed some properties" do
|
@@ -42,7 +43,7 @@ describe Bosh::Cli::Command::Base do
|
|
42
43
|
|
43
44
|
lambda {
|
44
45
|
job_rename.sanity_check_job_rename(new_manifest_with_some_deletions, "old_job", "new_job")
|
45
|
-
}.should raise_error(Bosh::Cli::
|
46
|
+
}.should raise_error(Bosh::Cli::CliError, /cannot have any other changes/)
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should raise exception if deployment is not updated with new job name" do
|
@@ -50,7 +51,7 @@ describe Bosh::Cli::Command::Base do
|
|
50
51
|
|
51
52
|
lambda {
|
52
53
|
job_rename.sanity_check_job_rename(new_missing_new_job, "old_job", "new_job")
|
53
|
-
}.should raise_error(Bosh::Cli::
|
54
|
+
}.should raise_error(Bosh::Cli::CliError, /include the new job/)
|
54
55
|
end
|
55
56
|
|
56
57
|
it "should raise exception if old job name does not exist in manifest" do
|
@@ -62,7 +63,7 @@ describe Bosh::Cli::Command::Base do
|
|
62
63
|
|
63
64
|
lambda {
|
64
65
|
job_rename.sanity_check_job_rename(new_extra_changes_manifest, "non_existent_job", "new_job")
|
65
|
-
}.should raise_error(Bosh::Cli::
|
66
|
+
}.should raise_error(Bosh::Cli::CliError, /non existent job/)
|
66
67
|
end
|
67
68
|
|
68
69
|
it "should raise exception if 2 jobs are changed in manifest" do
|
@@ -74,7 +75,7 @@ describe Bosh::Cli::Command::Base do
|
|
74
75
|
|
75
76
|
lambda {
|
76
77
|
job_rename.sanity_check_job_rename(new_extra_job_rename_manifest, "old_job", "new_job")
|
77
|
-
}.should raise_error(Bosh::Cli::
|
78
|
+
}.should raise_error(Bosh::Cli::CliError, /Cannot rename more than one job/)
|
78
79
|
end
|
79
80
|
|
80
81
|
def old_manifest_yaml
|
@@ -410,7 +410,7 @@ describe Bosh::Cli::PackageBuilder, "dev build" do
|
|
410
410
|
{ "name" => "bar", "files" => globs }, @release_dir, true, blobstore)
|
411
411
|
lambda {
|
412
412
|
final_builder.build
|
413
|
-
}.should raise_error(Bosh::Cli::
|
413
|
+
}.should raise_error(Bosh::Cli::CliError)
|
414
414
|
|
415
415
|
builder = make_builder("bar", globs)
|
416
416
|
builder.build
|
@@ -427,7 +427,7 @@ describe Bosh::Cli::PackageBuilder, "dev build" do
|
|
427
427
|
{ "name" => "bar", "files" => globs }, @release_dir, true, blobstore)
|
428
428
|
lambda {
|
429
429
|
final_builder3.build
|
430
|
-
}.should raise_error(Bosh::Cli::
|
430
|
+
}.should raise_error(Bosh::Cli::CliError)
|
431
431
|
end
|
432
432
|
|
433
433
|
it "includes dotfiles in a fingerprint" do
|
@@ -80,4 +80,37 @@ describe Bosh::Cli::ReleaseBuilder do
|
|
80
80
|
builder.version.should == "7.1-dev"
|
81
81
|
end
|
82
82
|
|
83
|
+
it "has packages and jobs fingerprints in spec" do
|
84
|
+
job = mock(
|
85
|
+
Bosh::Cli::JobBuilder,
|
86
|
+
:name => "job1",
|
87
|
+
:version => "1.1",
|
88
|
+
:new_version? => true,
|
89
|
+
:packages => %w(foo),
|
90
|
+
:fingerprint => "deadbeef",
|
91
|
+
:checksum => "cafebad"
|
92
|
+
)
|
93
|
+
|
94
|
+
package = mock(
|
95
|
+
Bosh::Cli::PackageBuilder,
|
96
|
+
:name => "foo",
|
97
|
+
:version => "42",
|
98
|
+
:new_version? => true,
|
99
|
+
:fingerprint => "deadcafe",
|
100
|
+
:checksum => "baddeed",
|
101
|
+
:dependencies => []
|
102
|
+
)
|
103
|
+
|
104
|
+
builder = Bosh::Cli::ReleaseBuilder.new(@release, [package], [job])
|
105
|
+
builder.should_receive(:copy_jobs)
|
106
|
+
builder.should_receive(:copy_packages)
|
107
|
+
|
108
|
+
builder.build
|
109
|
+
|
110
|
+
manifest = YAML.load_file(builder.manifest_path)
|
111
|
+
|
112
|
+
manifest["jobs"][0]["fingerprint"].should == "deadbeef"
|
113
|
+
manifest["packages"][0]["fingerprint"].should == "deadcafe"
|
114
|
+
end
|
115
|
+
|
83
116
|
end
|
data/spec/unit/release_spec.rb
CHANGED
@@ -77,6 +77,11 @@ describe Bosh::Cli::Release do
|
|
77
77
|
r.blobstore
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should detect blobstore secrets for deprecated options" do
|
81
|
+
r = Bosh::Cli::Release.new(spec_asset("config/deprecation"))
|
82
|
+
r.has_blobstore_secret?.should be_true
|
83
|
+
end
|
84
|
+
|
80
85
|
it "should merge s3 secrets into options" do
|
81
86
|
r = Bosh::Cli::Release.new(spec_asset("config/s3"))
|
82
87
|
opts = {
|
@@ -88,6 +93,11 @@ describe Bosh::Cli::Release do
|
|
88
93
|
r.blobstore
|
89
94
|
end
|
90
95
|
|
96
|
+
it "should detect blobstore secrets for s3 options" do
|
97
|
+
r = Bosh::Cli::Release.new(spec_asset("config/s3"))
|
98
|
+
r.has_blobstore_secret?.should be_true
|
99
|
+
end
|
100
|
+
|
91
101
|
it "should merge atmos secrets into options" do
|
92
102
|
r = Bosh::Cli::Release.new(spec_asset("config/atmos"))
|
93
103
|
opts = {
|
@@ -97,5 +107,49 @@ describe Bosh::Cli::Release do
|
|
97
107
|
Bosh::Blobstore::Client.should_receive(:create).with("atmos", opts)
|
98
108
|
r.blobstore
|
99
109
|
end
|
110
|
+
|
111
|
+
it "should detect blobstore secrets for atmos options" do
|
112
|
+
r = Bosh::Cli::Release.new(spec_asset("config/atmos"))
|
113
|
+
r.has_blobstore_secret?.should be_true
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should merge swift (HP) secrets into options" do
|
117
|
+
r = Bosh::Cli::Release.new(spec_asset("config/swift-hp"))
|
118
|
+
opts = {
|
119
|
+
:container_name => "test",
|
120
|
+
:swift_provider => "hp",
|
121
|
+
:hp => {
|
122
|
+
:hp_account_id => "foo",
|
123
|
+
:hp_secret_key => "bar",
|
124
|
+
:hp_tenant_id => "foo"
|
125
|
+
}
|
126
|
+
}
|
127
|
+
Bosh::Blobstore::Client.should_receive(:create).with("swift", opts)
|
128
|
+
r.blobstore
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should detect blobstore secrets for swift (HP) options" do
|
132
|
+
r = Bosh::Cli::Release.new(spec_asset("config/swift-hp"))
|
133
|
+
r.has_blobstore_secret?.should be_true
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should merge swift (Rackspace) secrets into options" do
|
137
|
+
r = Bosh::Cli::Release.new(spec_asset("config/swift-rackspace"))
|
138
|
+
opts = {
|
139
|
+
:container_name => "test",
|
140
|
+
:swift_provider => "rackspace",
|
141
|
+
:rackspace => {
|
142
|
+
:rackspace_username => "foo",
|
143
|
+
:rackspace_api_key => "bar"
|
144
|
+
}
|
145
|
+
}
|
146
|
+
Bosh::Blobstore::Client.should_receive(:create).with("swift", opts)
|
147
|
+
r.blobstore
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should detect blobstore secrets for swift (Rackspace) options" do
|
151
|
+
r = Bosh::Cli::Release.new(spec_asset("config/swift-rackspace"))
|
152
|
+
r.has_blobstore_secret?.should be_true
|
153
|
+
end
|
100
154
|
end
|
101
155
|
end
|
@@ -12,15 +12,10 @@ describe Bosh::Cli::ReleaseTarball do
|
|
12
12
|
|
13
13
|
it "verifies repacked release if appropriate option is set" do
|
14
14
|
tarball = Bosh::Cli::ReleaseTarball.new(spec_asset("valid_release.tgz"))
|
15
|
-
remote_release = {
|
16
|
-
"packages" => [{ "name" => "mutator", "version" => "2.99.7" }],
|
17
|
-
"jobs" => [{ "name" => "cacher", "version" => "1" },
|
18
|
-
{ "name" => "sweeper", "version" => "1" }]
|
19
|
-
}
|
20
15
|
package_matches = ["86bd8b15562cde007f030a303fa64779af5fa4e7"]
|
21
|
-
repacked_tarball_path = tarball.repack(
|
16
|
+
repacked_tarball_path = tarball.repack(package_matches)
|
22
17
|
|
23
|
-
tarball.skipped.should ==
|
18
|
+
tarball.skipped.should == 1
|
24
19
|
|
25
20
|
repacked_tarball = Bosh::Cli::ReleaseTarball.new(repacked_tarball_path)
|
26
21
|
repacked_tarball.valid?.should be_false
|
data/spec/unit/runner_spec.rb
CHANGED
@@ -3,155 +3,5 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe Bosh::Cli::Runner do
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
@out = StringIO.new
|
9
|
-
Bosh::Cli::Config.output = @out
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_cmd(args, namespace, action, cmd_args = [])
|
13
|
-
runner = Bosh::Cli::Runner.new(args)
|
14
|
-
runner.prepare
|
15
|
-
runner.dispatch
|
16
|
-
|
17
|
-
runner.namespace.should == namespace
|
18
|
-
runner.action.should == action
|
19
|
-
runner.args.should == cmd_args
|
20
|
-
end
|
21
|
-
|
22
|
-
it "has a set of default global options" do
|
23
|
-
runner = Bosh::Cli::Runner.new(["do", "some", "stuff"])
|
24
|
-
runner.parse_options!
|
25
|
-
runner.options[:verbose].should == nil
|
26
|
-
runner.options[:colorize].should == true
|
27
|
-
runner.options[:director_checks].should == true
|
28
|
-
runner.options[:quiet].should == nil
|
29
|
-
runner.options[:non_interactive].should == nil
|
30
|
-
end
|
31
|
-
|
32
|
-
it "allows overriding global options" do
|
33
|
-
runner = Bosh::Cli::Runner.new(["--verbose", "--no-color",
|
34
|
-
"--skip-director-checks", "--quiet",
|
35
|
-
"--non-interactive", "release",
|
36
|
-
"upload", "/path"])
|
37
|
-
runner.parse_options!
|
38
|
-
runner.options[:verbose].should == true
|
39
|
-
runner.options[:colorize].should == false
|
40
|
-
runner.options[:director_checks].should == false
|
41
|
-
runner.options[:quiet].should == true
|
42
|
-
runner.options[:non_interactive].should == true
|
43
|
-
end
|
44
|
-
|
45
|
-
it "allows specifying target, deployment and credentials via command line" do
|
46
|
-
runner = Bosh::Cli::Runner.new([
|
47
|
-
"--target", "foo",
|
48
|
-
"--deployment", "bar",
|
49
|
-
"--user", "baz",
|
50
|
-
"--password", "deadbeef"
|
51
|
-
])
|
52
|
-
runner.parse_options!
|
53
|
-
runner.options[:target].should == "foo"
|
54
|
-
runner.options[:deployment].should == "bar"
|
55
|
-
runner.options[:username].should == "baz"
|
56
|
-
runner.options[:password].should == "deadbeef"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "dispatches commands to appropriate methods (nu school)" do
|
60
|
-
test_cmd(["version"], :misc, :version)
|
61
|
-
test_cmd(["status"], :misc, :status)
|
62
|
-
test_cmd(["alias", "test", "alias"], :misc, :set_alias, ["test", "alias"])
|
63
|
-
test_cmd(["aliases"], :misc, :list_aliases)
|
64
|
-
test_cmd(["target"], :misc, :show_target)
|
65
|
-
test_cmd(["target", "test"], :misc, :set_target, ["test"])
|
66
|
-
test_cmd(["target", "test", "alias"], :misc, :set_target, ["test", "alias"])
|
67
|
-
test_cmd(["targets"], :misc, :list_targets)
|
68
|
-
test_cmd(["deploy"], :deployment, :perform)
|
69
|
-
test_cmd(["deployment"], :deployment, :show_current)
|
70
|
-
test_cmd(["deployment", "test"], :deployment, :set_current, ["test"])
|
71
|
-
|
72
|
-
test_cmd(["delete", "deployment", "foo"], :deployment, :delete, ["foo"])
|
73
|
-
test_cmd(["delete", "stemcell", "a", "1"], :stemcell, :delete, ["a", "1"])
|
74
|
-
test_cmd(["delete", "release", "a"], :release, :delete, ["a"])
|
75
|
-
test_cmd(["delete", "release", "a", "--force"],
|
76
|
-
:release, :delete, ["a", "--force"])
|
77
|
-
test_cmd(["delete", "release", "a", "2.2.1", "--force"],
|
78
|
-
:release, :delete, ["a", "2.2.1", "--force"])
|
79
|
-
|
80
|
-
test_cmd(["create", "user", "admin"], :user, :create, ["admin"])
|
81
|
-
test_cmd(["create", "user", "admin", "12321"],
|
82
|
-
:user, :create, ["admin", "12321"])
|
83
|
-
test_cmd(["create", "release"], :release, :create)
|
84
|
-
test_cmd(["reset", "release"], :release, :reset)
|
85
|
-
test_cmd(["create", "package", "bla"], :package, :create, ["bla"])
|
86
|
-
|
87
|
-
test_cmd(["login", "admin", "12321"], :misc, :login, ["admin", "12321"])
|
88
|
-
test_cmd(["logout"], :misc, :logout)
|
89
|
-
test_cmd(["purge"], :misc, :purge_cache)
|
90
|
-
|
91
|
-
test_cmd(["init", "release"], :release, :init)
|
92
|
-
test_cmd(["init", "release", "/path"], :release, :init, ["/path"])
|
93
|
-
|
94
|
-
test_cmd(["upload", "release", "/path"], :release, :upload, ["/path"])
|
95
|
-
test_cmd(["upload", "release"], :release, :upload)
|
96
|
-
test_cmd(["upload", "stemcell", "/path"], :stemcell, :upload, ["/path"])
|
97
|
-
|
98
|
-
test_cmd(["generate", "package", "foo"], :package, :generate, ["foo"])
|
99
|
-
test_cmd(["generate", "job", "baz"], :job, :generate, ["baz"])
|
100
|
-
|
101
|
-
test_cmd(["verify", "release", "/path"], :release, :verify, ["/path"])
|
102
|
-
test_cmd(["verify", "stemcell", "/path"], :stemcell, :verify, ["/path"])
|
103
|
-
|
104
|
-
test_cmd(["stemcells"], :stemcell, :list)
|
105
|
-
test_cmd(["releases"], :release, :list)
|
106
|
-
test_cmd(["deployments"], :deployment, :list)
|
107
|
-
|
108
|
-
test_cmd(["tasks"], :task, :list_running)
|
109
|
-
test_cmd(["task", "500"], :task, :track, ["500"])
|
110
|
-
test_cmd(["tasks"], :task, :list_running)
|
111
|
-
test_cmd(["tasks", "recent"], :task, :list_recent)
|
112
|
-
test_cmd(["tasks", "recent", "42"], :task, :list_recent, ["42"])
|
113
|
-
|
114
|
-
test_cmd(%w(blobs), :blob_management, :status)
|
115
|
-
test_cmd(%w(add blob foo bar), :blob_management, :add, %w(foo bar))
|
116
|
-
test_cmd(%w(upload blobs), :blob_management, :upload)
|
117
|
-
test_cmd(%w(sync blobs), :blob_management, :sync)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "loads custom plugins" do
|
121
|
-
plugin_path = spec_asset("plugins")
|
122
|
-
$:.unshift(plugin_path)
|
123
|
-
|
124
|
-
begin
|
125
|
-
test_cmd(["banner", "foo"], :echo, :banner, ["foo"])
|
126
|
-
test_cmd(["say", "bar"], :echo, :say_color, ["bar"])
|
127
|
-
test_cmd(["say", "baz", "--color", "red"],
|
128
|
-
:echo, :say_color, ["baz", "--color", "red"])
|
129
|
-
|
130
|
-
test_cmd(["ruby", "version"], :ruby, :ruby_version)
|
131
|
-
test_cmd(["ruby", "config", "arch"], :ruby, :ruby_config, ["arch"])
|
132
|
-
ensure
|
133
|
-
$:.shift.should == plugin_path
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "command completion" do
|
138
|
-
let(:runner) { r = Bosh::Cli::Runner.new([]); r.prepare; r }
|
139
|
-
|
140
|
-
it "should complete 'cr' to 'create'" do
|
141
|
-
runner.complete("cr").should == %w[create]
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should complete 'create' to 'package, release & user'" do
|
145
|
-
completion = runner.complete("create")
|
146
|
-
completion.should include("package")
|
147
|
-
completion.should include("release")
|
148
|
-
completion.should include("user")
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should complete 'cr' to 'create'" do
|
152
|
-
runner.complete("create u").should == %w[user]
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
6
|
+
pending "needs tests"
|
157
7
|
end
|