All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] oeqa/selftest/signing: use a temporary directory for GPG home
@ 2016-07-21 17:15 Ross Burton
  2016-07-21 17:15 ` [PATCH 2/2] oeqa/selftest/signing: check that we have GPG in setup Ross Burton
  0 siblings, 1 reply; 2+ messages in thread
From: Ross Burton @ 2016-07-21 17:15 UTC (permalink / raw)
  To: openembedded-core

Instead of using a directory in the layer as the GPG home and carefully deleting
the right files from it, use tempfile to create a temporary directory which will
be cleaned up for us.

Also change the public/secret key variables to be absolute paths as they're
always used as absolute paths.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/lib/oeqa/selftest/signing.py | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/meta/lib/oeqa/selftest/signing.py b/meta/lib/oeqa/selftest/signing.py
index 1babca0..beafd63 100644
--- a/meta/lib/oeqa/selftest/signing.py
+++ b/meta/lib/oeqa/selftest/signing.py
@@ -12,30 +12,18 @@ from oeqa.utils.ftools import write_file
 class Signing(oeSelfTest):
 
     gpg_dir = ""
-    pub_key_name = 'key.pub'
-    secret_key_name = 'key.secret'
+    pub_key_path = ""
+    secret_key_path = ""
 
     @classmethod
     def setUpClass(cls):
-        # Import the gpg keys
+        cls.gpg_home_dir = tempfile.TemporaryDirectory(prefix="oeqa-signing-")
+        cls.gpg_dir = cls.gpg_home_dir.name
 
-        cls.gpg_dir = os.path.join(cls.testlayer_path, 'files/signing/')
+        cls.pub_key_path = os.path.join(cls.testlayer_path, 'files', 'signing', "key.pub")
+        cls.secret_key_path = os.path.join(cls.testlayer_path, 'files', 'signing', "key.secret")
 
-        # key.secret key.pub are located in gpg_dir
-        pub_key_location = cls.gpg_dir + cls.pub_key_name
-        secret_key_location = cls.gpg_dir + cls.secret_key_name
-        runCmd('gpg --homedir %s --import %s %s' % (cls.gpg_dir, pub_key_location, secret_key_location))
-
-    @classmethod
-    def tearDownClass(cls):
-        # Delete the files generated by 'gpg --import'
-
-        gpg_files = glob.glob(cls.gpg_dir + '*.gpg*')
-        random_seed_file = cls.gpg_dir + 'random_seed'
-        gpg_files.append(random_seed_file)
-
-        for gpg_file in gpg_files:
-            runCmd('rm -f ' + gpg_file)
+        runCmd('gpg --homedir %s --import %s %s' % (cls.gpg_dir, cls.pub_key_path, cls.secret_key_path))
 
     @testcase(1362)
     def test_signing_packages(self):
@@ -57,7 +45,7 @@ class Signing(oeSelfTest):
         feature = 'INHERIT += "sign_rpm"\n'
         feature += 'RPM_GPG_PASSPHRASE = "test123"\n'
         feature += 'RPM_GPG_NAME = "testuser"\n'
-        feature += 'RPM_GPG_PUBKEY = "%s%s"\n' % (self.gpg_dir, self.pub_key_name)
+        feature += 'RPM_GPG_PUBKEY = "%s"\n' % self.pub_key_path
         feature += 'GPG_PATH = "%s"\n' % self.gpg_dir
 
         self.write_config(feature)
@@ -81,8 +69,8 @@ class Signing(oeSelfTest):
         # Use a temporary rpmdb
         rpmdb = tempfile.mkdtemp(prefix='oeqa-rpmdb')
 
-        runCmd('%s/rpm --define "_dbpath %s" --import %s%s' %
-               (staging_bindir_native, rpmdb, self.gpg_dir, self.pub_key_name))
+        runCmd('%s/rpm --define "_dbpath %s" --import %s' %
+               (staging_bindir_native, rpmdb, self.pub_key_path))
 
         ret = runCmd('%s/rpm --define "_dbpath %s" --checksig %s' %
                      (staging_bindir_native, rpmdb, pkg_deploy))
-- 
2.8.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] oeqa/selftest/signing: check that we have GPG in setup
  2016-07-21 17:15 [PATCH 1/2] oeqa/selftest/signing: use a temporary directory for GPG home Ross Burton
@ 2016-07-21 17:15 ` Ross Burton
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Burton @ 2016-07-21 17:15 UTC (permalink / raw)
  To: openembedded-core

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/lib/oeqa/selftest/signing.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/meta/lib/oeqa/selftest/signing.py b/meta/lib/oeqa/selftest/signing.py
index beafd63..4c12d6d 100644
--- a/meta/lib/oeqa/selftest/signing.py
+++ b/meta/lib/oeqa/selftest/signing.py
@@ -17,6 +17,10 @@ class Signing(oeSelfTest):
 
     @classmethod
     def setUpClass(cls):
+        # Check that we can find the gpg binary and fail early if we can't
+        if not shutil.which("gpg"):
+            raise AssertionError("This test needs GnuPG")
+
         cls.gpg_home_dir = tempfile.TemporaryDirectory(prefix="oeqa-signing-")
         cls.gpg_dir = cls.gpg_home_dir.name
 
-- 
2.8.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-21 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-21 17:15 [PATCH 1/2] oeqa/selftest/signing: use a temporary directory for GPG home Ross Burton
2016-07-21 17:15 ` [PATCH 2/2] oeqa/selftest/signing: check that we have GPG in setup Ross Burton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.