OS access credentials processing added

What is done:
- os access credentials retriving from POST request body on wsgi
  controller for TestRun entity added;
- needed environment variables setting added in nose StoragePlugin;
- settuping process for HealthCheck updated;
- integration tests for ostf adapter updated;
- unit tests also updated;
- change was tested on deployed env.

Change-Id: I96580e4e59db0314a75c27f2dda49cf268b05b95
Closes-Bug: #1281838
This commit is contained in:
Artem Roma 2014-06-25 14:52:18 +03:00
parent 1e8d477597
commit 6f514d3487
11 changed files with 157 additions and 20 deletions

View File

@ -523,9 +523,23 @@ class NailgunConfig(object):
data = response.json()
LOG.info('RESPONSE FROM %s - %s' % (api_url, data))
access_data = data['editable']['access']
self.identity.admin_tenant_name = access_data['tenant']['value']
self.identity.admin_username = access_data['user']['value']
self.identity.admin_password = access_data['password']['value']
self.identity.admin_tenant_name = \
(
os.environ.get('OSTF_OS_TENANT_NAME') or
access_data['tenant']['value']
)
self.identity.admin_username = \
(
os.environ.get('OSTF_OS_USERNAME') or
access_data['user']['value']
)
self.identity.admin_password = \
(
os.environ.get('OSTF_OS_PASSWORD') or
access_data['password']['value']
)
api_url = '/api/clusters/%s' % self.cluster_id
cluster_data = self.req_session.get(self.nailgun_url + api_url).json()
network_provider = cluster_data.get('net_provider', 'nova_network')

View File

@ -40,7 +40,12 @@ class NoseDriver(object):
def __init__(self):
LOG.warning('Initializing Nose Driver')
def run(self, test_run, test_set, dbpath, tests=None):
def run(self, test_run, test_set, dbpath, ostf_os_access_creds=None,
tests=None):
if not ostf_os_access_creds:
ostf_os_access_creds = dict()
tests = tests or test_run.enabled_tests
if tests:
argv_add = [nose_utils.modify_test_name_for_nose(test)
@ -54,10 +59,11 @@ class NoseDriver(object):
dbpath,
test_run.id,
test_run.cluster_id,
ostf_os_access_creds,
argv_add).pid
def _run_tests(self, lock_path, dbpath,
test_run_id, cluster_id, argv_add):
def _run_tests(self, lock_path, dbpath, test_run_id, cluster_id,
ostf_os_access_creds, argv_add):
cleanup_flag = False
def raise_exception_handler(signum, stack_frame):
@ -83,7 +89,9 @@ class NoseDriver(object):
nose_test_runner.SilentTestProgram(
addplugins=[nose_storage_plugin.StoragePlugin(
session, test_run_id, str(cluster_id))],
session, test_run_id, str(cluster_id),
ostf_os_access_creds
)],
exit=False,
argv=['ostf_tests'] + argv_add)

View File

@ -33,10 +33,13 @@ class StoragePlugin(plugins.Plugin):
name = 'storage'
score = 15000
def __init__(self, session, test_run_id, cluster_id):
def __init__(self, session, test_run_id, cluster_id,
ostf_os_access_creds):
self.session = session
self.test_run_id = test_run_id
self.cluster_id = cluster_id
self.ostf_os_access_creds = ostf_os_access_creds
super(StoragePlugin, self).__init__()
self._start_time = None
@ -46,6 +49,9 @@ class StoragePlugin(plugins.Plugin):
if self.cluster_id:
env['CLUSTER_ID'] = str(self.cluster_id)
for var_name in self.ostf_os_access_creds:
env[var_name.upper()] = self.ostf_os_access_creds[var_name]
def configure(self, options, conf):
self.conf = conf

View File

@ -367,12 +367,13 @@ class TestRun(BASE):
# flush test_run data to db
session.commit()
plugin.run(test_run, test_set, dbpath)
plugin.run(test_run, test_set, dbpath,
metadata.get('ostf_os_access_creds'))
return test_run.frontend
return {}
def restart(self, session, dbpath, tests=None):
def restart(self, session, dbpath, ostf_os_access_creds, tests=None):
"""Restart test run with
if tests given they will be enabled
"""
@ -386,7 +387,8 @@ class TestRun(BASE):
Test.update_test_run_tests(
session, self.id, tests)
plugin.run(self, self.test_set, dbpath, tests)
plugin.run(self, self.test_set, dbpath,
ostf_os_access_creds, tests)
return self.frontend
return {}

View File

@ -160,6 +160,8 @@ class TestrunsController(BaseRestController):
for test_run in test_runs:
status = test_run.get('status')
tests = test_run.get('tests', [])
ostf_os_access_creds = test_run.get('ostf_os_access_creds')
test_run = models.TestRun.get_test_run(request.session,
test_run['id'])
if status == 'stopped':
@ -167,5 +169,6 @@ class TestrunsController(BaseRestController):
elif status == 'restarted':
data.append(test_run.restart(request.session,
cfg.CONF.adapter.dbpath,
ostf_os_access_creds,
tests=tests))
return data

View File

@ -24,7 +24,20 @@ class TestingAdapterClient(object):
def _request(self, method, url, data=None):
headers = {'content-type': 'application/json'}
ostf_os_access_creds = {
'ostf_os_username': 'ostf',
'ostf_os_password': 'ostf',
'ostf_os_tenant_name': 'ostf'
}
if data:
for data_el in data:
if 'metadata' in data_el:
data_el['metadata']['ostf_os_access_creds'] = \
ostf_os_access_creds
else:
data_el['ostf_os_access_creds'] = ostf_os_access_creds
data = dumps({'objects': data})
r = requests.request(

View File

@ -0,0 +1,35 @@
# Copyright 2013 Mirantis, Inc.
#
# 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.
__profile__ = {
"id": "environment_variables",
"driver": "nose",
"test_path": ("fuel_plugin/tests/functional/dummy_tests/"
"test_environment_variables.py"),
"description": ("Test for presence of env variables inside of"
" testrun subprocess"),
"deployment_tags": [],
"test_runs_ordering_priority": 12,
"exclusive_testsets": []
}
import os
import unittest2
class TestEnvVariables(unittest2.TestCase):
def test_os_credentials_env_variables(self):
self.assertTrue(os.environ.get('OSTF_OS_USERNAME'))
self.assertTrue(os.environ.get('OSTF_OS_PASSWORD'))
self.assertTrue(os.environ.get('OSTF_OS_TENANT_NAME'))

View File

@ -52,7 +52,10 @@ class AdapterTests(BaseAdapterTest):
('fuel_plugin.testing.fixture.dummy_tests.deployment_types_tests.'
'ha_deployment_test.HATest.test_ha_depl'): 'ha_depl',
('fuel_plugin.testing.fixture.dummy_tests.deployment_types_tests.'
'ha_deployment_test.HATest.test_ha_rhel_depl'): 'ha_rhel_depl'
'ha_deployment_test.HATest.test_ha_rhel_depl'): 'ha_rhel_depl',
('fuel_plugin.testing.fixture.dummy_tests.'
'test_environment_variables.TestEnvVariables.'
'test_os_credentials_env_variables'): 'test_env_vars'
}
cls.testsets = {
"ha_deployment_test": [],
@ -623,3 +626,48 @@ class AdapterTests(BaseAdapterTest):
])
self.compare(resp, assertions)
def test_env_variables_are_set(self):
assertions = Response([
{
'testset': 'environment_variables',
'status': 'finished',
'tests': [
{
'id': (
'fuel_plugin.testing.fixture.'
'dummy_tests.test_environment_variables.'
'TestEnvVariables.'
'test_os_credentials_env_variables'
),
'status': 'success'
},
]
},
])
def check_testrun_res():
resp = self.client.testruns()
self.compare(resp, assertions)
cluster_id = 1
testset = 'environment_variables'
tests = [
('fuel_plugin.testing.fixture.'
'dummy_tests.test_environment_variables.'
'TestEnvVariables.'
'test_os_credentials_env_variables')
]
# make sure we have all needed data in db
self.adapter.testsets(cluster_id)
self.adapter.start_testrun(testset, cluster_id)
time.sleep(5)
check_testrun_res()
self.client.restart_tests_last(testset, tests, cluster_id)
time.sleep(5)
check_testrun_res()

View File

@ -41,7 +41,8 @@ class BaseWSGITest(unittest2.TestCase):
'deployment_tags': set(['ha', 'rhel', 'nova_network'])
},
'test_sets': ['general_test',
'stopped_test', 'ha_deployment_test'],
'stopped_test', 'ha_deployment_test',
'environment_variables'],
'tests': [cls.ext_id + test for test in [
('deployment_types_tests.ha_deployment_test.'
'HATest.test_ha_depl'),
@ -56,7 +57,9 @@ class BaseWSGITest(unittest2.TestCase):
'general_test.Dummy_test.test_skip_directly',
'stopped_test.dummy_tests_stopped.test_really_long',
'stopped_test.dummy_tests_stopped.test_one_no_so_long',
'stopped_test.dummy_tests_stopped.test_not_long_at_all'
'stopped_test.dummy_tests_stopped.test_not_long_at_all',
('test_environment_variables.TestEnvVariables.'
'test_os_credentials_env_variables')
]]
}

View File

@ -55,8 +55,8 @@ class TestNoseDiscovery(unittest2.TestCase):
def test_discovery(self):
expected = {
'test_sets_count': 8,
'tests_count': 26
'test_sets_count': 9,
'tests_count': 27
}
self.assertTrue(

View File

@ -49,7 +49,8 @@ class TestTestSetsController(base.BaseWSGITest):
self.expected['test_set_description'] = [
'General fake tests',
'Long running 25 secs fake tests',
'Fake tests for HA deployment'
'Fake tests for HA deployment',
'Test for presence of env variables inside of testrun subprocess'
]
res = self.controller.get(self.expected['cluster']['id'])
@ -67,7 +68,8 @@ class TestTestSetsController(base.BaseWSGITest):
test_set_order = {
'general_test': 0,
'stopped_test': 1,
'ha_deployment_test': 2
'ha_deployment_test': 2,
'environment_variables': 3
}
resp_elements = [testset['id'] for testset in res]
@ -241,7 +243,8 @@ class TestClusterRedeployment(base.BaseWSGITest):
'deployment_tags': set(['multinode', 'ubuntu', 'nova_network'])
},
'test_sets': ['general_test',
'stopped_test', 'multinode_deployment_test'],
'stopped_test', 'multinode_deployment_test',
'environment_variables'],
'tests': [self.ext_id + test for test in [
('deployment_types_tests.multinode_deployment_test.'
'MultinodeTest.test_multi_novanet_depl'),
@ -256,7 +259,9 @@ class TestClusterRedeployment(base.BaseWSGITest):
'general_test.Dummy_test.test_skip_directly',
'stopped_test.dummy_tests_stopped.test_really_long',
'stopped_test.dummy_tests_stopped.test_one_no_so_long',
'stopped_test.dummy_tests_stopped.test_not_long_at_all'
'stopped_test.dummy_tests_stopped.test_not_long_at_all',
('test_environment_variables.TestEnvVariables.'
'test_os_credentials_env_variables')
]]
}