def lookup_port(host): """ Get the http port from config.properties http-server.http.port property if available. If the property is missing return default port 8080. If the file is missing or cannot parse the port number, throw ConfigurationError :param host: :return: """ config_file = constants.REMOTE_CONF_DIR + '/config.properties' with settings(hide('stdout', 'warnings', 'aborts')): try: port = execute(run, 'grep http-server.http.port= ' + config_file, warn_only=True, host=host)[host] except: raise ConfigurationError('Configuration file %s does not exist on ' 'host %s' % (config_file, host)) if isinstance(port, Exception): raise ConfigurationError('Configuration file %s does not exist on ' 'host %s' % (config_file, host)) else: if str(port) is '': _LOGGER.info('Could not find property http-server.http.port.' 'Defaulting to 8080.') return 8080 try: port = port.split('=', 1)[1] port = int(port) topology.validate_port(str(port)) _LOGGER.info('Looked up port ' + str(port) + ' on host ' + host) return port except ValueError: raise ConfigurationError('Unable to coerce http-server.http' '.port \'%s\' to an int. Failed to ' 'connect to %s.' % (port, host)) except ConfigurationError as e: raise ConfigurationError(e.message + ' for property ' 'http-server.http.port on host ' + host + '.')
def test_valid_port(self): port = "1234" self.assertEqual(topology.validate_port(port), port)