OSNEXUS / QSPyClient

BSD 2-Clause "Simplified" License
1 stars 2 forks source link

QuantastorClient timeout not configurable #3

Open singlecheeze opened 1 week ago

singlecheeze commented 1 week ago

For long runnin, non async operations, the client will disconnect before the operation will complete, e.g creating 300 LUNs. I am using QuantaStor array to load test some Kubernetes load testing for k8s CSI.

The only way to the requests timeout of choice is to override the make_call method:

class QC(QuantastorClient):
    def make_call(self, api, payload):
        strURL = self._base_url + api
        certPath = self._cert
        if not path.exists(self._cert) or not self._cert:
            print("Warning - SSL certificate path: '" + str(self._cert) + "' either doesn't exist, or was not given. HTTPS request cannot be verified.")
            certPath = False
        r = requests.get(strURL, params=payload, verify=certPath, auth=self._auth, timeout=1200)
        if r.status_code != 200:
            raise Exception("Failed to make a request '" + api + "' payload '" + str(payload) + "' status code = " + str(r.status_code) + "strUrl " + strURL)
        jsonOutput = r.json()
        if isinstance(jsonOutput, dict) and 'RestError' in jsonOutput:
            raise Exception("Failed to make a request '" + api + "' payload '" + str(payload) + "' RestError = " + jsonOutput['RestError'])
        return jsonOutput

I propose changing the constructor of the client class and just adding a timeout, and if not specified default to requests native timeout:

    def __init__(self, hostname="", username="", password="", cert="", timeout=None):
        self._hostname = hostname
        self._username = username
        self._password = password
        self._cert = cert
        self.tmeout = timeout
singlecheeze commented 1 week ago

https://github.com/OSNEXUS/QSPyClient/pull/4

singlecheeze commented 1 week ago

I am still seeing timeouts even after the above edit Total Call Time: 90.1486s

I even edited /opt/osnexus/quantastor/restsrv/restsrv.py to add a 20 min timeout based on this:

def runService():

    server_config = {
        'server.socket_host': '127.0.0.1',
        'server.socket_port': 5154,
        'tools.trailing_slash.on': False,
        'server.socket_timeout': 1200
    }

    cherrypy.config.update(server_config)

    cherrypy.tree.mount(QSServer(), '/qstorapi')
    cherrypy.tree.mount(QSJSONServer(), '/qstorapi/jsonrpc')
    cherrypy.engine.start()
    cherrypy.engine.block()
singlecheeze commented 1 week ago

Ah found it, suds needs a timeout set too as jsonRPC just calls SOAP client:

def getClientHandle(username='admin', password='password'):
    global soap_client

    if soap_client is None:
        soap_client = Client(url='file:///opt/osnexus/quantastor/lib/osn.wsdl', location='http://localhost:5152', timeout=1200)

    security = Security()
    token = UsernameToken(username, password)
    security.tokens.append(token)
    soap_client.set_options(wsse=security)

    return soap_client

Once change is made, restart two services:

sudo systemctl restart qs-jsonrpcd.service
sudo systemctl restart quantastor.service
singlecheeze commented 1 week ago

So in total 3 timeouts need to be configurable, well really two if you want to use the same timeout for jsonRPC and suds (SOAP), and then from the client side requests timeout.