Merge "Displays only invoked tests in fuel health output"

This commit is contained in:
Jenkins 2014-11-20 13:51:05 +00:00 committed by Gerrit Code Review
commit a5ed8cbc95
2 changed files with 71 additions and 10 deletions

View File

@ -52,6 +52,10 @@ class Environment(BaseObject):
data = cls.connection.post_request("clusters/", data)
return cls.init_with_data(data)
def __init__(self, *args, **kwargs):
super(Environment, self).__init__(*args, **kwargs)
self._testruns_ids = []
def set(self, data):
if data.get('mode'):
data["mode"] = "ha_compact" \
@ -308,7 +312,7 @@ class Environment(BaseObject):
return data["is_customized"]
def is_in_running_test_sets(self, test_set):
return test_set["testset"] in self._test_sets_to_run,
return test_set["testset"] in self._test_sets_to_run
def run_test_sets(self, test_sets_to_run):
self._test_sets_to_run = test_sets_to_run
@ -322,17 +326,18 @@ class Environment(BaseObject):
},
test_sets_to_run
)
return self.connection.post_request(
"testruns",
tests_data,
ostf=True
)
testruns = self.connection.post_request(
"testruns", tests_data, ostf=True)
self._testruns_ids = [tr['id'] for tr in testruns]
return testruns
def get_state_of_tests(self):
return self.connection.get_request(
"testruns/last/{0}".format(self.id),
ostf=True
)
return [
self.connection.get_request(
"testruns/{0}".format(testrun_id), ostf=True)
for testrun_id in self._testruns_ids
]
def stop(self):
return Task.init_with_data(

View File

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# Copyright 2014 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.
import mock
from fuelclient.objects.environment import Environment
from fuelclient.tests import base
class TestEnvironmentOstf(base.UnitTestCase):
def setUp(self):
super(TestEnvironmentOstf, self).setUp()
self.env = Environment(None)
@mock.patch.object(Environment.connection, 'post_request', mock.Mock(
return_value=[
{'id': 1},
{'id': 2}, ]))
def test_run_test_sets(self):
self.assertEqual(self.env._testruns_ids, [])
testruns = self.env.run_test_sets(['sanity', 'ha'])
self.assertEqual(len(testruns), 2)
self.assertIn(1, self.env._testruns_ids)
self.assertIn(2, self.env._testruns_ids)
@mock.patch.object(Environment.connection, 'get_request', mock.Mock(
side_effect=[
{'id': 1, 'status': 'running'},
{'id': 2, 'status': 'finished'}, ]))
def test_get_state_of_tests(self):
self.env._testruns_ids.extend([1, 2])
tests = self.env.get_state_of_tests()
self.env.connection.get_request.assert_has_calls([
mock.call('testruns/1', ostf=True),
mock.call('testruns/2', ostf=True)])
self.assertEqual(tests, [
{'id': 1, 'status': 'running'},
{'id': 2, 'status': 'finished'}])