def test_parse_full_config(self): self._prepare_config_file(True) config = KConfig(self.config_file[1]) config.read_conf() self.assertEqual(self.url, config.server_url) self.assertEqual(self._toUrl(self.path_login), config.login_url) self.assertEqual(self._toUrl(self.path_register), config.register_url) self.assertEqual(self._toUrl(self.path_ca_host), config.ca_host_url) self.assertEqual(self._toUrl(self.path_heartbeat), config.heartbeat_url) self.assertEqual(self._toUrl(self.path_alert), config.alert_url) self.assertEqual(self.username, config.server_username) self.assertEqual(self.server_password, config.server_password) self.assertEqual(self.host_id, config.host_id) self.assertEqual(int(self.restport), config.rest_port) self.assertEqual(int(self.heartbeat_interval), config.heartbeat_interval) self.assertEqual(self.services_file, config.services_file) self.assertEqual(int(self.watch_interval), config.watch_interval) self.assertEqual(self.bin_dir, config.bin_dir) self.assertEqual(self.pid_file, config.agent_pidfile) self.assertEqual(self.agent_log_file, config.agent_log_file) self.assertEqual(self.csr_log_file, config.csr_log_file) self.assertEqual(self.logging_level, config.logging_level_str) self.assertEqual(int(self.max_log_size), config.max_log_size) my_ip = netifaces.ifaddresses( self.network_interface)[netifaces.AF_INET][0]['addr'] if (IP(my_ip).iptype() == "PUBLIC"): self.assertEqual(my_ip, config.public_ip) else: self.assertEqual(my_ip, config.private_ip) self.assertEqual(self.mysql_socket, config.mysql_socket) self.assertEqual(self.hostname, config.hostname) self.assertEqual(self.network_interface, config.network_interface) self.assertEqual(self.group_name, config.group_name) self.assertEqual(self.hadoop_home, config.hadoop_home) self.assertEqual(self.certs_dir, config.certs_dir) self.assertEqual(self.certificate_file, config.certificate_file) self.assertEqual(self.key_file, config.key_file) self.assertEqual(self.server_keystore, config.server_keystore) self.assertEqual(self.server_truststore, config.server_truststore) self.assertEqual(self.keystore_script, config.keystore_script) self.assertEqual(self.state_store, config.state_store_location) self.assertEqual(self.agent_password, config.agent_password) self.assertEqual(self.conda_dir, config.conda_dir) self.assertEqual(self.conda_envs_blacklist, config.conda_envs_blacklist) self.assertEqual(self.conda_gc_interval, config.conda_gc_interval)
def test_parse_partial_config(self): self._prepare_config_file(False) config = KConfig(self.config_file[1]) config.read_conf() self.assertIsNotNone(config.agent_password) self.assertNotEqual('', config.agent_password) my_ip = netifaces.ifaddresses( self.network_interface)[netifaces.AF_INET][0]['addr'] my_hostname = socket.gethostbyaddr(my_ip)[0] self.assertEqual(my_hostname, config.hostname) self.assertEqual(my_hostname, config.host_id)
def test_alternate_host(self): alternate_host = "https://alternate.url:443/" self._prepare_config_file(False) config = KConfig(self.config_file[1]) config.load() config.server_url = alternate_host config.read_conf() self.assertEqual(alternate_host, config.server_url) register_path = config._config.get('server', 'path-register') self.assertEqual(alternate_host + register_path, config.register_url)
def test_parse_partial_config(self): self._prepare_config_file(False) config = KConfig(self.config_file[1]) config.load() config.read_conf() self.assertIsNotNone(config.agent_password) self.assertNotEqual('', config.agent_password) my_hostname = socket.gethostbyaddr(self.private_ip)[0] self.assertEqual(my_hostname, config.hostname) self.assertEqual(my_hostname, config.host_id)
def test_parse_full_config(self): self._prepare_config_file(True) config = KConfig(self.config_file[1]) config.load() config.read_conf() self.assertEqual(self.url, config.server_url) self.assertEqual(self._toUrl(self.path_login), config.login_url) self.assertEqual(self._toUrl(self.path_register), config.register_url) self.assertEqual(self._toUrl(self.path_ca_host), config.ca_host_url) self.assertEqual(self._toUrl(self.path_heartbeat), config.heartbeat_url) self.assertEqual(self.username, config.server_username) self.assertEqual(self.server_password, config.server_password) self.assertEqual(self.host_id, config.host_id) self.assertEqual(int(self.restport), config.rest_port) self.assertEqual(int(self.heartbeat_interval), config.heartbeat_interval) self.assertEqual(self.services_file, config.services_file) self.assertEqual(self.watch_interval, config.watch_interval) self.assertEqual(self.bin_dir, config.bin_dir) self.assertEqual(self.sbin_dir, config.sbin_dir) self.assertEqual(self.pid_file, config.agent_pidfile) self.assertEqual(self.agent_log_dir, config.agent_log_dir) self.assertEqual(self.csr_log_file, config.csr_log_file) self.assertEqual(self.logging_level, config.logging_level_str) self.assertEqual(int(self.max_log_size), config.max_log_size) self.assertEqual(self.private_ip, config.private_ip) self.assertEqual(self.public_ip, config.public_ip) self.assertEqual(self.hostname, config.hostname) self.assertEqual(self.hadoop_home, config.hadoop_home) self.assertEqual(self.certs_dir, config.certs_dir) self.assertEqual(self.certs_user, config.certs_user) self.assertEqual(self.keystore_script, config.keystore_script) self.assertEqual(self.state_store, config.state_store_location) self.assertEqual(self.agent_password, config.agent_password)
logger.info("Not watching %s/%s/%s", cluster, group, service_name) return host_services if __name__ == '__main__': parser = argparse.ArgumentParser(description='Hops nodes administration agent') parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('-c', '--config', default='config.ini', help='Path to configuration file') args = parser.parse_args() verbose = args.verbose global kconfig kconfig = KConfig(args.config) kconfig.read_conf() create_log_dir_if_not(kconfig) setupLogging(kconfig) prepare_conda_commands_logger(kconfig) readServicesFile() hw_http_client = kagent_utils.Http(kconfig) host_services = construct_services(kconfig, hw_http_client) agent_pid = str(os.getpid()) file(kconfig.agent_pidfile, 'w').write(agent_pid) logger.info("Hops Kagent PID: {0}".format(agent_pid))
def __init__(self, monitor_list): config = KConfig("some_path") config.conda_dir = "/some/path/anaconda-2-5.2.0" config.conda_envs_blacklist = "python27, python35, hops-system" CondaEnvsWatcherAction.__init__(self, monitor_list, config)
description='Register host with Hopsworks and get certificate.') parser.add_argument('-c', '--config', default='config.ini', help='Configuration file') parser.add_argument('--alt-url', help='Alternative Hopsworks URL') subparser = parser.add_subparsers(dest='operation', help='Operations') subparser.add_parser('init', help='Initialize agent') subparser.add_parser('rotate', help='Rotate node certificate') subparser.add_parser('elkadmin', help='Generate elastic admin certificate') args = parser.parse_args() config = KConfig(args.config) config.load() if args.alt_url: if not args.alt_url.endswith("/"): args.alt_url = args.alt_url + "/" config.server_url = args.alt_url config.read_conf() setup_logging(config.csr_log_file, config.max_log_size, config.logging_level) LOG = logging.getLogger(__name__) LOG.info("Hops CSR-agent started.") LOG.info("Register URL: {0}".format(config.register_url)) LOG.info("Public IP: {0}".format(config.public_ip)) LOG.info("Private IP: {0}".format(config.private_ip))