def test_port_sort_by_ip6_address_secondary(self, desc=False): info("\n########## Test to sort port by ip6_address_secondary " "##########\n") expected_values = [] values = fill_with_function(random_ip6_address() + '/64', NUM_FAKE_PORTS) for i in range(1, NUM_FAKE_PORTS + 1): value = values[i - 1] update_test_field(self.SWITCH_IP, self.PATH + "/Port-%s" % i, "ip6_address_secondary", [value], self.cookie_header) expected_values.append(value) expected_values.sort(key=lambda val: self.sort_value_to_lower(val), reverse=desc) json_data = self.execute_sort_by_request("ip6_address_secondary", httplib.OK, desc) assert len(json_data) is (NUM_FAKE_PORTS), \ "Retrieved more expected ports!" if self.non_null_col(json_data, "ip6_address_secondary"): self.check_sort_expectations(expected_values, json_data, "ip6_address_secondary") info("\n########## End Test to sort port by ip6_address_secondary " "##########\n")
def test_port_sort_by_interfaces(self, desc=False): info("\n########## Test to sort port by interfaces##########\n") expected_values = [] for i in range(1, NUM_FAKE_PORTS + 1): interfaces = [] if not desc: interfaces = [ "/rest/v1/system/interfaces/%s" % (NUM_FAKE_PORTS + 1 - i) ] else: interfaces = ["/rest/v1/system/interfaces/%s" % i] update_test_field(self.SWITCH_IP, self.PATH + "/Port-%s" % i, "interfaces", interfaces, self.cookie_header) expected_values.append(interfaces) expected_values.sort(key=lambda val: self.sort_value_to_lower(val), reverse=desc) json_data = self.execute_sort_by_request("interfaces", httplib.OK, desc) assert len(json_data) is (NUM_FAKE_PORTS), \ "Retrieved more expected ports!" if self.non_null_col(json_data, "interfaces"): self.check_sort_expectations(expected_values, json_data, "interfaces") info("########## End Test to sort ports by interfaces ##########\n")
def test_port_sort_by_tag(self, desc=False): info("\n########## Test to sort port by tag ##########\n") expected_values = [] for i in range(1024, NUM_FAKE_PORTS + 1): vlan_id = i vlan_name = "VLAN" + str(vlan_id) vlan_path = "%s/%s/vlans" % (bridge_path, DEFAULT_BRIDGE) create_fake_vlan(vlan_path, self.SWITCH_IP, vlan_name, vlan_id) value = ["%s/%s" % (vlan_path, vlan_name)] update_test_field(self.SWITCH_IP, self.PATH + "/Port-%s" % i, "vlan_tag", value[0], self.cookie_header) expected_values.append(value) expected_values.sort(key=lambda val: self.sort_value_to_lower(val), reverse=desc) json_data = self.execute_sort_by_request("vlan_tag", httplib.OK, desc) assert len(json_data) is (NUM_FAKE_PORTS), \ "Retrieved more expected ports!" if self.non_null_col(json_data, "vlan_tag"): self.check_sort_expectations(expected_values, json_data, "vlan_tag") info("\n########## End Test to sort port by tag ##########\n")
def test_port_sort_with_all_available_keys(self, desc=False): """ Test ports resource by sorting with all the available keys """ test_title = "Test to sort port with all available keys" info("\n########## " + test_title + " ##########\n") expected_values = [] admin_values = ["up", "down"] random.seed() for i in range(1, NUM_FAKE_PORTS + 1): port = "Port-%s" % i admin_value = admin_values[(i - 1) % len(admin_values)] update_test_field(self.SWITCH_IP, self.PATH + "/" + port, "admin", admin_value, self.cookie_header) status_code, response_data = execute_request( self.PATH + "/" + port, "GET", None, self.SWITCH_IP, xtra_header=self.cookie_header) assert status_code == httplib.OK, "Wrong status code %s " % \ status_code json_data = json.loads(response_data) expected_dict = json_data['configuration'] expected_values.append(expected_dict) columns = [] for key in expected_values[0].viewkeys(): columns.append(key) compare_function = lambda item: tuple( self.sort_value_to_lower(item[k]) for k in columns) expected_values = sorted(expected_values, key=compare_function, reverse=desc) json_data = self.execute_sort_by_request(columns, httplib.OK, desc) assert len(json_data) is ( NUM_FAKE_PORTS), "Retrieved more expected ports!" if self.non_null_col(json_data, columns): for i in range(0, len(json_data)): for column in columns: assert json_data[i]["configuration"][column] == \ expected_values[i][column], \ "Wrong order. Expected: %s Returned: %s" \ % (expected_values[i][column], json_data[i]["configuration"][column]) info("########## End " + test_title + " ##########\n")
def test(self): test_vlans = ["Vlan-2", "Vlan-3", "Vlan-4", "Vlan-5", "Vlan-6"] test_field = "admin" test_old_value = "up" test_new_value = "down" updated_vlans = len(test_vlans) # DEFAULT_VLAN_1 is set to admin=up other_vlans = NUM_FAKE_VLANS - updated_vlans + 1 info("\n########## Test Filter Admin ##########\n") ####################################################################### # Update values ####################################################################### for vlan in test_vlans: update_test_field(self.switch_ip, self.path + vlan, test_field, test_new_value) ####################################################################### # Query for the updated VLANs ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_new_value) request_response = validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == updated_vlans, \ "Retrieved more expected VLANs!" for i in range(0, updated_vlans): assert request_response[i]["configuration"][test_field] == \ test_new_value, "Retrieved wrong VLAN!" ####################################################################### # Query for other VLANs ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_old_value) request_response = validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == other_vlans, \ "Retrieved more expected VLANs!" for i in range(0, other_vlans): assert request_response[i]["configuration"][test_field] == \ test_old_value, "Retrieved wrong VLAN!" info("########## End Test Filter Admin ##########\n")
def test_port_sort_by_admin_name(self, desc=False): info("\n########## Test to sort port by (admin,name) ##########\n") expected_values = [] admin_values = ["up", "down"] random.seed() for i in range(1, NUM_FAKE_PORTS + 1): port = "Port-%s" % i admin_value = admin_values[(i - 1) % len(admin_values)] update_test_field(self.SWITCH_IP, self.PATH + "/" + port, "admin", admin_value, self.cookie_header) expected_dict = {"admin": admin_value, "name": port} expected_values.append(expected_dict) columns = ["admin", "name"] compare_function = lambda item: tuple( self.sort_value_to_lower(item[k]) for k in columns) expected_values = sorted(expected_values, key=compare_function, reverse=desc) json_data = self.execute_sort_by_request(columns, httplib.OK, desc) assert len(json_data) is ( NUM_FAKE_PORTS), "Retrieved more expected ports!" for i in range(0, len(expected_values)): expected_name = expected_values[i]["name"] expected_admin = expected_values[i]["admin"] returned_name = json_data[i]["configuration"]["name"] returned_admin = json_data[i]["configuration"]["admin"] if self.non_null_col(json_data, columns): assert returned_name == expected_name and \ expected_admin == returned_admin, \ "Wrong order. Expected: %s Returned: %s" \ % (expected_name, returned_name) info("\n########## End Test to sort port by (admin,name) ##########\n")
def test_port_sort_by_admin(self, desc=False): info("\n########## Test to sort port by admin ##########\n") expected_values = [] values = ["up", "down"] for i in range(1, NUM_FAKE_PORTS + 1): value = values[(i - 1) % len(values)] update_test_field(self.SWITCH_IP, self.PATH + "/Port-%s" % i, "admin", value, self.cookie_header) expected_values.append(value) expected_values.sort(key=lambda val: self.sort_value_to_lower(val), reverse=desc) json_data = self.execute_sort_by_request("admin", httplib.OK, desc) assert len(json_data) is (NUM_FAKE_PORTS), \ "Retrieved more expected ports!" if self.non_null_col(json_data, "admin"): self.check_sort_expectations(expected_values, json_data, "admin") info("\n########## End Test to sort port by admin ##########\n")
def test_port_filter_by_admin(self): test_ports = ["Port-1", "Port-2", "Port-3", "Port-4", "Port-5"] test_field = "admin" test_old_value = "up" test_new_value = "down" updated_ports = len(test_ports) other_ports = NUM_FAKE_PORTS - updated_ports info("\n########## Test Filter Admin ##########\n") ####################################################################### # Update values ####################################################################### for port in test_ports: update_test_field(self.switch_ip, self.path + port, test_field, test_new_value, self.cookie_header) ####################################################################### # Query for the updated ports ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_new_value) request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == updated_ports, \ "Retrieved more ports than expected!" for i in range(0, updated_ports): assert request_response[i]["configuration"][test_field] == \ test_new_value, "Retrieved wrong port!" ####################################################################### # Query for other ports ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_old_value) request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == other_ports, \ "Retrieved more ports than expected!" for i in range(0, other_ports): assert request_response[i]["configuration"][test_field] == \ test_old_value, "Retrieved wrong port!" ####################################################################### # Restore default value ####################################################################### for port in test_ports: update_test_field(self.switch_ip, self.path + port, test_field, test_old_value, self.cookie_header) info("########## End Test Filter Admin ##########\n")
def test_port_filter_by_vlan_mode(self): test_ports = ["Port-1", "Port-2", "Port-3"] test_field = "vlan_mode" test_old_value = "trunk" test_new_value = ["access", "native-tagged", "native-untagged"] updated_ports = len(test_ports) other_ports = NUM_FAKE_PORTS - updated_ports info("\n########## Test Filter vlan_mode ##########\n") ####################################################################### # Update values ####################################################################### for i in range(0, updated_ports): update_test_field(self.switch_ip, self.path + test_ports[i], test_field, test_new_value[i], self.cookie_header) ####################################################################### # Query for the updated ports ####################################################################### for mode in test_new_value: path = "%s?depth=1;%s=%s" % (self.path, test_field, mode) request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == 1, \ "Retrieved more ports than expected!" assert request_response[0]["configuration"][test_field] == \ mode, "Retrieved wrong port!" ####################################################################### # Query for other ports ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_old_value) request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == other_ports, \ "Retrieved more ports than expected!" for i in range(0, other_ports): assert request_response[i]["configuration"][test_field] == \ test_old_value, "Retrieved wrong port!" ####################################################################### # Restore default value ####################################################################### for port in test_ports: update_test_field(self.switch_ip, self.path + port, test_field, test_old_value, self.cookie_header) info("########## End Test Filter vlan_mode ##########\n")
def test_port_filter_by_tag(self): test_ports = ["Port-1", "Port-2", "Port-3", "Port-4", "Port-5"] test_field = "vlan_tag" test_old_value = ["/rest/v1/system/bridges/bridge_normal/vlans/VLAN654"] test_new_value = ["/rest/v1/system/bridges/bridge_normal/vlans/VLAN123"] vlan_id = 123 vlan_name = "VLAN123" vlan_path = "%s/%s/vlans" % (bridge_path, DEFAULT_BRIDGE) create_fake_vlan(vlan_path, self.switch_ip, vlan_name, vlan_id) updated_ports = len(test_ports) other_ports = NUM_FAKE_PORTS - updated_ports info("\n########## Test Filter Tag ##########\n") ####################################################################### # Update values ####################################################################### for port in test_ports: update_test_field(self.switch_ip, self.path + port, test_field, test_new_value, self.cookie_header) ####################################################################### # Query for the updated port ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_new_value[0]) request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == updated_ports, \ "Retrieved more ports than expected!" for i in range(0, updated_ports): assert request_response[i]["configuration"][test_field] == \ test_new_value, "Retrieved wrong port!" ####################################################################### # Query for other ports ####################################################################### path = "%s?depth=1;%s=%s" % (self.path, test_field, test_old_value[0]) request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == other_ports, \ "Retrieved more ports than expected!" for i in range(0, other_ports): assert request_response[i]["configuration"][test_field] == \ test_old_value, "Retrieved wrong port!" ####################################################################### # Restore default value ####################################################################### for port in test_ports: update_test_field(self.switch_ip, self.path + port, test_field, test_old_value, self.cookie_header) info("########## End Test Filter Tag ##########\n")
def test_port_filter_by_lacp(self): test_field = "lacp" updated_ports = 2 other_ports = NUM_FAKE_PORTS - updated_ports info("\n########## Test Filter Lacp ##########\n") ###################################################################### # Update values ###################################################################### update_test_field(self.switch_ip, self.path + "/Port-1", test_field, ["passive"], self.cookie_header) update_test_field(self.switch_ip, self.path + "/Port-2", test_field, ["off"], self.cookie_header) ###################################################################### # Query for the updated ports ###################################################################### path = self.path + "?depth=1;lacp=passive;lacp=off" request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == updated_ports, \ "Retrieved more ports than expected!" for i in range(0, updated_ports): lacp_value = request_response[i]["configuration"][test_field] if lacp_value is "passive" or lacp_value is "off": assert False, "Retrieved wrong port!" ####################################################################### # Query for other ports ####################################################################### path = self.path + "?depth=1;lacp=active" request_response = self.validate_request(self.switch_ip, path, None, "GET", httplib.OK, "") assert len(request_response) == other_ports, \ "Retrieved more ports than expected!" for i in range(0, other_ports): assert request_response[i]["configuration"][test_field] == \ "active", "Retrieved wrong port!" ####################################################################### # Restore default value ####################################################################### update_test_field(self.switch_ip, self.path + "/Port-2", test_field, ["active"], self.cookie_header) update_test_field(self.switch_ip, self.path + "/Port-3", test_field, ["active"], self.cookie_header) info("########## End Test Filter Lacp ##########\n")