the unit test do not have the correct user_agent

Bug #1741008 reported by baisen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Tricircle
Fix Released
High
Unassigned

Bug Description

INFO neutron.wsgi [None req-061e4d66-f63e-4176-8c3e-4f29b9873453 demo admin] 10.11.3.200 "POST /v2.0/ports HTTP/1.1" status: 201 len: 856 time: 5.1422789
> /opt/stack/tricircle/tricircle/common/request_source.py(38)distinguish_requests_source()
-> if source_header in cons.REQUEST_SOURCE_TYPE:
(Pdb) p source_header
'openstacksdk/0.9.18 keystoneauth1/3.2.0 python-requests/2.18.4 CPython/2.7.12'
(Pdb) l
 33
 34 def distinguish_requests_source(self, req):
 35 source_header = req.headers.get(cons.USER_AGENT, "")
 36 import pdb
 37 pdb.set_trace()
 38 -> if source_header in cons.REQUEST_SOURCE_TYPE:
 39 ctx = req.environ['neutron.context']
 40 ctx.USER_AGENT = source_header
 41 req.environ['neutron.context'] = ctx
 42
 43 @webob.dec.wsgify
(Pdb) p source_header
'openstacksdk/0.9.18 keystoneauth1/3.2.0 python-requests/2.18.4 CPython/2.7.12'

like above all the request from unit test will not in cons.REQUEST_SOURCE_TYPE.

so all the request will do not know whether come for user or from local neturon .

Chaoyi Huang (joehuang)
Changed in tricircle:
importance: Undecided → High
status: New → Confirmed
Revision history for this message
baisen (song1) wrote :

it is look like a throuble.

in resource2.py openstack generate the post methond base on the session,but it do not

pass the user-agent para.

 response = session.post(request.uri, endpoint_filter=self.service,
                                    json=request.body, headers=request.headers)

even in the session.py the function have allow to pass the user_agent para.like below.

 def request(self, url, method, json=None, original_ip=None,
                user_agent=None, redirect=None, authenticated=None,
                endpoint_filter=None, auth=None, requests_auth=None,
                raise_exc=True, allow_reauth=True, log=True,
                endpoint_override=None, connect_retries=0, logger=_logger,
                allow=None, client_name=None, client_version=None,
                microversion=None, microversion_service_type=None,
                **kwargs):

so even we set the usr-agent in the headers is also no use, because like below:
the request will rewrite the user-agent, which we have set it before this.

       if user_agent:
            headers['User-Agent'] = user_agent
        elif self.user_agent:
            user_agent = headers.setdefault('User-Agent', self.user_agent)

baisen (song1)
Changed in tricircle:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.