1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import mock
from troveclient.tests import fakes
from troveclient.tests.osc import utils
from troveclient.v1 import backups
from troveclient.v1 import clusters
from troveclient.v1 import configurations
from troveclient.v1 import databases
from troveclient.v1 import datastores
from troveclient.v1 import flavors
from troveclient.v1 import instances
from troveclient.v1 import limits
from troveclient.v1 import modules
from troveclient.v1 import quota
from troveclient.v1 import users
class TestDatabasev1(utils.TestCommand):
def setUp(self):
super(TestDatabasev1, self).setUp()
self.app.client_manager.database = mock.MagicMock()
class FakeFlavors(object):
fake_flavors = fakes.FakeHTTPClient().get_flavors()[2]['flavors']
def get_flavors_1(self):
return flavors.Flavor(None, self.fake_flavors[0])
class FakeBackups(object):
fake_backups = fakes.FakeHTTPClient().get_backups()[2]['backups']
def get_backup_bk_1234(self):
return backups.Backup(None, self.fake_backups[0])
class FakeClusters(object):
fake_clusters = fakes.FakeHTTPClient().get_clusters()[2]['clusters']
fake_cluster = (fakes.FakeHTTPClient()
.get_clusters_cls_1234()[2]['cluster'])
fake_cluster_member = fake_cluster['instances'][1]
fake_cluster_instance_modules = (fakes.FakeHTTPClient().
get_cluster_instance_modules()[2]
['modules'])
def get_clusters_cls_1234(self):
return clusters.Cluster(None, self.fake_cluster)
def get_clusters_member_2(self):
return instances.Instance(None, self.fake_cluster_member)
def cluster_instance_modules(self):
return [[modules.Module(None, mod)]
for mod in self.fake_cluster_instance_modules]
class FakeConfigurations(object):
fake_config = (fakes.FakeHTTPClient().get_configurations()
[2]['configurations'])
fake_config_instances = (fakes.FakeHTTPClient().
get_configurations_c_123_instances()[2])
def get_configurations_c_123(self):
return configurations.Configuration(None, self.fake_config[0])
def get_configuration_instances(self):
return [instances.Instance(None, fake_instance)
for fake_instance in self.fake_config_instances['instances']]
class FakeConfigurationParameters(object):
fake_config_param = (fakes.FakeHTTPClient().
get_datastores_d_123_versions_v_156_parameters()
[2]['configuration-parameters'])
def get_params_connect_timeout(self):
return configurations.\
ConfigurationParameter(None, self.fake_config_param[1])
class FakeLimits(object):
fake_limits = fakes.FakeHTTPClient().get_limits()[2]['limits']
def get_absolute_limits(self):
return limits.Limit(None, self.fake_limits[0])
def get_non_absolute_limits(self):
return limits.Limit(None,
{'value': 200,
'verb': 'DELETE',
'remaining': 200,
'unit': 'MINUTE'})
class FakeUsers(object):
fake_users = fakes.FakeHTTPClient().get_instances_1234_users()[2]['users']
fake_user_access = fakes.FakeHTTPClient().\
get_instances_1234_users_jacob_databases()[2]
def get_instances_1234_users_harry(self):
return users.User(None, self.fake_users[2])
def get_instances_1234_users_access(self):
return [databases.Database(self, db) for db in
self.fake_user_access['databases']]
class FakeInstances(object):
fake_instances = (fakes.FakeHTTPClient().get_instances()[2]['instances'])
fake_instance = fakes.FakeHTTPClient().get_instance_create()[2]
def get_instances_1234(self):
return instances.Instance(None, self.fake_instances[0])
def get_instances(self):
return [instances.Instance(None, fake_instance)
for fake_instance in self.fake_instances]
def get_instance_create(self):
return instances.Instance(None, self.fake_instance['instance'])
class FakeDatabases(object):
fake_databases = [{'name': 'fakedb1'}]
def get_databases_1(self):
return databases.Database(None, self.fake_databases[0])
class FakeDatastores(object):
fake_datastores = fakes.FakeHTTPClient().get_datastores()[2]['datastores']
fake_datastore_versions = fake_datastores[0]['versions']
def get_datastores_d_123(self):
return datastores.Datastore(None, self.fake_datastores[0])
def get_datastores_d_123_versions(self):
return datastores.Datastore(None, self.fake_datastore_versions[0])
class FakeRoot(object):
fake_instance_1234_root = (fakes.FakeHTTPClient()
.get_instances_1234_root()[2])
fake_cls_1234_root = (fakes.FakeHTTPClient()
.get_clusters_cls_1234_root()[2])
def get_instance_1234_root(self):
return users.User(None, self.fake_instance_1234_root,
loaded=True)
def get_cls_1234_root(self):
return users.User(None, self.fake_cls_1234_root,
loaded=True)
def post_instance_1234_root(self):
root = fakes.FakeHTTPClient().post_instances_1234_root()[2]['user']
return root['name'], root['password']
def post_cls_1234_root(self):
root = fakes.FakeHTTPClient().post_instances_1234_root()[2]['user']
return root['name'], root['password']
def delete_instance_1234_root(self):
return fakes.FakeHTTPClient().delete_instances_1234_root()[2]
class FakeQuota(object):
fake_quotas = fakes.FakeHTTPClient().get_quotas()[2]['quotas']
fake_instances_quota = (fakes.FakeHTTPClient()
.update_instances_quota()[2]['quotas'])
def get_quotas(self):
return [quota.Quotas.resource_class(None, q)
for q in self.fake_quotas]
class FakeLogs(object):
fake_logs = fakes.FakeHTTPClient().get_logs()[2]['logs']
def get_logs(self):
return [instances.DatastoreLog(None, fake_log)
for fake_log in self.fake_logs]
|