From 6c5636baab934c9c404810a6ba2e7aed35ad2657 Mon Sep 17 00:00:00 2001 From: Jan Hartkopf Date: Tue, 19 Oct 2021 18:44:16 +0200 Subject: [PATCH] ensure samples folder exists for microversion When adding a microversion, a new corresponding folder for auto-generated samples is required. However, the folder has to be created manually for the generation to succeed. With this change, it is ensured that the folder is present, removing manual interaction. Closes-Bug: #1946771 Change-Id: I18f2e509f8c1ae3ad5866b568afc6e0c341e5c3e Signed-off-by: Jan Hartkopf --- nova/tests/functional/api_samples_test_base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nova/tests/functional/api_samples_test_base.py b/nova/tests/functional/api_samples_test_base.py index 50cb1c4093c6..a6e5dbbe07c9 100644 --- a/nova/tests/functional/api_samples_test_base.py +++ b/nova/tests/functional/api_samples_test_base.py @@ -135,8 +135,11 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): outf.write(data) def _write_sample(self, name, data): - with open(self._get_sample( - name, self.microversion), 'w') as outf: + sample_file = self._get_sample(name, self.microversion) + + os.makedirs(os.path.dirname(sample_file), exist_ok = True) + + with open(sample_file, 'w') as outf: outf.write(data) def _compare_result(self, expected, result, result_str):