示例#1
0
    def setUp(self):
        self.credentials = {
            'username': '******',
            'password': '******',
            'auth_url': 'http://127.0.0.1:5000/v2',
            'tenant_name': 'some_tenant'
        }

        self.keystone = KeystoneClient(**self.credentials)
示例#2
0
class TestKeystoneClient(base.BaseTestCase):

    token = {'access': {'token': {'id': 'auth_token'}}}

    def setUp(self):
        self.credentials = {
            'username': '******',
            'password': '******',
            'auth_url': 'http://127.0.0.1:5000/v2',
            'tenant_name': 'some_tenant'}

        self.keystone = KeystoneClient(**self.credentials)

    @mock.patch('fuel_upgrade.clients.keystone_client.requests.post')
    @mock.patch('fuel_upgrade.clients.keystone_client.requests.Session')
    def test_makes_authenticated_requests(self, session, post_mock):
        post_mock.return_value.json.return_value = self.token
        self.keystone.request
        session.return_value.headers.update.assert_called_once_with(
            {'X-Auth-Token': 'auth_token'})

    @mock.patch('fuel_upgrade.clients.keystone_client.requests.Session')
    @mock.patch('fuel_upgrade.clients.keystone_client.requests.post',
                side_effect=requests.exceptions.HTTPError(''))
    def test_does_not_fail_without_keystone(self, _, __):
        self.keystone.request
        self.assertEqual(self.keystone.get_token(), None)
示例#3
0
    def setUp(self):
        self.credentials = {
            'username': '******',
            'password': '******',
            'auth_url': 'http://127.0.0.1:5000/v2',
            'tenant_name': 'some_tenant'}

        self.keystone = KeystoneClient(**self.credentials)
示例#4
0
class TestKeystoneClient(base.BaseTestCase):

    token = {'access': {'token': {'id': 'auth_token'}}}

    def setUp(self):
        self.credentials = {
            'username': '******',
            'password': '******',
            'auth_url': 'http://127.0.0.1:5000/v2',
            'tenant_name': 'some_tenant'
        }

        self.keystone = KeystoneClient(**self.credentials)

    @mock.patch('fuel_upgrade.clients.keystone_client.requests.post')
    @mock.patch('fuel_upgrade.clients.keystone_client.requests.Session')
    def test_makes_authenticated_requests(self, session, post_mock):
        post_mock.return_value.json.return_value = self.token
        self.keystone.request
        session.return_value.headers.update.assert_called_once_with(
            {'X-Auth-Token': 'auth_token'})

    @mock.patch('fuel_upgrade.clients.keystone_client.requests.Session')
    @mock.patch('fuel_upgrade.clients.keystone_client.requests.post',
                side_effect=requests.exceptions.HTTPError(''))
    def test_does_not_fail_without_keystone(self, _, __):
        with mock.patch('fuel_upgrade.utils.time.time') as time:
            # Unfortunately, in Python 2.6 the itertools.count() doesn't
            # support the step argument, so we need to implement our own
            # bicycle.
            def timestamp(start, step):
                x = start
                while True:
                    yield x
                    x += step

            # We need such infinity generator, because time.time() is used
            # by our loggers, so we can't predict how often it will be called.
            time.side_effect = timestamp(0, 15)

            self.keystone.request
            self.assertEqual(self.keystone.get_token(), None)
class TestKeystoneClient(base.BaseTestCase):

    token = {'access': {'token': {'id': 'auth_token'}}}

    def setUp(self):
        self.credentials = {
            'username': '******',
            'password': '******',
            'auth_url': 'http://127.0.0.1:5000/v2',
            'tenant_name': 'some_tenant'}

        self.keystone = KeystoneClient(**self.credentials)

    @mock.patch('fuel_upgrade.clients.keystone_client.requests.post')
    @mock.patch('fuel_upgrade.clients.keystone_client.requests.Session')
    def test_makes_authenticated_requests(self, session, post_mock):
        post_mock.return_value.json.return_value = self.token
        self.keystone.request
        session.return_value.headers.update.assert_called_once_with(
            {'X-Auth-Token': 'auth_token'})

    @mock.patch('fuel_upgrade.clients.keystone_client.requests.Session')
    @mock.patch('fuel_upgrade.clients.keystone_client.requests.post',
                side_effect=requests.exceptions.HTTPError(''))
    def test_does_not_fail_without_keystone(self, _, __):
        with mock.patch('fuel_upgrade.utils.time.time') as time:
            # Unfortunately, in Python 2.6 the itertools.count() doesn't
            # support the step argument, so we need to implement our own
            # bicycle.
            def timestamp(start, step):
                x = start
                while True:
                    yield x
                    x += step

            # We need such infinity generator, because time.time() is used
            # by our loggers, so we can't predict how often it will be called.
            time.side_effect = timestamp(0, 15)

            self.keystone.request
            self.assertEqual(self.keystone.get_token(), None)
示例#6
0
 def __init__(self, host=None, port=None, keystone_credentials={}):
     #: an url to nailgun's restapi service
     self.api_url = self.api_url.format(host=host, port=port)
     #: keystone credentials for authentification
     self.keystone_client = KeystoneClient(**keystone_credentials)