Skip to content

Commit

Permalink
Merge pull request #526 from freyes/user-agent
Browse files Browse the repository at this point in the history
Set user agent.
  • Loading branch information
ajkavanagh authored Jul 13, 2022
2 parents b393baa + c4df9bc commit 93a51a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions unit_tests/test_zaza_utilities_openstack_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ def test_get_nova_session_client(self):
session_mock = mock.MagicMock()
self.patch_object(openstack_provider.novaclient_client, "Client")
openstack_provider.get_nova_session_client(session_mock)
self.Client.assert_called_once_with(2, session=session_mock)
self.Client.assert_called_once_with(
2, session=session_mock, user_agent=openstack_provider.USER_AGENT)
self.Client.reset_mock()
openstack_provider.get_nova_session_client(session_mock, version=2.56)
self.Client.assert_called_once_with(2.56, session=session_mock)
self.Client.assert_called_once_with(
2.56, session=session_mock,
user_agent=openstack_provider.USER_AGENT)

def test__resource_removed(self):
resource_mock = mock.MagicMock()
Expand Down Expand Up @@ -185,7 +188,8 @@ def test_get_keystone_session(self):
"OS_TENANT_NAME": "tenant",
}
openstack_provider.get_keystone_session(_openrc)
self.session.Session.assert_called_once_with(auth=_auth, verify=None)
self.session.Session.assert_called_once_with(
auth=_auth, verify=None, user_agent=openstack_provider.USER_AGENT)

def test_get_keystone_session_tls(self):
self.patch_object(openstack_provider, "session")
Expand All @@ -202,4 +206,5 @@ def test_get_keystone_session_tls(self):
}
openstack_provider.get_keystone_session(_openrc)
self.session.Session.assert_called_once_with(
auth=_auth, verify=_cacert)
auth=_auth, verify=_cacert,
user_agent=openstack_provider.USER_AGENT)
9 changes: 7 additions & 2 deletions zaza/utilities/openstack_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
from novaclient import client as novaclient_client


USER_AGENT = 'zaza'


class MissingOSAthenticationException(Exception):
"""Exception when some data needed to authenticate is missing."""

Expand Down Expand Up @@ -66,7 +69,8 @@ def get_keystone_session(openrc_creds, scope='PROJECT', verify=None):
auth = v2.Password(**keystone_creds)
else:
auth = v3.Password(**keystone_creds)
return session.Session(auth=auth, verify=verify)
return session.Session(auth=auth, verify=verify,
user_agent=USER_AGENT)


def get_ks_creds(cloud_creds, scope='PROJECT'):
Expand Down Expand Up @@ -191,7 +195,8 @@ def get_nova_session_client(session, version=2):
:returns: Authenticated novaclient
:rtype: novaclient.Client object
"""
return novaclient_client.Client(version, session=session)
return novaclient_client.Client(version, session=session,
user_agent=USER_AGENT)


# Manage resources
Expand Down

0 comments on commit 93a51a8

Please sign in to comment.