From 01d5e5ca763c9db281a0d274e84b58b3c860a90f Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Thu, 29 Oct 2020 09:39:19 -0400 Subject: [PATCH] test/amazon/ebs: Add acceptance test for Session Manager Interface connectivity Test Results ``` ... 2020/10/29 09:35:39 ui: test: Starting session with SessionId: wilken-00bcfae4d314f54e7 2020/10/29 09:35:40 [DEBUG] TCP connection to SSH ip/port failed: dial tcp [::1]:8047: connect: connection refused 2020/10/29 09:35:40 ui: test: Port 8047 opened for sessionId wilken-00bcfae4d314f54e7. 2020/10/29 09:35:45 [INFO] Attempting SSH connection to localhost:8047... 2020/10/29 09:35:45 [DEBUG] reconnecting to TCP connection for SSH 2020/10/29 09:35:45 ui: test: Connection accepted for session wilken-00bcfae4d314f54e7. 2020/10/29 09:35:45 [DEBUG] handshaking with SSH 2020/10/29 09:35:45 [DEBUG] SSH handshake err: ssh: handshake failed: ssh: invalid packet length, packet too large 2020/10/29 09:35:52 [INFO] Attempting SSH connection to localhost:8047... 2020/10/29 09:35:52 [DEBUG] reconnecting to TCP connection for SSH 2020/10/29 09:35:52 [DEBUG] handshaking with SSH 2020/10/29 09:35:52 [DEBUG] handshake complete! 2020/10/29 09:35:52 [DEBUG] Opening new ssh session 2020/10/29 09:35:53 [INFO] agent forwarding enabled 2020/10/29 09:35:53 ui: ==> test: Connected to SSH! 2020/10/29 09:35:53 Running the provision hook 2020/10/29 09:35:53 ui: ==> test: Stopping the source instance... 2020/10/29 09:35:53 ui: test: Stopping instance 2020/10/29 09:35:54 ui: ==> test: Waiting for the instance to stop... 2020/10/29 09:36:25 ui: ==> test: Creating AMI packer-ssm-test-1603978447 from instance i-0853cb6186a3406d5 2020/10/29 09:36:25 ui: test: AMI: ami-0868a41bbb2df77b3 2020/10/29 09:36:25 ui: ==> test: Waiting for AMI to become ready... 2020/10/29 09:37:59 ui: ==> test: Terminating the source AWS instance... 2020/10/29 09:37:59 ui error: ==> test: Bad exit status: -1 2020/10/29 09:38:15 ui: ==> test: Cleaning up any extra volumes... 2020/10/29 09:38:15 ui: ==> test: No volumes to clean up, skipping 2020/10/29 09:38:15 ui: ==> test: Deleting temporary security group... 2020/10/29 09:38:16 ui: ==> test: Deleting temporary keypair... 2020/10/29 09:38:16 Deregistering image ID (ami-0868a41bbb2df77b3) from region (us-east-1) 2020/10/29 09:38:17 Deregistered AMI id: ami-0868a41bbb2df77b3 2020/10/29 09:38:17 Deleted snapshot: snap-09602f15994bc9f51 --- PASS: TestBuilderAcc_SessionManagerInterface (249.87s) PASS ``` --- builder/amazon/ebs/builder_acc_test.go | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/builder/amazon/ebs/builder_acc_test.go b/builder/amazon/ebs/builder_acc_test.go index d03b83ddb..cf569a353 100644 --- a/builder/amazon/ebs/builder_acc_test.go +++ b/builder/amazon/ebs/builder_acc_test.go @@ -246,6 +246,14 @@ func checkBootEncrypted() builderT.TestCheckFunc { } } +func TestBuilderAcc_SessionManagerInterface(t *testing.T) { + builderT.Test(t, builderT.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Builder: &Builder{}, + Template: testBuilderAccSessionManagerInterface, + }) +} + func testAccPreCheck(t *testing.T) { } @@ -350,6 +358,31 @@ const testBuilderAccEncrypted = ` } ` +const testBuilderAccSessionManagerInterface = ` +{ + "builders": [{ + "type": "test", + "region": "us-east-1", + "instance_type": "m3.medium", + "source_ami_filter": { + "filters": { + "virtualization-type": "hvm", + "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*", + "root-device-type": "ebs" + }, + "owners": [ + "099720109477" + ], + "most_recent": true + }, + "ssh_username": "ubuntu", + "ssh_interface": "session_manager", + "iam_instance_profile": "SSMInstanceProfile", + "ami_name": "packer-ssm-test-{{timestamp}}" + }] +} +` + func buildForceDeregisterConfig(val, name string) string { return fmt.Sprintf(testBuilderAccForceDeregister, val, name) }