bebox 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +13 -5
- data/lib/bebox/commands/commands_helper.rb +4 -2
- data/lib/bebox/commands/prepare_commands.rb +2 -2
- data/lib/bebox/commands/project_commands.rb +12 -3
- data/lib/bebox/commands/provision_commands.rb +1 -3
- data/lib/bebox/commands/role_commands.rb +1 -1
- data/lib/bebox/vagrant_helper.rb +1 -1
- data/lib/bebox/version.rb +1 -1
- data/lib/bebox/wizards/project_wizard.rb +1 -1
- data/spec/cli_spec.rb +366 -0
- data/spec/environment_spec.rb +1 -1
- data/spec/fixtures/commands/environment_help.test +1 -0
- data/spec/fixtures/commands/general_help.test +1 -0
- data/spec/fixtures/commands/in_project_help.test +1 -0
- data/spec/fixtures/commands/node_help.test +1 -0
- data/spec/fixtures/commands/profile_help.test +1 -0
- data/spec/fixtures/commands/role_help.test +1 -0
- data/spec/node0.server1.test/prepare_phase_spec.rb +1 -1
- data/spec/node0.server1.test/provision_step_0_spec.rb +1 -1
- data/spec/node0.server1.test/provision_step_1_spec.rb +1 -1
- data/spec/node0.server1.test/provision_step_2_spec.rb +1 -1
- data/spec/node0.server1.test/provision_step_3_spec.rb +1 -1
- data/spec/node_role_spec.rb +1 -1
- data/spec/node_spec.rb +1 -1
- data/spec/ordered_phases_spec.rb +1 -0
- data/spec/pre_prepare_spec.rb +1 -1
- data/spec/pre_provision_steps_spec.rb +1 -1
- data/spec/profile_spec.rb +1 -1
- data/spec/project_spec.rb +1 -1
- data/spec/role_profiles_spec.rb +1 -1
- data/spec/role_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -17
- data/spec/wizards/environment_wizard_spec.rb +1 -1
- data/spec/wizards/node_wizard_spec.rb +1 -1
- data/spec/wizards/profile_wizard_spec.rb +1 -1
- data/spec/wizards/project_wizard_spec.rb +49 -17
- data/spec/wizards/provision_wizard_spec.rb +1 -1
- data/spec/wizards/role_wizard_spec.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 886423855b71a864742480b34b9a13809cebd033
|
4
|
+
data.tar.gz: fef0a3dbcc6cf4122f83514933e044edf0510227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f493c919fba06dce468d5b0ca50af84404f45e00d3e8f5cb7b5f24990e3a8316cf8d97ea8221a514a09db34218e0e2e32ee8b405a740d1ea7a7324fed1f6e69
|
7
|
+
data.tar.gz: 1ec1b8514c512cc454900568885381874626951ad437be9f945da7cbe926a581ea386eed987e4c2001e68d659a9aa8f78ff2922c9de62fc308fba72286a6a4f0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -365,12 +365,20 @@ To use the project in development mode, you need to do this:
|
|
365
365
|
Tests
|
366
366
|
-----
|
367
367
|
|
368
|
-
|
368
|
+
Running the bebox tests require first to do some configurations:
|
369
369
|
|
370
|
-
|
370
|
+
* First you need to have the [ubuntu-server-12042-x64-vbox4210-nocm.box](http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box) in the bebox root folder to run the tests. This is the vagrant box used for the test project.
|
371
371
|
|
372
|
-
|
372
|
+
* Configure a free IP address for the test vagrant machine. To do this create the file *spec/support/config_specs.yaml* from the *spec/support/config_specs.yaml.example* and edit the file with the free IP address from your local network.
|
373
|
+
|
374
|
+
cp spec/support/config_specs.yaml.example spec/support/config_specs.yaml
|
373
375
|
|
374
|
-
|
376
|
+
* Make a tmp directory inside bebox root folder. This is the directory where the test project would be created temporarily.
|
377
|
+
|
378
|
+
mkdir tmp
|
379
|
+
|
380
|
+
By project's nature the specs must be run in order. To do this all specs has a 'Test XX:' naming convention. If you want to run all tests in order we have a ordered_phases_spec.rb file than you can run with:
|
381
|
+
|
382
|
+
rspec spec/ordered_phases_spec.rb
|
375
383
|
|
376
|
-
|
384
|
+
It would take a large time (at least 20 minutes) because it creates a vagrant machine and do a basic provision downloading packages and installing them in the machine. Also it can ask for some input (password, interface selection) during the process. The vagrant machine and the bebox test project would be destroyed after completion.
|
@@ -1,7 +1,9 @@
|
|
1
1
|
|
2
2
|
module Bebox
|
3
3
|
module CommandsHelper
|
4
|
+
|
4
5
|
include Bebox::WizardsHelper
|
6
|
+
|
5
7
|
# Obtain the environment from command parameters or menu
|
6
8
|
def get_environment(options)
|
7
9
|
environment = options[:environment]
|
@@ -22,12 +24,12 @@ module Bebox
|
|
22
24
|
end
|
23
25
|
|
24
26
|
# Check if vagrant is installed on the machine
|
25
|
-
def vagrant_installed?
|
27
|
+
def self.vagrant_installed?
|
26
28
|
(`which vagrant`) == 'vagrant not found' ? false : true
|
27
29
|
end
|
28
30
|
|
29
31
|
# Check if the step argument is valid
|
30
|
-
def valid_step?(step)
|
32
|
+
def self.valid_step?(step)
|
31
33
|
steps = %w{step-0 step-1 step-2 step-3}
|
32
34
|
steps.include?(step)
|
33
35
|
end
|
@@ -14,7 +14,7 @@ module Bebox
|
|
14
14
|
prepare_command.action do |global_options,options,args|
|
15
15
|
environment = get_environment(options)
|
16
16
|
# Check if vagrant is installed
|
17
|
-
return error('Vagrant is not installed in the system. No changes were made.') unless vagrant_installed?
|
17
|
+
return error('Vagrant is not installed in the system. No changes were made.') unless Bebox::CommandsHelper.vagrant_installed?
|
18
18
|
title "Environment: #{environment}"
|
19
19
|
Bebox::NodeWizard.new.prepare(project_root, environment)
|
20
20
|
end
|
@@ -40,7 +40,7 @@ module Bebox
|
|
40
40
|
|
41
41
|
def vagrant_command(command, message)
|
42
42
|
# Check if vagrant is installed
|
43
|
-
return error('Vagrant is not installed in the system. No changes were made.') unless vagrant_installed?
|
43
|
+
return error('Vagrant is not installed in the system. No changes were made.') unless Bebox::CommandsHelper.vagrant_installed?
|
44
44
|
nodes = Bebox::Node.nodes_in_environment(project_root, 'vagrant', 'nodes')
|
45
45
|
environment = 'vagrant'
|
46
46
|
title "Environment: #{environment}\n#{message}"
|
@@ -11,6 +11,7 @@ module Bebox
|
|
11
11
|
def load_commands
|
12
12
|
load_environment_commands
|
13
13
|
load_node_commands
|
14
|
+
load_role_profile_commands
|
14
15
|
load_prepare_commands
|
15
16
|
load_provision_commands
|
16
17
|
end
|
@@ -22,17 +23,25 @@ module Bebox
|
|
22
23
|
|
23
24
|
# Load node commands if there are environments configured
|
24
25
|
def load_node_commands
|
25
|
-
|
26
|
+
(self.extend Bebox::NodeCommands) if Bebox::Environment.list(project_root).count > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
# Load role/profile commands
|
30
|
+
def load_role_profile_commands
|
31
|
+
if Bebox::Node.count_all_nodes_by_type(project_root, 'nodes') > 0
|
32
|
+
self.extend Bebox::RoleCommands
|
33
|
+
self.extend Bebox::ProfileCommands
|
34
|
+
end
|
26
35
|
end
|
27
36
|
|
28
37
|
# Load prepare commands if there are at least one node
|
29
38
|
def load_prepare_commands
|
30
|
-
Bebox::Node.count_all_nodes_by_type(project_root, 'nodes') > 0
|
39
|
+
(self.extend Bebox::PrepareCommands) if Bebox::Node.count_all_nodes_by_type(project_root, 'nodes') > 0
|
31
40
|
end
|
32
41
|
|
33
42
|
# Load provision commands if there are nodes prepared
|
34
43
|
def load_provision_commands
|
35
|
-
Bebox::Node.count_all_nodes_by_type(project_root, 'prepared_nodes') > 0
|
44
|
+
(self.extend Bebox::ProvisionCommands) if Bebox::Node.count_all_nodes_by_type(project_root, 'prepared_nodes') > 0
|
36
45
|
end
|
37
46
|
end
|
38
47
|
end
|
@@ -8,8 +8,6 @@ module Bebox
|
|
8
8
|
|
9
9
|
def load_commands
|
10
10
|
load_provision_commands
|
11
|
-
self.extend Bebox::RoleCommands
|
12
|
-
self.extend Bebox::ProfileCommands
|
13
11
|
end
|
14
12
|
|
15
13
|
def load_provision_commands
|
@@ -36,7 +34,7 @@ module Bebox
|
|
36
34
|
def apply(environment, args)
|
37
35
|
step = args.first
|
38
36
|
help_now!(error('You did not specify an step')) if args.count == 0
|
39
|
-
help_now!(error('You did not specify a valid step')) unless valid_step?(step)
|
37
|
+
help_now!(error('You did not specify a valid step')) unless Bebox::CommandsHelper.valid_step?(step)
|
40
38
|
Bebox::ProvisionWizard.new.apply_step(project_root, environment, step)
|
41
39
|
end
|
42
40
|
end
|
@@ -13,7 +13,7 @@ module Bebox
|
|
13
13
|
generate_role_command(role_command, :remove, :remove_role, 'Remove a role from the project')
|
14
14
|
role_list_command(role_command)
|
15
15
|
# These commands are available if there are at least one role and one profile
|
16
|
-
(Bebox::Role.roles_count(project_root) > 0 && Bebox::Profile.profiles_count(project_root) > 0)
|
16
|
+
load_role_profile_commands(role_command) if (Bebox::Role.roles_count(project_root) > 0 && Bebox::Profile.profiles_count(project_root) > 0)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/bebox/vagrant_helper.rb
CHANGED
@@ -43,7 +43,7 @@ module Bebox
|
|
43
43
|
|
44
44
|
# Add the vagrant hosts to the local hosts file
|
45
45
|
def add_to_local_hosts(node)
|
46
|
-
host_command = "
|
46
|
+
host_command = "echo '#{node.ip} #{node.hostname} # Added by bebox' | sudo tee -a #{local_hosts_path}/hosts"
|
47
47
|
`#{host_command}` unless (file_content_trimmed("#{local_hosts_path}/hosts") =~ /#{node.ip}\s+#{node.hostname}/)
|
48
48
|
end
|
49
49
|
|
data/lib/bebox/version.rb
CHANGED
@@ -9,7 +9,7 @@ module Bebox
|
|
9
9
|
# Asks for the project parameters and create the project skeleton
|
10
10
|
def create_new_project(project_name)
|
11
11
|
# Check project existence
|
12
|
-
|
12
|
+
(error('Project not created. There is already a project with that name in the current directory.'); return false) if project_exists?(Dir.pwd, project_name)
|
13
13
|
# Setup the bebox boxes directory
|
14
14
|
bebox_boxes_setup
|
15
15
|
# Asks to choose an existing box
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,366 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'factories/environment.rb'
|
3
|
+
require_relative 'factories/node.rb'
|
4
|
+
require_relative 'factories/profile.rb'
|
5
|
+
require_relative 'factories/role.rb'
|
6
|
+
|
7
|
+
describe 'Test 00: Bebox::Cli' do
|
8
|
+
|
9
|
+
let(:environment) { build(:environment) }
|
10
|
+
let(:node) { build(:node) }
|
11
|
+
let(:profile) { build(:profile) }
|
12
|
+
let(:role) { build(:role) }
|
13
|
+
|
14
|
+
before :each do
|
15
|
+
$stderr.stub(:write)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'shows the help for general commands' do
|
19
|
+
argv = []
|
20
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
21
|
+
expected_content = File.read("spec/fixtures/commands/general_help.test").gsub(/\s+/, ' ').strip
|
22
|
+
expect(output.gsub(/\s+/, ' ').strip).to eq(expected_content)
|
23
|
+
end
|
24
|
+
|
25
|
+
context '00: general commands' do
|
26
|
+
it 'shows error for new without project name' do
|
27
|
+
argv = ['new']
|
28
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
29
|
+
expect(output).to match(/You did not supply a project name/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'executes new project command' do
|
33
|
+
argv = ['new', 'pname']
|
34
|
+
Bebox::ProjectWizard.any_instance.stub(:create_new_project) { true }
|
35
|
+
capture(:stdout) { cli_command(argv, :success) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context '01: project commands' do
|
40
|
+
|
41
|
+
before :each do
|
42
|
+
Bebox::Cli.any_instance.stub(:inside_project?) { true }
|
43
|
+
Bebox::Environment.stub(:environment_exists?) { true }
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'shows the help for project commands' do
|
47
|
+
argv = []
|
48
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
49
|
+
expected_content = File.read("spec/fixtures/commands/in_project_help.test").gsub(/\s+/, ' ').strip
|
50
|
+
expect(output.gsub(/\s+/, ' ').strip).to eq(expected_content)
|
51
|
+
end
|
52
|
+
|
53
|
+
context '02: environment commands' do
|
54
|
+
|
55
|
+
it 'shows the help for environment commands' do
|
56
|
+
argv = ['help', 'environment']
|
57
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
58
|
+
expected_content = File.read("spec/fixtures/commands/environment_help.test").gsub(/\s+/, ' ').strip
|
59
|
+
expect(output.gsub(/\s+/, ' ').strip).to eq(expected_content)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'list environments' do
|
63
|
+
Bebox::Environment.stub(:list) { [environment.name] }
|
64
|
+
argv = ['environment', 'list']
|
65
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
66
|
+
expect(output).to match(/Current environments:.*?#{environment.name}/im)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'not list environments if there are not any' do
|
70
|
+
Bebox::Environment.stub(:list) { [] }
|
71
|
+
argv = ['environment', 'list']
|
72
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
73
|
+
expect(output).to match(/Current environments:.*?There are not environments yet. You can create a new one with: 'bebox environment new' command./im)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'fails to create a new environment without name' do
|
77
|
+
Bebox::EnvironmentWizard.any_instance.stub(:send) { true }
|
78
|
+
argv = ['environment', 'new']
|
79
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
80
|
+
expect(output).to match(/You did not supply an environment/)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'creates a new environment with name' do
|
84
|
+
Bebox::EnvironmentWizard.any_instance.stub(:send) { true }
|
85
|
+
argv = ['environment', 'new', environment.name]
|
86
|
+
capture(:stdout) { cli_command(argv, :success) }
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'fails to remove an environment without name' do
|
90
|
+
Bebox::EnvironmentWizard.any_instance.stub(:send) { true }
|
91
|
+
argv = ['environment', 'remove']
|
92
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
93
|
+
expect(output).to match(/You did not supply an environment/)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'removes an environment with name' do
|
97
|
+
Bebox::EnvironmentWizard.any_instance.stub(:send) { true }
|
98
|
+
argv = ['environment', 'remove', environment.name]
|
99
|
+
capture(:stdout) { cli_command(argv, :success) }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context '03: node commands' do
|
104
|
+
|
105
|
+
before :each do
|
106
|
+
Bebox::Environment.stub(:list) { [node.environment] }
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'shows the help for node commands' do
|
110
|
+
argv = ['help', 'node']
|
111
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
112
|
+
expected_content = File.read("spec/fixtures/commands/node_help.test").gsub(/\s+/, ' ').strip
|
113
|
+
expect(output.gsub(/\s+/, ' ').strip).to eq(expected_content)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'list nodes if there are any' do
|
117
|
+
Bebox::Node.stub(:list) { [node.hostname] }
|
118
|
+
argv = ['node', 'list']
|
119
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
120
|
+
expect(output).to match(/Nodes for '#{node.environment}' environment:.*?#{node.hostname}/m)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'not list nodes if there are not any' do
|
124
|
+
Bebox::Node.stub(:list) { [] }
|
125
|
+
argv = ['node', 'list']
|
126
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
127
|
+
expect(output).to match(/Nodes for '#{node.environment}' environment:.*?There are not nodes yet in the environment. You can create a new one with: 'bebox node new' command./m)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'sets a role for a node' do
|
131
|
+
Bebox::Profile.stub(:profiles_count) { 1 }
|
132
|
+
Bebox::Role.stub(:roles_count) { 1 }
|
133
|
+
Bebox::Node.stub(:count_all_nodes_by_type) { 1 }
|
134
|
+
Bebox::NodeWizard.any_instance.stub(:send) { true }
|
135
|
+
argv = ['node', 'set_role']
|
136
|
+
capture(:stdout) { cli_command(argv, :success) }
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'creates a new node' do
|
140
|
+
Bebox::NodeWizard.any_instance.stub(:send) { true }
|
141
|
+
argv = ['node', 'new']
|
142
|
+
capture(:stdout) { cli_command(argv, :success) }
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'removes a node' do
|
146
|
+
Bebox::EnvironmentWizard.any_instance.stub(:send) { true }
|
147
|
+
argv = ['node', 'remove']
|
148
|
+
capture(:stdout) { cli_command(argv, :success) }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context '04: prepare commands' do
|
153
|
+
|
154
|
+
before :each do
|
155
|
+
Bebox::Node.stub(:count_all_nodes_by_type) { 1 }
|
156
|
+
Bebox::Node.stub(:list) { [node] }
|
157
|
+
Bebox::Node.stub(:nodes_in_environment) { [node] }
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'shows an error if vagrant is not installed' do
|
161
|
+
Bebox::CommandsHelper.stub(:vagrant_installed?) { false }
|
162
|
+
argv = ['prepare']
|
163
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
164
|
+
expect(output).to match(/Vagrant is not installed in the system. No changes were made./m)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'prepares a node' do
|
168
|
+
Bebox::NodeWizard.any_instance.stub(:prepare) { true }
|
169
|
+
argv = ['prepare']
|
170
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'halts a vagrant node' do
|
174
|
+
Bebox::VagrantHelper.stub(:send) { true }
|
175
|
+
argv = ['vagrant_halt']
|
176
|
+
capture(:stdout) { cli_command(argv, :success) }
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'ups a vagrant node' do
|
180
|
+
Bebox::VagrantHelper.stub(:send) { true }
|
181
|
+
argv = ['vagrant_up']
|
182
|
+
capture(:stdout) { cli_command(argv, :success) }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context '05: profile commands' do
|
187
|
+
|
188
|
+
before :each do
|
189
|
+
Bebox::Node.stub(:count_all_nodes_by_type) { 1 }
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'shows the help for profile commands' do
|
193
|
+
argv = ['help', 'profile']
|
194
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
195
|
+
expected_content = File.read("spec/fixtures/commands/profile_help.test").gsub(/\s+/, ' ').strip
|
196
|
+
expect(output.gsub(/\s+/, ' ').strip).to eq(expected_content)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'list profiles if there are any' do
|
200
|
+
Bebox::ProfileWizard.any_instance.stub(:list_profiles) { [profile.name] }
|
201
|
+
argv = ['profile', 'list']
|
202
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
203
|
+
expect(output).to match(/Current profiles:.*?#{profile.name}/m)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'not list profiles if there are not any' do
|
207
|
+
Bebox::ProfileWizard.any_instance.stub(:list_profiles) { [] }
|
208
|
+
argv = ['profile', 'list']
|
209
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
210
|
+
expect(output).to match(/There are not profiles yet. You can create a new one with: 'bebox profile new' command./m)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'can not create a new profile without name' do
|
214
|
+
argv = ['profile', 'new']
|
215
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
216
|
+
expect(output).to match(/You did not supply a name/)
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'creates a new profile with name' do
|
220
|
+
Bebox::ProfileWizard.any_instance.stub(:create_new_profile) { true }
|
221
|
+
argv = ['profile', 'new', profile.name]
|
222
|
+
capture(:stdout) { cli_command(argv, :success) }
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'removes a profile' do
|
226
|
+
Bebox::ProfileWizard.any_instance.stub(:remove_profile) { true }
|
227
|
+
argv = ['profile', 'remove', profile.name]
|
228
|
+
capture(:stdout) { cli_command(argv, :success) }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context '06: role commands' do
|
233
|
+
|
234
|
+
before :each do
|
235
|
+
Bebox::Profile.stub(:profiles_count) { 1 }
|
236
|
+
Bebox::Role.stub(:roles_count) { 1 }
|
237
|
+
Bebox::Node.stub(:count_all_nodes_by_type) { 1 }
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'shows the help for role commands' do
|
241
|
+
argv = ['help', 'role']
|
242
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
243
|
+
expected_content = File.read("spec/fixtures/commands/role_help.test").gsub(/\s+/, ' ').strip
|
244
|
+
expect(output.gsub(/\s+/, ' ').strip).to eq(expected_content)
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'list roles if there are any' do
|
248
|
+
Bebox::Role.stub(:list) { [role.name] }
|
249
|
+
argv = ['role', 'list']
|
250
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
251
|
+
expect(output).to match(/Current roles:.*?#{role.name}/m)
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'not list roles if there are not any' do
|
255
|
+
Bebox::Role.stub(:list) { [] }
|
256
|
+
argv = ['role', 'list']
|
257
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
258
|
+
expect(output).to match(/There are not roles yet. You can create a new one with: 'bebox role new' command./m)
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'can not create a new role without name' do
|
262
|
+
argv = ['role', 'new']
|
263
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
264
|
+
expect(output).to match(/You did not supply a name/)
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'creates a new role with name' do
|
268
|
+
Bebox::ProfileWizard.any_instance.stub(:create_new_role) { true }
|
269
|
+
argv = ['role', 'new', role.name]
|
270
|
+
capture(:stdout) { cli_command(argv, :success) }
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'removes a role' do
|
274
|
+
Bebox::RoleWizard.any_instance.stub(:send) { true }
|
275
|
+
argv = ['role', 'remove']
|
276
|
+
capture(:stdout) { cli_command(argv, :success) }
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'can not list role profiles without a role name' do
|
280
|
+
argv = ['role', 'list_profiles']
|
281
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
282
|
+
expect(output).to match(/You did not supply a role name./m)
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'can not list role profiles if role not exist' do
|
286
|
+
Bebox::RoleWizard.any_instance.stub(:role_exists?) { false }
|
287
|
+
argv = ['role', 'list_profiles', role.name]
|
288
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
289
|
+
expect(output).to match(/The '#{role.name}' role does not exist./m)
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'not list role profiles if there are not any' do
|
293
|
+
Bebox::RoleWizard.any_instance.stub(:role_exists?) { true }
|
294
|
+
Bebox::Role.stub(:list_profiles) { [] }
|
295
|
+
argv = ['role', 'list_profiles', role.name]
|
296
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
297
|
+
expect(output).to match(/There are not profiles in role '#{role.name}'. You can add a new one with: 'bebox role add_profile' command./m)
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'list role profiles if there are any' do
|
301
|
+
Bebox::RoleWizard.any_instance.stub(:role_exists?) { true }
|
302
|
+
Bebox::Role.stub(:list_profiles) { [profile.name] }
|
303
|
+
argv = ['role', 'list_profiles', role.name]
|
304
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
305
|
+
expect(output).to match(/Current profiles in '#{role.name}' role:.*?#{profile.name}/m)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context '07: provision commands' do
|
310
|
+
|
311
|
+
before :each do
|
312
|
+
Bebox::Node.stub(:count_all_nodes_by_type) { 1 }
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'can not apply provision if the step is not supplied' do
|
316
|
+
argv = ['apply']
|
317
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
318
|
+
expect(output).to match(/You did not specify an step/m)
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'can not apply provision if the step is not valid' do
|
322
|
+
argv = ['apply', 'step']
|
323
|
+
output = capture(:stdout) { cli_command(argv, :failure) }
|
324
|
+
expect(output).to match(/You did not specify a valid step/m)
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'applies provision if the step is valid' do
|
328
|
+
Bebox::ProvisionWizard.any_instance.stub(:apply_step) { true }
|
329
|
+
argv = ['apply', 'step-0']
|
330
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'applies provision in all steps' do
|
334
|
+
Bebox::ProvisionWizard.any_instance.stub(:apply_step) { true }
|
335
|
+
argv = ['apply', '--all']
|
336
|
+
output = capture(:stdout) { cli_command(argv, :success) }
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
# Helper method to capture the STDOUT from commands
|
343
|
+
def capture(stream)
|
344
|
+
begin
|
345
|
+
stream = stream.to_s
|
346
|
+
eval "$#{stream} = StringIO.new"
|
347
|
+
yield
|
348
|
+
result = eval("$#{stream}").string
|
349
|
+
ensure
|
350
|
+
eval("$#{stream} = #{stream.upcase}")
|
351
|
+
end
|
352
|
+
result
|
353
|
+
end
|
354
|
+
|
355
|
+
# Executes a cli command and do expectation from return status
|
356
|
+
def cli_command(argv, expectation)
|
357
|
+
begin
|
358
|
+
Bebox::Cli.new(argv)
|
359
|
+
rescue SystemExit => e
|
360
|
+
if expectation == :success
|
361
|
+
expect([0, 1]).to include(e.status)
|
362
|
+
else
|
363
|
+
expect([0, 1]).to_not include(e.status)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
data/spec/environment_spec.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
NAME environment - Manage environments for the project. The 'vagrant', 'production' and 'staging' environments are present by default. SYNOPSIS rspec [global options] environment list rspec [global options] environment new [environment] rspec [global options] environment remove [environment] COMMANDS list - List the remote environments in the project new - Add a remote environment to the project remove - Remove a remote environment in the project
|
@@ -0,0 +1 @@
|
|
1
|
+
NAME rspec - Create basic provisioning of remote servers. SYNOPSIS rspec [global options] command [command options] [arguments...] VERSION 0.1.2 GLOBAL OPTIONS --help - Show this message --version - Display the program version COMMANDS help - Shows a list of commands or help for one command new - Create a new bebox project through a simple wizard
|
@@ -0,0 +1 @@
|
|
1
|
+
NAME rspec - Create basic provisioning of remote servers. SYNOPSIS rspec [global options] command [command options] [arguments...] VERSION 0.1.2 GLOBAL OPTIONS --help - Show this message --version - Display the program version COMMANDS environment - Manage environments for the project. The 'vagrant', 'production' and 'staging' environments are present by default. help - Shows a list of commands or help for one command
|
@@ -0,0 +1 @@
|
|
1
|
+
NAME node - Manage nodes for a environment in the project. SYNOPSIS rspec [global options] node [command options] list [--all] rspec [global options] node [command options] new rspec [global options] node [command options] remove COMMAND OPTIONS --environment=arg - Set the environment for nodes (default: vagrant) COMMANDS list - list the nodes in a environment new - Add a node to a environment remove - Remove a node in a environment
|
@@ -0,0 +1 @@
|
|
1
|
+
NAME profile - Manage profiles for the node provisioning phase. SYNOPSIS rspec [global options] profile list rspec [global options] profile new [-p path] [name] rspec [global options] profile remove COMMANDS list - List the profiles in the project new - Add a profile to the project remove - Remove a profile from the project
|
@@ -0,0 +1 @@
|
|
1
|
+
NAME role - Manage roles for the node provisioning phase. SYNOPSIS rspec [global options] role add_profile rspec [global options] role list rspec [global options] role list_profiles [role_name] rspec [global options] role new [name] rspec [global options] role remove rspec [global options] role remove_profile COMMANDS add_profile - Add a profile to a role list - List the roles in the project list_profiles - List the profiles in a role new - Add a role to the project remove - Remove a role from the project remove_profile - Remove a profile from a role
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../factories/provision.rb'
|
3
3
|
require_relative '../vagrant_spec_helper.rb'
|
4
4
|
|
5
|
-
describe 'Test
|
5
|
+
describe 'Test 17: Apply provision for fundamental step-0' do
|
6
6
|
|
7
7
|
let(:provision) { build(:provision) }
|
8
8
|
let(:fundamental_profiles) {['base/fundamental/ruby', 'base/fundamental/sudo', 'base/fundamental/users']}
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../factories/provision.rb'
|
3
3
|
require_relative '../puppet_spec_helper.rb'
|
4
4
|
|
5
|
-
describe 'Test
|
5
|
+
describe 'Test 18: Apply provision for users layer step-1' do
|
6
6
|
|
7
7
|
let(:provision) { build(:provision, step: 'step-1') }
|
8
8
|
let(:users_profiles) {['base/users/ssh', 'base/users/users']}
|
@@ -4,7 +4,7 @@ require_relative '../factories/role.rb'
|
|
4
4
|
require_relative '../factories/profile.rb'
|
5
5
|
require_relative '../puppet_spec_helper.rb'
|
6
6
|
|
7
|
-
describe 'Test
|
7
|
+
describe 'Test 19: Apply provision for service layer step-2' do
|
8
8
|
|
9
9
|
let(:provision) { build(:provision, step: 'step-2') }
|
10
10
|
let(:role) { build(:role) }
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../factories/provision.rb'
|
3
3
|
require_relative '../puppet_spec_helper.rb'
|
4
4
|
|
5
|
-
describe 'Test
|
5
|
+
describe 'Test 20: Apply provision for security layer step-3' do
|
6
6
|
|
7
7
|
let(:provision) { build(:provision, step: 'step-3') }
|
8
8
|
let(:security_profiles) {['base/security/fail2ban', 'base/security/iptables', 'base/security/ssh', 'base/security/sysctl']}
|
data/spec/node_role_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative '../spec/factories/role.rb'
|
|
3
3
|
require_relative '../spec/factories/node.rb'
|
4
4
|
require_relative '../spec/factories/provision.rb'
|
5
5
|
|
6
|
-
describe 'Test
|
6
|
+
describe 'Test 15: Associate node and role' do
|
7
7
|
|
8
8
|
let(:role) { build(:role) }
|
9
9
|
let(:nodes) { [build(:node)] }
|
data/spec/node_spec.rb
CHANGED
data/spec/ordered_phases_spec.rb
CHANGED
data/spec/pre_prepare_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative '../spec/factories/role.rb'
|
|
3
3
|
require_relative '../spec/factories/profile.rb'
|
4
4
|
require_relative '../spec/factories/provision.rb'
|
5
5
|
|
6
|
-
describe 'Test
|
6
|
+
describe 'Test 16: Pre provision apply step' do
|
7
7
|
|
8
8
|
let(:provision) { build(:provision, step: 'step-2') }
|
9
9
|
let(:role) { build(:role) }
|
data/spec/profile_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../spec/factories/profile.rb'
|
3
3
|
require_relative '../lib/bebox/wizards/wizards_helper'
|
4
4
|
|
5
|
-
describe 'Test
|
5
|
+
describe 'Test 13: Bebox::Profile' do
|
6
6
|
|
7
7
|
# include Wizard helper methods
|
8
8
|
include Bebox::WizardsHelper
|
data/spec/project_spec.rb
CHANGED
data/spec/role_profiles_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../spec/factories/role.rb'
|
3
3
|
require_relative '../spec/factories/profile.rb'
|
4
4
|
|
5
|
-
describe 'Test
|
5
|
+
describe 'Test 14: Associate roles and profiles' do
|
6
6
|
|
7
7
|
let(:role) { build(:role) }
|
8
8
|
let(:profile) { build(:profile) }
|
data/spec/role_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../spec/factories/role.rb'
|
3
3
|
require_relative '../lib/bebox/wizards/wizards_helper'
|
4
4
|
|
5
|
-
describe 'Test
|
5
|
+
describe 'Test 12: Bebox::Role' do
|
6
6
|
|
7
7
|
# include Wizard helper methods
|
8
8
|
include Bebox::WizardsHelper
|
data/spec/spec_helper.rb
CHANGED
@@ -24,23 +24,7 @@ require 'colorize'
|
|
24
24
|
include Serverspec::Helper::Ssh
|
25
25
|
include Serverspec::Helper::Debian
|
26
26
|
|
27
|
-
require_relative '../lib/bebox
|
28
|
-
require_relative '../lib/bebox/files_helper'
|
29
|
-
require_relative '../lib/bebox/wizards/wizards_helper'
|
30
|
-
require_relative '../lib/bebox/vagrant_helper'
|
31
|
-
require_relative '../lib/bebox/wizards/project_wizard'
|
32
|
-
require_relative '../lib/bebox/project'
|
33
|
-
require_relative '../lib/bebox/wizards/environment_wizard'
|
34
|
-
require_relative '../lib/bebox/environment'
|
35
|
-
require_relative '../lib/bebox/wizards/node_wizard'
|
36
|
-
require_relative '../lib/bebox/node'
|
37
|
-
require_relative '../lib/bebox/wizards/provision_wizard'
|
38
|
-
require_relative '../lib/bebox/provision'
|
39
|
-
require_relative '../lib/bebox/wizards/role_wizard'
|
40
|
-
require_relative '../lib/bebox/role'
|
41
|
-
require_relative '../lib/bebox/wizards/profile_wizard'
|
42
|
-
require_relative '../lib/bebox/profile'
|
43
|
-
require_relative '../lib/bebox/vagrant_helper'
|
27
|
+
require_relative '../lib/bebox'
|
44
28
|
|
45
29
|
I18n.enforce_available_locales = false
|
46
30
|
|
@@ -3,7 +3,7 @@ require 'progressbar'
|
|
3
3
|
|
4
4
|
require_relative '../factories/project.rb'
|
5
5
|
|
6
|
-
describe 'Test
|
6
|
+
describe 'Test 01: Bebox::ProjectWizard' do
|
7
7
|
|
8
8
|
describe 'Project data provision' do
|
9
9
|
|
@@ -17,6 +17,7 @@ describe 'Test 00: Bebox::ProjectWizard' do
|
|
17
17
|
|
18
18
|
before :all do
|
19
19
|
`mkdir -p #{bebox_boxes_path}/tmp`
|
20
|
+
`rm #{bebox_boxes_path}/test_box.box`
|
20
21
|
`rm -rf #{Dir.pwd}/tmp/bebox-pname`
|
21
22
|
end
|
22
23
|
|
@@ -28,27 +29,23 @@ describe 'Test 00: Bebox::ProjectWizard' do
|
|
28
29
|
`rm #{bebox_boxes_path}/test_box.box`
|
29
30
|
end
|
30
31
|
|
32
|
+
it 'not create a project that already exist' do
|
33
|
+
subject.stub(:project_exists?) { true }
|
34
|
+
output = subject.create_new_project(project_name)
|
35
|
+
expect(output).to eq(false)
|
36
|
+
end
|
37
|
+
|
31
38
|
it 'creates a project with wizard' do
|
32
39
|
Bebox::Project.any_instance.stub(:create) { true }
|
33
40
|
subject.stub(:bebox_boxes_setup)
|
34
41
|
subject.stub(:choose_box) { 'test_box.box' }
|
42
|
+
subject.stub(:get_valid_box_uri) { 'test_box.box' }
|
43
|
+
subject.stub(:choose_option) { 'virtualbox' }
|
35
44
|
$stdin.stub(:gets).and_return('1')
|
36
45
|
output = subject.create_new_project(project_name)
|
37
46
|
expect(output).to eq(true)
|
38
47
|
end
|
39
48
|
|
40
|
-
it 'chooses a box from a menu' do
|
41
|
-
$stdin.stub(:gets).and_return('1')
|
42
|
-
output = subject.choose_box(['test_box.box'])
|
43
|
-
expect(output).to eq('test_box.box')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'gets a valid box uri from user' do
|
47
|
-
$stdin.stub(:gets).and_return(local_box_uri, 'y')
|
48
|
-
subject.get_valid_box_uri(nil)
|
49
|
-
expect(File.symlink?("#{bebox_boxes_path}/test_box.box")).to eq(true)
|
50
|
-
end
|
51
|
-
|
52
49
|
it 'checks for project existence' do
|
53
50
|
output = subject.project_exists?(parent_path, project_name)
|
54
51
|
expect(output).to eq(Dir.exists?("#{Dir.pwd}/tmp/#{project_name}"))
|
@@ -60,16 +57,52 @@ describe 'Test 00: Bebox::ProjectWizard' do
|
|
60
57
|
expect(Dir["#{bebox_boxes_path}/tmp/*"].count).to eq(0)
|
61
58
|
end
|
62
59
|
|
63
|
-
it '
|
64
|
-
|
60
|
+
it 'chooses a box from a menu' do
|
61
|
+
$stdin.stub(:gets).and_return('1')
|
62
|
+
output = subject.choose_box(['test_box.box'])
|
63
|
+
expect(output).to eq('test_box.box')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'not chooses a box from a menu' do
|
67
|
+
$stdin.stub(:gets).and_return('2')
|
68
|
+
output = subject.choose_box(['test_box.box'])
|
69
|
+
expect(output).to eq(nil)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'gets a valid box uri from user when box not exist' do
|
73
|
+
subject.stub(:set_box) { true }
|
74
|
+
subject.stub(:ask_uri) { local_box_uri }
|
75
|
+
subject.stub(:box_exists?) { false }
|
76
|
+
output = subject.get_valid_box_uri(nil)
|
77
|
+
expect(output).to eq(true)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'gets a valid box uri from user when box already exist' do
|
81
|
+
subject.stub(:set_box) { true }
|
82
|
+
subject.stub(:ask_uri) { local_box_uri }
|
83
|
+
subject.stub(:box_exists?) { true }
|
84
|
+
$stdin.stub(:gets).and_return('y')
|
85
|
+
output = subject.get_valid_box_uri(nil)
|
65
86
|
expect(output).to eq(true)
|
66
87
|
end
|
67
88
|
|
68
|
-
it '
|
89
|
+
it 'asks for a uri that is valid' do
|
90
|
+
subject.stub(:uri_valid?) { true }
|
91
|
+
$stdin.stub(:gets).and_return(local_box_uri)
|
92
|
+
output = subject.ask_uri
|
93
|
+
expect(output).to eq(local_box_uri)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'validates a local uri' do
|
69
97
|
output = subject.uri_valid?(local_box_uri)
|
70
98
|
expect(output).to eq(true)
|
71
99
|
end
|
72
100
|
|
101
|
+
it 'validates a remote uri' do
|
102
|
+
output = subject.uri_valid?(http_box_uri)
|
103
|
+
expect(output).to eq(true)
|
104
|
+
end
|
105
|
+
|
73
106
|
it 'links to a local file box' do
|
74
107
|
subject.set_box(local_box_uri)
|
75
108
|
expect(File.symlink?("#{bebox_boxes_path}/test_box.box")).to eq(true)
|
@@ -85,6 +118,5 @@ describe 'Test 00: Bebox::ProjectWizard' do
|
|
85
118
|
expect(File.exists?("#{bebox_boxes_path}/LICENSE")).to eq(true)
|
86
119
|
`rm #{bebox_boxes_path}/LICENSE`
|
87
120
|
end
|
88
|
-
|
89
121
|
end
|
90
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Codescrum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -334,6 +334,7 @@ files:
|
|
334
334
|
- lib/templates/puppet/step-3/hiera/hiera.yaml.erb
|
335
335
|
- lib/templates/puppet/step-3/manifests/node.erb
|
336
336
|
- lib/templates/puppet/step-3/manifests/site.pp.erb
|
337
|
+
- spec/cli_spec.rb
|
337
338
|
- spec/environment_spec.rb
|
338
339
|
- spec/factories/environment.rb
|
339
340
|
- spec/factories/node.rb
|
@@ -343,6 +344,12 @@ files:
|
|
343
344
|
- spec/factories/role.rb
|
344
345
|
- spec/fixtures/Capfile.test
|
345
346
|
- spec/fixtures/Gemfile.test
|
347
|
+
- spec/fixtures/commands/environment_help.test
|
348
|
+
- spec/fixtures/commands/general_help.test
|
349
|
+
- spec/fixtures/commands/in_project_help.test
|
350
|
+
- spec/fixtures/commands/node_help.test
|
351
|
+
- spec/fixtures/commands/profile_help.test
|
352
|
+
- spec/fixtures/commands/role_help.test
|
346
353
|
- spec/fixtures/config/deploy.test
|
347
354
|
- spec/fixtures/config/deploy/environment.test
|
348
355
|
- spec/fixtures/config/deploy/production.test
|