You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2014/01/20 16:00:07 UTC
git commit: AMBARI-4351. TestCases BaseClass should should support
asserting Templates. (aonishuk)
Updated Branches:
refs/heads/trunk e96845faa -> c3a1a5923
AMBARI-4351. TestCases BaseClass should should support asserting
Templates. (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c3a1a592
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c3a1a592
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c3a1a592
Branch: refs/heads/trunk
Commit: c3a1a5923573b035eece63fb748548ccdbc3dd52
Parents: e96845f
Author: Andrew Onischuk <ao...@hortonworks.com>
Authored: Mon Jan 20 06:58:59 2014 -0800
Committer: Andrew Onischuk <ao...@hortonworks.com>
Committed: Mon Jan 20 06:59:58 2014 -0800
----------------------------------------------------------------------
.../python/resource_management/core/source.py | 4 +++
.../stacks/1.3.3/HBASE/test_hbase_client.py | 2 +-
.../stacks/1.3.3/HBASE/test_hbase_master.py | 2 +-
.../1.3.3/HBASE/test_hbase_regionserver.py | 2 +-
.../stacks/2.1.1/HBASE/test_hbase_client.py | 2 +-
.../stacks/2.1.1/HBASE/test_hbase_master.py | 2 +-
.../2.1.1/HBASE/test_hbase_regionserver.py | 2 +-
.../src/test/python/stacks/utils/RMFTestCase.py | 35 +++++++++++++++-----
8 files changed, 37 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-agent/src/main/python/resource_management/core/source.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/source.py b/ambari-agent/src/main/python/resource_management/core/source.py
index ec7593a..c2a4c24 100644
--- a/ambari-agent/src/main/python/resource_management/core/source.py
+++ b/ambari-agent/src/main/python/resource_management/core/source.py
@@ -48,6 +48,10 @@ class Source(object):
def __repr__(self):
return self.__class__.__name__+"('"+self.name+"')"
+
+ def __eq__(self, other):
+ return (isinstance(other, self.__class__)
+ and self.get_content() == other.get_content())
class StaticFile(Source):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_client.py b/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_client.py
index 600d2cd..7845d97 100644
--- a/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_client.py
+++ b/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_client.py
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
from mock.mock import MagicMock, call, patch
-from stacks.utils.RMFTestCase import RMFTestCase
+from stacks.utils.RMFTestCase import *
class TestHBaseClient(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_master.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_master.py b/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_master.py
index 8fd94f5..6566415 100644
--- a/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_master.py
+++ b/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_master.py
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
from mock.mock import MagicMock, patch
-from stacks.utils.RMFTestCase import RMFTestCase
+from stacks.utils.RMFTestCase import *
class TestHBaseMaster(RMFTestCase):
def test_configure_default(self):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_regionserver.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_regionserver.py b/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_regionserver.py
index 613e9de..0b4492e 100644
--- a/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_regionserver.py
+++ b/ambari-server/src/test/python/stacks/1.3.3/HBASE/test_hbase_regionserver.py
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
from mock.mock import MagicMock, patch
-from stacks.utils.RMFTestCase import RMFTestCase
+from stacks.utils.RMFTestCase import *
class TestHbaseRegionServer(RMFTestCase):
def test_configure_default(self):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_client.py b/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_client.py
index 4396291..eeeb5a0 100644
--- a/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_client.py
+++ b/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_client.py
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
from mock.mock import MagicMock, call, patch
-from stacks.utils.RMFTestCase import RMFTestCase
+from stacks.utils.RMFTestCase import *
class TestHBaseClient(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_master.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_master.py b/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_master.py
index 4325851..12fb388 100644
--- a/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_master.py
+++ b/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_master.py
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
from mock.mock import MagicMock, patch
-from stacks.utils.RMFTestCase import RMFTestCase
+from stacks.utils.RMFTestCase import *
class TestHBaseMaster(RMFTestCase):
def test_configure_default(self):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_regionserver.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_regionserver.py b/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_regionserver.py
index 64bd470..468876b 100644
--- a/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_regionserver.py
+++ b/ambari-server/src/test/python/stacks/2.1.1/HBASE/test_hbase_regionserver.py
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
from mock.mock import MagicMock, patch
-from stacks.utils.RMFTestCase import RMFTestCase
+from stacks.utils.RMFTestCase import *
class TestHbaseRegionServer(RMFTestCase):
def test_configure_default(self):
http://git-wip-us.apache.org/repos/asf/ambari/blob/c3a1a592/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/utils/RMFTestCase.py b/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
index e18e12e..9f9b0d6 100644
--- a/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
+++ b/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
@@ -17,6 +17,8 @@ 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.
'''
+__all__ = ["RMFTestCase", "Template", "StaticFile", "InlineTemplate"]
+
from unittest import TestCase
import json
import os
@@ -44,8 +46,9 @@ class RMFTestCase(TestCase):
raise RuntimeError("Can not read config file: "+ config_file_path)
# append basedir to PYTHONPATH
- basedir = os.path.dirname(script_path)
- sys.path.append(basedir)
+ scriptsdir = os.path.dirname(script_path)
+ basedir = os.path.dirname(scriptsdir)
+ sys.path.append(scriptsdir)
# get method to execute
try:
@@ -61,10 +64,10 @@ class RMFTestCase(TestCase):
del(sys.modules["params"])
# run
- with Environment(basedir, test_mode=True) as self.env:
+ with Environment(basedir, test_mode=True) as RMFTestCase.env:
with patch.object(Script, 'install_packages', return_value=MagicMock()):
with patch.object(Script, 'get_config', return_value=self.config_dict):
- method(self.env)
+ method(RMFTestCase.env)
def getConfig(self):
return self.config_dict
@@ -93,24 +96,40 @@ class RMFTestCase(TestCase):
return val
def printResources(self):
- for resource in self.env.resource_list:
+ for resource in RMFTestCase.env.resource_list:
print "'{0}', {1},".format(resource.__class__.__name__, self._ppformat(resource.name))
for k,v in resource.arguments.iteritems():
print " {0} = {1},".format(k, self._ppformat(v))
print
def assertResourceCalled(self, resource_type, name, **kwargs):
- resource = self.env.resource_list.pop(0)
+ resource = RMFTestCase.env.resource_list.pop(0)
self.assertEquals(resource_type, resource.__class__.__name__)
self.assertEquals(name, resource.name)
self.assertEquals(kwargs, resource.arguments)
def assertNoMoreResources(self):
- self.assertEquals(len(self.env.resource_list), 0, "There was other resources executed!")
+ self.assertEquals(len(RMFTestCase.env.resource_list), 0, "There was other resources executed!")
def assertResourceCalledByIndex(self, index, resource_type, name, **kwargs):
- resource = self.env.resource_list[index]
+ resource = RMFTestCase.env.resource_list[index]
self.assertEquals(resource_type, resource.__class__.__name__)
self.assertEquals(name, resource.name)
self.assertEquals(kwargs, resource.arguments)
+
+# HACK: This is used to check Templates, StaticFile, InlineTemplate in testcases
+def Template(name, **kwargs):
+ with RMFTestCase.env:
+ from resource_management.core.source import Template
+ return Template(name, kwargs)
+
+def StaticFile(name, **kwargs):
+ with RMFTestCase.env:
+ from resource_management.core.source import StaticFile
+ return StaticFile(name, kwargs)
+
+def InlineTemplate(name, **kwargs):
+ with RMFTestCase.env:
+ from resource_management.core.source import InlineTemplate
+ return InlineTemplate(name, kwargs)