Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Add environment variable as option for vm_password.
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Upton <[email protected]>
  • Loading branch information
Shaan Sapra authored and ystros committed Apr 9, 2019
1 parent d89ec0c commit 56fa188
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/vm_shepherd/shepherd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def vsphere_vm_options(input_config)
end

def get_vsphere_vm_password(input_config)
ENV['PROVISION_WITH_PASSWORD'] == 'false' ? nil : (input_config.dig('vm', 'vm_password') || 'tempest')
ENV['PROVISION_WITH_PASSWORD'] == 'false' ? nil : (input_config.dig('vm', 'vm_password') || ENV['VSPHERE_VM_PASSWORD'] || 'tempest')
end

def get_vsphere_vm_public_ssh_key(input_config)
Expand Down
118 changes: 94 additions & 24 deletions spec/vm_shepherd/shepherd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,30 +300,100 @@ module VmShepherd
context 'and it is true' do
before { stub_const('ENV', {'PROVISION_WITH_PASSWORD' => 'true'}) }

it 'deploys with the set vm password' do
expect(first_ova_manager).to receive(:deploy).with(
'FIRST_FAKE_PATH',
{
ip: first_config.dig('vm', 'ip'),
gateway: first_config.dig('vm', 'gateway'),
netmask: first_config.dig('vm', 'netmask'),
dns: first_config.dig('vm', 'dns'),
ntp_servers: first_config.dig('vm', 'ntp_servers'),
cpus: first_config.dig('vm', 'cpus'),
ram_mb: first_config.dig('vm', 'ram_mb'),
vm_password: first_config.dig('vm', 'vm_password'),
public_ssh_key: 'A PUBLIC KEY',
custom_hostname: first_config.dig('vm', 'custom_hostname')
},
{
cluster: first_config.dig('vsphere', 'cluster'),
resource_pool: first_config.dig('vsphere', 'resource_pool'),
datastore: first_config.dig('vsphere', 'datastore'),
network: first_config.dig('vsphere', 'network'),
folder: first_config.dig('vsphere', 'folder'),
},
)
manager.deploy(paths: ['FIRST_FAKE_PATH'])
context 'when the vm_password is set' do
before { stub_const('ENV', {'PROVISION_WITH_PASSWORD' => 'true', 'VSPHERE_VM_PASSWORD' => 'a-password'}) }
it 'deploys with the set vm password' do
expect(first_ova_manager).to receive(:deploy).with(
'FIRST_FAKE_PATH',
{
ip: first_config.dig('vm', 'ip'),
gateway: first_config.dig('vm', 'gateway'),
netmask: first_config.dig('vm', 'netmask'),
dns: first_config.dig('vm', 'dns'),
ntp_servers: first_config.dig('vm', 'ntp_servers'),
cpus: first_config.dig('vm', 'cpus'),
ram_mb: first_config.dig('vm', 'ram_mb'),
vm_password: first_config.dig('vm', 'vm_password'),
public_ssh_key: 'A PUBLIC KEY',
custom_hostname: first_config.dig('vm', 'custom_hostname')
},
{
cluster: first_config.dig('vsphere', 'cluster'),
resource_pool: first_config.dig('vsphere', 'resource_pool'),
datastore: first_config.dig('vsphere', 'datastore'),
network: first_config.dig('vsphere', 'network'),
folder: first_config.dig('vsphere', 'folder'),
},
)

manager.deploy(paths: ['FIRST_FAKE_PATH'])
end
end

context 'when the ENV vsphere VM password is set' do
before do
stub_const('ENV', { 'PROVISION_WITH_PASSWORD' => 'true', 'VSPHERE_VM_PASSWORD' => 'a-password' })
first_config['vm']['vm_password'] = nil
end

it 'deploys with the ENV vm password' do
expect(first_ova_manager).to receive(:deploy).with(
'FIRST_FAKE_PATH',
{
ip: first_config.dig('vm', 'ip'),
gateway: first_config.dig('vm', 'gateway'),
netmask: first_config.dig('vm', 'netmask'),
dns: first_config.dig('vm', 'dns'),
ntp_servers: first_config.dig('vm', 'ntp_servers'),
cpus: first_config.dig('vm', 'cpus'),
ram_mb: first_config.dig('vm', 'ram_mb'),
vm_password: 'a-password',
public_ssh_key: 'A PUBLIC KEY',
custom_hostname: first_config.dig('vm', 'custom_hostname')
},
{
cluster: first_config.dig('vsphere', 'cluster'),
resource_pool: first_config.dig('vsphere', 'resource_pool'),
datastore: first_config.dig('vsphere', 'datastore'),
network: first_config.dig('vsphere', 'network'),
folder: first_config.dig('vsphere', 'folder'),
},
)

manager.deploy(paths: ['FIRST_FAKE_PATH'])
end
end

context 'and neither vm password is set' do
before do
first_config['vm']['vm_password'] = nil
end

it 'deploys with the hardcoded vm password' do
expect(first_ova_manager).to receive(:deploy).with(
'FIRST_FAKE_PATH',
{
ip: first_config.dig('vm', 'ip'),
gateway: first_config.dig('vm', 'gateway'),
netmask: first_config.dig('vm', 'netmask'),
dns: first_config.dig('vm', 'dns'),
ntp_servers: first_config.dig('vm', 'ntp_servers'),
cpus: first_config.dig('vm', 'cpus'),
ram_mb: first_config.dig('vm', 'ram_mb'),
vm_password: 'tempest',
public_ssh_key: 'A PUBLIC KEY',
custom_hostname: first_config.dig('vm', 'custom_hostname')
},
{
cluster: first_config.dig('vsphere', 'cluster'),
resource_pool: first_config.dig('vsphere', 'resource_pool'),
datastore: first_config.dig('vsphere', 'datastore'),
network: first_config.dig('vsphere', 'network'),
folder: first_config.dig('vsphere', 'folder'),
},
)
manager.deploy(paths: ['FIRST_FAKE_PATH'])
end
end
end

Expand Down

0 comments on commit 56fa188

Please sign in to comment.