def test_ecmp_reshash_disable(netop_login, topology, step, sanity_check): # disable ecmp resilient hash ECMP_PATCH[0]["value"]["resilient_hash_enabled"] = ( ECMP_PATCH[0]["value"].pop(list(ECMP_PATCH[0]["value"])[0])) ECMP_PATCH[0]["value"]["resilient_hash_enabled"] = FALSE status_code, response_data = execute_request(PATH, "PATCH", json.dumps(ECMP_PATCH), SWITCH_IP, False, xtra_header=cookie_header) assert \ status_code == http.client.NO_CONTENT, \ "Error patching ecmp resilient hash disable Status code:" \ "%s Response data: %s " % (status_code, response_data) step("### Disable Resilient Hash ECMP Patched. Status code is 204 " "NO CONTENT ###\n") # Verify data status_code, response_data = execute_request(PATH, "GET", None, SWITCH_IP, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query ecmp config" json_data = get_json(response_data) assert \ json_data["configuration"]["ecmp_config"]["resilient_hash_enabled"] \ == FALSE, "ECMP resilient hash disable failed" step("### ECMP resilient hash disable validated ###\n")
def test_ecmp_srcport_enable(netop_login, topology, step, sanity_check): # enable ecmp source port ECMP_PATCH[0]["value"]["hash_srcport_enabled"] = ( ECMP_PATCH[0]["value"].pop(list(ECMP_PATCH[0]["value"])[0])) ECMP_PATCH[0]["value"]["hash_srcport_enabled"] = TRUE status_code, response_data = execute_request(PATH, "PATCH", json.dumps(ECMP_PATCH), SWITCH_IP, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching ecmp src " \ "ecmp source port enable Status code: %s Response data: %s " \ % (status_code, response_data) step("Enable Source Port ECMP Patched. Status code is 204 " "NO CONTENT\n") # Verify data status_code, response_data = execute_request(PATH, "GET", None, SWITCH_IP, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query ecmp config" json_data = get_json(response_data) assert json_data["configuration"]["ecmp_config"]["hash_srcport_enabled"] \ == TRUE, "ECMP source port enable failed" step("### ECMP source port enable validated ###\n")
def setup_l2_lag(step, switch, cookie_header, lag_id, interfaces, mode): port_data = copy.deepcopy(LAG_PORT_DATA) port_data["configuration"]["name"] = "lag" + lag_id port_data["configuration"]["admin"] = "up" port_data["configuration"]["lacp"] = mode # build array of interfaces ints = [] for interface in interfaces: ints.append("/rest/v1/system/interfaces/" + interface) port_data["configuration"]["interfaces"] = ints step("\n########## Switch " + switch + ": Create LAG " + lag_id + " ##########\n") status_code, response_data = execute_request(PATH_PORTS, "POST", json.dumps(port_data), switch, False, xtra_header=cookie_header) assert status_code == http.client.CREATED, "Error creating a Port.Status" \ + " code: %s Response data: %s " % (status_code, response_data) step("### Port Created. Status code is 201 CREATED ###\n") assign_lacp_aggregation_key_ints(step, switch, cookie_header, lag_id, interfaces)
def overview_data(step): step("\n########## Test to Validate Base Info ##########\n") # Get data status_code, response_data = execute_request(PATHBASE, "GET", None, SWITCH_IP, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to get base information" # Verify Data json_data = get_json(response_data) other_info = json_data["status"]["other_info"] required_keys = { 'Product Name', 'part_number', 'onie_version', 'base_mac_address', 'serial_number', 'vendor', 'max_interface_speed', 'max_transmission_unit', 'interface_count' } for key in required_keys: assert key in other_info, "Missing key %s" % key step("\n########## Base Data Validated ##########\n") step("\n########## Test to Validate System Info ##########\n") # Get data status_code, response_data = execute_request(PATHSYS, "GET", None, SWITCH_IP, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to get base information" # Verify Data json_data = get_json(response_data) system_config = json_data["configuration"] system_status = json_data["status"] assert 'hostname' in system_config, "Missing key %s" % key assert 'switch_version' in system_status, "Missing key %s" % key step("\n########## System Data Validated ##########\n")
def int_admin_up(step, switch, cookie_header, port): int_path = PATH_INT + "/" + port status_code, response_data = execute_request(int_path, "PATCH", json.dumps(ADM_PATCH_INT), switch, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching an "\ "Interface. Status code: %s Response data: %s "\ % (status_code, response_data) step("### Interface Patched. Status code is 204 NO CONTENT ###\n")
def test_initial_config(netop_login, topology, step, sanity_check): # Verify data status_code, response_data = execute_request(PATH, "GET", None, SWITCH_IP, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query ecmp config " json_data = get_json(response_data) assert "ecmp" not in list(json_data["configuration"]), \ "Default ECMP configuration data is non blank" step("### ECMP default configuration data validated ###\n")
def validate_dynamic_lag_created(step, switch, cookie_header, lag_name): # assert status bond_hw_handle exists # Verify data port_path = PATH_PORTS + "/" + lag_name step("### Checking switch " + switch + " for LAG: " + lag_name + "###\n") status_code, response_data = execute_request(port_path, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Falied query: " + lag_name json_data = get_json(response_data) assert json_data["status"]["lacp_status"], "Lag port not created" step("### Switch: " + switch + " - Lag is created ###\n")
def set_vlan_mode(step, switch, cookie_header, port, mode): port_path = PATH_PORTS + "/" + port port_data = copy.deepcopy(VLAN_MODE_PATCH_PRT) port_data["value"] = mode status_code, response_data = execute_request(port_path, "PATCH", json.dumps([port_data]), switch, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching an " \ "Interface. Status code: %s Response data: %s " \ % (status_code, response_data) step("### VLAN mode Patched. Status code is 204 NO CONTENT ###\n")
def assign_lacp_aggregation_key_int(step, switch, cookie_header, lag_id, interface): int_path = PATH_INT + "/" + interface int_data = copy.deepcopy(LACP_KEY_PATCH_INT) int_data["value"][LACP_AGGREGATION_KEY] = lag_id status_code, response_data = execute_request(int_path, "PATCH", json.dumps([int_data]), switch, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching an "\ "Interface. Status code: %s Response data: %s "\ % (status_code, response_data) step("### Interface Patched. Status code is 204 NO CONTENT ###\n")
def patch_other(step, switch, cookie_header): global INT_PATH int_data = copy.deepcopy(INT_DATA) INT_PATH = PATH_INT + "/2" int_data["configuration"]["name"] = "2" # Setup patch int_data["configuration"]["user_config"] = {} int_data["configuration"]["user_config"]["duplex"] = "half" int_data["configuration"]["user_config"]["autoneg"] = "off" int_data["configuration"]["user_config"]["pause"] = "rxtx" # Patch step("\n########## Test to Validate Patch Other ##########\n") status_code, response_data = execute_request(INT_PATH, "PATCH", json.dumps(OTHER_PATCH), SWITCH_IP_1, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching an " \ "Interface. Status code: %s Response data: %s " \ % (status_code, response_data) step("### Interface Patched. Status code is 204 NO CONTENT ###\n") # Verify data status_code, response_data = execute_request(INT_PATH, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query patched Port" json_data = get_json(response_data) assert json_data["configuration"] == int_data["configuration"], \ "Configuration data is not equal that posted data" step("### Configuration data validated ###\n") # Remove data int_data = copy.deepcopy(INT_DATA) int_data["configuration"]["name"] = "2" status_code, response_data = execute_request(INT_PATH, "PATCH", json.dumps(REMOVE_PATCH), switch, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching an " \ "Interface. Status code: %s Response data: %s " \ % (status_code, response_data) step("### Interface Patched. Status code is 204 NO CONTENT ###\n") # Verify data status_code, response_data = execute_request(INT_PATH, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query patched Port" json_data = get_json(response_data) assert json_data["configuration"] == int_data["configuration"], \ "Configuration data is not equal that posted data" step("### Configuration data validated ###\n") step("\n########## End Test Create And Patch Port Int ##########\n")
def patch_port_int_admin(step, switch, cookie_header): global PORT_PATH, INT_PATH port_data = copy.deepcopy(PORT_DATA) int_data = copy.deepcopy(INT_DATA) PORT_PATH = PATH_PORTS + "/1" INT_PATH = PATH_INT + "/1" step("### Patch Port and Int on Switch " + switch + "###\n") # Create port status_code, response_data = execute_request(PATH_PORTS, "POST", json.dumps(port_data), switch, False, xtra_header=cookie_header) assert status_code == http.client.CREATED, "Error creating a Port. " \ "Status code: %s Response data: %s " % (status_code, response_data) step("### Port Created. Status code is 201 CREATED ###\n") # Verify data status_code, response_data = execute_request(PORT_PATH, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query added Port" json_data = get_json(response_data) assert json_data["configuration"] == port_data["configuration"], \ "Configuration data is not equal that posted data" step("### Configuration data validated ###\n") step("\n########## Test to Validate Patch Port Int ##########\n") port_data["configuration"]["admin"] = "up" int_data["configuration"]["user_config"] = {} int_data["configuration"]["user_config"]["admin"] = "up" status_code, response_data = execute_request(PORT_PATH, "PATCH", json.dumps(ADM_PATCH_PRT), switch, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching a Port " \ "Status code: %s Response data: %s " % (status_code, response_data) step("### Port Patched. Status code is 204 NO CONTENT ###\n") # Verify data status_code, response_data = execute_request(PORT_PATH, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query patched Port" json_data = get_json(response_data) assert json_data["configuration"] == port_data["configuration"], \ "Configuration data is not equal that posted data" step("### Configuration data validated ###\n") status_code, response_data = execute_request(INT_PATH, "PATCH", json.dumps(ADM_PATCH_INT), switch, False, xtra_header=cookie_header) assert status_code == http.client.NO_CONTENT, "Error patching an " \ "Interface. Status code: %s Response data: %s " \ % (status_code, response_data) step("### Interface Patched. Status code is 204 NO CONTENT ###\n") # Verify data status_code, response_data = execute_request(INT_PATH, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to query patched Port" json_data = get_json(response_data) assert json_data["configuration"] == int_data["configuration"], \ "Configuration data is not equal that posted data" step("### Configuration data validated ###\n") step("\n########## End Test Create And Patch Port Int ##########\n")
def rest_lldp_interface(step, switch, cookie_header): # Fetching /rest/v1/system/intefaces int_path = PATH_INT + "/" + "2" step("### GET for url = /rest/v1/system/interfaces/1 ###\n") status_code, response_data = execute_request( int_path, "GET", None, switch, False, xtra_header=cookie_header) assert status_code == http.client.OK, "Failed to execute rest cmd"\ "GET for url=/rest/v1/system/interfaces" json_data = get_json(response_data) step("### Fetch Success ###\n") # TEST 1 - Check to see if LLDP NEIGHBOR INFO TAG IS PRESENT step("### Check to see if LLDP NEIGHBOR INFO TAG IS PRESENT ###\n") assert json_data["status"]["lldp_neighbor_info"], "No LLDP Neighbor "\ "info" step("###LLDP NEIGHBOR INFO PRESENT ### \n") # TEST 2 - Check to see if LLDP NEIGHBOR INFO - IP MGMT TAG IS PRESENT step("### Check to see if LLDP NEIGHBOR INFO TAG IS PRESENT ###\n") assert json_data["status"]["lldp_neighbor_info"]["mgmt_ip_list"], "No "\ "MGMT IP PRESENT" step("###LLDP MGMT IP PRESENT ### \n") # TEST 3 - Check to see if NEIGHBOR INFO - IP MGMT TAG MATCHES EXP VALUE try: lldp_ip = json_data["status"]["lldp_neighbor_info"]["mgmt_ip_list"] except ValueError: step('### Value error in Rest GET for mgmt_ip_list ###\n') assert lldp_ip == "16.93.49.10", "Failed in checking the GET "\ "METHOD JSON response validation for mgmt_ip_list value" step("### Success in Rest GET for mgmt_ip_list value = expected ###\n") # TEST 4 - Check to see if LLDP STATISTICS TAG IS PRESENT assert json_data["statistics"]["lldp_statistics"], "Failed in checking "\ "the GET METHOD JSON response validation for lldp_statistics tag" step("### Success in Rest GET for lldp_statistics tag ###\n") # TEST 5 - Check to see if LLDP STATISTICS TAG FOR XMIT IS PRESENT assert json_data["statistics"]["lldp_statistics"]["lldp_tx"], "Failed "\ "in checking the GET METHOD JSON response validation for lldp_tx tag" step("### Success in Rest GET for lldp_tx tag ###\n") # TEST 6 - Check to see if LLDP STATISTICS TAG FOR XMIT IS > 0 try: lldp_tx = int(json_data["statistics"]["lldp_statistics"]["lldp_tx"]) except ValueError: step("### Value error in Rest GET for lldp_tx ###\n") assert lldp_tx != 0, "Failed in checking the GET METHOD JSON "\ "response validation for lldp_tx value = 0" step("### Success in Rest GET - lldp_tx value > 0 ###\n") # TEST 7 - Check to see if LLDP STATISTICS TAG FOR RCV IS PRESENT assert json_data["statistics"]["lldp_statistics"]["lldp_rx"], "Failed"\ "in checking the GET METHOD JSON response validation for lldp_rx tag" step("### Success in Rest GET for lldp_rx tag ###\n") # TEST 8 - Check to see if LLDP STATISTICS TAG FOR RCV > 0 try: lldp_rx = int(json_data["statistics"]["lldp_statistics"]["lldp_rx"]) except ValueError: step("### Value error in Rest GET for lldp_rx ###\n") assert lldp_rx != 0, "Failed in checking the GET METHOD JSON "\ "response validation for lldp_rx value = 0" step("### Success in Rest GET - lldp_rx value > 0 ###\n")