From 528e9635d199d9a97ab1ccb9f8a363dba62f2482 Mon Sep 17 00:00:00 2001 From: Jake Spain Date: Tue, 14 Mar 2023 07:42:38 -0400 Subject: [PATCH] exit application if domain setting is used --- lib/vmpooler.rb | 4 +++ spec/fixtures/vmpooler_domain.yaml | 45 ++++++++++++++++++++++++++++++ spec/unit/vmpooler_spec.rb | 25 +++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 spec/fixtures/vmpooler_domain.yaml diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index cfb2e2c..54c4ffc 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -76,6 +76,10 @@ module Vmpooler parsed_config[:config]['prefix'] = ENV['PREFIX'] || parsed_config[:config]['prefix'] || '' parsed_config[:config]['logfile'] = ENV['LOGFILE'] if ENV['LOGFILE'] parsed_config[:config]['site_name'] = ENV['SITE_NAME'] if ENV['SITE_NAME'] + if !parsed_config[:config]['domain'].nil? || !ENV['DOMAIN'].nil? + puts '[!] [error] The "domain" config setting has been removed in v3. Please see the docs for migrating the domain config to use a dns plugin at https://github.com/puppetlabs/vmpooler/blob/main/README.md#migrating-to-v3' + exit 1 + end parsed_config[:config]['clone_target'] = ENV['CLONE_TARGET'] if ENV['CLONE_TARGET'] parsed_config[:config]['timeout'] = string_to_int(ENV['TIMEOUT']) if ENV['TIMEOUT'] parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH'] diff --git a/spec/fixtures/vmpooler_domain.yaml b/spec/fixtures/vmpooler_domain.yaml new file mode 100644 index 0000000..9a79726 --- /dev/null +++ b/spec/fixtures/vmpooler_domain.yaml @@ -0,0 +1,45 @@ +--- +:providers: + :dummy: + +:redis: + server: 'localhost' + +:auth: + provider: dummy + +:tagfilter: + url: '(.*)\/' + +:config: + site_name: 'vmpooler' + # Need to change this on Windows + logfile: '/var/log/vmpooler.log' + task_limit: 10 + timeout: 15 + vm_checktime: 1 + vm_lifetime: 12 + vm_lifetime_auth: 24 + allowed_tags: + - 'created_by' + - 'project' + domain: 'example.com' + prefix: 'poolvm-' + +# Uncomment the lines below to suppress metrics to STDOUT +# :statsd: +# server: 'localhost' +# prefix: 'vmpooler' +# port: 8125 + +:pools: + - name: 'pool01' + size: 5 + provider: dummy + dns_plugin: 'example' + ready_ttl: 5 + - name: 'pool02' + size: 5 + provider: dummy + dns_plugin: 'example' + ready_ttl: 5 diff --git a/spec/unit/vmpooler_spec.rb b/spec/unit/vmpooler_spec.rb index 2e9831f..8e6d39a 100644 --- a/spec/unit/vmpooler_spec.rb +++ b/spec/unit/vmpooler_spec.rb @@ -70,5 +70,30 @@ describe 'Vmpooler' do expect(Vmpooler.config[:config]).not_to be_nil #merge does not deleted existing keys end end + + context 'when domain' do + context 'is set as a variable' do + before(:each) do + ENV['VMPOOLER_CONFIG_FILE'] = config_file + ENV['DOMAIN'] = 'example.com' + end + + it 'should exit' do + expect { Vmpooler.config }.to raise_error(SystemExit) + end + end + + context 'is set in a config file' do + let(:config_file) { File.join(fixtures_dir, 'vmpooler_domain.yaml') } + + before(:each) do + ENV['VMPOOLER_CONFIG_FILE'] = config_file + end + + it 'should exit' do + expect { Vmpooler.config }.to raise_error(SystemExit) + end + end + end end end