openstudio-aws 0.3.2 → 0.4.0.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/CHANGELOG.md +8 -3
- data/Gemfile +1 -1
- data/lib/openstudio/aws/aws.rb +109 -58
- data/lib/openstudio/aws/config.rb +16 -35
- data/lib/openstudio/aws/version.rb +1 -1
- data/lib/openstudio/core_ext/hash.rb +22 -0
- data/lib/openstudio/lib/ami_list.rb +29 -3
- data/lib/openstudio/lib/openstudio_aws_instance.rb +16 -14
- data/lib/openstudio/lib/openstudio_aws_logger.rb +1 -2
- data/lib/openstudio/lib/openstudio_aws_wrapper.rb +71 -23
- data/lib/openstudio/lib/openstudio_cloud_watch.rb +55 -0
- data/lib/openstudio/lib/server_script.sh.template +1 -19
- data/lib/openstudio/lib/worker_script.sh.template +8 -17
- data/lib/openstudio-aws.rb +4 -1
- data/openstudio-aws.gemspec +2 -2
- data/spec/aws_instances/aws_spec_api.rb +86 -58
- data/spec/openstudio-aws/ami_list_spec.rb +9 -0
- data/spec/openstudio-aws/aws_spec.rb +23 -1
- data/spec/openstudio-aws/aws_wrapper_spec.rb +3 -2
- data/spec/openstudio-aws/config_spec.rb +0 -44
- metadata +9 -7
@@ -1,6 +1,5 @@
|
|
1
|
-
# NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files
|
2
1
|
######################################################################
|
3
|
-
# Copyright (c) 2008-
|
2
|
+
# Copyright (c) 2008-2015, Alliance for Sustainable Energy.
|
4
3
|
# All rights reserved.
|
5
4
|
#
|
6
5
|
# This library is free software; you can redistribute it and/or
|
@@ -54,7 +53,8 @@ class OpenStudioAwsWrapper
|
|
54
53
|
VALID_OPTIONS = [:proxy, :credentials]
|
55
54
|
|
56
55
|
def initialize(options = {}, group_uuid = nil)
|
57
|
-
@group_uuid = group_uuid || (SecureRandom.uuid).
|
56
|
+
@group_uuid = group_uuid || (SecureRandom.uuid).gsub('-', '')
|
57
|
+
logger.info "GroupUUID is #{@group_uuid}"
|
58
58
|
|
59
59
|
@security_groups = []
|
60
60
|
@key_pair_name = nil
|
@@ -118,15 +118,44 @@ class OpenStudioAwsWrapper
|
|
118
118
|
describe_availability_zones.to_json
|
119
119
|
end
|
120
120
|
|
121
|
-
def
|
121
|
+
def total_instances_count
|
122
122
|
resp = @aws.describe_instance_status
|
123
123
|
|
124
|
+
# TODO: make this return the region not the availability zone
|
124
125
|
region = resp.instance_statuses.length > 0 ? resp.instance_statuses.first.availability_zone : 'no_instances'
|
125
126
|
{ total_instances: resp.instance_statuses.length, region: region }
|
126
127
|
end
|
127
128
|
|
128
|
-
|
129
|
-
|
129
|
+
# describe the instances by group id (this is the default method)
|
130
|
+
def describe_instances
|
131
|
+
resp = nil
|
132
|
+
if group_uuid
|
133
|
+
resp = @aws.describe_instances(
|
134
|
+
filters: [
|
135
|
+
# {name: 'instance-state-code', values: [0.to_s, 16.to_s]}, # running or pending -- any state
|
136
|
+
{ name: 'tag-key', values: ['GroupUUID'] },
|
137
|
+
{ name: 'tag-value', values: [group_uuid.to_s] }
|
138
|
+
]
|
139
|
+
)
|
140
|
+
else
|
141
|
+
resp = @aws.describe_instances
|
142
|
+
end
|
143
|
+
|
144
|
+
# Any additional filters
|
145
|
+
instance_data = nil
|
146
|
+
if resp
|
147
|
+
instance_data = []
|
148
|
+
resp.reservations.each do |r|
|
149
|
+
r.instances.each do |i|
|
150
|
+
i_h = i.to_hash
|
151
|
+
if i_h[:tags].any? { |h| (h[:key] == 'GroupUUID') && (h[:value] == group_uuid.to_s) }
|
152
|
+
instance_data << i_h
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
instance_data
|
130
159
|
end
|
131
160
|
|
132
161
|
# return all of the running instances, or filter by the group_uuid & instance type
|
@@ -220,13 +249,14 @@ class OpenStudioAwsWrapper
|
|
220
249
|
end
|
221
250
|
|
222
251
|
def terminate_instances(ids)
|
252
|
+
resp = nil
|
223
253
|
begin
|
224
254
|
resp = @aws.terminate_instances(
|
225
255
|
instance_ids: ids
|
226
256
|
)
|
227
257
|
rescue Aws::EC2::Errors::InvalidInstanceIDNotFound
|
228
258
|
# Log that the instances couldn't be found?
|
229
|
-
|
259
|
+
resp = { error: 'instances could not be found' }
|
230
260
|
end
|
231
261
|
|
232
262
|
resp
|
@@ -263,12 +293,26 @@ class OpenStudioAwsWrapper
|
|
263
293
|
logger.info("create key pair: #{@key_pair_name}")
|
264
294
|
end
|
265
295
|
|
296
|
+
# Delete the key pair from aws
|
297
|
+
def delete_key_pair(key_pair_name = nil)
|
298
|
+
tmp_name = key_pair_name || "os-key-pair-#{@group_uuid}"
|
299
|
+
resp = nil
|
300
|
+
begin
|
301
|
+
logger.info "Trying to delete key pair #{tmp_name}"
|
302
|
+
resp = @aws.delete_key_pair(key_name: tmp_name)
|
303
|
+
rescue
|
304
|
+
logger.info "could not delete the key pair '#{tmp_name}'"
|
305
|
+
end
|
306
|
+
|
307
|
+
resp
|
308
|
+
end
|
309
|
+
|
266
310
|
def load_private_key(filename)
|
267
311
|
unless File.exist? filename
|
268
312
|
# check if the file basename exists in your user directory
|
269
313
|
filename = File.expand_path("~/.ssh/#{File.basename(filename)}")
|
270
314
|
if File.exist? filename
|
271
|
-
|
315
|
+
logger.info "Found key of same name in user's home ssh folder #{filename}"
|
272
316
|
# using the key in your home directory
|
273
317
|
else
|
274
318
|
fail "Could not find private key #{filename}" unless File.exist? filename
|
@@ -279,11 +323,13 @@ class OpenStudioAwsWrapper
|
|
279
323
|
@private_key = File.read(filename)
|
280
324
|
end
|
281
325
|
|
282
|
-
def save_private_key(filename)
|
326
|
+
def save_private_key(directory = '.', filename = 'ec2_server_key.pem')
|
283
327
|
if @private_key
|
284
|
-
@private_key_file_name = File.expand_path filename
|
285
|
-
|
286
|
-
File.
|
328
|
+
@private_key_file_name = File.expand_path "#{directory}/#{filename}"
|
329
|
+
logger.info "Saving server private key in #{@private_key_file_name}"
|
330
|
+
File.open(@private_key_file_name, 'w') { |f| f << @private_key }
|
331
|
+
logger.info 'Setting permissions of server private key to 0600'
|
332
|
+
|
287
333
|
else
|
288
334
|
fail "No private key found in which to persist with filename #{filename}"
|
289
335
|
end
|
@@ -291,8 +337,15 @@ class OpenStudioAwsWrapper
|
|
291
337
|
|
292
338
|
# save off the worker public/private keys that were created
|
293
339
|
def save_worker_keys(directory = '.')
|
294
|
-
|
295
|
-
|
340
|
+
wk = "#{directory}/ec2_worker_key.pem"
|
341
|
+
logger.info "Saving worker private key in #{wk}"
|
342
|
+
File.open(wk, 'w') { |f| f << @worker_keys.private_key }
|
343
|
+
logger.info 'Setting permissions of worker private key to 0600'
|
344
|
+
File.chmod(0600, wk)
|
345
|
+
|
346
|
+
wk = "#{directory}/ec2_worker_key.pub"
|
347
|
+
logger.info "Saving worker public key in #{wk}"
|
348
|
+
File.open(wk, 'w') { |f| f << @worker_keys.public_key }
|
296
349
|
end
|
297
350
|
|
298
351
|
def launch_server(image_id, instance_type, launch_options = {})
|
@@ -397,8 +450,8 @@ class OpenStudioAwsWrapper
|
|
397
450
|
@group_uuid = server_data_hash[:group_id] || @group_uuid
|
398
451
|
load_private_key(server_data_hash[:server][:private_key_file_name])
|
399
452
|
|
400
|
-
logger.info "
|
401
|
-
fail 'no
|
453
|
+
logger.info "Finding the server for GroupUUID of #{group_uuid}"
|
454
|
+
fail 'no GroupUUID defined either in member variable or method argument' if group_uuid.nil?
|
402
455
|
|
403
456
|
# This should really just be a single call to describe running instances
|
404
457
|
@server = nil
|
@@ -417,7 +470,7 @@ class OpenStudioAwsWrapper
|
|
417
470
|
logger.info "Server instance is already defined with instance #{resp[:instance_id]}"
|
418
471
|
end
|
419
472
|
else
|
420
|
-
|
473
|
+
logger.info 'could not find a running server instance'
|
421
474
|
end
|
422
475
|
|
423
476
|
# find the workers
|
@@ -538,7 +591,7 @@ class OpenStudioAwsWrapper
|
|
538
591
|
sv = ami[:tags_hash][:openstudio_server_version]
|
539
592
|
|
540
593
|
if sv.nil? || sv == ''
|
541
|
-
|
594
|
+
logger.info 'found nil version, incrementing from 0.0.1'
|
542
595
|
sv = get_next_version('0.0.1', list_of_svs)
|
543
596
|
end
|
544
597
|
list_of_svs << sv
|
@@ -590,10 +643,8 @@ class OpenStudioAwsWrapper
|
|
590
643
|
end
|
591
644
|
end
|
592
645
|
end
|
593
|
-
# puts "Current AMIs: #{JSON.pretty_generate(amis)}"
|
594
646
|
|
595
647
|
# merge in the existing AMIs the existing amis into the 'unknown category, but don't flag them as 'deprecate'
|
596
|
-
# puts "Existing AMIs: #{JSON.pretty_generate(existing)}"
|
597
648
|
existing.keys.each do |ami_key|
|
598
649
|
next if ami_key == 'default'.to_sym # ignore default
|
599
650
|
|
@@ -612,7 +663,6 @@ class OpenStudioAwsWrapper
|
|
612
663
|
a[:openstudio_server_version] = next_version.to_s
|
613
664
|
end
|
614
665
|
|
615
|
-
# puts "After merge: #{JSON.pretty_generate(amis)}"
|
616
666
|
# flip these around for openstudio server section
|
617
667
|
amis[:openstudio_server].keys.each do |key|
|
618
668
|
next if key.to_s.to_version.satisfies('0.0.*')
|
@@ -639,8 +689,6 @@ class OpenStudioAwsWrapper
|
|
639
689
|
end
|
640
690
|
amis[:openstudio] = Hash[amis[:openstudio].sort_by { |k, _| k.to_s.to_version }.reverse]
|
641
691
|
|
642
|
-
# puts "After sort: #{JSON.pretty_generate(amis)}"
|
643
|
-
|
644
692
|
amis
|
645
693
|
end
|
646
694
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
######################################################################
|
2
|
+
# Copyright (c) 2008-2015, Alliance for Sustainable Energy.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
######################################################################
|
19
|
+
|
20
|
+
require_relative 'openstudio_aws_logger'
|
21
|
+
|
22
|
+
class OpenStudioCloudWatch
|
23
|
+
include Logging
|
24
|
+
|
25
|
+
attr_accessor :private_key_file_name
|
26
|
+
attr_accessor :security_groups
|
27
|
+
|
28
|
+
VALID_OPTIONS = [:proxy, :credentials]
|
29
|
+
|
30
|
+
def initialize(options = {})
|
31
|
+
# store an instance variable with the proxy for passing to instances for use in scp/ssh
|
32
|
+
@proxy = options[:proxy] ? options[:proxy] : nil
|
33
|
+
|
34
|
+
# need to remove the prxoy information here
|
35
|
+
@aws = Aws::CloudWatch::Client.new(options[:credentials])
|
36
|
+
end
|
37
|
+
|
38
|
+
def estimated_charges
|
39
|
+
end_time = Time.now.utc
|
40
|
+
start_time = end_time - 86400
|
41
|
+
resp = @aws.get_metric_statistics(
|
42
|
+
dimensions: [
|
43
|
+
{ name: 'ServiceName', value: 'AmazonEC2' },
|
44
|
+
{ name: 'Currency', value: 'USD' }],
|
45
|
+
metric_name: 'EstimatedCharges',
|
46
|
+
namespace: 'AWS/Billing',
|
47
|
+
start_time: start_time.iso8601,
|
48
|
+
end_time: end_time.iso8601,
|
49
|
+
period: 300,
|
50
|
+
statistics: ['Maximum']
|
51
|
+
)
|
52
|
+
|
53
|
+
resp.data || []
|
54
|
+
end
|
55
|
+
end
|
@@ -44,28 +44,12 @@ chmod 775 /usr/local/bin/ec2-metadata
|
|
44
44
|
mkdir -p /etc/openstudio-server
|
45
45
|
ec2-metadata -a -i -t -h -o -z -p -v > /etc/openstudio-server/instance.yml
|
46
46
|
|
47
|
-
# make sure supervisor is running
|
48
|
-
sudo service supervisor start
|
49
|
-
|
50
47
|
# stop the various services that use mongo
|
51
48
|
service delayed_job stop
|
52
|
-
supervisorctl stop delayed_job
|
53
49
|
service apache2 stop
|
54
50
|
service mongodb stop
|
55
51
|
service mongod stop
|
56
52
|
|
57
|
-
# make sure the the /mnt directory exists if i2 instances.
|
58
|
-
# For now this assumes that the volume is xvdb. In the future this
|
59
|
-
# should be dynamic
|
60
|
-
if ec2-metadata --instance-type | grep -q 'i2.'; then
|
61
|
-
mkfs.ext4 /dev/xvdb
|
62
|
-
mkdir -p /mnt
|
63
|
-
mount -t ext4 /dev/xvdb /mnt
|
64
|
-
|
65
|
-
echo "/dev/xvdb /mnt auto noatime 0 0" | sudo tee -a /etc/fstab
|
66
|
-
mount -a
|
67
|
-
fi
|
68
|
-
|
69
53
|
# remove mongo db & add it back
|
70
54
|
mkdir -p /mnt/mongodb/data
|
71
55
|
chown mongodb:nogroup /mnt/mongodb/data
|
@@ -134,11 +118,9 @@ find /mnt/openstudio -type f -print0 | xargs -0 chmod 664
|
|
134
118
|
|
135
119
|
# restart rserve
|
136
120
|
service Rserve restart
|
137
|
-
supervisorctl restart Rserve
|
138
121
|
|
139
|
-
#
|
122
|
+
# restart delayed jobs
|
140
123
|
service delayed_job start
|
141
|
-
supervisorctl start delayed_job
|
142
124
|
|
143
125
|
#file flag the user_data has completed
|
144
126
|
cat /dev/null > /home/ubuntu/user_data_done
|
@@ -35,18 +35,6 @@ chmod 775 /usr/local/bin/ec2-metadata
|
|
35
35
|
mkdir -p /etc/openstudio-server
|
36
36
|
ec2-metadata -a -i -t -h -o -z -p -v > /etc/openstudio-server/instance.yml
|
37
37
|
|
38
|
-
# make sure the the /mnt directory exists if i2 instances.
|
39
|
-
# For now this assumes that the volume is xvdb. In the future this
|
40
|
-
# should be dynamic
|
41
|
-
if ec2-metadata --instance-type | grep -q 'i2.'; then
|
42
|
-
mkfs.ext4 /dev/xvdb
|
43
|
-
mkdir -p /mnt
|
44
|
-
mount -t ext4 /dev/xvdb /mnt
|
45
|
-
|
46
|
-
echo "/dev/xvdb /mnt auto noatime 0 0" | sudo tee -a /etc/fstab
|
47
|
-
mount -a
|
48
|
-
fi
|
49
|
-
|
50
38
|
## Worker Data Configuration -- On Vagrant this is a separate file
|
51
39
|
|
52
40
|
rm -f /tmp/snow.log
|
@@ -75,11 +63,14 @@ find /mnt/openstudio -type f -print0 | xargs -0 chmod 664
|
|
75
63
|
|
76
64
|
## End Worker Data Configuration
|
77
65
|
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
|
66
|
+
#turn off hyperthreading
|
67
|
+
# NL: do not turn off hyperthreading, rather, just limit the number of cores and see if it
|
68
|
+
# makes a difference.
|
69
|
+
#for cpunum in $(
|
70
|
+
# cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list |
|
71
|
+
# cut -s -d, -f2- | tr ',' '\n' | sort -un); do
|
72
|
+
# echo 0 > /sys/devices/system/cpu/cpu$cpunum/online
|
73
|
+
#done
|
83
74
|
|
84
75
|
#file flag the user_data has completed
|
85
76
|
cat /dev/null > /home/ubuntu/user_data_done
|
data/lib/openstudio-aws.rb
CHANGED
@@ -16,13 +16,16 @@ begin
|
|
16
16
|
rescue LoadError
|
17
17
|
puts 'Failed to load AWS-SDK-CORE gem'
|
18
18
|
puts ' try running: gem install aws-sdk-core'
|
19
|
-
|
19
|
+
|
20
|
+
exit 1
|
20
21
|
end
|
21
22
|
|
23
|
+
require 'openstudio/core_ext/hash'
|
22
24
|
require 'openstudio/lib/openstudio_aws_logger'
|
23
25
|
require 'openstudio/aws/aws'
|
24
26
|
require 'openstudio/aws/config'
|
25
27
|
require 'openstudio/aws/version'
|
26
28
|
require 'openstudio/lib/openstudio_aws_instance'
|
27
29
|
require 'openstudio/lib/openstudio_aws_wrapper'
|
30
|
+
require 'openstudio/lib/openstudio_cloud_watch'
|
28
31
|
require 'openstudio/lib/ami_list'
|
data/openstudio-aws.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_dependency 'net-scp', '~> 1.1'
|
21
21
|
s.add_dependency 'aws-sdk-core', '~> 2.0'
|
22
|
-
s.add_dependency 'semantic', '~> 1.
|
23
|
-
s.add_dependency 'sshkey', '~> 1.
|
22
|
+
s.add_dependency 'semantic', '~> 1.4'
|
23
|
+
s.add_dependency 'sshkey', '~> 1.7'
|
24
24
|
|
25
25
|
s.add_development_dependency 'bundler', '~> 1.7'
|
26
26
|
s.add_development_dependency 'rake', '~> 10.4'
|
@@ -12,6 +12,7 @@ describe OpenStudio::Aws::Aws do
|
|
12
12
|
@group_id = nil
|
13
13
|
|
14
14
|
FileUtils.rm_f 'ec2_server_key.pem' if File.exist? 'ec2_server_key.pem'
|
15
|
+
FileUtils.rm_f 'server_data.json' if File.exist? 'server_data.json'
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'should create a new instance' do
|
@@ -27,6 +28,8 @@ describe OpenStudio::Aws::Aws do
|
|
27
28
|
|
28
29
|
@aws.create_server(options)
|
29
30
|
|
31
|
+
@aws.save_cluster_info 'server_data.json'
|
32
|
+
|
30
33
|
expect(File.exist?('ec2_server_key.pem')).to be true
|
31
34
|
expect(File.exist?('server_data.json')).to be true
|
32
35
|
expect(File.exist?('ec2_worker_key.pem')).to be true
|
@@ -64,19 +67,38 @@ describe OpenStudio::Aws::Aws do
|
|
64
67
|
expect(@aws.os_aws.server).not_to be_nil
|
65
68
|
end
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
after :all do
|
71
|
+
if File.exist? 'server_data.json'
|
72
|
+
j = JSON.parse(File.read('server_data.json'), symbolize_names: true)
|
73
|
+
|
74
|
+
@aws.terminate_instances_by_group_id(j[:group_id])
|
75
|
+
end
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
72
79
|
context 'upload data to a server' do
|
73
|
-
|
80
|
+
before :all do
|
81
|
+
@group_id = nil
|
82
|
+
|
74
83
|
config = OpenStudio::Aws::Config.new
|
75
|
-
aws = OpenStudio::Aws::Aws.new
|
84
|
+
@aws = OpenStudio::Aws::Aws.new
|
85
|
+
end
|
76
86
|
|
77
|
-
|
87
|
+
it 'should create a server' do
|
88
|
+
options = {
|
89
|
+
instance_type: 'm3.medium',
|
90
|
+
image_id: SERVER_AMI
|
91
|
+
}
|
78
92
|
|
79
|
-
aws.create_server(options)
|
93
|
+
@aws.create_server(options)
|
94
|
+
@aws.create_workers(0, options)
|
95
|
+
|
96
|
+
@aws.save_cluster_info 'server_data.json'
|
97
|
+
|
98
|
+
h = @aws.os_aws.server.to_os_hash
|
99
|
+
expect(h[:group_id]).to be_a String
|
100
|
+
expect(h[:group_id]).to match /^[\d\S]{32}$/
|
101
|
+
@group_id = h[:group_id]
|
80
102
|
end
|
81
103
|
|
82
104
|
it 'should upload a file after loading the existing server' do
|
@@ -90,7 +112,6 @@ describe OpenStudio::Aws::Aws do
|
|
90
112
|
aws2.load_instance_info_from_file('server_data.json')
|
91
113
|
|
92
114
|
expect(aws2.os_aws.server.group_uuid).to eq j[:group_id]
|
93
|
-
puts aws2.os_aws.server.inspect
|
94
115
|
|
95
116
|
local_file = File.expand_path('spec/resources/upload_me.sh')
|
96
117
|
remote_file = '/home/ubuntu/i_uploaded_this_file.sh'
|
@@ -111,7 +132,11 @@ describe OpenStudio::Aws::Aws do
|
|
111
132
|
end
|
112
133
|
|
113
134
|
after :all do
|
114
|
-
|
135
|
+
if File.exist? 'server_data.json'
|
136
|
+
j = JSON.parse(File.read('server_data.json'), symbolize_names: true)
|
137
|
+
|
138
|
+
@aws.terminate_instances_by_group_id(j[:group_id])
|
139
|
+
end
|
115
140
|
end
|
116
141
|
end
|
117
142
|
|
@@ -152,6 +177,8 @@ describe OpenStudio::Aws::Aws do
|
|
152
177
|
|
153
178
|
@aws.create_server(options)
|
154
179
|
|
180
|
+
@aws.save_cluster_info 'server_data.json'
|
181
|
+
|
155
182
|
expect(File.exist?('ec2_server_key.pem')).to be true
|
156
183
|
expect(File.exist?('server_data.json')).to be true
|
157
184
|
expect(@aws.os_aws.server).not_to be_nil
|
@@ -161,8 +188,6 @@ describe OpenStudio::Aws::Aws do
|
|
161
188
|
expect(h[:group_id]).to match /^[\d\S]{32}$/
|
162
189
|
expect(h[:location]).to eq 'AWS'
|
163
190
|
|
164
|
-
puts h.inspect
|
165
|
-
|
166
191
|
@group_id = h[:group_id]
|
167
192
|
ensure
|
168
193
|
@aws.terminate_instances_by_group_id(h[:group_id])
|
@@ -178,52 +203,10 @@ describe OpenStudio::Aws::Aws do
|
|
178
203
|
@group_id = nil
|
179
204
|
end
|
180
205
|
|
181
|
-
it 'should
|
182
|
-
begin
|
183
|
-
begin
|
184
|
-
options = {
|
185
|
-
instance_type: 'm3.medium',
|
186
|
-
image_id: SERVER_AMI,
|
187
|
-
tags: [
|
188
|
-
'ci_tests=true',
|
189
|
-
'ServerOnly=true'
|
190
|
-
]
|
191
|
-
}
|
192
|
-
|
193
|
-
expect { @aws.create_workers(0) }.to raise_error "Can't create workers without a server instance running"
|
194
|
-
|
195
|
-
test_pem_file = 'ec2_server_key.pem'
|
196
|
-
FileUtils.rm_f test_pem_file if File.exist? test_pem_file
|
197
|
-
FileUtils.rm_f 'server_data.json' if File.exist? 'server_data.json'
|
198
|
-
|
199
|
-
@aws.create_server(options)
|
200
|
-
|
201
|
-
# Still have to call "create workers" or the configuration won't happen.
|
202
|
-
@aws.create_workers(0, options)
|
203
|
-
|
204
|
-
h = @aws.os_aws.server.to_os_hash
|
205
|
-
expect(h[:group_id]).to be_a String
|
206
|
-
expect(h[:group_id]).to match /^[\d\S]{32}$/
|
207
|
-
expect(h[:location]).to eq 'AWS'
|
208
|
-
ensure
|
209
|
-
@aws.terminate_instances_by_group_id(h[:group_id])
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'i2-instances' do
|
216
|
-
before :all do
|
217
|
-
@config = OpenStudio::Aws::Config.new
|
218
|
-
@aws = OpenStudio::Aws::Aws.new
|
219
|
-
|
220
|
-
@group_id = nil
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'should create an i2 instance and mount the storage' do
|
206
|
+
it 'should allow a zero length worker' do
|
224
207
|
begin
|
225
208
|
options = {
|
226
|
-
instance_type: '
|
209
|
+
instance_type: 'm3.medium',
|
227
210
|
image_id: SERVER_AMI,
|
228
211
|
tags: [
|
229
212
|
'ci_tests=true',
|
@@ -243,13 +226,58 @@ describe OpenStudio::Aws::Aws do
|
|
243
226
|
@aws.create_workers(0, options)
|
244
227
|
|
245
228
|
h = @aws.os_aws.server.to_os_hash
|
246
|
-
|
247
|
-
|
248
|
-
expect(
|
249
|
-
expect(shell).to eq /\/dev\/xvdb.*\/mnt/
|
229
|
+
expect(h[:group_id]).to be_a String
|
230
|
+
expect(h[:group_id]).to match /^[\d\S]{32}$/
|
231
|
+
expect(h[:location]).to eq 'AWS'
|
250
232
|
ensure
|
251
233
|
@aws.terminate_instances_by_group_id(h[:group_id])
|
252
234
|
end
|
253
235
|
end
|
254
236
|
end
|
237
|
+
|
238
|
+
context 'key locations' do
|
239
|
+
before :all do
|
240
|
+
FileUtils.rm_rf 'spec/output/save_path'
|
241
|
+
|
242
|
+
@config = OpenStudio::Aws::Config.new
|
243
|
+
options = {
|
244
|
+
save_directory: 'spec/output/save_path'
|
245
|
+
}
|
246
|
+
@aws = OpenStudio::Aws::Aws.new(options)
|
247
|
+
|
248
|
+
@group_id = nil
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should allow a different location for saving aws config files' do
|
252
|
+
begin
|
253
|
+
options = {
|
254
|
+
instance_type: 'm3.medium',
|
255
|
+
image_id: SERVER_AMI
|
256
|
+
}
|
257
|
+
|
258
|
+
expect(@aws.save_directory).to eq File.join(File.expand_path('.'), 'spec/output/save_path')
|
259
|
+
|
260
|
+
@aws.create_server(options)
|
261
|
+
|
262
|
+
@aws.save_cluster_info "#{@aws.save_directory}/server_data.json"
|
263
|
+
|
264
|
+
expect(File.exist?('spec/output/save_path/ec2_server_key.pem')).to be true
|
265
|
+
expect(File.exist?('spec/output/save_path/ec2_worker_key.pem')).to be true
|
266
|
+
expect(File.exist?('spec/output/save_path/ec2_worker_key.pub')).to be true
|
267
|
+
expect(File.exist?('spec/output/save_path/server_data.json')).to be true
|
268
|
+
|
269
|
+
expect(@aws.os_aws.server).not_to be_nil
|
270
|
+
expect(@aws.os_aws.server.data.availability_zone).to match /us-east-../
|
271
|
+
|
272
|
+
h = @aws.os_aws.server.to_os_hash
|
273
|
+
expect(h[:group_id]).to be_a String
|
274
|
+
expect(h[:group_id]).to match /^[\d\S]{32}$/
|
275
|
+
@group_id = h[:group_id]
|
276
|
+
ensure
|
277
|
+
@aws.terminate_instances_by_group_id(@group_id)
|
278
|
+
end
|
279
|
+
|
280
|
+
# verify that the instances are dead -- how?
|
281
|
+
end
|
282
|
+
end
|
255
283
|
end
|
@@ -43,6 +43,15 @@ describe OpenStudioAmis do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'version 2' do
|
46
|
+
it 'should return openstudio version 1.7.1 stable & default versions correctly when 1.7.5 is passed' do
|
47
|
+
a = OpenStudioAmis.new(2, openstudio_version: '1.7.5', stable: true)
|
48
|
+
|
49
|
+
amis = a.get_amis
|
50
|
+
|
51
|
+
expect(amis[:server]).to eq('ami-845a54ec')
|
52
|
+
expect(amis[:worker]).to eq('ami-3a5a5452')
|
53
|
+
end
|
54
|
+
|
46
55
|
it 'should return openstudio version 1.7.1 stable & default versions correctly' do
|
47
56
|
a = OpenStudioAmis.new(2, openstudio_version: '1.7.1')
|
48
57
|
|
@@ -80,6 +80,18 @@ describe OpenStudio::Aws::Aws do
|
|
80
80
|
|
81
81
|
expect { aws.create_server(options) }.to raise_error /Must pass in the private_key_file_name/
|
82
82
|
end
|
83
|
+
|
84
|
+
it 'should create a key in another directory' do
|
85
|
+
options = {}
|
86
|
+
aws = OpenStudio::Aws::Aws.new
|
87
|
+
expect(aws.save_directory).to eq File.expand_path('.')
|
88
|
+
|
89
|
+
options = {
|
90
|
+
save_directory: 'spec/output/save_path'
|
91
|
+
}
|
92
|
+
aws = OpenStudio::Aws::Aws.new(options)
|
93
|
+
expect(aws.save_directory).to eq File.join(File.expand_path('.'), 'spec/output/save_path')
|
94
|
+
end
|
83
95
|
end
|
84
96
|
|
85
97
|
context 'proxy configuration' do
|
@@ -92,7 +104,6 @@ describe OpenStudio::Aws::Aws do
|
|
92
104
|
}
|
93
105
|
|
94
106
|
@aws = OpenStudio::Aws::Aws.new(options)
|
95
|
-
# puts @aws.inspect
|
96
107
|
expect(@aws.os_aws).not_to be_nil
|
97
108
|
end
|
98
109
|
|
@@ -140,4 +151,15 @@ describe OpenStudio::Aws::Aws do
|
|
140
151
|
expect(az[:availability_zone_info].first[:zone_name]).to eq 'us-east-1a'
|
141
152
|
end
|
142
153
|
end
|
154
|
+
|
155
|
+
context 'total instances' do
|
156
|
+
it 'should describe the total instances' do
|
157
|
+
options = {}
|
158
|
+
aws = OpenStudio::Aws::Aws.new(options)
|
159
|
+
az = aws.total_instances_count
|
160
|
+
|
161
|
+
expect(az[:total_instances]).to_not be_nil
|
162
|
+
expect(az[:region]).to_not be_nil
|
163
|
+
end
|
164
|
+
end
|
143
165
|
end
|
@@ -5,7 +5,7 @@ describe OpenStudioAwsWrapper do
|
|
5
5
|
context 'unauthenticated session' do
|
6
6
|
it 'should fail to authenticate' do
|
7
7
|
options = {
|
8
|
-
credentials:
|
8
|
+
credentials: {
|
9
9
|
access_key_id: 'some_random_access_key_id',
|
10
10
|
secret_access_key: 'some_super_secret_access_key',
|
11
11
|
region: 'us-east-1',
|
@@ -42,7 +42,7 @@ describe OpenStudioAwsWrapper do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should list number of instances' do
|
45
|
-
resp = @aws.os_aws.
|
45
|
+
resp = @aws.os_aws.total_instances_count
|
46
46
|
expect(resp).not_to be_nil
|
47
47
|
end
|
48
48
|
end
|
@@ -103,6 +103,7 @@ describe OpenStudioAwsWrapper do
|
|
103
103
|
|
104
104
|
it 'should create security group' do
|
105
105
|
sg = @aws.os_aws.create_or_retrieve_default_security_group
|
106
|
+
pp sg
|
106
107
|
expect(sg).to_not be nil
|
107
108
|
end
|
108
109
|
end
|