def check_honeycomb_startup_state(node, timeout=360, retries=20, interval=15): """Repeatedly check the status of Honeycomb startup until it is fully started or until timeout or max retries is reached. :param node: Honeycomb node. :param timeout: Timeout value in seconds. :param retries: Max number of retries. :param interval: Interval between checks, in seconds. :type node: dict :type timeout: int :type retries: int :type interval: int :raises HoneycombError: If the Honeycomb process IP cannot be found, or if timeout or number of retries is exceeded. """ ssh = SSH() ssh.connect(node) count = 0 start = time() while time() - start < timeout and count < retries: count += 1 try: status_code_version, _ = HcUtil.get_honeycomb_data( node, "oper_vpp_version") status_code_if_cfg, _ = HcUtil.get_honeycomb_data( node, "config_vpp_interfaces") status_code_if_oper, _ = HcUtil.get_honeycomb_data( node, "oper_vpp_interfaces") except HTTPRequestError: sleep(interval) continue if status_code_if_cfg == HTTPCodes.OK\ and status_code_if_cfg == HTTPCodes.OK\ and status_code_if_oper == HTTPCodes.OK: logger.info("Check successful, Honeycomb is up and running.") break else: logger.debug( "Attempt ${count} failed on Restconf check. Status codes:\n" "Version: {version}\n" "Interface config: {if_cfg}\n" "Interface operational: {if_oper}".format( count=count, version=status_code_version, if_cfg=status_code_if_cfg, if_oper=status_code_if_oper)) sleep(interval) continue else: _, vpp_status, _ = ssh.exec_command("sudo service vpp status") raise HoneycombError( "Timeout or max retries exceeded. Status of VPP:\n" "{vpp_status}".format(vpp_status=vpp_status))
def get_ipv6nd_configuration(node, interface): """Read IPv6 Neighbor Discovery proxy configuration on the specified interface. :param node: Honeycomb node. :param interface: Name of an interface on the node. :type node: dict :type interface: str :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the configuration could not be read. """ interface = Topology.convert_interface_reference( node, interface, "name") interface = interface.replace("/", "%2F") path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface) status_code, resp = HcUtil.get_honeycomb_data(node, "config_vpp_interfaces", path) if status_code != HTTPCodes.OK: raise HoneycombError("Could not read IPv6 ND proxy configuration. " "Status code: {0}.".format(status_code)) else: return resp
def check_honeycomb_startup_state(*nodes): """Check state of Honeycomb service during startup on specified nodes. Reads html path from template file oper_vpp_version.url. Honeycomb nodes reply with connection refused or the following status codes depending on startup progress: codes 200, 401, 403, 404, 500, 503 :param nodes: List of DUT nodes starting Honeycomb. :type nodes: list :return: True if all GETs returned code 200(OK). :rtype bool """ path = HcUtil.read_path_from_url_file("oper_vpp_version") expected_status_codes = (HTTPCodes.UNAUTHORIZED, HTTPCodes.FORBIDDEN, HTTPCodes.NOT_FOUND, HTTPCodes.SERVICE_UNAVAILABLE, HTTPCodes.INTERNAL_SERVER_ERROR) for node in nodes: if node['type'] == NodeType.DUT: HoneycombSetup.print_ports(node) try: status_code, _ = HTTPRequest.get(node, path, enable_logging=False) except HTTPRequestError: ssh = SSH() ssh.connect(node) ret_code, _, _ = ssh.exec_command_sudo( "tail -n 100 /var/log/syslog") if ret_code != 0: # It's probably Centos ssh.exec_command_sudo("tail -n 100 /var/log/messages") raise if status_code == HTTPCodes.OK: logger.info( "Honeycomb on node {0} is up and running".format( node['host'])) elif status_code in expected_status_codes: if status_code == HTTPCodes.UNAUTHORIZED: logger.info('Unauthorized. If this triggers keyword ' 'timeout, verify Honeycomb username and ' 'password.') raise HoneycombError('Honeycomb on node {0} running but ' 'not yet ready.'.format(node['host']), enable_logging=False) else: raise HoneycombError( 'Unexpected return code: {0}.'.format(status_code)) status_code, _ = HcUtil.get_honeycomb_data( node, "config_vpp_interfaces") if status_code != HTTPCodes.OK: raise HoneycombError('Honeycomb on node {0} running but ' 'not yet ready.'.format(node['host']), enable_logging=False) return True
def get_lispgpe_config_data(node): """Retrieve LISP GPE properties from Honeycomb config data. :param node: Honeycomb node. :type node: dict :returns: LISP GPE config data. :rtype: bytearray :raises HoneycombError: If the status code in response to GET is not 200 = OK. """ status_code, resp = HcUtil.get_honeycomb_data(node, "config_lisp_gpe") if status_code != HTTPCodes.OK: raise HoneycombError("Could not retrieve Lisp GPE config data." "Status code: {0}.".format(status_code)) else: return resp
def get_nat_oper_data(node): """Read NAT operational data. :param node: Honeycomb node. :type node: dict :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the operation fails or the response is not as expected. """ status_code, resp = HcUtil.get_honeycomb_data(node, "oper_nat") if status_code != HTTPCodes.OK: raise HoneycombError("Could not retrieve NAT operational data.") if "nat-state" not in resp.keys(): raise HoneycombError( "Unexpected format, response does not contain nat-state.") return resp['nat-state']
def set_lisp_state(node, state=True): """Enable or disable the Lisp feature. :param node: Honeycomb node. :param state: Enable or disable Lisp. :type node: dict :type state: bool :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the return code is not 200:OK or 404:NOT FOUND. """ ret_code, data = HcUtil.get_honeycomb_data(node, "config_lisp") if ret_code == HTTPCodes.OK: data["lisp"]["enable"] = bool(state) elif ret_code == HTTPCodes.NOT_FOUND: data = {"lisp": {"enable": bool(state)}} else: raise HoneycombError("Unexpected return code when getting existing" " Lisp configuration.") return LispKeywords._set_lisp_properties(node, '', data)
def get_lisp_operational_data(node): """Retrieve Lisp properties from Honeycomb operational data. :param node: Honeycomb node. :type node: dict :returns: List operational data. :rtype: bytearray """ status_code, resp = HcUtil.get_honeycomb_data(node, "oper_lisp") if status_code != HTTPCodes.OK: raise HoneycombError("Could not retrieve Lisp operational data." "Status code: {0}.".format(status_code)) else: # get rid of empty vni-table entry resp["lisp-state"]["lisp-feature-data"]["eid-table"][ "vni-table"].remove({ "virtual-network-identifier": 0, "vrf-subtable": { "table-id": 0 } }) return resp