Browse Source

AMBARI-11206 [WinTP2] Ambari Agent fails to start

Reinstated the Windows-specific read_file()
Florian Barca 10 years ago
parent
commit
a01d92b18c

+ 8 - 0
ambari-common/src/main/python/resource_management/core/source.py

@@ -33,6 +33,8 @@ import time
 import urllib2
 import urlparse
 
+from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
+from ambari_commons import OSConst
 
 class Source(object):
   def __init__(self, name):
@@ -74,10 +76,16 @@ class StaticFile(Source):
 
     return self.read_file(path)
 
+  @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
   def read_file(self, path):
     from resource_management.core import sudo
     return sudo.read_file(path)
 
+  @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
+  def read_file(self, path):
+    with open(path, "rb") as fp:
+      return fp.read()
+
 
 try:
   from ambari_jinja2 import Environment as JinjaEnvironment, BaseLoader, TemplateNotFound, FunctionLoader, StrictUndefined

+ 1 - 1
ambari-common/src/main/python/resource_management/core/sudo.py

@@ -29,7 +29,7 @@ from resource_management.core.utils import _coerce_uid
 from resource_management.core.utils import _coerce_gid
 from ambari_commons.os_check import OSCheck
 
-if os.geteuid() == 0 or OSCheck.is_windows_family():
+if os.geteuid() == 0:
   def chown(path, owner, group):
     return os.chown(path, _coerce_uid(owner) if owner else -1, _coerce_gid(group) if group else -1)