From e9e6ee845f7db90bc103c73c646007c415026596 Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Thu, 9 Feb 2017 16:42:57 +0800 Subject: [PATCH] use 'true' and 'false' instead of magic num Change-Id: I29282661cd3efc735bc9c12f771d13d0d3fcc9a2 Signed-off-by: dongwenjuan --- vitrage/api/controllers/v1/alarm.py | 8 +++---- vitrage/api/controllers/v1/rca.py | 6 ++--- vitrage/api/controllers/v1/topology.py | 2 +- vitrage/api_handler/apis/alarm.py | 2 +- vitrage/api_handler/apis/rca.py | 2 +- .../tests/functional/api_handler/test_apis.py | 20 ++++++++--------- vitrage_tempest_tests/tests/api/base.py | 2 +- .../tests/api/datasources/test_aodh.py | 4 ++-- .../api/datasources/test_cinder_volume.py | 2 +- .../tests/api/datasources/test_heat_stack.py | 2 +- .../tests/api/datasources/test_neutron.py | 2 +- .../tests/api/datasources/test_nova.py | 2 +- .../api/datasources/test_static_physical.py | 2 +- .../tests/api/rca/test_rca.py | 2 +- .../tests/api/topology/base.py | 2 +- .../tests/api/topology/test_topology.py | 22 +++++++++---------- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/vitrage/api/controllers/v1/alarm.py b/vitrage/api/controllers/v1/alarm.py index fdfe073c2..f24d610c6 100644 --- a/vitrage/api/controllers/v1/alarm.py +++ b/vitrage/api/controllers/v1/alarm.py @@ -30,12 +30,12 @@ LOG = log.getLogger(__name__) class AlarmsController(RootRestController): @pecan.expose('json') - def index(self, vitrage_id, all_tenants='0'): + def index(self, vitrage_id, all_tenants=False): return self.post(vitrage_id, all_tenants) @pecan.expose('json') - def post(self, vitrage_id, all_tenants='0'): - if all_tenants == '1': + def post(self, vitrage_id, all_tenants=False): + if all_tenants: enforce("list alarms:all_tenants", pecan.request.headers, pecan.request.enforcer, {}) else: @@ -52,7 +52,7 @@ class AlarmsController(RootRestController): abort(404, str(e)) @staticmethod - def _get_alarms(vitrage_id=None, all_tenants=0): + def _get_alarms(vitrage_id=None, all_tenants=False): alarms_json = pecan.request.client.call(pecan.request.context, 'get_alarms', vitrage_id=vitrage_id, diff --git a/vitrage/api/controllers/v1/rca.py b/vitrage/api/controllers/v1/rca.py index 1d22e647b..db5d114ad 100644 --- a/vitrage/api/controllers/v1/rca.py +++ b/vitrage/api/controllers/v1/rca.py @@ -30,12 +30,12 @@ LOG = log.getLogger(__name__) class RCAController(RootRestController): @pecan.expose('json') - def index(self, alarm_id, all_tenants='0'): + def index(self, alarm_id, all_tenants=False): return self.get(alarm_id, all_tenants) @pecan.expose('json') - def get(self, alarm_id, all_tenants='0'): - if all_tenants == '1': + def get(self, alarm_id, all_tenants=False): + if all_tenants: enforce('get rca:all_tenants', pecan.request.headers, pecan.request.enforcer, {}) else: diff --git a/vitrage/api/controllers/v1/topology.py b/vitrage/api/controllers/v1/topology.py index 8211f2844..c0207ce7f 100644 --- a/vitrage/api/controllers/v1/topology.py +++ b/vitrage/api/controllers/v1/topology.py @@ -34,7 +34,7 @@ LOG = log.getLogger(__name__) class TopologyController(RootRestController): @pecan.expose('json') - def post(self, depth, graph_type, query, root, all_tenants=0): + def post(self, depth, graph_type, query, root, all_tenants=False): if all_tenants: enforce('get topology:all_tenants', pecan.request.headers, pecan.request.enforcer, {}) diff --git a/vitrage/api_handler/apis/alarm.py b/vitrage/api_handler/apis/alarm.py index 8e3c419df..9c88231f2 100644 --- a/vitrage/api_handler/apis/alarm.py +++ b/vitrage/api_handler/apis/alarm.py @@ -39,7 +39,7 @@ class AlarmApis(EntityGraphApisBase): is_admin_project = ctx.get(self.IS_ADMIN_PROJECT_PROPERTY, False) if not vitrage_id or vitrage_id == 'all': - if all_tenants == "1": + if all_tenants: alarms = self.entity_graph.get_vertices( query_dict=ALARMS_ALL_QUERY) else: diff --git a/vitrage/api_handler/apis/rca.py b/vitrage/api_handler/apis/rca.py index 7c04b173c..c5a6e1029 100644 --- a/vitrage/api_handler/apis/rca.py +++ b/vitrage/api_handler/apis/rca.py @@ -47,7 +47,7 @@ class RcaApis(EntityGraphApisBase): direction=Direction.IN, edge_query_dict=EDGE_QUERY) - if all_tenants == '1': + if all_tenants: unified_graph = found_graph_in unified_graph.union(found_graph_out) else: diff --git a/vitrage/tests/functional/api_handler/test_apis.py b/vitrage/tests/functional/api_handler/test_apis.py index bf862cb94..9d4721fd4 100644 --- a/vitrage/tests/functional/api_handler/test_apis.py +++ b/vitrage/tests/functional/api_handler/test_apis.py @@ -37,7 +37,7 @@ class TestApis(TestEntityGraphUnitBase): ctx = {'tenant': 'project_1', 'is_admin': True} # Action - alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants='0') + alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False) alarms = json.loads(alarms)['alarms'] # Test assertions @@ -51,7 +51,7 @@ class TestApis(TestEntityGraphUnitBase): ctx = {'tenant': 'project_2', 'is_admin': False} # Action - alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants='0') + alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False) alarms = json.loads(alarms)['alarms'] # Test assertions @@ -65,7 +65,7 @@ class TestApis(TestEntityGraphUnitBase): ctx = {'tenant': 'project_1', 'is_admin': False} # Action - alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants='1') + alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=True) alarms = json.loads(alarms)['alarms'] # Test assertions @@ -79,7 +79,7 @@ class TestApis(TestEntityGraphUnitBase): ctx = {'tenant': 'project_1', 'is_admin': True} # Action - graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants='0') + graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False) graph_rca = json.loads(graph_rca) # Test assertions @@ -95,7 +95,7 @@ class TestApis(TestEntityGraphUnitBase): # Action graph_rca = apis.get_rca(ctx, root='alarm_on_instance_3', - all_tenants='0') + all_tenants=False) graph_rca = json.loads(graph_rca) # Test assertions @@ -109,7 +109,7 @@ class TestApis(TestEntityGraphUnitBase): ctx = {'tenant': 'project_2', 'is_admin': False} # Action - graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants='0') + graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False) graph_rca = json.loads(graph_rca) # Test assertions @@ -123,7 +123,7 @@ class TestApis(TestEntityGraphUnitBase): ctx = {'tenant': 'project_1', 'is_admin': False} # Action - graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants='1') + graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=True) graph_rca = json.loads(graph_rca) # Test assertions @@ -143,7 +143,7 @@ class TestApis(TestEntityGraphUnitBase): depth=10, query=None, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=0) + all_tenants=False) graph_topology = json.loads(graph_topology) # Test assertions @@ -165,7 +165,7 @@ class TestApis(TestEntityGraphUnitBase): depth=10, query=None, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=0) + all_tenants=False) graph_topology = json.loads(graph_topology) # Test assertions @@ -187,7 +187,7 @@ class TestApis(TestEntityGraphUnitBase): depth=10, query=None, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=1) + all_tenants=True) graph_topology = json.loads(graph_topology) # Test assertions diff --git a/vitrage_tempest_tests/tests/api/base.py b/vitrage_tempest_tests/tests/api/base.py index 70bbdb6c5..4b5842c12 100644 --- a/vitrage_tempest_tests/tests/api/base.py +++ b/vitrage_tempest_tests/tests/api/base.py @@ -118,7 +118,7 @@ class BaseApiTest(base.BaseTestCase): return volume def _get_host(self): - topology = self.vitrage_client.topology.get(all_tenants=1) + topology = self.vitrage_client.topology.get(all_tenants=True) host = filter(lambda item: item[VProps.TYPE] == NOVA_HOST_DATASOURCE, topology['nodes']) return host[0] diff --git a/vitrage_tempest_tests/tests/api/datasources/test_aodh.py b/vitrage_tempest_tests/tests/api/datasources/test_aodh.py index 112459eb4..5b1eb5e10 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_aodh.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_aodh.py @@ -38,7 +38,7 @@ class TestAodhAlarm(BaseAlarmsTest): self._create_ceilometer_alarm(self._find_instance_resource_id()) # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, @@ -73,7 +73,7 @@ class TestAodhAlarm(BaseAlarmsTest): self._create_ceilometer_alarm() # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, diff --git a/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py b/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py index f4f435051..b1d4b4f88 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py @@ -37,7 +37,7 @@ class TestCinderVolume(BaseTopologyTest): num_volumes=self.NUM_VOLUME) # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, diff --git a/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py b/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py index 84e55a4b9..f5ca5c57d 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py @@ -42,7 +42,7 @@ class TestHeatStack(BaseTopologyTest): self._create_stacks(num_stacks=self.NUM_STACKS) # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, diff --git a/vitrage_tempest_tests/tests/api/datasources/test_neutron.py b/vitrage_tempest_tests/tests/api/datasources/test_neutron.py index f9c9cd1cc..e527ef566 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_neutron.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_neutron.py @@ -43,7 +43,7 @@ class TestNeutron(BaseTopologyTest): set_public_network=True) # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, diff --git a/vitrage_tempest_tests/tests/api/datasources/test_nova.py b/vitrage_tempest_tests/tests/api/datasources/test_nova.py index 38a2339a4..98cf9cb34 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_nova.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_nova.py @@ -35,7 +35,7 @@ class TestNova(BaseTopologyTest): self._create_entities(num_instances=self.NUM_INSTANCE) # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, diff --git a/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py b/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py index a20b4c6e9..503b9032c 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py @@ -39,7 +39,7 @@ class TestStaticPhysical(BaseApiTest): self._create_switches() # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, diff --git a/vitrage_tempest_tests/tests/api/rca/test_rca.py b/vitrage_tempest_tests/tests/api/rca/test_rca.py index 279ade57b..efea5148f 100644 --- a/vitrage_tempest_tests/tests/api/rca/test_rca.py +++ b/vitrage_tempest_tests/tests/api/rca/test_rca.py @@ -128,7 +128,7 @@ class TestRca(BaseRcaTest): self._create_alarm( resource_id=self._get_hostname(), alarm_name=RCA_ALARM_NAME) - topology = self.vitrage_client.topology.get(all_tenants=1) + topology = self.vitrage_client.topology.get(all_tenants=True) self._validate_set_state(topology=topology['nodes'], instances=instances) diff --git a/vitrage_tempest_tests/tests/api/topology/base.py b/vitrage_tempest_tests/tests/api/topology/base.py index 43e36e506..7cb6efb6a 100644 --- a/vitrage_tempest_tests/tests/api/topology/base.py +++ b/vitrage_tempest_tests/tests/api/topology/base.py @@ -36,7 +36,7 @@ class BaseTopologyTest(BaseApiTest): api_graph = self.vitrage_client.topology.get( limit=4, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=1) + all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data() num_default_entities = self.num_default_entities + \ diff --git a/vitrage_tempest_tests/tests/api/topology/test_topology.py b/vitrage_tempest_tests/tests/api/topology/test_topology.py index 48e1c6a28..66493b6ee 100644 --- a/vitrage_tempest_tests/tests/api/topology/test_topology.py +++ b/vitrage_tempest_tests/tests/api/topology/test_topology.py @@ -67,7 +67,7 @@ class TestTopology(BaseTopologyTest): num_volumes=self.NUM_VOLUME) # Calculate expected results - api_graph = self.vitrage_client.topology.get(all_tenants=1) + api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, @@ -109,7 +109,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( query=self._graph_query(), - all_tenants=1) + all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, @@ -144,7 +144,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( - graph_type='tree', query=NOVA_QUERY, all_tenants=1) + graph_type='tree', query=NOVA_QUERY, all_tenants=True) graph = self._create_graph_from_tree_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, @@ -179,7 +179,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( - graph_type='tree', query=self._tree_query(), all_tenants=1) + graph_type='tree', query=self._tree_query(), all_tenants=True) graph = self._create_graph_from_tree_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1) @@ -209,7 +209,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( - limit=2, graph_type='tree', query=NOVA_QUERY, all_tenants=1) + limit=2, graph_type='tree', query=NOVA_QUERY, all_tenants=True) graph = self._create_graph_from_tree_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1) @@ -239,7 +239,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( - limit=3, graph_type='tree', query=NOVA_QUERY, all_tenants=1) + limit=3, graph_type='tree', query=NOVA_QUERY, all_tenants=True) graph = self._create_graph_from_tree_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, @@ -277,7 +277,7 @@ class TestTopology(BaseTopologyTest): api_graph = self.vitrage_client.topology.get( limit=2, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=1) + all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1) @@ -310,7 +310,7 @@ class TestTopology(BaseTopologyTest): api_graph = self.vitrage_client.topology.get( limit=3, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=1) + all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, @@ -348,7 +348,7 @@ class TestTopology(BaseTopologyTest): self.vitrage_client.topology.get( limit=2, root='RESOURCE:openstack.cluster:OpenStack Cluster', - all_tenants=1) + all_tenants=True) except ClientException as e: self.assertEqual(403, e.code) self.assertEqual( @@ -372,7 +372,7 @@ class TestTopology(BaseTopologyTest): # Calculate expected results api_graph = self.vitrage_client.topology.get( - query=self._graph_no_match_query(), all_tenants=1) + query=self._graph_no_match_query(), all_tenants=True) # Test Assertions self.assertEqual( @@ -403,7 +403,7 @@ class TestTopology(BaseTopologyTest): api_graph = self.vitrage_client.topology.get( graph_type='tree', query=self._tree_no_match_query(), - all_tenants=1) + all_tenants=True) # Test Assertions self.assertEqual({}, api_graph)