Esempio n. 1
0
    def test_resource_show_with_not_admin_and_resource_in_other_project(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resource = apis.show_resource(ctx, 'instance_2')

        # Test assertions
        self.assertIsNone(resource)
Esempio n. 2
0
    def test_resource_show_with_not_admin_and_no_project_resource(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        resource = apis.show_resource(ctx, 'zone_1')

        # Test assertions
        self.assertIsNone(resource)
Esempio n. 3
0
    def test_resource_count_with_not_admin_project_and_existing_type(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resources = apis.count_resources(
            ctx, resource_type=NOVA_INSTANCE_DATASOURCE, all_tenants=False)
        resources = json.loads(resources)

        # Test assertions
        self.assertEqual(2, resources[NOVA_INSTANCE_DATASOURCE])
Esempio n. 4
0
    def test_resource_list_with_all_tenants(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=None,
                                       all_tenants=True)
        resources = decompress_obj(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(7))
Esempio n. 5
0
    def test_resource_list_with_not_admin_project_and_existing_type(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=NOVA_INSTANCE_DATASOURCE,
                                       all_tenants=False)
        resources = decompress_obj(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(2))
Esempio n. 6
0
    def test_resource_show_with_admin_and_no_project_resource(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_1', 'is_admin': True}

        # Action
        resource = apis.show_resource(ctx, 'zone_1')
        resource = json.loads(resource)

        # Test assertions
        self.assertIsNotNone(resource)
        self._check_resource_properties(resource, 'zone_1',
                                        NOVA_ZONE_DATASOURCE)
Esempio n. 7
0
    def test_resource_list_with_not_admin_project_and_no_existing_type(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=NOVA_HOST_DATASOURCE,
                                       all_tenants=False)
        resources = json.loads(resources)['resources']

        # Test assertions
        self.assertThat(resources, IsEmpty())
Esempio n. 8
0
    def test_resource_list_with_not_admin_project(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=None,
                                       all_tenants=False)
        resources = json.loads(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(2))
Esempio n. 9
0
    def test_resource_count_with_not_admin_project_and_no_existing_type(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': False}

        # Action
        resources = apis.count_resources(ctx,
                                         resource_type=NOVA_HOST_DATASOURCE,
                                         all_tenants=False)
        resources = json.loads(resources)

        # Test assertions
        self.assertThat(resources.items(), matchers.HasLength(0))
Esempio n. 10
0
    def test_resource_show_with_admin_and_resource_in_other_project(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None)
        ctx = {'tenant': 'project_2', 'is_admin': True}

        # Action
        resource = apis.show_resource(ctx, 'instance_2')
        resource = json.loads(resource)

        # Test assertions
        self.assertIsNotNone(resource)
        self._check_resource_properties(resource, 'instance_2',
                                        NOVA_INSTANCE_DATASOURCE,
                                        project_id='project_1')
Esempio n. 11
0
    def test_resource_list_with_all_tenants(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        resources = apis.get_resources(
            ctx,
            resource_type=None,
            all_tenants=True)
        resources = json.loads(resources)['resources']

        # Test assertions
        self.assertEqual(7, len(resources))
Esempio n. 12
0
    def start(self):
        LOG.info("Vitrage Api Handler Service - Starting...")

        super(VitrageApiHandlerService, self).start()

        transport = messaging.get_rpc_transport(self.conf)
        rabbit_hosts = self.conf.oslo_messaging_rabbit.rabbit_hosts
        target = oslo_messaging.Target(topic=self.conf.rpc_topic,
                                       server=rabbit_hosts)

        endpoints = [
            TopologyApis(self.entity_graph, self.conf),
            AlarmApis(self.entity_graph, self.conf),
            RcaApis(self.entity_graph, self.conf),
            TemplateApis(self.scenario_repo.templates,
                         self.scenario_repo.def_templates),
            EventApis(self.conf),
            ResourceApis(self.entity_graph, self.conf)
        ]

        server = vitrage_rpc.get_server(target, endpoints, transport)

        server.start()

        LOG.info("Vitrage Api Handler Service - Started!")
Esempio n. 13
0
    def _init_instance(self):
        conf = self._conf
        LOG.info("Vitrage Api Handler Service - Starting...")
        notifier = messaging.VitrageNotifier(conf, "vitrage.api",
                                             [EVALUATOR_TOPIC])
        db = storage.get_connection_from_config(conf)
        transport = messaging.get_rpc_transport(conf)
        rabbit_hosts = conf.oslo_messaging_rabbit.rabbit_hosts
        target = oslo_messaging.Target(topic=conf.rpc_topic,
                                       server=rabbit_hosts)

        endpoints = [
            TopologyApis(self._entity_graph, conf),
            AlarmApis(self._entity_graph, conf, db),
            RcaApis(self._entity_graph, conf, db),
            TemplateApis(notifier, db),
            EventApis(conf),
            ResourceApis(self._entity_graph, conf),
            WebhookApis(conf)
        ]

        server = vitrage_rpc.get_server(target, endpoints, transport)

        server.start()

        LOG.info("Vitrage Api Handler Service - Started!")
Esempio n. 14
0
    def test_resource_list_with_admin_project_and_query(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': True}

        # Action
        resources = apis.get_resources(ctx,
                                       resource_type=NOVA_INSTANCE_DATASOURCE,
                                       all_tenants=False,
                                       query={'==': {
                                           'id': 'instance_3'
                                       }})
        resources = decompress_obj(resources)['resources']

        # Test assertions
        self.assertThat(resources, matchers.HasLength(1))
Esempio n. 15
0
    def test_resource_count_with_all_tenants(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        resources = apis.count_resources(ctx,
                                         resource_type=None,
                                         all_tenants=True)
        resources = json.loads(resources)

        # Test assertions
        self.assertEqual(4, resources[NOVA_INSTANCE_DATASOURCE])
        self.assertEqual(1, resources[NOVA_ZONE_DATASOURCE])
        self.assertEqual(1, resources[OPENSTACK_CLUSTER])
        self.assertEqual(1, resources[NOVA_HOST_DATASOURCE])
Esempio n. 16
0
    def test_resource_count_with_all_tenants_and_group_by(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_1', 'is_admin': False}

        # Action
        resources = apis.count_resources(ctx,
                                         resource_type=None,
                                         all_tenants=True,
                                         group_by=VProps.PROJECT_ID)
        resources = json.loads(resources)

        # Test assertions
        self.assertEqual(2, resources['project_1'])
        self.assertEqual(2, resources['project_2'])
        self.assertEqual(3, resources[''])
Esempio n. 17
0
    def test_resource_count_with_admin_project_and_query(self):
        # Setup
        graph = self._create_graph()
        apis = ResourceApis(graph, None, self.api_lock)
        ctx = {'tenant': 'project_2', 'is_admin': True}

        # Action
        resources = apis.count_resources(
            ctx,
            resource_type=NOVA_INSTANCE_DATASOURCE,
            all_tenants=False,
            query={'==': {
                'id': 'instance_3'
            }})
        resources = json.loads(resources)

        # Test assertions
        self.assertEqual(1, resources[NOVA_INSTANCE_DATASOURCE])
Esempio n. 18
0
    def _start(self):
        LOG.info("Vitrage Api Handler Service - Starting...")

        transport = messaging.get_rpc_transport(self.conf)
        rabbit_hosts = self.conf.oslo_messaging_rabbit.rabbit_hosts
        target = oslo_messaging.Target(topic=self.conf.rpc_topic,
                                       server=rabbit_hosts)

        endpoints = [TopologyApis(self.entity_graph, self.conf),
                     AlarmApis(self.entity_graph, self.conf),
                     RcaApis(self.entity_graph, self.conf),
                     TemplateApis(self.notifier, self.db),
                     EventApis(self.conf),
                     ResourceApis(self.entity_graph, self.conf),
                     WebhookApis(self.conf)]

        server = vitrage_rpc.get_server(target, endpoints, transport)

        server.start()

        LOG.info("Vitrage Api Handler Service - Started!")
Esempio n. 19
0
    def _init_instance(self):
        notifier = messaging.VitrageNotifier("vitrage.api", [EVALUATOR_TOPIC])
        db = storage.get_connection_from_config()
        transport = messaging.get_rpc_transport()
        target = oslo_messaging.Target(topic=CONF.rpc_topic,
                                       server=uuidutils.generate_uuid())
        self.api_lock = threading.RLock()

        endpoints = [
            TopologyApis(self._entity_graph, self.api_lock),
            AlarmApis(self._entity_graph, self.api_lock, db),
            RcaApis(self._entity_graph, self.api_lock, db),
            ResourceApis(self._entity_graph, self.api_lock),
            TemplateApis(notifier, db),
            EventApis(),
            WebhookApis(db),
            OperationalApis(self._entity_graph),
        ]

        server = vitrage_rpc.get_server(target, endpoints, transport)

        server.start()