1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Citrix Systems
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
20
gettext.install('quantum', unicode=1)
22
from miniclient import MiniClient
23
from quantum.common.wsgi import Serializer
31
{'network': {'network-name': 'test' }}
33
def print_response(res):
35
print "Status: %s" %res.status
36
print "Content: %s" %content
39
def test_list_networks_and_ports(format = 'xml'):
40
client = MiniClient(HOST, PORT, USE_SSL)
41
print "TEST LIST NETWORKS AND PORTS -- FORMAT:%s" %format
42
print "----------------------------"
43
print "--> Step 1 - List All Networks"
44
res = client.do_request(TENANT_ID,'GET', "/networks." + format)
46
print "--> Step 2 - Details for Network 001"
47
res = client.do_request(TENANT_ID,'GET', "/networks/001." + format)
49
print "--> Step 3 - Ports for Network 001"
50
res = client.do_request(TENANT_ID,'GET', "/networks/001/ports." + format)
52
print "--> Step 4 - Details for Port 1"
53
res = client.do_request(TENANT_ID,'GET', "/networks/001/ports/1." + format)
56
print "----------------------------"
58
def test_create_network(format = 'xml'):
59
client = MiniClient(HOST, PORT, USE_SSL)
60
print "TEST CREATE NETWORK -- FORMAT:%s" %format
61
print "----------------------------"
62
print "--> Step 1 - Create Network"
63
content_type = "application/" + format
64
body = Serializer().serialize(test_network_data, content_type)
65
res = client.do_request(TENANT_ID,'POST', "/networks." + format, body=body)
67
print "--> Step 2 - List All Networks"
68
res = client.do_request(TENANT_ID,'GET', "/networks." + format)
71
print "----------------------------"
73
def test_rename_network(format = 'xml'):
74
client = MiniClient(HOST, PORT, USE_SSL)
75
content_type = "application/" + format
76
print "TEST RENAME NETWORK -- FORMAT:%s" %format
77
print "----------------------------"
78
print "--> Step 1 - Retrieve network"
79
res = client.do_request(TENANT_ID,'GET', "/networks/001." + format)
81
print "--> Step 2 - Rename network to 'test_renamed'"
82
test_network_data['network']['network-name'] = 'test_renamed'
83
body = Serializer().serialize(test_network_data, content_type)
84
res = client.do_request(TENANT_ID,'PUT', "/networks/001." + format, body=body)
86
print "--> Step 2 - Retrieve network (again)"
87
res = client.do_request(TENANT_ID,'GET', "/networks/001." + format)
90
print "----------------------------"
92
def test_delete_network(format = 'xml'):
93
client = MiniClient(HOST, PORT, USE_SSL)
94
content_type = "application/" + format
95
print "TEST DELETE NETWORK -- FORMAT:%s" %format
96
print "----------------------------"
97
print "--> Step 1 - List All Networks"
98
res = client.do_request(TENANT_ID,'GET', "/networks." + format)
99
content = print_response(res)
100
network_data = Serializer().deserialize(content, content_type)
102
net_id = network_data['networks'][0]['id']
103
print "--> Step 2 - Delete network %s" %net_id
104
res = client.do_request(TENANT_ID,'DELETE',
105
"/networks/" + net_id + "." + format)
107
print "--> Step 3 - List All Networks (Again)"
108
res = client.do_request(TENANT_ID,'GET', "/networks." + format)
111
print "----------------------------"
114
def test_create_port(format = 'xml'):
115
client = MiniClient(HOST, PORT, USE_SSL)
116
print "TEST CREATE PORT -- FORMAT:%s" %format
117
print "----------------------------"
118
print "--> Step 1 - List Ports for network 001"
119
res = client.do_request(TENANT_ID,'GET', "/networks/001/ports." + format)
121
print "--> Step 2 - Create Port for network 001"
122
res = client.do_request(TENANT_ID,'POST', "/networks/001/ports." + format)
124
print "--> Step 3 - List Ports for network 001 (again)"
125
res = client.do_request(TENANT_ID,'GET', "/networks/001/ports." + format)
128
print "----------------------------"
132
test_list_networks_and_ports('xml')
133
test_list_networks_and_ports('json')
134
test_create_network('xml')
135
test_create_network('json')
136
test_rename_network('xml')
137
test_rename_network('json')
138
# NOTE: XML deserializer does not work properly
139
# disabling XML test - this is NOT a server-side issue
140
#test_delete_network('xml')
141
test_delete_network('json')
142
test_create_port('xml')
143
test_create_port('json')
148
# Standard boilerplate to call the main() function.
149
if __name__ == '__main__':
b'\\ No newline at end of file'