]> git.llucax.com Git - software/pymin.git/commitdiff
Give a nice error if a VPN key can't be readed (refs #22).
authorLeandro Lucarella <llucax@gmail.com>
Mon, 12 May 2008 15:32:24 +0000 (12:32 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Mon, 12 May 2008 15:32:24 +0000 (12:32 -0300)
pymin/services/vpn/__init__.py

index dead949d02a8506d4e335e68bc19c5e5bb25aad8..ec6fd50eb4f6bcc129580e0cbe539d1072c338ce 100644 (file)
@@ -160,10 +160,16 @@ class VpnHandler(Restorable, ConfigWriter,
                         log.debug(u'VpnHandler._write_config: creating key...')
                         call(('tincd', '-n', v.vpn_src, '-K', '<', '/dev/null'))
                         #open the created files and load the keys
                         log.debug(u'VpnHandler._write_config: creating key...')
                         call(('tincd', '-n', v.vpn_src, '-K', '<', '/dev/null'))
                         #open the created files and load the keys
-                        f = file(path.join(self._config_writer_cfg_dir,
-                                            v.vpn_src, 'rsa_key.pub'), 'r')
-                        pub = f.read()
-                        f.close()
+                        try:
+                            f = file(path.join(self._config_writer_cfg_dir,
+                                               v.vpn_src, 'rsa_key.pub'),
+                                     'r')
+                            pub = f.read()
+                            f.close()
+                        except (IOError, OSError), e:
+                            raise HandlerError(u"Can't read VPN key '%s' (%s)'"
+                                                % (e.filename, e.strerror))
+
                         v.pub_key = pub
                         v.priv_key = priv
                     except ExecutionError, e:
                         v.pub_key = pub
                         v.priv_key = priv
                     except ExecutionError, e: