kitchen-ec2 2.2.1 → 2.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 863664a181278e965fac6bb54cf85b705b88e72c
4
- data.tar.gz: c2245899fe742f202ebe555038931d8df7776452
2
+ SHA256:
3
+ metadata.gz: 047c12b65b4d66719dcd642c0b10fa555f0566dbb45871abdc1d68d1d9aa07ae
4
+ data.tar.gz: affdb19c5f1682c5eb7dfa2db0a385d45657d58b6c6446b3ebe361341e8bcbf1
5
5
  SHA512:
6
- metadata.gz: ad29d9a33374c23d585d1ddbefda2712005a5a5c57117a2e071fffdde98ccb7b43e84b409f6eef9e4c0e0a23620714633d2bab7d2782ce6b99cd595f8da1a2fd
7
- data.tar.gz: 542e97cb2aa201bac249aca2b3cfe790e2a604acefdd916e7eac59beecb644ed167f164d6e8119ff4bd390c636ca218122581f3654e650455f65bada09607fc0
6
+ metadata.gz: 552de0310d60fcff8cf8cdb63b3d0cc5512897cf670ad8d67c1695dc48081aeebc99d3a2d0b027774d4b9a905caaa9ca4f553e0e3995a2530f4b7a49b4ce7313
7
+ data.tar.gz: ec77defad9d3ff3073000142d54e9f66269b6f76f3a218c4958bf3eec5c6a661a45caff9e9c92cadd351ab23047a2a3fd7e43dd9de5f85f19d27fceab351aecd
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
data/.yardopts CHANGED
File without changes
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## [v2.2.2](https://github.com/test-kitchen/kitchen-ec2/tree/v2.2.2) (2018-06-11)
4
+ [Full Changelog](https://github.com/test-kitchen/kitchen-ec2/compare/v2.2.1...v2.2.2)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - Kitchen failure when adding spot\_price [\#328](https://github.com/test-kitchen/kitchen-ec2/issues/328)
9
+
10
+ **Closed issues:**
11
+
12
+ - image\_id: required [\#397](https://github.com/test-kitchen/kitchen-ec2/issues/397)
13
+ - kitchen-ec2 ssh port [\#396](https://github.com/test-kitchen/kitchen-ec2/issues/396)
14
+ - Provide option to terminate after "X" minutes [\#395](https://github.com/test-kitchen/kitchen-ec2/issues/395)
15
+ - Explicitly support usage w/o manual or autoconfiguration of aws\_ssh\_key\_id [\#391](https://github.com/test-kitchen/kitchen-ec2/issues/391)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - Fix dynamic key creation [\#400](https://github.com/test-kitchen/kitchen-ec2/pull/400) ([bdwyertech](https://github.com/bdwyertech))
20
+ - allow AWS-managed ssh key pairs to be disabled [\#392](https://github.com/test-kitchen/kitchen-ec2/pull/392) ([cheeseplus](https://github.com/cheeseplus))
21
+
3
22
  ## [v2.2.1](https://github.com/test-kitchen/kitchen-ec2/tree/v2.2.1) (2018-02-12)
4
23
  [Full Changelog](https://github.com/test-kitchen/kitchen-ec2/compare/v2.2.0...v2.2.1)
5
24
 
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -152,20 +152,30 @@ specify.
152
152
 
153
153
  #### SSH
154
154
 
155
- The `aws_ssh_key_id` value is the name of the AWS key pair you want to use. The default will be read from the `AWS_SSH_KEY_ID` environment variable if set. If a key ID is not specified, a temporary key will be created for you (**>= 2.1.0**).
155
+ The `aws_ssh_key_id` value is the name of the AWS key pair you want to use.
156
156
 
157
- To see a list of existing key pair IDs in a region, run `aws ec2 describe-key-pairs --region us-east-1`.
157
+ The value can be one of:
158
158
 
159
- When using an existing key, ensure that the private key is configured in your
160
- Test Kitchen `transport`, either directly or made available via `ssh-agent`:
159
+ * `nil` (default)
160
+
161
+ By default the key ID is read from the `AWS_SSH_KEY_ID` environment variable. If the environment variable is not set, the value will be nil. In this case, a temporary key will be created for you (**>= 2.1.0**).
162
+
163
+ * `name_of_some_existing_aws_key_pair`
164
+
165
+ By setting the environment variable `AWS_SSH_KEY_ID` or by setting the `aws_ssh_key_id` driver option in kitchen.yml. This will be the key that becomes associated with the test EC2 instances. The key must already exist in AWS. To see a list of existing key pair IDs in a region, use the `aws` CLI tool. For example, in the US-East-1 region: `aws ec2 describe-key-pairs --region us-east-1`.
166
+
167
+ * `_disable`
168
+
169
+ This will not directly associate the EC2 instance with an AWS-managed key pair (pre-existing or auto-generated). This may be useful in environments that have disabled AWS-managed keys. Getting SSH keys onto the instance then becomes an exercise for the reader, though it can be done, for example, with scripting in `user_data` or if the credentials are already baked into the AMI.
170
+
171
+ When using an existing key, either an AWS-managed key pair or keys that exist on the instance through some other means, ensure that the private key is configured in your Test Kitchen `transport` section, either directly or made available via `ssh-agent`:
161
172
 
162
173
  ```yaml
163
174
  transport:
164
175
  ssh_key: ~/.ssh/mykey.pem
165
176
  ```
166
177
 
167
- For standard platforms we automatically provide the SSH username, but when
168
- specifying your own AMI you may need to configure that as well.
178
+ For standard platforms we automatically provide the SSH username, but when specifying your own AMI you may need to configure that as well.
169
179
 
170
180
  #### WinRM
171
181
 
data/Rakefile CHANGED
File without changes
File without changes
File without changes
@@ -217,9 +217,16 @@ module Kitchen
217
217
  end
218
218
 
219
219
  # If no SSH key pair name is specified, create one automatically.
220
- unless config[:aws_ssh_key_id]
220
+ # If `_disabled`, nullify the key ID to avoid associating the instance with
221
+ # an AWS-managed key pair.
222
+ case config[:aws_ssh_key_id]
223
+ when nil
221
224
  create_key(state)
222
225
  config[:aws_ssh_key_id] = state[:auto_key_id]
226
+ when "_disable"
227
+ info("Disabling AWS-managed SSH key pairs for this EC2 instance.")
228
+ info("The key pairs for the kitchen transport config and the AMI must match.")
229
+ config[:aws_ssh_key_id] = nil
223
230
  end
224
231
 
225
232
  if config[:spot_price]
@@ -778,10 +785,9 @@ module Kitchen
778
785
  resp = ec2.client.create_key_pair(key_name: "kitchen-#{name_parts.join('-')}")
779
786
  state[:auto_key_id] = resp.key_name
780
787
  info("Created automatic key pair #{state[:auto_key_id]}")
781
- # Write the key out, but safely hence the weird sysopen.
788
+ # Write the key out with safe permissions
782
789
  key_path = "#{config[:kitchen_root]}/.kitchen/#{instance.name}.pem"
783
- key_fd = File.sysopen(key_path, File::WRONLY | File::CREAT | File::EXCL, 00600)
784
- File.open(key_fd) do |f|
790
+ File.open(key_path, File::WRONLY | File::CREAT | File::EXCL, 00600) do |f|
785
791
  f.write(resp.key_material)
786
792
  end
787
793
  # Inject the key into the state to be used by the SSH transport, or for
@@ -22,6 +22,6 @@ module Kitchen
22
22
  module Driver
23
23
 
24
24
  # Version string for EC2 Test Kitchen driver
25
- EC2_VERSION = "2.2.1"
25
+ EC2_VERSION = "2.2.2"
26
26
  end
27
27
  end
File without changes
@@ -20,44 +20,6 @@ require "kitchen/transport/dummy"
20
20
  require "kitchen/verifier/dummy"
21
21
 
22
22
  describe "Default images for various platforms" do
23
-
24
- class FakeImage
25
- def self.next_ami
26
- @n ||= 0
27
- @n += 1
28
- [sprintf("ami-%08x", @n), Time.now + @n]
29
- end
30
-
31
- def initialize(name: "foo")
32
- @id, @creation_date = FakeImage.next_ami
33
- @name = name
34
- @creation_date = @creation_date.strftime("%F %T")
35
- @architecture = :x86_64
36
- @volume_type = "gp2"
37
- @root_device_type = "ebs"
38
- @virtualization_type = "hvm"
39
- @root_device_name = "root"
40
- @device_name = "root"
41
- end
42
- attr_reader :id
43
- attr_reader :name
44
- attr_reader :creation_date
45
- attr_reader :architecture
46
- attr_reader :volume_type
47
- attr_reader :root_device_type
48
- attr_reader :virtualization_type
49
- attr_reader :root_device_name
50
- attr_reader :device_name
51
-
52
- def block_device_mappings
53
- [self]
54
- end
55
-
56
- def ebs
57
- self
58
- end
59
- end
60
-
61
23
  let(:driver) do
62
24
  Kitchen::Driver::Ec2.new(:region => "us-west-2", :aws_ssh_key_id => "foo", **config)
63
25
  end
@@ -499,6 +499,28 @@ describe Kitchen::Driver::Ec2 do
499
499
  end
500
500
  end
501
501
 
502
+ describe "#create_key" do
503
+ context "creates a key pair via the ec2 API, saves the generated key locally" do
504
+ before do
505
+ config[:kitchen_root] = "/kitchen"
506
+ config.delete(:aws_ssh_key_id)
507
+ allow(instance).to receive(:name).and_return("instance_name")
508
+
509
+ expect(actual_client).to receive(:create_key_pair).with(key_name: /kitchen-/).and_return(double(key_name: "expected-key-name", key_material: "RSA PRIVATE KEY"))
510
+ fake_file = double()
511
+ allow(File).to receive(:open).and_call_original
512
+ expect(File).to receive(:open).with("/kitchen/.kitchen/instance_name.pem", kind_of(Numeric), kind_of(Numeric)).and_yield(fake_file)
513
+ expect(fake_file).to receive(:write).with("RSA PRIVATE KEY")
514
+ end
515
+
516
+ it "generates a temporary SSH key pair for the instance" do
517
+ driver.send(:create_key, state)
518
+ expect(state[:auto_key_id]).to eq("expected-key-name")
519
+ expect(state[:ssh_key]).to eq("/kitchen/.kitchen/instance_name.pem")
520
+ end
521
+ end
522
+ end
523
+
502
524
  describe "#create" do
503
525
  let(:server) { double("aws server object", :id => id, :image_id => "ami-3f807145") }
504
526
  let(:id) { "i-12345" }
@@ -658,26 +680,52 @@ describe Kitchen::Driver::Ec2 do
658
680
  include_examples "common create"
659
681
  end
660
682
 
661
- context "with no key pair configured" do
683
+ context "and AWS SSH keys" do
662
684
  before do
663
- config[:kitchen_root] = "/kitchen"
664
- config.delete(:aws_ssh_key_id)
665
- expect(driver).to receive(:submit_server).and_return(server)
685
+ allow(driver).to receive(:submit_server).and_return(server)
666
686
  allow(instance).to receive(:name).and_return("instance_name")
687
+ end
667
688
 
668
- expect(actual_client).to receive(:create_key_pair).with(key_name: /kitchen-/).and_return(double(key_name: "kitchen-asdf", key_material: "RSA PRIVATE KEY"))
669
- fake_fd = double()
670
- fake_file = double()
671
- allow(File).to receive(:sysopen).and_call_original
672
- expect(File).to receive(:sysopen).with("/kitchen/.kitchen/instance_name.pem", kind_of(Numeric), kind_of(Numeric)).and_return(fake_fd)
673
- allow(File).to receive(:open).and_call_original
674
- expect(File).to receive(:open).with(fake_fd).and_yield(fake_file)
675
- expect(fake_file).to receive(:write).with("RSA PRIVATE KEY")
689
+ context "with no AWS-managed ssh key pair configured, creates a key pair to use" do
690
+ before do
691
+ config[:aws_ssh_key_id] = nil
692
+ expect(driver).to receive(:create_key)
693
+ state[:auto_key_id] = "autogenerated_by_create_key"
694
+ end
695
+
696
+ after do
697
+ expect(config[:aws_ssh_key_id]).to eq("autogenerated_by_create_key")
698
+ end
699
+
700
+ include_examples "common create"
676
701
  end
677
702
 
678
- include_examples "common create"
679
- end
703
+ context "with AWS-managed ssh key pair disabled, does not create a key pair or pass a key id" do
704
+ before do
705
+ config[:aws_ssh_key_id] = "_disable"
706
+ expect(driver).to_not receive(:create_key)
707
+ end
708
+
709
+ after do
710
+ expect(config[:aws_ssh_key_id]).to be_nil
711
+ end
680
712
 
713
+ include_examples "common create"
714
+ end
715
+
716
+ context "with AWS ssh key pair set, uses set key and does not create a key pair" do
717
+ before do
718
+ config[:aws_ssh_key_id] = "use_this_key_please"
719
+ expect(driver).to_not receive(:create_key)
720
+ end
721
+
722
+ after do
723
+ expect(config[:aws_ssh_key_id]).to eq("use_this_key_please")
724
+ end
725
+
726
+ include_examples "common create"
727
+ end
728
+ end
681
729
  end
682
730
 
683
731
  describe "#destroy" do
@@ -17,6 +17,8 @@
17
17
  # See the License for the specific language governing permissions and
18
18
  # limitations under the License.
19
19
 
20
+ require "support/fake_image"
21
+
20
22
  if ENV["CODECLIMATE_REPO_TOKEN"]
21
23
  require "codeclimate-test-reporter"
22
24
  CodeClimate::TestReporter.start
@@ -0,0 +1,36 @@
1
+ class FakeImage
2
+ def self.next_ami
3
+ @n ||= 0
4
+ @n += 1
5
+ [sprintf("ami-%08x", @n), Time.now + @n]
6
+ end
7
+
8
+ def initialize(name: "foo")
9
+ @id, @creation_date = FakeImage.next_ami
10
+ @name = name
11
+ @creation_date = @creation_date.strftime("%F %T")
12
+ @architecture = :x86_64
13
+ @volume_type = "gp2"
14
+ @root_device_type = "ebs"
15
+ @virtualization_type = "hvm"
16
+ @root_device_name = "root"
17
+ @device_name = "root"
18
+ end
19
+ attr_reader :id
20
+ attr_reader :name
21
+ attr_reader :creation_date
22
+ attr_reader :architecture
23
+ attr_reader :volume_type
24
+ attr_reader :root_device_type
25
+ attr_reader :virtualization_type
26
+ attr_reader :root_device_name
27
+ attr_reader :device_name
28
+
29
+ def block_device_mappings
30
+ [self]
31
+ end
32
+
33
+ def ebs
34
+ self
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -225,6 +225,7 @@ files:
225
225
  - spec/kitchen/driver/ec2/instance_generator_spec.rb
226
226
  - spec/kitchen/driver/ec2_spec.rb
227
227
  - spec/spec_helper.rb
228
+ - spec/support/fake_image.rb
228
229
  homepage: https://kitchen.ci/
229
230
  licenses:
230
231
  - Apache 2.0
@@ -245,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
246
  version: '0'
246
247
  requirements: []
247
248
  rubyforge_project:
248
- rubygems_version: 2.6.13
249
+ rubygems_version: 2.7.6
249
250
  signing_key:
250
251
  specification_version: 4
251
252
  summary: A Test Kitchen Driver for Amazon EC2
@@ -255,3 +256,4 @@ test_files:
255
256
  - spec/kitchen/driver/ec2/instance_generator_spec.rb
256
257
  - spec/kitchen/driver/ec2_spec.rb
257
258
  - spec/spec_helper.rb
259
+ - spec/support/fake_image.rb