Code for querying failed tests and list tests in the last x hours

Change-Id: I6b279ab2e909526606a9a6bc8cbfa1eea6d4ac30
This commit is contained in:
Anand Shanmugam 2015-10-28 13:47:15 -07:00
parent 05012c8bbe
commit 9a858fec19
2 changed files with 32 additions and 4 deletions

@ -14,6 +14,8 @@
# limitations under the License.
from cloudpulseclient.common import base
import six
from six.moves.urllib import parse
class HealthCheck(base.Resource):
@ -28,9 +30,23 @@ class HealthCheckManager(base.Manager):
def _path(id=None):
return '/v1/cpulse/%s' % id if id else '/v1/cpulse'
def list(self, marker=None, limit=None, sort_key=None,
sort_dir=None, detail=False):
return self._list(self._path(''), "cpulses")
def list(self, search_opts=None, marker=None, limit=None,
sort_key=None, sort_dir=None, detail=False):
if search_opts is None:
search_opts = {}
qparams = {}
for opt, val in six.iteritems(search_opts):
if val:
if isinstance(val, six.text_type):
val = val.encode('utf-8')
qparams[opt] = val
if qparams:
items = list(qparams.items())
new_qparams = sorted(items, key=lambda x: x[0])
query_string = "?%s" % parse.urlencode(new_qparams)
else:
query_string = ""
return self._list("%s%s" % (self._path(''), query_string), "cpulses")
def create(self, **kwargs):
new = {}

@ -20,9 +20,21 @@ def _print_list_field(field):
return lambda obj: ', '.join(getattr(obj, field))
@utils.arg('--failed',
dest='failed',
action="store_true",
default=False,
help='Display only failed tests.')
@utils.arg('--period',
metavar='<period>',
help='List all tests in the last x hours.')
def do_result(cs, args):
"""List all the tests"""
healtchecks = cs.healthcheck.list()
search_opts = {
'failed': args.failed,
'period': args.period,
}
healtchecks = cs.healthcheck.list(search_opts=search_opts)
columns = ('uuid', 'id', 'name', 'testtype', 'state')
utils.print_list(healtchecks, columns,
{'versions': _print_list_field('versions')},