Merge "use 'true' and 'false' instead of magic num"

This commit is contained in:
Jenkins 2017-02-15 12:55:29 +00:00 committed by Gerrit Code Review
commit e59816494d
16 changed files with 41 additions and 41 deletions

View File

@ -30,12 +30,12 @@ LOG = log.getLogger(__name__)
class AlarmsController(RootRestController): class AlarmsController(RootRestController):
@pecan.expose('json') @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) return self.post(vitrage_id, all_tenants)
@pecan.expose('json') @pecan.expose('json')
def post(self, vitrage_id, all_tenants='0'): def post(self, vitrage_id, all_tenants=False):
if all_tenants == '1': if all_tenants:
enforce("list alarms:all_tenants", pecan.request.headers, enforce("list alarms:all_tenants", pecan.request.headers,
pecan.request.enforcer, {}) pecan.request.enforcer, {})
else: else:
@ -52,7 +52,7 @@ class AlarmsController(RootRestController):
abort(404, str(e)) abort(404, str(e))
@staticmethod @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, alarms_json = pecan.request.client.call(pecan.request.context,
'get_alarms', 'get_alarms',
vitrage_id=vitrage_id, vitrage_id=vitrage_id,

View File

@ -30,12 +30,12 @@ LOG = log.getLogger(__name__)
class RCAController(RootRestController): class RCAController(RootRestController):
@pecan.expose('json') @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) return self.get(alarm_id, all_tenants)
@pecan.expose('json') @pecan.expose('json')
def get(self, alarm_id, all_tenants='0'): def get(self, alarm_id, all_tenants=False):
if all_tenants == '1': if all_tenants:
enforce('get rca:all_tenants', pecan.request.headers, enforce('get rca:all_tenants', pecan.request.headers,
pecan.request.enforcer, {}) pecan.request.enforcer, {})
else: else:

View File

@ -34,7 +34,7 @@ LOG = log.getLogger(__name__)
class TopologyController(RootRestController): class TopologyController(RootRestController):
@pecan.expose('json') @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: if all_tenants:
enforce('get topology:all_tenants', pecan.request.headers, enforce('get topology:all_tenants', pecan.request.headers,
pecan.request.enforcer, {}) pecan.request.enforcer, {})

View File

@ -39,7 +39,7 @@ class AlarmApis(EntityGraphApisBase):
is_admin_project = ctx.get(self.IS_ADMIN_PROJECT_PROPERTY, False) is_admin_project = ctx.get(self.IS_ADMIN_PROJECT_PROPERTY, False)
if not vitrage_id or vitrage_id == 'all': if not vitrage_id or vitrage_id == 'all':
if all_tenants == "1": if all_tenants:
alarms = self.entity_graph.get_vertices( alarms = self.entity_graph.get_vertices(
query_dict=ALARMS_ALL_QUERY) query_dict=ALARMS_ALL_QUERY)
else: else:

View File

@ -47,7 +47,7 @@ class RcaApis(EntityGraphApisBase):
direction=Direction.IN, direction=Direction.IN,
edge_query_dict=EDGE_QUERY) edge_query_dict=EDGE_QUERY)
if all_tenants == '1': if all_tenants:
unified_graph = found_graph_in unified_graph = found_graph_in
unified_graph.union(found_graph_out) unified_graph.union(found_graph_out)
else: else:

View File

@ -37,7 +37,7 @@ class TestApis(TestEntityGraphUnitBase):
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'tenant': 'project_1', 'is_admin': True}
# Action # 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'] alarms = json.loads(alarms)['alarms']
# Test assertions # Test assertions
@ -51,7 +51,7 @@ class TestApis(TestEntityGraphUnitBase):
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'tenant': 'project_2', 'is_admin': False}
# Action # 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'] alarms = json.loads(alarms)['alarms']
# Test assertions # Test assertions
@ -65,7 +65,7 @@ class TestApis(TestEntityGraphUnitBase):
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'tenant': 'project_1', 'is_admin': False}
# Action # 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'] alarms = json.loads(alarms)['alarms']
# Test assertions # Test assertions
@ -79,7 +79,7 @@ class TestApis(TestEntityGraphUnitBase):
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'tenant': 'project_1', 'is_admin': True}
# Action # 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) graph_rca = json.loads(graph_rca)
# Test assertions # Test assertions
@ -95,7 +95,7 @@ class TestApis(TestEntityGraphUnitBase):
# Action # Action
graph_rca = apis.get_rca(ctx, graph_rca = apis.get_rca(ctx,
root='alarm_on_instance_3', root='alarm_on_instance_3',
all_tenants='0') all_tenants=False)
graph_rca = json.loads(graph_rca) graph_rca = json.loads(graph_rca)
# Test assertions # Test assertions
@ -109,7 +109,7 @@ class TestApis(TestEntityGraphUnitBase):
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'tenant': 'project_2', 'is_admin': False}
# Action # 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) graph_rca = json.loads(graph_rca)
# Test assertions # Test assertions
@ -123,7 +123,7 @@ class TestApis(TestEntityGraphUnitBase):
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'tenant': 'project_1', 'is_admin': False}
# Action # 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) graph_rca = json.loads(graph_rca)
# Test assertions # Test assertions
@ -143,7 +143,7 @@ class TestApis(TestEntityGraphUnitBase):
depth=10, depth=10,
query=None, query=None,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=0) all_tenants=False)
graph_topology = json.loads(graph_topology) graph_topology = json.loads(graph_topology)
# Test assertions # Test assertions
@ -165,7 +165,7 @@ class TestApis(TestEntityGraphUnitBase):
depth=10, depth=10,
query=None, query=None,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=0) all_tenants=False)
graph_topology = json.loads(graph_topology) graph_topology = json.loads(graph_topology)
# Test assertions # Test assertions
@ -187,7 +187,7 @@ class TestApis(TestEntityGraphUnitBase):
depth=10, depth=10,
query=None, query=None,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=1) all_tenants=True)
graph_topology = json.loads(graph_topology) graph_topology = json.loads(graph_topology)
# Test assertions # Test assertions

View File

@ -118,7 +118,7 @@ class BaseApiTest(base.BaseTestCase):
return volume return volume
def _get_host(self): 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, host = filter(lambda item: item[VProps.TYPE] == NOVA_HOST_DATASOURCE,
topology['nodes']) topology['nodes'])
return host[0] return host[0]

View File

@ -38,7 +38,7 @@ class TestAodhAlarm(BaseAlarmsTest):
self._create_ceilometer_alarm(self._find_instance_resource_id()) self._create_ceilometer_alarm(self._find_instance_resource_id())
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,
@ -73,7 +73,7 @@ class TestAodhAlarm(BaseAlarmsTest):
self._create_ceilometer_alarm() self._create_ceilometer_alarm()
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,

View File

@ -37,7 +37,7 @@ class TestCinderVolume(BaseTopologyTest):
num_volumes=self.NUM_VOLUME) num_volumes=self.NUM_VOLUME)
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,

View File

@ -42,7 +42,7 @@ class TestHeatStack(BaseTopologyTest):
self._create_stacks(num_stacks=self.NUM_STACKS) self._create_stacks(num_stacks=self.NUM_STACKS)
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,

View File

@ -43,7 +43,7 @@ class TestNeutron(BaseTopologyTest):
set_public_network=True) set_public_network=True)
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,

View File

@ -35,7 +35,7 @@ class TestNova(BaseTopologyTest):
self._create_entities(num_instances=self.NUM_INSTANCE) self._create_entities(num_instances=self.NUM_INSTANCE)
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,

View File

@ -39,7 +39,7 @@ class TestStaticPhysical(BaseApiTest):
self._create_switches() self._create_switches()
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,

View File

@ -128,7 +128,7 @@ class TestRca(BaseRcaTest):
self._create_alarm( self._create_alarm(
resource_id=self._get_hostname(), resource_id=self._get_hostname(),
alarm_name=RCA_ALARM_NAME) 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'], self._validate_set_state(topology=topology['nodes'],
instances=instances) instances=instances)

View File

@ -36,7 +36,7 @@ class BaseTopologyTest(BaseApiTest):
api_graph = self.vitrage_client.topology.get( api_graph = self.vitrage_client.topology.get(
limit=4, limit=4,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=1) all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data() entities = self._entities_validation_data()
num_default_entities = self.num_default_entities + \ num_default_entities = self.num_default_entities + \

View File

@ -67,7 +67,7 @@ class TestTopology(BaseTopologyTest):
num_volumes=self.NUM_VOLUME) num_volumes=self.NUM_VOLUME)
# Calculate expected results # 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) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,
@ -109,7 +109,7 @@ class TestTopology(BaseTopologyTest):
# Calculate expected results # Calculate expected results
api_graph = self.vitrage_client.topology.get( api_graph = self.vitrage_client.topology.get(
query=self._graph_query(), query=self._graph_query(),
all_tenants=1) all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,
@ -144,7 +144,7 @@ class TestTopology(BaseTopologyTest):
# Calculate expected results # Calculate expected results
api_graph = self.vitrage_client.topology.get( 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) graph = self._create_graph_from_tree_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,
@ -179,7 +179,7 @@ class TestTopology(BaseTopologyTest):
# Calculate expected results # Calculate expected results
api_graph = self.vitrage_client.topology.get( 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) graph = self._create_graph_from_tree_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_edges=1) host_entities=1, host_edges=1)
@ -209,7 +209,7 @@ class TestTopology(BaseTopologyTest):
# Calculate expected results # Calculate expected results
api_graph = self.vitrage_client.topology.get( 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) graph = self._create_graph_from_tree_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_edges=1) host_entities=1, host_edges=1)
@ -239,7 +239,7 @@ class TestTopology(BaseTopologyTest):
# Calculate expected results # Calculate expected results
api_graph = self.vitrage_client.topology.get( 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) graph = self._create_graph_from_tree_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,
@ -277,7 +277,7 @@ class TestTopology(BaseTopologyTest):
api_graph = self.vitrage_client.topology.get( api_graph = self.vitrage_client.topology.get(
limit=2, limit=2,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=1) all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_edges=1) host_entities=1, host_edges=1)
@ -310,7 +310,7 @@ class TestTopology(BaseTopologyTest):
api_graph = self.vitrage_client.topology.get( api_graph = self.vitrage_client.topology.get(
limit=3, limit=3,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=1) all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph) graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data( entities = self._entities_validation_data(
host_entities=1, host_entities=1,
@ -348,7 +348,7 @@ class TestTopology(BaseTopologyTest):
self.vitrage_client.topology.get( self.vitrage_client.topology.get(
limit=2, limit=2,
root='RESOURCE:openstack.cluster:OpenStack Cluster', root='RESOURCE:openstack.cluster:OpenStack Cluster',
all_tenants=1) all_tenants=True)
except ClientException as e: except ClientException as e:
self.assertEqual(403, e.code) self.assertEqual(403, e.code)
self.assertEqual( self.assertEqual(
@ -372,7 +372,7 @@ class TestTopology(BaseTopologyTest):
# Calculate expected results # Calculate expected results
api_graph = self.vitrage_client.topology.get( 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 # Test Assertions
self.assertEqual( self.assertEqual(
@ -403,7 +403,7 @@ class TestTopology(BaseTopologyTest):
api_graph = self.vitrage_client.topology.get( api_graph = self.vitrage_client.topology.get(
graph_type='tree', graph_type='tree',
query=self._tree_no_match_query(), query=self._tree_no_match_query(),
all_tenants=1) all_tenants=True)
# Test Assertions # Test Assertions
self.assertEqual({}, api_graph) self.assertEqual({}, api_graph)