From 73827a3d574a6149bfc0984d0c9838ed4f9881d5 Mon Sep 17 00:00:00 2001
From: Jakob Meng <code@jakobmeng.de>
Date: Wed, 7 Sep 2022 09:09:08 +0200
Subject: [PATCH] Do not remove trailing spaces when reading public key in
 keypair module

Previously, openstack.cloud.keypair would remove trailing spaces after
reading a public key from a file. The openstack cli tool, python-\
openstackclient, does not do so, i.e. it does not use rstrip to remove
spaces at the end [1]. This breaks idempotency when using openstack
cli tool and our keypair module at the same time.

The rstrip code was introduced to keypair when our modules were still
part of ansible (non-core) in a completely unrelated change [2].

Now, keypair module does no longer alter the public key and instead
uploads it unchanged to OpenStack API.

[1] https://opendev.org/openstack/python-openstackclient/src/commit/7df94c9f821aa7fabef09cad9e6ab16ed66d46b6/openstackclient/compute/v2/keypair.py#L103
[2] https://github.com/ansible/ansible/commit/341efbf7ae078d9818b17036af5ccfed277db52d

Story: 2008574
Task: 41726
Change-Id: Ia09658467d98516ca1ea612e7301629b2f69d2d1
---
 plugins/modules/keypair.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/modules/keypair.py b/plugins/modules/keypair.py
index 9e93110..0419ec3 100644
--- a/plugins/modules/keypair.py
+++ b/plugins/modules/keypair.py
@@ -139,7 +139,7 @@ class KeyPairModule(OpenStackModule):
 
         if self.params['public_key_file']:
             with open(self.params['public_key_file']) as public_key_fh:
-                public_key = public_key_fh.read().rstrip()
+                public_key = public_key_fh.read()
 
         keypair = self.conn.compute.find_keypair(name)
 
-- 
GitLab