Bläddra i källkod

AMBARI-12211 Windows unit tests: Server unit tests: adapt the existing unit tests to Windows

Fixed the platform-specific Python and Java tests. Fixed file handle leaks in serverConfiguration.py.
Added profile to help suppress Python tests execution.
Florian Barca 10 år sedan
förälder
incheckning
03a927ddb2
21 ändrade filer med 924 tillägg och 240 borttagningar
  1. 2 2
      ambari-common/src/main/python/ambari_commons/os_windows.py
  2. 5 2
      ambari-common/src/test/python/only_for_platform.py
  3. 14 2
      ambari-server/pom.xml
  4. 17 12
      ambari-server/src/main/python/ambari-server.py
  5. 3 0
      ambari-server/src/main/python/ambari_server/dbConfiguration.py
  6. 31 18
      ambari-server/src/main/python/ambari_server/serverConfiguration.py
  7. 1 1
      ambari-server/src/main/python/ambari_server/setupSecurity.py
  8. 1 1
      ambari-server/src/main/python/setupAgent.py
  9. 20 2
      ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
  10. 11 15
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
  11. 5 0
      ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerActionTest.java
  12. 571 134
      ambari-server/src/test/python/TestAmbariServer.py
  13. 13 4
      ambari-server/src/test/python/TestOSCheck.py
  14. 42 24
      ambari-server/src/test/python/TestResourceFilesKeeper.py
  15. 83 8
      ambari-server/src/test/python/TestSetupAgent.py
  16. 4 1
      ambari-server/src/test/python/TestUtils.py
  17. 1 0
      ambari-server/src/test/python/TestValidateConfigs.py
  18. 59 7
      ambari-server/src/test/python/custom_actions/TestCheckHost.py
  19. 1 0
      ambari-server/src/test/python/custom_actions/TestInstallPackages.py
  20. 35 6
      ambari-server/src/test/python/custom_actions/test_ru_execute_tasks.py
  21. 5 1
      ambari-server/src/test/python/unitTests.py

+ 2 - 2
ambari-common/src/main/python/ambari_commons/os_windows.py

@@ -532,8 +532,8 @@ class WinServiceController:
         win32serviceutil.StopServiceWithDeps(serviceName, waitSecs=waitSecs)
         win32serviceutil.StopServiceWithDeps(serviceName, waitSecs=waitSecs)
       else:
       else:
         win32serviceutil.StopService(serviceName)
         win32serviceutil.StopService(serviceName)
-        if waitSecs:
-          win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_STOPPED, waitSecs)
+      if waitSecs:
+        win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_STOPPED, waitSecs)
     except win32service.error, exc:
     except win32service.error, exc:
       if exc.winerror != 1062:
       if exc.winerror != 1062:
         msg = "Error stopping service: %s (%d)" % (exc.strerror, exc.winerror)
         msg = "Error stopping service: %s (%d)" % (exc.strerror, exc.winerror)

+ 5 - 2
ambari-common/src/test/python/only_for_platform.py

@@ -46,7 +46,10 @@ def for_specific_platforms(systems):
       return obj
       return obj
   return decorator
   return decorator
 
 
+os_distro_value_linux = ('Suse','11','Final')
+os_distro_value_windows = ('win2012serverr2','6.3','WindowsServer')
+
 if get_platform() != PLATFORM_WINDOWS:
 if get_platform() != PLATFORM_WINDOWS:
-  os_distro_value = ('Suse','11','Final')
+  os_distro_value = os_distro_value_linux
 else:
 else:
-  os_distro_value = ('win2012serverr2','6.3','WindowsServer')
+  os_distro_value = os_distro_value_windows

+ 14 - 2
ambari-server/pom.xml

@@ -41,6 +41,7 @@
     <ambari-admin-dir>${basedir}/../ambari-admin</ambari-admin-dir>
     <ambari-admin-dir>${basedir}/../ambari-admin</ambari-admin-dir>
     <contrib-views-dir>${basedir}/../contrib/views</contrib-views-dir>
     <contrib-views-dir>${basedir}/../contrib/views</contrib-views-dir>
     <powermock.version>1.5</powermock.version>
     <powermock.version>1.5</powermock.version>
+    <skipPythonTests>false</skipPythonTests>
   </properties>
   </properties>
   <build>
   <build>
     <plugins>
     <plugins>
@@ -1217,7 +1218,7 @@
               <environmentVariables>
               <environmentVariables>
                   <PYTHONPATH>${path.python.1}${pathsep}$PYTHONPATH</PYTHONPATH>
                   <PYTHONPATH>${path.python.1}${pathsep}$PYTHONPATH</PYTHONPATH>
               </environmentVariables>
               </environmentVariables>
-              <skip>${skipTests}</skip>
+              <skip>${skipPythonTests}</skip>
             </configuration>
             </configuration>
             <id>python-test</id>
             <id>python-test</id>
             <phase>test</phase>
             <phase>test</phase>
@@ -1364,6 +1365,17 @@
         </plugins>
         </plugins>
       </build>
       </build>
     </profile>
     </profile>
+    <profile>
+      <id>skipTestRun</id>
+      <activation>
+        <property>
+          <name>skipTests</name>
+        </property>
+      </activation>
+      <properties>
+        <skipPythonTests>true</skipPythonTests>
+      </properties>
+    </profile>
     <profile>
     <profile>
       <id>windows</id>
       <id>windows</id>
       <activation>
       <activation>
@@ -1379,7 +1391,7 @@
         <executable.shell>cmd</executable.shell>
         <executable.shell>cmd</executable.shell>
         <fileextension.shell>cmd</fileextension.shell>
         <fileextension.shell>cmd</fileextension.shell>
         <fileextension.dot.shell-default>.cmd</fileextension.dot.shell-default>
         <fileextension.dot.shell-default>.cmd</fileextension.dot.shell-default>
-        <path.python.1>${project.basedir}\..\ambari-common\src\main\python;${project.basedir}\..\ambari-agent\src\main\python;${project.basedir}\..\ambari-common\src\main\python\ambari_jinja2;${project.basedir}\..\ambari-common\src\main\python\ambari_commons;${project.basedir}\..\ambari-common\src\test\python;${project.basedir}\src\main\python;${project.basedir}\src\main\python\ambari-server-state;${project.basedir}\src\main\resources\custom_actions;${project.basedir}\src\main\resources\scripts;${project.basedir}\src\test\python</path.python.1>
+        <path.python.1>${project.basedir}\..\ambari-common\src\main\python;${project.basedir}\..\ambari-agent\src\main\python;${project.basedir}\..\ambari-common\src\main\python\ambari_jinja2;${project.basedir}\..\ambari-common\src\main\python\ambari_commons;${project.basedir}\..\ambari-common\src\test\python;${project.basedir}\src\main\python;${project.basedir}\src\main\python\ambari-server-state;${project.basedir}\src\main\resources\custom_actions\scripts;${project.basedir}\src\main\resources\scripts;${project.basedir}\src\test\python</path.python.1>
         <assemblydescriptor>src/main/assemblies/server-windows.xml</assemblydescriptor>
         <assemblydescriptor>src/main/assemblies/server-windows.xml</assemblydescriptor>
         <assemblybootstrap>src/main/assemblies/bootstrap-windows.xml</assemblybootstrap>
         <assemblybootstrap>src/main/assemblies/bootstrap-windows.xml</assemblybootstrap>
         <assemblychocodescriptor>src/main/assemblies/server-windows-choco.xml</assemblychocodescriptor>
         <assemblychocodescriptor>src/main/assemblies/server-windows-choco.xml</assemblychocodescriptor>

+ 17 - 12
ambari-server/src/main/python/ambari-server.py

@@ -433,6 +433,7 @@ def init_debug(options):
 
 
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 def fix_database_options(options, parser):
 def fix_database_options(options, parser):
+  _validate_database_port(options, parser)
   pass
   pass
 
 
 @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
 @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
@@ -450,18 +451,7 @@ def fix_database_options(options, parser):
   elif options.dbms is not None:
   elif options.dbms is not None:
     options.dbms = options.dbms.lower()
     options.dbms = options.dbms.lower()
 
 
-  # correct port
-  if options.database_port is not None:
-    correct = False
-    try:
-      port = int(options.database_port)
-      if 65536 > port > 0:
-        correct = True
-    except ValueError:
-      pass
-    if not correct:
-      parser.print_help()
-      parser.error("Incorrect database port " + options.database_port)
+  _validate_database_port(options, parser)
 
 
   # jdbc driver and db options validation
   # jdbc driver and db options validation
   if options.jdbc_driver is None and options.jdbc_db is not None:
   if options.jdbc_driver is None and options.jdbc_db is not None:
@@ -477,6 +467,21 @@ def fix_database_options(options, parser):
     options.sid_or_sname = options.sid_or_sname.lower()
     options.sid_or_sname = options.sid_or_sname.lower()
 
 
 
 
+def _validate_database_port(options, parser):
+  # correct port
+  if options.database_port is not None:
+    correct = False
+    try:
+      port = int(options.database_port)
+      if 65536 > port > 0:
+        correct = True
+    except ValueError:
+      pass
+    if not correct:
+      parser.print_help()
+      parser.error("Incorrect database port " + options.database_port)
+
+
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 def create_user_action_map(args, options):
 def create_user_action_map(args, options):
   action_map = {
   action_map = {

+ 3 - 0
ambari-server/src/main/python/ambari_server/dbConfiguration.py

@@ -276,6 +276,9 @@ class DBMSConfigFactory(object):
   def get_supported_dbms(self):
   def get_supported_dbms(self):
     return []
     return []
 
 
+  def get_supported_jdbc_drivers(self):
+    return []
+
 #
 #
 # Database configuration factory for Windows
 # Database configuration factory for Windows
 #
 #

+ 31 - 18
ambari-server/src/main/python/ambari_server/serverConfiguration.py

@@ -411,7 +411,8 @@ def get_ambari_properties():
   properties = None
   properties = None
   try:
   try:
     properties = Properties()
     properties = Properties()
-    properties.load(open(conf_file))
+    with open(conf_file) as hfR:
+      properties.load(hfR)
   except (Exception), e:
   except (Exception), e:
     print 'Could not read "%s": %s' % (conf_file, e)
     print 'Could not read "%s": %s' % (conf_file, e)
     return -1
     return -1
@@ -571,7 +572,8 @@ def update_database_name_property(upgrade=False):
     properties.process_pair(JDBC_DATABASE_NAME_PROPERTY, configDefaults.DEFAULT_DB_NAME)
     properties.process_pair(JDBC_DATABASE_NAME_PROPERTY, configDefaults.DEFAULT_DB_NAME)
     conf_file = find_properties_file()
     conf_file = find_properties_file()
     try:
     try:
-      properties.store(open(conf_file, "w"))
+      with open(conf_file, "w") as hfW:
+        properties.store(hfW)
     except Exception, e:
     except Exception, e:
       err = 'Could not write ambari config file "%s": %s' % (conf_file, e)
       err = 'Could not write ambari config file "%s": %s' % (conf_file, e)
       raise FatalException(-1, err)
       raise FatalException(-1, err)
@@ -631,9 +633,8 @@ def read_passwd_for_alias(alias, masterKey=""):
     tempDir = tempfile.gettempdir()
     tempDir = tempfile.gettempdir()
     #create temporary file for writing
     #create temporary file for writing
     tempFilePath = tempDir + os.sep + tempFileName
     tempFilePath = tempDir + os.sep + tempFileName
-    file = open(tempFilePath, 'w+')
-    os.chmod(tempFilePath, stat.S_IREAD | stat.S_IWRITE)
-    file.close()
+    with open(tempFilePath, 'w+'):
+      os.chmod(tempFilePath, stat.S_IREAD | stat.S_IWRITE)
 
 
     if masterKey is None or masterKey == "":
     if masterKey is None or masterKey == "":
       masterKey = "None"
       masterKey = "None"
@@ -646,7 +647,8 @@ def read_passwd_for_alias(alias, masterKey=""):
     if retcode != 0:
     if retcode != 0:
       print 'ERROR: Unable to read password from store. alias = ' + alias
       print 'ERROR: Unable to read password from store. alias = ' + alias
     else:
     else:
-      passwd = open(tempFilePath, 'r').read()
+      with open(tempFilePath, 'r') as hfRTemp:
+        passwd = hfRTemp.read()
       # Remove temporary file
       # Remove temporary file
     os.remove(tempFilePath)
     os.remove(tempFilePath)
     return passwd
     return passwd
@@ -783,7 +785,8 @@ def parse_properties_file(args):
   args.database_password_file = properties[JDBC_PASSWORD_PROPERTY]
   args.database_password_file = properties[JDBC_PASSWORD_PROPERTY]
   if args.database_password_file:
   if args.database_password_file:
     if not is_alias_string(args.database_password_file):
     if not is_alias_string(args.database_password_file):
-      args.database_password = open(properties[JDBC_PASSWORD_PROPERTY]).read()
+      with open(properties[JDBC_PASSWORD_PROPERTY]) as hfDbPwd:
+        args.database_password = hfDbPwd.read()
     else:
     else:
       args.database_password = args.database_password_file
       args.database_password = args.database_password_file
   return 0
   return 0
@@ -837,16 +840,18 @@ def update_ambari_properties():
     print_error_msg("Can't find %s file" % AMBARI_PROPERTIES_FILE)
     print_error_msg("Can't find %s file" % AMBARI_PROPERTIES_FILE)
     return -1
     return -1
 
 
-  try:
-    old_properties = Properties()
-    old_properties.load(open(prev_conf_file))
-  except Exception, e:
-    print 'Could not read "%s": %s' % (prev_conf_file, e)
-    return -1
+  with open(prev_conf_file) as hfOld:
+    try:
+      old_properties = Properties()
+      old_properties.load(hfOld)
+    except Exception, e:
+      print 'Could not read "%s": %s' % (prev_conf_file, e)
+      return -1
 
 
   try:
   try:
     new_properties = Properties()
     new_properties = Properties()
-    new_properties.load(open(conf_file))
+    with open(conf_file) as hfNew:
+      new_properties.load(hfNew)
 
 
     for prop_key, prop_value in old_properties.getPropertyDict().items():
     for prop_key, prop_value in old_properties.getPropertyDict().items():
       if "agent.fqdn.service.url" == prop_key:
       if "agent.fqdn.service.url" == prop_key:
@@ -866,7 +871,8 @@ def update_ambari_properties():
     if OS_FAMILY_PROPERTY not in new_properties.keys():
     if OS_FAMILY_PROPERTY not in new_properties.keys():
       new_properties.process_pair(OS_FAMILY_PROPERTY, OS_FAMILY + OS_VERSION)
       new_properties.process_pair(OS_FAMILY_PROPERTY, OS_FAMILY + OS_VERSION)
 
 
-    new_properties.store(open(conf_file, 'w'))
+    with open(conf_file, 'w') as hfW:
+      new_properties.store(hfW)
 
 
   except Exception, e:
   except Exception, e:
     print 'Could not write "%s": %s' % (conf_file, e)
     print 'Could not write "%s": %s' % (conf_file, e)
@@ -874,7 +880,12 @@ def update_ambari_properties():
 
 
   timestamp = datetime.datetime.now()
   timestamp = datetime.datetime.now()
   fmt = '%Y%m%d%H%M%S'
   fmt = '%Y%m%d%H%M%S'
-  os.rename(prev_conf_file, prev_conf_file + '.' + timestamp.strftime(fmt))
+  new_conf_file = prev_conf_file + '.' + timestamp.strftime(fmt)
+  try:
+    os.rename(prev_conf_file, new_conf_file)
+  except Exception, e:
+    print 'Could not rename "%s" to "%s": %s' % (prev_conf_file, new_conf_file, e)
+    #Not critical, move on
 
 
   return 0
   return 0
 
 
@@ -924,13 +935,15 @@ def write_property(key, value):
   conf_file = find_properties_file()
   conf_file = find_properties_file()
   properties = Properties()
   properties = Properties()
   try:
   try:
-    properties.load(open(conf_file))
+    with open(conf_file, "r") as hfR:
+      properties.load(hfR)
   except Exception, e:
   except Exception, e:
     print_error_msg('Could not read ambari config file "%s": %s' % (conf_file, e))
     print_error_msg('Could not read ambari config file "%s": %s' % (conf_file, e))
     return -1
     return -1
   properties.process_pair(key, value)
   properties.process_pair(key, value)
   try:
   try:
-    properties.store(open(conf_file, "w"))
+    with open(conf_file, 'w') as hfW:
+      properties.store(hfW)
   except Exception, e:
   except Exception, e:
     print_error_msg('Could not write ambari config file "%s": %s' % (conf_file, e))
     print_error_msg('Could not write ambari config file "%s": %s' % (conf_file, e))
     return -1
     return -1

+ 1 - 1
ambari-server/src/main/python/ambari_server/setupSecurity.py

@@ -555,7 +555,7 @@ def init_ldap_properties_list_reqd(properties):
     LdapPropTemplate(properties, "authentication.ldap.usernameAttribute", "User name attribute* {0}: ", REGEX_ANYTHING, False, "uid"),
     LdapPropTemplate(properties, "authentication.ldap.usernameAttribute", "User name attribute* {0}: ", REGEX_ANYTHING, False, "uid"),
     LdapPropTemplate(properties, "authentication.ldap.baseDn", "Base DN* {0}: ", REGEX_ANYTHING, False),
     LdapPropTemplate(properties, "authentication.ldap.baseDn", "Base DN* {0}: ", REGEX_ANYTHING, False),
     LdapPropTemplate(properties, "authentication.ldap.referral", "Referral method [follow/ignore] {0}: ", REGEX_REFERRAL, True),
     LdapPropTemplate(properties, "authentication.ldap.referral", "Referral method [follow/ignore] {0}: ", REGEX_REFERRAL, True),
-    LdapPropTemplate(properties, "authentication.ldap.bindAnonymously" "Bind anonymously* [true/false] {0}: ", REGEX_TRUE_FALSE, False, "false")
+    LdapPropTemplate(properties, "authentication.ldap.bindAnonymously", "Bind anonymously* [true/false] {0}: ", REGEX_TRUE_FALSE, False, "false")
   ]
   ]
   return ldap_properties
   return ldap_properties
 
 

+ 1 - 1
ambari-server/src/main/python/setupAgent.py

@@ -206,7 +206,7 @@ def checkVerbose():
 def getOptimalVersion(initialProjectVersion):
 def getOptimalVersion(initialProjectVersion):
   optimalVersion = initialProjectVersion
   optimalVersion = initialProjectVersion
   ret = findNearestAgentPackageVersion(optimalVersion)
   ret = findNearestAgentPackageVersion(optimalVersion)
-  if ret["exitstatus"] == 0 and ret["log"][0].strip() != "" \
+  if ret["exitstatus"] == 0 and ret["log"][0].strip() != "" and initialProjectVersion \
      and ret["log"][0].strip().startswith(initialProjectVersion):
      and ret["log"][0].strip().startswith(initialProjectVersion):
     optimalVersion = ret["log"][0].strip()
     optimalVersion = ret["log"][0].strip()
     retcode = 0
     retcode = 0

+ 20 - 2
ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java

@@ -72,7 +72,7 @@ public class BootStrapTest extends TestCase {
     }
     }
 
 
     properties.setProperty(Configuration.BOOTSTRAP_DIR, bootdir);
     properties.setProperty(Configuration.BOOTSTRAP_DIR, bootdir);
-    properties.setProperty(Configuration.BOOTSTRAP_SCRIPT, "echo");
+    properties.setProperty(Configuration.BOOTSTRAP_SCRIPT, prepareEchoCommand(bootdir));
     properties.setProperty(Configuration.SRVR_KSTR_DIR_KEY, "target" + File.separator + "classes");
     properties.setProperty(Configuration.SRVR_KSTR_DIR_KEY, "target" + File.separator + "classes");
     properties.setProperty(Configuration.METADETA_DIR_PATH, metadetadir);
     properties.setProperty(Configuration.METADETA_DIR_PATH, metadetadir);
     properties.setProperty(Configuration.SERVER_VERSION_FILE, serverVersionFilePath);
     properties.setProperty(Configuration.SERVER_VERSION_FILE, serverVersionFilePath);
@@ -111,6 +111,24 @@ public class BootStrapTest extends TestCase {
     Assert.assertFalse(new File(bootdir + File.separator + "1" + File.separator + "host_pass").exists());
     Assert.assertFalse(new File(bootdir + File.separator + "1" + File.separator + "host_pass").exists());
   }
   }
 
 
+  private static String prepareEchoCommand(String bootdir) throws IOException {
+    if (System.getProperty("os.name").contains("Windows")) {
+      //The command line becomes "python echo", so create a Python script in the current dir
+      String pythonEcho = "import sys;\nif __name__ == '__main__':\n" +
+          "  args = sys.argv\n" +
+          "  if len(args) > 1:\n" +
+          "    print args[1]";
+      File echo = new File(bootdir, "echo.py");
+      //Ensure the file wasn't there
+      echo.delete();
+      FileUtils.writeStringToFile(echo, pythonEcho);
+
+      return echo.getPath();
+    } else {
+      return "echo";
+    }
+  }
+
   @Test
   @Test
   public void testHostFailure() throws Exception {
   public void testHostFailure() throws Exception {
     Properties properties = new Properties();
     Properties properties = new Properties();
@@ -129,7 +147,7 @@ public class BootStrapTest extends TestCase {
     }
     }
 
 
     properties.setProperty(Configuration.BOOTSTRAP_DIR, bootdir);
     properties.setProperty(Configuration.BOOTSTRAP_DIR, bootdir);
-    properties.setProperty(Configuration.BOOTSTRAP_SCRIPT, "echo");
+    properties.setProperty(Configuration.BOOTSTRAP_SCRIPT, prepareEchoCommand(bootdir));
     properties.setProperty(Configuration.SRVR_KSTR_DIR_KEY, serverKSTRDir);
     properties.setProperty(Configuration.SRVR_KSTR_DIR_KEY, serverKSTRDir);
     properties.setProperty(Configuration.METADETA_DIR_PATH, metadetadir);
     properties.setProperty(Configuration.METADETA_DIR_PATH, metadetadir);
     properties.setProperty(Configuration.SERVER_VERSION_FILE, serverVersionFilePath);
     properties.setProperty(Configuration.SERVER_VERSION_FILE, serverVersionFilePath);

+ 11 - 15
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java

@@ -181,8 +181,8 @@ public class ClientConfigResourceProviderTest {
 
 
     // create the request
     // create the request
     Request request = PropertyHelper.getReadRequest(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID, "c1",
     Request request = PropertyHelper.getReadRequest(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID, "c1",
-            ClientConfigResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID,
-            ClientConfigResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID);
+        ClientConfigResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID,
+        ClientConfigResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID);
 
 
     Predicate predicate = new PredicateBuilder().property(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("c1").
     Predicate predicate = new PredicateBuilder().property(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("c1").
         toPredicate();
         toPredicate();
@@ -200,11 +200,10 @@ public class ClientConfigResourceProviderTest {
     String packageFolder="PIG/package";
     String packageFolder="PIG/package";
 
 
     if (System.getProperty("os.name").contains("Windows")) {
     if (System.getProperty("os.name").contains("Windows")) {
-      stackRoot = "\\tmp\\stacks\\S1\\V1";
+      stackRoot = "C:\\tmp\\stacks\\S1\\V1";
       packageFolder = "PIG\\package";
       packageFolder = "PIG\\package";
     }
     }
 
 
-    File stackRootFile = new File(stackRoot);
     HashMap<String, Host> hosts = new HashMap<String, Host>();
     HashMap<String, Host> hosts = new HashMap<String, Host>();
     hosts.put(hostName, host);
     hosts.put(hostName, host);
     HashMap<String, Service> services = new HashMap<String, Service>();
     HashMap<String, Service> services = new HashMap<String, Service>();
@@ -220,7 +219,7 @@ public class ClientConfigResourceProviderTest {
 
 
     Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
     Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
     responses.add(shr1);
     responses.add(shr1);
-    
+
     Map<String, String> returnConfigMap = new HashMap<String, String>();
     Map<String, String> returnConfigMap = new HashMap<String, String>();
     returnConfigMap.put(Configuration.SERVER_TMP_DIR_KEY, Configuration.SERVER_TMP_DIR_DEFAULT);
     returnConfigMap.put(Configuration.SERVER_TMP_DIR_KEY, Configuration.SERVER_TMP_DIR_DEFAULT);
     returnConfigMap.put(Configuration.AMBARI_PYTHON_WRAP_KEY, Configuration.AMBARI_PYTHON_WRAP_DEFAULT);
     returnConfigMap.put(Configuration.AMBARI_PYTHON_WRAP_KEY, Configuration.AMBARI_PYTHON_WRAP_DEFAULT);
@@ -236,7 +235,7 @@ public class ClientConfigResourceProviderTest {
     expect(configMap.get(Configuration.SERVER_TMP_DIR_KEY)).andReturn(Configuration.SERVER_TMP_DIR_DEFAULT);
     expect(configMap.get(Configuration.SERVER_TMP_DIR_KEY)).andReturn(Configuration.SERVER_TMP_DIR_DEFAULT);
     expect(configMap.get(Configuration.AMBARI_PYTHON_WRAP_KEY)).andReturn(Configuration.AMBARI_PYTHON_WRAP_DEFAULT);
     expect(configMap.get(Configuration.AMBARI_PYTHON_WRAP_KEY)).andReturn(Configuration.AMBARI_PYTHON_WRAP_DEFAULT);
     expect(configuration.getConfigsMap()).andReturn(returnConfigMap);
     expect(configuration.getConfigsMap()).andReturn(returnConfigMap);
-    expect(configuration.getResourceDirPath()).andReturn("/tmp/stacks/S1/V1");
+    expect(configuration.getResourceDirPath()).andReturn(stackRoot);
     expect(configuration.getJavaVersion()).andReturn(8);
     expect(configuration.getJavaVersion()).andReturn(8);
     expect(configuration.areHostsSysPrepped()).andReturn("false");
     expect(configuration.areHostsSysPrepped()).andReturn("false");
     expect(configuration.getExternalScriptTimeout()).andReturn(Integer.parseInt(Configuration.EXTERNAL_SCRIPT_TIMEOUT_DEFAULT));
     expect(configuration.getExternalScriptTimeout()).andReturn(Integer.parseInt(Configuration.EXTERNAL_SCRIPT_TIMEOUT_DEFAULT));
@@ -300,10 +299,9 @@ public class ClientConfigResourceProviderTest {
             "INFO /var/lib/ambari-server/tmp";
             "INFO /var/lib/ambari-server/tmp";
 
 
     if (System.getProperty("os.name").contains("Windows")) {
     if (System.getProperty("os.name").contains("Windows")) {
-      String absoluteStackRoot = stackRootFile.getAbsolutePath();
-      commandLine = "ambari-python-wrap " + absoluteStackRoot +
+      commandLine = "ambari-python-wrap " + stackRoot +
               "\\PIG\\package\\null generate_configs null " +
               "\\PIG\\package\\null generate_configs null " +
-              absoluteStackRoot + "\\PIG\\package /var/lib/ambari-server/tmp\\structured-out.json " +
+              stackRoot + "\\PIG\\package /var/lib/ambari-server/tmp\\structured-out.json " +
               "INFO /var/lib/ambari-server/tmp";
               "INFO /var/lib/ambari-server/tmp";
     }
     }
 
 
@@ -381,8 +379,8 @@ public class ClientConfigResourceProviderTest {
 
 
     // create the request
     // create the request
     Request request = PropertyHelper.getReadRequest(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID, "c1",
     Request request = PropertyHelper.getReadRequest(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID, "c1",
-            ClientConfigResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID,
-            ClientConfigResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID);
+        ClientConfigResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID,
+        ClientConfigResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID);
 
 
     Predicate predicate = new PredicateBuilder().property(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("c1").
     Predicate predicate = new PredicateBuilder().property(ClientConfigResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("c1").
         toPredicate();
         toPredicate();
@@ -398,14 +396,13 @@ public class ClientConfigResourceProviderTest {
 
 
     String stackRoot="/tmp/stacks/S1/V1";
     String stackRoot="/tmp/stacks/S1/V1";
     String packageFolder= StackManager.COMMON_SERVICES + "/PIG/package";
     String packageFolder= StackManager.COMMON_SERVICES + "/PIG/package";
-    String commonServicesPath = "/var/lib/ambari-server/src/main/resources/common-services";
+    String commonServicesPath = "/var/lib/ambari-server/src/main/resources" + File.separator + "common-services";
 
 
     if (System.getProperty("os.name").contains("Windows")) {
     if (System.getProperty("os.name").contains("Windows")) {
-      stackRoot = "\\tmp\\stacks\\S1\\V1";
+      stackRoot = "C:\\tmp\\stacks\\S1\\V1";
       packageFolder = StackManager.COMMON_SERVICES + "\\PIG\\package";
       packageFolder = StackManager.COMMON_SERVICES + "\\PIG\\package";
     }
     }
 
 
-    File stackRootFile = new File(stackRoot);
     HashMap<String, Host> hosts = new HashMap<String, Host>();
     HashMap<String, Host> hosts = new HashMap<String, Host>();
     hosts.put(hostName, host);
     hosts.put(hostName, host);
     HashMap<String, Service> services = new HashMap<String, Service>();
     HashMap<String, Service> services = new HashMap<String, Service>();
@@ -502,7 +499,6 @@ public class ClientConfigResourceProviderTest {
             "INFO /var/lib/ambari-server/tmp";
             "INFO /var/lib/ambari-server/tmp";
 
 
     if (System.getProperty("os.name").contains("Windows")) {
     if (System.getProperty("os.name").contains("Windows")) {
-      String absoluteStackRoot = stackRootFile.getAbsolutePath();
       commandLine = "ambari-python-wrap " + commonServicesPath +
       commandLine = "ambari-python-wrap " + commonServicesPath +
               "\\PIG\\package\\null generate_configs null " +
               "\\PIG\\package\\null generate_configs null " +
               commonServicesPath + "\\PIG\\package /var/lib/ambari-server/tmp\\structured-out.json " +
               commonServicesPath + "\\PIG\\package /var/lib/ambari-server/tmp\\structured-out.json " +

+ 5 - 0
ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerActionTest.java

@@ -19,6 +19,7 @@
 package org.apache.ambari.server.serveraction.kerberos;
 package org.apache.ambari.server.serveraction.kerberos;
 
 
 import junit.framework.Assert;
 import junit.framework.Assert;
+import org.junit.Assume;
 import org.junit.Rule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.rules.TemporaryFolder;
@@ -30,6 +31,8 @@ import java.nio.file.Paths;
 import java.nio.file.attribute.PosixFilePermission;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Set;
 import java.util.Set;
 
 
+import org.apache.ambari.server.utils.ShellCommandUtil;
+
 public class CreateKeytabFilesServerActionTest {
 public class CreateKeytabFilesServerActionTest {
 
 
   @Rule
   @Rule
@@ -37,6 +40,8 @@ public class CreateKeytabFilesServerActionTest {
 
 
   @Test
   @Test
   public void testEnsureAmbariOnlyAccess() throws Exception {
   public void testEnsureAmbariOnlyAccess() throws Exception {
+    Assume.assumeTrue(ShellCommandUtil.UNIX_LIKE);
+
     Path path;
     Path path;
     Set<PosixFilePermission> permissions;
     Set<PosixFilePermission> permissions;
 
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 571 - 134
ambari-server/src/test/python/TestAmbariServer.py


+ 13 - 4
ambari-server/src/test/python/TestOSCheck.py

@@ -28,13 +28,15 @@ from unittest import TestCase
 from mock.mock import patch
 from mock.mock import patch
 from mock.mock import MagicMock
 from mock.mock import MagicMock
 
 
+from only_for_platform import os_distro_value, os_distro_value_linux
+
 from ambari_commons import OSCheck
 from ambari_commons import OSCheck
 import os_check_type
 import os_check_type
 
 
 utils = __import__('ambari_server.utils').utils
 utils = __import__('ambari_server.utils').utils
 # We have to use this import HACK because the filename contains a dash
 # We have to use this import HACK because the filename contains a dash
-with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
-  with patch.object(OSCheck, "os_distribution", return_value = ('Suse','11','Final')):
+with patch("platform.linux_distribution", return_value = os_distro_value_linux):
+  with patch.object(OSCheck, "os_distribution", return_value = os_distro_value):
     with patch.object(utils, "get_postgre_hba_dir"):
     with patch.object(utils, "get_postgre_hba_dir"):
       ambari_server = __import__('ambari-server')
       ambari_server = __import__('ambari-server')
 
 
@@ -207,15 +209,21 @@ class TestOSCheck(TestCase):
     configDefaults.AMBARI_PROPERTIES_BACKUP_FILE = fn1
     configDefaults.AMBARI_PROPERTIES_BACKUP_FILE = fn1
     serverConfiguration.AMBARI_PROPERTIES_FILE = fn2
     serverConfiguration.AMBARI_PROPERTIES_FILE = fn2
 
 
-    with open(configDefaults.AMBARI_PROPERTIES_BACKUP_FILE, 'w') as f:
+    f = open(configDefaults.AMBARI_PROPERTIES_BACKUP_FILE, 'w')
+    try:
       for line in properties:
       for line in properties:
         f.write(line)
         f.write(line)
+    finally:
+      f.close()
 
 
     #Call tested method
     #Call tested method
     update_ambari_properties()
     update_ambari_properties()
 
 
-    with open(serverConfiguration.AMBARI_PROPERTIES_FILE, 'r') as f:
+    f = open(serverConfiguration.AMBARI_PROPERTIES_FILE, 'r')
+    try:
       ambari_properties_content = f.readlines()
       ambari_properties_content = f.readlines()
+    finally:
+      f.close()
 
 
     count = 0
     count = 0
     for line in ambari_properties_content:
     for line in ambari_properties_content:
@@ -230,6 +238,7 @@ class TestOSCheck(TestCase):
     # Command should not fail if *.rpmsave file is missing
     # Command should not fail if *.rpmsave file is missing
     result = update_ambari_properties()
     result = update_ambari_properties()
     self.assertEquals(result, 0)
     self.assertEquals(result, 0)
+    pass
 
 
   @patch.object(OSCheck, "os_distribution")
   @patch.object(OSCheck, "os_distribution")
   def test_os_type_check(self, mock_linux_distribution):
   def test_os_type_check(self, mock_linux_distribution):

+ 42 - 24
ambari-server/src/test/python/TestResourceFilesKeeper.py

@@ -29,45 +29,74 @@ from subprocess import Popen
 from mock.mock import MagicMock, call
 from mock.mock import MagicMock, call
 from mock.mock import patch
 from mock.mock import patch
 from mock.mock import create_autospec
 from mock.mock import create_autospec
+from only_for_platform import get_platform, not_for_platform, only_for_platform, os_distro_value, PLATFORM_WINDOWS
+
 from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
 from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
 
 
 
 
 class TestResourceFilesKeeper(TestCase):
 class TestResourceFilesKeeper(TestCase):
 
 
-  TEST_RESOURCES_DIR = "../resources"
-  TEST_STACKS_DIR="../resources/stacks"
+  TEST_RESOURCES_DIR = ".." + os.sep + "resources"
+  TEST_STACKS_DIR = ".." + os.sep + "resources" + os.sep + "stacks"
 
 
   # Stack that is not expected to change
   # Stack that is not expected to change
-  DUMMY_UNCHANGEABLE_STACK="../resources/TestAmbaryServer.samples/" \
-                           "dummy_stack/HIVE/"
+  DUMMY_UNCHANGEABLE_STACK = ".." + os.sep + "resources" + os.sep + "TestAmbaryServer.samples" + os.sep + \
+                           "dummy_stack" + os.sep + "HIVE"
 
 
-  DUMMY_ACTIVE_STACK="../resources/TestAmbaryServer.samples/" \
-                           "active_stack/"
+  DUMMY_ACTIVE_STACK = ".." + os.sep + "resources" + os.sep + "TestAmbaryServer.samples" + os.sep + \
+                           "active_stack"
 
 
-  DUMMY_INACTIVE_STACK="../resources/TestAmbaryServer.samples/" \
-                     "inactive_stack/"
+  DUMMY_INACTIVE_STACK = ".." + os.sep + "resources" + os.sep + "TestAmbaryServer.samples" + os.sep + \
+                     "inactive_stack"
 
 
   DUMMY_UNCHANGEABLE_PACKAGE=os.path.join(DUMMY_UNCHANGEABLE_STACK,
   DUMMY_UNCHANGEABLE_PACKAGE=os.path.join(DUMMY_UNCHANGEABLE_STACK,
                                     ResourceFilesKeeper.PACKAGE_DIR)
                                     ResourceFilesKeeper.PACKAGE_DIR)
 
 
-  DUMMY_UNCHANGEABLE_PACKAGE_HASH="33a5f7d3bb6e7b4545431fc07ae87fa2d59a09c4"
+  if get_platform() != PLATFORM_WINDOWS:
+    DUMMY_UNCHANGEABLE_PACKAGE_HASH="33a5f7d3bb6e7b4545431fc07ae87fa2d59a09c4"
+  else:
+    DUMMY_UNCHANGEABLE_PACKAGE_HASH="2e438f4f9862420ed8930a56b8809b8aca359e87"
   DUMMY_HASH="dummy_hash"
   DUMMY_HASH="dummy_hash"
   YA_HASH="yet_another_hash"
   YA_HASH="yet_another_hash"
   SOME_PATH="some-path"
   SOME_PATH="some-path"
 
 
-  DUMMY_UNCHANGEABLE_COMMON_SERVICES="../resources/TestAmbaryServer.samples/" \
-                                     "dummy_common_services/HIVE/0.11.0.2.0.5.0"
+  DUMMY_UNCHANGEABLE_COMMON_SERVICES=".." + os.sep + "resources" + os.sep + "TestAmbaryServer.samples" + os.sep + \
+                                     "dummy_common_services" + os.sep + "HIVE" + os.sep + "0.11.0.2.0.5.0"
 
 
   DUMMY_UNCHANGEABLE_COMMON_SERVICES_PACKAGE=os.path.join(DUMMY_UNCHANGEABLE_COMMON_SERVICES,
   DUMMY_UNCHANGEABLE_COMMON_SERVICES_PACKAGE=os.path.join(DUMMY_UNCHANGEABLE_COMMON_SERVICES,
                                                           ResourceFilesKeeper.PACKAGE_DIR)
                                                           ResourceFilesKeeper.PACKAGE_DIR)
 
 
+  if get_platform() != PLATFORM_WINDOWS:
+    UPDATE_DIRECTORY_ARCHIVE_CALL_LIST = \
+      "[call('../resources/TestAmbaryServer.samples/" \
+      "dummy_stack/HIVE/package'),\n " \
+      "call('../resources/TestAmbaryServer.samples/" \
+      "dummy_stack/HIVE/package'),\n " \
+      "call('../resources/TestAmbaryServer.samples/" \
+      "dummy_stack/HIVE/package'),\n " \
+      "call('../resources/TestAmbaryServer.samples/" \
+      "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n " \
+      "call('../resources/TestAmbaryServer.samples/" \
+      "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n " \
+      "call('../resources/custom_actions'),\n " \
+      "call('../resources/host_scripts')]"
+  else:
+    UPDATE_DIRECTORY_ARCHIVE_CALL_LIST = \
+      "[call('..\\\\resources\\\\TestAmbaryServer.samples\\\\dummy_stack\\\\HIVE\\\\package'),\n " \
+      "call('..\\\\resources\\\\TestAmbaryServer.samples\\\\dummy_stack\\\\HIVE\\\\package'),\n " \
+      "call('..\\\\resources\\\\TestAmbaryServer.samples\\\\dummy_stack\\\\HIVE\\\\package'),\n " \
+      "call('..\\\\resources\\\\TestAmbaryServer.samples\\\\dummy_common_services\\\\HIVE\\\\0.11.0.2.0.5.0\\\\package'),\n " \
+      "call('..\\\\resources\\\\TestAmbaryServer.samples\\\\dummy_common_services\\\\HIVE\\\\0.11.0.2.0.5.0\\\\package'),\n " \
+      "call('..\\\\resources\\\\custom_actions'),\n " \
+      "call('..\\\\resources\\\\host_scripts')]"
+
   def setUp(self):
   def setUp(self):
     logging.basicConfig(level=logging.ERROR)
     logging.basicConfig(level=logging.ERROR)
 
 
 
 
   @patch.object(ResourceFilesKeeper, "update_directory_archieves")
   @patch.object(ResourceFilesKeeper, "update_directory_archieves")
   def test_perform_housekeeping(self, update_directory_archieves_mock):
   def test_perform_housekeeping(self, update_directory_archieves_mock):
-    resource_files_keeper = ResourceFilesKeeper("/dummy-resources", "/dummy-path")
+    resource_files_keeper = ResourceFilesKeeper(os.sep + "dummy-resources", os.sep + "dummy-path")
     resource_files_keeper.perform_housekeeping()
     resource_files_keeper.perform_housekeeping()
     update_directory_archieves_mock.assertCalled()
     update_directory_archieves_mock.assertCalled()
     pass
     pass
@@ -91,18 +120,7 @@ class TestResourceFilesKeeper(TestCase):
     resource_files_keeper.update_directory_archieves()
     resource_files_keeper.update_directory_archieves()
     self.assertEquals(pprint.pformat(
     self.assertEquals(pprint.pformat(
       update_directory_archive_mock.call_args_list),
       update_directory_archive_mock.call_args_list),
-            "[call('../resources/TestAmbaryServer.samples/"
-            "dummy_stack/HIVE/package'),\n "
-            "call('../resources/TestAmbaryServer.samples/"
-            "dummy_stack/HIVE/package'),\n "
-            "call('../resources/TestAmbaryServer.samples/"
-            "dummy_stack/HIVE/package'),\n "
-            "call('../resources/TestAmbaryServer.samples/"
-            "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n "
-            "call('../resources/TestAmbaryServer.samples/"
-            "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n "
-            "call('../resources/custom_actions'),\n "
-            "call('../resources/host_scripts')]")
+      self.UPDATE_DIRECTORY_ARCHIVE_CALL_LIST)
     pass
     pass
 
 
 
 

+ 83 - 8
ambari-server/src/test/python/TestSetupAgent.py

@@ -22,14 +22,9 @@ from mock.mock import patch
 import sys
 import sys
 
 
 from ambari_commons import OSCheck
 from ambari_commons import OSCheck
-from only_for_platform import get_platform, not_for_platform, only_for_platform, PLATFORM_WINDOWS, PLATFORM_LINUX
+from only_for_platform import get_platform, not_for_platform, only_for_platform, os_distro_value, PLATFORM_WINDOWS
 from mock.mock import MagicMock, patch, ANY, Mock
 from mock.mock import MagicMock, patch, ANY, Mock
 
 
-if get_platform() != PLATFORM_WINDOWS:
-  os_distro_value = ('Suse','11','Final')
-else:
-  os_distro_value = ('win2012serverr2','6.3','WindowsServer')
-
 with patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)):
 with patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)):
 #  from ambari_agent import NetUtil, security
 #  from ambari_agent import NetUtil, security
 
 
@@ -69,6 +64,7 @@ class TestSetupAgent(TestCase):
     pass
     pass
 
 
 
 
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(setup_agent, 'execOsCommand')
   @patch.object(setup_agent, 'execOsCommand')
   @patch("os.environ")
   @patch("os.environ")
   @patch("subprocess.Popen")
   @patch("subprocess.Popen")
@@ -127,6 +123,36 @@ class TestSetupAgent(TestCase):
     execOsCommand_mock.reset_mock()
     execOsCommand_mock.reset_mock()
     pass
     pass
 
 
+  @only_for_platform(PLATFORM_WINDOWS)
+  @patch.object(setup_agent, 'run_os_command')
+  @patch("os.environ")
+  @patch("time.sleep")
+  def test_runAgent(self, sleep_mock, environ_mock, run_os_command_mock):
+    expected_hostname = "test.hst"
+    passphrase = "passphrase"
+    run_os_command_mock.return_value = (0, "log", "")
+    # Test if expected_hostname is passed
+    ret = setup_agent.runAgent(passphrase, expected_hostname, "root", False)
+    self.assertEqual(run_os_command_mock.call_count, 1)
+    cmdStr = str(run_os_command_mock.call_args_list[0][0])
+    self.assertEqual(cmdStr, str((["cmd", "/c", "ambari-agent.cmd", "restart"],)))
+    self.assertFalse('-v' in cmdStr)
+    self.assertEqual(ret["exitstatus"], 0)
+    self.assertFalse(sleep_mock.called)
+
+    run_os_command_mock.reset_mock()
+    sleep_mock.reset_mock()
+
+    # Retry command
+    run_os_command_mock.side_effect = [(2, "log", "err"), (0, "log", "")]
+    ret = setup_agent.runAgent(passphrase, expected_hostname, "root", False)
+    self.assertEqual(run_os_command_mock.call_count, 2)
+    self.assertTrue("Retrying" in ret['log'][1])
+    self.assertEqual(ret["exitstatus"], 0)
+    self.assertTrue(sleep_mock.called)
+    pass
+
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_suse_family')
@@ -144,6 +170,7 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["exitstatus"] == 1)
     self.assertTrue(result_version["exitstatus"] == 1)
     pass
     pass
 
 
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_suse_family')
@@ -161,6 +188,21 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["exitstatus"] == 1)
     self.assertTrue(result_version["exitstatus"] == 1)
     pass
     pass
 
 
+  @only_for_platform(PLATFORM_WINDOWS)
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
+  @patch.object(setup_agent, 'findNearestAgentPackageVersion')
+  def test_returned_optimal_version_is_initial_on_suse(self, findNearestAgentPackageVersion_method,
+                                                       getAvailableAgentPackageVersions_method):
+    getAvailableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": "1.1.1"}
+
+    projectVersion = "1.1.1"
+    result_version = setup_agent.getOptimalVersion(projectVersion)
+    self.assertTrue(findNearestAgentPackageVersion_method.called)
+    self.assertTrue(result_version["exitstatus"] == 1)
+    pass
+
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_ubuntu_family')
   @patch('ambari_commons.OSCheck.is_ubuntu_family')
@@ -183,6 +225,7 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["exitstatus"] == 1)
     self.assertTrue(result_version["exitstatus"] == 1)
     pass
     pass
 
 
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_ubuntu_family')
   @patch('ambari_commons.OSCheck.is_ubuntu_family')
@@ -205,6 +248,25 @@ class TestSetupAgent(TestCase):
     self.assertTrue(result_version["exitstatus"] == 1)
     self.assertTrue(result_version["exitstatus"] == 1)
     pass
     pass
 
 
+  @only_for_platform(PLATFORM_WINDOWS)
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch.object(setup_agent, 'findNearestAgentPackageVersion')
+  @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
+  def test_returned_optimal_version_is_nearest_on_windows(self, findNearestAgentPackageVersion_method,
+                                                          getAvailableAgentPackageVersions_method):
+    projectVersion = ""
+    nearest_version = projectVersion + "1.1.1"
+    findNearestAgentPackageVersion_method.return_value = {
+      "exitstatus": 0,
+      "log": [nearest_version, ""]
+    }
+    getAvailableAgentPackageVersions_method.return_value = {"exitstatus": 0, "log": nearest_version}
+
+    result_version = setup_agent.getOptimalVersion(projectVersion)
+    self.assertTrue(findNearestAgentPackageVersion_method.called)
+    self.assertTrue(result_version["exitstatus"] == 1)
+    pass
+
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
   @patch.object(setup_agent, 'getAvailableAgentPackageVersions')
   @patch('ambari_commons.OSCheck.is_suse_family')
   @patch('ambari_commons.OSCheck.is_suse_family')
@@ -239,18 +301,31 @@ class TestSetupAgent(TestCase):
       "log": ["1.1.1.1", ""]
       "log": ["1.1.1.1", ""]
     }
     }
 
 
-    projectVersion = "1.1.1"
+    projectVersion = "1.1.2"
     result_version = setup_agent.getOptimalVersion(projectVersion)
     result_version = setup_agent.getOptimalVersion(projectVersion)
 
 
     self.assertTrue(findNearestAgentPackageVersion_method.called)
     self.assertTrue(findNearestAgentPackageVersion_method.called)
-    self.assertTrue(result_version["exitstatus"] == 1)
+    self.assertEqual(result_version["exitstatus"], 1)
     pass
     pass
 
 
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(subprocess, 'Popen')
   @patch.object(subprocess, 'Popen')
   def test_execOsCommand(self, Popen_mock):
   def test_execOsCommand(self, Popen_mock):
     self.assertFalse(setup_agent.execOsCommand("hostname -f") == None)
     self.assertFalse(setup_agent.execOsCommand("hostname -f") == None)
 
 
+  @only_for_platform(PLATFORM_WINDOWS)
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch.object(subprocess, 'Popen')
+  def test_execOsCommand(self, Popen_mock):
+    p = MagicMock()
+    p.communicate.return_value = ("", "")
+    p.returncode = 0
+    Popen_mock.return_value = p
+    retval = setup_agent.execOsCommand("hostname -f")
+    self.assertEqual(retval["exitstatus"], 0)
+    pass
+
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(setup_agent, 'checkVerbose')
   @patch.object(setup_agent, 'checkVerbose')
   @patch.object(setup_agent, 'isAgentPackageAlreadyInstalled')
   @patch.object(setup_agent, 'isAgentPackageAlreadyInstalled')

+ 4 - 1
ambari-server/src/test/python/TestUtils.py

@@ -20,11 +20,14 @@ import StringIO
 import sys
 import sys
 from unittest import TestCase
 from unittest import TestCase
 from mock.mock import patch, MagicMock
 from mock.mock import patch, MagicMock
+from only_for_platform import not_for_platform, PLATFORM_WINDOWS
+
 from ambari_commons.os_check import OSCheck, OSConst
 from ambari_commons.os_check import OSCheck, OSConst
 
 
 utils = __import__('ambari_server.utils').utils
 utils = __import__('ambari_server.utils').utils
 
 
 
 
+@not_for_platform(PLATFORM_WINDOWS)
 class TestUtils(TestCase):
 class TestUtils(TestCase):
 
 
   @patch.object(OSCheck, "get_os_family")
   @patch.object(OSCheck, "get_os_family")
@@ -36,7 +39,7 @@ class TestUtils(TestCase):
     os_listdir_mock.return_value = ['8.4', '9.1']
     os_listdir_mock.return_value = ['8.4', '9.1']
 
 
     self.assertEqual('9.1', utils.get_ubuntu_pg_version())
     self.assertEqual('9.1', utils.get_ubuntu_pg_version())
-    
+
   @patch.object(OSCheck, "is_suse_family")
   @patch.object(OSCheck, "is_suse_family")
   @patch.object(OSCheck, "is_ubuntu_family")
   @patch.object(OSCheck, "is_ubuntu_family")
   @patch.object(OSCheck, "is_redhat_family")
   @patch.object(OSCheck, "is_redhat_family")

+ 1 - 0
ambari-server/src/test/python/TestValidateConfigs.py

@@ -26,6 +26,7 @@ if get_platform() != PLATFORM_WINDOWS:
   from validate_configs import ValidateConfigs
   from validate_configs import ValidateConfigs
 
 
 
 
+@not_for_platform(PLATFORM_WINDOWS)
 class TestValidateConfigs(TestCase):
 class TestValidateConfigs(TestCase):
 
 
   @patch("os.geteuid")
   @patch("os.geteuid")

+ 59 - 7
ambari-server/src/test/python/custom_actions/TestCheckHost.py

@@ -31,14 +31,12 @@ from unittest import TestCase
 
 
 from check_host import CheckHost
 from check_host import CheckHost
 
 
-from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
-from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler
+from only_for_platform import get_platform, not_for_platform, only_for_platform, os_distro_value, PLATFORM_WINDOWS
 
 
-from only_for_platform import get_platform, not_for_platform, only_for_platform, os_distro_value, PLATFORM_LINUX, PLATFORM_WINDOWS
+from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler
 
 
 
 
 @patch.object(HostCheckReportFileHandler, "writeHostChecksCustomActionsFile", new=MagicMock())
 @patch.object(HostCheckReportFileHandler, "writeHostChecksCustomActionsFile", new=MagicMock())
-@patch.object(HostCheckReportFileHandler, "resolve_ambari_config", new=MagicMock())
 class TestCheckHost(TestCase):
 class TestCheckHost(TestCase):
   current_dir = os.path.dirname(os.path.realpath(__file__))
   current_dir = os.path.dirname(os.path.realpath(__file__))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@@ -172,6 +170,7 @@ class TestCheckHost(TestCase):
     checkHost.actionexecute(None)
     checkHost.actionexecute(None)
     self.assertEquals(structured_out_mock.call_args[0][0], {'db_connection_check': {'message': 'Custom java is not ' \
     self.assertEquals(structured_out_mock.call_args[0][0], {'db_connection_check': {'message': 'Custom java is not ' \
             'available on host. Please install it. Java home should be the same as on server. \n', 'exit_code': 1}})
             'available on host. Please install it. Java home should be the same as on server. \n', 'exit_code': 1}})
+    pass
 
 
 
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@@ -214,6 +213,7 @@ class TestCheckHost(TestCase):
                     {'cause': (), 'host': u'!!!', 'type': 'FORWARD_LOOKUP'}], 
                     {'cause': (), 'host': u'!!!', 'type': 'FORWARD_LOOKUP'}], 
        'message': 'There were 5 host(s) that could not resolve to an IP address.', 
        'message': 'There were 5 host(s) that could not resolve to an IP address.', 
        'failed_count': 5, 'success_count': 0, 'exit_code': 0}})
        'failed_count': 5, 'success_count': 0, 'exit_code': 0}})
+    pass
 
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(Script, 'get_config')
   @patch.object(Script, 'get_config')
@@ -234,8 +234,10 @@ class TestCheckHost(TestCase):
     # ensure the correct function was called
     # ensure the correct function was called
     self.assertTrue(structured_out_mock.called)
     self.assertTrue(structured_out_mock.called)
     structured_out_mock.assert_called_with({})
     structured_out_mock.assert_called_with({})
+    pass
 
 
 
 
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("platform.system")
   @patch("platform.system")
   @patch.object(Script, 'get_config')
   @patch.object(Script, 'get_config')
@@ -288,6 +290,59 @@ class TestCheckHost(TestCase):
 
 
     #ensure the correct response is returned
     #ensure the correct response is returned
     put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test exception', 'exit_code': 1}})
     put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test exception', 'exit_code': 1}})
+    pass
+
+  @only_for_platform(PLATFORM_WINDOWS)
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch("platform.system")
+  @patch.object(Script, 'get_config')
+  @patch.object(Script, 'get_tmp_dir')
+  @patch('resource_management.libraries.script.Script.put_structured_out')
+  @patch('ambari_agent.HostInfo.HostInfoWindows.javaProcs')
+  @patch('ambari_agent.HostInfo.HostInfoWindows.checkLiveServices')
+  @patch('ambari_agent.HostInfo.HostInfoWindows.getUMask')
+  @patch('ambari_agent.HostInfo.HostInfoWindows.checkFirewall')
+  @patch('ambari_agent.HostInfo.HostInfoWindows.checkReverseLookup')
+  @patch('time.time')
+  def testLastAgentEnv(self, time_mock, checkReverseLookup_mock, checkFirewall_mock,
+                       getUMask_mock, checkLiveServices_mock, javaProcs_mock, put_structured_out_mock,
+                       get_tmp_dir_mock, get_config_mock, systemmock):
+    jsonFilePath = os.path.join(TestCheckHost.current_dir, "..", "..", "resources", "custom_actions", "check_last_agent_env.json")
+    with open(jsonFilePath, "r") as jsonFile:
+      jsonPayload = json.load(jsonFile)
+
+    get_config_mock.return_value = ConfigDictionary(jsonPayload)
+    get_tmp_dir_mock.return_value = "/tmp"
+
+    checkHost = CheckHost()
+    checkHost.actionexecute(None)
+
+    # ensure the correct function was called
+    self.assertTrue(time_mock.called)
+    self.assertTrue(checkReverseLookup_mock.called)
+    self.assertTrue(checkFirewall_mock.called)
+    self.assertTrue(getUMask_mock.called)
+    self.assertTrue(checkLiveServices_mock.called)
+    self.assertTrue(javaProcs_mock.called)
+    self.assertTrue(put_structured_out_mock.called)
+    # ensure the correct keys are in the result map
+    last_agent_env_check_result = put_structured_out_mock.call_args[0][0]
+    self.assertTrue('last_agent_env_check' in last_agent_env_check_result)
+    self.assertTrue('hostHealth' in last_agent_env_check_result['last_agent_env_check'])
+    self.assertTrue('firewallRunning' in last_agent_env_check_result['last_agent_env_check'])
+    self.assertTrue('firewallName' in last_agent_env_check_result['last_agent_env_check'])
+    self.assertTrue('alternatives' in last_agent_env_check_result['last_agent_env_check'])
+    self.assertTrue('umask' in last_agent_env_check_result['last_agent_env_check'])
+    self.assertTrue('stackFoldersAndFiles' in last_agent_env_check_result['last_agent_env_check'])
+    self.assertTrue('existingUsers' in last_agent_env_check_result['last_agent_env_check'])
+
+    # try it now with errors
+    javaProcs_mock.side_effect = Exception("test exception")
+    checkHost.actionexecute(None)
+
+    #ensure the correct response is returned
+    put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test exception', 'exit_code': 1}})
+    pass
 
 
 
 
   @patch("resource_management.libraries.script.Script.put_structured_out")
   @patch("resource_management.libraries.script.Script.put_structured_out")
@@ -324,6 +379,3 @@ class TestCheckHost(TestCase):
 
 
 
 
 
 
-
-
-

+ 1 - 0
ambari-server/src/test/python/custom_actions/TestInstallPackages.py

@@ -44,6 +44,7 @@ subproc_mock.return_value = MagicMock()
 subproc_stdout = MagicMock()
 subproc_stdout = MagicMock()
 subproc_mock.return_value.stdout = subproc_stdout
 subproc_mock.return_value.stdout = subproc_stdout
 
 
+@not_for_platform(PLATFORM_WINDOWS)
 @patch.object(os, "read", new=MagicMock(return_value=None))
 @patch.object(os, "read", new=MagicMock(return_value=None))
 @patch.object(select, "select", new=MagicMock(return_value=([subproc_stdout], None, None)))
 @patch.object(select, "select", new=MagicMock(return_value=([subproc_stdout], None, None)))
 @patch("pty.openpty", new = MagicMock(return_value=(1,5)))
 @patch("pty.openpty", new = MagicMock(return_value=(1,5)))

+ 35 - 6
ambari-server/src/test/python/custom_actions/test_ru_execute_tasks.py

@@ -21,18 +21,21 @@ limitations under the License.
 # Python Imports
 # Python Imports
 import os
 import os
 import json
 import json
+from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
 
 
 from mock.mock import patch
 from mock.mock import patch
 from mock.mock import MagicMock
 from mock.mock import MagicMock
 
 
 # Module imports
 # Module imports
 from stacks.utils.RMFTestCase import *
 from stacks.utils.RMFTestCase import *
+from only_for_platform import not_for_platform, only_for_platform, os_distro_value, PLATFORM_WINDOWS
+
 from resource_management import Script, ConfigDictionary
 from resource_management import Script, ConfigDictionary
 from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.default import default
 from resource_management.core.logger import Logger
 from resource_management.core.logger import Logger
 from ambari_agent.AmbariConfig import AmbariConfig
 from ambari_agent.AmbariConfig import AmbariConfig
 from ambari_agent.FileCache import FileCache
 from ambari_agent.FileCache import FileCache
-from ambari_commons.os_check import OSCheck
+from ambari_commons.os_check import OSCheck, OSConst
 
 
 
 
 def fake_call(command, **kwargs):
 def fake_call(command, **kwargs):
@@ -46,8 +49,9 @@ def fake_call(command, **kwargs):
 
 
 class TestRUExecuteTasks(RMFTestCase):
 class TestRUExecuteTasks(RMFTestCase):
   def get_custom_actions_dir(self):
   def get_custom_actions_dir(self):
-    return os.path.join(self.get_src_folder(), "test/resources/custom_actions/")
+    return os.path.normpath(os.path.join(self.get_src_folder(), "test", "resources", "custom_actions"))
   
   
+  @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
   @patch.object(Logger, "info")
   @patch.object(Logger, "info")
   @patch.object(Logger, "error")
   @patch.object(Logger, "error")
   @patch.object(OSCheck, "get_os_type")
   @patch.object(OSCheck, "get_os_type")
@@ -55,6 +59,25 @@ class TestRUExecuteTasks(RMFTestCase):
     # Must patch the logger and get_os_type function.
     # Must patch the logger and get_os_type function.
     os_type_mock.return_value = "redhat"
     os_type_mock.return_value = "redhat"
 
 
+    self.CACHE_MOCK_DIR = "/var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package"
+    self.AGENT_INI_FILE_PATH = os.path.normpath(os.path.join(self.get_src_folder(), "../../ambari-agent/conf/unix/ambari-agent.ini"))
+
+    self.osIndependentSetUp()
+
+  @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
+  @patch.object(Logger, "info")
+  @patch.object(Logger, "error")
+  @patch.object(OSCheck, "get_os_type")
+  def setUp(self, os_type_mock, error_mock, info_mock):
+    # Must patch the logger and get_os_type function.
+    os_type_mock.return_value = "Windows"
+
+    self.CACHE_MOCK_DIR = "/var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package"
+    self.AGENT_INI_FILE_PATH = os.path.normpath(os.path.join(self.get_src_folder(), "..", "..", "ambari-agent", "conf", "windows", "ambari-agent.ini"))
+
+    self.osIndependentSetUp()
+
+  def osIndependentSetUp(self):
     Logger.logger = MagicMock()
     Logger.logger = MagicMock()
 
 
     # Import the class under test. This is done here as opposed to the rest of the imports because the get_os_type()
     # Import the class under test. This is done here as opposed to the rest of the imports because the get_os_type()
@@ -80,10 +103,11 @@ class TestRUExecuteTasks(RMFTestCase):
 
 
     config_dict = ConfigDictionary(json_payload)
     config_dict = ConfigDictionary(json_payload)
 
 
-    cache_mock.return_value = "/var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package"
+    cache_mock.return_value = self.CACHE_MOCK_DIR
     get_config_mock.return_value = config_dict
     get_config_mock.return_value = config_dict
     get_tmp_dir_mock.return_value = "/tmp"
     get_tmp_dir_mock.return_value = "/tmp"
-    ambari_agent_ini_file_path = os.path.join(self.get_src_folder(), "../../ambari-agent/conf/unix/ambari-agent.ini")
+
+    ambari_agent_ini_file_path = self.AGENT_INI_FILE_PATH
     self.assertTrue(os.path.isfile(ambari_agent_ini_file_path))
     self.assertTrue(os.path.isfile(ambari_agent_ini_file_path))
     get_config_file_mock.return_value = ambari_agent_ini_file_path
     get_config_file_mock.return_value = ambari_agent_ini_file_path
 
 
@@ -104,7 +128,10 @@ class TestRUExecuteTasks(RMFTestCase):
     ru_execute = ExecuteUpgradeTasks()
     ru_execute = ExecuteUpgradeTasks()
     ru_execute.actionexecute(None)
     ru_execute.actionexecute(None)
 
 
-    call_mock.assert_called_with("/usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package/scripts/namenode.py prepare_rolling_upgrade /tmp", logoutput=True, quiet=True)
+    call_mock.assert_called_with(
+        "/usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/common-services/HDFS/2.1.0.2.0/package" + os.sep +
+        "scripts/namenode.py prepare_rolling_upgrade /tmp", logoutput=True, quiet=True)
+    pass
 
 
   @patch("resource_management.core.shell.checked_call")
   @patch("resource_management.core.shell.checked_call")
   @patch("os.path.exists")
   @patch("os.path.exists")
@@ -149,4 +176,6 @@ class TestRUExecuteTasks(RMFTestCase):
     ru_execute = ExecuteUpgradeTasks()
     ru_execute = ExecuteUpgradeTasks()
     ru_execute.actionexecute(None)
     ru_execute.actionexecute(None)
 
 
-    call_mock.assert_called_with("/usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/custom_actions/scripts/namenode.py prepare_rolling_upgrade /tmp", logoutput=True, quiet=True)
+    call_mock.assert_called_with("/usr/bin/ambari-python-wrap /var/lib/ambari-agent/cache/custom_actions" + os.sep +
+                                 "scripts/namenode.py prepare_rolling_upgrade /tmp", logoutput=True, quiet=True)
+    pass

+ 5 - 1
ambari-server/src/test/python/unitTests.py

@@ -258,7 +258,11 @@ def main():
   sys.stderr.write("Total errors:{0}\n".format(len(test_errors)))
   sys.stderr.write("Total errors:{0}\n".format(len(test_errors)))
   sys.stderr.write("Total failures:{0}\n".format(len(test_failures)))
   sys.stderr.write("Total failures:{0}\n".format(len(test_failures)))
 
 
-  shutil.rmtree(newtmpdirpath)
+  try:
+    shutil.rmtree(newtmpdirpath)
+  except:
+    #Swallow the errors, nothing to do if the dir is being held by a dangling process
+    pass
   tempfile.tempdir = oldtmpdirpath
   tempfile.tempdir = oldtmpdirpath
   tempfile.oldtmpdirpath = None
   tempfile.oldtmpdirpath = None
 
 

Vissa filer visades inte eftersom för många filer har ändrats