mirror of
https://git.yoctoproject.org/poky
synced 2026-09-29 07:36:20 +02:00
oeqa: fix temp file handling in dnf package feed test
Prevent stale temp files and a possible (if unlikely) race in tempfile usage. (From OE-Core rev: 1b8ac555ee1443be5cd14614cc6b722960d228b8) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
05361f9a4f
commit
14fc08e3b0
@@ -6,6 +6,8 @@ class DnfSelftest(DnfTest):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
import tempfile
|
||||||
|
cls.temp_dir = tempfile.TemporaryDirectory(prefix="oeqa-remotefeeds-")
|
||||||
cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-rootfs-repo'),
|
cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-rootfs-repo'),
|
||||||
cls.tc.target.server_ip)
|
cls.tc.target.server_ip)
|
||||||
cls.repo_server.start()
|
cls.repo_server.start()
|
||||||
@@ -13,6 +15,7 @@ class DnfSelftest(DnfTest):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
cls.repo_server.stop()
|
cls.repo_server.stop()
|
||||||
|
cls.temp_dir.cleanup()
|
||||||
|
|
||||||
@OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
|
@OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
|
||||||
def test_verify_package_feeds(self):
|
def test_verify_package_feeds(self):
|
||||||
@@ -25,11 +28,11 @@ class DnfSelftest(DnfTest):
|
|||||||
"""
|
"""
|
||||||
# When we created an image, we had to supply fake ip and port
|
# When we created an image, we had to supply fake ip and port
|
||||||
# for the feeds. Now we can patch the real ones into the config file.
|
# for the feeds. Now we can patch the real ones into the config file.
|
||||||
import tempfile
|
temp_file = os.path.join(self.temp_dir.name, 'tmp.repo')
|
||||||
temp_file = tempfile.TemporaryDirectory(prefix="oeqa-remotefeeds-").name
|
|
||||||
self.tc.target.copyFrom("/etc/yum.repos.d/oe-remote-repo.repo", temp_file)
|
self.tc.target.copyFrom("/etc/yum.repos.d/oe-remote-repo.repo", temp_file)
|
||||||
fixed_config = open(temp_file, "r").read().replace("bogus_ip", self.tc.target.server_ip).replace("bogus_port", str(self.repo_server.port))
|
fixed_config = open(temp_file, "r").read().replace("bogus_ip", self.tc.target.server_ip).replace("bogus_port", str(self.repo_server.port))
|
||||||
open(temp_file, "w").write(fixed_config)
|
with open(temp_file, "w") as f:
|
||||||
|
f.write(fixed_config)
|
||||||
self.tc.target.copyTo(temp_file, "/etc/yum.repos.d/oe-remote-repo.repo")
|
self.tc.target.copyTo(temp_file, "/etc/yum.repos.d/oe-remote-repo.repo")
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|||||||
Reference in New Issue
Block a user