Testing: autonomous resource testing draft

This commit is contained in:
Przemyslaw Kaminski 2015-06-30 15:28:40 +02:00
parent 260ce1ee97
commit 0b70384bc8
8 changed files with 121 additions and 34 deletions

View File

@ -8,6 +8,7 @@ from solar.core import actions
from solar.core import virtual_resource as vr
from solar.core import resource
from solar.core import signals
from solar.core import testing
from solar.interfaces.db import get_db
from solar.core.resource_provider import GitProvider, RemoteZipProvider
@ -224,39 +225,42 @@ def deploy():
time.sleep(10)
# test working configuration
requests.get('http://%s:%s' % (keystone_service1.args['ip'].value, keystone_service1.args['port'].value))
requests.get('http://%s:%s' % (keystone_service2.args['ip'].value, keystone_service2.args['port'].value))
requests.get('http://%s:%s' % (haproxy_service.args['ip'].value, haproxy_service.args['ports'].value[0]['value'][0]['value']))
testing.test_all()
# requests.get('http://%s:%s' % (keystone_service1.args['ip'].value, keystone_service1.args['port'].value))
# requests.get('http://%s:%s' % (keystone_service2.args['ip'].value, keystone_service2.args['port'].value))
# requests.get('http://%s:%s' % (haproxy_service.args['ip'].value, haproxy_service.args['ports'].value[0]['value'][0]['value']))
#
# token_data = requests.post(
# 'http://%s:%s/v2.0/tokens' % (haproxy_service.args['ip'].value, haproxy_keystone_config.args['listen_port'].value),
# json.dumps({
# 'auth': {
# 'tenantName': glance_keystone_user.args['tenant_name'].value,
# 'passwordCredentials': {
# 'username': glance_keystone_user.args['user_name'].value,
# 'password': glance_keystone_user.args['user_password'].value,
# }
# }
# }),
# headers={'Content-Type': 'application/json'}
# )
#
# token = token_data.json()['access']['token']['id']
# print 'TOKEN: {}'.format(token)
token_data = requests.post(
'http://%s:%s/v2.0/tokens' % (haproxy_service.args['ip'].value, haproxy_keystone_config.args['listen_port'].value),
json.dumps({
'auth': {
'tenantName': glance_keystone_user.args['tenant_name'].value,
'passwordCredentials': {
'username': glance_keystone_user.args['user_name'].value,
'password': glance_keystone_user.args['user_password'].value,
}
}
}),
headers={'Content-Type': 'application/json'}
)
# requests.get('http://%s:%s' % (rabbitmq_service1.args['ip'].value, rabbitmq_service1.args['management_port'].value))
token = token_data.json()['access']['token']['id']
print 'TOKEN: {}'.format(token)
# images = requests.get(
# 'http://%s:%s/v1/images' % (glance_api_container.args['ip'].value, haproxy_glance_api_config.args['listen_port'].value),
# headers={'X-Auth-Token': token}
# )
# assert images.json() == {'images': []}
requests.get('http://%s:%s' % (rabbitmq_service1.args['ip'].value, rabbitmq_service1.args['management_port'].value))
images = requests.get(
'http://%s:%s/v1/images' % (glance_api_container.args['ip'].value, haproxy_glance_api_config.args['listen_port'].value),
headers={'X-Auth-Token': token}
)
assert images.json() == {'images': []}
images = requests.get(
'http://%s:%s' % (glance_registry_container.args['ip'].value, glance_registry_container.args['ports'].value[0]['value'][0]['value']),
headers={'X-Auth-Token': token}
)
assert images.json() == {'images': []}
# TODO
# images = requests.get(
# 'http://%s:%s' % (glance_registry_container.args['ip'].value, glance_registry_container.args['ports'].value[0]['value'][0]['value']),
# headers={'X-Auth-Token': token}
# )
# assert images.json() == {'images': []}
@click.command()

View File

@ -0,0 +1,28 @@
import json
import requests
def test(resource):
print 'Testing glance_service'
token_data = requests.post(
'http://%s:%s/v2.0/tokens' % (resource.args['ip'].value, resource.args['listen_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'}
)
token = token_data.json()['access']['token']['id']
print 'GLANCE TOKEN: {}'.format(token)
images = requests.get(
'http://%s:%s/v1/images' % (resource.args['ip'].value, resource.args['listen_port'].value),
headers={'X-Auth-Token': token}
)
assert images.json() == {'images': []}

View File

@ -0,0 +1,8 @@
import requests
def test(resource):
print 'Testing haproxy_service'
requests.get(
'http://%s:%s' % (resource.args['ip'].value, resource.args['ports'].value[0]['value'][0]['value'])
)

View File

@ -0,0 +1,8 @@
import requests
def test(resource):
print 'Testing keystone_service'
requests.get(
'http://%s:%s' % (resource.args['ip'].value, resource.args['port'].value)
)

View File

@ -0,0 +1,7 @@
import requests
def test(resource):
print 'Testing rabbitmq_service'
requests.get('http://%s:%s' % (resource.args['ip'].value, resource.args['management_port'].value))

View File

@ -34,6 +34,7 @@ from solar.core.resource import assign_resources_to_nodes
from solar.core import signals
from solar.core.tags_set_parser import Expression
from solar.core import virtual_resource as vr
from solar.core import testing
from solar.interfaces.db import get_db
# NOTE: these are extensions, they shouldn't be imported here
@ -158,6 +159,10 @@ def init_changes():
elif uid:
click.echo(operations.rollback_uid(uid))
@changes.command()
def test():
testing.test_all()
def init_cli_connect():
@main.command()

View File

@ -0,0 +1,31 @@
import imp
import networkx as nx
import os
from solar.core import resource
from solar.core import signals
def test_all():
conn_graph = signals.detailed_connection_graph()
srt = nx.topological_sort(conn_graph)
for name in srt:
print 'Trying {}'.format(name)
r = resource.load(name)
script_path = os.path.join(r.metadata['base_path'], 'test.py')
if not os.path.exists(script_path):
continue
print 'File {} found'.format(script_path)
with open(script_path) as f:
module = imp.load_module(
'{}_test'.format(name),
f,
script_path,
('', 'r', imp.PY_SOURCE)
)
module.test(r)

View File

@ -62,8 +62,6 @@ def create_diff(staged, commited):
def _stage_changes(staged_resources, conn_graph,
commited_resources, staged_log):
action = None
try:
srt = nx.topological_sort(conn_graph)
except:
@ -195,5 +193,3 @@ def rollback_all():
while cl:
rollback(cl.pop())