Adding health monitoring test case
Test cases for health monitoring (load balancer) were missing.
I have added list, show, create, update, delete,associate, disassociate
test cases fot health monitoring.
Change-Id: If123d9bf8f11babc760ca8fbcbc0d6c9931d138b
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index 378b4bf..4a4bf60 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -59,9 +59,12 @@
cls.pools = []
cls.vips = []
cls.members = []
+ cls.health_monitors = []
@classmethod
def tearDownClass(cls):
+ for health_monitor in cls.health_monitors:
+ cls.client.delete_health_monitor(health_monitor['id'])
for member in cls.members:
cls.client.delete_member(member['id'])
for vip in cls.vips:
@@ -148,3 +151,13 @@
member = body['member']
cls.members.append(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,
+ max_retries,
+ Type, timeout)
+ health_monitor = body['health_monitor']
+ cls.health_monitors.append(health_monitor)
+ return health_monitor
diff --git a/tempest/api/network/test_load_balancer.py b/tempest/api/network/test_load_balancer.py
index b0a6851..62017dc 100644
--- a/tempest/api/network/test_load_balancer.py
+++ b/tempest/api/network/test_load_balancer.py
@@ -36,6 +36,7 @@
delete pool
show pool
list pool
+ health monitoring operations
"""
@classmethod
@@ -50,6 +51,7 @@
"HTTP", cls.subnet)
cls.vip = cls.create_vip(vip_name, "HTTP", 80, cls.subnet, cls.pool)
cls.member = cls.create_member(80, cls.pool)
+ cls.health_monitor = cls.create_health_monitor(4, 3, "TCP", 1)
@attr(type='smoke')
def test_list_vips(self):
@@ -156,6 +158,53 @@
self.assertEqual(self.member['admin_state_up'],
member['admin_state_up'])
+ @attr(type='smoke')
+ def test_list_health_monitors(self):
+ # Verify the health monitor exists in the list of all health monitors
+ resp, body = self.client.list_health_monitors()
+ self.assertEqual('200', resp['status'])
+ health_monitors = body['health_monitors']
+ self.assertIn(self.health_monitor['id'],
+ [h['id'] for h in health_monitors])
+
+ @attr(type='smoke')
+ def test_create_update_delete_health_monitor(self):
+ # Creates a health_monitor
+ resp, body = self.client.create_health_monitor(4, 3, "TCP", 1)
+ self.assertEqual('201', resp['status'])
+ health_monitor = body['health_monitor']
+ # Verification of health_monitor update
+ admin_state = [False, 'False']
+ resp, body = self.client.update_health_monitor(admin_state[0],
+ health_monitor['id'])
+ self.assertEqual('200', resp['status'])
+ updated_health_monitor = body['health_monitor']
+ self.assertIn(updated_health_monitor['admin_state_up'], admin_state)
+ # Verification of health_monitor delete
+ resp, body = self.client.delete_health_monitor(health_monitor['id'])
+ self.assertEqual('204', resp['status'])
+
+ @attr(type='smoke')
+ def test_show_health_monitor(self):
+ # Verifies the details of a health_monitor
+ 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'])
+
+ @attr(type='smoke')
+ def test_associate_disassociate_health_monitor_with_pool(self):
+ # Verify that a health monitor can be associated with a pool
+ resp, body = (self.client.associate_health_monitor_with_pool
+ (self.health_monitor['id'], self.pool['id']))
+ self.assertEqual('201', resp['status'])
+ # 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'])
+
class LoadBalancerXML(LoadBalancerJSON):
_interface = 'xml'
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index fbcb6c1..369dd81 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -533,3 +533,68 @@
resp, body = self.put(uri, body=body, headers=self.headers)
body = json.loads(body)
return resp, body
+
+ def list_health_monitors(self):
+ uri = '%s/lb/health_monitors' % (self.uri_prefix)
+ resp, body = self.get(uri, self.headers)
+ body = json.loads(body)
+ return resp, body
+
+ def create_health_monitor(self, delay, max_retries, Type, timeout):
+ post_body = {
+ "health_monitor": {
+ "delay": delay,
+ "max_retries": max_retries,
+ "type": Type,
+ "timeout": timeout
+ }
+ }
+ body = json.dumps(post_body)
+ uri = '%s/lb/health_monitors' % (self.uri_prefix)
+ resp, body = self.post(uri, headers=self.headers, body=body)
+ body = json.loads(body)
+ return resp, body
+
+ def show_health_monitor(self, uuid):
+ uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, uuid)
+ resp, body = self.get(uri, self.headers)
+ body = json.loads(body)
+ return resp, body
+
+ def delete_health_monitor(self, uuid):
+ uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, uuid)
+ resp, body = self.delete(uri, self.headers)
+ return resp, body
+
+ def update_health_monitor(self, admin_state_up, uuid):
+ put_body = {
+ "health_monitor": {
+ "admin_state_up": admin_state_up
+ }
+ }
+ body = json.dumps(put_body)
+ uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, uuid)
+ resp, body = self.put(uri, body=body, headers=self.headers)
+ body = json.loads(body)
+ return resp, body
+
+ def associate_health_monitor_with_pool(self, health_monitor_id,
+ pool_id):
+ post_body = {
+ "health_monitor": {
+ "id": health_monitor_id,
+ }
+ }
+ body = json.dumps(post_body)
+ uri = '%s/lb/pools/%s/health_monitors' % (self.uri_prefix,
+ pool_id)
+ resp, body = self.post(uri, headers=self.headers, body=body)
+ body = json.loads(body)
+ return resp, body
+
+ def disassociate_health_monitor_with_pool(self, health_monitor_id,
+ pool_id):
+ uri = '%s/lb/pools/%s/health_monitors/%s' % (self.uri_prefix, pool_id,
+ health_monitor_id)
+ resp, body = self.delete(uri, headers=self.headers)
+ return resp, body
diff --git a/tempest/services/network/xml/network_client.py b/tempest/services/network/xml/network_client.py
index e8e362a..a9b5512 100755
--- a/tempest/services/network/xml/network_client.py
+++ b/tempest/services/network/xml/network_client.py
@@ -370,6 +370,64 @@
body = _root_tag_fetcher_and_xml_to_json_parse(body)
return resp, body
+ def list_health_monitors(self):
+ uri = '%s/lb/health_monitors' % (self.uri_prefix)
+ resp, body = self.get(uri, self.headers)
+ body = self._parse_array(etree.fromstring(body))
+ body = {"health_monitors": body}
+ return resp, body
+
+ def create_health_monitor(self, delay, max_retries, Type, timeout):
+ uri = '%s/lb/health_monitors' % (self.uri_prefix)
+ post_body = Element("health_monitor")
+ p1 = Element("delay", delay)
+ p2 = Element("max_retries", max_retries)
+ p3 = Element("type", Type)
+ p4 = Element("timeout", timeout)
+ post_body.append(p1)
+ post_body.append(p2)
+ post_body.append(p3)
+ post_body.append(p4)
+ resp, body = self.post(uri, str(Document(post_body)), self.headers)
+ body = _root_tag_fetcher_and_xml_to_json_parse(body)
+ return resp, body
+
+ def delete_health_monitor(self, uuid):
+ uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, str(uuid))
+ return self.delete(uri, self.headers)
+
+ def show_health_monitor(self, uuid):
+ uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, str(uuid))
+ resp, body = self.get(uri, self.headers)
+ body = _root_tag_fetcher_and_xml_to_json_parse(body)
+ return resp, body
+
+ def update_health_monitor(self, admin_state_up, uuid):
+ uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, str(uuid))
+ put_body = Element("health_monitor")
+ p2 = Element("admin_state_up", admin_state_up)
+ put_body.append(p2)
+ resp, body = self.put(uri, str(Document(put_body)), self.headers)
+ 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,
+ pool_id)
+ post_body = Element("health_monitor")
+ p1 = Element("id", health_monitor_id,)
+ post_body.append(p1)
+ resp, body = self.post(uri, str(Document(post_body)), self.headers)
+ body = _root_tag_fetcher_and_xml_to_json_parse(body)
+ return resp, body
+
+ def disassociate_health_monitor_with_pool(self, health_monitor_id,
+ pool_id):
+ uri = '%s/lb/pools/%s/health_monitors/%s' % (self.uri_prefix, pool_id,
+ health_monitor_id)
+ return self.delete(uri, self.headers)
+
def _root_tag_fetcher_and_xml_to_json_parse(xml_returned_body):
body = ET.fromstring(xml_returned_body)