Pass credentials to ostf

"--ostf-tenant-name", "--ostf-username" and "--ostf-password" are now passed
to ostf so that cli behaviour matches webui

Change-Id: I1d407833ed9e1bcbc18febe7885006d1012b1351
Closes-Bug: #1578137
This commit is contained in:
Georgy Kibardin 2016-05-12 11:56:41 +03:00
parent 0381c0dd2f
commit 8fe27741f9
4 changed files with 76 additions and 10 deletions

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
from fuelclient.cli.actions.base import Action
import fuelclient.cli.arguments as Args
@ -19,6 +20,7 @@ from fuelclient.cli.error import EnvironmentException
from fuelclient.cli.formatting import format_table
from fuelclient.cli.formatting import print_health_check
from fuelclient.objects.environment import Environment
import six
class HealthCheckAction(Action):
@ -38,7 +40,10 @@ class HealthCheckAction(Action):
Args.get_env_arg(required=True),
Args.get_list_arg("List all available checks"),
Args.get_force_arg("Forced test run"),
Args.get_check_arg("Run check for some testset.")
Args.get_check_arg("Run check for some testset."),
Args.get_ostf_username_arg(),
Args.get_ostf_password_arg(),
Args.get_ostf_tenant_name_arg()
)
self.flag_func_map = (
@ -68,7 +73,17 @@ class HealthCheckAction(Action):
)
test_sets_to_check = params.check or set(
ts["id"] for ts in env.get_testsets())
env.run_test_sets(test_sets_to_check)
ostf_credentials = {}
if params.ostf_tenant_name is not None:
ostf_credentials['tenant'] = params.ostf_tenant_name
if params.ostf_username is not None:
ostf_credentials['username'] = params.ostf_username
if params.ostf_password is not None:
ostf_credentials['password'] = params.ostf_password
if not ostf_credentials:
six.print_("WARNING: ostf credentials are going to be",
"mandatory in the next release.", file=sys.stderr)
env.run_test_sets(test_sets_to_check, ostf_credentials)
tests_state = env.get_state_of_tests()
self.serializer.print_to_output(
tests_state,

View File

@ -314,6 +314,33 @@ def get_check_arg(help_msg):
return get_set_type_arg("check", help=help_msg)
def get_ostf_username_arg():
return get_str_arg(
"ostf_username",
dest="ostf_username",
help="OSTF username",
required=False
)
def get_ostf_password_arg():
return get_str_arg(
"ostf_password",
dest="ostf_password",
help="OSTF password",
required=False
)
def get_ostf_tenant_name_arg():
return get_str_arg(
"ostf_tenant_name",
dest="ostf_tenant_name",
help="OSTF tenant name",
required=False
)
def get_change_password_arg(help_msg):
return get_boolean_arg("change-password", help=help_msg)

View File

@ -415,19 +415,29 @@ class Environment(BaseObject):
def is_in_running_test_sets(self, test_set):
return test_set["testset"] in self._test_sets_to_run
def run_test_sets(self, test_sets_to_run):
def run_test_sets(self, test_sets_to_run, ostf_credentials=None):
self._test_sets_to_run = test_sets_to_run
tests_data = map(
lambda testset: {
"testset": testset,
def make_test_set(name):
result = {
"testset": name,
"metadata": {
"config": {},
"cluster_id": self.id
"cluster_id": self.id,
}
},
test_sets_to_run
)
}
if ostf_credentials:
creds = result['metadata'].setdefault(
'ostf_os_access_creds', {})
if 'tenant' in ostf_credentials:
creds['ostf_os_tenant_name'] = ostf_credentials['tenant']
if 'username' in ostf_credentials:
creds['ostf_os_username'] = ostf_credentials['username']
if 'password' in ostf_credentials:
creds['ostf_os_password'] = ostf_credentials['password']
return result
tests_data = [make_test_set(ts) for ts in test_sets_to_run]
testruns = self.connection.post_request(
"testruns", tests_data, ostf=True)
self._testruns_ids = [tr['id'] for tr in testruns]

View File

@ -133,6 +133,20 @@ class TestEnvironmentOstf(base.UnitTestCase):
self.assertIn(1, self.env._testruns_ids)
self.assertIn(2, self.env._testruns_ids)
@mock.patch.object(Environment.connection, 'post_request')
def test_credentials_are_passed_to_ostf(self, post_request):
self.env.run_test_sets(['sanity'], {'tenant': 't1',
'username': 'u1',
'password': 'p1'})
run_test_request = post_request.call_args[0][1]
self.assertTrue(len(run_test_request) > 0, 'Got empty request')
self.assertIn('metadata', run_test_request[0])
self.assertIn('ostf_os_access_creds', run_test_request[0]['metadata'])
creds = run_test_request[0]['metadata']['ostf_os_access_creds']
self.assertEqual(creds['ostf_os_tenant_name'], 't1')
self.assertEqual(creds['ostf_os_username'], 'u1')
self.assertEqual(creds['ostf_os_password'], 'p1')
@mock.patch.object(Environment.connection, 'get_request', mock.Mock(
side_effect=[
{'id': 1, 'status': 'running'},