Add generic token validation function

This commit is contained in:
Przemyslaw Kaminski 2015-08-03 16:22:19 +02:00
parent f33fcf5ebf
commit 24453fd16f
4 changed files with 60 additions and 35 deletions

View File

@ -1,27 +1,21 @@
import json
import requests
from solar.core.log import log
from solar.core import validation
def test(resource):
log.debug('Testing glance_service')
token_data = requests.post(
'http://%s:%s/v2.0/tokens' % (resource.args['ip'].value, resource.args['keystone_port'].value),
json.dumps({
'auth': {
'tenantName': 'services',
'passwordCredentials': {
'username': 'glance_admin',
'password': resource.args['keystone_password'].value,
}
}
}),
headers={'Content-Type': 'application/json'}
)
token = token_data.json()['access']['token']['id']
log.debug('GLANCE TOKEN: %s', token)
args = resource.args
token = validation.validate_token(
keystone_host=args['keystone_host'].value,
keystone_port=args['keystone_port'].value,
user='glance_admin',
tenant='services',
password=args['keystone_password'].value,
)
images = requests.get(
'http://%s:%s/v1/images' % (resource.args['ip'].value, 9393),

View File

@ -1,11 +1,22 @@
import requests
from solar.core.log import log
from solar.core import validation
def test(resource):
log.debug('Testing glance_puppet')
requests.get(
'http://%s:%s' % (resource.args['ip'].value, resource.args['port'].value)
'http://%s:%s' % (resource.args['ip'].value, resource.args['bind_port'].value)
)
#TODO(bogdando) test packages installed and filesystem store datadir created
args = resource.args
token = validation.validate_token(
keystone_host=args['keystone_host'].value,
keystone_port=args['keystone_port'].value,
user=args['keystone_user'].value,
tenant=args['keystone_tenant'].value,
password=args['keystone_password'].value,
)

View File

@ -1,27 +1,18 @@
import json
import requests
from solar.core.log import log
from solar.core import validation
def test(resource):
log.debug('Testing keystone_user %s', resource.args['user_name'].value)
token_data = requests.post(
'http://%s:%s/v2.0/tokens' % (resource.args['keystone_host'].value,
resource.args['keystone_port'].value),
json.dumps({
'auth': {
'tenantName': resource.args['tenant_name'].value,
'passwordCredentials': {
'username': resource.args['user_name'].value,
'password': resource.args['user_password'].value,
},
},
}),
headers={'Content-Type': 'application/json'}
args = resource.args
token = validation.validate_token(
keystone_host=args['keystone_host'].value,
keystone_port=args['keystone_port'].value,
user=args['user_name'].value,
tenant=args['tenant_name'].value,
password=args['user_password'].value,
)
token = token_data.json()['access']['token']['id']
log.debug('%s TOKEN: %s', resource.args['user_name'].value, token)

View File

@ -41,7 +41,9 @@ mount_points:
minLength: 1
"""
import json
from jsonschema import validate, ValidationError
import requests
from solar.core.log import log
@ -164,3 +166,30 @@ def validate_resource(r):
ret[input_name] = errors
return ret
def validate_token(
keystone_host=None,
keystone_port=None,
user=None,
tenant=None,
password=None):
token_data = requests.post(
'http://%s:%s/v2.0/tokens' % (keystone_host, keystone_port),
json.dumps({
'auth': {
'tenantName': tenant,
'passwordCredentials': {
'username': user,
'password': password,
},
},
}),
headers={'Content-Type': 'application/json'}
)
token = token_data.json()['access']['token']['id']
log.debug('%s TOKEN: %s', user, token)
return token