當前位置: 首頁>>代碼示例>>Python>>正文


Python jsonutils.dump_as_bytes方法代碼示例

本文整理匯總了Python中oslo_serialization.jsonutils.dump_as_bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python jsonutils.dump_as_bytes方法的具體用法?Python jsonutils.dump_as_bytes怎麽用?Python jsonutils.dump_as_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_serialization.jsonutils的用法示例。


在下文中一共展示了jsonutils.dump_as_bytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def __call__(self, environ, start_response):
        for err_str in self.app_iter:
            err = {}
            try:
                err = json.loads(err_str.decode('utf-8'))
            except ValueError:
                pass

            links = {'rel': 'help', 'href': 'https://docs.openstack.org'
                     '/api-guide/compute/microversions.html'}

            err['max_version'] = self.max_version
            err['min_version'] = self.min_version
            err['code'] = "zun.microversion-unsupported"
            err['links'] = [links]
            err['title'] = "Requested microversion is unsupported"

        self.app_iter = [json.dump_as_bytes(err).encode("latin-1")]
        self.headers['Content-Length'] = str(len(self.app_iter[0]))

        return super(HTTPNotAcceptableAPIVersion, self).__call__(
            environ, start_response) 
開發者ID:openstack,項目名稱:zun,代碼行數:24,代碼來源:http_error.py

示例2: test_watch

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_watch(self, m_get):
        path = '/test'
        data = [{'obj': 'obj%s' % i} for i in range(3)]
        lines = [jsonutils.dump_as_bytes(i) for i in data]

        m_resp = mock.MagicMock()
        m_resp.ok = True
        m_resp.iter_lines.return_value = lines
        m_get.return_value = m_resp

        cycles = 3
        self.assertEqual(
            data * cycles,
            list(itertools.islice(self.client.watch(path),
                                  len(data) * cycles)))

        self.assertEqual(cycles, m_get.call_count)
        self.assertEqual(cycles, m_resp.close.call_count)
        m_get.assert_called_with(self.base_url + path, headers={}, stream=True,
                                 params={'watch': 'true'}, cert=(None, None),
                                 verify=False, timeout=(30, 60)) 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:23,代碼來源:test_k8s_client.py

示例3: test_watch_restart

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_watch_restart(self, m_get):
        path = '/test'
        data = [{'object': {'metadata': {'name': 'obj%s' % i,
                                         'resourceVersion': i}}}
                for i in range(3)]
        lines = [jsonutils.dump_as_bytes(i) for i in data]

        m_resp = mock.MagicMock()
        m_resp.ok = True
        m_resp.iter_lines.side_effect = [lines, requests.ReadTimeout, lines]
        m_get.return_value = m_resp

        self.assertEqual(data * 2,
                         list(itertools.islice(self.client.watch(path),
                                               len(data) * 2)))
        self.assertEqual(3, m_get.call_count)
        self.assertEqual(3, m_resp.close.call_count)
        m_get.assert_any_call(
            self.base_url + path, headers={}, stream=True,
            params={"watch": "true"}, cert=(None, None), verify=False,
            timeout=(30, 60))
        m_get.assert_any_call(
            self.base_url + path, headers={}, stream=True,
            params={"watch": "true", "resourceVersion": 2}, cert=(None, None),
            verify=False, timeout=(30, 60)) 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:27,代碼來源:test_k8s_client.py

示例4: test_StatsRequestHandler_handle

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_StatsRequestHandler_handle(self, mock_recv, mock_driverupdater):
        TEST_OBJECT = {"test": "msg"}
        mock_recv.return_value = 'bogus'
        mock_updater = mock.MagicMock()
        mock_update_listener_stats = mock.MagicMock()
        mock_update_listener_stats.return_value = TEST_OBJECT
        mock_updater.update_listener_statistics = (mock_update_listener_stats)
        mock_driverupdater.return_value = mock_updater
        mock_request = mock.MagicMock()
        mock_send = mock.MagicMock()
        mock_sendall = mock.MagicMock()
        mock_request.send = mock_send
        mock_request.sendall = mock_sendall

        StatsRequestHandler = driver_listener.StatsRequestHandler(
            mock_request, 'bogus', 'bogus')
        StatsRequestHandler.handle()

        mock_recv.assert_called_with(mock_request)
        mock_update_listener_stats.assert_called_with('bogus')
        mock_send.assert_called_with(b'15\n')
        mock_sendall.assert_called_with(jsonutils.dump_as_bytes(TEST_OBJECT)) 
開發者ID:openstack,項目名稱:octavia,代碼行數:24,代碼來源:test_driver_listener.py

示例5: test_GetRequestHandler_handle

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_GetRequestHandler_handle(self, mock_recv, mock_process_get):
        TEST_OBJECT = {"test": "msg"}

        mock_recv.return_value = 'bogus'

        mock_process_get.return_value = TEST_OBJECT
        mock_request = mock.MagicMock()
        mock_send = mock.MagicMock()
        mock_sendall = mock.MagicMock()
        mock_request.send = mock_send
        mock_request.sendall = mock_sendall

        GetRequestHandler = driver_listener.GetRequestHandler(
            mock_request, 'bogus', 'bogus')
        GetRequestHandler.handle()

        mock_recv.assert_called_with(mock_request)
        mock_process_get.assert_called_with('bogus')

        mock_send.assert_called_with(b'15\n')
        mock_sendall.assert_called_with(jsonutils.dump_as_bytes(TEST_OBJECT)) 
開發者ID:openstack,項目名稱:octavia,代碼行數:23,代碼來源:test_driver_listener.py

示例6: __call__

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def __call__(self, environ, start_response):
        for err_str in self.app_iter:
            err = {}
            try:
                err = jsonutils.loads(err_str.decode('utf-8'))
            except ValueError:
                pass

            links = {'rel': 'help', 'href': 'http://docs.openstack.org'
                     '/api-guide/compute/microversions.html'}

            err['max_version'] = self.max_version
            err['min_version'] = self.min_version
            err['code'] = "magnum.microversion-unsupported"
            err['links'] = [links]
            err['title'] = "Requested microversion is unsupported"

        self.app_iter = [jsonutils.dump_as_bytes(err)]
        self.headers['Content-Length'] = str(len(self.app_iter[0]))

        return super(HTTPNotAcceptableAPIVersion, self).__call__(
            environ, start_response) 
開發者ID:openstack,項目名稱:magnum,代碼行數:24,代碼來源:http_error.py

示例7: test_create_success_with_201_response_code

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_create_success_with_201_response_code(
        self, mock_client, mock_create):
        body = {
            "notification": {
                "hostname": "fake_host",
                "payload": {
                    "instance_uuid": uuidsentinel.instance_uuid,
                    "vir_domain_event": "STOPPED_FAILED",
                    "event": "LIFECYCLE"
                },
                "type": "VM",
                "generated_time": NOW
            }
        }
        fake_req = self.req
        fake_req.headers['Content-Type'] = 'application/json'
        fake_req.method = 'POST'
        fake_req.body = jsonutils.dump_as_bytes(body)
        resp = fake_req.get_response(self.app)
        self.assertEqual(http.ACCEPTED, resp.status_code) 
開發者ID:openstack,項目名稱:masakari,代碼行數:22,代碼來源:test_notifications.py

示例8: test_create_success_with_201_response_code

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_create_success_with_201_response_code(
        self, mock_client, mock_create):
        body = {
            "host": {
                "name": "host-1", "type": "fake",
                "reserved": False,
                "on_maintenance": False,
                "control_attributes": "fake-control_attributes"
            }
        }
        fake_req = self.req
        fake_req.headers['Content-Type'] = 'application/json'
        fake_req.method = 'POST'
        fake_req.body = jsonutils.dump_as_bytes(body)
        resp = fake_req.get_response(self.app)
        self.assertEqual(http.CREATED, resp.status_code) 
開發者ID:openstack,項目名稱:masakari,代碼行數:18,代碼來源:test_hosts.py

示例9: test_create_success_with_201_response_code

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_create_success_with_201_response_code(
        self, mock_client, mock_create):
        body = {
            "segment": {
                "name": "segment1",
                "service_type": "COMPUTE",
                "recovery_method": "auto",
                "description": "failover_segment for compute"
            }
        }
        fake_req = self.req
        fake_req.headers['Content-Type'] = 'application/json'
        fake_req.method = 'POST'
        fake_req.body = jsonutils.dump_as_bytes(body)
        resp = fake_req.get_response(self.app)
        self.assertEqual(http.CREATED, resp.status_code) 
開發者ID:openstack,項目名稱:masakari,代碼行數:18,代碼來源:test_segments.py

示例10: get_token_from_zbxserver

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def get_token_from_zbxserver(self, node):

        temp_auth_api = copy.deepcopy(zapi.dAUTH_API)
        temp_auth_api['params']['user'] = \
            self.hostinfo[node]['zbx_info']['zabbix_user']
        temp_auth_api['params']['password'] = \
            self.hostinfo[node]['zbx_info']['zabbix_pass']
        zabbixip = \
            self.hostinfo[node]['zbx_info']['zabbix_ip']
        zabbixport = \
            self.hostinfo[node]['zbx_info']['zabbix_port']
        self.URL = "http://" + zabbixip + ":" + \
                   str(zabbixport) + zapi.URL
        if netaddr.valid_ipv6(zabbixip):
            self.URL = "http://[" + zabbixip + "]:" + \
                       str(zabbixport) + zapi.URL
        response = requests.post(
            self.URL,
            headers=zapi.HEADERS,
            data=jsonutils.dump_as_bytes(temp_auth_api)
        )
        response_dict = dict(response.json())
        VNFMonitorZabbix.check_error(response_dict)
        LOG.info('Success Connect Zabbix Server')
        return response_dict['result'] 
開發者ID:openstack,項目名稱:tacker,代碼行數:27,代碼來源:zabbix.py

示例11: generate_hot

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def generate_hot(self):

        self._get_vnfd()
        dev_attrs = self._update_fields()
        vnfd_dict = yamlparser.simple_ordered_parse(self.vnfd_yaml)
        LOG.debug('vnfd_dict %s', vnfd_dict)
        self._get_unsupported_resource_props(self.heatclient)

        self._generate_hot_from_tosca(vnfd_dict, dev_attrs,
                                      self.inst_req_info, self.grant_info)
        self.fields['template'] = self.heat_template_yaml
        if not self.vnf['attributes'].get('heat_template'):
            self.vnf['attributes']['heat_template'] = self.fields['template']
        if self.monitoring_dict:
            self.vnf['attributes'][
                'monitoring_policy'] = jsonutils.dump_as_bytes(
                self.monitoring_dict)
        if self.appmonitoring_dict:
            self.vnf['attributes']['app_monitoring_policy'] = \
                jsonutils.dump_as_bytes(self.appmonitoring_dict) 
開發者ID:openstack,項目名稱:tacker,代碼行數:22,代碼來源:translate_template.py

示例12: create_wait

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def create_wait(self, plugin, context, vnf_dict, vnf_id, auth_attr):
        region_name = vnf_dict.get('placement_attr', {}).get(
            'region_name', None)
        heatclient = hc.HeatClient(auth_attr, region_name)

        stack = self._wait_until_stack_ready(
            vnf_id, auth_attr, infra_cnst.STACK_CREATE_IN_PROGRESS,
            infra_cnst.STACK_CREATE_COMPLETE,
            vnfm.VNFCreateWaitFailed, region_name=region_name)

        # scaling enabled
        if vnf_dict['attributes'].get('scaling_group_names'):
            group_names = jsonutils.loads(
                vnf_dict['attributes'].get('scaling_group_names')).values()
            mgmt_ips = self._find_mgmt_ips_from_groups(heatclient,
                                                       vnf_id,
                                                       group_names)
        else:
            mgmt_ips = self._find_mgmt_ips(stack.outputs)

        if mgmt_ips:
            vnf_dict['mgmt_ip_address'] = jsonutils.dump_as_bytes(mgmt_ips) 
開發者ID:openstack,項目名稱:tacker,代碼行數:24,代碼來源:openstack.py

示例13: test_process_request_with_body

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_process_request_with_body(self, mock_create_token):
        req = Request.blank(self.ordered_url)
        req.method = 'POST'
        old_body = {'fake_key': 'fake_value'}
        req.body = jsonutils.dump_as_bytes(old_body)

        self.alarmrc.process_request(req)

        body_dict = jsonutils.loads(req.body)
        self.assertDictEqual(old_body,
                             body_dict['trigger']['params']['data'])
        self.assertEqual(self.alarm_url['05_key'],
                         body_dict['trigger']['params']['credential'])
        self.assertEqual(self.alarm_url['03_monitoring_policy_name'],
                         body_dict['trigger']['policy_name'])
        self.assertEqual(self.alarm_url['04_action_name'],
                         body_dict['trigger']['action_name']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:19,代碼來源:test_alarm_receiver.py

示例14: test_upload_vnf_package_content

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_upload_vnf_package_content(self, mock_vnf_pack_save,
                                        mock_vnf_by_id,
                                        mock_upload_vnf_package_content,
                                        mock_glance_store):
        updates = {'onboarding_state': 'CREATED',
                   'operational_state': 'DISABLED'}
        vnf_package_dict = fakes.fake_vnf_package(updates)
        vnf_package_obj = objects.VnfPackage(**vnf_package_dict)
        mock_vnf_by_id.return_value = vnf_package_obj
        mock_vnf_pack_save.return_value = vnf_package_obj
        mock_glance_store.return_value = 'location', 0, 'checksum',\
                                         'multihash', 'loc_meta'
        req = fake_request.HTTPRequest.blank(
            '/vnf_packages/%s/package_content'
            % constants.UUID)
        req.headers['Content-Type'] = 'application/zip'
        req.method = 'PUT'
        req.body = jsonutils.dump_as_bytes(mock.mock_open())
        resp = req.get_response(self.app)
        mock_glance_store.assert_called()
        self.assertEqual(http_client.ACCEPTED, resp.status_code) 
開發者ID:openstack,項目名稱:tacker,代碼行數:23,代碼來源:test_controller.py

示例15: test_upload_vnf_package_from_uri

# 需要導入模塊: from oslo_serialization import jsonutils [as 別名]
# 或者: from oslo_serialization.jsonutils import dump_as_bytes [as 別名]
def test_upload_vnf_package_from_uri(self, mock_vnf_pack_save,
                                         mock_vnf_by_id,
                                         mock_upload_vnf_package_from_uri,
                                         mock_url_open):
        body = {"addressInformation": "http://localhost/test_data.zip"}
        updates = {'onboarding_state': 'CREATED',
                   'operational_state': 'DISABLED'}
        vnf_package_dict = fakes.fake_vnf_package(updates)
        vnf_package_obj = objects.VnfPackage(**vnf_package_dict)
        mock_vnf_by_id.return_value = vnf_package_obj
        mock_vnf_pack_save.return_value = vnf_package_obj
        req = fake_request.HTTPRequest.blank(
            '/vnf_packages/%s/package_content/upload_from_uri'
            % constants.UUID)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'
        req.body = jsonutils.dump_as_bytes(body)
        resp = req.get_response(self.app)
        self.assertEqual(http_client.ACCEPTED, resp.status_code) 
開發者ID:openstack,項目名稱:tacker,代碼行數:21,代碼來源:test_controller.py


注:本文中的oslo_serialization.jsonutils.dump_as_bytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。