From 64d8d991f16dd818a981daa34ce418265a907b28 Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Fri, 8 Oct 2021 07:33:58 +0200 Subject: [PATCH] Fix template issue with user_data_config_drive Fix a python3 error that prevented to use the user_data_config_drive option when building amphorae. user_data_config_drive has been broken since we switched to python3, a mix of str and bytes variables were provided to the jinja2 templates. This commit ensures that the type of all the certificates provided to jinja2 are strings. Story: 2005553 Task: 30705 Change-Id: I53ed0425f00cfbbc964f5083b4f2942cf5bf565e --- octavia/controller/worker/v1/tasks/compute_tasks.py | 3 ++- octavia/controller/worker/v2/tasks/compute_tasks.py | 2 +- .../unit/controller/worker/v1/tasks/test_compute_tasks.py | 3 ++- .../unit/controller/worker/v2/tasks/test_compute_tasks.py | 2 +- .../notes/fix-user_data_config_drive-b4ce8cc66fb21365.yaml | 6 ++++++ 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/fix-user_data_config_drive-b4ce8cc66fb21365.yaml diff --git a/octavia/controller/worker/v1/tasks/compute_tasks.py b/octavia/controller/worker/v1/tasks/compute_tasks.py index 6e63916e88..2f5c825c43 100644 --- a/octavia/controller/worker/v1/tasks/compute_tasks.py +++ b/octavia/controller/worker/v1/tasks/compute_tasks.py @@ -165,7 +165,8 @@ class CertComputeCreate(ComputeCreate): key = utils.get_compatible_server_certs_key_passphrase() fer = fernet.Fernet(key) config_drive_files = { - '/etc/octavia/certs/server.pem': fer.decrypt(server_pem), + '/etc/octavia/certs/server.pem': fer.decrypt( + server_pem).decode('utf-8'), '/etc/octavia/certs/client_ca.pem': ca} return super().execute( amphora_id, config_drive_files=config_drive_files, diff --git a/octavia/controller/worker/v2/tasks/compute_tasks.py b/octavia/controller/worker/v2/tasks/compute_tasks.py index f881c143f8..5f27a960a1 100644 --- a/octavia/controller/worker/v2/tasks/compute_tasks.py +++ b/octavia/controller/worker/v2/tasks/compute_tasks.py @@ -173,7 +173,7 @@ class CertComputeCreate(ComputeCreate): fer = fernet.Fernet(key) config_drive_files = { '/etc/octavia/certs/server.pem': fer.decrypt( - server_pem.encode("utf-8")), + server_pem.encode("utf-8")).decode("utf-8"), '/etc/octavia/certs/client_ca.pem': ca} return super().execute( amphora_id, config_drive_files=config_drive_files, diff --git a/octavia/tests/unit/controller/worker/v1/tasks/test_compute_tasks.py b/octavia/tests/unit/controller/worker/v1/tasks/test_compute_tasks.py index f41f917f7a..169814ca3f 100644 --- a/octavia/tests/unit/controller/worker/v1/tasks/test_compute_tasks.py +++ b/octavia/tests/unit/controller/worker/v1/tasks/test_compute_tasks.py @@ -378,7 +378,8 @@ class TestComputeTasks(base.TestCase): user_data=None, config_drive_files={ '/etc/rsyslog.d/10-rsyslog.conf': 'FAKE CFG', - '/etc/octavia/certs/server.pem': fer.decrypt(test_cert), + '/etc/octavia/certs/server.pem': fer.decrypt( + test_cert).decode('utf-8'), '/etc/octavia/certs/client_ca.pem': 'test', '/etc/octavia/amphora-agent.conf': 'test_conf'}, server_group_id=SERVER_GRPOUP_ID, diff --git a/octavia/tests/unit/controller/worker/v2/tasks/test_compute_tasks.py b/octavia/tests/unit/controller/worker/v2/tasks/test_compute_tasks.py index 2febd35782..abf5bad139 100644 --- a/octavia/tests/unit/controller/worker/v2/tasks/test_compute_tasks.py +++ b/octavia/tests/unit/controller/worker/v2/tasks/test_compute_tasks.py @@ -391,7 +391,7 @@ class TestComputeTasks(base.TestCase): config_drive_files={ '/etc/rsyslog.d/10-rsyslog.conf': 'FAKE CFG', '/etc/octavia/certs/server.pem': fer.decrypt( - test_cert.encode('utf-8')), + test_cert.encode('utf-8')).decode('utf-8'), '/etc/octavia/certs/client_ca.pem': 'test', '/etc/octavia/amphora-agent.conf': 'test_conf'}, server_group_id=SERVER_GRPOUP_ID, diff --git a/releasenotes/notes/fix-user_data_config_drive-b4ce8cc66fb21365.yaml b/releasenotes/notes/fix-user_data_config_drive-b4ce8cc66fb21365.yaml new file mode 100644 index 0000000000..acf73f00fd --- /dev/null +++ b/releasenotes/notes/fix-user_data_config_drive-b4ce8cc66fb21365.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fix a python3 error that prevented to use the + ``[controller_worker]/user_data_config_drive`` option when building + amphorae.