Pārlūkot izejas kodu

AMBARI-9696. RU - Ranger does not advertise a version (alejandro)

Alejandro Fernandez 10 gadi atpakaļ
vecāks
revīzija
225afe35c7

+ 9 - 9
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py

@@ -17,19 +17,21 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 """
-
+from resource_management.libraries.script import Script
 from resource_management.libraries.functions.version import format_hdp_stack_version, compare_versions
-from resource_management import *
+from resource_management.libraries.functions.format import format
+from resource_management.libraries.functions.default import default
 
 config  = Script.get_config()
 tmp_dir = Script.get_tmp_dir()
 
-hdp_stack_version         = str(config['hostLevelParams']['stack_version'])
-hdp_stack_version         = format_hdp_stack_version(hdp_stack_version)
-stack_is_hdp22_or_further = hdp_stack_version != "" and compare_versions(hdp_stack_version, '2.2') >= 0
-
-version = default("/commandParams/version", None)
 stack_name = default("/hostLevelParams/stack_name", None)
+version = default("/commandParams/version", None)
+
+stack_version_unformatted = str(config['hostLevelParams']['stack_version'])
+hdp_stack_version = format_hdp_stack_version(stack_version_unformatted)
+
+stack_is_hdp22_or_further = hdp_stack_version != "" and compare_versions(hdp_stack_version, '2.2') >= 0
 
 if stack_is_hdp22_or_further:
   ranger_home    = '/usr/hdp/current/ranger-admin'
@@ -39,8 +41,6 @@ if stack_is_hdp22_or_further:
   usersync_home  = '/usr/hdp/current/ranger-usersync'
   usersync_start = '/usr/bin/ranger-usersync-start'
   usersync_stop  = '/usr/bin/ranger-usersync-stop'
-else:
-  pass
 
 java_home = config['hostLevelParams']['java_home']
 unix_user  = default("/configurations/ranger-env/ranger_user", "ranger")

+ 7 - 3
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py

@@ -17,16 +17,20 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 """
-
-import sys
-from resource_management import *
+from resource_management.libraries.script import Script
+from resource_management.core.resources.system import Execute
 from resource_management.core.exceptions import ComponentIsNotRunning
+from resource_management.libraries.functions.format import format
 from resource_management.core.logger import Logger
 from resource_management.core import shell
 from setup_ranger import setup_ranger
 import upgrade
 
 class RangerAdmin(Script):
+
+  def get_stack_to_component(self):
+    return {"HDP": "ranger-admin"}
+
   def install(self, env):
     self.install_packages(env)
     setup_ranger()

+ 7 - 2
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py

@@ -17,15 +17,20 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 """
-import sys
-from resource_management import *
+from resource_management.libraries.script import Script
+from resource_management.core.resources.system import Execute
 from resource_management.core.exceptions import ComponentIsNotRunning
+from resource_management.libraries.functions.format import format
 from resource_management.core.logger import Logger
 from resource_management.core import shell
 from setup_ranger import setup_usersync
 import upgrade
 
 class RangerUsersync(Script):
+
+  def get_stack_to_component(self):
+    return {"HDP": "ranger-usersync"}
+
   def install(self, env):
     self.install_packages(env)
     setup_usersync()

+ 1 - 1
ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py

@@ -18,8 +18,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 """
-from resource_management import *
 from resource_management.core.resources.system import Execute
+from resource_management.libraries.functions.format import format
 
 def prestart(env, hdp_component):
   import params

+ 45 - 0
ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_admin.py

@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+'''
+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 sys
+import os
+from stacks.utils.RMFTestCase import RMFTestCase
+from mock.mock import patch
+
+
+class TestRangerAdmin(RMFTestCase):
+  COMMON_SERVICES_PACKAGE_DIR = "RANGER/0.4.0/package"
+  STACK_VERSION = "2.2"
+
+  def setUp(self):
+    sys.path.insert(0, os.path.join(os.getcwd(), "../../main/resources/common-services", self.COMMON_SERVICES_PACKAGE_DIR, "scripts"))
+
+  @patch("setup_ranger.setup_ranger")
+  def test_upgrade(self, setup_ranger_mock):
+    self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/ranger_admin.py",
+                       classname = "RangerAdmin",
+                       command = "restart",
+                       config_file="ranger-admin-upgrade.json",
+                       hdp_stack_version = self.STACK_VERSION,
+                       target = RMFTestCase.TARGET_COMMON_SERVICES)
+
+    self.assertTrue(setup_ranger_mock.called)
+    self.assertResourceCalled("Execute", "/usr/bin/ranger-admin-stop", user="ranger")
+    self.assertResourceCalled("Execute", "hdp-select set ranger-admin 2.2.2.0-2399")

+ 40 - 0
ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_usersync.py

@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+'''
+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 stacks.utils.RMFTestCase import RMFTestCase
+from mock.mock import patch
+
+
+class TestRangerUserSync(RMFTestCase):
+  COMMON_SERVICES_PACKAGE_DIR = "RANGER/0.4.0/package"
+  STACK_VERSION = "2.2"
+
+  @patch("setup_ranger.setup_usersync")
+  def test_upgrade(self, setup_usersync_mock):
+    self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/ranger_usersync.py",
+                       classname = "RangerUsersync",
+                       command = "restart",
+                       config_file="ranger-usersync-upgrade.json",
+                       hdp_stack_version = self.STACK_VERSION,
+                       target = RMFTestCase.TARGET_COMMON_SERVICES)
+
+    self.assertTrue(setup_usersync_mock.called)
+    self.assertResourceCalled("Execute", "/usr/bin/ranger-usersync-stop")
+    self.assertResourceCalled("Execute", "hdp-select set ranger-usersync 2.2.2.0-2399")

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 173 - 0
ambari-server/src/test/python/stacks/2.2/configs/ranger-admin-upgrade.json


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 173 - 0
ambari-server/src/test/python/stacks/2.2/configs/ranger-usersync-upgrade.json


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels