Merge "Use keystoneauth1 config option loading for masakari client"
This commit is contained in:
commit
a34ddd216e
@ -39,8 +39,9 @@ monitor_api_opts = [
|
|||||||
def register_opts(conf):
|
def register_opts(conf):
|
||||||
conf.register_group(api_group)
|
conf.register_group(api_group)
|
||||||
conf.register_opts(monitor_api_opts, group=api_group)
|
conf.register_opts(monitor_api_opts, group=api_group)
|
||||||
conf.register_opts(ks_loading.get_auth_plugin_conf_options('password'),
|
ks_loading.register_session_conf_options(conf, api_group)
|
||||||
group=api_group)
|
ks_loading.register_auth_conf_options(conf, api_group)
|
||||||
|
conf.set_default('auth_type', 'password', group=api_group)
|
||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
|
@ -13,8 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from keystoneauth1.identity.generic import password as ks_password
|
from keystoneauth1 import loading as ks_loading
|
||||||
from keystoneauth1 import session as ks_session
|
|
||||||
from openstack import connection
|
from openstack import connection
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from oslo_log import log as oslo_logging
|
from oslo_log import log as oslo_logging
|
||||||
@ -28,14 +27,9 @@ CONF = masakarimonitors.conf.CONF
|
|||||||
class SendNotification(object):
|
class SendNotification(object):
|
||||||
|
|
||||||
def _make_client(self):
|
def _make_client(self):
|
||||||
auth = ks_password.Password(
|
auth = ks_loading.load_auth_from_conf_options(CONF, 'api')
|
||||||
auth_url=CONF.api.auth_url,
|
session = ks_loading.load_session_from_conf_options(CONF, 'api',
|
||||||
username=CONF.api.username,
|
auth=auth)
|
||||||
password=CONF.api.password,
|
|
||||||
user_domain_id=CONF.api.user_domain_id,
|
|
||||||
project_name=CONF.api.project_name,
|
|
||||||
project_domain_id=CONF.api.project_domain_id)
|
|
||||||
session = ks_session.Session(auth=auth)
|
|
||||||
conn = connection.Connection(session=session,
|
conn = connection.Connection(session=session,
|
||||||
interface=CONF.api.api_interface,
|
interface=CONF.api.api_interface,
|
||||||
region_name=CONF.api.region)
|
region_name=CONF.api.region)
|
||||||
|
@ -17,15 +17,17 @@ from unittest import mock
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from keystoneauth1.identity.generic import password as ks_password
|
from keystoneauth1 import loading as ks_loading
|
||||||
from keystoneauth1 import session as ks_session
|
|
||||||
from openstack import connection
|
from openstack import connection
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.ha import masakari
|
from masakarimonitors.ha import masakari
|
||||||
from masakarimonitors.objects import event_constants as ec
|
from masakarimonitors.objects import event_constants as ec
|
||||||
|
|
||||||
|
CONF = masakarimonitors.conf.CONF
|
||||||
|
|
||||||
PROFILE_TYPE = "ha"
|
PROFILE_TYPE = "ha"
|
||||||
PROFILE_NAME = "masakari"
|
PROFILE_NAME = "masakari"
|
||||||
|
|
||||||
@ -60,10 +62,10 @@ class TestSendNotification(testtools.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@mock.patch.object(connection, 'Connection')
|
@mock.patch.object(connection, 'Connection')
|
||||||
@mock.patch.object(ks_session, 'Session')
|
@mock.patch.object(ks_loading, 'load_session_from_conf_options')
|
||||||
@mock.patch.object(ks_password, 'Password')
|
@mock.patch.object(ks_loading, 'load_auth_from_conf_options')
|
||||||
def test_send_notification(
|
def test_send_notification(
|
||||||
self, mock_password, mock_session, mock_connection):
|
self, mock_auth, mock_session, mock_connection):
|
||||||
|
|
||||||
mock_conn = mock.Mock()
|
mock_conn = mock.Mock()
|
||||||
mock_conn.instance_ha.return_value = mock.Mock()
|
mock_conn.instance_ha.return_value = mock.Mock()
|
||||||
@ -80,11 +82,15 @@ class TestSendNotification(testtools.TestCase):
|
|||||||
generated_time=self.event['notification']['generated_time'],
|
generated_time=self.event['notification']['generated_time'],
|
||||||
payload=self.event['notification']['payload'])
|
payload=self.event['notification']['payload'])
|
||||||
|
|
||||||
|
mock_auth.assert_called_once_with(CONF, 'api')
|
||||||
|
mock_session.assert_called_once_with(CONF, 'api',
|
||||||
|
auth=mock_auth.return_value)
|
||||||
|
|
||||||
@mock.patch.object(connection, 'Connection')
|
@mock.patch.object(connection, 'Connection')
|
||||||
@mock.patch.object(ks_session, 'Session')
|
@mock.patch.object(ks_loading, 'load_session_from_conf_options')
|
||||||
@mock.patch.object(ks_password, 'Password')
|
@mock.patch.object(ks_loading, 'load_auth_from_conf_options')
|
||||||
def test_send_notification_409_error(
|
def test_send_notification_409_error(
|
||||||
self, mock_password, mock_session, mock_connection):
|
self, mock_auth, mock_session, mock_connection):
|
||||||
|
|
||||||
mock_conn = mock.Mock()
|
mock_conn = mock.Mock()
|
||||||
mock_conn.instance_ha.return_value = mock.Mock()
|
mock_conn.instance_ha.return_value = mock.Mock()
|
||||||
@ -113,10 +119,10 @@ class TestSendNotification(testtools.TestCase):
|
|||||||
|
|
||||||
@mock.patch.object(eventlet.greenthread, 'sleep')
|
@mock.patch.object(eventlet.greenthread, 'sleep')
|
||||||
@mock.patch.object(connection, 'Connection')
|
@mock.patch.object(connection, 'Connection')
|
||||||
@mock.patch.object(ks_session, 'Session')
|
@mock.patch.object(ks_loading, 'load_session_from_conf_options')
|
||||||
@mock.patch.object(ks_password, 'Password')
|
@mock.patch.object(ks_loading, 'load_auth_from_conf_options')
|
||||||
def test_send_notification_500_error(
|
def test_send_notification_500_error(
|
||||||
self, mock_password, mock_session, mock_connection, mock_sleep):
|
self, mock_auth, mock_session, mock_connection, mock_sleep):
|
||||||
|
|
||||||
mock_conn = mock.Mock()
|
mock_conn = mock.Mock()
|
||||||
mock_conn.instance_ha.return_value = mock.Mock()
|
mock_conn.instance_ha.return_value = mock.Mock()
|
||||||
|
Loading…
Reference in New Issue
Block a user