本文整理汇总了Python中nailgun.openstack.common.jsonutils.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stats_sending_enabled
def test_stats_sending_enabled(self):
self.assertEqual(StatsSender().must_send_stats(), False)
resp = self.app.get(
reverse("MasterNodeSettingsHandler"),
headers=self.default_headers)
self.assertEqual(200, resp.status_code)
data = resp.json_body
# emulate user confirmed settings in UI
data["settings"]["statistics"]["user_choice_saved"]["value"] = True
resp = self.app.put(
reverse("MasterNodeSettingsHandler"),
headers=self.default_headers,
params=jsonutils.dumps(data)
)
self.assertEqual(200, resp.status_code)
self.assertEqual(StatsSender().must_send_stats(), True)
# emulate user disabled statistics sending
data["settings"]["statistics"]["send_anonymous_statistic"]["value"] = \
False
resp = self.app.put(
reverse("MasterNodeSettingsHandler"),
headers=self.default_headers,
params=jsonutils.dumps(data)
)
self.assertEqual(200, resp.status_code)
self.assertEqual(StatsSender().must_send_stats(), False)
示例2: upgrade_releases
def upgrade_releases(connection):
select = text(
"""SELECT id, attributes_metadata, roles_metadata
from releases"""
)
update = text(
"""UPDATE releases
SET attributes_metadata = :attrs, roles_metadata = :roles,
wizard_metadata = :wiz_meta
WHERE id = :id"""
)
r = connection.execute(select)
# reading fixture files in loop is in general a bad idea and as long as
# wizard_metadata is the same for all existing releases getting it can
# be moved outside of the loop
wizard_meta = upgrade_release_wizard_metadata_50_to_51()
for release in r:
attrs_meta = upgrade_release_attributes_50_to_51(jsonutils.loads(release[1]))
roles_meta = upgrade_release_roles_50_to_51(jsonutils.loads(release[2]))
connection.execute(
update,
id=release[0],
attrs=jsonutils.dumps(attrs_meta),
roles=jsonutils.dumps(roles_meta),
wiz_meta=jsonutils.dumps(wizard_meta),
)
示例3: test_node_timestamp_updated_only_by_agent
def test_node_timestamp_updated_only_by_agent(self):
node = self.env.create_node(api=False)
timestamp = node.timestamp
resp = self.app.put(
reverse('NodeCollectionHandler'),
jsonutils.dumps([
{'mac': node.mac, 'status': 'discover',
'manufacturer': 'old'}
]),
headers=self.default_headers)
self.assertEqual(resp.status_code, 200)
node = self.db.query(Node).get(node.id)
self.assertEqual(node.timestamp, timestamp)
resp = self.app.put(
reverse('NodeAgentHandler'),
jsonutils.dumps(
{'mac': node.mac, 'status': 'discover',
'manufacturer': 'new'}
),
headers=self.default_headers)
self.assertEqual(resp.status_code, 200)
node = self.db.query(Node).get(node.id)
self.assertNotEqual(node.timestamp, timestamp)
self.assertEqual('new', node.manufacturer)
示例4: test_cluster_node_list_update
def test_cluster_node_list_update(self):
node1 = self.env.create_node(api=False)
node2 = self.env.create_node(api=False)
cluster = self.env.create_cluster(api=False)
resp = self.app.put(
reverse('ClusterHandler', kwargs={'obj_id': cluster.id}),
jsonutils.dumps({'nodes': [node1.id]}),
headers=self.default_headers,
expect_errors=True
)
self.assertEqual(resp.status_code, 200)
nodes = self.db.query(Node).filter(Node.cluster == cluster).all()
self.assertEqual(1, len(nodes))
self.assertEqual(nodes[0].id, node1.id)
resp = self.app.put(
reverse('ClusterHandler', kwargs={'obj_id': cluster.id}),
jsonutils.dumps({'nodes': [node2.id]}),
headers=self.default_headers
)
self.assertEqual(resp.status_code, 200)
nodes = self.db.query(Node).filter(Node.cluster == cluster)
self.assertEqual(1, nodes.count())
示例5: cast
def cast(name, message, service=False):
logger.debug(
"RPC cast to orchestrator:\n{0}".format(
jsonutils.dumps(message, indent=4)
)
)
#测试使用
file_object = open('/opt/queuemsg.txt', 'w')
file_object.write(jsonutils.dumps(message, indent=4))
file_object.close()
use_queue = naily_queue if not service else naily_service_queue
use_exchange = naily_exchange if not service else naily_service_exchange
with Connection(conn_str) as conn:
with conn.Producer(serializer='json') as producer:
publish = functools.partial(producer.publish, message,
exchange=use_exchange, routing_key=name, declare=[use_queue])
try:
#pass
publish()
except amqp_exceptions.PreconditionFailed as e:
logger.warning(six.text_type(e))
# (dshulyak) we should drop both exchanges/queues in order
# for astute to be able to recover temporary queues
utils.delete_entities(
conn, naily_service_exchange, naily_service_queue,
naily_exchange, naily_queue)
publish()
示例6: PUT
def PUT(self, cluster_id):
""":returns: JSONized Task object.
:http: * 202 (network checking task created)
* 404 (cluster not found in db)
"""
data = jsonutils.loads(web.data())
if data.get("networks"):
data["networks"] = [n for n in data["networks"] if n.get("name") != "fuelweb_admin"]
cluster = self.get_object_or_404(objects.Cluster, cluster_id)
self.check_net_provider(cluster)
self.check_if_network_configuration_locked(cluster)
task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
task = task_manager.execute(data)
if task.status != consts.TASK_STATUSES.error:
try:
if "networks" in data:
self.validator.validate_networks_update(jsonutils.dumps(data))
if "dns_nameservers" in data:
self.validator.validate_dns_servers_update(jsonutils.dumps(data))
objects.Cluster.get_network_manager(cluster).update(cluster, data)
except Exception as exc:
# set task status to error and update its corresponding data
data = {"status": consts.TASK_STATUSES.error, "progress": 100, "message": six.text_type(exc)}
objects.Task.update(task, data)
logger.error(traceback.format_exc())
raise self.http(202, objects.Task.to_json(task))
示例7: test_node_agent_api
def test_node_agent_api(self):
self.env.create_node(
api=False,
status='provisioning',
meta=self.env.default_metadata()
)
node_db = self.env.nodes[0]
resp = self.app.put(
reverse('NodeAgentHandler'),
jsonutils.dumps(
{'mac': node_db.mac,
'status': 'discover', 'manufacturer': 'new'}
),
headers=self.default_headers
)
self.assertEqual(resp.status_code, 200)
node_id = '080000000003'
resp = self.app.post(
reverse('NodeCollectionHandler'),
jsonutils.dumps({'id': node_id,
'mac': self.env.generate_random_mac(),
'status': 'discover'}),
headers=self.default_headers)
self.assertEqual(201, resp.status_code)
示例8: test_unassignment
def test_unassignment(self):
cluster = self.env.create(
cluster_kwargs={"api": True},
nodes_kwargs=[{}]
)
node = self.env.nodes[0]
# correct unassignment
resp = self.app.post(
reverse(
'NodeUnassignmentHandler',
kwargs={'cluster_id': cluster['id']}
),
jsonutils.dumps([{'id': node.id}]),
headers=self.default_headers
)
self.assertEqual(200, resp.status_code)
self.assertEqual(node.cluster, None)
self.assertEqual(node.pending_roles, [])
#Test with invalid node ids
for node_id in (0, node.id + 50):
resp = self.app.post(
reverse(
'NodeUnassignmentHandler',
kwargs={'cluster_id': cluster['id']}
),
jsonutils.dumps([{'id': node_id}]),
headers=self.default_headers,
expect_errors=True
)
self.assertEqual(400, resp.status_code)
#Test with invalid cluster id
resp = self.app.post(
reverse(
'NodeUnassignmentHandler',
kwargs={'cluster_id': cluster['id'] + 5}
),
jsonutils.dumps([{'id': node.id}]),
headers=self.default_headers,
expect_errors=True
)
self.assertEqual(resp.status_code, 404)
# Test with wrong cluster id
self.env.create(
cluster_kwargs={"api": True},
nodes_kwargs=[{}]
)
resp = self.app.post(
reverse(
'NodeUnassignmentHandler',
kwargs={'cluster_id': cluster['id']}
),
jsonutils.dumps([{'id': self.env.clusters[1].nodes[0].id}]),
headers=self.default_headers,
expect_errors=True
)
self.assertEqual(resp.status_code, 400)
示例9: test_attributes_update_put
def test_attributes_update_put(self):
cluster_id = self.env.create_cluster(api=True)['id']
cluster_db = self.env.clusters[0]
resp = self.app.get(
reverse(
'ClusterAttributesHandler',
kwargs={'cluster_id': cluster_id}),
headers=self.default_headers
)
self.assertEqual(200, resp.status_code)
resp = self.app.put(
reverse(
'ClusterAttributesHandler',
kwargs={'cluster_id': cluster_id}),
params=jsonutils.dumps({
'editable': {
"foo": "bar"
},
}),
headers=self.default_headers
)
self.assertEqual(200, resp.status_code)
attrs = objects.Cluster.get_attributes(cluster_db)
self.assertEqual("bar", attrs.editable["foo"])
attrs.editable.pop('foo')
self.assertEqual(attrs.editable, {})
# 400 on generated update
resp = self.app.put(
reverse(
'ClusterAttributesHandler',
kwargs={'cluster_id': cluster_id}),
params=jsonutils.dumps({
'generated': {
"foo": "bar"
},
}),
headers=self.default_headers,
expect_errors=True
)
self.assertEqual(400, resp.status_code)
# 400 if editable is not dict
resp = self.app.put(
reverse(
'ClusterAttributesHandler',
kwargs={'cluster_id': cluster_id}),
params=jsonutils.dumps({
'editable': ["foo", "bar"],
}),
headers=self.default_headers,
expect_errors=True
)
self.assertEqual(400, resp.status_code)
示例10: GET
def GET(self):
"""Returns Fuel Key data
:returns: base64 of FUEL commit SHA, release version and Fuel UUID.
:http: * 200 (OK)
"""
key_data = {
"sha": str(settings.VERSION['nailgun_sha']),
"release": str(settings.VERSION['release']),
"uuid": str(settings.FUEL_KEY)
}
signature = base64.b64encode(jsonutils.dumps(key_data))
key_data["signature"] = signature
return {"key": base64.b64encode(jsonutils.dumps(key_data))}
示例11: test_version_handler
def test_version_handler(self):
resp = self.app.get(reverse("FuelKeyHandler"), headers=self.default_headers)
fuel_release = "0.1"
key_data = {"sha": "12345", "release": fuel_release, "uuid": "uuid"}
signature = base64.b64encode(jsonutils.dumps(key_data))
key_data["signature"] = signature
self.assertEqual(200, resp.status_code)
response = resp.json_body
self.assertEqual(response, {"key": base64.b64encode(jsonutils.dumps(key_data))})
resp_data = jsonutils.loads(base64.b64decode(response["key"]))
self.assertEqual(resp_data["release"], fuel_release)
示例12: test_remove_assigned_interface
def test_remove_assigned_interface(self):
def get_nodes():
resp = self.app.get(
reverse("NodeCollectionHandler", kwargs={"cluster_id": self.env.clusters[0].id}),
headers=self.default_headers,
)
return jsonutils.loads(resp.body)
self.env.create(nodes_kwargs=[{"api": True}])
# check all possible handlers
for handler in ("NodeAgentHandler", "NodeHandler", "NodeCollectionHandler"):
# create node and check it availability
nodes_data = get_nodes()
self.assertEqual(len(nodes_data), 1)
# remove all interfaces except admin one
adm_eth = self.env.network_manager._get_interface_by_network_name(nodes_data[0]["id"], "fuelweb_admin")
ifaces = list(nodes_data[0]["meta"]["interfaces"])
nodes_data[0]["meta"]["interfaces"] = [i for i in ifaces if i["name"] == adm_eth.name]
# prepare put request
data = {"id": nodes_data[0]["id"], "meta": nodes_data[0]["meta"]}
if handler in ("NodeCollectionHandler",):
data = [data]
if handler in ("NodeHandler",):
endpoint = reverse(handler, kwargs={"obj_id": data["id"]})
else:
endpoint = reverse(handler)
self.app.put(endpoint, jsonutils.dumps(data), headers=self.default_headers)
# check the node is visible for api
nodes_data = get_nodes()
self.assertEqual(len(nodes_data), 1)
self.assertEqual(len(nodes_data[0]["meta"]["interfaces"]), 1)
# restore removed interfaces
nodes_data[0]["meta"]["interfaces"] = ifaces
self.app.put(
reverse("NodeAgentHandler"),
jsonutils.dumps({"id": nodes_data[0]["id"], "meta": nodes_data[0]["meta"]}),
headers=self.default_headers,
)
# check node availability
nodes_data = get_nodes()
self.assertEqual(len(nodes_data), 1)
self.assertItemsEqual(nodes_data[0]["meta"]["interfaces"], ifaces)
示例13: PUT
def PUT(self, cluster_id):
""":returns: JSONized Task object.
:http: * 202 (network checking task created)
* 404 (cluster not found in db)
"""
data = jsonutils.loads(web.data())
if data.get("networks"):
data["networks"] = [
n for n in data["networks"] if n.get("name") != "fuelweb_admin"
]
cluster = self.get_object_or_404(Cluster, cluster_id)
self.check_net_provider(cluster)
self.check_if_network_configuration_locked(cluster)
task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
task = task_manager.execute(data)
if task.status != 'error':
try:
if 'networks' in data:
self.validator.validate_networks_update(
jsonutils.dumps(data)
)
if 'dns_nameservers' in data:
self.validator.validate_dns_servers_update(
jsonutils.dumps(data)
)
objects.Cluster.get_network_manager(
cluster
).update(cluster, data)
except Exception as exc:
# set task status to error and update its corresponding data
data = {'status': 'error',
'progress': 100,
'message': six.text_type(exc)}
objects.Task.update(task, data)
logger.error(traceback.format_exc())
#TODO(enchantner): research this behaviour
if task.status == 'error':
db().rollback()
else:
db().commit()
raise self.http(202, Task.to_json(task))
示例14: dump_environment_resp
def dump_environment_resp(cls, **kwargs):
logger.info(
"RPC method dump_environment_resp received: %s" %
jsonutils.dumps(kwargs)
)
task_uuid = kwargs.get('task_uuid')
status = kwargs.get('status')
progress = kwargs.get('progress')
error = kwargs.get('error')
msg = kwargs.get('msg')
task = objects.Task.get_by_uuid(task_uuid, fail_if_not_found=True)
if status == 'error':
notifier.notify('error', error)
data = {'status': status, 'progress': 100, 'message': error}
objects.Task.update(task, data)
elif status == 'ready':
dumpfile = os.path.basename(msg)
notifier.notify('done', 'Snapshot is ready. '
'Visit Support page to download')
data = {'status': status, 'progress': progress,
'message': '/dump/{0}'.format(dumpfile)}
objects.Task.update(task, data)
示例15: test_occurs_error_not_enough_osds_for_ceph
def test_occurs_error_not_enough_osds_for_ceph(self):
cluster = self.env.create(
nodes_kwargs=[
{'roles': ['controller', 'ceph-osd'],
'pending_addition': True}])
self.app.patch(
reverse(
'ClusterAttributesHandler',
kwargs={'cluster_id': cluster['id']}),
params=jsonutils.dumps({
'editable': {
'storage': {'volumes_ceph': {'value': True},
'osd_pool_size': {'value': 3}}}}),
headers=self.default_headers)
task = self.env.launch_deployment()
self.assertEqual(task.status, 'error')
self.assertEqual(
task.message,
'Number of OSD nodes (1) cannot be less than '
'the Ceph object replication factor (3). '
'Please either assign ceph-osd role to more nodes, '
'or reduce Ceph replication factor in the Settings tab.')