예제 #1
0
 def test_get_id_from_id_then_name_empty(self):
     _id = str(uuid.uuid4())
     reses = {
         'networks': [
             {
                 'id': _id,
             },
         ],
     }
     resstr = self.client.serialize(reses)
     resstr1 = self.client.serialize({'networks': []})
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, "networks_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&id=" + _id),
         'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr1))
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&name=" + _id),
         'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     returned_id = quantumv20.find_resourceid_by_name_or_id(
         self.client, 'network', _id)
     self.assertEqual(_id, returned_id)
    def test_list_nets_empty_with_column(self):
        resources = "networks"
        cmd = ListNetwork(MyApp(sys.stdout), None)
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        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.end_url(path, query), 'GET',
            body=None,
            headers=test_cli20.ContainsKeyValue(
                'X-Auth-Token',
                test_cli20.TOKEN)).AndReturn(
                    (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertEquals('\n', _str)
    def test_disassociate_healthmonitor(self):
        cmd = healthmonitor.DisassociateHealthMonitor(
            test_cli20.MyApp(sys.stdout),
            None)
        resource = 'health_monitor'
        health_monitor_id = 'hm-id'
        pool_id = 'p_id'
        args = [health_monitor_id, pool_id]

        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)

        path = getattr(self.client,
                       "disassociate_pool_health_monitors_path") % \
            {'pool': pool_id, 'health_monitor': health_monitor_id}
        return_tup = (test_cli20.MyResp(204), None)
        self.client.httpclient.request(
            test_cli20.end_url(path), 'DELETE',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(return_tup)
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser('test_' + resource)
        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
    def test_associate_healthmonitor(self):
        cmd = healthmonitor.AssociateHealthMonitor(
            test_cli20.MyApp(sys.stdout),
            None)
        resource = 'health_monitor'
        health_monitor_id = 'hm-id'
        pool_id = 'p_id'
        args = [health_monitor_id, pool_id]

        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)

        body = {resource: {'id': health_monitor_id}}
        result = {resource: {'id': health_monitor_id}, }
        result_str = self.client.serialize(result)

        path = getattr(self.client,
                       "associate_pool_health_monitors_path") % pool_id
        return_tup = (test_cli20.MyResp(200), result_str)
        self.client.httpclient.request(
            test_cli20.end_url(path), 'POST',
            body=test_cli20.MyComparator(body, self.client),
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(return_tup)
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser('test_' + resource)
        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
    def test_retrieve_pool_stats(self):
        """lb-pool-stats test_id"""
        resource = 'pool'
        cmd = pool.RetrievePoolStats(test_cli20.MyApp(sys.stdout), None)
        my_id = self.test_id
        fields = ['bytes_in', 'bytes_out']
        args = ['--fields', 'bytes_in', '--fields', 'bytes_out', my_id]

        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 = {'stats': {'bytes_in': '1234', 'bytes_out': '4321'}}
        resstr = self.client.serialize(expected_res)
        path = getattr(self.client, "pool_path_stats")
        return_tup = (test_cli20.MyResp(200), resstr)
        self.client.httpclient.request(
            test_cli20.end_url(path % my_id, query), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(return_tup)
        self.mox.ReplayAll()

        cmd_parser = cmd.get_parser("test_" + resource)
        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)

        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue('bytes_in' in _str)
        self.assertTrue('bytes_out' in _str)
예제 #6
0
    def test_list_nets_empty_with_column(self):
        resources = "networks"
        cmd = ListNetwork(MyApp(sys.stdout), None)
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        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.end_url(path, query),
                                       'GET',
                                       body=None,
                                       headers=test_cli20.ContainsKeyValue(
                                           'X-Auth-Token',
                                           test_cli20.TOKEN)).AndReturn(
                                               (test_cli20.MyResp(200),
                                                resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertEquals('\n', _str)
예제 #7
0
 def test_get_id_from_name_multiple(self):
     name = 'myname'
     reses = {
         'networks': [{
             'id': str(uuid.uuid4())
         }, {
             'id': str(uuid.uuid4())
         }]
     }
     resstr = self.client.serialize(reses)
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, "networks_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&name=" + name),
         'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     try:
         quantumv20.find_resourceid_by_name_or_id(self.client, 'network',
                                                  name)
     except exceptions.QuantumClientException as ex:
         self.assertTrue('Multiple' in ex.message)
 def setup_list_stub(resources, data, query):
     reses = {resources: data}
     resstr = self.client.serialize(reses)
     resp = (test_cli20.MyResp(200), resstr)
     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(resp)
 def test_get_id_from_id_then_name_empty(self):
     _id = str(uuid.uuid4())
     reses = {'networks': [{'id': _id, }, ], }
     resstr = self.client.serialize(reses)
     resstr1 = self.client.serialize({'networks': []})
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, "networks_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&id=" + _id), 'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr1))
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&name=" + _id), 'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     returned_id = quantumv20.find_resourceid_by_name_or_id(
         self.client, 'network', _id)
     self.assertEqual(_id, returned_id)
 def test_get_id_from_name_multiple(self):
     name = 'myname'
     reses = {'networks': [{'id': str(uuid.uuid4())},
                           {'id': str(uuid.uuid4())}]}
     resstr = self.client.serialize(reses)
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, "networks_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&name=" + name), 'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     try:
         quantumv20.find_resourceid_by_name_or_id(
             self.client, 'network', name)
     except exceptions.QuantumClientException as ex:
         self.assertTrue('Multiple' in ex.message)
    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")
        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)
        fields_1.extend(fields_2)
        for field in fields_1:
            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.end_url(path, query), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                    (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)

        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()

        self.assertTrue('myid1' in _str)