Esempio n. 1
0
    def test_noauth_mode_list_alarms(self):
        with mock.patch('pecan.request') as request:
            request.client.call.return_value = compress_obj({"alarms": []})
            params = dict(vitrage_id='all', all_tenants=False)
            data = self.get_json('/alarm/', params=params)

            self.assertEqual(1, request.client.call.call_count)
            self.assert_is_empty(data)
Esempio n. 2
0
    def test_noauth_mode_get_topology(self):
        with mock.patch('pecan.request') as request:
            request.client.call.return_value = compress_obj({})
            params = dict(depth=None, graph_type='graph', query=None,
                          root=None,
                          all_tenants=False)
            resp = self.post_json('/topology/', params=params)

            self.assertEqual(1, request.client.call.call_count)
            self.assertEqual('200 OK', resp.status)
            self.assert_is_empty(resp.json)
Esempio n. 3
0
    def get_resources(self,
                      ctx,
                      resource_type=None,
                      all_tenants=False,
                      query=None):
        LOG.debug(
            'ResourceApis get_resources - resource_type: %s, all_tenants: %s,'
            ' query: %s', resource_type, all_tenants, query)

        query = self._get_query(ctx, resource_type, all_tenants, query)
        resources = self.entity_graph.get_vertices(query_dict=query)
        data = {'resources': [r.properties for r in resources]}
        return compress_obj(data, level=1)
Esempio n. 4
0
    def get_alarms(self, ctx, vitrage_id, all_tenants, *args, **kwargs):

        kwargs = self._parse_kwargs(kwargs)

        if not vitrage_id or vitrage_id == 'all':
            if not all_tenants:
                kwargs['project_id'] = \
                    ctx.get(TenantProps.TENANT, 'no-project')
                kwargs['is_admin_project'] = \
                    ctx.get(TenantProps.IS_ADMIN, False)
        else:
            kwargs.get('filter_by', []).append(VProps.VITRAGE_RESOURCE_ID)
            kwargs.get('filter_vals', []).append(vitrage_id)

        alarms = self._get_alarms(*args, **kwargs)
        data = {'alarms': [v.payload for v in alarms]}
        return compress_obj(data, level=1)
Esempio n. 5
0
    def get_topology(self, ctx, graph_type, depth, query, root, all_tenants):
        LOG.debug("TopologyApis get_topology - root: %s, all_tenants=%s", root,
                  all_tenants)

        project_id = ctx.get(TenantProps.TENANT, None)
        is_admin_project = ctx.get(TenantProps.IS_ADMIN, False)

        LOG.debug('project_id = %s, is_admin_project  %s', project_id,
                  is_admin_project)

        root_id = root or self._default_root_id()
        if graph_type == 'tree' or \
                ((root is not None) and (depth is not None)):
            if not query:
                LOG.error("Graph-type 'tree' requires a filter.")
                raise Exception("Graph-type 'tree' requires a filter.")

            current_query = query
            if not all_tenants:
                project_query = \
                    {'or': [{'==': {VProps.PROJECT_ID: project_id}},
                            {'==': {VProps.PROJECT_ID: None}}]}
                current_query = {'and': [query, project_query]}

            graph = self.entity_graph.algo.graph_query_vertices(
                root_id,
                query_dict=current_query,
                depth=depth,
                edge_query_dict=base.EDGE_QUERY)
        # By default the graph_type is 'graph'
        else:
            if all_tenants:
                q = query if query else base.TOPOLOGY_AND_ALARMS_QUERY
                graph = \
                    self.entity_graph.algo.create_graph_from_matching_vertices(
                        query_dict=q,
                        edge_attr_filter={VProps.VITRAGE_IS_DELETED: False})
            else:
                graph = self._get_topology_for_specific_project(
                    query, project_id, is_admin_project, root_id)

        data = graph.json_output_graph(raw=True)
        return compress_obj(data, level=1)