summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/contrib/fakes.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/contrib/fakes.py')
-rw-r--r--novaclient/tests/unit/v2/contrib/fakes.py151
1 files changed, 151 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/contrib/fakes.py b/novaclient/tests/unit/v2/contrib/fakes.py
new file mode 100644
index 0000000..8703395
--- /dev/null
+++ b/novaclient/tests/unit/v2/contrib/fakes.py
@@ -0,0 +1,151 @@
1# Copyright 2012 OpenStack Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from novaclient.tests.unit.v2 import fakes
16from novaclient.v2 import client
17
18
19class FakeClient(fakes.FakeClient):
20 def __init__(self, *args, **kwargs):
21 client.Client.__init__(self, 'username', 'password',
22 'project_id', 'auth_url',
23 extensions=kwargs.get('extensions'))
24 self.client = FakeHTTPClient(**kwargs)
25
26
27class FakeHTTPClient(fakes.FakeHTTPClient):
28 def get_os_tenant_networks(self):
29 return (200, {}, {
30 'networks': [{"label": "1", "cidr": "10.0.0.0/24",
31 'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
32 'id': '1'}]})
33
34 def get_os_tenant_networks_1(self, **kw):
35 return (200, {}, {
36 'network': {"label": "1", "cidr": "10.0.0.0/24",
37 'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
38 'id': '1'}})
39
40 def post_os_tenant_networks(self, **kw):
41 return (201, {}, {
42 'network': {"label": "1", "cidr": "10.0.0.0/24",
43 'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
44 'id': '1'}})
45
46 def delete_os_tenant_networks_1(self, **kw):
47 return (204, {}, None)
48
49 def get_os_baremetal_nodes(self, **kw):
50 return (
51 200, {}, {
52 'nodes': [
53 {
54 "id": 1,
55 "instance_uuid": None,
56 "interfaces": [],
57 "cpus": 2,
58 "local_gb": 10,
59 "memory_mb": 5,
60 "pm_address": "2.3.4.5",
61 "pm_user": "pmuser",
62 "pm_password": "pmpass",
63 "prov_mac_address": "aa:bb:cc:dd:ee:ff",
64 "prov_vlan_id": 1,
65 "service_host": "somehost",
66 "terminal_port": 8080,
67 }
68 ]
69 }
70 )
71
72 def get_os_baremetal_nodes_1(self, **kw):
73 return (
74 200, {}, {
75 'node': {
76 "id": 1,
77 "instance_uuid": None,
78 "pm_address": "1.2.3.4",
79 "interfaces": [],
80 "cpus": 2,
81 "local_gb": 10,
82 "memory_mb": 5,
83 "pm_user": "pmuser",
84 "pm_password": "pmpass",
85 "prov_mac_address": "aa:bb:cc:dd:ee:ff",
86 "prov_vlan_id": 1,
87 "service_host": "somehost",
88 "terminal_port": 8080,
89 }
90 }
91 )
92
93 def post_os_baremetal_nodes(self, **kw):
94 return (
95 200, {}, {
96 'node': {
97 "id": 1,
98 "instance_uuid": None,
99 "cpus": 2,
100 "local_gb": 10,
101 "memory_mb": 5,
102 "pm_address": "2.3.4.5",
103 "pm_user": "pmuser",
104 "pm_password": "pmpass",
105 "prov_mac_address": "aa:bb:cc:dd:ee:ff",
106 "prov_vlan_id": 1,
107 "service_host": "somehost",
108 "terminal_port": 8080,
109 }
110 }
111 )
112
113 def delete_os_baremetal_nodes_1(self, **kw):
114 return (202, {}, {})
115
116 def post_os_baremetal_nodes_1_action(self, **kw):
117 body = kw['body']
118 action = list(body)[0]
119 if action == "add_interface":
120 return (
121 200, {}, {
122 'interface': {
123 "id": 2,
124 "address": "bb:cc:dd:ee:ff:aa",
125 "datapath_id": 1,
126 "port_no": 2,
127 }
128 }
129 )
130 elif action == "remove_interface":
131 return (202, {}, {})
132 else:
133 return (500, {}, {})
134
135 def post_os_assisted_volume_snapshots(self, **kw):
136 return (202, {}, {'snapshot': {'id': 'blah', 'volumeId': '1'}})
137
138 def delete_os_assisted_volume_snapshots_x(self, **kw):
139 return (202, {}, {})
140
141 def post_os_server_external_events(self, **kw):
142 return (200, {}, {
143 'events': [
144 {'name': 'test-event',
145 'status': 'completed',
146 'tag': 'tag',
147 'server_uuid': 'fake-uuid1'},
148 {'name': 'test-event',
149 'status': 'completed',
150 'tag': 'tag',
151 'server_uuid': 'fake-uuid2'}]})