~asomya/+junk/quantum-dev

« back to all changes in this revision

Viewing changes to test_scripts/tests.py

* Merged changes from Salvatore's branch - quantum-api-workinprogress
* Removed spurious methods from quantum_base_plugin class.
* Updated the sample plugins to be compliant with the new QuantumBase class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2011 Citrix Systems
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
import gettext
 
19
 
 
20
gettext.install('quantum', unicode=1)
 
21
 
 
22
from miniclient import MiniClient
 
23
from quantum.common.wsgi import Serializer
 
24
 
 
25
HOST = '127.0.0.1'
 
26
PORT = 9696
 
27
USE_SSL = False
 
28
TENANT_ID = 'totore'
 
29
 
 
30
test_network_data = \
 
31
    {'network': {'network-name': 'test' }}
 
32
 
 
33
def print_response(res):
 
34
    content = res.read()
 
35
    print "Status: %s" %res.status
 
36
    print "Content: %s" %content
 
37
    return content
 
38
 
 
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)
 
45
    print_response(res)
 
46
    print "--> Step 2 - Details for Network 001"
 
47
    res = client.do_request(TENANT_ID,'GET', "/networks/001." + format)
 
48
    print_response(res)
 
49
    print "--> Step 3 - Ports for Network 001"
 
50
    res = client.do_request(TENANT_ID,'GET', "/networks/001/ports." + format)
 
51
    print_response(res)
 
52
    print "--> Step 4 - Details for Port 1"
 
53
    res = client.do_request(TENANT_ID,'GET', "/networks/001/ports/1." + format)
 
54
    print_response(res)
 
55
    print "COMPLETED"
 
56
    print "----------------------------"
 
57
    
 
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)
 
66
    print_response(res)
 
67
    print "--> Step 2 - List All Networks"
 
68
    res = client.do_request(TENANT_ID,'GET', "/networks." + format)
 
69
    print_response(res)
 
70
    print "COMPLETED"
 
71
    print "----------------------------"
 
72
 
 
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)
 
80
    print_response(res)
 
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)
 
85
    print_response(res)
 
86
    print "--> Step 2 - Retrieve network (again)"
 
87
    res = client.do_request(TENANT_ID,'GET', "/networks/001." + format)
 
88
    print_response(res)
 
89
    print "COMPLETED"
 
90
    print "----------------------------"
 
91
    
 
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)
 
101
    print network_data
 
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)
 
106
    print_response(res)
 
107
    print "--> Step 3 - List All Networks (Again)"
 
108
    res = client.do_request(TENANT_ID,'GET', "/networks." + format)
 
109
    print_response(res)
 
110
    print "COMPLETED"
 
111
    print "----------------------------"
 
112
 
 
113
 
 
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)
 
120
    print_response(res)
 
121
    print "--> Step 2 - Create Port for network 001"
 
122
    res = client.do_request(TENANT_ID,'POST', "/networks/001/ports." + format)
 
123
    print_response(res)
 
124
    print "--> Step 3 - List Ports for network 001 (again)"
 
125
    res = client.do_request(TENANT_ID,'GET', "/networks/001/ports." + format)
 
126
    print_response(res)
 
127
    print "COMPLETED"
 
128
    print "----------------------------"
 
129
 
 
130
 
 
131
def main():
 
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')
 
144
    
 
145
    pass
 
146
    
 
147
 
 
148
# Standard boilerplate to call the main() function.
 
149
if __name__ == '__main__':
 
150
    main()
 
 
b'\\ No newline at end of file'