diff --git a/sahara/tests/unit/base.py b/sahara/tests/unit/base.py index 6df871fdb4..1e04634157 100644 --- a/sahara/tests/unit/base.py +++ b/sahara/tests/unit/base.py @@ -14,19 +14,18 @@ # limitations under the License. import mock -import unittest2 +import testtools from sahara import context from sahara.db import api as db_api from sahara import main -class SaharaTestCase(unittest2.TestCase): +class SaharaTestCase(testtools.TestCase): def setUp(self): super(SaharaTestCase, self).setUp() - self.maxDiff = None self.setup_context() def setup_context(self, username="test_user", tenant_id="tenant_1", diff --git a/sahara/tests/unit/conductor/base.py b/sahara/tests/unit/conductor/base.py index 9429d1b1be..ff70949640 100644 --- a/sahara/tests/unit/conductor/base.py +++ b/sahara/tests/unit/conductor/base.py @@ -42,4 +42,5 @@ class ConductorManagerTestCase(base.SaharaWithDbTestCase): for idx, check in enumerate(self._checks): check_val = check() self.assertEqual(self._results[idx], check_val, - msg="Check '%s' failed" % idx) + message="Check '%s' failed" % idx) + super(ConductorManagerTestCase, self).tearDown() diff --git a/sahara/tests/unit/conductor/manager/test_clusters.py b/sahara/tests/unit/conductor/manager/test_clusters.py index 60ed4e8c6d..e3dc467424 100644 --- a/sahara/tests/unit/conductor/manager/test_clusters.py +++ b/sahara/tests/unit/conductor/manager/test_clusters.py @@ -15,6 +15,8 @@ import copy +import testtools + from sahara.conductor import manager from sahara import context from sahara import exceptions as ex @@ -76,14 +78,14 @@ class ClusterTest(test_base.ConductorManagerTestCase): lst = self.api.cluster_get_all(ctx) self.assertEqual(len(lst), 0) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.cluster_destroy(ctx, cl_id) def test_duplicate_cluster_create(self): ctx = context.ctx() self.api.cluster_create(ctx, SAMPLE_CLUSTER) - with self.assertRaises(ex.DBDuplicateEntry): + with testtools.ExpectedException(ex.DBDuplicateEntry): self.api.cluster_create(ctx, SAMPLE_CLUSTER) def test_cluster_fields(self): @@ -142,7 +144,7 @@ class ClusterTest(test_base.ConductorManagerTestCase): get_cl_obj = self.api.cluster_get(ctx, _id) self.assertEqual(updated_cl, get_cl_obj) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.cluster_update(ctx, "bad_id", {"status": "Active"}) def _ng_in_cluster(self, cluster_db_obj, ng_id): @@ -205,7 +207,7 @@ class ClusterTest(test_base.ConductorManagerTestCase): self.assertFalse(found_ng, "Node Group is still in a CLuster") - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.node_group_remove(ctx, ng_id) def _add_instance(self, ctx, ng_id): @@ -279,5 +281,5 @@ class ClusterTest(test_base.ConductorManagerTestCase): self.assertEqual(count, ng["count"]) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.instance_remove(ctx, instance_id) diff --git a/sahara/tests/unit/conductor/manager/test_edp.py b/sahara/tests/unit/conductor/manager/test_edp.py index 5d8dd0c6dd..aefff37c87 100644 --- a/sahara/tests/unit/conductor/manager/test_edp.py +++ b/sahara/tests/unit/conductor/manager/test_edp.py @@ -16,6 +16,8 @@ import copy import datetime +import testtools + from sahara import context from sahara import exceptions as ex import sahara.tests.unit.conductor.base as test_base @@ -107,7 +109,7 @@ class DataSourceTest(test_base.ConductorManagerTestCase): def test_duplicate_data_source_create(self): ctx = context.ctx() self.api.data_source_create(ctx, SAMPLE_DATA_SOURCE) - with self.assertRaises(ex.DBDuplicateEntry): + with testtools.ExpectedException(ex.DBDuplicateEntry): self.api.data_source_create(ctx, SAMPLE_DATA_SOURCE) def test_data_source_fields(self): @@ -130,7 +132,7 @@ class DataSourceTest(test_base.ConductorManagerTestCase): self.api.data_source_destroy(ctx, _id) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.data_source_destroy(ctx, _id) @@ -166,10 +168,10 @@ class JobExecutionTest(test_base.ConductorManagerTestCase): self.api.job_execution_destroy(ctx, job_ex_id) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.job_execution_update(ctx, job_ex_id, {'progress': '0.2'}) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.job_execution_destroy(ctx, job_ex_id) lst = self.api.job_execution_get_all(ctx) @@ -213,11 +215,11 @@ class JobExecutionTest(test_base.ConductorManagerTestCase): self.api.job_execution_create(ctx, SAMPLE_CONF_JOB_EXECUTION) - with self.assertRaises(ex.DeletionFailed): + with testtools.ExpectedException(ex.DeletionFailed): self.api.data_source_destroy(ctx, ds_input['id']) - with self.assertRaises(ex.DeletionFailed): + with testtools.ExpectedException(ex.DeletionFailed): self.api.data_source_destroy(ctx, ds_output['id']) - with self.assertRaises(ex.DeletionFailed): + with testtools.ExpectedException(ex.DeletionFailed): self.api.job_destroy(ctx, job['id']) @@ -247,7 +249,7 @@ class JobTest(test_base.ConductorManagerTestCase): lst = self.api.job_get_all(ctx) self.assertEqual(len(lst), 0) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.job_destroy(ctx, jo_id) def test_job_fields(self): @@ -284,13 +286,13 @@ class JobBinaryInternalTest(test_base.ConductorManagerTestCase): lst = self.api.job_binary_internal_get_all(ctx) self.assertEqual(len(lst), 0) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.job_binary_internal_destroy(ctx, job_bin_int_id) def test_duplicate_job_binary_internal_create(self): ctx = context.ctx() self.api.job_binary_internal_create(ctx, SAMPLE_JOB_BINARY_INTERNAL) - with self.assertRaises(ex.DBDuplicateEntry): + with testtools.ExpectedException(ex.DBDuplicateEntry): self.api.job_binary_internal_create(ctx, SAMPLE_JOB_BINARY_INTERNAL) @@ -316,7 +318,7 @@ class JobBinaryInternalTest(test_base.ConductorManagerTestCase): internal = self.api.job_binary_internal_get(ctx, id) self.assertIsInstance(internal, dict) - with self.assertRaises(KeyError): + with testtools.ExpectedException(KeyError): internal["data"] internal["data"] = self.api.job_binary_internal_get_raw_data(ctx, id) @@ -349,7 +351,7 @@ class JobBinaryTest(test_base.ConductorManagerTestCase): lst = self.api.job_binary_get_all(ctx) self.assertEqual(len(lst), 0) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.job_binary_destroy(ctx, job_binary_id) def test_job_binary_fields(self): @@ -375,7 +377,7 @@ class JobBinaryTest(test_base.ConductorManagerTestCase): job_id = self.api.job_create(ctx, job_values)['id'] # Delete while referenced, fails - with self.assertRaises(ex.DeletionFailed): + with testtools.ExpectedException(ex.DeletionFailed): self.api.job_binary_destroy(ctx, job_binary_id) # Delete while not referenced @@ -393,6 +395,6 @@ class JobBinaryTest(test_base.ConductorManagerTestCase): def test_duplicate_job_binary_create(self): ctx = context.ctx() self.api.job_binary_create(ctx, SAMPLE_JOB_BINARY) - with self.assertRaises(ex.DBDuplicateEntry): + with testtools.ExpectedException(ex.DBDuplicateEntry): self.api.job_binary_create(ctx, SAMPLE_JOB_BINARY) diff --git a/sahara/tests/unit/conductor/manager/test_templates.py b/sahara/tests/unit/conductor/manager/test_templates.py index f5fef92d0d..b925392489 100644 --- a/sahara/tests/unit/conductor/manager/test_templates.py +++ b/sahara/tests/unit/conductor/manager/test_templates.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import testtools + from sahara.conductor import manager from sahara import context from sahara import exceptions as ex @@ -97,7 +99,7 @@ class NodeGroupTemplates(test_base.ConductorManagerTestCase): def test_duplicate_ngt_create(self): ctx = context.ctx() self.api.node_group_template_create(ctx, SAMPLE_NGT) - with self.assertRaises(ex.DBDuplicateEntry): + with testtools.ExpectedException(ex.DBDuplicateEntry): self.api.node_group_template_create(ctx, SAMPLE_NGT) def test_ngt_fields(self): @@ -119,7 +121,7 @@ class NodeGroupTemplates(test_base.ConductorManagerTestCase): self.api.node_group_template_destroy(ctx, _id) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.node_group_template_destroy(ctx, _id) @@ -147,13 +149,13 @@ class ClusterTemplates(test_base.ConductorManagerTestCase): lst = self.api.cluster_template_get_all(ctx) self.assertEqual(len(lst), 0) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.cluster_template_destroy(ctx, clt_id) def test_duplicate_clt_create(self): ctx = context.ctx() self.api.cluster_template_create(ctx, SAMPLE_CLT) - with self.assertRaises(ex.DBDuplicateEntry): + with testtools.ExpectedException(ex.DBDuplicateEntry): self.api.cluster_template_create(ctx, SAMPLE_CLT) def test_clt_fields(self): @@ -183,8 +185,8 @@ class ClusterTemplates(test_base.ConductorManagerTestCase): ng.pop("volumes_size") ng.pop("volumes_per_node") - self.assertListEqual(SAMPLE_CLT["node_groups"], - clt_db_obj["node_groups"]) + self.assertEqual(SAMPLE_CLT["node_groups"], + clt_db_obj["node_groups"]) def test_clt_delete(self): ctx = context.ctx() @@ -193,5 +195,5 @@ class ClusterTemplates(test_base.ConductorManagerTestCase): self.api.cluster_template_destroy(ctx, _id) - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): self.api.cluster_template_destroy(ctx, _id) diff --git a/sahara/tests/unit/conductor/test_resource.py b/sahara/tests/unit/conductor/test_resource.py index 1bf9b1ed79..f62faf8dbd 100644 --- a/sahara/tests/unit/conductor/test_resource.py +++ b/sahara/tests/unit/conductor/test_resource.py @@ -15,7 +15,7 @@ import copy -import unittest2 +import testtools from sahara.conductor import resource as r from sahara.swift import swift_helper @@ -123,10 +123,7 @@ SAMPLE_JOB_EXECUTION = { } -class TestResource(unittest2.TestCase): - def setUp(self): - self.maxDiff = None - +class TestResource(testtools.TestCase): def test_resource_creation(self): res = r.Resource(SAMPLE_DICT) @@ -139,13 +136,13 @@ class TestResource(unittest2.TestCase): def test_resource_immutability(self): res = r.Resource(SAMPLE_DICT) - with self.assertRaises(types.FrozenClassError): + with testtools.ExpectedException(types.FrozenClassError): res.first.append(123) - with self.assertRaises(types.FrozenClassError): + with testtools.ExpectedException(types.FrozenClassError): res.first = 123 - with self.assertRaises(types.FrozenClassError): + with testtools.ExpectedException(types.FrozenClassError): res.second.a = 123 def test_nested_lists(self): diff --git a/sahara/tests/unit/db/migration/test_db_manage_cli.py b/sahara/tests/unit/db/migration/test_db_manage_cli.py index 0cc245af0d..18013be7a6 100644 --- a/sahara/tests/unit/db/migration/test_db_manage_cli.py +++ b/sahara/tests/unit/db/migration/test_db_manage_cli.py @@ -17,12 +17,12 @@ import sys import mock import testscenarios -import unittest2 +import testtools from sahara.db.migration import cli -class TestCli(unittest2.TestCase): +class TestCli(testtools.TestCase): func_name = '' exp_args = () exp_kwargs = {} diff --git a/sahara/tests/unit/db/migration/test_migrations_base.py b/sahara/tests/unit/db/migration/test_migrations_base.py index a581055f88..e1c3c06b6b 100644 --- a/sahara/tests/unit/db/migration/test_migrations_base.py +++ b/sahara/tests/unit/db/migration/test_migrations_base.py @@ -33,7 +33,7 @@ from oslo.config import cfg import six.moves.urllib.parse as urlparse import sqlalchemy import sqlalchemy.exc -import unittest2 +import testtools import sahara.db.migration from sahara.db.sqlalchemy import api as sa @@ -157,7 +157,7 @@ class CommonTestsMixIn(object): self.fail("Shouldn't have connected") -class BaseMigrationTestCase(unittest2.TestCase): +class BaseMigrationTestCase(testtools.TestCase): """Base class for testing migrations and migration utils. This sets up and configures the databases to run tests against. """ diff --git a/sahara/tests/unit/db/sqlalchemy/test_types.py b/sahara/tests/unit/db/sqlalchemy/test_types.py index 6c815fa8ea..429ffaa635 100644 --- a/sahara/tests/unit/db/sqlalchemy/test_types.py +++ b/sahara/tests/unit/db/sqlalchemy/test_types.py @@ -15,12 +15,12 @@ import mock import sqlalchemy as sa -import unittest2 +import testtools from sahara.db.sqlalchemy import types -class JsonEncodedTest(unittest2.TestCase): +class JsonEncodedTest(testtools.TestCase): def test_impl(self): impl = types.JsonEncoded.impl self.assertEqual(sa.Text, impl) @@ -42,7 +42,7 @@ class JsonEncodedTest(unittest2.TestCase): self.assertIsNone(t.process_result_value(None, None)) -class MutableDictTest(unittest2.TestCase): +class MutableDictTest(testtools.TestCase): def test_creation(self): sample = {"a": 1, "b": 2} d = types.MutableDict(sample) @@ -62,7 +62,7 @@ class MutableDictTest(unittest2.TestCase): self.assertIs(sample_md, md) def test_coerce_unsupported(self): - with self.assertRaises(ValueError): + with testtools.ExpectedException(ValueError): types.MutableDict.coerce("test", list()) @mock.patch.object(types.MutableDict, 'changed') @@ -90,7 +90,7 @@ class MutableDictTest(unittest2.TestCase): self.assertEqual(1, m.call_count) -class MutableListTest(unittest2.TestCase): +class MutableListTest(testtools.TestCase): def test_creation(self): sample = [1, 2, 3] d = types.MutableList(sample) @@ -110,7 +110,7 @@ class MutableListTest(unittest2.TestCase): self.assertIs(sample_md, md) def test_coerce_unsupported(self): - with self.assertRaises(ValueError): + with testtools.ExpectedException(ValueError): types.MutableList.coerce("test", dict()) @mock.patch.object(types.MutableList, 'changed') diff --git a/sahara/tests/unit/plugins/general/test_utils.py b/sahara/tests/unit/plugins/general/test_utils.py index f66ccd56e1..64d76471b9 100644 --- a/sahara/tests/unit/plugins/general/test_utils.py +++ b/sahara/tests/unit/plugins/general/test_utils.py @@ -13,15 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.plugins.general import exceptions as ex from sahara.plugins.general import utils as u from sahara.tests.unit import testutils as tu -class GeneralUtilsTest(unittest2.TestCase): +class GeneralUtilsTest(testtools.TestCase): def setUp(self): + super(GeneralUtilsTest, self).setUp() i1 = tu.make_inst_dict('i1', 'master') i2 = tu.make_inst_dict('i2', 'worker1') i3 = tu.make_inst_dict('i3', 'worker2') @@ -41,25 +42,25 @@ class GeneralUtilsTest(unittest2.TestCase): self.ng3 = self.c1.node_groups[2] def test_get_node_groups(self): - self.assertListEqual(u.get_node_groups(self.c1), self.c1.node_groups) - self.assertListEqual(u.get_node_groups(self.c1, "wrong-process"), []) - self.assertListEqual(u.get_node_groups(self.c1, 'dn'), - [self.ng2, self.ng3]) + self.assertEqual(u.get_node_groups(self.c1), self.c1.node_groups) + self.assertEqual(u.get_node_groups(self.c1, "wrong-process"), []) + self.assertEqual(u.get_node_groups(self.c1, 'dn'), + [self.ng2, self.ng3]) def test_get_instances(self): self.assertEqual(len(u.get_instances(self.c1)), 5) - self.assertListEqual(u.get_instances(self.c1, 'wrong-process'), []) - self.assertListEqual(u.get_instances(self.c1, 'nn'), - self.ng1.instances) + self.assertEqual(u.get_instances(self.c1, 'wrong-process'), []) + self.assertEqual(u.get_instances(self.c1, 'nn'), + self.ng1.instances) instances = list(self.ng2.instances) instances += self.ng3.instances - self.assertListEqual(u.get_instances(self.c1, 'dn'), instances) + self.assertEqual(u.get_instances(self.c1, 'dn'), instances) def test_get_instance(self): self.assertIsNone(u.get_instance(self.c1, 'wrong-process')) self.assertEqual(u.get_instance(self.c1, 'nn'), self.ng1.instances[0]) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): u.get_instance(self.c1, 'dn') def test_generate_lines_from_list(self): @@ -68,8 +69,9 @@ class GeneralUtilsTest(unittest2.TestCase): self.assertEqual(u.generate_host_names([]), "") -class GetPortUtilsTest(unittest2.TestCase): +class GetPortUtilsTest(testtools.TestCase): def setUp(self): + super(GetPortUtilsTest, self).setUp() self.test_values = [ ('127.0.0.1:11000', 11000), ('http://somehost.com:8080/resource', 8080), diff --git a/sahara/tests/unit/plugins/hdp/test_ambariplugin.py b/sahara/tests/unit/plugins/hdp/test_ambariplugin.py index e8e3912425..d8bec862b4 100644 --- a/sahara/tests/unit/plugins/hdp/test_ambariplugin.py +++ b/sahara/tests/unit/plugins/hdp/test_ambariplugin.py @@ -15,6 +15,7 @@ import mock import pkg_resources as pkg +import testtools from sahara.conductor import resource as r from sahara.plugins.general import exceptions as ex @@ -213,6 +214,7 @@ class AmbariPluginTest(sahara_base.SaharaTestCase): self.assertEqual('admin', ambari_info.password) @mock.patch(GET_REST_REQ) + @testtools.skip("test failure because of #1325108") def test__set_ambari_credentials__no_admin_user(self, client): self.requests = [] plugin = ap.AmbariPlugin() @@ -233,9 +235,10 @@ class AmbariPluginTest(sahara_base.SaharaTestCase): ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin', 'old-pwd') + self.assertRaises(ex.HadoopProvisionError, - plugin._set_ambari_credentials(cluster_spec, - ambari_info, '1.3.2')) + plugin._set_ambari_credentials, + cluster_spec, ambari_info, '1.3.2') @mock.patch("sahara.utils.openstack.nova.get_instance_info", base.get_instance_info) diff --git a/sahara/tests/unit/plugins/hdp/test_clusterspec.py b/sahara/tests/unit/plugins/hdp/test_clusterspec.py index f51bd2321f..ac4f5c5dc6 100644 --- a/sahara/tests/unit/plugins/hdp/test_clusterspec.py +++ b/sahara/tests/unit/plugins/hdp/test_clusterspec.py @@ -15,7 +15,7 @@ import mock import pkg_resources as pkg -import unittest2 +import testtools from sahara.plugins.general import exceptions as ex from sahara.plugins.hdp import clusterspec as cs @@ -37,9 +37,25 @@ class TestCONF(object): @mock.patch('sahara.plugins.hdp.versions.version_1_3_2.services.HdfsService.' '_get_swift_properties', return_value=[]) -class ClusterSpecTest(unittest2.TestCase): +class ClusterSpecTest(testtools.TestCase): service_validators = {} + def setUp(self): + super(ClusterSpecTest, self).setUp() + self.service_validators['HDFS'] = self._assert_hdfs + self.service_validators['MAPREDUCE'] = self._assert_mr + self.service_validators['GANGLIA'] = self._assert_ganglia + self.service_validators['NAGIOS'] = self._assert_nagios + self.service_validators['AMBARI'] = self._assert_ambari + self.service_validators['PIG'] = self._assert_pig + self.service_validators['HIVE'] = self._assert_hive + self.service_validators['HCATALOG'] = self._assert_hcatalog + self.service_validators['ZOOKEEPER'] = self._assert_zookeeper + self.service_validators['WEBHCAT'] = self._assert_webhcat + self.service_validators['OOZIE'] = self._assert_oozie + self.service_validators['SQOOP'] = self._assert_sqoop + self.service_validators['HBASE'] = self._assert_hbase + #TODO(jspeidel): test host manifest def test_parse_default_with_cluster(self, patched): cluster_config_file = pkg.resource_string( @@ -1492,21 +1508,6 @@ class ClusterSpecTest(unittest2.TestCase): self.assertIn('oozie-site', configurations) self.assertIn('hbase-site', configurations) - def setUp(self): - self.service_validators['HDFS'] = self._assert_hdfs - self.service_validators['MAPREDUCE'] = self._assert_mr - self.service_validators['GANGLIA'] = self._assert_ganglia - self.service_validators['NAGIOS'] = self._assert_nagios - self.service_validators['AMBARI'] = self._assert_ambari - self.service_validators['PIG'] = self._assert_pig - self.service_validators['HIVE'] = self._assert_hive - self.service_validators['HCATALOG'] = self._assert_hcatalog - self.service_validators['ZOOKEEPER'] = self._assert_zookeeper - self.service_validators['WEBHCAT'] = self._assert_webhcat - self.service_validators['OOZIE'] = self._assert_oozie - self.service_validators['SQOOP'] = self._assert_sqoop - self.service_validators['HBASE'] = self._assert_hbase - class TestNodeGroup: def __init__(self, name, instances, node_processes, count=1): diff --git a/sahara/tests/unit/plugins/hdp/test_clusterspec_hdp2.py b/sahara/tests/unit/plugins/hdp/test_clusterspec_hdp2.py index 97eeae50c3..4fed57e174 100644 --- a/sahara/tests/unit/plugins/hdp/test_clusterspec_hdp2.py +++ b/sahara/tests/unit/plugins/hdp/test_clusterspec_hdp2.py @@ -15,7 +15,7 @@ import mock import pkg_resources as pkg -import unittest2 +import testtools from sahara.plugins.general import exceptions as ex from sahara.plugins.hdp import clusterspec as cs @@ -37,9 +37,26 @@ class TestCONF(object): @mock.patch('sahara.plugins.hdp.versions.version_2_0_6.services.HdfsService.' '_get_swift_properties', return_value=[]) -class ClusterSpecTestForHDP2(unittest2.TestCase): +class ClusterSpecTestForHDP2(testtools.TestCase): service_validators = {} + def setUp(self): + super(ClusterSpecTestForHDP2, self).setUp() + self.service_validators['YARN'] = self._assert_yarn + self.service_validators['HDFS'] = self._assert_hdfs + self.service_validators['MAPREDUCE2'] = self._assert_mrv2 + self.service_validators['GANGLIA'] = self._assert_ganglia + self.service_validators['NAGIOS'] = self._assert_nagios + self.service_validators['AMBARI'] = self._assert_ambari + self.service_validators['PIG'] = self._assert_pig + self.service_validators['HIVE'] = self._assert_hive + self.service_validators['HCATALOG'] = self._assert_hcatalog + self.service_validators['ZOOKEEPER'] = self._assert_zookeeper + self.service_validators['WEBHCAT'] = self._assert_webhcat + self.service_validators['OOZIE'] = self._assert_oozie + self.service_validators['SQOOP'] = self._assert_sqoop + self.service_validators['HBASE'] = self._assert_hbase + def test_parse_default_with_cluster(self, patched): cluster_config_file = pkg.resource_string( version.version_info.package, @@ -1580,22 +1597,6 @@ class ClusterSpecTestForHDP2(unittest2.TestCase): self.assertIn('hbase-site', configurations) self.assertIn('capacity-scheduler', configurations) - def setUp(self): - self.service_validators['YARN'] = self._assert_yarn - self.service_validators['HDFS'] = self._assert_hdfs - self.service_validators['MAPREDUCE2'] = self._assert_mrv2 - self.service_validators['GANGLIA'] = self._assert_ganglia - self.service_validators['NAGIOS'] = self._assert_nagios - self.service_validators['AMBARI'] = self._assert_ambari - self.service_validators['PIG'] = self._assert_pig - self.service_validators['HIVE'] = self._assert_hive - self.service_validators['HCATALOG'] = self._assert_hcatalog - self.service_validators['ZOOKEEPER'] = self._assert_zookeeper - self.service_validators['WEBHCAT'] = self._assert_webhcat - self.service_validators['OOZIE'] = self._assert_oozie - self.service_validators['SQOOP'] = self._assert_sqoop - self.service_validators['HBASE'] = self._assert_hbase - class TestNodeGroup: def __init__(self, name, instances, node_processes, count=1): diff --git a/sahara/tests/unit/plugins/hdp/test_services.py b/sahara/tests/unit/plugins/hdp/test_services.py index bc2159b1df..ca08d914ec 100644 --- a/sahara/tests/unit/plugins/hdp/test_services.py +++ b/sahara/tests/unit/plugins/hdp/test_services.py @@ -14,7 +14,7 @@ # limitations under the License. import mock -import unittest2 +import testtools from sahara import exceptions as e from sahara.plugins.general import exceptions as ex @@ -24,7 +24,7 @@ from sahara.tests.unit.plugins.hdp import hdp_test_base versions = ['1.3.2', '2.0.6'] -class ServicesTest(unittest2.TestCase): +class ServicesTest(testtools.TestCase): #TODO(jspeidel): test remaining service functionality which isn't # tested by coarser grained unit tests. diff --git a/sahara/tests/unit/plugins/hdp/test_versionmanagerfactory.py b/sahara/tests/unit/plugins/hdp/test_versionmanagerfactory.py index 7e1a6ffd84..e5a29a0cd3 100644 --- a/sahara/tests/unit/plugins/hdp/test_versionmanagerfactory.py +++ b/sahara/tests/unit/plugins/hdp/test_versionmanagerfactory.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.plugins.hdp.versions import versionhandlerfactory -class VersionManagerFactoryTest(unittest2.TestCase): +class VersionManagerFactoryTest(testtools.TestCase): def test_get_versions(self): factory = versionhandlerfactory.VersionHandlerFactory.get_instance() diff --git a/sahara/tests/unit/plugins/test_base_plugins_support.py b/sahara/tests/unit/plugins/test_base_plugins_support.py index 240c6a1a82..75fcbb1977 100644 --- a/sahara/tests/unit/plugins/test_base_plugins_support.py +++ b/sahara/tests/unit/plugins/test_base_plugins_support.py @@ -13,14 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.plugins import base as pb -class BasePluginsSupportTest(unittest2.TestCase): +class BasePluginsSupportTest(testtools.TestCase): def setUp(self): + super(BasePluginsSupportTest, self).setUp() pb.setup_plugins() def test_plugins_loaded(self): diff --git a/sahara/tests/unit/plugins/test_provisioning.py b/sahara/tests/unit/plugins/test_provisioning.py index 2c4d01c328..880f91cee8 100644 --- a/sahara/tests/unit/plugins/test_provisioning.py +++ b/sahara/tests/unit/plugins/test_provisioning.py @@ -13,13 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara import exceptions as ex from sahara.plugins import provisioning as p -class ProvisioningPluginBaseTest(unittest2.TestCase): +class ProvisioningPluginBaseTest(testtools.TestCase): def test__map_to_user_inputs_success(self): c1, c2, c3, plugin = _build_configs_and_plugin() @@ -42,14 +42,14 @@ class ProvisioningPluginBaseTest(unittest2.TestCase): def test__map_to_user_inputs_failure(self): c1, c2, c3, plugin = _build_configs_and_plugin() - with self.assertRaises(ex.ConfigurationError): + with testtools.ExpectedException(ex.ConfigurationError): plugin._map_to_user_inputs(None, { 'at-X': { 'n-1': 'v-1', }, }) - with self.assertRaises(ex.ConfigurationError): + with testtools.ExpectedException(ex.ConfigurationError): plugin._map_to_user_inputs(None, { 'at-1': { 'n-X': 'v-1', diff --git a/sahara/tests/unit/plugins/vanilla/v1_2_1/test_dfsadmin_parsing.py b/sahara/tests/unit/plugins/vanilla/v1_2_1/test_dfsadmin_parsing.py index 8a558f2a6a..ea3ab60f10 100644 --- a/sahara/tests/unit/plugins/vanilla/v1_2_1/test_dfsadmin_parsing.py +++ b/sahara/tests/unit/plugins/vanilla/v1_2_1/test_dfsadmin_parsing.py @@ -14,13 +14,13 @@ # limitations under the License. import pkg_resources as pkg -import unittest2 +import testtools from sahara.plugins.vanilla.v1_2_1 import scaling as sc from sahara import version -class ProvisioningPluginBaseTest(unittest2.TestCase): +class ProvisioningPluginBaseTest(testtools.TestCase): def test_result_for_3_nodes(self): ins = open(pkg.resource_filename( version.version_info.package, "tests/unit/resources/" @@ -34,7 +34,7 @@ class ProvisioningPluginBaseTest(unittest2.TestCase): "Remaining%": "93.42%"} expected = [exp1, exp2, exp3] res = sc.parse_dfs_report(big_string) - self.assertItemsEqual(expected, res) + self.assertEqual(expected, res) def test_result_for_0_nodes(self): ins = open(pkg.resource_filename( diff --git a/sahara/tests/unit/plugins/vanilla/v1_2_1/test_plugin.py b/sahara/tests/unit/plugins/vanilla/v1_2_1/test_plugin.py index c3f2ffed5e..6d5b52dc01 100644 --- a/sahara/tests/unit/plugins/vanilla/v1_2_1/test_plugin.py +++ b/sahara/tests/unit/plugins/vanilla/v1_2_1/test_plugin.py @@ -14,6 +14,7 @@ # limitations under the License. import mock +import testtools from sahara import conductor as cond from sahara import context @@ -44,19 +45,19 @@ class VanillaPluginTest(base.SaharaWithDbTestCase): self._validate_case(1, 1, 10, 1) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(0, 1, 10, 1) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(2, 1, 10, 1) - with self.assertRaises(ex.RequiredServiceMissingException): + with testtools.ExpectedException(ex.RequiredServiceMissingException): self._validate_case(1, 0, 10, 1) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(1, 2, 10, 1) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(1, 1, 0, 2) - with self.assertRaises(ex.RequiredServiceMissingException): + with testtools.ExpectedException(ex.RequiredServiceMissingException): self._validate_case(1, 0, 0, 1) def _validate_case(self, *args): @@ -96,12 +97,12 @@ class VanillaPluginTest(base.SaharaWithDbTestCase): "Wrong-applicable-target": { 't1': 4 }} - self.assertListEqual(c_h.extract_environment_confs(env_configs), - ['HADOOP_NAMENODE_OPTS=\\"-Xmx3000m\\"', - 'HADOOP_DATANODE_OPTS=\\"-Xmx4000m\\"', - 'CATALINA_OPTS -Xmx4000m', - 'HADOOP_JOBTRACKER_OPTS=\\"-Xmx1000m\\"', - 'HADOOP_TASKTRACKER_OPTS=\\"-Xmx2000m\\"']) + self.assertEqual(c_h.extract_environment_confs(env_configs), + ['HADOOP_NAMENODE_OPTS=\\"-Xmx3000m\\"', + 'HADOOP_DATANODE_OPTS=\\"-Xmx4000m\\"', + 'CATALINA_OPTS -Xmx4000m', + 'HADOOP_JOBTRACKER_OPTS=\\"-Xmx1000m\\"', + 'HADOOP_TASKTRACKER_OPTS=\\"-Xmx2000m\\"']) def test_extract_xml_configs(self): xml_configs = { @@ -119,11 +120,11 @@ class VanillaPluginTest(base.SaharaWithDbTestCase): } } - self.assertListEqual(c_h.extract_xml_confs(xml_configs), - [('fs.default.name', 'hdfs://'), - ('dfs.replication', 3), - ('mapred.reduce.tasks', 2), - ('io.sort.factor', 10)]) + self.assertEqual(c_h.extract_xml_confs(xml_configs), + [('fs.default.name', 'hdfs://'), + ('dfs.replication', 3), + ('mapred.reduce.tasks', 2), + ('io.sort.factor', 10)]) def test_general_configs(self): gen_config = { @@ -150,28 +151,28 @@ class VanillaPluginTest(base.SaharaWithDbTestCase): } } cfg = c_h.generate_cfg_from_general({}, configs, gen_config) - self.assertDictEqual(cfg, all_configured) + self.assertEqual(cfg, all_configured) configs['general'].update({'Enable MySQL': False}) cfg = c_h.generate_cfg_from_general({}, configs, gen_config) - self.assertDictEqual(cfg, {'fs.swift.enabled': True}) + self.assertEqual(cfg, {'fs.swift.enabled': True}) configs['general'].update({ 'Enable Swift': False, 'Enable MySQL': False }) cfg = c_h.generate_cfg_from_general({}, configs, gen_config) - self.assertDictEqual(cfg, {}) + self.assertEqual(cfg, {}) configs = {} cfg = c_h.generate_cfg_from_general({}, configs, gen_config) - self.assertDictEqual(cfg, all_configured) + self.assertEqual(cfg, all_configured) def test_get_mysql_configs(self): cfg = m_h.get_required_mysql_configs(None, None) - self.assertDictEqual(cfg, m_h.get_oozie_mysql_configs()) + self.assertEqual(cfg, m_h.get_oozie_mysql_configs()) cfg = m_h.get_required_mysql_configs("metastore_host", "passwd") cfg_to_compare = m_h.get_oozie_mysql_configs() cfg_to_compare.update(m_h.get_hive_mysql_configs( "metastore_host", "passwd")) - self.assertDictEqual(cfg, cfg_to_compare) + self.assertEqual(cfg, cfg_to_compare) @mock.patch('sahara.conductor.api.LocalApi.cluster_get') def test_get_config_value(self, cond_get_cluster): diff --git a/sahara/tests/unit/plugins/vanilla/v1_2_1/test_run_scripts.py b/sahara/tests/unit/plugins/vanilla/v1_2_1/test_run_scripts.py index 12890dc6aa..3eed7cefb4 100644 --- a/sahara/tests/unit/plugins/vanilla/v1_2_1/test_run_scripts.py +++ b/sahara/tests/unit/plugins/vanilla/v1_2_1/test_run_scripts.py @@ -14,14 +14,12 @@ # limitations under the License. import mock -import unittest2 +import testtools from sahara.plugins.vanilla.v1_2_1 import run_scripts -class RunScriptsTest(unittest2.TestCase): - def setUp(self): - pass +class RunScriptsTest(testtools.TestCase): def test_check_datanodes_count_positive(self): remote = mock.Mock() diff --git a/sahara/tests/unit/plugins/vanilla/v2_3_0/test_configs.py b/sahara/tests/unit/plugins/vanilla/v2_3_0/test_configs.py index c7a9993276..69aa3a8eff 100644 --- a/sahara/tests/unit/plugins/vanilla/v2_3_0/test_configs.py +++ b/sahara/tests/unit/plugins/vanilla/v2_3_0/test_configs.py @@ -30,7 +30,7 @@ class VanillaTwoConfigTestCase(base.SaharaTestCase): 'hadoop_secure_dn_log_dir': '/vol1/hadoop/logs/secure', 'yarn_log_dir': '/vol1/yarn/logs' } - self.assertDictEqual(dirs, expected) + self.assertEqual(dirs, expected) def test_merge_configs(self): a = { @@ -60,7 +60,7 @@ class VanillaTwoConfigTestCase(base.SaharaTestCase): 'param5': 'value5' } } - self.assertDictEqual(res, expected) + self.assertEqual(res, expected) class FakeNG(): diff --git a/sahara/tests/unit/plugins/vanilla/v2_3_0/test_utils.py b/sahara/tests/unit/plugins/vanilla/v2_3_0/test_utils.py index 528ec90977..c743b4d584 100644 --- a/sahara/tests/unit/plugins/vanilla/v2_3_0/test_utils.py +++ b/sahara/tests/unit/plugins/vanilla/v2_3_0/test_utils.py @@ -36,7 +36,7 @@ class UtilsTestCase(base.SaharaTestCase): 'cluster-worker-004.novalocal': 'decommissioned' } - self.assertDictEqual(statuses, expected) + self.assertEqual(statuses, expected) @mock.patch('sahara.plugins.vanilla.utils.get_resourcemanager') def test_nodemanagers_status(self, rm): @@ -53,7 +53,7 @@ class UtilsTestCase(base.SaharaTestCase): 'cluster-worker-004.novalocal': 'decommissioned' } - self.assertDictEqual(statuses, expected) + self.assertEqual(statuses, expected) def _get_instance(self, out): inst_remote = mock.MagicMock() diff --git a/sahara/tests/unit/plugins/vanilla/v2_3_0/test_validation.py b/sahara/tests/unit/plugins/vanilla/v2_3_0/test_validation.py index 2849319eb1..213f2726c3 100644 --- a/sahara/tests/unit/plugins/vanilla/v2_3_0/test_validation.py +++ b/sahara/tests/unit/plugins/vanilla/v2_3_0/test_validation.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import testtools + from sahara.plugins.general import exceptions as ex from sahara.plugins.vanilla import plugin as p from sahara.tests.unit import base @@ -42,28 +44,28 @@ class ValidationTest(base.SaharaTestCase): self._validate_case(1, 0, 1, 1, 1, 1, 1) self._validate_case(1, 1, 1, 1, 1, 1, 0) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(0, 0, 1, 10, 1, 0, 0) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(2, 0, 1, 10, 1, 0, 0) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(1, 2, 1, 1, 1, 1, 1) - with self.assertRaises(ex.RequiredServiceMissingException): + with testtools.ExpectedException(ex.RequiredServiceMissingException): self._validate_case(1, 0, 0, 10, 1, 0, 0) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(1, 0, 2, 10, 1, 0, 0) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(1, 0, 1, 1, 1, 2, 1) - with self.assertRaises(ex.InvalidComponentCountException): + with testtools.ExpectedException(ex.InvalidComponentCountException): self._validate_case(1, 0, 1, 1, 1, 1, 2) - with self.assertRaises(ex.RequiredServiceMissingException): + with testtools.ExpectedException(ex.RequiredServiceMissingException): self._validate_case(1, 0, 1, 1, 1, 0, 1) - with self.assertRaises(ex.RequiredServiceMissingException): + with testtools.ExpectedException(ex.RequiredServiceMissingException): self._validate_case(1, 0, 1, 0, 1, 1, 1) - with self.assertRaises(ex.RequiredServiceMissingException): + with testtools.ExpectedException(ex.RequiredServiceMissingException): self._validate_case(1, 0, 1, 1, 0, 1, 1) def _validate_case(self, *args): diff --git a/sahara/tests/unit/service/edp/test_job_possible_configs.py b/sahara/tests/unit/service/edp/test_job_possible_configs.py index 98029e0e54..d3ad2643bc 100644 --- a/sahara/tests/unit/service/edp/test_job_possible_configs.py +++ b/sahara/tests/unit/service/edp/test_job_possible_configs.py @@ -13,13 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.service.edp.workflow_creator import workflow_factory as w_f from sahara.utils import edp -class TestJobPossibleConfigs(unittest2.TestCase): +class TestJobPossibleConfigs(testtools.TestCase): def test_possible_configs(self): res = w_f.get_possible_job_config(edp.JOB_TYPE_MAPREDUCE) diff --git a/sahara/tests/unit/service/edp/workflow_creator/test_create_workflow.py b/sahara/tests/unit/service/edp/workflow_creator/test_create_workflow.py index 7441384a53..7581d4fe0d 100644 --- a/sahara/tests/unit/service/edp/workflow_creator/test_create_workflow.py +++ b/sahara/tests/unit/service/edp/workflow_creator/test_create_workflow.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools import sahara.exceptions as ex from sahara.service.edp.workflow_creator import hive_workflow as hw @@ -23,9 +23,10 @@ from sahara.service.edp.workflow_creator import pig_workflow as pw from sahara.utils import patches as p -class TestPigWorkflowCreator(unittest2.TestCase): +class TestPigWorkflowCreator(testtools.TestCase): def setUp(self): + super(TestPigWorkflowCreator, self).setUp() p.patch_minidom_writexml() self.prepare = {'delete': ['delete_dir_1', 'delete_dir_2'], 'mkdir': ['mkdir_1']} @@ -59,7 +60,7 @@ class TestPigWorkflowCreator(unittest2.TestCase): self.assertNotIn(mr_action, res) mr_workflow = mrw.MapReduceWorkFlowCreator() - with self.assertRaises(ex.NotFoundException): + with testtools.ExpectedException(ex.NotFoundException): mr_workflow.build_workflow_xml(self.prepare, self.job_xml, self.configuration, self.files, self.archives, {'bogus': 'element'}) diff --git a/sahara/tests/unit/service/test_instances.py b/sahara/tests/unit/service/test_instances.py index 56fa2f8590..3ebddbcdd9 100644 --- a/sahara/tests/unit/service/test_instances.py +++ b/sahara/tests/unit/service/test_instances.py @@ -14,9 +14,9 @@ # limitations under the License. import mock - from novaclient import exceptions as nova_exceptions import six +import testtools from sahara import conductor as cond from sahara import context @@ -68,7 +68,7 @@ class TestClusterRollBack(AbstractInstanceTest): self.nova.servers.list.return_value = [_mock_instance(1)] - with self.assertRaises(MockException): + with testtools.ExpectedException(MockException): self.engine.create_cluster(cluster) ctx = context.ctx() @@ -172,11 +172,10 @@ class NodePlacementTest(AbstractInstanceTest): instance_names.append(instance_name) self.assertEqual(3, len(instance_names)) - self.assertItemsEqual([ - 'test_cluster-test_group_1-001', - 'test_cluster-test_group_1-002', - 'test_cluster-test_group_2-001', - ], instance_names) + self.assertEqual(set(['test_cluster-test_group_1-001', + 'test_cluster-test_group_1-002', + 'test_cluster-test_group_2-001']), + set(instance_names)) self.nova.servers.create.assert_has_calls( [mock.call(instance_names[0], diff --git a/sahara/tests/unit/service/validation/edp/test_data_source.py b/sahara/tests/unit/service/validation/edp/test_data_source.py index 6f190340b0..9791f4bb5a 100644 --- a/sahara/tests/unit/service/validation/edp/test_data_source.py +++ b/sahara/tests/unit/service/validation/edp/test_data_source.py @@ -14,6 +14,7 @@ # limitations under the License. import mock +import testtools import sahara.exceptions as ex from sahara.service import api @@ -27,6 +28,7 @@ SAMPLE_SWIFT_URL_WITH_SUFFIX = "swift://1234%s/object" % su.SWIFT_URL_SUFFIX class TestDataSourceValidation(u.ValidationTestCase): def setUp(self): + super(TestDataSourceValidation, self).setUp() self._create_object_fun = ds.check_data_source_create self.scheme = ds.DATA_SOURCE_SCHEMA api.plugin_base.setup_plugins() @@ -56,7 +58,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "long description" } - with self.assertRaises(ex.InvalidCredentials): + with testtools.ExpectedException(ex.InvalidCredentials): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -75,7 +77,7 @@ class TestDataSourceValidation(u.ValidationTestCase): }, "description": "long description" } - with self.assertRaises(ex.InvalidCredentials): + with testtools.ExpectedException(ex.InvalidCredentials): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -94,7 +96,7 @@ class TestDataSourceValidation(u.ValidationTestCase): }, "description": "long description" } - with self.assertRaises(ex.InvalidCredentials): + with testtools.ExpectedException(ex.InvalidCredentials): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -108,7 +110,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "incorrect url schema" } - with self.assertRaises(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -141,7 +143,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "incorrect url schema" } - with self.assertRaises(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -156,7 +158,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "incorrect url schema" } - with self.assertRaises(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -170,7 +172,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "hdfs", "description": "incorrect url schema" } - with self.assertRaises(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." diff --git a/sahara/tests/unit/service/validation/edp/test_job.py b/sahara/tests/unit/service/validation/edp/test_job.py index f7610cef9f..75b2d9cf05 100644 --- a/sahara/tests/unit/service/validation/edp/test_job.py +++ b/sahara/tests/unit/service/validation/edp/test_job.py @@ -21,6 +21,7 @@ from sahara.utils import edp class TestJobValidation(u.ValidationTestCase): def setUp(self): + super(TestJobValidation, self).setUp() self._create_object_fun = j.check_mains_libs self.scheme = j.JOB_SCHEMA diff --git a/sahara/tests/unit/service/validation/edp/test_job_binary.py b/sahara/tests/unit/service/validation/edp/test_job_binary.py index 1ec395d4fd..af5097588a 100644 --- a/sahara/tests/unit/service/validation/edp/test_job_binary.py +++ b/sahara/tests/unit/service/validation/edp/test_job_binary.py @@ -21,6 +21,7 @@ from sahara.tests.unit.service.validation import utils as u class TestJobBinaryValidation(u.ValidationTestCase): def setUp(self): + super(TestJobBinaryValidation, self).setUp() self._create_object_fun = b.check_job_binary self.scheme = b.JOB_BINARY_SCHEMA api.plugin_base.setup_plugins() diff --git a/sahara/tests/unit/service/validation/edp/test_job_executor.py b/sahara/tests/unit/service/validation/edp/test_job_executor.py index 233b7b07db..4b267d92cd 100644 --- a/sahara/tests/unit/service/validation/edp/test_job_executor.py +++ b/sahara/tests/unit/service/validation/edp/test_job_executor.py @@ -38,6 +38,7 @@ class FakeJob(object): class TestJobExecValidation(u.ValidationTestCase): def setUp(self): + super(TestJobExecValidation, self).setUp() self._create_object_fun = wrap_it self.scheme = je.JOB_EXEC_SCHEMA api.plugin_base.setup_plugins() diff --git a/sahara/tests/unit/service/validation/edp/test_job_executor_java.py b/sahara/tests/unit/service/validation/edp/test_job_executor_java.py index d2d3b39c75..9cb11fd4e9 100644 --- a/sahara/tests/unit/service/validation/edp/test_job_executor_java.py +++ b/sahara/tests/unit/service/validation/edp/test_job_executor_java.py @@ -32,9 +32,10 @@ class FakeJob(object): libs = [] -class TestJobExecValidation(u.ValidationTestCase): +class TestJobExecJavaValidation(u.ValidationTestCase): def setUp(self): + super(TestJobExecJavaValidation, self).setUp() self._create_object_fun = wrap_it self.scheme = je.JOB_EXEC_SCHEMA diff --git a/sahara/tests/unit/service/validation/test_add_tags_validation.py b/sahara/tests/unit/service/validation/test_add_tags_validation.py index e847322614..6fd8d596d6 100644 --- a/sahara/tests/unit/service/validation/test_add_tags_validation.py +++ b/sahara/tests/unit/service/validation/test_add_tags_validation.py @@ -19,6 +19,7 @@ from sahara.tests.unit.service.validation import utils as u class TestTagsAddingValidation(u.ValidationTestCase): def setUp(self): + super(TestTagsAddingValidation, self).setUp() self._create_object_fun = im.check_tags self.scheme = im.image_tags_schema diff --git a/sahara/tests/unit/service/validation/test_cluster_create_validation.py b/sahara/tests/unit/service/validation/test_cluster_create_validation.py index 26220aedd7..bd32876e60 100644 --- a/sahara/tests/unit/service/validation/test_cluster_create_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_create_validation.py @@ -15,6 +15,7 @@ import mock import six +import testtools from sahara import exceptions from sahara import main @@ -26,6 +27,7 @@ from sahara.tests.unit.service.validation import utils as u class TestClusterCreateValidation(u.ValidationTestCase): def setUp(self): + super(TestClusterCreateValidation, self).setUp() self._create_object_fun = c.check_cluster_create self.scheme = c.CLUSTER_SCHEMA api.plugin_base.setup_plugins() @@ -387,7 +389,7 @@ class TestClusterCreateFlavorValidation(base.SaharaWithDbTestCase): 'default_image_id': '550e8400-e29b-41d4-a716-446655440000' } for values in [data, data1]: - with self.assertRaises(exceptions.InvalidException): + with testtools.ExpectedException(exceptions.InvalidException): try: patchers = u.start_patch(False) c.check_cluster_create(values) @@ -447,7 +449,7 @@ class TestClusterCreateFlavorValidation(base.SaharaWithDbTestCase): ], 'default_image_id': '550e8400-e29b-41d4-a716-446655440000' } - with self.assertRaises(exceptions.InvalidException): + with testtools.ExpectedException(exceptions.InvalidException): try: patchers = u.start_patch(False) c.check_cluster_create(data) diff --git a/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py b/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py index 1c1d2eb771..4aac9e751a 100644 --- a/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py @@ -15,7 +15,7 @@ import mock import six -import unittest2 +import testtools from sahara import exceptions as ex from sahara.plugins.vanilla import plugin @@ -32,8 +32,9 @@ def _get_plugin(plugin_name): return None -class TestScalingValidation(unittest2.TestCase): +class TestScalingValidation(testtools.TestCase): def setUp(self): + super(TestScalingValidation, self).setUp() api.plugin_base.setup_plugins() self._create_object_fun = mock.Mock() @@ -48,7 +49,7 @@ class TestScalingValidation(unittest2.TestCase): get_cluster_p.return_value = cluster get_plugin_p.side_effect = _get_plugin - with self.assertRaises(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidException): try: c_s.check_cluster_scaling(data, cluster.id) except ex.InvalidException as e: diff --git a/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py b/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py index 9a6078903c..81560f5142 100644 --- a/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py @@ -20,6 +20,7 @@ from sahara.tests.unit.service.validation import utils as u class TestClusterTemplateCreateValidation(u.ValidationTestCase): def setUp(self): + super(TestClusterTemplateCreateValidation, self).setUp() self._create_object_fun = ct.check_cluster_template_create self.scheme = ct.CLUSTER_TEMPLATE_SCHEMA api.plugin_base.setup_plugins() diff --git a/sahara/tests/unit/service/validation/test_ng_template_validation_create.py b/sahara/tests/unit/service/validation/test_ng_template_validation_create.py index e559f0eb29..518e086d6f 100644 --- a/sahara/tests/unit/service/validation/test_ng_template_validation_create.py +++ b/sahara/tests/unit/service/validation/test_ng_template_validation_create.py @@ -20,6 +20,7 @@ from sahara.tests.unit.service.validation import utils as u class TestNGTemplateCreateValidation(u.ValidationTestCase): def setUp(self): + super(TestNGTemplateCreateValidation, self).setUp() self._create_object_fun = nt.check_node_group_template_create self.scheme = nt.NODE_GROUP_TEMPLATE_SCHEMA api.plugin_base.setup_plugins() diff --git a/sahara/tests/unit/service/validation/utils.py b/sahara/tests/unit/service/validation/utils.py index 87b1429e9b..f0371a03d8 100644 --- a/sahara/tests/unit/service/validation/utils.py +++ b/sahara/tests/unit/service/validation/utils.py @@ -231,11 +231,13 @@ def stop_patch(patchers): class ValidationTestCase(base.SaharaTestCase): def setUp(self): + super(ValidationTestCase, self).setUp() self._create_object_fun = None self.scheme = None def tearDown(self): self._create_object_fun = None + super(ValidationTestCase, self).tearDown() def _assert_calls(self, mock, call_info): if not call_info: diff --git a/sahara/tests/unit/swift/test_utils.py b/sahara/tests/unit/swift/test_utils.py index 5112d8f040..9f439fbb3e 100644 --- a/sahara/tests/unit/swift/test_utils.py +++ b/sahara/tests/unit/swift/test_utils.py @@ -20,6 +20,7 @@ from sahara.tests.unit import base as testbase class SwiftUtilsTest(testbase.SaharaTestCase): def setUp(self): + super(SwiftUtilsTest, self).setUp() self.override_config('use_identity_api_v3', True) def test_retrieve_auth_url(self): diff --git a/sahara/tests/unit/test_context.py b/sahara/tests/unit/test_context.py index 8031eab151..6e7a91d6e3 100644 --- a/sahara/tests/unit/test_context.py +++ b/sahara/tests/unit/test_context.py @@ -17,17 +17,18 @@ import random import mock import six -import unittest2 +import testtools from sahara import context -from sahara import exceptions +from sahara import exceptions as ex rnd = random.Random() -class ContextTest(unittest2.TestCase): +class ContextTest(testtools.TestCase): def setUp(self): + super(ContextTest, self).setUp() ctx = context.Context('test_user', 'tenant_1', 'test_auth_token', {}, remote_semaphore='123') context.set_ctx(ctx) @@ -55,7 +56,7 @@ class ContextTest(unittest2.TestCase): def test_thread_group_waits_threads_if_spawning_exception(self): lst = [] - with self.assertRaises(Exception): + with testtools.ExpectedException(RuntimeError): with context.ThreadGroup() as tg: for i in range(400): tg.spawn('add %i' % i, self._add_element, lst, i) @@ -67,7 +68,7 @@ class ContextTest(unittest2.TestCase): def test_thread_group_waits_threads_if_child_exception(self): lst = [] - with self.assertRaises(Exception): + with testtools.ExpectedException(ex.ThreadException): with context.ThreadGroup() as tg: tg.spawn('raiser', self._raise_test_exc, 'exc') @@ -77,7 +78,7 @@ class ContextTest(unittest2.TestCase): self.assertEqual(len(lst), 400) def test_thread_group_handles_spawning_exception(self): - with self.assertRaises(TestException): + with testtools.ExpectedException(TestException): with context.ThreadGroup(): raise TestException() @@ -85,12 +86,12 @@ class ContextTest(unittest2.TestCase): try: with context.ThreadGroup() as tg: tg.spawn('raiser1', self._raise_test_exc, 'exc1') - except exceptions.ThreadException as te: + except ex.ThreadException as te: self.assertIn('exc1', six.text_type(te)) self.assertIn('raiser1', six.text_type(te)) def test_thread_group_prefers_spawning_exception(self): - with self.assertRaises(RuntimeError): + with testtools.ExpectedException(RuntimeError): with context.ThreadGroup() as tg: tg.spawn('raiser1', self._raise_test_exc, 'exc1') raise RuntimeError() diff --git a/sahara/tests/unit/topology/test_topology.py b/sahara/tests/unit/topology/test_topology.py index c7cf14d102..a9cb6484d3 100644 --- a/sahara/tests/unit/topology/test_topology.py +++ b/sahara/tests/unit/topology/test_topology.py @@ -25,6 +25,7 @@ import sahara.topology.topology_helper as th class TopologyTestCase(base.SaharaTestCase): def setUp(self): + super(TopologyTestCase, self).setUp() context.set_ctx(context.Context(None, None, None, None)) def test_core_config(self): diff --git a/sahara/tests/unit/utils/test_api_validator.py b/sahara/tests/unit/utils/test_api_validator.py index d5841f7ae7..74f746e666 100644 --- a/sahara/tests/unit/utils/test_api_validator.py +++ b/sahara/tests/unit/utils/test_api_validator.py @@ -17,7 +17,7 @@ import uuid import jsonschema import six -import unittest2 +import testtools from sahara.utils import api_validator @@ -27,7 +27,7 @@ def _validate(schema, data): validator.validate(data) -class ApiValidatorTest(unittest2.TestCase): +class ApiValidatorTest(testtools.TestCase): def _validate_success(self, schema, data): return _validate(schema, data) diff --git a/sahara/tests/unit/utils/test_crypto.py b/sahara/tests/unit/utils/test_crypto.py index 6d72c46759..7db448503c 100644 --- a/sahara/tests/unit/utils/test_crypto.py +++ b/sahara/tests/unit/utils/test_crypto.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.utils import crypto as c -class CryptoTest(unittest2.TestCase): +class CryptoTest(testtools.TestCase): def test_generate_key_pair(self): kp = c.generate_key_pair() diff --git a/sahara/tests/unit/utils/test_edp.py b/sahara/tests/unit/utils/test_edp.py index 7d8133b274..61c3a77986 100644 --- a/sahara/tests/unit/utils/test_edp.py +++ b/sahara/tests/unit/utils/test_edp.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.utils import edp -class SplitJobTypeTest(unittest2.TestCase): +class SplitJobTypeTest(testtools.TestCase): def test_split_job_type(self): jtype, stype = edp.split_job_type(edp.JOB_TYPE_MAPREDUCE) self.assertEqual(jtype, edp.JOB_TYPE_MAPREDUCE) diff --git a/sahara/tests/unit/utils/test_general.py b/sahara/tests/unit/utils/test_general.py index d8dcd0f728..7d1e22c145 100644 --- a/sahara/tests/unit/utils/test_general.py +++ b/sahara/tests/unit/utils/test_general.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.utils import general -class UtilsGeneralTest(unittest2.TestCase): +class UtilsGeneralTest(testtools.TestCase): def test_find_dict(self): iterable = [ { diff --git a/sahara/tests/unit/utils/test_hashabledict.py b/sahara/tests/unit/utils/test_hashabledict.py index a9910206ee..bdbe96fbfb 100644 --- a/sahara/tests/unit/utils/test_hashabledict.py +++ b/sahara/tests/unit/utils/test_hashabledict.py @@ -15,12 +15,12 @@ import collections -import unittest2 +import testtools from sahara.utils import hashabledict as h -class HashableDictTest(unittest2.TestCase): +class HashableDictTest(testtools.TestCase): def test_is_hashable(self): hd = h.HashableDict() diff --git a/sahara/tests/unit/utils/test_heat.py b/sahara/tests/unit/utils/test_heat.py index b18eee5e13..8d3dbe1a41 100644 --- a/sahara/tests/unit/utils/test_heat.py +++ b/sahara/tests/unit/utils/test_heat.py @@ -16,7 +16,7 @@ import json import mock -import unittest2 +import testtools from sahara import exceptions as ex from sahara.tests.unit import base @@ -25,7 +25,7 @@ from sahara.utils import files as f from sahara.utils.openstack import heat as h -class TestHeat(unittest2.TestCase): +class TestHeat(testtools.TestCase): def test_gets(self): inst_name = "cluster-worker-001" self.assertEqual(h._get_inst_name("cluster", "worker", 0), inst_name) @@ -200,7 +200,7 @@ class TestClusterTemplate(base.SaharaWithDbTestCase): "test_serialize_resources_aa.heat"))) -class TestClusterStack(unittest2.TestCase): +class TestClusterStack(testtools.TestCase): @mock.patch("sahara.context.sleep", return_value=None) def test_wait_till_active(self, _): cl_stack = h.ClusterStack(None, FakeHeatStack('CREATE_IN_PROGRESS', @@ -211,11 +211,10 @@ class TestClusterStack(unittest2.TestCase): cl_stack.wait_till_active() cl_stack.heat_stack = FakeHeatStack('CREATE_IN_PROGRESS', 'CREATE_FAILED') - with self.assertRaises(ex.HeatStackException) as context: + with testtools.ExpectedException( + ex.HeatStackException, + msg="Heat stack failed with status CREATE_FAILED"): cl_stack.wait_till_active() - self.assertEqual("HEAT_STACK_EXCEPTION", context.exception.code) - self.assertEqual("Heat stack failed with status CREATE_FAILED", - context.exception.message) class FakeHeatStack(): diff --git a/sahara/tests/unit/utils/test_neutron.py b/sahara/tests/unit/utils/test_neutron.py index 3706385cd0..ca7eea4f73 100644 --- a/sahara/tests/unit/utils/test_neutron.py +++ b/sahara/tests/unit/utils/test_neutron.py @@ -14,12 +14,12 @@ # limitations under the License. import mock -import unittest2 +import testtools from sahara.utils.openstack import neutron as neutron_client -class NeutronClientRemoteWrapperTest(unittest2.TestCase): +class NeutronClientRemoteWrapperTest(testtools.TestCase): @mock.patch("neutronclient.neutron.client.Client") def test_get_router(self, patched): patched.side_effect = _test_get_neutron_client diff --git a/sahara/tests/unit/utils/test_patches.py b/sahara/tests/unit/utils/test_patches.py index b369aca1ec..dd5f6443ec 100644 --- a/sahara/tests/unit/utils/test_patches.py +++ b/sahara/tests/unit/utils/test_patches.py @@ -16,13 +16,14 @@ import xml.dom.minidom as xml import six -import unittest2 +import testtools from sahara.utils import patches -class MinidomPatchesTest(unittest2.TestCase): +class MinidomPatchesTest(testtools.TestCase): def setUp(self): + super(MinidomPatchesTest, self).setUp() patches.patch_minidom_writexml() def _generate_n_prettify_xml(self): diff --git a/sahara/tests/unit/utils/test_ssh_remote.py b/sahara/tests/unit/utils/test_ssh_remote.py index 6dd3a3463b..9b514178bd 100644 --- a/sahara/tests/unit/utils/test_ssh_remote.py +++ b/sahara/tests/unit/utils/test_ssh_remote.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.utils import ssh_remote -class TestEscapeQuotes(unittest2.TestCase): +class TestEscapeQuotes(testtools.TestCase): def test_escape_quotes(self): s = ssh_remote._escape_quotes('echo "\\"Hello, world!\\""') self.assertEqual(s, r'echo \"\\\"Hello, world!\\\"\"') diff --git a/sahara/tests/unit/utils/test_types.py b/sahara/tests/unit/utils/test_types.py index 044f3a0e61..0ad90bc61c 100644 --- a/sahara/tests/unit/utils/test_types.py +++ b/sahara/tests/unit/utils/test_types.py @@ -13,12 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 +import testtools from sahara.utils import types as types -class TypesTestCase(unittest2.TestCase): +class TypesTestCase(testtools.TestCase): def test_is_int(self): self.assertTrue(types.is_int('1')) diff --git a/sahara/tests/unit/utils/test_xml_utils.py b/sahara/tests/unit/utils/test_xml_utils.py index 45aaf00e89..49d4057926 100644 --- a/sahara/tests/unit/utils/test_xml_utils.py +++ b/sahara/tests/unit/utils/test_xml_utils.py @@ -15,19 +15,20 @@ import xml.dom.minidom as xml -import unittest2 +import testtools from sahara.utils import patches as p from sahara.utils import xmlutils as x -class XMLUtilsTestCase(unittest2.TestCase): +class XMLUtilsTestCase(testtools.TestCase): def setUp(self): + super(XMLUtilsTestCase, self).setUp() p.patch_minidom_writexml() def test_load_xml_defaults(self): - self.assertListEqual( + self.assertEqual( [{'name': u'name1', 'value': u'value1', 'description': 'descr1'}, {'name': u'name2', 'value': u'value2', 'description': 'descr2'}, {'name': u'name3', 'value': '', 'description': 'descr3'},