Refactor create_ and update_ methods for VIPs and health_monitors
Remove the following methods from json and xml network clients:
-create_vip;
-update_vip;
-create_health_monitor;
-update_halth_monitor;
Move the update_ methods to network/base and modify create_ methods.
Modify test_load_balancer accordingly.
Change-Id: I4eaad4270780b99181a357115d4061ae5ed6bc35
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index b129786..4de76f6 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -213,13 +213,22 @@
@classmethod
def create_vip(cls, name, protocol, protocol_port, subnet, pool):
"""Wrapper utility that returns a test vip."""
- resp, body = cls.client.create_vip(name, protocol, protocol_port,
- subnet['id'], pool['id'])
+ resp, body = cls.client.create_vip(name=name,
+ protocol=protocol,
+ protocol_port=protocol_port,
+ subnet_id=subnet['id'],
+ pool_id=pool['id'])
vip = body['vip']
cls.vips.append(vip)
return vip
@classmethod
+ def update_vip(cls, name):
+ resp, body = cls.client.update_vip(name=name)
+ vip = body['vip']
+ return vip
+
+ @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",
@@ -232,14 +241,21 @@
@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)
+ resp, body = cls.client.create_health_monitor(delay=delay,
+ max_retries=max_retries,
+ type=Type,
+ timeout=timeout)
health_monitor = body['health_monitor']
cls.health_monitors.append(health_monitor)
return health_monitor
@classmethod
+ def update_health_monitor(cls, admin_state_up):
+ resp, body = cls.client.update_vip(admin_state_up=admin_state_up)
+ health_monitor = body['health_monitor']
+ return health_monitor
+
+ @classmethod
def create_router_interface(cls, router_id, subnet_id):
"""Wrapper utility that returns a router interface."""
resp, interface = cls.client.add_router_interface_with_subnet_id(
diff --git a/tempest/api/network/test_load_balancer.py b/tempest/api/network/test_load_balancer.py
index d5f2b5b..53541ed 100644
--- a/tempest/api/network/test_load_balancer.py
+++ b/tempest/api/network/test_load_balancer.py
@@ -50,9 +50,16 @@
vip_name = data_utils.rand_name('vip-')
cls.pool = cls.create_pool(pool_name, "ROUND_ROBIN",
"HTTP", cls.subnet)
- cls.vip = cls.create_vip(vip_name, "HTTP", 80, cls.subnet, cls.pool)
+ cls.vip = cls.create_vip(name=vip_name,
+ protocol="HTTP",
+ protocol_port=80,
+ subnet=cls.subnet,
+ pool=cls.pool)
cls.member = cls.create_member(80, cls.pool)
- cls.health_monitor = cls.create_health_monitor(4, 3, "TCP", 1)
+ cls.health_monitor = cls.create_health_monitor(delay=4,
+ max_retries=3,
+ Type="TCP",
+ timeout=1)
@test.attr(type='smoke')
def test_list_vips(self):
@@ -76,14 +83,17 @@
protocol='HTTP',
subnet_id=self.subnet['id'])
pool = body['pool']
- resp, body = self.client.create_vip(name, "HTTP", 80,
- self.subnet['id'], pool['id'])
+ resp, body = self.client.create_vip(name=name,
+ protocol="HTTP",
+ protocol_port=80,
+ subnet_id=self.subnet['id'],
+ pool_id=pool['id'])
self.assertEqual('201', resp['status'])
vip = body['vip']
vip_id = vip['id']
# Verification of vip update
new_name = "New_vip"
- resp, body = self.client.update_vip(vip_id, new_name)
+ resp, body = self.client.update_vip(vip_id, name=new_name)
self.assertEqual('200', resp['status'])
updated_vip = body['vip']
self.assertEqual(updated_vip['name'], new_name)
@@ -143,11 +153,10 @@
self.assertEqual('201', resp['status'])
member = body['member']
# Verification of member update
- admin_state = [False, 'False']
- resp, body = self.client.update_member(admin_state[0], member['id'])
+ resp, body = self.client.update_member(False, member['id'])
self.assertEqual('200', resp['status'])
updated_member = body['member']
- self.assertIn(updated_member['admin_state_up'], admin_state)
+ self.assertFalse(updated_member['admin_state_up'])
# Verification of member delete
resp, body = self.client.delete_member(member['id'])
self.assertEqual('204', resp['status'])
@@ -174,16 +183,19 @@
@test.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)
+ resp, body = self.client.create_health_monitor(delay=4,
+ max_retries=3,
+ type="TCP",
+ timeout=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'])
+ resp, body = (self.client.update_health_monitor
+ (health_monitor['id'],
+ admin_state_up=False))
self.assertEqual('200', resp['status'])
updated_health_monitor = body['health_monitor']
- self.assertIn(updated_health_monitor['admin_state_up'], admin_state)
+ self.assertFalse(updated_health_monitor['admin_state_up'])
# Verification of health_monitor delete
resp, body = self.client.delete_health_monitor(health_monitor['id'])
self.assertEqual('204', resp['status'])
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index 1458c7b..0d00c75 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -193,34 +193,6 @@
body = json.loads(body)
return resp, body
- def create_vip(self, name, protocol, protocol_port, subnet_id, pool_id):
- post_body = {
- "vip": {
- "protocol": protocol,
- "name": name,
- "subnet_id": subnet_id,
- "pool_id": pool_id,
- "protocol_port": protocol_port
- }
- }
- body = json.dumps(post_body)
- uri = '%s/lb/vips' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
-
- def update_vip(self, vip_id, new_name):
- put_body = {
- "vip": {
- "name": new_name,
- }
- }
- body = json.dumps(put_body)
- uri = '%s/lb/vips/%s' % (self.uri_prefix, vip_id)
- resp, body = self.put(uri, body)
- body = json.loads(body)
- return resp, body
-
def create_member(self, address, protocol_port, pool_id):
post_body = {
"member": {
@@ -247,33 +219,6 @@
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, body)
- body = json.loads(body)
- 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 = 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 720c842..18b99d1 100644
--- a/tempest/services/network/xml/network_client.py
+++ b/tempest/services/network/xml/network_client.py
@@ -101,32 +101,6 @@
body = _root_tag_fetcher_and_xml_to_json_parse(body)
return resp, body
- def create_vip(self, name, protocol, protocol_port, subnet_id, pool_id):
- uri = '%s/lb/vips' % (self.uri_prefix)
- post_body = Element("vip")
- p1 = Element("name", name)
- p2 = Element("protocol", protocol)
- p3 = Element("protocol_port", protocol_port)
- p4 = Element("subnet_id", subnet_id)
- p5 = Element("pool_id", pool_id)
- post_body.append(p1)
- post_body.append(p2)
- post_body.append(p3)
- post_body.append(p4)
- post_body.append(p5)
- resp, body = self.post(uri, str(Document(post_body)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
-
- def update_vip(self, vip_id, new_name):
- uri = '%s/lb/vips/%s' % (self.uri_prefix, str(vip_id))
- put_body = Element("vip")
- p2 = Element("name", new_name)
- put_body.append(p2)
- resp, body = self.put(uri, str(Document(put_body)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
-
def create_member(self, address, protocol_port, pool_id):
uri = '%s/lb/members' % (self.uri_prefix)
post_body = Element("member")
@@ -149,30 +123,6 @@
body = _root_tag_fetcher_and_xml_to_json_parse(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)))
- 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)))
- 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,