Unit tests for CDH plugin

partially implement: blueprint cdh-plugin

Change-Id: Ib3373d140d6c89e05c46d09df64bf692fa0d94ff
This commit is contained in:
Sergey Reshetnyak
2014-08-12 16:57:53 +04:00
parent c76e125693
commit 89a1d675c1
5 changed files with 201 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
# Copyright (c) 2014 Mirantis Inc.
#
# 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 sahara.plugins.cdh import cloudera_utils as cu
from sahara.tests.unit import base
from sahara.tests.unit.plugins.cdh import utils as ctu
class ClouderaUtilsTestCase(base.SaharaTestCase):
@mock.patch('sahara.plugins.cdh.cloudera_utils.get_cloudera_cluster')
def test_get_service(self, mock_get_cl_cluster):
self.assertRaises(ValueError, cu.get_service, 'NAMENODE')
cluster = ctu.get_fake_cluster()
inst = cluster.node_groups[0].instances[0]
mock_get_cl_cluster.return_value = None
self.assertRaises(ValueError, cu.get_service, 'spam', cluster)
self.assertRaises(ValueError, cu.get_service, 'spam', instance=inst)
mock_get_cl_cluster.reset_mock()
mock_get_service = mock.MagicMock()
mock_get_service.get_service.return_value = mock.Mock()
mock_get_cl_cluster.return_value = mock_get_service
cu.get_service('NAMENODE', cluster)
args = ((cu.HDFS_SERVICE_NAME,),)
self.assertEqual(args, mock_get_service.get_service.call_args)
mock_get_service.reset_mock()
cu.get_service('JOBHISTORY', instance=inst)
args = ((cu.YARN_SERVICE_NAME,),)
self.assertEqual(args, mock_get_service.get_service.call_args)
mock_get_service.reset_mock()
cu.get_service('OOZIE_SERVER', cluster)
args = ((cu.OOZIE_SERVICE_NAME,),)
self.assertEqual(args, mock_get_service.get_service.call_args)
def test_get_role_name(self):
inst_mock = mock.Mock()
inst_mock.hostname.return_value = 'spam-host'
self.assertEqual('eggs_spam_host', cu.get_role_name(inst_mock, 'eggs'))

View File

@@ -0,0 +1,37 @@
# Copyright (c) 2014 Mirantis Inc.
#
# 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.
from sahara.plugins.cdh import config_helper as c_h
from sahara.tests.unit import base
from sahara.tests.unit.plugins.cdh import utils as ctu
class ConfigHelperTestCase(base.SaharaTestCase):
def test_is_swift_enabled(self):
cluster = ctu.get_fake_cluster(cluster_configs={})
self.assertTrue(c_h.is_swift_enabled(cluster))
cluster = ctu.get_fake_cluster(
cluster_configs={'general': {c_h.ENABLE_SWIFT.name: False}})
self.assertFalse(c_h.is_swift_enabled(cluster))
def test_get_swift_lib_url(self):
cluster = ctu.get_fake_cluster(cluster_configs={})
self.assertEqual(c_h.DEFAULT_SWIFT_LIB_URL,
c_h.get_swift_lib_url(cluster))
cluster = ctu.get_fake_cluster(
cluster_configs={'general': {c_h.SWIFT_LIB_URL.name: 'spam'}})
self.assertEqual('spam', c_h.get_swift_lib_url(cluster))

View File

@@ -0,0 +1,62 @@
# Copyright (c) 2014 Mirantis Inc.
#
# 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.
from sahara.plugins.cdh import utils as u
from sahara.tests.unit import base
from sahara.tests.unit.plugins.cdh import utils as tu
class UtilsTestCase(base.SaharaTestCase):
def test_get_manager(self):
cluster = tu.get_fake_cluster()
inst = u.get_manager(cluster)
self.assertEqual('id1', inst.instance_id)
def test_get_namenode(self):
cluster = tu.get_fake_cluster()
inst = u.get_namenode(cluster)
self.assertEqual('id2', inst.instance_id)
def test_get_secondarynamenode(self):
cluster = tu.get_fake_cluster()
inst = u.get_secondarynamenode(cluster)
self.assertEqual('id2', inst.instance_id)
def test_get_resourcemanager(self):
cluster = tu.get_fake_cluster()
inst = u.get_resourcemanager(cluster)
self.assertEqual('id2', inst.instance_id)
def test_get_datanodes(self):
cluster = tu.get_fake_cluster()
dns = u.get_datanodes(cluster)
ids = [dn.instance_id for dn in dns]
self.assertEqual(sorted(['id00', 'id01', 'id02']), sorted(ids))
def test_get_nodemanagers(self):
cluster = tu.get_fake_cluster()
nms = u.get_nodemanagers(cluster)
ids = [nm.instance_id for nm in nms]
self.assertEqual(sorted(['id00', 'id01', 'id02']), sorted(ids))
def test_get_historyserver(self):
cluster = tu.get_fake_cluster()
inst = u.get_historyserver(cluster)
self.assertEqual('id2', inst.instance_id)
def test_get_oozie(self):
cluster = tu.get_fake_cluster()
inst = u.get_oozie(cluster)
self.assertEqual('id2', inst.instance_id)

View File

@@ -0,0 +1,43 @@
# Copyright (c) 2014 Mirantis Inc.
#
# 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.
from sahara.tests.unit import testutils as tu
def get_fake_cluster(**kwargs):
mng = tu.make_inst_dict('id1', 'manager_inst', management_ip='1.2.3.4')
mng_ng = tu.make_ng_dict('manager_ng', 1, ['MANAGER'], 1, [mng])
mst = tu.make_inst_dict('id2', 'master_inst', management_ip='1.2.3.5')
mst_ng = tu.make_ng_dict('master_ng', 1, ['NAMENODE', 'SECONDARYNAMENODE',
'RESOURCEMANAGER', 'JOBHISTORY',
'OOZIE_SERVER'], 1, [mst])
wkrs = _get_workers()
wkrs_ng = tu.make_ng_dict('worker_ng', 1, ['DATANODE', 'NODEMANAGER'],
len(wkrs), wkrs)
return tu.create_cluster('test_cluster', 1, 'cdh', '5',
[mng_ng, mst_ng, wkrs_ng],
**kwargs)
def _get_workers():
workers = []
for i in range(3):
w = tu.make_inst_dict('id0%d' % i, 'worker-0%d' % i,
management_ip='1.2.3.1%d' % i)
workers.append(w)
return workers