Added flavor filter tests: lp899979, lp899980, lp899982
* Modified flavor service to return results in line with other services
* Added bug flag to tests that are failing due to known issues

Change-Id: Icd167c58f7782b12e757cde7fa8ce4b4f505cb6c
diff --git a/tempest/services/nova/json/flavors_client.py b/tempest/services/nova/json/flavors_client.py
index 4d78e66..60807a3 100644
--- a/tempest/services/nova/json/flavors_client.py
+++ b/tempest/services/nova/json/flavors_client.py
@@ -20,7 +20,7 @@
 
         resp, body = self.client.get(url)
         body = json.loads(body)
-        return resp, body
+        return resp, body['flavors']
 
     def list_flavors_with_detail(self, params=None):
         url = 'flavors/detail'
@@ -33,7 +33,7 @@
 
         resp, body = self.client.get(url)
         body = json.loads(body)
-        return resp, body
+        return resp, body['flavors']
 
     def get_flavor_details(self, flavor_id):
         resp, body = self.client.get("flavors/%s" % str(flavor_id))
diff --git a/tempest/tests/test_flavors.py b/tempest/tests/test_flavors.py
index 70ae9db..7e87830 100644
--- a/tempest/tests/test_flavors.py
+++ b/tempest/tests/test_flavors.py
@@ -1,7 +1,5 @@
 import unittest2 as unittest
-
 from nose.plugins.attrib import attr
-
 from tempest import exceptions
 from tempest import openstack
 
@@ -18,9 +16,7 @@
     @attr(type='smoke')
     def test_list_flavors(self):
         """List of all flavors should contain the expected flavor"""
-        resp, body = self.client.list_flavors()
-        flavors = body['flavors']
-
+        resp, flavors = self.client.list_flavors()
         resp, flavor = self.client.get_flavor_details(self.flavor_id)
         flavor_min_detail = {'id': flavor['id'], 'links': flavor['links'],
                              'name': flavor['name']}
@@ -29,8 +25,7 @@
     @attr(type='smoke')
     def test_list_flavors_with_detail(self):
         """Detailed list of all flavors should contain the expected flavor"""
-        resp, body = self.client.list_flavors_with_detail()
-        flavors = body['flavors']
+        resp, flavors = self.client.list_flavors_with_detail()
         resp, flavor = self.client.get_flavor_details(self.flavor_id)
         self.assertTrue(flavor in flavors)
 
@@ -45,3 +40,87 @@
         """flavor details are not returned for non existant flavors"""
         self.assertRaises(exceptions.NotFound, self.client.get_flavor_details,
                           999)
+
+    @unittest.expectedFailure
+    @attr(type='positive', bug='lp912922')
+    def test_list_flavors_limit_results(self):
+        """Only the expected number of flavors should be returned"""
+        params = {'limit': 1}
+        resp, flavors = self.client.list_flavors(params)
+        self.assertEqual(1, len(flavors))
+
+    @unittest.expectedFailure
+    @attr(type='positive', bug='lp912922')
+    def test_list_flavors_detailed_limit_results(self):
+        """Only the expected number of flavors (detailed) should be returned"""
+        params = {'limit': 1}
+        resp, flavors = self.client.list_flavors_with_detail(params)
+        self.assertEqual(1, len(flavors))
+
+    @unittest.expectedFailure
+    @attr(type='positive', bug='lp912922')
+    def test_list_flavors_using_marker(self):
+        """The list of flavors should start from the provided marker"""
+        resp, flavors = self.client.list_flavors()
+        flavor_id = flavors[0]['id']
+
+        params = {'marker': flavor_id}
+        resp, flavors = self.client.list_flavors(params)
+        self.assertFalse(any([i for i in flavors if i['id'] == flavor_id]),
+                        'The list of flavors did not start after the marker.')
+
+    @unittest.expectedFailure
+    @attr(type='positive', bug='lp912922')
+    def test_list_flavors_detailed_using_marker(self):
+        """The list of flavors should start from the provided marker"""
+        resp, flavors = self.client.list_flavors_with_detail()
+        flavor_id = flavors[0]['id']
+
+        params = {'marker': flavor_id}
+        resp, flavors = self.client.list_flavors_with_detail(params)
+        self.assertFalse(any([i for i in flavors if i['id'] == flavor_id]),
+                        'The list of flavors did not start after the marker.')
+
+    @attr(type='positive')
+    def test_list_flavors_detailed_filter_by_min_disk(self):
+        """The detailed list of flavors should be filtered by disk space"""
+        resp, flavors = self.client.list_flavors_with_detail()
+        flavors = sorted(flavors, key=lambda k: k['disk'])
+        flavor_id = flavors[0]['id']
+
+        params = {'minDisk': flavors[1]['disk']}
+        resp, flavors = self.client.list_flavors_with_detail(params)
+        self.assertFalse(any([i for i in flavors if i['id'] == flavor_id]))
+
+    @attr(type='positive')
+    def test_list_flavors_detailed_filter_by_min_ram(self):
+        """The detailed list of flavors should be filtered by RAM"""
+        resp, flavors = self.client.list_flavors_with_detail()
+        flavors = sorted(flavors, key=lambda k: k['ram'])
+        flavor_id = flavors[0]['id']
+
+        params = {'minRam': flavors[1]['ram']}
+        resp, flavors = self.client.list_flavors_with_detail(params)
+        self.assertFalse(any([i for i in flavors if i['id'] == flavor_id]))
+
+    @attr(type='positive')
+    def test_list_flavors_filter_by_min_disk(self):
+        """The list of flavors should be filtered by disk space"""
+        resp, flavors = self.client.list_flavors_with_detail()
+        flavors = sorted(flavors, key=lambda k: k['disk'])
+        flavor_id = flavors[0]['id']
+
+        params = {'minDisk': flavors[1]['disk']}
+        resp, flavors = self.client.list_flavors(params)
+        self.assertFalse(any([i for i in flavors if i['id'] == flavor_id]))
+
+    @attr(type='positive')
+    def test_list_flavors_filter_by_min_ram(self):
+        """The list of flavors should be filtered by RAM"""
+        resp, flavors = self.client.list_flavors_with_detail()
+        flavors = sorted(flavors, key=lambda k: k['ram'])
+        flavor_id = flavors[0]['id']
+
+        params = {'minRam': flavors[1]['ram']}
+        resp, flavors = self.client.list_flavors(params)
+        self.assertFalse(any([i for i in flavors if i['id'] == flavor_id]))