def set_adaptive_parameters(self, adaptiveurl=None, adaptiveport=None, adaptiveinterval=None, minpercent=None): parameters = {} if adaptiveurl is not None: parameters['AdaptiveURL'] = adaptiveurl if adaptiveport is not None: validate_port(adaptiveport) parameters['AdaptivePort'] = adaptiveport if adaptiveinterval is not None: try: parameters['AdaptiveInterval'] = int(adaptiveinterval) except ValueError: raise LoadMasterParameterError( "AdaptiveInterval specified is not an integer", adaptiveinterval) if minpercent is not None: try: parameters['MinPercent'] = int(minpercent) except ValueError: raise LoadMasterParameterError( "MinPercent specified is not an integer", minpercent) response = self._get("/modadaptive", parameters) if not is_successful(response): raise LoadMasterParameterError(self, parameters)
def get_virtual_service(self, index=None, address=None, port=None, protocol=None): if index is None: validate_ip(address) validate_port(port) validate_protocol(protocol) service_id = {"vs": address, "port": port, "prot": protocol} else: service_id = {"vs": index} response = self._get("/showvs", service_id) service = get_data(response) # again line below will fail with ValidationError if empty response virt_serv = self.build_virtual_service(service) return virt_serv
def test_wildcard_port(self): expected = None actual = validate_port("*") assert_equal(expected, actual)
def test_out_of_range(self): with assert_raises(ValidationError): validate_port(1000000)
def test_non_integer(self): with assert_raises(ValidationError): validate_port('sds')
def test_ok(self): assert_is_none(validate_port('22'))