[Test] Add test for simple app based on rally api

* Add functional test for simple app
  based on rally api

Change-Id: I9044805507b83639c7f75fe844997359486269c1
This commit is contained in:
Anton Studenov 2017-01-19 13:23:01 +03:00
parent da46a90971
commit ae49377418
3 changed files with 62 additions and 0 deletions

30
tests/ci/rally_app.py Normal file
View File

@ -0,0 +1,30 @@
# Copyright 2016: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Simple app based on rally api for testing porpuses"""
import sys
from rally import api as rapi
def main():
api = rapi.API(config_args=sys.argv[1:])
print(len(api.task.list()))
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@ -0,0 +1,30 @@
# Copyright 2016: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import subprocess
import unittest
from tests.functional import utils
class LibAPITestCase(unittest.TestCase):
def test_rally_lib(self):
rally = utils.Rally(force_new_db=True)
cdir = os.path.dirname(os.path.realpath(__file__))
app = os.path.join(cdir, "../ci/rally_app.py")
subprocess.check_output(
["python", app, "--config-file", rally.config_filename])

View File

@ -86,6 +86,7 @@ class Rally(object):
self.tmp_dir = tempfile.mkdtemp()
self.env = copy.deepcopy(os.environ)
self.env["HOME"] = self.tmp_dir
self.config_filename = None
if force_new_db or ("RCI_KEEP_DB" not in os.environ):
config_filename = os.path.join(self.tmp_dir, "conf")
@ -98,6 +99,7 @@ class Rally(object):
self.args = ["rally", "--config-file", config_filename]
subprocess.call(["rally-manage", "--config-file", config_filename,
"db", "recreate"], env=self.env)
self.config_filename = config_filename
else:
self.args = ["rally"]
subprocess.call(["rally-manage", "db", "recreate"], env=self.env)