def test_get_client_id(self, mock_get_auth_plugin, mock_ksc_session, mock_socket): mock_socket.gethostname.return_value = 'parmenide' mock_session = Mock() mock_session.get_project_id.return_value = 'H2O' c = client.Client(session=mock_session, endpoint='justtest', opts=Mock()) self.assertIsInstance(c, client.Client) self.assertEquals(c.client_id, 'H2O_parmenide')
def test_client_new_with_kwargs(self, mock_get_auth_plugin, mock_ksa_session): kwargs = { 'token': 'alpha', 'username': '******', 'password': '******', 'tenant_name': 'delta', 'auth_url': 'echo', 'session': 'foxtrot', 'endpoint': 'golf', 'version': 'hotel', 'cert': 'india', 'insecure': 'juliet', 'opts': Mock() } c = client.Client(**kwargs) self.assertIsInstance(c, client.Client) self.assertEqual('alpha', c.opts.os_token) self.assertEqual('bravo', c.opts.os_username) self.assertEqual('charlie', c.opts.os_password) self.assertEqual('delta', c.opts.os_tenant_name) self.assertEqual('echo', c.opts.os_auth_url) self.assertEqual('foxtrot', c._session) self.assertEqual('foxtrot', c.session) self.assertEqual('golf', c.endpoint) self.assertEqual('hotel', c.version)
def test_get_token(self, mock_get_auth_plugin, mock_ksa_session): mock_session = Mock() mock_session.get_token.return_value = 'antaniX2' c = client.Client(session=mock_session, endpoint='justtest', opts=Mock()) self.assertIsInstance(c, client.Client) self.assertEqual('antaniX2', c.auth_token)
def main(): doers = _get_doers(shell) doers.update(_get_doers(utils)) possible_actions = doers.keys() + ['start', 'stop', 'status', 'reload'] arguments.parse_args(possible_actions) arguments.setup_logging() if CONF.action is None: CONF.print_help() return 65 # os.EX_DATAERR if CONF.action not in ['start', 'stop', 'status', 'reload']: sys.stderr.write("Using freezer-scheduler as a command line client is " "deprecated. Please use the freezer command line tool" " from python-freezerclient.") apiclient = None insecure = False if CONF.insecure: insecure = True if CONF.no_api is False: try: apiclient = client.Client(opts=CONF, insecure=insecure) if CONF.client_id: apiclient.client_id = CONF.client_id except Exception as e: LOG.error(e) print(e) sys.exit(1) else: if winutils.is_windows(): print("--no-api mode is not available on windows") return 69 # os.EX_UNAVAILABLE if CONF.action in doers: try: return doers[CONF.action](apiclient, CONF) except Exception as e: LOG.error(e) print('ERROR {0}'.format(e)) return 70 # os.EX_SOFTWARE freezer_scheduler = FreezerScheduler(apiclient=apiclient, interval=int(CONF.interval), job_path=CONF.jobs_dir) if CONF.no_daemon: print('Freezer Scheduler running in no-daemon mode') LOG.debug('Freezer Scheduler running in no-daemon mode') daemon = NoDaemon(daemonizable=freezer_scheduler) else: if winutils.is_windows(): daemon = Daemon(daemonizable=freezer_scheduler, interval=int(CONF.interval), job_path=CONF.jobs_dir, insecure=CONF.insecure) else: daemon = Daemon(daemonizable=freezer_scheduler) if CONF.action == 'start': daemon.start() elif CONF.action == 'stop': daemon.stop() elif CONF.action == 'reload': daemon.reload() elif CONF.action == 'status': daemon.status() # os.RETURN_CODES are only available to posix like systems, on windows # we need to translate the code to an actual number which is the equivalent return 0 # os.EX_OK
def test_client_new(self, mock_get_auth_plugin, mock_ksc_session): c = client.Client(opts=Mock(), endpoint='blabla') self.assertIsInstance(c, client.Client)