Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
e2e: Changes to get behave tests to at least run.
Browse files Browse the repository at this point in the history
Tailoring the test suite for use with the Vagrant environment.
  • Loading branch information
mbarnes authored and ashcrow committed Dec 13, 2016
1 parent 9c91fdb commit 2710e22
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
2 changes: 0 additions & 2 deletions features/cluster/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ Feature: Creating A Cluster
when we create a cluster without type named multigrain
then commissaire will allow access
and commissaire will note creation
and the cluster multigrain will have the default type

@recreate
Scenario: Recreating a compatible cluster with authentication and no type
Given we have a valid username and password
when we create a cluster without type named multigrain
then commissaire will allow access
and commissaire will note creation
and the cluster multigrain will have the default type
5 changes: 2 additions & 3 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@

DEFAULT_COMMISSAIRE_SERVER_ARGS = [
'--authentication-plugin',
'commissaire_http.authentication.httpbasicauth',
'--authentication-plugin-kwargs',
'filepath=conf/users.json'
'commissaire_http.authentication.httpbasicauth:'
'filepath=../commissaire-http/conf/users.json',
]


Expand Down
53 changes: 21 additions & 32 deletions features/steps/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import json
import requests
import sys

from behave import *

Expand All @@ -28,26 +29,24 @@
@given('we have a cluster named {cluster}')
def impl(context, cluster):
request = requests.put(
context.SERVER + '/api/v0/cluster/{0}'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}'.format(cluster),
auth=(VALID_USERNAME, VALID_PASSWORD),
data=json.dumps({
'type': C.CLUSTER_TYPE_HOST,
'network': 'default'}))
data={})
assert_status_code(request.status_code, 201)


@given('we have added host {host} to cluster {cluster}')
def impl(context, host, cluster):
request = requests.put(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(request.status_code, 200)


@given('we have removed host {host} from cluster {cluster}')
def impl(context, host, cluster):
request = requests.delete(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(request.status_code, 200)

Expand All @@ -56,7 +55,7 @@ def impl(context, host, cluster):
def impl(context, host, cluster):
context.cluster = cluster
context.request = requests.get(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=context.auth)


Expand All @@ -65,31 +64,31 @@ def impl(context, host, cluster):
def impl(context, host, cluster):
context.cluster = cluster
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=context.auth)


@when('we remove host {host} from the cluster {cluster}')
def impl(context, host, cluster):
context.cluster = cluster
context.request = requests.delete(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=context.auth)


@when('we set the host list for cluster {cluster} to {json}')
def impl(context, cluster, json):
context.cluster = cluster
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}/hosts'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts'.format(cluster),
json=eval(json),
auth=context.auth)


@when('we create a cluster without type named {cluster}')
def impl(context, cluster):
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}'.format(cluster),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(context.request.status_code, 201)

Expand All @@ -99,20 +98,20 @@ def impl(context, operation, cluster):
context.cluster = cluster
if operation == 'get':
context.request = requests.get(
context.SERVER + '/api/v0/cluster/{0}'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}'.format(cluster),
auth=context.auth)
elif operation == 'create':
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}'.format(cluster),
auth=context.auth,
data=json.dumps({'type': C.CLUSTER_TYPE_HOST}))
data={})
elif operation == 'delete':
context.request = requests.delete(
context.SERVER + '/api/v0/cluster/{0}'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}'.format(cluster),
auth=context.auth)
elif operation == 'get hosts in':
context.request = requests.get(
context.SERVER + '/api/v0/cluster/{0}/hosts'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts'.format(cluster),
auth=context.auth)
else:
raise NotImplementedError
Expand All @@ -123,15 +122,15 @@ def impl(context, async_operation, cluster):
context.cluster = cluster
if async_operation == 'an upgrade':
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}/upgrade'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}/upgrade'.format(cluster),
auth=context.auth)
elif async_operation == 'a restart':
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}/restart'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}/restart'.format(cluster),
auth=context.auth)
elif async_operation == 'a tree deployment':
context.request = requests.put(
context.SERVER + '/api/v0/cluster/{0}/deploy'.format(cluster),
context.SERVER_HTTP + '/api/v0/cluster/{0}/deploy'.format(cluster),
auth=context.auth,
data=json.dumps({'version': '1.2.3'}))
else:
Expand All @@ -141,7 +140,7 @@ def impl(context, async_operation, cluster):
@when('we list all clusters')
def impl(context):
context.request = requests.get(
context.SERVER + '/api/v0/clusters', auth=context.auth)
context.SERVER_HTTP + '/api/v0/clusters', auth=context.auth)


@then('the provided cluster status is {status}')
Expand All @@ -162,29 +161,19 @@ def impl(context, what, expected):
@then('the host {host} will be in the cluster {cluster}')
def impl(context, host, cluster):
request = requests.get(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(request.status_code, 200)


@then('the host {host} will not be in the cluster {cluster}')
def impl(context, host, cluster):
request = requests.get(
context.SERVER + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
context.SERVER_HTTP + '/api/v0/cluster/{0}/hosts/{1}'.format(cluster, host),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(request.status_code, 404)


@then('the cluster {cluster} will have the default type')
def impl(context, cluster):
context.request = requests.get(
context.SERVER + '/api/v0/cluster/{0}'.format(cluster),
auth=(VALID_USERNAME, VALID_PASSWORD))
cluster_type = context.request.json()['type']
assert cluster_type == C.CLUSTER_TYPE_DEFAULT, \
'Expected {0}, got {1}'.format(C.CLUSTER_TYPE_DEFAULT, cluster_type)


@then('commissaire will provide {async_operation} status')
def impl(context, async_operation):
json_data = context.request.json()
Expand Down
18 changes: 9 additions & 9 deletions features/steps/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def impl(context, host):
data = dict(context.HOST_DATA)
data['address'] = host
request = requests.put(
context.SERVER + '/api/v0/host/{0}'.format(host),
context.SERVER_HTTP + '/api/v0/host/{0}'.format(host),
auth=(VALID_USERNAME, VALID_PASSWORD),
data=json.dumps(data))
assert_status_code(request.status_code, 201)
Expand All @@ -61,7 +61,7 @@ def impl(context, host):
while status_is_busy:
time.sleep(1)
request = requests.get(
context.SERVER + '/api/v0/host/{0}'.format(host),
context.SERVER_HTTP + '/api/v0/host/{0}'.format(host),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(request.status_code, 200)
data = request.json()
Expand All @@ -71,23 +71,23 @@ def impl(context, host):
@given('we have deleted host {host}')
def impl(context, host):
request = requests.delete(
context.SERVER + '/api/v0/host/{0}'.format(host),
context.SERVER_HTTP + '/api/v0/host/{0}'.format(host),
auth=(VALID_USERNAME, VALID_PASSWORD))
assert_status_code(request.status_code, 200)


@when('we list all hosts')
def impl(context):
context.request = requests.get(
context.SERVER + '/api/v0/hosts',
context.SERVER_HTTP + '/api/v0/hosts',
auth=(context.username, context.password))


@when('we get host status for {host}')
def impl(context, host):
context.host = host
context.request = requests.get(
context.SERVER + '/api/v0/host/{0}/status'.format(context.host),
context.SERVER_HTTP + '/api/v0/host/{0}/status'.format(context.host),
auth=context.auth)


Expand All @@ -96,25 +96,25 @@ def impl(context, operation, host):
context.host = host
if operation == 'get':
context.request = requests.get(
context.SERVER + '/api/v0/host/{0}'.format(context.host),
context.SERVER_HTTP + '/api/v0/host/{0}'.format(context.host),
auth=context.auth)
elif operation == 'create':
context.HOST_DATA['address'] = context.host
context.request = requests.put(
context.SERVER + '/api/v0/host/{0}'.format(context.host),
context.SERVER_HTTP + '/api/v0/host/{0}'.format(context.host),
data=json.dumps(context.HOST_DATA),
auth=context.auth)
elif operation == 'delete':
context.request = requests.delete(
context.SERVER + '/api/v0/host/{0}'.format(context.host),
context.SERVER_HTTP + '/api/v0/host/{0}'.format(context.host),
auth=context.auth)


@when('we get host credentials for {host}')
def impl(context, host):
context.host = host
context.request = requests.get(
context.SERVER + '/api/v0/host/{0}/creds'.format(context.host),
context.SERVER_HTTP + '/api/v0/host/{0}/creds'.format(context.host),
auth=context.auth)


Expand Down
6 changes: 3 additions & 3 deletions features/steps/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
@when('we get status')
def impl(context):
verify=False
if context.SERVER.startswith("https"):
if context.SERVER_HTTP.startswith("https"):
verify=os.path.join(context.CERT_DIR, "ca.pem")

try:
context.request = requests.get(
context.SERVER + '/api/v0/status',
context.SERVER_HTTP + '/api/v0/status',
auth=context.auth,
verify=verify,
cert=getattr(context, "cert", None))
except SSLError, e:
except SSLError as e:
context.request_ssl_error = e

@then('commissaire will return status')
Expand Down

0 comments on commit 2710e22

Please sign in to comment.