本文整理汇总了Python中meniscus.openstack.common.jsonutils.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.body = {'worker_status': 'online'}
self.body_disk = {
"disk_usage": {
"/dev/sda1": {
"total": 313764528,
"used": 112512436
}
}
}
self.body_load = {
"load_average": {
"1": 0.24755859375,
"5": 1.0751953125,
"15": 0.9365234375
}
}
self.body_bad = {'not_status': 'bad_status'}
self.status = jsonutils.dumps(self.body)
self.disk = jsonutils.dumps(self.body_disk)
self.load = jsonutils.dumps(self.body_load)
self.status = jsonutils.dumps(self.body)
self.req = MagicMock()
self.resp = MagicMock()
self.registration = WorkerRegistration('correlation').format()
self.worker_dict = Worker(**self.registration).format()
self.worker_not_found = None
self.db_handler = MagicMock()
self.resource = WorkerUpdateResource(self.db_handler)
self.worker_id = '51375fc4eea50d53066292b6'
示例2: set_tenant
def set_tenant(self, tenant):
if self.cache.cache_exists(tenant.tenant_id, CACHE_TENANT):
self.cache.cache_update(
tenant.tenant_id, jsonutils.dumps(tenant.format()),
DEFAULT_EXPIRES, CACHE_TENANT)
else:
self.cache.cache_set(
tenant.tenant_id, jsonutils.dumps(tenant.format()),
DEFAULT_EXPIRES, CACHE_TENANT)
示例3: set_token
def set_token(self, tenant_id, token):
if self.cache.cache_exists(tenant_id, CACHE_TOKEN):
self.cache.cache_update(
tenant_id, jsonutils.dumps(token.format()),
DEFAULT_EXPIRES, CACHE_TOKEN)
else:
self.cache.cache_set(
tenant_id, jsonutils.dumps(token.format()),
DEFAULT_EXPIRES, CACHE_TOKEN)
示例4: set_routes
def set_routes(self, pipeline_workers):
if self.cache.cache_exists('routes', CACHE_CONFIG):
self.cache.cache_update(
'routes',
jsonutils.dumps(pipeline_workers),
CONFIG_EXPIRES, CACHE_CONFIG)
else:
self.cache.cache_set(
'routes',
jsonutils.dumps(pipeline_workers),
CONFIG_EXPIRES, CACHE_CONFIG)
示例5: set_config
def set_config(self, worker_config):
if self.cache.cache_exists('worker_configuration', CACHE_CONFIG):
self.cache.cache_update(
'worker_configuration',
jsonutils.dumps(worker_config.format()),
CONFIG_EXPIRES, CACHE_CONFIG)
else:
self.cache.cache_set(
'worker_configuration',
jsonutils.dumps(worker_config.format()),
CONFIG_EXPIRES, CACHE_CONFIG)
示例6: setUp
def setUp(self):
self.tenant_id = "12673247623548752387452378"
self.tenant_dict = {
"tenant_id": self.tenant_id,
"tenant_name": "TenantName",
"_id": "507f1f77bcf86cd799439011",
"event_producers": [
{
"id": 123,
"name": "apache",
"pattern": "apache2.cee",
"durable": False,
"encrypted": False,
"sinks": ["elasticsearch"]
},
{
"id": 124,
"name": "system.auth",
"pattern": "auth_log.cee",
"durable": False,
"encrypted": False,
"sinks": ["elasticsearch", "hdfs"]
}
],
"token": {
"valid": "c8a4db32-635a-46b6-94ed-04b1bd533f41",
"previous": None,
"last_changed": "2013-03-19T18:16:48.411029Z"
}
}
self.producer_id = "234"
self.event_producer = EventProducer(
_id=self.producer_id, name="nginx", pattern="nginx")
self.ds_handler = MagicMock()
self.ds_handler.find_one.return_value = self.tenant_dict
self.tenant_obj = tenant_util.load_tenant_from_dict(self.tenant_dict)
self.tenant_cache = MagicMock()
self.tenant_cache.cache_get.return_value = jsonutils.dumps(
self.tenant_dict)
self.tenant_cache.cache_exists.return_value = True
self.tenant_cache.cache_update = MagicMock()
self.token_cache = MagicMock()
self.token_cache.cache_get.return_value = jsonutils.dumps(
self.tenant_dict['token'])
self.token_cache.cache_exists.return_value = True
self.cache_empty = MagicMock()
self.cache_empty.cache_exists.return_value = False
self.cache_empty.cache_set = MagicMock()
示例7: setUp
def setUp(self):
self.tenant = {
"tenant_id": "12345",
"tenant_name": "TenantName",
"_id": "507f1f77bcf86cd799439011",
"event_producers": [
{
"id": 123,
"name": "apache",
"pattern": "apache2.cee",
"durable": False,
"encrypted": False,
"sinks": ["elasticsearch"]
},
{
"id": 124,
"name": "system.auth",
"pattern": "auth_log.cee",
"durable": False,
"encrypted": False,
"sinks": ["elasticsearch", "hdfs"]
}
],
"token": {
"valid": "c8a4db32-635a-46b6-94ed-04b1bd533f41",
"previous": None,
"last_changed": "2013-03-19T18:16:48.411029Z"
}
}
self.ds_handler = MagicMock()
self.ds_handler.find_one.return_value = self.tenant
self.ds_handler_empty = MagicMock()
self.ds_handler_empty.find_one.return_value = None
self.ds_handler_no_tenant = MagicMock()
self.ds_handler_no_tenant.put = MagicMock()
self.ds_handler_no_tenant.find_one.side_effect = [None, self.tenant]
self.tenant_cache = MagicMock()
self.tenant_cache.cache_get.return_value = jsonutils.dumps(self.tenant)
self.tenant_cache.cache_exists.return_value = True
self.tenant_cache.cache_update = MagicMock()
self.token_cache = MagicMock()
self.token_cache.cache_get.return_value = jsonutils.dumps(
self.tenant['token'])
self.token_cache.cache_exists.return_value = True
self.cache_empty = MagicMock()
self.cache_empty.cache_exists.return_value = False
self.cache_empty.cache_set = MagicMock()
示例8: format
def format(self, record):
message = {'message': record.getMessage(),
'asctime': self.formatTime(record, self.datefmt),
'name': record.name,
'msg': record.msg,
'args': record.args,
'levelname': record.levelname,
'levelno': record.levelno,
'pathname': record.pathname,
'filename': record.filename,
'module': record.module,
'lineno': record.lineno,
'funcname': record.funcName,
'created': record.created,
'msecs': record.msecs,
'relative_created': record.relativeCreated,
'thread': record.thread,
'thread_name': record.threadName,
'process_name': record.processName,
'process': record.process,
'traceback': None}
if hasattr(record, 'extra'):
message['extra'] = record.extra
if record.exc_info:
message['traceback'] = self.formatException(record.exc_info)
return jsonutils.dumps(message)
示例9: test_return_201_for_multiple_supported_sink
def test_return_201_for_multiple_supported_sink(self):
save_tenant = MagicMock()
create_event_producer = MagicMock()
with patch(
'meniscus.api.tenant.resources.tenant_util.find_tenant',
self.tenant_found), \
patch(
'meniscus.api.tenant.resources.tenant_util.save_tenant',
save_tenant), \
patch(
'meniscus.api.tenant.resources.'
'tenant_util.create_event_producer',
create_event_producer):
self.simulate_request(
self.test_route,
method='POST',
headers={'content-type': 'application/json'},
body=jsonutils.dumps(
{
'event_producer': {
'name': 'producer55',
'pattern': 'syslog',
'sinks': ["elasticsearch", "hdfs"]
}
}
)
)
self.assertEqual(falcon.HTTP_201, self.srmock.status)
示例10: _register_with_coordinator
def _register_with_coordinator(
self, coordinator_uri, personality, registration, auth_header):
"""
register with the coordinator and persist the configuration to cache
"""
try:
resp = http_request(coordinator_uri + '/pairing', auth_header,
jsonutils.dumps(
registration), http_verb='POST')
except requests.RequestException:
_LOG.exception(
'Pairing Process: error posting worker registration')
return False
_LOG.debug('resp.status_code: {0}'.format(resp.status_code))
if resp.status_code == httplib.ACCEPTED:
body = resp.json()['worker_identity']
config = WorkerConfiguration(
personality, body['personality_module'], body['worker_token'],
body['worker_id'], coordinator_uri)
config_cache = ConfigCache()
config_cache.set_config(config)
return True
示例11: test_return_201_with_optional_fields
def test_return_201_with_optional_fields(self):
save_tenant = MagicMock()
create_event_producer = MagicMock()
with patch(
'meniscus.api.tenant.resources.tenant_util.find_tenant',
self.tenant_found), \
patch(
'meniscus.api.tenant.resources.tenant_util.save_tenant',
save_tenant), \
patch(
'meniscus.api.tenant.resources.'
'tenant_util.create_event_producer',
create_event_producer):
self.simulate_request(
self.test_route,
method='POST',
headers={'content-type': 'application/json'},
body=jsonutils.dumps(
{
'event_producer': {
'name': 'producer55',
'pattern': 'syslog',
'durable': True,
'encrypted': False,
'sinks': ['elasticsearch']
}
}
)
)
self.assertEqual(falcon.HTTP_201, self.srmock.status)
示例12: _send_target_list_to_broadcaster
def _send_target_list_to_broadcaster(db, worker):
"""
send broadcast list to broadcaster
"""
# list of broadcasters
broadcasters = _get_broadcaster_list(db)
if not broadcasters:
## todo log no online broadcasters
return False
# list of broadcast targets
broadcast_targets = _get_broadcast_targets(db, worker)
if not broadcast_targets:
## todo: log failed to find target
return False
for broadcaster_uri in broadcasters:
resp = None
try:
## todo refactor callback address to not include /v1/callback/"
resp = http_request(
'{0}:8080/v1/broadcast'.format(broadcaster_uri),
jsonutils.dumps(broadcast_targets), http_verb='PUT')
except requests.RequestException:
raise coordinator_errors.BroadcasterCommunicationError
if resp.status_code == httplib.OK:
return True
else:
## todo Log broadcaster connection failure
return False
示例13: test_return_200_producer_updated
def test_return_200_producer_updated(self):
save_tenant = MagicMock()
with patch(
'meniscus.api.tenant.resources.tenant_util.find_tenant',
self.tenant_found), \
patch(
'meniscus.api.tenant.resources.tenant_util.save_tenant',
save_tenant):
self.simulate_request(
'/v1/tenant/{tenant_id}/producers/{event_producer_id}'.format(
tenant_id=self.tenant_id,
event_producer_id=self.producer_id
),
method='PUT',
headers={'content-type': 'application/json'},
body=jsonutils.dumps(
{
'event_producer': {
'name': self.producer_name,
'pattern': 'syslog',
'encrypted': False,
'durable': False
}
}
)
)
self.assertEqual(falcon.HTTP_200, self.srmock.status)
示例14: test_returns_200_worker_status
def test_returns_200_worker_status(self):
self.db_handler.find_one.return_value = self.worker_dict
self.simulate_request(
self.test_route,
method='PUT',
headers={'content-type': 'application/json'},
body=jsonutils.dumps(self.worker_status))
self.assertEqual(falcon.HTTP_200, self.srmock.status)
示例15: test_returns_400_body_validation
def test_returns_400_body_validation(self):
with patch('meniscus.data.model.worker_util.save_worker', MagicMock()):
self.simulate_request(
self.test_route,
method='PUT',
headers={'content-type': 'application/json'},
body=jsonutils.dumps(self.bad_worker_status))
self.assertEqual(falcon.HTTP_400, self.srmock.status)