def guess_version(self): """ :returns: (float) version of the config file or 0.9 if unrecognized """ from kamaki.cli import logger # Ignore logs from "checker" logger logger.deactivate(__name__) checker = Config(self.path, with_defaults=False) logger.activate(__name__) sections = checker.sections() # log.debug('Config file heuristic 1: old global section ?') if 'global' in sections: if checker.get('global', 'url') or checker.get('global', 'token'): log.debug('config file has an old global section') return 0.8 # log.debug('Config file heuristic 2: Any cloud sections ?') if CLOUD_PREFIX in sections: for r in self.keys(CLOUD_PREFIX): log.debug('found cloud "%s"' % r) ipv = self.get('global', 'ip_cli') if ipv in ('cyclades', ): return 0.11 netv = self.get('global', 'network_cli') if netv in ('cyclades', ): return 0.10 return 0.12 log.debug('All heuristics failed, cannot decide') return 0.12
def test_activate(self, GL): from kamaki.cli.logger import activate activate('another logger') GL.assert_called_once_with('another logger') self.assertEqual( self.PseudoLogger._setLevel_calls[-1], (self.PseudoLogger.level, ))
def test_activate(self, GL): from kamaki.cli.logger import activate activate('another logger') GL.assert_called_once_with('another logger') self.assertEqual(self.PseudoLogger._setLevel_calls[-1], (self.PseudoLogger.level, ))