1
# Copyright (c) 2013 Mirantis Inc.
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
7
# http://www.apache.org/licenses/LICENSE-2.0
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
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
18
from sahara.conductor import manager
19
from sahara import context
20
from sahara import exceptions as ex
21
import sahara.tests.unit.conductor.base as test_base
25
"plugin_name": "test_plugin",
27
"tenant_id": "tenant_1",
28
"hadoop_version": "test_version",
30
"node_processes": ["p1", "p2"],
31
"floating_ip_pool": None,
43
"plugin_name": "test_plugin",
44
"tenant_id": "tenant_1",
45
"hadoop_version": "test_version",
59
"node_processes": ["p1", "p2"],
61
"floating_ip_pool": None,
62
"security_groups": None,
67
"node_processes": ["p3", "p4"],
69
"floating_ip_pool": None,
70
"security_groups": ["group1", "group2"],
77
class NodeGroupTemplates(test_base.ConductorManagerTestCase):
78
def __init__(self, *args, **kwargs):
79
super(NodeGroupTemplates, self).__init__(
83
lambda: manager.CLUSTER_DEFAULTS,
84
lambda: manager.NODE_GROUP_DEFAULTS,
85
lambda: manager.INSTANCE_DEFAULTS,
88
def test_minimal_ngt_create_list_delete(self):
90
self.api.node_group_template_create(ctx, SAMPLE_NGT)
92
lst = self.api.node_group_template_get_all(ctx)
93
self.assertEqual(len(lst), 1)
96
self.api.node_group_template_destroy(ctx, ngt_id)
98
lst = self.api.node_group_template_get_all(ctx)
99
self.assertEqual(len(lst), 0)
101
def test_duplicate_ngt_create(self):
103
self.api.node_group_template_create(ctx, SAMPLE_NGT)
104
with testtools.ExpectedException(ex.DBDuplicateEntry):
105
self.api.node_group_template_create(ctx, SAMPLE_NGT)
107
def test_ngt_fields(self):
109
ngt_db_obj_id = self.api.node_group_template_create(
110
ctx, SAMPLE_NGT)['id']
112
ngt_db_obj = self.api.node_group_template_get(ctx, ngt_db_obj_id)
113
self.assertIsInstance(ngt_db_obj, dict)
115
for key, val in SAMPLE_NGT.items():
116
self.assertEqual(val, ngt_db_obj.get(key),
117
"Key not found %s" % key)
119
def test_ngt_delete(self):
121
db_obj_ngt = self.api.node_group_template_create(ctx, SAMPLE_NGT)
122
_id = db_obj_ngt['id']
124
self.api.node_group_template_destroy(ctx, _id)
126
with testtools.ExpectedException(ex.NotFoundException):
127
self.api.node_group_template_destroy(ctx, _id)
130
class ClusterTemplates(test_base.ConductorManagerTestCase):
131
def __init__(self, *args, **kwargs):
132
super(ClusterTemplates, self).__init__(
136
lambda: manager.CLUSTER_DEFAULTS,
137
lambda: manager.NODE_GROUP_DEFAULTS,
138
lambda: manager.INSTANCE_DEFAULTS,
141
def test_minimal_clt_create_list_delete(self):
143
self.api.cluster_template_create(ctx, SAMPLE_CLT)
145
lst = self.api.cluster_template_get_all(ctx)
146
self.assertEqual(len(lst), 1)
148
clt_id = lst[0]['id']
149
self.api.cluster_template_destroy(ctx, clt_id)
151
lst = self.api.cluster_template_get_all(ctx)
152
self.assertEqual(len(lst), 0)
154
with testtools.ExpectedException(ex.NotFoundException):
155
self.api.cluster_template_destroy(ctx, clt_id)
157
def test_duplicate_clt_create(self):
159
self.api.cluster_template_create(ctx, SAMPLE_CLT)
160
with testtools.ExpectedException(ex.DBDuplicateEntry):
161
self.api.cluster_template_create(ctx, SAMPLE_CLT)
163
def test_clt_fields(self):
165
clt_db_obj_id = self.api.cluster_template_create(ctx, SAMPLE_CLT)['id']
167
clt_db_obj = self.api.cluster_template_get(ctx, clt_db_obj_id)
168
self.assertIsInstance(clt_db_obj, dict)
170
for key, val in SAMPLE_CLT.items():
171
if key == 'node_groups':
172
# this will be checked separately
174
self.assertEqual(val, clt_db_obj.get(key),
175
"Key not found %s" % key)
177
for ng in clt_db_obj["node_groups"]:
182
self.assertEqual(ng.pop("cluster_template_id"), clt_db_obj_id)
184
ng.pop("node_configs")
185
ng.pop("node_group_template_id")
186
ng.pop("volume_mount_prefix")
187
ng.pop("volumes_size")
188
ng.pop("volumes_per_node")
189
ng.pop("auto_security_group")
191
self.assertEqual(SAMPLE_CLT["node_groups"],
192
clt_db_obj["node_groups"])
194
def test_clt_delete(self):
196
db_obj_clt = self.api.cluster_template_create(ctx, SAMPLE_CLT)
197
_id = db_obj_clt['id']
199
self.api.cluster_template_destroy(ctx, _id)
201
with testtools.ExpectedException(ex.NotFoundException):
202
self.api.cluster_template_destroy(ctx, _id)