Example #1
0
    def test_get_request_host_model(self):
        """Get Host Request Model"""

        under_test = Host.get_request_model()

        self.assertTrue('endpoint' in under_test)
        self.assertEqual('host', under_test['endpoint'])
        self.assertTrue('params' in under_test)
        self.assertTrue('projection' in under_test)
    def test_get_request_host_model(self):
        """Get Host Request Model"""

        under_test = Host.get_request_model()

        self.assertTrue('endpoint' in under_test)
        self.assertEqual('host', under_test['endpoint'])
        self.assertTrue('params' in under_test)
        self.assertTrue('projection' in under_test)
    def query_hosts(self):
        """
        Launch request on "host" endpoint, add hosts in problems if needed

        """

        request_model = Host.get_request_model()

        request = self.get(
            request_model['endpoint'],
            request_model['params'],
            request_model['projection'],
            all_items=True
        )

        if request:
            hosts_list = []
            for backend_item in request['_items']:
                host = Host()

                host.create(
                    backend_item['_id'],
                    backend_item,
                    backend_item['name'],
                )
                hosts_list.append(host)

                # If host is a problem, add / update it
                if data_manager.is_problem('host', backend_item):
                    if data_manager.get_item('problems', host.item_id):
                        data_manager.update_item_data('problems', host.item_id, host.data)
                    else:
                        data_manager.database['problems'].append(host)

            data_manager.db_is_ready['problems']['host'] = True

            if hosts_list:
                data_manager.update_database('host', hosts_list)
            if 'OK' in request['_status']:
                data_manager.db_is_ready[request_model['endpoint']] = True
    def query_hosts(self):
        """
        Launch request on "host" endpoint, add hosts in problems if needed

        """

        request_model = Host.get_request_model()

        request = self.get(request_model['endpoint'],
                           request_model['params'],
                           request_model['projection'],
                           all_items=True)

        if request:
            hosts_list = []
            for backend_item in request['_items']:
                host = Host()

                host.create(
                    backend_item['_id'],
                    backend_item,
                    backend_item['name'],
                )
                hosts_list.append(host)

                # If host is a problem, add / update it
                if data_manager.is_problem('host', backend_item):
                    if data_manager.get_item('problems', host.item_id):
                        data_manager.update_item_data('problems', host.item_id,
                                                      host.data)
                    else:
                        data_manager.database['problems'].append(host)

            data_manager.db_is_ready['problems']['host'] = True

            if hosts_list:
                data_manager.update_database('host', hosts_list)
            if 'OK' in request['_status']:
                data_manager.db_is_ready[request_model['endpoint']] = True