• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shell.run_command函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neutronclient.shell.run_command函数的典型用法代码示例。如果您正苦于以下问题:Python run_command函数的具体用法?Python run_command怎么用?Python run_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _test_delete_resource

    def _test_delete_resource(self, resource, cmd, myid, args,
                              cmd_resource=None, parent_id=None,
                              extra_id=None, delete_fail=False):
        mock_request_calls = []
        mock_request_returns = []
        if not cmd_resource:
            cmd_resource = resource
        path = getattr(self.client, cmd_resource + "_path")
        self._test_set_path_and_delete(path, parent_id, myid,
                                       mock_request_calls,
                                       mock_request_returns)
        # extra_id is used to test for bulk_delete
        if extra_id:
            self._test_set_path_and_delete(path, parent_id, extra_id,
                                           mock_request_calls,
                                           mock_request_returns,
                                           delete_fail)
        cmd_parser = cmd.get_parser("delete_" + cmd_resource)

        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient,
                                  "request") as mock_request:
            mock_request.side_effect = mock_request_returns
            shell.run_command(cmd, cmd_parser, args)

        self.assert_mock_multiple_calls_with_same_arguments(
            mock_get_client, mock.call(), None)
        mock_request.assert_has_calls(mock_request_calls)
        _str = self.fake_stdout.make_string()
        self.assertIn(myid, _str)
        if extra_id:
            self.assertIn(extra_id, _str)
开发者ID:openstack,项目名称:python-neutronclient,代码行数:33,代码来源:test_cli20.py


示例2: _test_show_resource

    def _test_show_resource(self, resource, cmd, myid, args, fields=(),
                            cmd_resource=None, parent_id=None):
        if not cmd_resource:
            cmd_resource = resource

        query = "&".join(["fields=%s" % field for field in fields])
        expected_res = {resource:
                        {self.id_field: myid,
                         'name': 'myname', }, }
        resstr = self.client.serialize(expected_res)
        path = getattr(self.client, cmd_resource + "_path")
        if parent_id:
            path = path % (parent_id, myid)
        else:
            path = path % myid
        cmd_parser = cmd.get_parser("show_" + cmd_resource)
        resp = (MyResp(200), resstr)

        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request:
            shell.run_command(cmd, cmd_parser, args)

        self.assert_mock_multiple_calls_with_same_arguments(
            mock_get_client, mock.call(), None)
        mock_request.assert_called_once_with(
            end_url(path, query), 'GET',
            body=None,
            headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
        _str = self.fake_stdout.make_string()
        self.assertIn(myid, _str)
        self.assertIn('myname', _str)
开发者ID:openstack,项目名称:python-neutronclient,代码行数:33,代码来源:test_cli20.py


示例3: _test_show_resource

 def _test_show_resource(self, resource, cmd, myid, args, fields=[]):
     self.mox.StubOutWithMock(cmd, "get_client")
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     query = "&".join(["fields=%s" % field for field in fields])
     expected_res = {resource:
                     {self.id_field: myid,
                      'name': 'myname', }, }
     self.client.format = self.format
     resstr = self.client.serialize(expected_res)
     path = getattr(self.client, resource + "_path")
     self.client.httpclient.request(
         end_url(path % myid, query, format=self.format), 'GET',
         body=None,
         headers=mox.ContainsKeyValue(
             'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr))
     args.extend(['--request-format', self.format])
     self.mox.ReplayAll()
     cmd_parser = cmd.get_parser("show_" + resource)
     shell.run_command(cmd, cmd_parser, args)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
     _str = self.fake_stdout.make_string()
     self.assertTrue(myid in _str)
     self.assertTrue('myname' in _str)
开发者ID:niuzhenguo,项目名称:python-neutronclient,代码行数:25,代码来源:test_cli20.py


示例4: _test_list_columns

    def _test_list_columns(self, cmd, resources,
                           resources_out, args=('-f', 'json'),
                           cmd_resources=None, parent_id=None):
        if not cmd_resources:
            cmd_resources = resources

        resstr = self.client.serialize(resources_out)

        path = getattr(self.client, cmd_resources + "_path")
        if parent_id:
            path = path % parent_id
        cmd_parser = cmd.get_parser("list_" + cmd_resources)
        resp = (MyResp(200), resstr)

        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request:
            shell.run_command(cmd, cmd_parser, args)

        self.assert_mock_multiple_calls_with_same_arguments(
            mock_get_client, mock.call(), None)
        mock_request.assert_called_once_with(
            end_url(path), 'GET',
            body=None,
            headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
开发者ID:openstack,项目名称:python-neutronclient,代码行数:26,代码来源:test_cli20.py


示例5: _test_update_resource

    def _test_update_resource(self, resource, cmd, myid, args, extrafields,
                              cmd_resource=None, parent_id=None):
        if not cmd_resource:
            cmd_resource = resource

        body = {resource: extrafields}
        path = getattr(self.client, cmd_resource + "_path")

        if parent_id:
            path = path % (parent_id, myid)
        else:
            path = path % extrafields['vcenter_id']
        mock_body = MyComparator(body, self.client)

        cmd_parser = cmd.get_parser("update_" + cmd_resource)

        resp = (MyResp(204), None)
        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request:

            neutronshell.run_command(cmd, cmd_parser, args)
            _str = self.fake_stdout.make_string()
            self.assertEqual(_str, '')

            self.assert_mock_multiple_calls_with_same_arguments(
                mock_get_client, mock.call(), None)

            mock_request.asswert_called_once_with(
                MyUrlComparator(end_url(path), self.client),
                'PUT',
                body=mock_body,
                headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
开发者ID:openstack,项目名称:networking-vsphere,代码行数:34,代码来源:test_cli20.py


示例6: _test_show_resource

    def _test_show_resource(self, resource, cmd, myid, args, fields=(), cmd_resource=None, parent_id=None):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        if not cmd_resource:
            cmd_resource = resource

        query = "&".join(["fields=%s" % field for field in fields])
        expected_res = {resource: {self.id_field: myid, "name": "myname"}}
        resstr = self.client.serialize(expected_res)
        path = getattr(self.client, cmd_resource + "_path")
        if parent_id:
            path = path % (parent_id, myid)
        else:
            path = path % myid
        self.client.httpclient.request(
            end_url(path, query, format=self.format),
            "GET",
            body=None,
            headers=mox.ContainsKeyValue("X-Auth-Token", TOKEN),
        ).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("show_" + cmd_resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertIn(myid, _str)
        self.assertIn("myname", _str)
开发者ID:Juniper,项目名称:python-neutronclient,代码行数:29,代码来源:test_cli20.py


示例7: _test_create_resource

    def _test_create_resource(self, resource, cmd,
                              name, myid, args,
                              position_names, position_values, tenant_id=None,
                              tags=None, admin_state_up=True, extra_body=None,
                              **kwargs):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        non_admin_status_resources = ['subnet', 'floatingip', 'security_group',
                                      'security_group_rule', 'qos_queue',
                                      'network_gateway', 'gateway_device',
                                      'credential', 'network_profile',
                                      'policy_profile', 'ikepolicy',
                                      'ipsecpolicy', 'metering_label',
                                      'metering_label_rule', 'net_partition']
        if (resource in non_admin_status_resources):
            body = {resource: {}, }
        else:
            body = {resource: {'admin_state_up': admin_state_up, }, }
        if tenant_id:
            body[resource].update({'tenant_id': tenant_id})
        if tags:
            body[resource].update({'tags': tags})
        if extra_body:
            body[resource].update(extra_body)
        body[resource].update(kwargs)

        for i in range(len(position_names)):
            body[resource].update({position_names[i]: position_values[i]})
        ress = {resource:
                {self.id_field: myid}, }
        if name:
            ress[resource].update({'name': name})
        self.client.format = self.format
        resstr = self.client.serialize(ress)
        # url method body
        resource_plural = neutronV2_0._get_resource_plural(resource,
                                                           self.client)
        path = getattr(self.client, resource_plural + "_path")
        # Work around for LP #1217791. XML deserializer called from
        # MyComparator does not decodes XML string correctly.
        if self.format == 'json':
            mox_body = MyComparator(body, self.client)
        else:
            mox_body = self.client.serialize(body)
        self.client.httpclient.request(
            end_url(path, format=self.format), 'POST',
            body=mox_body,
            headers=mox.ContainsKeyValue(
                'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr))
        args.extend(['--request-format', self.format])
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser('create_' + resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertIn(myid, _str)
        if name:
            self.assertIn(name, _str)
开发者ID:carrierstack,项目名称:python-neutronclient,代码行数:60,代码来源:test_cli20.py


示例8: test_list_external_nets_empty_with_column

 def test_list_external_nets_empty_with_column(self):
     resources = "networks"
     cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
     self.mox.StubOutWithMock(cmd, "get_client")
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     self.mox.StubOutWithMock(network.ListNetwork, "extend_list")
     network.ListNetwork.extend_list(mox.IsA(list), mox.IgnoreArg())
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     reses = {resources: []}
     resstr = self.client.serialize(reses)
     # url method body
     query = "router%3Aexternal=True&id=myfakeid"
     args = ['-c', 'id', '--', '--id', 'myfakeid']
     path = getattr(self.client, resources + "_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, query), 'GET',
         body=None,
         headers=mox.ContainsKeyValue(
             'X-Auth-Token',
             test_cli20.TOKEN)).AndReturn(
                 (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     cmd_parser = cmd.get_parser("list_" + resources)
     shell.run_command(cmd, cmd_parser, args)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
     _str = self.fake_stdout.make_string()
     self.assertEquals('\n', _str)
开发者ID:niuzhenguo,项目名称:python-neutronclient,代码行数:28,代码来源:test_cli20_network.py


示例9: test_list_external_nets_empty_with_column

    def test_list_external_nets_empty_with_column(self):
        resources = "networks"
        cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
        reses = {resources: []}
        resstr = self.client.serialize(reses)
        # url method body
        query = "router%3Aexternal=True&id=myfakeid"
        args = ['-c', 'id', '--', '--id', 'myfakeid']
        path = getattr(self.client, resources + "_path")
        resp = (test_cli20.MyResp(200), resstr)
        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request, \
                mock.patch.object(network.ListNetwork, "extend_list",
                                  return_value=None) as mock_extend_list:
            cmd_parser = cmd.get_parser("list_" + resources)
            shell.run_command(cmd, cmd_parser, args)

        mock_get_client.assert_called_once_with()
        mock_request.assert_called_once_with(
            test_cli20.MyUrlComparator(
                test_cli20.end_url(path, query), self.client),
            'GET',
            body=None,
            headers=test_cli20.ContainsKeyValue(
                {'X-Auth-Token': test_cli20.TOKEN}))
        mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
                                                 mock.ANY)
        _str = self.fake_stdout.make_string()
        self.assertEqual('\n', _str)
开发者ID:sajuptpm,项目名称:python-neutronclient,代码行数:31,代码来源:test_cli20_network.py


示例10: _test_list_router_port

    def _test_list_router_port(self, resources, cmd,
                               myid, detail=False, tags=[],
                               fields_1=[], fields_2=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {resources: [{'id': 'myid1', },
                             {'id': 'myid2', }, ], }

        resstr = self.client.serialize(reses)

        # url method body
        query = ""
        args = detail and ['-D', ] or []

        if fields_1:
            for field in fields_1:
                args.append('--fields')
                args.append(field)
        args.append(myid)
        if tags:
            args.append('--')
            args.append("--tag")
        for tag in tags:
            args.append(tag)
        if (not tags) and fields_2:
            args.append('--')
        if fields_2:
            args.append("--fields")
            for field in fields_2:
                args.append(field)
        fields_1.extend(fields_2)
        for field in fields_1:
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field

        for tag in tags:
            if query:
                query += "&tag=" + tag
            else:
                query = "tag=" + tag
        if detail:
            query = query and query + '&verbose=True' or 'verbose=True'
        query = query and query + '&device_id=%s' or 'device_id=%s'
        path = getattr(self.client, resources + "_path")
        self.client.httpclient.request(
            test_cli20.end_url(path, query % myid), 'GET',
            body=None,
            headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
        ).AndReturn((test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()

        self.assertTrue('myid1' in _str)
开发者ID:openstack-vmwareapi-team,项目名称:python-neutronclient,代码行数:60,代码来源:test_cli20_port.py


示例11: _test_update_resource

    def _test_update_resource(self, resource, cmd, myid, args, extrafields,
                              cmd_resource=None, parent_id=None):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        if not cmd_resource:
            cmd_resource = resource

        body = {resource: extrafields}
        path = getattr(self.client, cmd_resource + "_path")

        if parent_id:
            path = path % (parent_id, myid)
        else:
            path = path % extrafields['vcenter_id']
        mox_body = MyComparator(body, self.client)

        self.client.httpclient.request(
            MyUrlComparator(end_url(path, format=self.format),
                            self.client),
            'PUT',
            body=mox_body,
            headers=mox.ContainsKeyValue(
                'X-Auth-Token', TOKEN)).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + cmd_resource)
        neutronshell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        # Delete a given vcenter cluster with given details
        # will return nothing
        self.assertEqual(_str, '')
开发者ID:Mirantis,项目名称:vmware-dvs,代码行数:33,代码来源:test_cli20.py


示例12: test_remove_firewall_rule

    def test_remove_firewall_rule(self):
        # firewall-policy-remove-rule myid ruleid
        resource = 'firewall_policy'
        cmd = firewallpolicy.FirewallPolicyRemoveRule(
            test_cli20.MyApp(sys.stdout),
            None)
        myid = 'myid'
        args = ['myid', 'removerule']
        extrafields = {'firewall_rule_id': 'removerule', }

        body = extrafields
        path = getattr(self.client, resource + "_remove_path")
        cmd_parser = cmd.get_parser(resource + "_remove_rule")
        resp = (test_cli20.MyResp(204), None)

        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request:
            shell.run_command(cmd, cmd_parser, args)
        self.assert_mock_multiple_calls_with_same_arguments(
            mock_get_client, mock.call(), 2)
        mock_request.assert_called_once_with(
            test_cli20.MyUrlComparator(
                test_cli20.end_url(path % myid),
                self.client),
            'PUT', body=test_cli20.MyComparator(body, self.client),
            headers=test_cli20.ContainsKeyValue(
                {'X-Auth-Token': test_cli20.TOKEN}))
开发者ID:noironetworks,项目名称:python-neutronclient,代码行数:29,代码来源:test_cli20_firewallpolicy.py


示例13: test_remove_firewall_rule

    def test_remove_firewall_rule(self):
        # firewall-policy-remove-rule myid ruleid
        resource = 'firewall_policy'
        cmd = firewallpolicy.FirewallPolicyRemoveRule(
            test_cli20.MyApp(sys.stdout),
            None)
        myid = 'myid'
        args = ['myid', 'removerule']
        extrafields = {'firewall_rule_id': 'removerule', }

        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        body = extrafields
        path = getattr(self.client, resource + "_remove_path")
        self.client.httpclient.request(
            test_cli20.MyUrlComparator(
                test_cli20.end_url(path % myid),
                self.client),
            'PUT', body=test_cli20.MyComparator(body, self.client),
            headers=mox.ContainsKeyValue(
                'X-Auth-Token',
                test_cli20.TOKEN)).AndReturn((test_cli20.MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser(resource + "_remove_rule")
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
开发者ID:huntxu,项目名称:python-neutronclient,代码行数:28,代码来源:test_cli20_firewallpolicy.py


示例14: _test_list_resources_with_pagination

 def _test_list_resources_with_pagination(self, resources, cmd):
     self.mox.StubOutWithMock(cmd, "get_client")
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     path = getattr(self.client, resources + "_path")
     fake_query = "marker=myid2&limit=2"
     reses1 = {resources: [{'id': 'myid1', },
                           {'id': 'myid2', }],
               '%s_links' % resources: [{'href': end_url(path, fake_query),
                                         'rel': 'next'}]}
     reses2 = {resources: [{'id': 'myid3', },
                           {'id': 'myid4', }]}
     self.client.format = self.format
     resstr1 = self.client.serialize(reses1)
     resstr2 = self.client.serialize(reses2)
     self.client.httpclient.request(
         end_url(path, "", format=self.format), 'GET',
         body=None,
         headers=mox.ContainsKeyValue(
             'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr1))
     self.client.httpclient.request(
         end_url(path, fake_query, format=self.format), 'GET',
         body=None,
         headers=mox.ContainsKeyValue(
             'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr2))
     self.mox.ReplayAll()
     cmd_parser = cmd.get_parser("list_" + resources)
     args = ['--request-format', self.format]
     shell.run_command(cmd, cmd_parser, args)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
开发者ID:niuzhenguo,项目名称:python-neutronclient,代码行数:31,代码来源:test_cli20.py


示例15: _test_create_resource

    def _test_create_resource(self, resource, cmd, name, myid, args,
                              position_names, position_values,
                              tenant_id=None, tags=None, admin_state_up=True,
                              extra_body=None, cmd_resource=None,
                              parent_id=None, no_api_call=False,
                              expected_exception=None,
                              **kwargs):
        if not cmd_resource:
            cmd_resource = resource
        if (resource in self.non_admin_status_resources):
            body = {resource: {}, }
        else:
            body = {resource: {'admin_state_up': admin_state_up, }, }
        if tenant_id:
            body[resource].update({'tenant_id': tenant_id})
        if tags:
            body[resource].update({'tags': tags})
        if extra_body:
            body[resource].update(extra_body)
        body[resource].update(kwargs)

        for i in range(len(position_names)):
            body[resource].update({position_names[i]: position_values[i]})
        ress = {resource:
                {self.id_field: myid}, }
        if name:
            ress[resource].update({'name': name})
        resstr = self.client.serialize(ress)
        # url method body
        resource_plural = self.client.get_resource_plural(cmd_resource)
        path = getattr(self.client, resource_plural + "_path")
        if parent_id:
            path = path % parent_id
        mock_body = MyComparator(body, self.client)

        cmd_parser = cmd.get_parser('create_' + resource)
        resp = (MyResp(200), resstr)

        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request:
            if expected_exception:
                self.assertRaises(expected_exception,
                                  shell.run_command, cmd, cmd_parser, args)
            else:
                shell.run_command(cmd, cmd_parser, args)

        self.assert_mock_multiple_calls_with_same_arguments(
            mock_get_client, mock.call(), None)
        if not no_api_call:
            mock_request.assert_called_once_with(
                end_url(path), 'POST',
                body=mock_body,
                headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
        if not expected_exception:
            _str = self.fake_stdout.make_string()
            self.assertIn(myid, _str)
            if name:
                self.assertIn(name, _str)
开发者ID:openstack,项目名称:python-neutronclient,代码行数:60,代码来源:test_cli20.py


示例16: _test_update_resource

 def _test_update_resource(self, resource, cmd, myid, args, extrafields):
     self.mox.StubOutWithMock(cmd, "get_client")
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     body = {resource: extrafields}
     path = getattr(self.client, resource + "_path")
     self.client.format = self.format
     # Work around for LP #1217791. XML deserializer called from
     # MyComparator does not decodes XML string correctly.
     if self.format == 'json':
         mox_body = MyComparator(body, self.client)
     else:
         mox_body = self.client.serialize(body)
     self.client.httpclient.request(
         MyUrlComparator(end_url(path % myid, format=self.format),
                         self.client),
         'PUT',
         body=mox_body,
         headers=mox.ContainsKeyValue(
             'X-Auth-Token', TOKEN)).AndReturn((MyResp(204), None))
     args.extend(['--request-format', self.format])
     self.mox.ReplayAll()
     cmd_parser = cmd.get_parser("update_" + resource)
     shell.run_command(cmd, cmd_parser, args)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
     _str = self.fake_stdout.make_string()
     self.assertIn(myid, _str)
开发者ID:carrierstack,项目名称:python-neutronclient,代码行数:28,代码来源:test_cli20.py


示例17: _test_delete_resource

 def _test_delete_resource(self, resource, cmd, myid, args,
                           cmd_resource=None, parent_id=None):
     self.mox.StubOutWithMock(cmd, "get_client")
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     if not cmd_resource:
         cmd_resource = resource
     path = getattr(self.client, cmd_resource + "_path")
     if parent_id:
         path = path % (parent_id, myid)
     else:
         path = path % (myid)
     self.client.httpclient.request(
         end_url(path, format=self.format), 'DELETE',
         body=None,
         headers=mox.ContainsKeyValue(
             'X-Auth-Token', TOKEN)).AndReturn((MyResp(204), None))
     args.extend(['--request-format', self.format])
     self.mox.ReplayAll()
     cmd_parser = cmd.get_parser("delete_" + cmd_resource)
     shell.run_command(cmd, cmd_parser, args)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
     _str = self.fake_stdout.make_string()
     self.assertIn(myid, _str)
开发者ID:gocloudxyz,项目名称:rackspace-python-neutronclient,代码行数:25,代码来源:test_cli20.py


示例18: _test_update_resource

    def _test_update_resource(self, resource, cmd, myid, args, extrafields, cmd_resource=None, parent_id=None):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        if not cmd_resource:
            cmd_resource = resource

        body = {resource: extrafields}
        path = getattr(self.client, cmd_resource + "_path")
        if parent_id:
            path = path % (parent_id, myid)
        else:
            path = path % myid
        mox_body = MyComparator(body, self.client)

        self.client.httpclient.request(
            MyUrlComparator(end_url(path, format=self.format), self.client),
            "PUT",
            body=mox_body,
            headers=mox.ContainsKeyValue("X-Auth-Token", TOKEN),
        ).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + cmd_resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertIn(myid, _str)
开发者ID:Juniper,项目名称:python-neutronclient,代码行数:28,代码来源:test_cli20.py


示例19: _test_list_external_nets

    def _test_list_external_nets(self, resources, cmd, detail=False, tags=(), fields_1=(), fields_2=()):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        self.mox.StubOutWithMock(network.ListNetwork, "extend_list")
        network.ListNetwork.extend_list(mox.IsA(list), mox.IgnoreArg())
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {resources: [{"id": "myid1"}, {"id": "myid2"}]}

        resstr = self.client.serialize(reses)

        # url method body
        query = ""
        args = detail and ["-D"] or []
        if fields_1:
            for field in fields_1:
                args.append("--fields")
                args.append(field)
        if tags:
            args.append("--")
            args.append("--tag")
        for tag in tags:
            args.append(tag)
        if (not tags) and fields_2:
            args.append("--")
        if fields_2:
            args.append("--fields")
            for field in fields_2:
                args.append(field)
        for field in itertools.chain(fields_1, fields_2):
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field
        if query:
            query += "&router%3Aexternal=True"
        else:
            query += "router%3Aexternal=True"
        for tag in tags:
            if query:
                query += "&tag=" + tag
            else:
                query = "tag=" + tag
        if detail:
            query = query and query + "&verbose=True" or "verbose=True"
        path = getattr(self.client, resources + "_path")

        self.client.httpclient.request(
            test_cli20.MyUrlComparator(test_cli20.end_url(path, query), self.client),
            "GET",
            body=None,
            headers=mox.ContainsKeyValue("X-Auth-Token", test_cli20.TOKEN),
        ).AndReturn((test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()

        self.assertIn("myid1", _str)
开发者ID:gocloudxyz,项目名称:rackspace-python-neutronclient,代码行数:60,代码来源:test_cli20_network.py


示例20: test_list_nets_empty_with_column

 def test_list_nets_empty_with_column(self):
     resources = "networks"
     cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
     self.mox.StubOutWithMock(cmd, "get_client")
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     self.mox.StubOutWithMock(network.ListNetwork, "extend_list")
     network.ListNetwork.extend_list(mox.IsA(list), mox.IgnoreArg())
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     reses = {resources: []}
     resstr = self.client.serialize(reses)
     # url method body
     query = "id=myfakeid"
     args = ["-c", "id", "--", "--id", "myfakeid"]
     path = getattr(self.client, resources + "_path")
     self.client.httpclient.request(
         test_cli20.MyUrlComparator(test_cli20.end_url(path, query), self.client),
         "GET",
         body=None,
         headers=mox.ContainsKeyValue("X-Auth-Token", test_cli20.TOKEN),
     ).AndReturn((test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     cmd_parser = cmd.get_parser("list_" + resources)
     shell.run_command(cmd, cmd_parser, args)
     self.mox.VerifyAll()
     self.mox.UnsetStubs()
     _str = self.fake_stdout.make_string()
     self.assertEqual("\n", _str)
开发者ID:gocloudxyz,项目名称:rackspace-python-neutronclient,代码行数:27,代码来源:test_cli20_network.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_cli20.end_url函数代码示例发布时间:2022-05-27
下一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap