def test_add_data_repo(self): robot = Robot() dir_path = j.sal.fs.getTmpDirPath() robot.set_data_repo(dir_path) self.assertEqual(config.data_repo.path, os.path.join(dir_path, 'zrobot_data')) self.assertEqual(robot.data_repo_url, dir_path)
def start(listen, data_repo, template_repo, config_repo, config_key, debug, telegram_bot_token, telegram_chat_id, auto_push, auto_push_interval, admin_organization, user_organization, mode, god): """ start the 0-robot daemon. this will start the REST API on address and port specified by --listen and block """ level = "INFO" if debug: level = "DEBUG" j.logger.handlers_level_set(level) j.logger.loggers_level_set(level) # Check if configmanager is configured to zdb backend and has a namespace configured if j.core.state.configGetFromDict("myconfig", "backend", "file") == "db": namespace = j.core.state.configGetFromDict("myconfig", "namespace", "default") if namespace: j.tools.configmanager.set_namespace(namespace) else: raise RuntimeError( "Working in zdb backend mode and don't have a namespace") if (telegram_bot_token and not telegram_chat_id) or (telegram_chat_id and not telegram_bot_token): raise ValueError( "To enable telegram error logging, you need to specify both the --telegram-bot-token and the --telegram-chat-id options" ) if telegram_bot_token: telegram_logger.disabled = False telegrambot = j.clients.telegram_bot.get( instance='errorbot', data=dict(bot_token_=telegram_bot_token)) handler = TelegramHandler(telegrambot, telegram_chat_id) handler.setFormatter(TelegramFormatter()) handler.setLevel(logging.ERROR) telegram_logger.addHandler(handler) robot = Robot() config_repo = config_repo or get_db_config_repo() config_key = config_key or get_db_config_key() robot.set_config_repo(config_repo, config_key) robot.set_data_repo(data_repo) for url in template_repo: robot.add_template_repo(url) robot.start(listen=listen, auto_push=auto_push, auto_push_interval=auto_push_interval, admin_organization=admin_organization, user_organization=user_organization, mode=mode, god=god)
def new(id, with_tmpl): robot = Robot() robot.set_data_repo(j.sal.fs.getTmpDirPath()) if with_tmpl: robot.add_template_repo('http://github.com/threefoldtech/0-robot', directory='tests/fixtures/templates') listen = "localhost:660%d" % int(id) addr = "http://%s" % listen robot.start(listen=listen, testing=True)
def test_address(self): robot = Robot() self.assertIsNone(robot.address) with tempfile.TemporaryDirectory() as data_dir: robot.set_data_repo(data_dir) robot.start(listen="localhost:6600", block=False) self.assertEqual(robot.address, ('127.0.0.1', 6600)) robot.stop(timeout=1) self.assertIsNone(robot.address)
def __enter__(self): j.clients.zrobot.get('test', {'url': 'http://localhost:6600'}) self.cl = ZeroRobotManager('test') self.robot = Robot() self.robot.set_data_repo(j.sal.fs.getTmpDirPath()) self.robot.add_template_repo('http://github.com/zero-os/0-robot', directory='tests/fixtures/templates') if os.path.exists(config.data_repo.path): shutil.rmtree(config.data_repo.path) # make sure we don't have any service loaded scol.drop_all() self.robot.start(listen='127.0.0.1:6600', block=False, testing=True, god=self.god) return self.cl
def start(listen, data_repo, template_repo, config_repo, config_key, debug, telegram_bot_token, telegram_chat_id, auto_push, auto_push_interval, admin_organization, user_organization, mode, god): """ start the 0-robot daemon. this will start the REST API on address and port specified by --listen and block """ level = "INFO" if debug: level = "DEBUG" j.logger.handlers_level_set(level) j.logger.loggers_level_set(level) if (telegram_bot_token and not telegram_chat_id) or (telegram_chat_id and not telegram_bot_token): raise ValueError( "To enable telegram error logging, you need to specify both the --telegram-bot-token and the --telegram-chat-id options" ) if telegram_bot_token: telegram_logger.disabled = False telegrambot = j.clients.telegram_bot.get( instance='errorbot', data=dict(bot_token_=telegram_bot_token)) handler = TelegramHandler(telegrambot, telegram_chat_id) handler.setFormatter(TelegramFormatter()) handler.setLevel(logging.ERROR) telegram_logger.addHandler(handler) robot = Robot() for url in template_repo: robot.add_template_repo(url) robot.set_data_repo(data_repo) robot.set_config_repo(config_repo, config_key) robot.start(listen=listen, auto_push=auto_push, auto_push_interval=auto_push_interval, admin_organization=admin_organization, user_organization=user_organization, mode=mode, god=god)
def test_data_dir_required(self): with self.assertRaises( RuntimeError, msg="robot should not start if not data dir set"): robot = Robot() robot.start(testing=True)
def start(self): """ start the 0-robot daemon. this will start the REST API on address and port specified by --listen and block Arguments: listen {string} -- listen address (default :6600) data_repo {string} -- URL of the git repository or absolute path where to save the data of the zero robot template_repo {list} -- list of template repository URL. Use fragment URL to specify a branch: http://github.com/account/repo#branch' config_repo {string} -- URL of the configuration repository (https://github.com/Jumpscale/core9/blob/development/docs/config/configmanager.md) config_key {string} -- Absolute path to ssh key to secure configuration data, which is committed and pushed (see auto-push) in the configuration repo debug {boolean} -- enable debug logging telegram_bot_token {string} -- Bot to push template action failures telegram_chat_id {string} -- Chat id to push template action failures auto_push {boolean} -- enable automatically commit and pushing of data repository auto_push_interval {integer} -- interval in minutes of automatic pushing of data repository organization {string} -- if specified, enable JWT authentication for each request Raises: ValueError -- when telegram_bot is enable but no chat id is specified """ data_repo = self.config.data['data_repo'] listen = self.config.data.get('listen', ':6600') template_repo = self.config.data.get('template_repo') config_repo = self.config.data.get('config_repo') or None config_key = self.config.data.get('config_key') or None debug = self.config.data.get('debug', False) telegram_bot_token = self.config.data.get('telegram_bot_token') or None telegram_chat_id = self.config.data.get('telegram_chat_id') or None auto_push = self.config.data.get('auto_push', False) auto_push_interval = self.config.data.get('auto_push_interval', False) organization = self.config.data.get('organization') or None level = "INFO" if debug: level = "DEBUG" j.logger.handlers_level_set(level) j.logger.loggers_level_set(level) if (telegram_bot_token and not telegram_chat_id) or (telegram_chat_id and not telegram_bot_token): raise ValueError( "To enable telegram error logging, you need to specify both the --telegram-bot-token and the --telegram-chat-id options" ) if telegram_bot_token: telegram_logger.disabled = False telegrambot = j.clients.telegram_bot.get( instance='errorbot', data=dict(bot_token_=telegram_bot_token)) handler = TelegramHandler(telegrambot, telegram_chat_id) handler.setFormatter(TelegramFormatter()) handler.setLevel(logging.ERROR) telegram_logger.addHandler(handler) robot = Robot() for url in template_repo or []: robot.add_template_repo(url) robot.set_data_repo(data_repo) robot.set_config_repo(config_repo, config_key) robot.start(listen=listen, auto_push=auto_push, auto_push_interval=auto_push_interval, jwt_organization=organization)