#95 Support authentication for ResultsDB result reporting (#92)
Merged 2 years ago by adamwill. Opened 2 years ago by adamwill.

file modified
+1 -1
@@ -3,6 +3,6 @@ 

  openqa-client>=1.1

  setuptools

  six

- resultsdb_api

+ resultsdb_api>=2.1.5

  resultsdb_conventions>=2.1.0

  wikitcms

@@ -14,6 +14,11 @@ 

  [report]

  # URL of ResultsDB instance to report to

  resultsdb_url: http://localhost/resultsdb_api/api/v2.0/

+ # Username to use for ResultsDB authentication if any

+ resultsdb_user: someuser

+ # Password to use for ResultsDB authentication if any

+ # If both user and password are set, authentication will be enabled

+ resultsdb_password: somepass

  

  # Hostname of Fedora wiki to report to

  wiki_hostname: stg.fedoraproject.org

@@ -43,6 +43,8 @@ 

  CONFIG.set('cli', 'log-level', 'info')

  

  CONFIG.set('report', 'resultsdb_url', 'http://localhost:5001/api/v2.0/')

+ CONFIG.set('report', 'resultsdb_user', '')

+ CONFIG.set('report', 'resultsdb_password', '')

  CONFIG.set('report', 'wiki_hostname', 'stg.fedoraproject.org')

  

  CONFIG.set('schedule', 'arches', 'x86_64')

file modified
+7 -2
@@ -34,7 +34,7 @@ 

  import mwclient.errors

  from openqa_client.client import OpenQA_Client

  from openqa_client.const import JOB_SCENARIO_WITH_MACHINE_KEYS

- from resultsdb_api import ResultsDBapi, ResultsDBapiException

+ from resultsdb_api import ResultsDBapi, ResultsDBapiException, ResultsDBAuth

  from resultsdb_conventions.fedora import FedoraImageResult, FedoraComposeResult, FedoraBodhiResult

  from resultsdb_conventions.fedoracoreos import FedoraCoreOSBuildResult, FedoraCoreOSImageResult

  from wikitcms.wiki import Wiki, ResTuple
@@ -370,8 +370,13 @@ 

          resultsdb_url = CONFIG.get('report', 'resultsdb_url')

  

      if do_report:

+         authmethod = None

+         authuser = CONFIG.get("report", "resultsdb_user")

+         authpass = CONFIG.get("report", "resultsdb_password")

+         if authuser and authpass:

+             authmethod = ResultsDBAuth.basic_auth(authuser, authpass)

          try:

-             rdb_instance = ResultsDBapi(resultsdb_url)

+             rdb_instance = ResultsDBapi(resultsdb_url, request_auth=authmethod)

          except ResultsDBapiException as e:

              logger.error(e)

              return

file modified
+20
@@ -425,6 +425,26 @@ 

          scenario = 'fedora.Server-dvd-iso.x86_64.64bit'

          assert fakeres.call_args[1]['scenario'] == scenario

  

+     @mock.patch('fedora_openqa.report.ResultsDBapi')

+     def test_config(self, fakeapi, fakeres, jobdict01):

+         """Check config values (URL, username, password) are used."""

+         testurl = "http://someotherhost:5001/api/v2.0/"

+         testuser = "someuser"

+         testpassword = "somepassword"

+         # first, check non-config case

+         fosreport.resultsdb_report(jobs=[1])

+         assert fakeapi.call_args[0][0] != testurl

+         assert fakeapi.call_args[1]["request_auth"] is None

+         # now, set some config

+         fakeapi.reset_mock()

+         fosreport.CONFIG.set("report", "resultsdb_url", testurl)

+         fosreport.CONFIG.set("report", "resultsdb_user", testuser)

+         fosreport.CONFIG.set("report", "resultsdb_password", testpassword)

+         fosreport.resultsdb_report(jobs=[1])

+         assert fakeapi.call_args[0][0] == testurl

+         assert fakeapi.call_args[1]["request_auth"].username == testuser

+         assert fakeapi.call_args[1]["request_auth"].password == testpassword

+ 

      def test_update(self, fakeres, oqaclientmock, jobdict02):

          """Check report behaviour with an update test job (rather than

          a compose test job).

It's a fairly simple mechanism so this is a fairly simple
implementation. It will require the password to be plain text
in the config file, which I don't love, but hey.

Signed-off-by: Adam Williamson awilliam@redhat.com

@kevin @lrossett this should be what's needed for authenticated reporting of openQA results to resultsdb for now. let me know if you see any issues.

Build succeeded.

rebased onto 98af2f7

2 years ago

Build succeeded.

rebased onto d439c0d

2 years ago

Build succeeded.

rebased onto 4fa3eca

2 years ago

Build succeeded.

Pull-Request has been merged by adamwill

2 years ago