AMBARI-12465. Non-Root: Knox fails to start during install with custom pid 
directory (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8b218693
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8b218693
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8b218693

Branch: refs/heads/branch-2.1
Commit: 8b218693754d5b51fca39c7e53191e92caee7654
Parents: 6ce4214
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Tue Jul 21 12:45:13 2015 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Tue Jul 21 12:45:13 2015 +0300

----------------------------------------------------------------------
 .../KNOX/0.5.0.2.2/package/scripts/knox_gateway.py     | 13 ++++++++-----
 .../test/python/stacks/2.2/KNOX/test_knox_gateway.py   | 10 ++++------
 2 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8b218693/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/knox_gateway.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/knox_gateway.py
 
b/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/knox_gateway.py
index 8117312..7323a73 100644
--- 
a/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/knox_gateway.py
+++ 
b/ambari-server/src/main/resources/common-services/KNOX/0.5.0.2.2/package/scripts/knox_gateway.py
@@ -32,7 +32,7 @@ from resource_management.libraries.functions import Direction
 from resource_management.libraries.functions.security_commons import 
build_expectations, \
   cached_kinit_executor, validate_security_config_properties, 
get_params_from_filesystem, \
   FILE_TYPE_XML
-from resource_management.core.resources.system import File, Execute, Directory
+from resource_management.core.resources.system import File, Execute, 
Directory, Link
 from resource_management.core.resources.service import Service
 from resource_management.core.logger import Logger
 
@@ -148,9 +148,10 @@ class KnoxGatewayDefault(KnoxGateway):
     no_op_test = format('ls {knox_pid_file} >/dev/null 2>&1 && ps -p `cat 
{knox_pid_file}` >/dev/null 2>&1')
     setup_ranger_knox(rolling_upgrade=rolling_restart)
     # Used to setup symlink, needed to update the knox managed symlink, in 
case of custom locations
-    if os.path.islink(params.knox_managed_pid_symlink) and 
os.path.realpath(params.knox_managed_pid_symlink) != params.knox_pid_dir:
-      os.unlink(params.knox_managed_pid_symlink)
-      os.symlink(params.knox_pid_dir, params.knox_managed_pid_symlink)
+    if os.path.islink(params.knox_managed_pid_symlink):
+      Link(params.knox_managed_pid_symlink,
+           to = params.knox_pid_dir,
+      )
 
     Execute(daemon_cmd,
             user=params.knox_user,
@@ -196,7 +197,9 @@ class KnoxGatewayDefault(KnoxGateway):
             environment={'JAVA_HOME': params.java_home},
             user=params.knox_user,
             )
-    Execute (format("rm -f {ldap_pid_file}"))
+    File(params.ldap_pid_file,
+      action = "delete"
+    )
 
   def security_status(self, env):
     import status_params

http://git-wip-us.apache.org/repos/asf/ambari/blob/8b218693/ambari-server/src/test/python/stacks/2.2/KNOX/test_knox_gateway.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.2/KNOX/test_knox_gateway.py 
b/ambari-server/src/test/python/stacks/2.2/KNOX/test_knox_gateway.py
index 5ca5251..11f476e 100644
--- a/ambari-server/src/test/python/stacks/2.2/KNOX/test_knox_gateway.py
+++ b/ambari-server/src/test/python/stacks/2.2/KNOX/test_knox_gateway.py
@@ -319,10 +319,7 @@ class TestKnoxGateway(RMFTestCase):
        mocks_dict['call'].call_args_list[0][0][0])
 
   @patch("os.path.islink")
-  @patch("os.path.realpath")
-  @patch("os.unlink")
-  @patch("os.symlink")
-  def test_start_default(self, symlink_mock, unlink_mock, realpath_mock, 
islink_mock):
+  def test_start_default(self, islink_mock):
 
 
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
"/scripts/knox_gateway.py",
@@ -409,12 +406,13 @@ class TestKnoxGateway(RMFTestCase):
                               owner = 'knox',
                               content = 
self.getConfig()['configurations']['users-ldif']['content']
     )
-
+    self.assertResourceCalled('Link', '/usr/hdp/current/knox-server/pids',
+        to = '/var/run/knox',
+    )
     self.assertResourceCalled("Execute", 
"/usr/hdp/current/knox-server/bin/gateway.sh start",
                               environment = {'JAVA_HOME': 
u'/usr/jdk64/jdk1.7.0_45'},
                               not_if = u'ls /var/run/knox/gateway.pid 
>/dev/null 2>&1 && ps -p `cat /var/run/knox/gateway.pid` >/dev/null 2>&1',
                               user = u'knox',)
     self.assertTrue(islink_mock.called)
-    self.assertTrue(realpath_mock.called)
     self.assertNoMoreResources()
 

Reply via email to