Beispiel #1
0
    def _get_tenant_from_coordinator(self):
        """
        This method calls to the coordinator to retrieve tenant
        """

        config_cache = ConfigCache()
        config = config_cache.get_config()

        token_header = {
            MESSAGE_TOKEN: self.message_token,
            "WORKER-ID": config.worker_id,
            "WORKER-TOKEN": config.worker_token
        }

        request_uri = "{0}/tenant/{1}".format(config.coordinator_uri,
                                              self.tenant_id)

        try:
            resp = http_request(request_uri, token_header, http_verb='GET')

        except requests.RequestException as ex:
            _LOG.exception(ex.message)
            raise errors.CoordinatorCommunicationError

        if resp.status_code == httplib.OK:
            response_body = resp.json()
            tenant = load_tenant_from_dict(response_body['tenant'])
            return tenant

        elif resp.status_code == httplib.NOT_FOUND:
            message = 'unable to locate tenant.'
            _LOG.debug(message)
            raise errors.ResourceNotFoundError(message)
        else:
            raise errors.CoordinatorCommunicationError
Beispiel #2
0
 def test_find_event_producer_for_host_no_producer_found(self):
     tenant = load_tenant_from_dict(self.tenant)
     test_host = find_host(tenant, host_name='ws-n01')
     tenant.event_producers = list()
     test_producer = find_event_producer_for_host(
         tenant, test_host, 'producer_name_none')
     self.assertEqual(test_producer, None)
Beispiel #3
0
 def test_find_event_producer_for_host_no_profile_returns_none(self):
     tenant = load_tenant_from_dict(self.tenant)
     test_host = find_host(tenant, host_name='ws-n01')
     test_host.profile = None
     test_producer = find_event_producer_for_host(
         tenant, test_host, 'producer_name_none')
     self.assertEqual(test_producer, None)
Beispiel #4
0
    def _get_tenant_from_coordinator(self):
        """
        This method calls to the coordinator to retrieve tenant
        """

        config_cache = ConfigCache()
        config = config_cache.get_config()

        token_header = {
            MESSAGE_TOKEN: self.message_token,
            "WORKER-ID": config.worker_id,
            "WORKER-TOKEN": config.worker_token
        }

        request_uri = "{0}/tenant/{1}".format(
            config.coordinator_uri, self.tenant_id)

        try:
            resp = http_request(request_uri, token_header,
                                http_verb='GET')

        except requests.RequestException:
            raise errors.CoordinatorCommunicationError

        if resp.status_code == httplib.OK:
            response_body = resp.json()
            tenant = load_tenant_from_dict(response_body['tenant'])
            return tenant

        elif resp.status_code == httplib.NOT_FOUND:
            raise errors.ResourceNotFoundError('Unable to locate tenant.')
        else:
            raise errors.CoordinatorCommunicationError
Beispiel #5
0
    def get_tenant(self, tenant_id):
        if self.cache.cache_exists(tenant_id, CACHE_TENANT):
            tenant_dict = jsonutils.loads(
                self.cache.cache_get(tenant_id, CACHE_TENANT))
            tenant = load_tenant_from_dict(tenant_dict)
            return tenant

        return None
Beispiel #6
0
 def test_find_event_producer_for_host_producer_not_in_profile(self):
     tenant = load_tenant_from_dict(self.tenant)
     test_host = find_host(tenant, host_name='ws-n01')
     test_profile = find_host_profile(tenant, profile_id=122)
     test_profile.event_producers = [124]
     test_producer = find_event_producer_for_host(
         tenant, test_host, 'apache')
     self.assertEqual(test_producer, None)
Beispiel #7
0
    def get_tenant(self, tenant_id):
        if self.cache.cache_exists(tenant_id, CACHE_TENANT):
            tenant_dict = jsonutils.loads(
                self.cache.cache_get(tenant_id, CACHE_TENANT))
            tenant = load_tenant_from_dict(tenant_dict)
            return tenant

        return None
Beispiel #8
0
 def test_find_event_producer_for_host_success_returns_producer(self):
     tenant = load_tenant_from_dict(self.tenant)
     test_host = find_host(tenant, host_name='ws-n01')
     test_producer = find_event_producer_for_host(
         tenant, test_host, 'apache')
     self.assertIsInstance(test_producer, EventProducer)