Do not break if client section/or OTP creds missing from conf file

This commit is contained in:
ahmadbilalkhalid 2020-01-10 16:39:40 +05:00
parent e91fd9e24a
commit 00d876aea1
4 changed files with 20 additions and 15 deletions

View file

@ -73,8 +73,6 @@ if __name__ == '__main__':
except UncloudException as err:
logger.error(err)
sys.exit(1)
except etcd3.exceptions.ConnectionFailedError as err:
logger.error("Cannot connect to etcd")
except Exception as err:
logger.exception(err)
sys.exit(1)

View file

@ -10,10 +10,19 @@ from uncloud.common.settings import settings
def get_otp_parser():
otp_parser = argparse.ArgumentParser('otp')
otp_parser.add_argument('--name', default=settings['client']['name'])
otp_parser.add_argument('--realm', default=settings['client']['realm'])
otp_parser.add_argument('--seed', type=get_token, default=settings['client']['seed'],
dest='token', metavar='SEED')
try:
name = settings['client']['name']
realm = settings['client']['realm']
seed = settings['client']['seed']
except Exception:
otp_parser.add_argument('--name', required=True)
otp_parser.add_argument('--realm', required=True)
otp_parser.add_argument('--seed', required=True, type=get_token, dest='token', metavar='SEED')
else:
otp_parser.add_argument('--name', default=name)
otp_parser.add_argument('--realm', default=realm)
otp_parser.add_argument('--seed', default=seed, type=get_token, dest='token', metavar='SEED')
return otp_parser

View file

@ -12,12 +12,12 @@ for component in ['user', 'host', 'image', 'network', 'vm']:
subparser.add_parser(name=parser.prog, parents=[parser])
def main(**kwargs):
if not kwargs['subcommand']:
def main(arguments):
if not arguments['subcommand']:
arg_parser.print_help()
else:
name = kwargs.pop('subcommand')
kwargs.pop('debug')
name = arguments.pop('subcommand')
arguments.pop('debug')
mod = importlib.import_module('uncloud.cli.{}'.format(name))
_main = getattr(mod, 'main')
_main(**kwargs)
_main(**arguments)

View file

@ -99,12 +99,10 @@ class Settings(object):
def read_config_file_values(self, config_file):
try:
# Trying to read configuration file
with open(config_file, 'r') as config_file_handle:
with open(config_file) as config_file_handle:
self.config_parser.read_file(config_file_handle)
except FileNotFoundError:
sys.exit(
'Configuration file {} not found!'.format(config_file)
)
sys.exit('Configuration file {} not found!'.format(config_file))
except Exception as err:
logger.exception(err)
sys.exit('Error occurred while reading configuration file')