vagrant-config_builder 0.15.1 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +18 -4
- data/CHANGELOG +44 -0
- data/Gemfile +3 -4
- data/lib/config_builder/model/base.rb +182 -8
- data/lib/config_builder/model/network/forwarded_port.rb +34 -13
- data/lib/config_builder/model/network/private_network.rb +17 -1
- data/lib/config_builder/model/network/public_network.rb +39 -0
- data/lib/config_builder/model/nfs.rb +33 -0
- data/lib/config_builder/model/provider/aws.rb +16 -39
- data/lib/config_builder/model/provider/azure.rb +11 -33
- data/lib/config_builder/model/provider/base.rb +37 -0
- data/lib/config_builder/model/provider/libvirt.rb +33 -39
- data/lib/config_builder/model/provider/openstack.rb +69 -0
- data/lib/config_builder/model/provider/openstack_plugin.rb +46 -0
- data/lib/config_builder/model/provider/softlayer.rb +85 -0
- data/lib/config_builder/model/provider/virtualbox.rb +84 -17
- data/lib/config_builder/model/provider/vmware.rb +6 -4
- data/lib/config_builder/model/provider/vsphere.rb +33 -15
- data/lib/config_builder/model/provisioner/base.rb +33 -0
- data/lib/config_builder/model/provisioner/file.rb +1 -10
- data/lib/config_builder/model/provisioner/puppet.rb +32 -22
- data/lib/config_builder/model/provisioner/puppet_server.rb +21 -15
- data/lib/config_builder/model/provisioner/shell.rb +28 -10
- data/lib/config_builder/model/root.rb +28 -4
- data/lib/config_builder/model/ssh.rb +29 -11
- data/lib/config_builder/model/synced_folder.rb +83 -14
- data/lib/config_builder/model/vm.rb +111 -52
- data/lib/config_builder/model/winrm.rb +27 -7
- data/lib/config_builder/model.rb +9 -1
- data/lib/config_builder/model_delegator.rb +5 -24
- data/lib/config_builder/version.rb +1 -1
- data/spec/integration/vagrant/root_config_spec.rb +89 -0
- data/spec/integration/vagrant/vm_config_spec.rb +101 -0
- data/spec/integration/vagrant/vm_provider_spec.rb +57 -0
- data/spec/integration/vagrant/vm_provisioner_spec.rb +90 -0
- data/spec/spec_helper.rb +6 -2
- data/spec/{config_builder → unit}/filter/boxes_spec.rb +0 -0
- data/spec/{config_builder → unit}/filter/roles_spec.rb +0 -0
- data/spec/{config_builder → unit}/loader/yaml_spec.rb +0 -0
- data/spec/unit/model/base_spec.rb +122 -0
- data/spec/{config_builder → unit}/model/provider/vmware_fusion_spec.rb +6 -5
- data/templates/locales/en.yml +4 -0
- metadata +33 -20
@@ -36,21 +36,41 @@ class ConfigBuilder::Model::WinRM < ConfigBuilder::Model::Base
|
|
36
36
|
# @return [Fixnum] Maximum number of retry attempts. By default this is 20.
|
37
37
|
def_model_attribute :max_tries
|
38
38
|
|
39
|
+
# @!attribute [rw] retry_delay
|
40
|
+
# @return [Fixnum]
|
41
|
+
def_model_attribute :retry_delay
|
42
|
+
|
39
43
|
# @!attribute [rw] timeout
|
40
44
|
# @return [Fixnum] The timeout in seconds. By default this is 1800 seconds.
|
41
45
|
def_model_attribute :timeout
|
42
46
|
|
47
|
+
# @!attribute [rw] transport
|
48
|
+
# @return [String, Symbol]
|
49
|
+
def_model_attribute :transport
|
50
|
+
|
51
|
+
# @!attribute [rw] ssl_peer_verification
|
52
|
+
# @return [Boolean]
|
53
|
+
def_model_attribute :ssl_peer_verification
|
54
|
+
|
55
|
+
# @!attribute [rw] execution_time_limit
|
56
|
+
# @return [String]
|
57
|
+
def_model_attribute :execution_time_limit
|
58
|
+
|
43
59
|
def to_proc
|
44
60
|
Proc.new do |global_config|
|
45
61
|
winrm = global_config.winrm
|
46
62
|
|
47
|
-
with_attr(:username)
|
48
|
-
with_attr(:password)
|
49
|
-
with_attr(:host)
|
50
|
-
with_attr(:guest)
|
51
|
-
with_attr(:guest_port)
|
52
|
-
with_attr(:max_tries)
|
53
|
-
with_attr(:
|
63
|
+
with_attr(:username) { |val| winrm.username = val }
|
64
|
+
with_attr(:password) { |val| winrm.password = val }
|
65
|
+
with_attr(:host) { |val| winrm.host = val }
|
66
|
+
with_attr(:guest) { |val| winrm.guest = val }
|
67
|
+
with_attr(:guest_port) { |val| winrm.guest_port = val }
|
68
|
+
with_attr(:max_tries) { |val| winrm.max_tries = val }
|
69
|
+
with_attr(:retry_delay) { |val| winrm.retry_delay = val }
|
70
|
+
with_attr(:timeout) { |val| winrm.timeout = val }
|
71
|
+
with_attr(:transport) { |val| winrm.transport = val.to_sym }
|
72
|
+
with_attr(:ssl_peer_verification) { |val| winrm.ssl_peer_verification = val }
|
73
|
+
with_attr(:execution_time_limit) { |val| winrm.execution_time_limit = val }
|
54
74
|
end
|
55
75
|
end
|
56
76
|
end
|
data/lib/config_builder/model.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'vagrant/errors'
|
2
2
|
require 'config_builder/class_registry'
|
3
|
-
require 'config_builder/model_delegator'
|
4
3
|
|
5
4
|
module ConfigBuilder
|
6
5
|
|
@@ -10,6 +9,7 @@ module ConfigBuilder
|
|
10
9
|
|
11
10
|
require 'config_builder/model/root'
|
12
11
|
|
12
|
+
require 'config_builder/model/nfs'
|
13
13
|
require 'config_builder/model/ssh'
|
14
14
|
require 'config_builder/model/winrm'
|
15
15
|
#require 'config_builder/model/host'
|
@@ -24,6 +24,7 @@ module ConfigBuilder
|
|
24
24
|
module Network
|
25
25
|
require 'config_builder/model/network/forwarded_port'
|
26
26
|
require 'config_builder/model/network/private_network'
|
27
|
+
require 'config_builder/model/network/public_network'
|
27
28
|
end
|
28
29
|
|
29
30
|
module Provider
|
@@ -38,6 +39,8 @@ module ConfigBuilder
|
|
38
39
|
@registry.register(name, klass)
|
39
40
|
end
|
40
41
|
|
42
|
+
require 'config_builder/model/provider/base'
|
43
|
+
|
41
44
|
require 'config_builder/model/provider/virtualbox'
|
42
45
|
require 'config_builder/model/provider/vmware'
|
43
46
|
require 'config_builder/model/provider/vmware_fusion'
|
@@ -46,6 +49,9 @@ module ConfigBuilder
|
|
46
49
|
require 'config_builder/model/provider/vsphere'
|
47
50
|
require 'config_builder/model/provider/azure'
|
48
51
|
require 'config_builder/model/provider/aws'
|
52
|
+
require 'config_builder/model/provider/openstack'
|
53
|
+
require 'config_builder/model/provider/openstack_plugin'
|
54
|
+
require 'config_builder/model/provider/softlayer'
|
49
55
|
end
|
50
56
|
|
51
57
|
module Provisioner
|
@@ -60,6 +66,8 @@ module ConfigBuilder
|
|
60
66
|
@registry.register(name, klass)
|
61
67
|
end
|
62
68
|
|
69
|
+
require 'config_builder/model/provisioner/base'
|
70
|
+
|
63
71
|
require 'config_builder/model/provisioner/file'
|
64
72
|
require 'config_builder/model/provisioner/shell'
|
65
73
|
require 'config_builder/model/provisioner/puppet'
|
@@ -1,30 +1,11 @@
|
|
1
|
+
require 'config_builder' # For logging.
|
2
|
+
|
1
3
|
module ConfigBuilder
|
2
4
|
module ModelDelegator
|
3
|
-
|
4
|
-
def model_delegators
|
5
|
-
self.class.model_delegators
|
6
|
-
end
|
7
|
-
|
8
|
-
def eval_models(config)
|
9
|
-
model_delegators.each do |model|
|
10
|
-
meth = "eval_#{model}"
|
11
|
-
send(meth, config)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
def self.included(klass)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
module ClassMethods
|
20
|
-
def def_model_delegator(identifier)
|
21
|
-
def_model_attribute(identifier)
|
22
|
-
model_delegators << identifier
|
23
|
-
end
|
24
|
-
|
25
|
-
def model_delegators
|
26
|
-
(@models ||= [])
|
27
|
-
end
|
6
|
+
ConfigBuilder.logger.warn {
|
7
|
+
I18n.t('config_builder.model_delegator.is_deprecated', :name => klass.inspect)
|
8
|
+
}
|
28
9
|
end
|
29
10
|
end
|
30
11
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Vagrant Integration: ConfigBuilder::Model::Root' do
|
4
|
+
include_context 'vagrant-unit'
|
5
|
+
|
6
|
+
# Set inside test contexts to generate Vagrant configuration.
|
7
|
+
let(:config_data) { Hash.new }
|
8
|
+
|
9
|
+
let(:test_env) { isolated_environment }
|
10
|
+
let(:env) { test_env.create_vagrant_env }
|
11
|
+
let(:root_config) { env.vagrantfile.config }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
model = ConfigBuilder::Model::Root.new_from_hash(config_data)
|
15
|
+
|
16
|
+
model.call(root_config)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when configured with ssh data' do
|
20
|
+
let(:config_data) {
|
21
|
+
{'ssh' =>
|
22
|
+
{
|
23
|
+
'insert_key' => false,
|
24
|
+
'username' => 'AzureDiamond',
|
25
|
+
'password' => 'hunter2',
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
subject { root_config.ssh }
|
31
|
+
|
32
|
+
it 'sets Vagrant config.ssh parameters' do
|
33
|
+
expect(subject.insert_key).to be_false
|
34
|
+
expect(subject.username).to eq 'AzureDiamond'
|
35
|
+
expect(subject.password).to eq 'hunter2'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when configured with WinRM data' do
|
40
|
+
let(:config_data) {
|
41
|
+
{'winrm' =>
|
42
|
+
{
|
43
|
+
'username' => 'AzureDiamond',
|
44
|
+
'password' => 'hunter2',
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
subject { root_config.winrm }
|
50
|
+
|
51
|
+
it 'sets Vagrant config.winrm parameters' do
|
52
|
+
expect(subject.username).to eq 'AzureDiamond'
|
53
|
+
expect(subject.password).to eq 'hunter2'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when configured with NFS data' do
|
58
|
+
let(:config_data) {
|
59
|
+
{'nfs' =>
|
60
|
+
{
|
61
|
+
'map_uid' => 42,
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
subject { root_config.nfs }
|
67
|
+
|
68
|
+
it 'sets Vagrant config.nfs parameters' do
|
69
|
+
expect(subject.map_uid).to eq 42
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when configured with VM defaults' do
|
74
|
+
let(:config_data) {
|
75
|
+
{'vm_defaults' =>
|
76
|
+
{
|
77
|
+
'box' => 'somebox',
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
subject { root_config.vm }
|
83
|
+
|
84
|
+
it 'sets Vagrant config.vm parameters' do
|
85
|
+
expect(subject.box).to eq 'somebox'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Vagrant Integration: ConfigBuilder::Model::VM' do
|
4
|
+
include_context 'vagrant-unit'
|
5
|
+
|
6
|
+
# Set inside test contexts to generate Vagrant configuration.
|
7
|
+
let(:config_data) { Hash.new }
|
8
|
+
|
9
|
+
let(:test_env) { isolated_environment }
|
10
|
+
let(:env) {
|
11
|
+
test_env.create_vagrant_env(local_data_path: "#{test_env.workdir}/.vagrant")
|
12
|
+
}
|
13
|
+
let(:root_config) { env.vagrantfile.config }
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
model = ConfigBuilder::Model::Root.new_from_hash(config_data)
|
17
|
+
|
18
|
+
model.call(root_config)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when building vms' do
|
22
|
+
let(:config_data) {
|
23
|
+
{'vms' =>
|
24
|
+
[
|
25
|
+
{'name' => 'machine1'},
|
26
|
+
{'name' => 'machine2', 'autostart' => false},
|
27
|
+
]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
subject { root_config.vm }
|
32
|
+
|
33
|
+
it 'defines named machines under Vagrant config.vm' do
|
34
|
+
expect(subject.defined_vm_keys).to include(:machine1, :machine2)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'sets the autostart option when defining machines' do
|
38
|
+
test_vm = subject.defined_vms[:machine2]
|
39
|
+
|
40
|
+
expect(test_vm.options[:autostart]).to be_false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when configuring vms' do
|
45
|
+
let(:config_data) {
|
46
|
+
{'vms' =>
|
47
|
+
[
|
48
|
+
{
|
49
|
+
'name' => 'test',
|
50
|
+
'hostname' => 'test-vm',
|
51
|
+
'box' => 'testbox',
|
52
|
+
'communicator' => 'winrm',
|
53
|
+
'forwarded_ports' => [
|
54
|
+
{'id' => 'winrm', 'host' => 666}
|
55
|
+
],
|
56
|
+
'synced_folders' => [
|
57
|
+
{'host_path' => '.', 'guest_path' => '/vagrant', 'disabled' => true}
|
58
|
+
],
|
59
|
+
'private_networks' => [
|
60
|
+
{'type' => 'dhcp'}
|
61
|
+
],
|
62
|
+
'public_networks' => [
|
63
|
+
{'bridge' => 'some_interface:'}
|
64
|
+
],
|
65
|
+
},
|
66
|
+
]
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
subject { env.machine(:test, :dummy).config.vm }
|
71
|
+
|
72
|
+
it 'sets Vagrant VM attributes' do
|
73
|
+
expect(subject.box).to eq 'testbox'
|
74
|
+
expect(subject.communicator).to eq :winrm
|
75
|
+
expect(subject.hostname).to eq 'test-vm'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'configures Vagrant forwarded ports' do
|
79
|
+
winrm_port = subject.networks.find {|t, o| t == :forwarded_port && o[:id] == 'winrm'}
|
80
|
+
|
81
|
+
expect(winrm_port.last[:host]).to eq 666
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'configures Vagrant synced folders' do
|
85
|
+
expect(subject.synced_folders['/vagrant'][:disabled]).to be_true
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'configures Vagrant private networks' do
|
89
|
+
private_networks = subject.networks.select {|t, o| t == :private_network}
|
90
|
+
|
91
|
+
expect(private_networks).to_not be_empty
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'configures Vagrant public networks' do
|
95
|
+
private_networks = subject.networks.select {|t, o| t == :public_network}
|
96
|
+
|
97
|
+
expect(private_networks).to_not be_empty
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class DummyModel < ConfigBuilder::Model::Provider::Base
|
4
|
+
def instance_id
|
5
|
+
'dummy'
|
6
|
+
end
|
7
|
+
|
8
|
+
ConfigBuilder::Model::Provider.register('dummy', self)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Vagrant Integration: ConfigBuilder::Model::Provider' do
|
12
|
+
include_context 'vagrant-unit'
|
13
|
+
|
14
|
+
# Set inside test contexts to generate Vagrant configuration.
|
15
|
+
let(:config_data) { Hash.new }
|
16
|
+
|
17
|
+
let(:test_env) { isolated_environment }
|
18
|
+
let(:env) {
|
19
|
+
test_env.create_vagrant_env(local_data_path: "#{test_env.workdir}/.vagrant")
|
20
|
+
}
|
21
|
+
let(:root_config) { env.vagrantfile.config }
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
model = ConfigBuilder::Model::Root.new_from_hash(config_data)
|
25
|
+
|
26
|
+
model.call(root_config)
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when configuring providers' do
|
30
|
+
let(:config_data) {
|
31
|
+
{'vms' =>
|
32
|
+
[
|
33
|
+
{
|
34
|
+
'name' => 'test',
|
35
|
+
'providers' => [
|
36
|
+
{
|
37
|
+
'type' => 'dummy',
|
38
|
+
'overrides' => {
|
39
|
+
'ssh' => {'username' => 'AzureDiamond'},
|
40
|
+
'vm_defaults' => {'box' => 'testbox'},
|
41
|
+
},
|
42
|
+
},
|
43
|
+
],
|
44
|
+
},
|
45
|
+
]
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
subject { env.machine(:test, :dummy) }
|
50
|
+
|
51
|
+
it 'sets configuration overrides' do #YAAARP.
|
52
|
+
expect(subject.config.ssh.username).to eq 'AzureDiamond'
|
53
|
+
expect(subject.config.vm.box).to eq 'testbox'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Vagrant Integration: ConfigBuilder::Model::Provisioner' do
|
4
|
+
include_context 'vagrant-unit'
|
5
|
+
|
6
|
+
# Set inside test contexts to generate Vagrant configuration.
|
7
|
+
let(:config_data) { Hash.new }
|
8
|
+
|
9
|
+
let(:test_env) { isolated_environment }
|
10
|
+
let(:env) {
|
11
|
+
test_env.create_vagrant_env(local_data_path: "#{test_env.workdir}/.vagrant")
|
12
|
+
}
|
13
|
+
let(:root_config) { env.vagrantfile.config }
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
model = ConfigBuilder::Model::Root.new_from_hash(config_data)
|
17
|
+
|
18
|
+
model.call(root_config)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when building provisioners' do
|
22
|
+
let(:config_data) {
|
23
|
+
{'vms' =>
|
24
|
+
[
|
25
|
+
{
|
26
|
+
'name' => 'test',
|
27
|
+
'provisioners' => [
|
28
|
+
{'type' => 'shell', 'run' => 'once'},
|
29
|
+
{'type' => 'file', 'name' => 'supercoolfile'},
|
30
|
+
],
|
31
|
+
},
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
subject { env.machine(:test, :dummy).config.vm }
|
37
|
+
|
38
|
+
it 'defines provisioners' do
|
39
|
+
expect(subject.provisioners).to have(2).items
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'sets provisioner names' do
|
43
|
+
if Vagrant::VERSION < '1.7'
|
44
|
+
provisioner = subject.provisioners.find {|p| p.name == :file}
|
45
|
+
|
46
|
+
expect(provisioner.id).to eq 'supercoolfile'
|
47
|
+
else
|
48
|
+
provisioner = subject.provisioners.find {|p| p.type == :file}
|
49
|
+
|
50
|
+
expect(provisioner.name).to eq :supercoolfile
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'sets provisioner options' do
|
55
|
+
if Vagrant::VERSION < '1.7'
|
56
|
+
provisioner = subject.provisioners.find {|p| p.name == :shell}
|
57
|
+
|
58
|
+
expect(provisioner.run).to eq :once
|
59
|
+
else
|
60
|
+
provisioner = subject.provisioners.find {|p| p.type == :shell}
|
61
|
+
|
62
|
+
expect(provisioner.run).to eq :once
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when configuring provisioners' do
|
68
|
+
let(:config_data) {
|
69
|
+
{'vms' =>
|
70
|
+
[
|
71
|
+
{
|
72
|
+
'name' => 'test',
|
73
|
+
'provisioners' => [
|
74
|
+
{'type' => 'shell', 'inline' => 'hello world'},
|
75
|
+
],
|
76
|
+
},
|
77
|
+
]
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
subject { env.machine(:test, :dummy).config.vm }
|
82
|
+
|
83
|
+
it 'sets provisioner attributes' do
|
84
|
+
shell_config = subject.provisioners.first.config
|
85
|
+
|
86
|
+
expect(shell_config.inline).to eq 'hello world'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
-
require 'config_builder'
|
3
2
|
|
4
|
-
|
3
|
+
# Disable Vagrant autoloading so that other plugins defined in the Gemfile for
|
4
|
+
# Acceptance tests are not loaded.
|
5
|
+
ENV['VAGRANT_NO_PLUGINS'] = '1'
|
6
|
+
|
7
|
+
require 'vagrant-spec/unit'
|
8
|
+
require 'config_builder'
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConfigBuilder::Model::Base do
|
4
|
+
context 'when initialized with attributes' do
|
5
|
+
subject do
|
6
|
+
described_class.new_from_hash({'attr_1' => 'val_1', 'attr_2' => 'val_2'})
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'provides access via #attr' do
|
10
|
+
expect(subject.attr(:attr_1)).to eq 'val_1'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'provides conditional access via #with_attr' do
|
14
|
+
test_val_2 = nil
|
15
|
+
test_val_3 = nil
|
16
|
+
|
17
|
+
subject.with_attr(:attr_2) { |value| test_val_2 = value }
|
18
|
+
subject.with_attr(:non_existent) { |value| test_val_3 = value }
|
19
|
+
|
20
|
+
expect(test_val_2).to eq 'val_2'
|
21
|
+
expect(test_val_3).to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when subclassed' do
|
26
|
+
let (:subclass_a) do
|
27
|
+
Class.new(described_class) do
|
28
|
+
def_model_id :id_key
|
29
|
+
|
30
|
+
def_model_attribute :attr_1
|
31
|
+
def_model_attribute :attr_2
|
32
|
+
|
33
|
+
def_model_option :opt_1
|
34
|
+
def_model_option :opt_2
|
35
|
+
|
36
|
+
def_model_delegator :delegator_1
|
37
|
+
|
38
|
+
def configure_attr_2(config, value)
|
39
|
+
config.custom_setter(value)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
subject { subclass_a }
|
45
|
+
|
46
|
+
it 'responds to .model_id' do
|
47
|
+
expect(subject.model_id).to eq :id_key
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'lists attributes via .model_attributes' do
|
51
|
+
expect(subject.model_attributes).to include(:attr_1, :attr_2)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'lists options via .model_options' do
|
55
|
+
expect(subject.model_options).to include(:opt_1, :opt_2)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'lists delegators via .model_delegators' do
|
59
|
+
expect(subject.model_delegators).to include(:delegator_1)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns #instance_id by using .model_id' do
|
63
|
+
instance = subject.new_from_hash({'id_key' => 'id_value'})
|
64
|
+
|
65
|
+
expect(instance.instance_id).to eq 'id_value'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns all set options via #instance_options' do
|
69
|
+
instance = subject.new_from_hash({'opt_1' => 'option_value'})
|
70
|
+
|
71
|
+
expect(instance.instance_options).to eq({:opt_1 => 'option_value'})
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'copies attributes to config objects with #configure!' do
|
75
|
+
config = double('vagrant config')
|
76
|
+
instance = subject.new_from_hash({'attr_1' => 'attr_value'})
|
77
|
+
|
78
|
+
expect(config).to receive("attr_1=").with('attr_value')
|
79
|
+
|
80
|
+
instance.configure!(config)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'uses custom setters to copy attributes with #configure!' do
|
84
|
+
config = double('vagrant config')
|
85
|
+
instance = subject.new_from_hash({'attr_2' => 'custom_value'})
|
86
|
+
|
87
|
+
expect(config).to receive("custom_setter").with('custom_value')
|
88
|
+
|
89
|
+
instance.configure!(config)
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when subclassed further' do
|
93
|
+
let (:subclass_b) do
|
94
|
+
Class.new(subclass_a) do
|
95
|
+
def_model_attribute :attr_3
|
96
|
+
|
97
|
+
def_model_delegator :delegator_2
|
98
|
+
|
99
|
+
def_model_option :opt_3
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
subject { subclass_b }
|
104
|
+
|
105
|
+
it 'lists inherited attributes via .model_attributes' do
|
106
|
+
expect(subject.model_attributes).to include(:attr_1, :attr_2, :attr_3)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'lists inherited options via .model_options' do
|
110
|
+
expect(subject.model_options).to include(:opt_1, :opt_2, :opt_3)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'lists inherited delegators via .model_delegators' do
|
114
|
+
expect(subject.model_delegators).to include(:delegator_1, :delegator_2)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'does not inherit model_id' do
|
118
|
+
expect(subject.model_id).to be_nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -5,23 +5,24 @@ describe ConfigBuilder::Model::Provider::VMwareFusion do
|
|
5
5
|
describe "converting to a proc" do
|
6
6
|
|
7
7
|
let(:vmx) { Hash.new }
|
8
|
-
let(:
|
9
|
-
let(:
|
8
|
+
let(:vm_config) { double('vagrant VM config', :provider => provider_config) }
|
9
|
+
let(:provider_config) { double('fusion provider config', :vmx => vmx) }
|
10
|
+
let(:override_config) { double('fusion override config') }
|
10
11
|
|
11
12
|
before do
|
12
|
-
allow(vm_config).to receive(:provider).and_yield(
|
13
|
+
allow(vm_config).to receive(:provider).and_yield(provider_config, override_config)
|
13
14
|
end
|
14
15
|
|
15
16
|
it "assigns the gui value to the fusion provider object" do
|
16
17
|
subject.attrs = {:gui => 'guivalue'}
|
17
|
-
expect(
|
18
|
+
expect(provider_config).to receive(:gui=).with('guivalue')
|
18
19
|
p = subject.to_proc
|
19
20
|
p.call(vm_config)
|
20
21
|
end
|
21
22
|
|
22
23
|
it "assigns the vmx value to the fusion provider object" do
|
23
24
|
subject.attrs = {:vmx => {:hello => 'world'}}
|
24
|
-
allow(
|
25
|
+
allow(provider_config).to receive(:gui=)
|
25
26
|
subject.call(vm_config)
|
26
27
|
expect(vmx).to eq({:hello => 'world'})
|
27
28
|
end
|
data/templates/locales/en.yml
CHANGED
@@ -13,3 +13,7 @@ en:
|
|
13
13
|
vm:
|
14
14
|
provider_is_deprecated: |-
|
15
15
|
The provider attribute, set on vm %{name}, is deprecated and will be removed in an upcoming release. Use the providers attribute instead.
|
16
|
+
model_delegator:
|
17
|
+
is_deprecated: |-
|
18
|
+
The functionality provided by ConfigBuilder::ModelDelegator has been folded into Config::Builder::Model::Base.
|
19
|
+
The ModelDelegator module will be removed in an upcoming release (included by %{name}).
|