Use lb_id (load balancer) in Octavia services/scenario
As suggested by Andrey, we should have a consistent format for the arguments in the octavia services. It makes sense to use just the id of the resource rather than the entire dict. This patch fixes the load balancer resource Change-Id: If642649c078e1182807582c287141509579b2d21 Signed-off-by: Lucas H. Xu <hanxu@redhat.com>
This commit is contained in:
parent
a43d507546
commit
6832082aa5
@ -104,7 +104,7 @@ class CreateAndDeleteLoadbalancers(octavia_utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
self.octavia.load_balancer_delete(
|
||||
loadbalancer["loadbalancer"]["id"])
|
||||
loadbalancer["id"])
|
||||
|
||||
|
||||
@validation.add("required_services", services=[consts.Service.OCTAVIA])
|
||||
@ -151,7 +151,7 @@ class CreateAndUpdateLoadBalancers(octavia_utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
self.octavia.load_balancer_set(
|
||||
lb_id=loadbalancer["loadbalancer"]["id"],
|
||||
lb_id=loadbalancer["id"],
|
||||
lb_update_args=update_loadbalancer)
|
||||
|
||||
|
||||
@ -195,7 +195,7 @@ class CreateAndShowStatsLoadBalancers(octavia_utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
self.octavia.load_balancer_stats_show(
|
||||
loadbalancer["loadbalancer"])
|
||||
loadbalancer["id"])
|
||||
|
||||
|
||||
@validation.add("required_services", services=[consts.Service.OCTAVIA])
|
||||
@ -238,4 +238,4 @@ class CreateAndShowLoadBalancers(octavia_utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
self.octavia.load_balancer_show(
|
||||
loadbalancer["loadbalancer"])
|
||||
loadbalancer["id"])
|
||||
|
@ -49,7 +49,7 @@ class CreateAndListPools(utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
self.octavia.pool_create(
|
||||
lb_id=loadbalancer["loadbalancer"]["id"],
|
||||
lb_id=loadbalancer["id"],
|
||||
protocol=protocol, lb_algorithm=lb_algorithm)
|
||||
self.octavia.pool_list()
|
||||
|
||||
@ -81,7 +81,7 @@ class CreateAndDeletePools(utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
pools = self.octavia.pool_create(
|
||||
lb_id=loadbalancer["loadbalancer"]["id"],
|
||||
lb_id=loadbalancer["id"],
|
||||
protocol=protocol, lb_algorithm=lb_algorithm)
|
||||
self.octavia.pool_delete(pools["id"])
|
||||
|
||||
@ -117,7 +117,7 @@ class CreateAndUpdatePools(utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
pools = self.octavia.pool_create(
|
||||
lb_id=loadbalancer["loadbalancer"]["id"],
|
||||
lb_id=loadbalancer["id"],
|
||||
protocol=protocol, lb_algorithm=lb_algorithm)
|
||||
self.octavia.pool_set(
|
||||
pool_id=pools["id"], pool_update_args=update_pool)
|
||||
@ -150,6 +150,6 @@ class CreateAndShowPools(utils.OctaviaBase):
|
||||
for loadbalancer in loadbalancers:
|
||||
self.octavia.wait_for_loadbalancer_prov_status(loadbalancer)
|
||||
pools = self.octavia.pool_create(
|
||||
lb_id=loadbalancer["loadbalancer"]["id"],
|
||||
lb_id=loadbalancer["id"],
|
||||
protocol=protocol, lb_algorithm=lb_algorithm)
|
||||
self.octavia.pool_show(pools["id"])
|
||||
|
@ -36,7 +36,7 @@ class Octavia(service.Service):
|
||||
return self._clients.octavia().load_balancer_list()
|
||||
|
||||
@atomic.action_timer("octavia.load_balancer_show")
|
||||
def load_balancer_show(self, lb):
|
||||
def load_balancer_show(self, lb_id):
|
||||
"""Show a load balancer
|
||||
|
||||
:param string lb:
|
||||
@ -44,7 +44,13 @@ class Octavia(service.Service):
|
||||
:return:
|
||||
A dict of the specified load balancer's settings
|
||||
"""
|
||||
return self._clients.octavia().load_balancer_show(lb["id"])
|
||||
try:
|
||||
new_lb = self._clients.octavia().load_balancer_show(lb_id)
|
||||
except Exception as e:
|
||||
if getattr(e, "code", 400) == 404:
|
||||
raise exceptions.GetResourceNotFound(resource=lb_id)
|
||||
raise exceptions.GetResourceFailure(resource=lb_id, err=e)
|
||||
return new_lb
|
||||
|
||||
@atomic.action_timer("octavia.load_balancer_create")
|
||||
def load_balancer_create(self, subnet_id, description=None,
|
||||
@ -64,8 +70,9 @@ class Octavia(service.Service):
|
||||
"vip_subnet_id": subnet_id,
|
||||
"vip_qos_policy_id": vip_qos_policy_id,
|
||||
}
|
||||
return self._clients.octavia().load_balancer_create(
|
||||
lb = self._clients.octavia().load_balancer_create(
|
||||
json={"loadbalancer": args})
|
||||
return lb["loadbalancer"]
|
||||
|
||||
@atomic.action_timer("octavia.load_balancer_delete")
|
||||
def load_balancer_delete(self, lb_id, cascade=False):
|
||||
@ -94,7 +101,7 @@ class Octavia(service.Service):
|
||||
lb_id, json={"loadbalancer": lb_update_args})
|
||||
|
||||
@atomic.action_timer("octavia.load_balancer_stats_show")
|
||||
def load_balancer_stats_show(self, lb, **kwargs):
|
||||
def load_balancer_stats_show(self, lb_id, **kwargs):
|
||||
"""Shows the current statistics for a load balancer.
|
||||
|
||||
:param string lb:
|
||||
@ -103,10 +110,10 @@ class Octavia(service.Service):
|
||||
A dict of the specified load balancer's statistics
|
||||
"""
|
||||
return self._clients.octavia().load_balancer_stats_show(
|
||||
lb["id"], **kwargs)
|
||||
lb_id, **kwargs)
|
||||
|
||||
@atomic.action_timer("octavia.load_balancer_failover")
|
||||
def load_balancer_failover(self, lb):
|
||||
def load_balancer_failover(self, lb_id):
|
||||
"""Trigger load balancer failover
|
||||
|
||||
:param string lb:
|
||||
@ -114,7 +121,7 @@ class Octavia(service.Service):
|
||||
:return:
|
||||
Response Code from the API
|
||||
"""
|
||||
return self._clients.octavia().load_balancer_failover(lb["id"])
|
||||
return self._clients.octavia().load_balancer_failover(lb_id)
|
||||
|
||||
@atomic.action_timer("octavia.listener_list")
|
||||
def listener_list(self, **kwargs):
|
||||
@ -609,23 +616,13 @@ class Octavia(service.Service):
|
||||
"""
|
||||
return self._clients.octavia().amphora_list(**kwargs)
|
||||
|
||||
def update_loadbalancer_resource(self, lb):
|
||||
try:
|
||||
new_lb = self._clients.octavia().load_balancer_show(
|
||||
lb["id"])
|
||||
except Exception as e:
|
||||
if getattr(e, "status_code", 400) == 404:
|
||||
raise exceptions.GetResourceNotFound(resource=lb)
|
||||
raise exceptions.GetResourceFailure(resource=lb, err=e)
|
||||
return new_lb
|
||||
|
||||
@atomic.action_timer("octavia.wait_for_loadbalancers")
|
||||
def wait_for_loadbalancer_prov_status(self, lb, prov_status="ACTIVE"):
|
||||
return utils.wait_for_status(
|
||||
lb["loadbalancer"],
|
||||
lb,
|
||||
ready_statuses=[prov_status],
|
||||
status_attr="provisioning_status",
|
||||
update_resource=self.update_loadbalancer_resource,
|
||||
update_resource=lambda lb: self.load_balancer_show(lb["id"]),
|
||||
timeout=CONF.openstack.octavia_create_loadbalancer_timeout,
|
||||
check_interval=(
|
||||
CONF.openstack.octavia_create_loadbalancer_poll_interval)
|
||||
|
@ -61,12 +61,29 @@ class LoadBalancerServiceTestCase(test.TestCase):
|
||||
|
||||
def test_load_balancer_show(self):
|
||||
lb = {"id": "loadbalancer-id"}
|
||||
self.service.load_balancer_show(lb)
|
||||
self.service.load_balancer_show(lb["id"])
|
||||
self.service._clients.octavia().load_balancer_show \
|
||||
.assert_called_once_with(lb["id"])
|
||||
self._test_atomic_action_timer(self.atomic_actions(),
|
||||
"octavia.load_balancer_show")
|
||||
|
||||
def test_load_balancer_show_fail_404(self):
|
||||
fake_lb = {"id": "fake_lb"}
|
||||
ex = Exception()
|
||||
ex.code = 404
|
||||
self.service._clients.octavia().load_balancer_show.side_effect = ex
|
||||
self.assertRaises(
|
||||
exceptions.GetResourceNotFound,
|
||||
self.service.load_balancer_show, fake_lb["id"])
|
||||
|
||||
def test_load_balancer_show_resource_fail(self):
|
||||
fake_lb = {"id": "fake_lb"}
|
||||
ex = Exception()
|
||||
self.service._clients.octavia().load_balancer_show.side_effect = ex
|
||||
self.assertRaises(
|
||||
exceptions.GetResourceFailure,
|
||||
self.service.load_balancer_show, fake_lb["id"])
|
||||
|
||||
def test_load_balancer_create(self):
|
||||
self.service.generate_random_name = mock.MagicMock(
|
||||
return_value="lb")
|
||||
@ -113,7 +130,7 @@ class LoadBalancerServiceTestCase(test.TestCase):
|
||||
|
||||
def test_load_balancer_failover(self):
|
||||
lb = {"id": "new_lb"}
|
||||
self.service.load_balancer_failover(lb)
|
||||
self.service.load_balancer_failover(lb["id"])
|
||||
self.service._clients.octavia().load_balancer_failover \
|
||||
.assert_called_once_with(lb["id"])
|
||||
self._test_atomic_action_timer(self.atomic_actions(),
|
||||
@ -432,32 +449,9 @@ class LoadBalancerServiceTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.atomic_actions(),
|
||||
"octavia.amphora_list")
|
||||
|
||||
def test_update_loadbalancer_resource(self):
|
||||
fake_lb = {"id": "fake_lb"}
|
||||
self.service.update_loadbalancer_resource(lb=fake_lb)
|
||||
self.service._clients.octavia().load_balancer_show \
|
||||
.assert_called_once_with("fake_lb")
|
||||
|
||||
def test_update_loadbalancer_resource_fail_404(self):
|
||||
fake_lb = {"id": "fake_lb"}
|
||||
ex = Exception()
|
||||
ex.status_code = 404
|
||||
self.service._clients.octavia().load_balancer_show.side_effect = ex
|
||||
self.assertRaises(
|
||||
exceptions.GetResourceNotFound,
|
||||
self.service.update_loadbalancer_resource, fake_lb)
|
||||
|
||||
def test_update_loadbalancer_resource_fail(self):
|
||||
fake_lb = {"id": "fake_lb"}
|
||||
ex = Exception()
|
||||
self.service._clients.octavia().load_balancer_show.side_effect = ex
|
||||
self.assertRaises(
|
||||
exceptions.GetResourceFailure,
|
||||
self.service.update_loadbalancer_resource, fake_lb)
|
||||
|
||||
@mock.patch("%s.Ocvita.wait_for_loadbalancer_prov_status" % BASE_PATH)
|
||||
def wait_for_loadbalancer_prov_status(self, mock_wait_for_status):
|
||||
fake_lb = {"loadbalancer": {}}
|
||||
fake_lb = {}
|
||||
self.service.wait_for_loadbalancer_prov_status(lb=fake_lb)
|
||||
self.assertTrue(mock_wait_for_status.called)
|
||||
self._test_atomic_action_timer(self.atomic_actions(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user