def testGetSettings(self, run_mock): configService = Config("/fake/path") settings = configService.getSettings() targetSettings = {'rancher.host': "test", 'rancher.port': 1234} self.assertEqual(settings, targetSettings) configService = Config() settings = configService.getSettings() self.assertEqual(settings, targetSettings)
def getAndcheckAllParameters(): configService = Config() settings = configService.getSettings() try: checkParameters(settings) except KeyError as e: raise Exception("Somthing wrong on your config file: %s" % e.message) logger.info("Rancher URL: %s", settings['rancher']['api']['url'][:-2] + "v2-beta") logger.info("Rancher key: %s", settings['rancher']['api']['key']) logger.info("Rancher secret: XXXX") logger.info("Backup path: %s", settings['duplicity']['source-path']) logger.info("Backup target path: %s", settings['duplicity']['target-path']) logger.info("Backend to receive remote backup: %s", settings['duplicity']['url']) logger.info("Backup full frequency: %s", settings['duplicity']['full-if-older-than']) logger.info("Backup full to keep: %s", settings['duplicity']['remove-all-but-n-full']) logger.info("Backup incremental chain to keep: %s", settings['duplicity']['remove-all-inc-of-but-n-full']) logger.info("Volume size: %s", settings['duplicity']['volsize']) logger.info("Backup options: %s", settings['duplicity']['options']) # Init services try: rancherService = Rancher( settings['rancher']['api']['url'][:-2] + "v2-beta", settings['rancher']['api']['key'], settings['rancher']['api']['secret']) except Exception as e: raise Exception("Can't connect to rancher API : %s \n%s" % (e.message, traceback.format_exc())) try: rancherDatabaseSettings = rancherService.getDatabaseSettings() except Exception as e: rancherDatabaseSettings = {} pass # Check database settings try: rancherDatabaseSettings = checkAndGetDatabaseSettings( settings, rancherDatabaseSettings) except KeyError as e: raise Exception( "You must set the Rancher database settings on config file to dump it: %s" % e.message) return (settings, rancherDatabaseSettings)