def test_delete_orphaned_volumes(self): """ Test that we clean up instance volumes that are orphaned by AWS. """ aws_svc, encryptor_image, guest_image = _build_aws_service() brkt_cli.SLEEP_ENABLED = False # Simulate a tagged orphaned volume. volume = Volume() volume.id = _new_id() aws_svc.volumes[volume.id] = volume aws_svc.tagged_volumes.append(volume) # Verify that lookup succeeds before run(). self.assertEqual(volume, aws_svc.get_volume(volume.id)) self.assertEqual( [volume], aws_svc.get_volumes( tag_key=brkt_cli.TAG_ENCRYPTOR_SESSION_ID, tag_value='123') ) brkt_cli.run( aws_svc=aws_svc, enc_svc_cls=DummyEncryptorService, image_id=guest_image.id, encryptor_ami=encryptor_image.id ) # Verify that the volume was deleted. self.assertIsNone(aws_svc.get_volume(volume.id))
def test_encryption_error_console_output_not_available(self): """ Test that we handle the case when encryption fails and console output is not available. """ aws_svc, encryptor_image, guest_image = _build_aws_service() brkt_cli.SLEEP_ENABLED = False aws_svc.console_output_text = None try: brkt_cli.run( aws_svc=aws_svc, enc_svc_cls=FailedEncryptionService, image_id=guest_image.id, encryptor_ami=encryptor_image.id ) self.fail('Encryption should have failed') except EncryptionError as e: self.assertIsNone(e.console_output_file)
def test_encryption_error_console_output_available(self): """ Test that when an encryption failure occurs, we write the console log to a temp file. """ aws_svc, encryptor_image, guest_image = _build_aws_service() brkt_cli.SLEEP_ENABLED = False try: brkt_cli.run( aws_svc=aws_svc, enc_svc_cls=FailedEncryptionService, image_id=guest_image.id, encryptor_ami=encryptor_image.id ) self.fail('Encryption should have failed') except EncryptionError as e: with open(e.console_output_file.name) as f: content = f.read() self.assertEquals(CONSOLE_OUTPUT_TEXT, content) os.remove(e.console_output_file.name)
def test_smoke(self): """ Run the entire process and test that nothing obvious is broken. """ aws_svc, encryptor_image, guest_image = _build_aws_service() brkt_cli.SLEEP_ENABLED = False encrypted_ami_id = brkt_cli.run( aws_svc=aws_svc, enc_svc_cls=DummyEncryptorService, image_id=guest_image.id, encryptor_ami=encryptor_image.id ) self.assertIsNotNone(encrypted_ami_id)