incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1185895 - in /incubator/ambari/trunk: ./ agent/ agent/src/main/python/ambari_agent/ agent/src/test/ agent/src/test/python/
Date Tue, 18 Oct 2011 21:52:58 GMT
Author: eyang
Date: Tue Oct 18 21:52:58 2011
New Revision: 1185895

URL: http://svn.apache.org/viewvc?rev=1185895&view=rev
Log:
AMBARI-83. Added python unit test framework. (Eric Yang)

Added:
    incubator/ambari/trunk/agent/src/test/
    incubator/ambari/trunk/agent/src/test/python/
    incubator/ambari/trunk/agent/src/test/python/TestActionQueue.py
    incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py
    incubator/ambari/trunk/agent/src/test/python/TestHardware.py
    incubator/ambari/trunk/agent/src/test/python/TestHeartbeat.py
    incubator/ambari/trunk/agent/src/test/python/TestServerStatus.py
    incubator/ambari/trunk/agent/src/test/python/unitTests.py
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/agent/pom.xml
    incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
    incubator/ambari/trunk/agent/src/main/python/ambari_agent/AmbariConfig.py
    incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1185895&r1=1185894&r2=1185895&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue Oct 18 21:52:58 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-83. Added python unit test framework. (Eric Yang)
+
   AMBARI-82. Fix example clusters. (omalley)
 
   AMBARI-81. Updated xslt document to show human readable stylesheet. (Eric 

Modified: incubator/ambari/trunk/agent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/pom.xml?rev=1185895&r1=1185894&r2=1185895&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/pom.xml (original)
+++ incubator/ambari/trunk/agent/pom.xml Tue Oct 18 21:52:58 2011
@@ -62,6 +62,23 @@
                 <executions>
                     <execution>
                         <configuration>
+                            <executable>python</executable>
+                            <workingDirectory>src/test/python</workingDirectory>
+                            <arguments>
+                                <argument>unitTests.py</argument>
+                            </arguments>    
+                            <environmentVariables>
+                                <PYTHONPATH>../../main/python:$PYTHONPATH</PYTHONPATH>
+                            </environmentVariables>
+                        </configuration>
+                        <id>python-test</id>
+                        <phase>test</phase>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <configuration>
                             <executable>python2.6</executable>
                             <workingDirectory>target/ambari-agent-${project.version}</workingDirectory>
                             <arguments>

Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py?rev=1185895&r1=1185894&r2=1185895&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py Tue Oct 18 21:52:58
2011
@@ -39,18 +39,27 @@ class ActionQueue(threading.Thread):
 
   def __init__(self, config):
     global clusterId, clusterDefinitionRevision 
-    threading.Thread.__init__(self)
+    super(ActionQueue, self).__init__()
+    #threading.Thread.__init__(self)
     self.config = config
     self.sh = shellRunner()
+    self._stop = threading.Event()
+
+  def stop(self):
+    self._stop.set()
+
+  def stopped(self):
+    return self._stop.isSet()
 
   def put(self, response):
-    actions = response['actions']
-    for action in actions:
-      q.put(action)
+    if 'actions' in response:
+      actions = response['actions']
+      for action in actions:
+        q.put(action)
 
   def run(self):
     global clusterId, clusterDefinitionRevision
-    while True:
+    while not self.stopped():
       while not q.empty():
         action = q.get()
         switches = {
@@ -64,7 +73,8 @@ class ActionQueue(threading.Thread):
         result = switches.get(action['kind'], self.unknownAction)(action)
         # Update the result
         r.put(result)
-      time.sleep(5)
+      if not self.stopped():
+        time.sleep(5)
 
   # Store action result to agent response queue
   def result(self):

Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/AmbariConfig.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/AmbariConfig.py?rev=1185895&r1=1185894&r2=1185895&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/AmbariConfig.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/AmbariConfig.py Tue Oct 18 21:52:58
2011
@@ -36,6 +36,11 @@ prefix=/tmp/ambari
 s = StringIO.StringIO(content)
 config.readfp(s)
 
+class AmbariConfig:
+  def getConfig(self):
+    global config
+    return config
+
 def setConfig(customConfig):
   global config
   config = customConfig

Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py?rev=1185895&r1=1185894&r2=1185895&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py Tue Oct 18 21:52:58
2011
@@ -32,13 +32,7 @@ __contributors__ = "see http://incubator
 
 import logging
 import logging.handlers
-import web
-import mimeparse
-import mimerender
-import simplejson
-import bencode
 import threading
-import zookeeper
 import sys
 import time
 import signal

Added: incubator/ambari/trunk/agent/src/test/python/TestActionQueue.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/TestActionQueue.py?rev=1185895&view=auto
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/TestActionQueue.py (added)
+++ incubator/ambari/trunk/agent/src/test/python/TestActionQueue.py Tue Oct 18 21:52:58 2011
@@ -0,0 +1,32 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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 unittest import TestCase
+from ambari_agent.ActionQueue import ActionQueue
+from ambari_agent.AmbariConfig import AmbariConfig
+import os, errno
+
+class TestActionQueue(TestCase):
+  def test_ActionQueueStartStop(self):
+    actionQueue = ActionQueue(AmbariConfig().getConfig())
+    actionQueue.start()
+    actionQueue.stop()
+    actionQueue.join()
+    self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.') 

Added: incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py?rev=1185895&view=auto
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py (added)
+++ incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py Tue Oct 18 21:52:58 2011
@@ -0,0 +1,51 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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 unittest import TestCase
+from ambari_agent.FileUtil import writeFile, createStructure, deleteStructure
+import os, errno
+
+class TestFileUtil(TestCase):
+  def test_createStructure(self):
+    action = { 'clusterId' : 'abc', 'role' : 'hdfs' }
+    result = {}
+    result = createStructure(action, result)
+    self.assertEqual(result['exitCode'], 0, 'Create cluster structure failed.')
+
+#  def test_writeFile(self):
+    configFile = {
+      "data"       : "test",
+      "owner"      : os.getuid(),
+      "group"      : os.getgid() ,
+      "permission" : 0700,
+      "path"       : "/tmp/ambari_file_test/_file_write_test",
+      "umask"      : 022
+    }
+    action = { 'clusterId' : 'abc', 'role' : 'hdfs', 'file' : configFile }
+    result = { }
+    result = writeFile(action, result)
+    self.assertEqual(result['exitCode'], 0, 'WriteFile test with uid/gid failed.')
+
+#  def test_deleteStructure(self):
+    result = { }
+    action = { 'clusterId' : 'abc', 'role' : 'hdfs' }
+    result = deleteStructure(action, result)
+    self.assertEqual(result['exitCode'], 0, 'Delete cluster structure failed.')
+

Added: incubator/ambari/trunk/agent/src/test/python/TestHardware.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/TestHardware.py?rev=1185895&view=auto
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/TestHardware.py (added)
+++ incubator/ambari/trunk/agent/src/test/python/TestHardware.py Tue Oct 18 21:52:58 2011
@@ -0,0 +1,30 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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 unittest import TestCase
+from ambari_agent.Hardware import Hardware
+
+class TestHardware(TestCase):
+  def test_build(self):
+    hardware = Hardware()
+    result = hardware.get()
+    self.assertGreater(result['coreCount'], 1, 'CPU can not be less than 1.')
+    self.assertGreater(result['netSpeed'], 1, 'Network speed can not be less than 1.')
+

Added: incubator/ambari/trunk/agent/src/test/python/TestHeartbeat.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/TestHeartbeat.py?rev=1185895&view=auto
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/TestHeartbeat.py (added)
+++ incubator/ambari/trunk/agent/src/test/python/TestHeartbeat.py Tue Oct 18 21:52:58 2011
@@ -0,0 +1,34 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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 unittest import TestCase
+from ambari_agent.Heartbeat import Heartbeat
+from ambari_agent.ActionQueue import ActionQueue
+from ambari_agent.AmbariConfig import AmbariConfig
+import socket
+
+class TestHeartbeat(TestCase):
+  def test_build(self):
+    actionQueue = ActionQueue(AmbariConfig().getConfig())
+    heartbeat = Heartbeat(actionQueue)
+    result = heartbeat.build(100)
+    self.assertEqual(result['hostname'], socket.gethostname(), 'hostname mismatched.')
+    self.assertEqual(result['responseId'], 100, 'responseId mismatched.')
+    self.assertEqual(result['idle'], True, 'Heartbeat should indicate Agent is idle.')

Added: incubator/ambari/trunk/agent/src/test/python/TestServerStatus.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/TestServerStatus.py?rev=1185895&view=auto
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/TestServerStatus.py (added)
+++ incubator/ambari/trunk/agent/src/test/python/TestServerStatus.py Tue Oct 18 21:52:58 2011
@@ -0,0 +1,29 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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 unittest import TestCase
+from ambari_agent.ServerStatus import ServerStatus
+
+class TestServerStatus(TestCase):
+  def test_build(self):
+    serverStatus = ServerStatus()
+    result = serverStatus.build()
+    self.assertEqual(result, [], 'List of running servers should be 0.')
+

Added: incubator/ambari/trunk/agent/src/test/python/unitTests.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/unitTests.py?rev=1185895&view=auto
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/unitTests.py (added)
+++ incubator/ambari/trunk/agent/src/test/python/unitTests.py Tue Oct 18 21:52:58 2011
@@ -0,0 +1,49 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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 unittest
+import doctest
+
+class TestAgent(unittest.TestSuite):
+  def run(self, result):
+    run = unittest.TestSuite.run
+    run(self, result)
+    return result
+
+def all_tests_suite():
+  suite = unittest.TestLoader().loadTestsFromNames([
+    'TestHeartbeat',
+    'TestHardware',
+    'TestServerStatus',
+    'TestFileUtil',
+    'TestActionQueue'
+  ])
+  return TestAgent([suite])
+
+def main():
+  runner = unittest.TextTestRunner()
+  suite = all_tests_suite()
+  raise SystemExit(not runner.run(suite).wasSuccessful())
+
+if __name__ == '__main__':
+  import os
+  import sys
+  sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+  main()



Mime
View raw message