AMBARI-9696. RU - Ranger does not advertise a version (alejandro)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/225afe35 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/225afe35 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/225afe35 Branch: refs/heads/trunk Commit: 225afe35c7ef9d0cef44bcb08f6eaebcdc980202 Parents: 53b7561 Author: Alejandro Fernandez <[email protected]> Authored: Wed Feb 18 11:36:58 2015 -0800 Committer: Alejandro Fernandez <[email protected]> Committed: Fri Feb 20 14:14:20 2015 -0800 ---------------------------------------------------------------------- .../RANGER/0.4.0/package/scripts/params.py | 18 +- .../0.4.0/package/scripts/ranger_admin.py | 10 +- .../0.4.0/package/scripts/ranger_usersync.py | 9 +- .../RANGER/0.4.0/package/scripts/upgrade.py | 2 +- .../stacks/2.2/RANGER/test_ranger_admin.py | 45 + .../stacks/2.2/RANGER/test_ranger_usersync.py | 40 + .../2.2/configs/ranger-admin-upgrade.json | 1029 ++++++++++++++++++ .../2.2/configs/ranger-usersync-upgrade.json | 1029 ++++++++++++++++++ 8 files changed, 2167 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/225afe35/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py index f440ed0..d67211e 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py +++ b/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") http://git-wip-us.apache.org/repos/asf/ambari/blob/225afe35/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py index 2a36f98..9fd794c 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py +++ b/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() http://git-wip-us.apache.org/repos/asf/ambari/blob/225afe35/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py index 9cd0938..b3fe777 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_usersync.py +++ b/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() http://git-wip-us.apache.org/repos/asf/ambari/blob/225afe35/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py index e173b34..99b6edc 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/upgrade.py +++ b/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 http://git-wip-us.apache.org/repos/asf/ambari/blob/225afe35/ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_admin.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_admin.py b/ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_admin.py new file mode 100644 index 0000000..84ffa01 --- /dev/null +++ b/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") \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/225afe35/ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_usersync.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_usersync.py b/ambari-server/src/test/python/stacks/2.2/RANGER/test_ranger_usersync.py new file mode 100644 index 0000000..d25d43a --- /dev/null +++ b/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") \ No newline at end of file
