X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=system%2FTestKey.py;h=ddef527c6680eb046dfa6d7800bd03b579b48d1b;hb=457d31694f7b0f60e2a6fea230e9a3572b9d2b78;hp=8284609fca9965c8d552f8ef054f499f4b80e568;hpb=d00b4f516f15780796bab3f8d0241b0b5af3fe00;p=tests.git diff --git a/system/TestKey.py b/system/TestKey.py index 8284609..ddef527 100644 --- a/system/TestKey.py +++ b/system/TestKey.py @@ -1,33 +1,36 @@ +# Thierry Parmentelat +# Copyright (C) 2010 INRIA +# import utils import os, os.path +from TestSsh import TestSsh class TestKey: - def __init__ (self,test_plc,key_spec): - self.test_plc=test_plc - self.key_spec=key_spec + def __init__ (self, test_plc, key_spec): + self.test_plc = test_plc + self.key_spec = key_spec + self.test_ssh = TestSsh(self.test_plc.test_ssh) def name(self): - return self.key_spec['name'] + return self.key_spec['key_name'] def publicpath(self): - return "%s/keys/%s.pub"%(self.test_plc.path,self.name()) + return "keys/{}.pub".format(self.name()) def privatepath(self): - return "%s/keys/%s.rsa"%(self.test_plc.path,self.name()) + return "keys/{}.rsa".format(self.name()) def store_key(self): - pub=self.publicpath() - priv=self.privatepath() - utils.header("Storing key %s in %s"%(self.name(),pub)) - dir=os.path.dirname(pub) + pub = self.publicpath() + priv = self.privatepath() + utils.header("Storing key {} in {}".format(self.name(), pub)) + dir = os.path.dirname(pub) if not os.path.isdir(dir): os.mkdir(dir) - f=open(pub,"w") - f.write(self.key_spec['key_fields']['key']) - f.close() - f=open(priv,"w") - f.write(self.key_spec['private']) - f.close() - os.chmod(priv,0400) - os.chmod(pub,0444) + with open(pub,"w") as f: + f.write(self.key_spec['key_fields']['key']) + with open(priv,"w") as f: + f.write(self.key_spec['private']) + os.chmod(priv,0o400) + os.chmod(pub,0o444)