Upgrades, remove keystone client from dependencies

Removed keystone client dependencies to prevent
errors, when fuel client and upgrade script use
different versions.

Also it helps to solve the problem with broken
script because keystone client uses pip as
dependencies.

Change-Id: I16b0a6ecfdc4b4b14eac4441d9f1dbc06fa0c13a
Closes-bug: #1346366
This commit is contained in:
Evgeniy L 2014-07-21 19:57:06 +04:00
parent 9dd5dbd6d1
commit 5ccd70952d
4 changed files with 24 additions and 17 deletions

View File

@ -126,7 +126,7 @@ def get_endpoints(astute_config):
'keystone_credentials': {
'username': fuel_access['user'],
'password': fuel_access['password'],
'auth_url': 'http://{0}:5000/v2.0/'.format(master_ip),
'auth_url': 'http://{0}:5000/v2.0/tokens'.format(master_ip),
'tenant_name': 'admin'}},
'nginx_repo': {

View File

@ -18,9 +18,6 @@ import json
import logging
import requests
from keystoneclient import exceptions
from keystoneclient.v2_0.client import Client as KeystoneClient
logger = logging.getLogger(__name__)
@ -156,9 +153,20 @@ class NailgunClient(object):
return None
try:
keystone_client = KeystoneClient(**self.keystone_credentials)
return keystone_client.auth_token
except exceptions.ClientException as exc:
logger.debug('Cannot initialize keystone client: {0}'.format(exc))
auth_data = self.keystone_credentials
resp = requests.post(
auth_data['auth_url'],
headers={'content-type': 'application/json'},
data=json.dumps({
'auth': {
'tenantName': auth_data['tenant_name'],
'passwordCredentials': {
'username': auth_data['username'],
'password': auth_data['password']}}})).json()
return (isinstance(resp, dict) and
resp.get('access', {}).get('token', {}).get('id'))
except (ValueError, requests.exceptions.RequestException) as exc:
logger.debug('Cannot authenticate in keystone: {0}'.format(exc))
return None

View File

@ -19,7 +19,6 @@ import requests
from fuel_upgrade import nailgun_client
from fuel_upgrade.tests import base
from keystoneclient import exceptions
class TestNailgunClient(base.BaseTestCase):
@ -115,6 +114,8 @@ class TestNailgunClient(base.BaseTestCase):
class TestNailgunClientWithAuthentification(base.BaseTestCase):
token = {'access': {'token': {'id': 'auth_token'}}}
def setUp(self):
self.credentials = {
'username': 'some_user',
@ -127,18 +128,17 @@ class TestNailgunClientWithAuthentification(base.BaseTestCase):
8000,
keystone_credentials=self.credentials)
@mock.patch('fuel_upgrade.nailgun_client.KeystoneClient')
@mock.patch('fuel_upgrade.nailgun_client.requests.post')
@mock.patch('fuel_upgrade.nailgun_client.requests.Session')
def test_makes_authenticated_requests(self, session, keystone):
keystone.return_value.auth_token = 'auth_token'
def test_makes_authenticated_requests(self, session, post_mock):
post_mock.return_value.json.return_value = self.token
self.nailgun.request.get('http://some.url/path')
session.return_value.headers.update.assert_called_once_with(
{'X-Auth-Token': 'auth_token'})
@mock.patch('fuel_upgrade.nailgun_client.requests.Session')
@mock.patch('fuel_upgrade.nailgun_client.KeystoneClient',
side_effect=exceptions.ConnectionError('a'))
def test_does_not_fail_without_keystone(self, keystone, _):
@mock.patch('fuel_upgrade.nailgun_client.requests.post',
side_effect=requests.exceptions.HTTPError(''))
def test_does_not_fail_without_keystone(self, _, __):
self.nailgun.request.get('http://some.url/path')
keystone.assert_called_once_with(**self.credentials)
self.assertEqual(self.nailgun.get_token(), None)

View File

@ -3,7 +3,6 @@ PyYAML==3.10
Mako==0.9.1
requests==2.2.1
six==1.5.2
python-keystoneclient==0.7
# We have to use custom version of docker
# because docker 0.10 changed their api