From 0bff2df07921c285011c041fa0a552ede3d7b977 Mon Sep 17 00:00:00 2001 From: Samuel Beaulieu Date: Fri, 8 Jul 2022 08:56:12 -0500 Subject: [PATCH] Change the way we load secrets so that we do not have to pass them as ENV vars. they will be pulled from the provider config, similarily to the other providers --- README.md | 2 +- lib/vmpooler/aws_setup.rb | 2 +- lib/vmpooler/providers/ec2.rb | 18 +++++++++++------ spec/unit/providers/ec2_spec.rb | 34 +++++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index de7332b..2fb385c 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ aws authorization is handled via two required ENV vars When you add the pool config `provision: true` to a pool, the new VMs will also get initialized with extra steps to setup the sshd config via NET:SSH These steps expect two environment vars 1. ROOT_KEYS_SCRIPT: (optional) the URI location of a script (eg https in github) that will be run to setup keys. If not set, this will be skipped -2. KEY_FILE_LOCATION: (required) the location on local disk where the ssh key resides for VMPooler to connect via SSH to the EC2 node +2. AWS_KEY_FILE_LOCATION: (required) the location on local disk where the ssh key resides for VMPooler to connect via SSH to the EC2 node ### DNS AWS will setup a private ip and private dns hostname for the VM once running. Optionally we can setup a human readable DNS entry to resolve the VMPooler provider `spicy-proton` fqdn diff --git a/lib/vmpooler/aws_setup.rb b/lib/vmpooler/aws_setup.rb index 94a9b99..90a0825 100644 --- a/lib/vmpooler/aws_setup.rb +++ b/lib/vmpooler/aws_setup.rb @@ -11,7 +11,7 @@ module Vmpooler ROOT_KEYS_SYNC_CMD = "curl -k -o - -L #{ROOT_KEYS_SCRIPT} | %s" def self.setup_node_by_ssh(host, platform) - @key_file = ENV['KEY_FILE_LOCATION'] || '/app/abs/.ssh/abs-aws-ec2.rsa' + @key_file = ENV['AWS_KEY_FILE_LOCATION'] conn = check_ssh_accepting_connections(host, platform) configure_host(host, platform, conn) end diff --git a/lib/vmpooler/providers/ec2.rb b/lib/vmpooler/providers/ec2.rb index e72c877..4a7c26c 100644 --- a/lib/vmpooler/providers/ec2.rb +++ b/lib/vmpooler/providers/ec2.rb @@ -17,8 +17,8 @@ module Vmpooler def initialize(config, logger, metrics, redis_connection_pool, name, options) super(config, logger, metrics, redis_connection_pool, name, options) - @aws_access_key = ENV['ABS_AWS_ACCESS_KEY'] - @aws_secret_key = ENV['ABS_AWS_SECRET_KEY'] + @aws_access_key = ENV['ABS_AWS_ACCESS_KEY'] || provider_config['ABS_AWS_ACCESS_KEY'] + @aws_secret_key = ENV['ABS_AWS_SECRET_KEY'] || provider_config['ABS_AWS_SECRET_KEY'] task_limit = global_config[:config].nil? || global_config[:config]['task_limit'].nil? ? 10 : global_config[:config]['task_limit'].to_i # The default connection pool size is: @@ -123,10 +123,16 @@ module Vmpooler pool = pool_config(pool_name) raise("Pool #{pool_name} does not exist for the provider #{name}") if pool.nil? - filters = [{ - name: 'tag:pool', - values: [pool_name] - }] + filters = [ + { + name: 'tag:pool', + values: [pool_name] + }, + { + name: 'instance-state-name', + values: %w[pending running shutting-down stopping stopped] + } + ] instance_list = connection.instances(filters: filters) return vms if instance_list.first.nil? diff --git a/spec/unit/providers/ec2_spec.rb b/spec/unit/providers/ec2_spec.rb index f1d4850..5225835 100644 --- a/spec/unit/providers/ec2_spec.rb +++ b/spec/unit/providers/ec2_spec.rb @@ -53,16 +53,38 @@ EOT describe '#manual tests live' do context 'in itsysops' do + let(:vmname) { "instance-50" } + let(:poolname) { "ubuntu-2004-arm64" } + let(:config) { YAML.load(<<~EOT + --- + :config: + max_tries: 3 + retry_factor: 10 + :providers: + :ec2: + connection_pool_timeout: 1 + zone: '#{zone}' + region: '#{region}' + :pools: + - name: '#{poolname}' + alias: [ 'mockpool' ] + amisize: 'a1.large' + template: 'ami-03c1b544a7566b3e5' + size: 5 + timeout: 10 + ready_ttl: 1440 + provider: 'ec2' + provision: 'true' + EOT + ) + } before(:each) { - config['provision'] = "true" allow(subject).to receive(:dns).and_call_original } - let(:vmname) { "instance-46" } - let(:poolname) { "ubuntu-2004-arm64" } skip 'gets a vm' do - - # result = subject.create_vm(poolname, vmname) - subject.provision_node_aws("ip-10-227-4-27.amz-dev.puppet.net", poolname) + result = subject.create_vm(poolname, vmname) + #subject.vms_in_pool("amazon-6-x86_64-ec2") + #subject.provision_node_aws("ip-10-227-4-97.amz-dev.puppet.net", poolname) # subject.create_snapshot(poolname, vmname, "foo") #subject.create_disk(poolname, vmname, 10) # a = subject.destroy_vm(poolname, vmname)