• Icon: Sub-task Sub-task
    • Resolution: Done
    • Icon: Medium Medium
    • Frankfurt Release
    • None
    • sli/plugins
    • None

      All unit tests in dmaap require that the ConsulHandle functions which would make connections to a consul service are mocked.

      However, only tests for consulif and dmaapcontrollerif do this, where the dmaapcontrollerif test actually imports and calls a consulif test to use that test's (mocked) return value further.

      A mockconsul fixture is available to all the tests to achieve the same effect properly.

      A negative consequence of the current setup is that the consulif test must be present, and run beofre other tests, in order to setup the consul mock. I.e., the tests work when run together, but not if run separately: That the tests work at this time is a matter of default test ordering. Compare:

      ccsdk/plugins/dmaap$ PYTHONPATH=$PWD pytest 
      ============================= test session starts ==============================
      platform linux2 -- Python 2.7.15+, pytest-4.6.6, py-1.8.0, pluggy-0.13.0
      rootdir: ccsdk/plugins/dmaap
      collected 7 items                                                              tests/test_consulif.py ..                                                [ 28%]
      tests/test_dmaapcontrollerif.py .                                        [ 42%]
      tests/test_dr_lifecycle.py .                                             [ 57%]
      tests/test_mr_lifecycle.py .                                             [ 71%]
      tests/test_plugin.py .                                                   [ 85%]
      tests/test_utils.py .                                                    [100%]=========================== 7 passed in 0.10 seconds ===========================
      ccsdk/plugins/dmaap$ PYTHONPATH=$PWD pytest tests/test_dr_lifecycle.py 
      ============================= test session starts ==============================
      platform linux2 -- Python 2.7.15+, pytest-4.6.6, py-1.8.0, pluggy-0.13.0
      rootdir: ccsdk/plugins/dmaap
      collected 1 item                                                               tests/test_dr_lifecycle.py F                                             [100%]=================================== FAILURES ===================================
      _______________________________ test_create_feed _______________________________monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f91fb4d4e90>
      mockdmaapbc = None    def test_create_feed(monkeypatch, mockdmaapbc):
      >       import dmaapplugintests/test_dr_lifecycle.py:40: 
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _     from consulif.consulif import ConsulHandle
          from cloudify.exceptions import NonRecoverableError
          import os
          
          os.environ["REQUESTS_CA_BUNDLE"]="/opt/onap/certs/cacert.pem" 	# This is to handle https request thru plugin
          
          CONSUL_HOST = "consul"                      # Should always be a local consul agent on Cloudify Manager
          DBCL_KEY_NAME = "dmaap-plugin"              # Consul key containing DMaaP data bus credentials
          # In the ONAP Kubernetes environment, bus controller address is always "dmaap-bc", on port 8080 (http) and 8443 (https)
          ONAP_SERVICE_ADDRESS = "dmaap-bc"
          HTTP_PORT = "8080"
          HTTPS_PORT = "8443"
          
          try:
              _ch = ConsulHandle("http://{0}:8500".format(CONSUL_HOST), None, None, None)
          except Exception as e:
              raise NonRecoverableError("Error getting ConsulHandle when configuring dmaap plugin: {0}".format(e))
          
          try:
              config = _ch.get_config(DBCL_KEY_NAME)
          except Exception as e:
      >       raise NonRecoverableError("Error getting config for '{0}' from ConsulHandle when configuring dmaap plugin: {1}".format(DBCL_KEY_NAME, e))
      E       NonRecoverableError: Error getting config for 'dmaap-plugin' from ConsulHandle when configuring dmaap plugin: HTTPConnectionPool(host='consul', port=8500): Max retries exceeded with url: /v1/kv/dmaap-plugin (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91fb427890>: Failed to establish a new connection: [Errno -2] Name or service not known',))
       

      The actual error shown is caused by the dmaapplugin package's init, which executes connections to the consul service on module load. That shall be resolved by a related issue.

      A further weakness of the tests is that they unnecessarily wrap the actual error encountered during testing with a NonRecoverableError of their own.

       

            mirlos mirlos
            mirlos mirlos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: