Merge "Don't show deleted objects in v2 API"
This commit is contained in:
commit
8fdcb88dee
@ -76,7 +76,7 @@ class HealthMonitorController(base.BaseController):
|
||||
else:
|
||||
project_id = {'project_id': context.project_id}
|
||||
db_hm = self.repositories.health_monitor.get_all(
|
||||
context.session, **project_id)
|
||||
context.session, show_deleted=False, **project_id)
|
||||
result = self._convert_db_to_type(
|
||||
db_hm, [hm_types.HealthMonitorResponse])
|
||||
return hm_types.HealthMonitorsRootResponse(healthmonitors=result)
|
||||
|
@ -63,7 +63,7 @@ class L7PolicyController(base.BaseController):
|
||||
else:
|
||||
project_id = {'project_id': context.project_id}
|
||||
db_l7policies = self.repositories.l7policy.get_all(
|
||||
context.session, **project_id)
|
||||
context.session, show_deleted=False, **project_id)
|
||||
result = self._convert_db_to_type(db_l7policies,
|
||||
[l7policy_types.L7PolicyResponse])
|
||||
return l7policy_types.L7PoliciesRootResponse(l7policies=result)
|
||||
|
@ -54,7 +54,7 @@ class L7RuleController(base.BaseController):
|
||||
"""Lists all l7rules of a l7policy."""
|
||||
context = pecan.request.context.get('octavia_context')
|
||||
db_l7rules = self.repositories.l7rule.get_all(
|
||||
context.session, l7policy_id=self.l7policy_id)
|
||||
context.session, show_deleted=False, l7policy_id=self.l7policy_id)
|
||||
result = self._convert_db_to_type(db_l7rules,
|
||||
[l7rule_types.L7RuleResponse])
|
||||
return l7rule_types.L7RulesRootResponse(rules=result)
|
||||
|
@ -75,7 +75,7 @@ class ListenersController(base.BaseController):
|
||||
else:
|
||||
project_id = {'project_id': context.project_id}
|
||||
db_listeners = self.repositories.listener.get_all(
|
||||
context.session, **project_id)
|
||||
context.session, show_deleted=False, **project_id)
|
||||
result = self._convert_db_to_type(db_listeners,
|
||||
[listener_types.ListenerResponse])
|
||||
return listener_types.ListenersRootResponse(listeners=result)
|
||||
|
@ -64,7 +64,7 @@ class LoadBalancersController(base.BaseController):
|
||||
else:
|
||||
project_id = {'project_id': context.project_id}
|
||||
load_balancers = self.repositories.load_balancer.get_all(
|
||||
context.session, **project_id)
|
||||
context.session, show_deleted=False, **project_id)
|
||||
result = self._convert_db_to_type(load_balancers,
|
||||
[lb_types.LoadBalancerResponse])
|
||||
return lb_types.LoadBalancersRootResponse(loadbalancers=result)
|
||||
|
@ -55,7 +55,7 @@ class MembersController(base.BaseController):
|
||||
"""Lists all pool members of a pool."""
|
||||
context = pecan.request.context.get('octavia_context')
|
||||
db_members = self.repositories.member.get_all(
|
||||
context.session, pool_id=self.pool_id)
|
||||
context.session, show_deleted=False, pool_id=self.pool_id)
|
||||
result = self._convert_db_to_type(
|
||||
db_members, [member_types.MemberResponse])
|
||||
return member_types.MembersRootResponse(members=result)
|
||||
|
@ -63,7 +63,7 @@ class PoolsController(base.BaseController):
|
||||
else:
|
||||
project_id = {'project_id': context.project_id}
|
||||
db_pools = self.repositories.pool.get_all(
|
||||
context.session, **project_id)
|
||||
context.session, show_deleted=False, **project_id)
|
||||
result = self._convert_db_to_type(db_pools, [pool_types.PoolResponse])
|
||||
return pool_types.PoolsRootResponse(pools=result)
|
||||
|
||||
|
@ -109,7 +109,12 @@ class BaseRepository(object):
|
||||
:param filters: Filters to decide which entities should be retrieved.
|
||||
:returns: [octavia.common.data_model]
|
||||
"""
|
||||
model_list = session.query(self.model_class).filter_by(**filters).all()
|
||||
deleted = filters.pop('show_deleted', True)
|
||||
model_list = session.query(self.model_class).filter_by(**filters)
|
||||
if not deleted:
|
||||
model_list = model_list.filter(
|
||||
self.model_class.provisioning_status != consts.DELETED)
|
||||
model_list = model_list.all()
|
||||
data_model_list = [model.to_data_model() for model in model_list]
|
||||
return data_model_list
|
||||
|
||||
@ -1143,8 +1148,13 @@ class L7PolicyRepository(BaseRepository):
|
||||
listener.load_balancer_id, listener.project_id)
|
||||
|
||||
def get_all(self, session, **filters):
|
||||
l7policy_list = session.query(self.model_class).filter_by(
|
||||
**filters).order_by(self.model_class.position).all()
|
||||
deleted = filters.pop('show_deleted', True)
|
||||
l7policy_list = session.query(self.model_class).filter_by(**filters)
|
||||
if not deleted:
|
||||
l7policy_list = l7policy_list.filter(
|
||||
self.model_class.provisioning_status != consts.DELETED)
|
||||
|
||||
l7policy_list = l7policy_list.order_by(self.model_class.position).all()
|
||||
data_model_list = [p.to_data_model() for p in l7policy_list]
|
||||
return data_model_list
|
||||
|
||||
|
@ -253,9 +253,9 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
|
||||
|
||||
def _set_lb_and_children_statuses(self, lb_id, prov_status, op_status,
|
||||
autodetect=True):
|
||||
self.lb_repo.update(db_api.get_session(), lb_id,
|
||||
provisioning_status=prov_status,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.lb_repo, lb_id,
|
||||
provisioning_status=prov_status,
|
||||
operating_status=op_status)
|
||||
lb_listeners = self.listener_repo.get_all(db_api.get_session(),
|
||||
load_balancer_id=lb_id)
|
||||
for listener in lb_listeners:
|
||||
@ -264,9 +264,9 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
|
||||
listener_prov = constants.DELETED
|
||||
else:
|
||||
listener_prov = prov_status
|
||||
self.listener_repo.update(db_api.get_session(), listener.id,
|
||||
provisioning_status=listener_prov,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.listener_repo, listener.id,
|
||||
provisioning_status=listener_prov,
|
||||
operating_status=op_status)
|
||||
lb_l7policies = self.l7policy_repo.get_all(db_api.get_session(),
|
||||
listener_id=listener.id)
|
||||
for l7policy in lb_l7policies:
|
||||
@ -275,9 +275,9 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
|
||||
l7policy_prov = constants.DELETED
|
||||
else:
|
||||
l7policy_prov = prov_status
|
||||
self.l7policy_repo.update(db_api.get_session(), l7policy.id,
|
||||
provisioning_status=l7policy_prov,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.l7policy_repo, l7policy.id,
|
||||
provisioning_status=l7policy_prov,
|
||||
operating_status=op_status)
|
||||
l7rules = self.l7rule_repo.get_all(db_api.get_session(),
|
||||
l7policy_id=l7policy.id)
|
||||
for l7rule in l7rules:
|
||||
@ -286,9 +286,9 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
|
||||
l7rule_prov = constants.DELETED
|
||||
else:
|
||||
l7rule_prov = prov_status
|
||||
self.l7rule_repo.update(db_api.get_session(), l7rule.id,
|
||||
provisioning_status=l7rule_prov,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.l7rule_repo, l7rule.id,
|
||||
provisioning_status=l7rule_prov,
|
||||
operating_status=op_status)
|
||||
lb_pools = self.pool_repo.get_all(db_api.get_session(),
|
||||
load_balancer_id=lb_id)
|
||||
for pool in lb_pools:
|
||||
@ -297,28 +297,28 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
|
||||
pool_prov = constants.DELETED
|
||||
else:
|
||||
pool_prov = prov_status
|
||||
self.pool_repo.update(db_api.get_session(), pool.id,
|
||||
provisioning_status=pool_prov,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.pool_repo, pool.id,
|
||||
provisioning_status=pool_prov,
|
||||
operating_status=op_status)
|
||||
for member in pool.members:
|
||||
if autodetect and (member.provisioning_status ==
|
||||
constants.PENDING_DELETE):
|
||||
member_prov = constants.DELETED
|
||||
else:
|
||||
member_prov = prov_status
|
||||
self.member_repo.update(db_api.get_session(), member.id,
|
||||
provisioning_status=member_prov,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.member_repo, member.id,
|
||||
provisioning_status=member_prov,
|
||||
operating_status=op_status)
|
||||
if pool.health_monitor:
|
||||
if autodetect and (pool.health_monitor.provisioning_status ==
|
||||
constants.PENDING_DELETE):
|
||||
hm_prov = constants.DELETED
|
||||
else:
|
||||
hm_prov = prov_status
|
||||
self.health_monitor_repo.update(db_api.get_session(),
|
||||
pool.health_monitor.id,
|
||||
provisioning_status=hm_prov,
|
||||
operating_status=op_status)
|
||||
self.set_object_status(self.health_monitor_repo,
|
||||
pool.health_monitor.id,
|
||||
provisioning_status=hm_prov,
|
||||
operating_status=op_status)
|
||||
|
||||
def set_lb_status(self, lb_id, status=None):
|
||||
explicit_status = True if status is not None else False
|
||||
@ -335,6 +335,13 @@ class BaseAPITest(base_db_test.OctaviaDBTestBase):
|
||||
autodetect=not explicit_status)
|
||||
return self.get(self.LB_PATH.format(lb_id=lb_id)).json
|
||||
|
||||
@staticmethod
|
||||
def set_object_status(repo, id_, provisioning_status=constants.ACTIVE,
|
||||
operating_status=constants.ONLINE):
|
||||
repo.update(db_api.get_session(), id_,
|
||||
provisioning_status=provisioning_status,
|
||||
operating_status=operating_status)
|
||||
|
||||
def assert_final_lb_statuses(self, lb_id, delete=False):
|
||||
expected_prov_status = constants.ACTIVE
|
||||
expected_op_status = constants.ONLINE
|
||||
|
@ -60,6 +60,20 @@ class TestHealthMonitor(base.BaseAPITest):
|
||||
response.pop('updated_at')
|
||||
self.assertEqual(api_hm, response)
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_hm = self.create_health_monitor(
|
||||
self.pool_id, constants.HEALTH_MONITOR_HTTP,
|
||||
1, 1, 1, 1).get(self.root_tag)
|
||||
|
||||
response = self.get(self.HMS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.health_monitor_repo, api_hm.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.HMS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_bad_get(self):
|
||||
self.get(self.HM_PATH.format(
|
||||
healthmonitor_id=uuidutils.generate_uuid()), status=404)
|
||||
|
@ -51,6 +51,20 @@ class TestL7Policy(base.BaseAPITest):
|
||||
l7policy_id=api_l7policy.get('id'))).json.get(self.root_tag)
|
||||
self.assertEqual(api_l7policy, response)
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_l7policy = self.create_l7policy(
|
||||
self.listener_id,
|
||||
constants.L7POLICY_ACTION_REJECT).get(self.root_tag)
|
||||
|
||||
response = self.get(self.L7POLICIES_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.l7policy_repo, api_l7policy.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.L7POLICIES_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_bad_get(self):
|
||||
self.get(self.L7POLICY_PATH.format(
|
||||
l7policy_id=uuidutils.generate_uuid()), status=404)
|
||||
|
@ -50,6 +50,21 @@ class TestL7Rule(base.BaseAPITest):
|
||||
l7rule_id=l7rule.get('id'))).json.get(self.root_tag)
|
||||
self.assertEqual(l7rule, response)
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_l7rule = self.create_l7rule(
|
||||
self.l7policy_id, constants.L7RULE_TYPE_PATH,
|
||||
constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
|
||||
'/api').get(self.root_tag)
|
||||
|
||||
response = self.get(self.l7rules_path)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.l7rule_repo, api_l7rule.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.l7rules_path)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_get_bad_parent_policy(self):
|
||||
bad_path = (self.L7RULES_PATH.format(
|
||||
lb_id=self.lb_id, listener_id=self.listener_id,
|
||||
|
@ -138,17 +138,24 @@ class TestListener(base.BaseAPITest):
|
||||
|
||||
def test_get(self):
|
||||
listener = self.create_listener(
|
||||
constants.PROTOCOL_HTTP, 80, self.lb_id)
|
||||
listener_path = self.listener_path
|
||||
response = self.get(listener_path.format(
|
||||
listener_id=listener['listener']['id']))
|
||||
api_lb = response.json['listener']
|
||||
expected = {'name': None, 'description': None, 'admin_state_up': True,
|
||||
'operating_status': constants.OFFLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'connection_limit': None}
|
||||
listener.update(expected)
|
||||
self.assertEqual(listener['listener'], api_lb)
|
||||
constants.PROTOCOL_HTTP, 80, self.lb_id).get(self.root_tag)
|
||||
response = self.get(self.listener_path.format(
|
||||
listener_id=listener['id']))
|
||||
api_listener = response.json.get(self.root_tag)
|
||||
self.assertEqual(listener, api_listener)
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_listener = self.create_listener(
|
||||
constants.PROTOCOL_HTTP, 80, self.lb_id).get(self.root_tag)
|
||||
|
||||
response = self.get(self.LISTENERS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.listener_repo, api_listener.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.LISTENERS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_get_bad_listener_id(self):
|
||||
listener_path = self.listener_path
|
||||
|
@ -344,6 +344,19 @@ class TestLoadBalancer(base.BaseAPITest):
|
||||
self.assertEqual(network.id, response.get('vip_network_id'))
|
||||
self.assertEqual(port.id, response.get('vip_port_id'))
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_lb = self.create_load_balancer(
|
||||
uuidutils.generate_uuid()).get(self.root_tag)
|
||||
|
||||
response = self.get(self.LBS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.lb_repo, api_lb.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.LBS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_get_bad_lb_id(self):
|
||||
path = self.LB_PATH.format(lb_id='SEAN-CONNERY')
|
||||
self.get(path, status=404)
|
||||
|
@ -64,6 +64,19 @@ class TestMember(base.BaseAPITest):
|
||||
self.assertEqual(api_member, response)
|
||||
self.assertEqual(api_member.get('name'), '')
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_member = self.create_member(
|
||||
self.pool_id, '10.0.0.1', 80).get(self.root_tag)
|
||||
|
||||
response = self.get(self.members_path)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.member_repo, api_member.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.members_path)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_bad_get(self):
|
||||
self.get(self.member_path.format(member_id=uuidutils.generate_uuid()),
|
||||
status=404)
|
||||
|
@ -61,6 +61,22 @@ class TestPool(base.BaseAPITest):
|
||||
response.pop('updated_at')
|
||||
self.assertEqual(api_pool, response)
|
||||
|
||||
def test_get_hides_deleted(self):
|
||||
api_pool = self.create_pool(
|
||||
self.lb_id,
|
||||
constants.PROTOCOL_HTTP,
|
||||
constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
listener_id=self.listener_id).get(self.root_tag)
|
||||
|
||||
response = self.get(self.POOLS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 1)
|
||||
self.set_object_status(self.pool_repo, api_pool.get('id'),
|
||||
provisioning_status=constants.DELETED)
|
||||
response = self.get(self.POOLS_PATH)
|
||||
objects = response.json.get(self.root_tag_list)
|
||||
self.assertEqual(len(objects), 0)
|
||||
|
||||
def test_bad_get(self):
|
||||
self.get(self.POOL_PATH.format(pool_id=uuidutils.generate_uuid()),
|
||||
status=404)
|
||||
|
Loading…
Reference in New Issue
Block a user