Commit a108236a by Czémán Arnold

freebsd: resolve flake8 warnings in FreeBSD specific files

parent a0f8465b
...@@ -7,19 +7,19 @@ from shutil import copy, rmtree, move ...@@ -7,19 +7,19 @@ from shutil import copy, rmtree, move
import subprocess import subprocess
import sys import sys
system = platform.system() system = platform.system() # noqa
working_directory = sys.path[0] working_directory = sys.path[0] # noqa
try: try: # noqa
# load virtio console driver, the device is /dev/ttyV0.1 # load virtio console driver, the device is /dev/ttyV0.1 # noqa
subprocess.call(('/sbin/kldload', '-n', 'virtio_console')) subprocess.call(('/sbin/kldload', '-n', 'virtio_console')) # noqa
subprocess.call(('/sbin/kldload', '-n', 'smbfs')) subprocess.call(('/sbin/kldload', '-n', 'smbfs')) # noqa
chdir(working_directory) chdir(working_directory) # noqa
subprocess.call( subprocess.call( # noqa
('/usr/local/bin/pip', 'install', '-r', 'requirements.txt')) ('/usr/local/bin/pip', 'install', '-r', 'requirements.txt')) # noqa
copy("/root/agent/misc/vm_renewal", "/usr/local/bin/") copy("/root/agent/misc/vm_renewal", "/usr/local/bin/") # noqa
except: except Exception: # noqa
pass # hope it works pass # hope it works # noqa
import logging import logging
...@@ -109,7 +109,7 @@ class Context(BaseContext): ...@@ -109,7 +109,7 @@ class Context(BaseContext):
Context._freebsd_set_time(float(time)) Context._freebsd_set_time(float(time))
try: try:
subprocess.call(['/usr/sbin/service' 'ntpd', 'onerestart']) subprocess.call(['/usr/sbin/service' 'ntpd', 'onerestart'])
except: except Exception:
pass pass
@staticmethod @staticmethod
...@@ -152,7 +152,7 @@ class Context(BaseContext): ...@@ -152,7 +152,7 @@ class Context(BaseContext):
for line in f.readlines(): for line in f.readlines():
try: try:
retval.append(PubKey.from_str(line)) retval.append(PubKey.from_str(line))
except: except Exception:
logger.exception(u'Invalid ssh key: ') logger.exception(u'Invalid ssh key: ')
except IOError: except IOError:
pass pass
...@@ -177,7 +177,7 @@ class Context(BaseContext): ...@@ -177,7 +177,7 @@ class Context(BaseContext):
p = PubKey.from_str(key) p = PubKey.from_str(key)
if p not in new_keys: if p not in new_keys:
new_keys.append(p) new_keys.append(p)
except: except Exception:
logger.exception(u'Invalid ssh key: ') logger.exception(u'Invalid ssh key: ')
Context._save_keys(new_keys) Context._save_keys(new_keys)
...@@ -191,7 +191,7 @@ class Context(BaseContext): ...@@ -191,7 +191,7 @@ class Context(BaseContext):
new_keys.remove(p) new_keys.remove(p)
except ValueError: except ValueError:
pass pass
except: except Exception:
logger.exception(u'Invalid ssh key: ') logger.exception(u'Invalid ssh key: ')
Context._save_keys(new_keys) Context._save_keys(new_keys)
......
from base64 import decodestring from base64 import decodestring
from struct import unpack from struct import unpack
import binascii import binascii
import unittest
class InvalidKeyType(Exception): class InvalidKeyType(Exception):
...@@ -56,8 +57,7 @@ class PubKey(object): ...@@ -56,8 +57,7 @@ class PubKey(object):
return u'<PubKey: %s>' % unicode(self) return u'<PubKey: %s>' % unicode(self)
import unittest # Unit tests
class SshTestCase(unittest.TestCase): class SshTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -102,5 +102,6 @@ class SshTestCase(unittest.TestCase): ...@@ -102,5 +102,6 @@ class SshTestCase(unittest.TestCase):
s.add(self.p3) s.add(self.p3)
self.assertEqual(len(s), 2) self.assertEqual(len(s), 2)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment