Project

General

Profile

Actions

Bug #44317

closed

mgr/dashboard: backend Grafana unit test error

Added by Patrick Seidensal about 4 years ago. Updated about 3 years ago.

Status:
Resolved
Priority:
Normal
Category:
Testing & QA
Target version:
% Done:

0%

Source:
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

Some of the Grafana Unit Test in the backend are not using mocks properly and don't prevent requests being made to a configured HTTP address. In fact, it is required for the tests to pass, that no service is running on this address (`http://localhost:3000`). If a service is available at that port (usually a Grafana instance), the tests will fail:

tests/test_grafana.py ....F

__________________________________________________________ GrafanaTest.test_validation ___________________________________________________________

self = <dashboard.tests.test_grafana.GrafanaTest testMethod=test_validation>

    def test_validation(self):
        self.server_settings()
        self._get('/api/grafana/validation/foo')
>       self.assertStatus(500)

tests/test_grafana.py:47: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/py3/lib/python3.6/site-packages/cheroot/test/webtest.py:325: in assertStatus
    self._handlewebError(msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <dashboard.tests.test_grafana.GrafanaTest testMethod=test_validation>, msg = 'Status 200 OK does not match 500'

    def _handlewebError(self, msg):
        print('')
        print('    ERROR: %s' % msg)

        if not self.interactive:
>           raise self.failureException(msg)
E           AssertionError: Status 200 OK does not match 500

.tox/py3/lib/python3.6/site-packages/cheroot/test/webtest.py:257: AssertionError
-------------------------------------------------------------- Captured stdout call --------------------------------------------------------------

    ERROR: Status 200 OK does not match 500
-------------------------------------------------------------- Captured stderr call --------------------------------------------------------------
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:3000
DEBUG:urllib3.connectionpool:http://localhost:3000 "GET /api/dashboards/uid/foo HTTP/1.1" 501 496
INFO:cherrypy.access.140271818942672:127.0.0.1 - - [27/Feb/2020:09:14:55] "GET /api/grafana/validation/foo HTTP/1.1" 200 3 "" "" 
--------------------------------------------------------------- Captured log call ----------------------------------------------------------------

It should be ensured that no requests whatsoever are made from the backend that target external URLs.

How to reproduce

  1. Run `python3 -c 'from http import server; s = server.HTTPServer(("", 3000), server.BaseHTTPRequestHandler); s.serve_forever()'` on the host where the unit test will run.
  2. Run the unit test.
  3. Observe stray requests being made, which are relied upon to not respond and hence result in failing tests.
user@work ~ » python3 -c 'from http import server; s = server.HTTPServer(("", 3000), server.BaseHTTPRequestHandler); s.serve_forever()'     130 ↵
127.0.0.1 - - [27/Feb/2020 09:14:55] code 501, message Unsupported method ('POST')
127.0.0.1 - - [27/Feb/2020 09:14:55] "POST /api/dashboards/db HTTP/1.1" 501 -
127.0.0.1 - - [27/Feb/2020 09:14:55] code 501, message Unsupported method ('POST')
127.0.0.1 - - [27/Feb/2020 09:14:55] "POST /api/dashboards/db HTTP/1.1" 501 -
127.0.0.1 - - [27/Feb/2020 09:14:55] code 501, message Unsupported method ('GET')
127.0.0.1 - - [27/Feb/2020 09:14:55] "GET /api/dashboards/uid/foo HTTP/1.1" 501 -
Actions #1

Updated by Patrick Seidensal about 4 years ago

  • Description updated (diff)
Actions #2

Updated by Patrick Seidensal about 4 years ago

  • Description updated (diff)
Actions #3

Updated by Patrick Seidensal about 4 years ago

  • Description updated (diff)
Actions #4

Updated by Patrick Seidensal about 4 years ago

  • Status changed from In Progress to Fix Under Review
  • Pull request ID set to 33572
Actions #5

Updated by Lenz Grimmer about 4 years ago

  • Status changed from Fix Under Review to Resolved
  • Target version set to v15.0.0
Actions #6

Updated by Ernesto Puerta about 3 years ago

  • Project changed from mgr to Dashboard
  • Category changed from 151 to Testing & QA
Actions

Also available in: Atom PDF