From ae27056f09f324146ff7f92dc8cfdecb6faafdb5 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 3 Jan 2020 23:46:51 -0800 Subject: [PATCH] probe-tests: Avoid a DuplicateSectionError on py3 ... when you already have a [swift-constraints] section in your swift.conf Change-Id: I0b2c906892130639ab2e3e84a6fc4aa0b3033e80 --- test/probe/test_signals.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/probe/test_signals.py b/test/probe/test_signals.py index 2023bfcf19..e1eb9d1dd6 100644 --- a/test/probe/test_signals.py +++ b/test/probe/test_signals.py @@ -283,11 +283,19 @@ class TestProxyServerReloadBase(TestWSGIServerProcessHandling): self.new_swift_conf_path = self.swift_conf_path + '.new' self.saved_swift_conf_path = self.swift_conf_path + '.orig' shutil.copy(self.swift_conf_path, self.saved_swift_conf_path) - shutil.copy(self.swift_conf_path, self.new_swift_conf_path) - with open(self.new_swift_conf_path, 'a+') as fh: - fh.seek(0, os.SEEK_END) - fh.write('\n[swift-constraints]\nmax_header_size = 8191\n') - fh.flush() + with open(self.swift_conf_path, 'r') as rfh: + config = rfh.read() + section_header = '\n[swift-constraints]\n' + if section_header in config: + config = config.replace( + section_header, + section_header + 'max_header_size = 8191\n', + 1) + else: + config += section_header + 'max_header_size = 8191\n' + with open(self.new_swift_conf_path, 'w') as wfh: + wfh.write(config) + wfh.flush() def tearDown(self): shutil.move(self.saved_swift_conf_path, self.swift_conf_path)