Merge "Verify more information in API tests for LBaaS"
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index 93335e7..231c4bf 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -242,14 +242,20 @@
     @classmethod
     def create_member(cls, protocol_port, pool):
         """Wrapper utility that returns a test member."""
-        resp, body = cls.client.create_member("10.0.9.46",
-                                              protocol_port,
-                                              pool['id'])
+        resp, body = cls.client.create_member(address="10.0.9.46",
+                                              protocol_port=protocol_port,
+                                              pool_id=pool['id'])
         member = body['member']
         cls.members.append(member)
         return member
 
     @classmethod
+    def update_member(cls, admin_state_up):
+        resp, body = cls.client.update_member(admin_state_up=admin_state_up)
+        member = body['member']
+        return member
+
+    @classmethod
     def create_health_monitor(cls, delay, max_retries, Type, timeout):
         """Wrapper utility that returns a test health monitor."""
         resp, body = cls.client.create_health_monitor(delay=delay,
diff --git a/tempest/api/network/test_load_balancer.py b/tempest/api/network/test_load_balancer.py
index 03e095d..ba92199 100644
--- a/tempest/api/network/test_load_balancer.py
+++ b/tempest/api/network/test_load_balancer.py
@@ -61,19 +61,50 @@
                                                        Type="TCP",
                                                        timeout=1)
 
+    def _check_list_with_filter(self, obj_name, attr_exceptions, **kwargs):
+        create_obj = getattr(self.client, 'create_' + obj_name)
+        delete_obj = getattr(self.client, 'delete_' + obj_name)
+        list_objs = getattr(self.client, 'list_' + obj_name + 's')
+
+        resp, body = create_obj(**kwargs)
+        self.assertEqual('201', resp['status'])
+        obj = body[obj_name]
+        self.addCleanup(delete_obj, obj['id'])
+        for key, value in obj.iteritems():
+            # It is not relevant to filter by all arguments. That is why
+            # there is a list of attr to except
+            if key not in attr_exceptions:
+                resp, body = list_objs(**{key: value})
+                self.assertEqual('200', resp['status'])
+                objs = [v[key] for v in body[obj_name + 's']]
+                self.assertIn(value, objs)
+
     @test.attr(type='smoke')
     def test_list_vips(self):
         # Verify the vIP exists in the list of all vIPs
         resp, body = self.client.list_vips()
         self.assertEqual('200', resp['status'])
         vips = body['vips']
-        found = None
-        for n in vips:
-            if (n['id'] == self.vip['id']):
-                found = n['id']
-        msg = "vIPs list doesn't contain created vip"
-        self.assertIsNotNone(found, msg)
+        self.assertIn(self.vip['id'], [v['id'] for v in vips])
 
+    @test.attr(type='smoke')
+    def test_list_vips_with_filter(self):
+        name = data_utils.rand_name('vip-')
+        resp, body = self.client.create_pool(
+            name=data_utils.rand_name("pool-"), lb_method="ROUND_ROBIN",
+            protocol="HTTPS", subnet_id=self.subnet['id'])
+        self.assertEqual('201', resp['status'])
+        pool = body['pool']
+        self.addCleanup(self.client.delete_pool, pool['id'])
+        attr_exceptions = ['status', 'session_persistence',
+                           'status_description']
+        self._check_list_with_filter(
+            'vip', attr_exceptions, name=name, protocol="HTTPS",
+            protocol_port=81, subnet_id=self.subnet['id'], pool_id=pool['id'],
+            description=data_utils.rand_name('description-'),
+            admin_state_up=False)
+
+    @test.attr(type='smoke')
     def test_create_update_delete_pool_vip(self):
         # Creates a vip
         name = data_utils.rand_name('vip-')
@@ -117,17 +148,30 @@
         resp, body = self.client.show_vip(self.vip['id'])
         self.assertEqual('200', resp['status'])
         vip = body['vip']
-        self.assertEqual(self.vip['id'], vip['id'])
-        self.assertEqual(self.vip['name'], vip['name'])
+        for key, value in vip.iteritems():
+            # 'status' should not be confirmed in api tests
+            if key != 'status':
+                self.assertEqual(self.vip[key], value)
 
     @test.attr(type='smoke')
     def test_show_pool(self):
-        # Verifies the details of a pool
-        resp, body = self.client.show_pool(self.pool['id'])
-        self.assertEqual('200', resp['status'])
+        # Here we need to new pool without any dependence with vips
+        resp, body = self.client.create_pool(
+            name=data_utils.rand_name("pool-"),
+            lb_method='ROUND_ROBIN',
+            protocol='HTTP',
+            subnet_id=self.subnet['id'])
+        self.assertEqual('201', resp['status'])
         pool = body['pool']
-        self.assertEqual(self.pool['id'], pool['id'])
-        self.assertEqual(self.pool['name'], pool['name'])
+        self.addCleanup(self.client.delete_pool, pool['id'])
+        # Verifies the details of a pool
+        resp, body = self.client.show_pool(pool['id'])
+        self.assertEqual('200', resp['status'])
+        shown_pool = body['pool']
+        for key, value in pool.iteritems():
+            # 'status' should not be confirmed in api tests
+            if key != 'status':
+                self.assertEqual(value, shown_pool[key])
 
     @test.attr(type='smoke')
     def test_list_pools(self):
@@ -138,6 +182,17 @@
         self.assertIn(self.pool['id'], [p['id'] for p in pools])
 
     @test.attr(type='smoke')
+    def test_list_pools_with_filters(self):
+        attr_exceptions = ['status', 'vip_id', 'members', 'provider',
+                           'status_description']
+        self._check_list_with_filter(
+            'pool', attr_exceptions, name=data_utils.rand_name("pool-"),
+            lb_method="ROUND_ROBIN", protocol="HTTPS",
+            subnet_id=self.subnet['id'],
+            description=data_utils.rand_name('description-'),
+            admin_state_up=False)
+
+    @test.attr(type='smoke')
     def test_list_members(self):
         # Verify the member exists in the list of all members
         resp, body = self.client.list_members()
@@ -146,14 +201,23 @@
         self.assertIn(self.member['id'], [m['id'] for m in members])
 
     @test.attr(type='smoke')
+    def test_list_members_with_filters(self):
+        attr_exceptions = ['status', 'status_description']
+        self._check_list_with_filter('member', attr_exceptions,
+                                     address="10.0.9.47", protocol_port=80,
+                                     pool_id=self.pool['id'])
+
+    @test.attr(type='smoke')
     def test_create_update_delete_member(self):
         # Creates a member
-        resp, body = self.client.create_member("10.0.9.47", 80,
-                                               self.pool['id'])
+        resp, body = self.client.create_member(address="10.0.9.47",
+                                               protocol_port=80,
+                                               pool_id=self.pool['id'])
         self.assertEqual('201', resp['status'])
         member = body['member']
         # Verification of member update
-        resp, body = self.client.update_member(False, member['id'])
+        resp, body = self.client.update_member(member['id'],
+                                               admin_state_up=False)
         self.assertEqual('200', resp['status'])
         updated_member = body['member']
         self.assertFalse(updated_member['admin_state_up'])
@@ -167,9 +231,10 @@
         resp, body = self.client.show_member(self.member['id'])
         self.assertEqual('200', resp['status'])
         member = body['member']
-        self.assertEqual(self.member['id'], member['id'])
-        self.assertEqual(self.member['admin_state_up'],
-                         member['admin_state_up'])
+        for key, value in member.iteritems():
+             # 'status' should not be confirmed in api tests
+            if key != 'status':
+                self.assertEqual(self.member[key], value)
 
     @test.attr(type='smoke')
     def test_list_health_monitors(self):
@@ -181,6 +246,13 @@
                       [h['id'] for h in health_monitors])
 
     @test.attr(type='smoke')
+    def test_list_health_monitors_with_filters(self):
+        attr_exceptions = ['status', 'status_description', 'pools']
+        self._check_list_with_filter('health_monitor', attr_exceptions,
+                                     delay=5, max_retries=4, type="TCP",
+                                     timeout=2)
+
+    @test.attr(type='smoke')
     def test_create_update_delete_health_monitor(self):
         # Creates a health_monitor
         resp, body = self.client.create_health_monitor(delay=4,
@@ -206,9 +278,10 @@
         resp, body = self.client.show_health_monitor(self.health_monitor['id'])
         self.assertEqual('200', resp['status'])
         health_monitor = body['health_monitor']
-        self.assertEqual(self.health_monitor['id'], health_monitor['id'])
-        self.assertEqual(self.health_monitor['admin_state_up'],
-                         health_monitor['admin_state_up'])
+        for key, value in health_monitor.iteritems():
+             # 'status' should not be confirmed in api tests
+            if key != 'status':
+                self.assertEqual(self.health_monitor[key], value)
 
     @test.attr(type='smoke')
     def test_associate_disassociate_health_monitor_with_pool(self):
@@ -216,10 +289,26 @@
         resp, body = (self.client.associate_health_monitor_with_pool
                      (self.health_monitor['id'], self.pool['id']))
         self.assertEqual('201', resp['status'])
+        resp, body = self.client.show_health_monitor(
+            self.health_monitor['id'])
+        health_monitor = body['health_monitor']
+        resp, body = self.client.show_pool(self.pool['id'])
+        pool = body['pool']
+        self.assertIn(pool['id'],
+                      [p['pool_id'] for p in health_monitor['pools']])
+        self.assertIn(health_monitor['id'], pool['health_monitors'])
         # Verify that a health monitor can be disassociated from a pool
         resp, body = (self.client.disassociate_health_monitor_with_pool
                      (self.health_monitor['id'], self.pool['id']))
         self.assertEqual('204', resp['status'])
+        resp, body = self.client.show_pool(self.pool['id'])
+        pool = body['pool']
+        resp, body = self.client.show_health_monitor(
+            self.health_monitor['id'])
+        health_monitor = body['health_monitor']
+        self.assertNotIn(health_monitor['id'], pool['health_monitors'])
+        self.assertNotIn(pool['id'],
+                         [p['pool_id'] for p in health_monitor['pools']])
 
     @test.attr(type='smoke')
     def test_get_lb_pool_stats(self):
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index d8c0979..a804e8e 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -163,32 +163,6 @@
         body = json.loads(body)
         return resp, body
 
-    def create_member(self, address, protocol_port, pool_id):
-        post_body = {
-            "member": {
-                "protocol_port": protocol_port,
-                "pool_id": pool_id,
-                "address": address
-            }
-        }
-        body = json.dumps(post_body)
-        uri = '%s/lb/members' % (self.uri_prefix)
-        resp, body = self.post(uri, body)
-        body = json.loads(body)
-        return resp, body
-
-    def update_member(self, admin_state_up, member_id):
-        put_body = {
-            "member": {
-                "admin_state_up": admin_state_up
-            }
-        }
-        body = json.dumps(put_body)
-        uri = '%s/lb/members/%s' % (self.uri_prefix, member_id)
-        resp, body = self.put(uri, body)
-        body = json.loads(body)
-        return resp, body
-
     def associate_health_monitor_with_pool(self, health_monitor_id,
                                            pool_id):
         post_body = {
diff --git a/tempest/services/network/xml/network_client.py b/tempest/services/network/xml/network_client.py
index daa60da..2a5083c 100644
--- a/tempest/services/network/xml/network_client.py
+++ b/tempest/services/network/xml/network_client.py
@@ -23,7 +23,8 @@
 
     # list of plurals used for xml serialization
     PLURALS = ['dns_nameservers', 'host_routes', 'allocation_pools',
-               'fixed_ips', 'extensions', 'extra_dhcp_opts']
+               'fixed_ips', 'extensions', 'extra_dhcp_opts', 'pools',
+               'health_monitors', 'vips']
 
     def get_rest_client(self, auth_provider):
         rc = rest_client.RestClient(auth_provider)
@@ -92,28 +93,6 @@
             root.add_attr('xmlns:%s' % element,
                           common.NEUTRON_NAMESPACES[element])
 
-    def create_member(self, address, protocol_port, pool_id):
-        uri = '%s/lb/members' % (self.uri_prefix)
-        post_body = common.Element("member")
-        p1 = common.Element("address", address)
-        p2 = common.Element("protocol_port", protocol_port)
-        p3 = common.Element("pool_id", pool_id)
-        post_body.append(p1)
-        post_body.append(p2)
-        post_body.append(p3)
-        resp, body = self.post(uri, str(common.Document(post_body)))
-        body = _root_tag_fetcher_and_xml_to_json_parse(body)
-        return resp, body
-
-    def update_member(self, admin_state_up, member_id):
-        uri = '%s/lb/members/%s' % (self.uri_prefix, str(member_id))
-        put_body = common.Element("member")
-        p2 = common.Element("admin_state_up", admin_state_up)
-        put_body.append(p2)
-        resp, body = self.put(uri, str(common.Document(put_body)))
-        body = _root_tag_fetcher_and_xml_to_json_parse(body)
-        return resp, body
-
     def associate_health_monitor_with_pool(self, health_monitor_id,
                                            pool_id):
         uri = '%s/lb/pools/%s/health_monitors' % (self.uri_prefix,