当前位置: 首页>>代码示例>>Python>>正文


Python jsonutils.dumps方法代码示例

本文整理汇总了Python中oslo_serialization.jsonutils.dumps方法的典型用法代码示例。如果您正苦于以下问题:Python jsonutils.dumps方法的具体用法?Python jsonutils.dumps怎么用?Python jsonutils.dumps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_serialization.jsonutils的用法示例。


在下文中一共展示了jsonutils.dumps方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_409_concurrent_provider_update

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_409_concurrent_provider_update(self, mock_sleep):
        # there will be 1 normal call and 3 retries
        self.mock_get.side_effect = [self.source_rsp, self.target_rsp,
                                     self.source_rsp, self.target_rsp,
                                     self.source_rsp, self.target_rsp,
                                     self.source_rsp, self.target_rsp]
        rsp = fake_requests.FakeResponse(
            409,
            jsonutils.dumps(
                {'errors': [
                    {'code': 'placement.concurrent_update',
                     'detail': ''}]}))

        self.mock_post.return_value = rsp

        resp = self.client.move_allocations(
            self.context, self.source_consumer_uuid, self.target_consumer_uuid)

        self.assertFalse(resp)
        # Post was attempted four times.
        self.assertEqual(4, self.mock_post.call_count) 
开发者ID:openstack,项目名称:zun,代码行数:23,代码来源:test_report.py

示例2: test_set_aggregates_for_provider

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_set_aggregates_for_provider(self):
        aggs = [uuids.agg1, uuids.agg2]
        self.ks_adap_mock.put.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dumps({
                'aggregates': aggs,
                'resource_provider_generation': 1}))

        # Prime the provider tree cache
        self.client._provider_tree.new_root('rp', uuids.rp, generation=0)
        self.assertEqual(set(),
                         self.client._provider_tree.data(uuids.rp).aggregates)

        self.client.set_aggregates_for_provider(self.context, uuids.rp, aggs)

        exp_payload = {'aggregates': aggs,
                       'resource_provider_generation': 0}
        self.ks_adap_mock.put.assert_called_once_with(
            '/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload,
            microversion='1.19', endpoint_filter=mock.ANY, logger=mock.ANY,
            headers={'X-Openstack-Request-Id': self.context.global_id})
        # Cache was updated
        ptree_data = self.client._provider_tree.data(uuids.rp)
        self.assertEqual(set(aggs), ptree_data.aggregates)
        self.assertEqual(1, ptree_data.generation) 
开发者ID:openstack,项目名称:zun,代码行数:26,代码来源:test_report.py

示例3: test_set_aggregates_for_provider_no_short_circuit

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_set_aggregates_for_provider_no_short_circuit(self):
        """Don't short-circuit if generation doesn't match, even if aggs have
        not changed.
        """
        # Prime the provider tree cache
        self.client._provider_tree.new_root('rp', uuids.rp, generation=2)
        self.ks_adap_mock.put.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dumps({
                'aggregates': [],
                'resource_provider_generation': 5}))
        self.client.set_aggregates_for_provider(self.context, uuids.rp, [],
                                                generation=4)
        exp_payload = {'aggregates': [],
                       'resource_provider_generation': 4}
        self.ks_adap_mock.put.assert_called_once_with(
            '/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload,
            microversion='1.19', endpoint_filter=mock.ANY, logger=mock.ANY,
            headers={'X-Openstack-Request-Id': self.context.global_id})
        # Cache was updated
        ptree_data = self.client._provider_tree.data(uuids.rp)
        self.assertEqual(set(), ptree_data.aggregates)
        self.assertEqual(5, ptree_data.generation) 
开发者ID:openstack,项目名称:zun,代码行数:24,代码来源:test_report.py

示例4: _test_remove_res_from_alloc

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def _test_remove_res_from_alloc(
            self, current_allocations, resources_to_remove,
            updated_allocations):

        with zun_utils.nested_contexts(
                mock.patch(
                    "zun.scheduler.client.report.SchedulerReportClient.get"),
                mock.patch(
                    "zun.scheduler.client.report.SchedulerReportClient.put")
        ) as (mock_get, mock_put):
            mock_get.return_value = fake_requests.FakeResponse(
                200, content=jsonutils.dumps(current_allocations))

            self.client.remove_resources_from_container_allocation(
                self.context, uuids.consumer_uuid, resources_to_remove)

            mock_get.assert_called_once_with(
                '/allocations/%s' % uuids.consumer_uuid, version='1.28',
                global_request_id=self.context.global_id)
            mock_put.assert_called_once_with(
                '/allocations/%s' % uuids.consumer_uuid, updated_allocations,
                version='1.28', global_request_id=self.context.global_id) 
开发者ID:openstack,项目名称:zun,代码行数:24,代码来源:test_report.py

示例5: setUp

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def setUp(self):
        super(CinderVolumeDriverTestCase, self).setUp()
        self.fake_uuid = uuidutils.generate_uuid()
        self.fake_volume_id = 'fake-volume-id'
        self.fake_devpath = '/fake-path'
        self.fake_mountpoint = '/fake-mountpoint'
        self.fake_container_path = '/fake-container-path'
        self.fake_conn_info = {
            'data': {'device_path': self.fake_devpath},
        }
        self.volmap = mock.MagicMock()
        self.volmap.volume.uuid = self.fake_uuid
        self.volmap.volume_provider = 'cinder'
        self.volmap.volume_id = self.fake_volume_id
        self.volmap.container_path = self.fake_container_path
        self.volmap.connection_info = jsonutils.dumps(self.fake_conn_info) 
开发者ID:openstack,项目名称:zun,代码行数:18,代码来源:test_driver.py

示例6: get_pci_resources

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def get_pci_resources(self):
        addresses = []
        try:
            output, status = utils.execute('lspci', '-D', '-nnmm')
            lines = output.split('\n')
            for line in lines:
                if not line:
                    continue
                columns = line.split()
                address = columns[0]
                addresses.append(address)
        except processutils.ProcessExecutionError as e:
            raise exception.CommandError(cmd='lspci',
                                         error=str(e))

        pci_info = []
        for addr in addresses:
            pci_info.append(self._get_pci_dev_info(addr))

        return jsonutils.dumps(pci_info) 
开发者ID:openstack,项目名称:zun,代码行数:22,代码来源:host_capability.py

示例7: add

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def add(self):
        try:
            params = self._prepare_request()
        except Exception:
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            vif = self.plugin.add(params)
            data = jsonutils.dumps(vif.obj_to_primitive())
        except exception.ResourceNotReady:
            LOG.error('Error when processing addNetwork request')
            return '', httplib.GATEWAY_TIMEOUT, self.headers
        except Exception:
            LOG.exception('Error when processing addNetwork request. CNI '
                          'Params: %s', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers

        return data, httplib.ACCEPTED, self.headers 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:service.py

示例8: playbook_treeview

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def playbook_treeview(playbook):
    """
    Creates a fake filesystem with playbook files and uses generate_tree() to
    recurse and return a JSON structure suitable for bootstrap-treeview.
    """
    fs = fake_filesystem.FakeFilesystem()
    mock_os = fake_filesystem.FakeOsModule(fs)

    files = models.File.query.filter(models.File.playbook_id.in_([playbook]))

    paths = {}
    for file in files:
        fs.CreateFile(file.path)
        paths[file.path] = file.id

    return jsonutils.dumps(generate_tree('/', paths, mock_os),
                           sort_keys=True,
                           indent=2) 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:20,代码来源:utils.py

示例9: __init__

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def __init__(self, image_dict, from_get=False):

        if from_get:
            attrs = [k for k in image_dict.keys()
                     if image_dict[k] is not None]
        else:
            attrs = list(image_dict)
            attrs.extend(
                ['owner', 'created_at', 'visibility', 'status',
                 'container_format', 'name'])
        self._image_dict = {'id': image_dict['id']}
        self._image_dict.update({k: image_dict.get(k)
                                 for k in attrs})
        for complex_attr in ('mappings', 'block_device_mapping'):
            if complex_attr in self._image_dict:
                self._image_dict[complex_attr] = jsonutils.dumps(
                    self._image_dict[complex_attr])
        for k in self._image_dict:
            setattr(self, k, self._image_dict[k]) 
开发者ID:openstack,项目名称:ec2-api,代码行数:21,代码来源:fakes.py

示例10: _list_pools

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def _list_pools(self):
        try:
            drv_vif = drivers.PodVIFDriver.get_instance()
            drv_vif_pool = drivers.VIFPoolDriver.get_instance()
            drv_vif_pool.set_vif_driver(drv_vif)

            available_pools = drv_vif_pool.list_pools()
        except TypeError:
            LOG.error("Invalid driver type")
            raise

        pools_info = ""
        for pool_key, pool_items in available_pools.items():
            pools_info += (jsonutils.dumps(pool_key) + " has "
                           + str(len(pool_items)) + " ports\n")
        if pools_info:
            return pools_info
        return "There are no pools" 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:20,代码来源:pool.py

示例11: test_annotate

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_annotate(self, m_patch, m_count):
        m_count.return_value = list(range(1, 5))
        path = '/test'
        annotations = {'a1': 'v1', 'a2': 'v2'}
        resource_version = "123"
        ret = {'metadata': {'annotations': annotations,
                            "resourceVersion": resource_version}}
        data = jsonutils.dumps(ret, sort_keys=True)

        m_resp = mock.MagicMock()
        m_resp.ok = True
        m_resp.json.return_value = ret
        m_patch.return_value = m_resp

        self.assertEqual(annotations, self.client.annotate(
            path, annotations, resource_version=resource_version))
        m_patch.assert_called_once_with(self.base_url + path,
                                        data=data, headers=mock.ANY,
                                        cert=(None, None), verify=False) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:21,代码来源:test_k8s_client.py

示例12: test_annotate_resource_not_found

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_annotate_resource_not_found(self, m_patch, m_count):
        m_count.return_value = list(range(1, 5))
        path = '/test'
        annotations = {'a1': 'v1', 'a2': 'v2'}
        resource_version = "123"
        annotate_obj = {'metadata': {
            'annotations': annotations,
            'resourceVersion': resource_version}}
        annotate_data = jsonutils.dumps(annotate_obj, sort_keys=True)

        m_resp_not_found = mock.MagicMock()
        m_resp_not_found.ok = False
        m_resp_not_found.status_code = requests.codes.not_found
        m_patch.return_value = m_resp_not_found

        self.assertRaises(exc.K8sResourceNotFound,
                          self.client.annotate,
                          path,
                          annotations,
                          resource_version=resource_version)
        m_patch.assert_called_once_with(self.base_url + path,
                                        data=annotate_data,
                                        headers=mock.ANY,
                                        cert=(None, None), verify=False) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:26,代码来源:test_k8s_client.py

示例13: test__get_in_use_ports

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test__get_in_use_ports(self):
        cls = vif_pool.BaseVIFPool
        m_driver = mock.MagicMock(spec=cls)

        kubernetes = self.useFixture(k_fix.MockK8sClient()).client
        pod = get_pod_obj()
        port_id = str(uuid.uuid4())
        pod_vif = osv_vif.VIFBase(id=port_id)
        pod_state = vif.PodState(default_vif=pod_vif)

        pod['metadata']['annotations'][constants.K8S_ANNOTATION_VIF] = (
            jsonutils.dumps(pod_state.obj_to_primitive()))
        items = [pod]
        kubernetes.get.return_value = {'items': items}

        resp = cls._get_in_use_ports(m_driver)

        self.assertEqual(resp, [port_id]) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:20,代码来源:test_vif_pool.py

示例14: test_do_POST_populate

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_do_POST_populate(self):
        method = 'create'
        path = "http://localhost/populatePool"
        trunk_ips = ["10.0.0.6"]
        num_ports = 3
        body = jsonutils.dumps({"trunks": trunk_ips,
                                "num_ports": num_ports})
        headers = {'Content-Type': 'application/json', 'Connection': 'close'}
        headers['Content-Length'] = len(body)
        trigger_exception = False

        expected_resp = ('Ports pool at {} was populated with 3 ports.'
                         .format(trunk_ips)).encode()

        self._do_POST_helper(method, path, headers, body, expected_resp,
                             trigger_exception, trunk_ips, num_ports) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:18,代码来源:test_pool.py

示例15: test_do_GET_list_exception

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dumps [as 别名]
def test_do_GET_list_exception(self):
        method = 'list'
        method_resp = ('["10.0.0.6", "9d2b45c4efaa478481c30340b49fd4d2", '
                       '["00efc78c-f11c-414a-bfcd-a82e16dc07d1", '
                       '"fd6b13dc-7230-4cbe-9237-36b4614bc6b5"]] '
                       'has 5 ports')

        path = "http://localhost/listPools"
        body = jsonutils.dumps({})
        headers = {'Content-Type': 'application/json', 'Connection': 'close'}
        headers['Content-Length'] = len(body)
        trigger_exception = True

        expected_resp = ('Error listing the pools.').encode()

        self._do_GET_helper(method, method_resp, path, headers, body,
                            expected_resp, trigger_exception) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:19,代码来源:test_pool.py


注:本文中的oslo_serialization.jsonutils.dumps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。