def test_update_quota(self):
     resource = 'quota'
     cmd = test_quota.UpdateQuota(test_cli20.MyApp(sys.stdout), None)
     args = ['--tenant-id', self.test_id, '--network', 'test']
     self.assertRaises(exceptions.NeutronClientException,
                       self._test_update_resource,
                       resource,
                       cmd,
                       self.test_id,
                       args=args,
                       extrafields={'network': 'new'})
 def test_create_port_secgroup(self):
     """Create port: --security-group sg1_id netid."""
     resource = 'port'
     cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     args = ['--security-group', 'sg1_id', netid]
     position_names = ['network_id', 'security_groups']
     position_values = [netid, ['sg1_id']]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
Example #3
0
 def test_disconnect_network_from_gateway(self):
     cmd = nwgw.DisconnectNetworkGateway(test_cli20.MyApp(sys.stdout), None)
     args = [
         'gw_id', 'net_id', '--segmentation-type', 'edi',
         '--segmentation-id', '7'
     ]
     self._test_update_resource_action(
         self.resource, cmd, 'gw_id', 'disconnect_network', args, {
             'network_id': 'net_id',
             'segmentation_type': 'edi',
             'segmentation_id': '7'
         })
Example #4
0
 def test_create_qos_queue(self):
     """Create a qos queue."""
     resource = 'qos_queue'
     cmd = qos.CreateQoSQueue(test_cli20.MyApp(sys.stdout), None)
     myid = 'myid'
     name = 'my_queue'
     default = False
     args = ['--default', default, name]
     position_names = ['name', 'default']
     position_values = [name, default]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
 def test_create_security_group(self):
     """Create security group: webservers."""
     resource = 'security_group'
     cmd = securitygroup.CreateSecurityGroup(
         test_cli20.MyApp(sys.stdout), None)
     name = 'webservers'
     myid = 'myid'
     args = [name, ]
     position_names = ['name']
     position_values = [name]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
Example #6
0
 def test_set_gateway(self):
     """Set external gateway for router: myid externalid."""
     resource = 'router'
     cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
     args = ['myid', 'externalid']
     self._test_update_resource(
         resource, cmd, 'myid', args, {
             "external_gateway_info": {
                 "network_id": "externalid",
                 "enable_snat": True
             }
         })
 def test_create_port(self):
     """Create port: netid."""
     resource = 'port'
     cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     args = [netid]
     position_names = ['network_id']
     position_values = []
     position_values.extend([netid])
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
Example #8
0
 def test_create_subnet_with_no_gateway(self):
     """Create subnet: --no-gateway netid cidr."""
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'cidrvalue'
     args = ['--no-gateway', netid, cidr]
     position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
     position_values = [4, netid, cidr, None]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
 def test_create_security_group_tenant(self):
     """Create security group: webservers."""
     resource = 'security_group'
     cmd = securitygroup.CreateSecurityGroup(
         test_cli20.MyApp(sys.stdout), None)
     name = 'webservers'
     description = 'my webservers'
     myid = 'myid'
     args = ['--tenant_id', 'tenant_id', '--description', description, name]
     position_names = ['name', 'description']
     position_values = [name, description]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values,
                                tenant_id='tenant_id')
Example #10
0
 def test_create_subnet_tenant(self):
     """Create subnet: --tenant_id tenantid netid cidr."""
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'prefixvalue'
     args = ['--tenant_id', 'tenantid', netid, cidr]
     position_names = ['ip_version', 'network_id', 'cidr']
     position_values = [4, netid, cidr]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values,
                                tenant_id='tenantid')
Example #11
0
 def test_create_subnet_tags(self):
     """Create subnet: netid cidr --tags a b."""
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'prefixvalue'
     args = [netid, cidr, '--tags', 'a', 'b']
     position_names = ['ip_version', 'network_id', 'cidr']
     position_values = [4, netid, cidr]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values,
                                tags=['a', 'b'])
 def test_update_vip_with_session_persistence_and_name(self):
     resource = 'vip'
     cmd = vip.UpdateVip(test_cli20.MyApp(sys.stdout), None)
     body = {
         'name': 'newname',
         'session_persistence': {
             'type': 'cookie',
             'cookie_name': 'pie',
         },
     }
     args = [
         'myid', '--name', 'newname', '--session-persistence', 'type=dict',
         'type=cookie,cookie_name=pie'
     ]
     self._test_update_resource(resource, cmd, 'myid', args, body)
Example #13
0
 def test_create_gateway(self):
     cmd = nwgw.CreateNetworkGateway(test_cli20.MyApp(sys.stdout), None)
     name = 'gw-test'
     myid = 'myid'
     args = [
         name,
     ]
     position_names = [
         'name',
     ]
     position_values = [
         name,
     ]
     self._test_create_resource(self.resource, cmd, name, myid, args,
                                position_names, position_values)
    def _test_list_nets_extend_subnets(self, data, expected):
        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)

        cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
        self.mox.StubOutWithMock(cmd, 'get_client')
        self.mox.StubOutWithMock(self.client.httpclient, 'request')
        cmd.get_client().AndReturn(self.client)
        setup_list_stub('networks', data, '')
        cmd.get_client().AndReturn(self.client)
        filters = ''
        for n in data:
            for s in n['subnets']:
                filters = filters + "&id=%s" % s
        setup_list_stub('subnets', [{
            'id': 'mysubid1',
            'cidr': '192.168.1.0/24'
        }, {
            'id': 'mysubid2',
            'cidr': '172.16.0.0/24'
        }, {
            'id': 'mysubid3',
            'cidr': '10.1.1.0/24'
        }],
                        query='fields=id&fields=cidr' + filters)
        self.mox.ReplayAll()

        args = []
        cmd_parser = cmd.get_parser('list_networks')
        parsed_args = cmd_parser.parse_args(args)
        result = cmd.get_data(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _result = [x for x in result[1]]
        self.assertEqual(len(_result), len(expected))
        for res, exp in zip(_result, expected):
            self.assertEqual(len(res), len(exp))
            for a, b in zip(res, exp):
                self.assertEqual(a, b)
 def _test_extend_list(self, mox_calls):
     data = [{
         'id': 'netid%d' % i,
         'name': 'net%d' % i,
         'subnets': ['mysubid%d' % i]
     } for i in range(0, 10)]
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, 'subnets_path')
     cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
     self.mox.StubOutWithMock(cmd, "get_client")
     cmd.get_client().MultipleTimes().AndReturn(self.client)
     mox_calls(path, data)
     self.mox.ReplayAll()
     known_args, _vs = cmd.get_parser('create_subnets').parse_known_args()
     cmd.extend_list(data, known_args)
     self.mox.VerifyAll()
 def test_create_network(self):
     """Create net: myname."""
     resource = 'network'
     cmd = network.CreateNetwork(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     args = [
         name,
     ]
     position_names = [
         'name',
     ]
     position_values = [
         name,
     ]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
Example #17
0
 def test_create_router(self):
     """Create router: router1."""
     resource = 'router'
     cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
     name = 'router1'
     myid = 'myid'
     args = [
         name,
     ]
     position_names = [
         'name',
     ]
     position_values = [
         name,
     ]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
 def test_list_nets_with_default_column(self):
     cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
     returned_body = {
         "networks": [{
             "name": "buildname3",
             "id": "id3",
             "tenant_id": "tenant_3",
             "subnets": []
         }]
     }
     self._test_list_nets_columns(cmd, returned_body)
     _str = self.fake_stdout.make_string()
     returned_networks = utils.loads(_str)
     self.assertEquals(1, len(returned_networks))
     net = returned_networks[0]
     self.assertEquals(3, len(net))
     self.assertEquals(0, len(set(net) ^ set(cmd.list_columns)))
 def test_create_network_with_unicode(self):
     """Create net: u'\u7f51\u7edc'."""
     resource = 'network'
     cmd = network.CreateNetwork(test_cli20.MyApp(sys.stdout), None)
     name = u'\u7f51\u7edc'
     myid = 'myid'
     args = [
         name,
     ]
     position_names = [
         'name',
     ]
     position_values = [
         name,
     ]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
 def test_create_floatingip_and_port_and_address(self):
     """Create floatingip: fip1 with a given port and address."""
     resource = 'floatingip'
     cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
     name = 'fip1'
     myid = 'myid'
     pid = 'mypid'
     addr = '10.0.0.99'
     args = [name, '--port_id', pid, '--fixed_ip_address', addr]
     position_names = ['floating_network_id', 'port_id', 'fixed_ip_address']
     position_values = [name, pid, addr]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
     # Test dashed options
     args = [name, '--port-id', pid, '--fixed-ip-address', addr]
     position_names = ['floating_network_id', 'port_id', 'fixed_ip_address']
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
    def test_create_floatingip_and_port(self):
        """Create floatingip: fip1."""
        resource = 'floatingip'
        cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
        name = 'fip1'
        myid = 'myid'
        pid = 'mypid'
        args = [name, '--port_id', pid]
        position_names = ['floating_network_id', 'port_id']
        position_values = [name, pid]
        self._test_create_resource(resource, cmd, name, myid, args,
                                   position_names, position_values)

        # Test dashed options
        args = [name, '--port-id', pid]
        position_names = ['floating_network_id', 'port_id']
        self._test_create_resource(resource, cmd, name, myid, args,
                                   position_names, position_values)
Example #22
0
 def test_create_subnet_with_bad_gateway_option(self):
     """Create sbunet: --no-gateway netid cidr."""
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'cidrvalue'
     gateway = 'gatewayvalue'
     args = ['--gateway', gateway, '--no-gateway', netid, cidr]
     position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
     position_values = [4, netid, cidr, None]
     try:
         self._test_create_resource(resource, cmd, name, myid, args,
                                    position_names, position_values)
     except Exception:
         return
     self.fail('No exception for bad gateway option')
Example #23
0
 def test_create_subnet_merge_plurar(self):
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'prefixvalue'
     args = ['--tenant_id', 'tenantid',
             netid, cidr,
             '--allocation-pools', 'list=true', 'type=dict',
             'start=1.1.1.30,end=1.1.1.40']
     position_names = ['ip_version', 'allocation_pools', 'network_id',
                       'cidr']
     pools = [{'start': '1.1.1.30', 'end': '1.1.1.40'}]
     position_values = [4, pools, netid, cidr]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values,
                                tenant_id='tenantid')
    def test_create_port_full(self):
        """Create port: --mac_address mac --device_id deviceid netid."""
        resource = 'port'
        cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
        name = 'myname'
        myid = 'myid'
        netid = 'netid'
        args = ['--mac_address', 'mac', '--device_id', 'deviceid', netid]
        position_names = ['network_id', 'mac_address', 'device_id']
        position_values = [netid, 'mac', 'deviceid']
        self._test_create_resource(resource, cmd, name, myid, args,
                                   position_names, position_values)

        # Test dashed options
        args = ['--mac-address', 'mac', '--device-id', 'deviceid', netid]
        position_names = ['network_id', 'mac_address', 'device_id']
        self._test_create_resource(resource, cmd, name, myid, args,
                                   position_names, position_values)
 def test_list_nets_defined_column(self):
     cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
     returned_body = {
         "networks": [{
             "name": "buildname3",
             "id": "id3",
             "tenant_id": "tenant_3",
             "subnets": []
         }]
     }
     self._test_list_nets_columns(cmd,
                                  returned_body,
                                  args=['-f', 'json', '-c', 'id'])
     _str = self.fake_stdout.make_string()
     returned_networks = utils.loads(_str)
     self.assertEquals(1, len(returned_networks))
     net = returned_networks[0]
     self.assertEquals(1, len(net))
     self.assertEquals("id", net.keys()[0])
 def test_create_port_tags(self):
     """Create port: netid mac_address device_id --tags a b."""
     resource = 'port'
     cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     args = [netid, '--tags', 'a', 'b']
     position_names = ['network_id']
     position_values = []
     position_values.extend([netid])
     self._test_create_resource(resource,
                                cmd,
                                name,
                                myid,
                                args,
                                position_names,
                                position_values,
                                tags=['a', 'b'])
Example #27
0
 def test_create_subnet_allocation_pool(self):
     """Create subnet: --tenant_id tenantid <allocation_pool> netid cidr.
     The <allocation_pool> is --allocation_pool start=1.1.1.10,end=1.1.1.20
     """
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'prefixvalue'
     args = ['--tenant_id', 'tenantid',
             '--allocation_pool', 'start=1.1.1.10,end=1.1.1.20',
             netid, cidr]
     position_names = ['ip_version', 'allocation_pools', 'network_id',
                       'cidr']
     pool = [{'start': '1.1.1.10', 'end': '1.1.1.20'}]
     position_values = [4, pool, netid, cidr]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values,
                                tenant_id='tenantid')
Example #28
0
 def test_create_router_tenant(self):
     """Create router: --tenant_id tenantid myname."""
     resource = 'router'
     cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     args = ['--tenant_id', 'tenantid', name]
     position_names = [
         'name',
     ]
     position_values = [
         name,
     ]
     self._test_create_resource(resource,
                                cmd,
                                name,
                                myid,
                                args,
                                position_names,
                                position_values,
                                tenant_id='tenantid')
Example #29
0
 def test_create_qos_queue_all_values(self):
     """Create a qos queue."""
     resource = 'qos_queue'
     cmd = qos.CreateQoSQueue(test_cli20.MyApp(sys.stdout), None)
     myid = 'myid'
     name = 'my_queue'
     default = False
     min = '10'
     max = '40'
     qos_marking = 'untrusted'
     dscp = '0'
     args = [
         '--default', default, '--min', min, '--max', max, '--qos-marking',
         qos_marking, '--dscp', dscp, name
     ]
     position_names = [
         'name', 'default', 'min', 'max', 'qos_marking', 'dscp'
     ]
     position_values = [name, default, min, max, qos_marking, dscp]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values)
Example #30
0
 def test_create_subnet_host_route(self):
     """Create subnet: --tenant_id tenantid <host_route> netid cidr.
     The <host_route> is
     --host-route destination=172.16.1.0/24,nexthop=1.1.1.20
     """
     resource = 'subnet'
     cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
     name = 'myname'
     myid = 'myid'
     netid = 'netid'
     cidr = 'prefixvalue'
     args = ['--tenant_id', 'tenantid',
             '--host-route', 'destination=172.16.1.0/24,nexthop=1.1.1.20',
             netid, cidr]
     position_names = ['ip_version', 'host_routes', 'network_id',
                       'cidr']
     route = [{'destination': '172.16.1.0/24', 'nexthop': '1.1.1.20'}]
     position_values = [4, route, netid, cidr]
     self._test_create_resource(resource, cmd, name, myid, args,
                                position_names, position_values,
                                tenant_id='tenantid')