def test_show_router(self): """Show router: myid.""" resource = 'router' cmd = ShowRouter(MyApp(sys.stdout), None) args = ['--fields', 'id', '--fields', 'name', self.test_id] self._test_show_resource(resource, cmd, self.test_id, args, ['id', 'name'])
def test_show_network(self): """Show net: --fields id --fields name myid.""" resource = 'network' cmd = ShowNetwork(MyApp(sys.stdout), None) args = ['--fields', 'id', '--fields', 'name', self.test_id] self._test_show_resource(resource, cmd, self.test_id, args, ['id', 'name'])
def test_delete_floatingip(self): """Delete floatingip: fip1""" resource = 'floatingip' cmd = DeleteFloatingIP(MyApp(sys.stdout), None) myid = 'myid' args = [myid] self._test_delete_resource(resource, cmd, myid, args)
def test_delete_network(self): """Delete net: myid.""" resource = 'network' cmd = DeleteNetwork(MyApp(sys.stdout), None) myid = 'myid' args = [myid] self._test_delete_resource(resource, cmd, myid, args)
def test_update_router(self): """Update router: myid --name myname --tags a b.""" resource = 'router' cmd = UpdateRouter(MyApp(sys.stdout), None) self._test_update_resource(resource, cmd, 'myid', ['myid', '--name', 'myname'], {'name': 'myname'})
def test_create_network_tenant(self): """Create net: --tenant_id tenantid myname.""" resource = 'network' cmd = CreateNetwork(MyApp(sys.stdout), None) name = 'myname' myid = 'myid' args = ['--tenant_id', 'tenantid', name] position_names = [ 'name', ] position_values = [ name, ] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values, tenant_id='tenantid') # Test dashed options args = ['--tenant-id', 'tenantid', name] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values, tenant_id='tenantid')
def test_delete_port(self): """Delete port: myid.""" resource = 'port' cmd = DeletePort(MyApp(sys.stdout), None) myid = 'myid' args = [myid] self._test_delete_resource(resource, cmd, myid, args)
def test_remove_gateway(self): """Remove external gateway from router: externalid""" resource = 'router' cmd = RemoveGatewayRouter(MyApp(sys.stdout), None) args = ['externalid'] self._test_update_resource(resource, cmd, 'externalid', args, {"external_gateway_info": {}})
def test_delete_router(self): """Delete router: myid.""" resource = 'router' cmd = DeleteRouter(MyApp(sys.stdout), None) myid = 'myid' args = [myid] self._test_delete_resource(resource, cmd, myid, args)
def test_show_port(self): """Show port: --fields id --fields name myid.""" resource = 'port' cmd = ShowPort(MyApp(sys.stdout), None) args = ['--fields', 'id', '--fields', 'name', self.test_id] self._test_show_resource(resource, cmd, self.test_id, args, ['id', 'name'])
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_delete_subnet(self): """Delete subnet: subnetid.""" resource = 'subnet' cmd = DeleteSubnet(MyApp(sys.stdout), None) myid = 'myid' args = [myid] self._test_delete_resource(resource, cmd, myid, args)
def test_create_subnet_allocation_pools(self): """Create subnet: --tenant-id tenantid <pools> netid cidr. The <pools> are --allocation_pool start=1.1.1.10,end=1.1.1.20 and --allocation_pool start=1.1.1.30,end=1.1.1.40 """ resource = 'subnet' cmd = CreateSubnet(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', '--allocation_pool', 'start=1.1.1.30,end=1.1.1.40', netid, cidr ] position_names = [ 'ip_version', 'allocation_pools', 'network_id', 'cidr' ] pools = [{ 'start': '1.1.1.10', 'end': '1.1.1.20' }, { 'start': '1.1.1.30', 'end': '1.1.1.40' }] position_values = [4, pools, netid, cidr] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values, tenant_id='tenantid')
def test_associate_ip(self): """Associate floating IP: myid portid""" resource = 'floatingip' cmd = AssociateFloatingIP(MyApp(sys.stdout), None) args = ['myid', 'portid'] self._test_update_resource(resource, cmd, 'myid', args, {"port_id": "portid"})
def test_list_ports_fields(self): """List ports: --fields a --fields b -- --fields c d.""" resources = "ports" cmd = ListPort(MyApp(sys.stdout), None) self._test_list_resources(resources, cmd, fields_1=['a', 'b'], fields_2=['c', 'd'])
def test_del_interface(self): """Delete interface from router: myid subnetid""" resource = 'router' cmd = RemoveInterfaceRouter(MyApp(sys.stdout), None) args = ['myid', 'subnetid'] self._test_update_resource_action(resource, cmd, 'myid', 'remove_router_interface', args, {'subnet_id': 'subnetid'})
def test_list_nets_fields(self): """List nets: --fields a --fields b -- --fields c d.""" resources = "networks" cmd = ListNetwork(MyApp(sys.stdout), None) self._test_list_resources(resources, cmd, fields_1=['a', 'b'], fields_2=['c', 'd'])
def test_add_interface(self): """Add interface to router: myid subnetid""" resource = 'router' cmd = AddInterfaceRouter(MyApp(sys.stdout), None) args = ['myid', 'subnetid'] self._test_update_resource_action(resource, cmd, 'myid', 'add_router_interface', args, {'subnet_id': 'subnetid'})
def test_update_network(self): """Update net: myid --name myname --tags a b.""" resource = 'network' cmd = UpdateNetwork(MyApp(sys.stdout), None) self._test_update_resource( resource, cmd, 'myid', ['myid', '--name', 'myname', '--tags', 'a', 'b'], { 'name': 'myname', 'tags': ['a', 'b'], })
def test_update_port(self): """Update port: myid --name myname --tags a b.""" resource = 'port' cmd = UpdatePort(MyApp(sys.stdout), None) self._test_update_resource( resource, cmd, 'myid', ['myid', '--name', 'myname', '--tags', 'a', 'b'], { 'name': 'myname', 'tags': ['a', 'b'], })
def test_set_gateway(self): """Set external gateway for router: myid externalid""" resource = 'router' cmd = SetGatewayRouter(MyApp(sys.stdout), None) args = ['myid', 'externalid'] self._test_update_resource( resource, cmd, 'myid', args, {"external_gateway_info": { "network_id": "externalid" }})
def test_create_floatingip(self): """Create floatingip: fip1.""" resource = 'floatingip' cmd = CreateFloatingIP(MyApp(sys.stdout), None) name = 'fip1' myid = 'myid' args = [name] position_names = ['floating_network_id'] position_values = [name] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values)
def test_create_port(self): """Create port: netid.""" resource = 'port' cmd = CreatePort(MyApp(sys.stdout), None) name = 'myname' myid = 'myid' netid = 'netid' args = [netid] position_names = ['network_id'] position_values = [] position_values.extend([netid]) _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values)
def test_create_subnet_with_no_gateway(self): """Create subnet: --no-gateway netid cidr""" resource = 'subnet' cmd = CreateSubnet(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] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values)
def test_create_network(self): """Create net: myname.""" resource = 'network' cmd = CreateNetwork(MyApp(sys.stdout), None) name = 'myname' myid = 'myid' args = [ name, ] position_names = [ 'name', ] position_values = [ name, ] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values)
def test_create_router(self): """Create router: router1.""" resource = 'router' cmd = CreateRouter(MyApp(sys.stdout), None) name = 'router1' myid = 'myid' args = [ name, ] position_names = [ 'name', ] position_values = [ name, ] _str = 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 = CreateFloatingIP(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] _str = 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'] _str = 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 = CreateFloatingIP(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] _str = 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'] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values)
def test_create_port_full(self): """Create port: --mac_address mac --device_id deviceid netid.""" resource = 'port' cmd = CreatePort(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'] _str = 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'] _str = self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values)
def test_list_nets_with_default_column(self): resources = 'networks' cmd = ListNetwork(MyApp(sys.stdout), None) returned_body = { "networks": [{ "name": "buildname3", "id": "id3", "tenant_id": "tenant_3", "subnets": [] }] } self._test_list_columns(cmd, resources, returned_body) _str = self.fake_stdout.make_string() returned_networks = utils.loads(_str) self.assertEquals(1, len(returned_networks)) network = returned_networks[0] self.assertEquals(3, len(network)) self.assertEquals(0, len(set(network) ^ set(cmd.list_columns)))