Simplify integration tests configuration

- Make it more OpenStack-aligned
This commit is contained in:
Denis Makogon 2016-11-23 00:31:07 +02:00
parent 15710f6cd4
commit 207bc86f3e
3 changed files with 74 additions and 79 deletions

View File

@ -190,66 +190,20 @@ Testing: Integration
Integration tests are dependent on following env variables:
* TEST_DB_URI - similar to functional tests, database endpoint
* FUNCTIONS_HOST - IronFunctions API host
* FUNCTIONS_PORT - IronFunctions API port
* FUNCTIONS_API_PROTO - IronFunctions API protocol
* FUNCTIONS_API_VERSION - IronFunctions API version
* FUNCTIONS_API_URL - IronFunctions API URL (default value - `http://localhost:8080/v1`)
* OS_AUTH_URL - OpenStack Identity endpoint
* OS_PROJECT_ID - OpenStack user-specific project ID
* OS_TOKEN - OpenStack user project-bound auth token
How to get token? - Set env variables:
* OS_USERNAME
* OS_PASSWORD
* OS_PROJECT_NAME
and run following command:
echo -e "{
\"auth\": {
\"identity\": {
\"methods\": [\"password\"],
\"password\": {
\"user\": {
\"name\": \"${OS_USERNAME:-admin}\",
\"domain\": { \"id\": \"${OS_DOMAIN:-default}\" },
\"password\": \"${OS_PASSWORD:-root}\"
}
}
},
\"scope\": {
\"project\": {
\"name\": \"${OS_PROJECT_NAME:-admin}\",
\"domain\": {\"id\": \"${OS_DOMAIN:-default}\" }
}
}
}
}" >> token_request.json
After that:
export OS_TOKEN=`curl -si -d @token_request.json -H "Content-type: application/json" ${OS_AUTH_URL}/auth/tokens | awk '/X-Subject-Token/ {print $2}'`
If variable remains empty, please check your authentication parameters specified in `token_request.json`.
How to get project ID? - Use following command
export RAW_PrID=`curl -si -d @token_request.json -H "Content-type: application/json" ${OS_AUTH_URL}/auth/tokens | grep Default | awk '{print $20}'`
export OS_PROJECT_ID=${RAW_PrID:1:-2}
If variable remains empty, please check your authentication parameters specified in `token_request.json`.
* OS_PROJECT_NAME - OpenStack user-specific project name
* OS_USERNAME - OpenStack user name
* OS_PASSWORD - OpenStack user user password
To run tests use following command:
export TEST_DB_URI=mysql://<your-user>:<your-user-password>@<mysql-host>:<mysql-port>/<functions-db>
export FUNCTIONS_HOST=<functions-host>
export FUNCTIONS_PORT=<functions-port>
export FUNCTIONS_API_PROTO=<functions-api-protocol>
export FUNCTIONS_API_VERSION=<functions-api-version>
export OS_AUTH_URL=<openstack-idenitity-url>
export OS_PROJECT_ID=<project-id>
export OS_TOKEN=<project-bound-auth-token>
export FUNCTIONS_API_URL=<functions-api-protocol>://<functions-host>:<functions-port>/<functions-api-version>
export OS_AUTH_URL=<identity-api-protocol>://<identity-host>:<identity-port>/<identity-api-version>
export OS_PROJECT_NAME=<project-name>
export OS_USERNAME=<project-name>
export OS_PASSWORD=<project-name>
tox -epy35-integration
Testing: Coverage regression
@ -271,10 +225,6 @@ IronFunctions:
* https://github.com/iron-io/functions/issues/275
* https://github.com/iron-io/functions/issues/274
aiohttp_swagger:
* https://github.com/cr0hn/aiohttp-swagger/issues/12 ([fix proposed](https://github.com/cr0hn/aiohttp-swagger/pull/13))
TODOs
-----

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import aiohttp
import json
import os
import testtools
@ -21,35 +23,75 @@ from laos.service import laos_api
from laos.tests.common import base
from laos.tests.common import client
from urllib import parse
class LaosIntegrationTestsBase(base.LaosTestsBase, testtools.TestCase):
async def authenticate(self, os_user, os_pass, os_project, url):
auth_request_data = {
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": os_user,
"domain": {"id": "default"},
"password": os_pass
}
}
},
"scope": {
"project": {
"name": os_project,
"domain": {"id": "default"}
}
}
}
}
with aiohttp.ClientSession(loop=self.testloop) as session:
response = await session.post(
"{}/auth/tokens".format(url),
data=json.dumps(auth_request_data),
headers={
"Content-Type": "application/json"
},
timeout=20)
response.raise_for_status()
result = await response.json()
return (response.headers["X-Subject-Token"],
result["token"]["project"]["id"])
def setUp(self):
self.testloop, logger = self.get_loop_and_logger("integration")
(functions_host, functions_port,
functions_api_protocol,
functions_api_version, db_uri,
keystone_endpoint, project_id, os_token) = (
os.getenv("FUNCTIONS_HOST"), os.getenv("FUNCTIONS_PORT", 8080),
os.getenv("FUNCTIONS_API_PROTO", "http"),
os.getenv("FUNCTIONS_API_VERSION", "v1"), os.getenv("TEST_DB_URI"),
os.getenv("OS_AUTH_URL"), os.getenv("OS_PROJECT_ID"),
os.getenv("OS_TOKEN"),
(functions_url, db_uri,
os_auth_url, os_user, os_pass, os_project) = (
os.getenv("FUNCTIONS_API_URL", "http://localhost:8080/v1"),
os.getenv("TEST_DB_URI"),
os.getenv("OS_AUTH_URL"),
os.getenv("OS_USERNAME"),
os.getenv("OS_PASSWORD"),
os.getenv("OS_PROJECT_NAME"),
)
if not all([db_uri, os_auth_url, os_user, os_pass, os_project]):
raise self.skipTest("Not all test env variables were set.")
parts = parse.urlparse(functions_url)
fnclient = config.FunctionsClient(
functions_host,
api_port=functions_port,
api_protocol=functions_api_protocol,
api_version=functions_api_version,
parts.hostname,
api_port=parts.port,
api_protocol=parts.scheme,
api_version=parts.path[1:]
)
self.testloop.run_until_complete(fnclient.ping(loop=self.testloop))
connection_pool = config.Connection(db_uri, loop=self.testloop)
config.Config(
auth_url=keystone_endpoint,
auth_url=os_auth_url,
functions_client=fnclient,
logger=logger,
connection=connection_pool,
@ -59,6 +101,11 @@ class LaosIntegrationTestsBase(base.LaosTestsBase, testtools.TestCase):
self.test_app = laos_api.API(
loop=self.testloop, logger=logger, debug=True)
os_token, project_id = self.testloop.run_until_complete(
self.authenticate(
os_user, os_pass,
os_project, os_auth_url))
self.test_client = client.ProjectBoundLaosTestClient(
self.test_app.root, project_id, headers={
"X-Auth-Token": os_token

10
tox.ini
View File

@ -9,13 +9,11 @@ skipsdist = True
passenv =
PYTHONASYNCIODEBUG
TEST_DB_URI
FUNCTIONS_HOST
FUNCTIONS_PORT
FUNCTIONS_API_PROTO
FUNCTIONS_API_VERSION
FUNCTIONS_API_URL
OS_AUTH_URL
OS_PROJECT_ID
OS_TOKEN
OS_PASSWORD
OS_USERNAME
OS_PROJECT_NAME
setenv = VIRTUAL_ENV={envdir}
usedevelop = True
install_command = pip install -U {opts} {packages}