You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2015/10/26 19:18:25 UTC
[1/2] ambari git commit: AMBARI-13568. RU - Downgrade from 2.3 to 2.2
may fail if configs were not back'ed up (dlysnichenko)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1 4a4d8d09e -> ce417eb1d
refs/heads/trunk 66b1c2717 -> 6d662b17a
AMBARI-13568. RU - Downgrade from 2.3 to 2.2 may fail if configs were not back'ed up (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6d662b17
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6d662b17
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6d662b17
Branch: refs/heads/trunk
Commit: 6d662b17a7e88799e01c4b8d8cd27732a11758bd
Parents: 66b1c27
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Mon Oct 26 20:16:48 2015 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Mon Oct 26 20:16:48 2015 +0200
----------------------------------------------------------------------
.../custom_actions/scripts/ru_set_all.py | 22 +++++-----
.../python/custom_actions/test_ru_set_all.py | 43 +++++++++++++++++++-
2 files changed, 52 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d662b17/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py b/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
index c4660a7..7bfd820 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
@@ -128,21 +128,19 @@ class UpgradeSetAll(Script):
:original_conf_directory: the original conf directory that was made into a symlink (/etc/component/conf)
"""
- if not os.path.islink(original_conf_directory):
- Logger.info("Skipping the unlink of {0}; it is not a symlink or does not exist".format(original_conf_directory))
- return
-
# calculate the parent and backup directories
original_conf_parent_directory = os.path.abspath(os.path.join(original_conf_directory, os.pardir))
backup_conf_directory = os.path.join(original_conf_parent_directory, "conf.backup")
-
- Logger.info("Unlinking {0} and restoring {1}".format(original_conf_directory, backup_conf_directory))
-
- # remove the old symlink
- Execute(("rm", original_conf_directory), sudo=True)
-
- # rename the backup to the original name
- Execute(("mv", backup_conf_directory, original_conf_directory), sudo=True)
+ if not os.path.isdir(backup_conf_directory):
+ Logger.info("Skipping restoring config from backup {0} since it does not exist".format(backup_conf_directory))
+ elif not os.path.islink(original_conf_directory):
+ Logger.info("Skipping the unlink of {0}; it is not a symlink or does not exist".format(original_conf_directory))
+ else:
+ Logger.info("Unlinking {0} and restoring {1}".format(original_conf_directory, backup_conf_directory))
+ # remove the old symlink
+ Execute(("rm", original_conf_directory), sudo=True)
+ # rename the backup to the original name
+ Execute(("mv", backup_conf_directory, original_conf_directory), sudo=True)
def link_config(old_conf, link_conf):
http://git-wip-us.apache.org/repos/asf/ambari/blob/6d662b17/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/test_ru_set_all.py b/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
index 2f74619..162a2fd 100644
--- a/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
+++ b/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
@@ -26,6 +26,7 @@ from mock.mock import patch
from mock.mock import MagicMock
# Module imports
+import subprocess
from stacks.utils.RMFTestCase import *
from resource_management import Script, ConfigDictionary
from resource_management.libraries.functions.default import default
@@ -34,6 +35,8 @@ from resource_management.core.logger import Logger
from ambari_agent.AmbariConfig import AmbariConfig
from ambari_agent.FileCache import FileCache
from ambari_commons.os_check import OSCheck
+from resource_management.core import shell
+import pprint
def fake_call(command, **kwargs):
@@ -133,15 +136,19 @@ class TestRUSetAll(RMFTestCase):
@patch("os.path.islink")
+ @patch("os.path.isdir")
@patch("resource_management.core.shell.call")
@patch.object(Script, 'get_config')
@patch.object(OSCheck, 'is_redhat_family')
- def test_downgrade_unlink_configs(self, family_mock, get_config_mock, call_mock, islink_mock):
+ def test_downgrade_unlink_configs(self, family_mock, get_config_mock, call_mock,
+ isdir_mock, islink_mock):
"""
Tests downgrading from 2.3 to 2.2 to ensure that conf symlinks are removed and the backup
directories restored.
"""
+ isdir_mock.return_value = True
+
# required for the test to run since the Execute calls need this
from resource_management.core.environment import Environment
env = Environment(test_mode=True)
@@ -237,3 +244,37 @@ class TestRUSetAll(RMFTestCase):
# ensure it wasn't called this time
self.assertFalse(islink_mock.called)
+
+
+ @patch("os.path.isdir")
+ @patch("os.path.islink")
+ def test_unlink_configs_missing_backup(self, islink_mock, isdir_mock):
+
+ # required for the test to run since the Execute calls need this
+ from resource_management.core.environment import Environment
+ env = Environment(test_mode=True)
+ env._instances.append(env)
+
+ # Case: missing backup directory
+ isdir_mock.return_value = False
+ ru_execute = UpgradeSetAll()
+ self.assertEqual(len(env.resource_list), 0)
+ # Case: missing symlink
+ isdir_mock.reset_mock()
+ isdir_mock.return_value = True
+ islink_mock.return_value = False
+ ru_execute._unlink_config("/fake/config")
+ self.assertEqual(len(env.resource_list), 0)
+ # Case: missing symlink
+ isdir_mock.reset_mock()
+ isdir_mock.return_value = True
+ islink_mock.reset_mock()
+ islink_mock.return_value = True
+
+ ru_execute._unlink_config("/fake/config")
+ self.assertEqual(pprint.pformat(env.resource_list),
+ "[Execute[('rm', '/fake/config')],\n"
+ " Execute[('mv', '/fake/conf.backup', "
+ "'/fake/config')]]")
+
+
[2/2] ambari git commit: AMBARI-13568. RU - Downgrade from 2.3 to 2.2
may fail if configs were not back'ed up (dlysnichenko)
Posted by dm...@apache.org.
AMBARI-13568. RU - Downgrade from 2.3 to 2.2 may fail if configs were not back'ed up (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ce417eb1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ce417eb1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ce417eb1
Branch: refs/heads/branch-2.1
Commit: ce417eb1d16ce968132d3bf6515b52e603e32434
Parents: 4a4d8d0
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Mon Oct 26 20:16:48 2015 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Mon Oct 26 20:18:08 2015 +0200
----------------------------------------------------------------------
.../custom_actions/scripts/ru_set_all.py | 22 +++++-----
.../python/custom_actions/test_ru_set_all.py | 43 +++++++++++++++++++-
2 files changed, 52 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ce417eb1/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py b/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
index 6e5ddd2..3ff0bc6 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/ru_set_all.py
@@ -127,21 +127,19 @@ class UpgradeSetAll(Script):
:original_conf_directory: the original conf directory that was made into a symlink (/etc/component/conf)
"""
- if not os.path.islink(original_conf_directory):
- Logger.info("Skipping the unlink of {0}; it is not a symlink or does not exist".format(original_conf_directory))
- return
-
# calculate the parent and backup directories
original_conf_parent_directory = os.path.abspath(os.path.join(original_conf_directory, os.pardir))
backup_conf_directory = os.path.join(original_conf_parent_directory, "conf.backup")
-
- Logger.info("Unlinking {0} and restoring {1}".format(original_conf_directory, backup_conf_directory))
-
- # remove the old symlink
- Execute(("rm", original_conf_directory), sudo=True)
-
- # rename the backup to the original name
- Execute(("mv", backup_conf_directory, original_conf_directory), sudo=True)
+ if not os.path.isdir(backup_conf_directory):
+ Logger.info("Skipping restoring config from backup {0} since it does not exist".format(backup_conf_directory))
+ elif not os.path.islink(original_conf_directory):
+ Logger.info("Skipping the unlink of {0}; it is not a symlink or does not exist".format(original_conf_directory))
+ else:
+ Logger.info("Unlinking {0} and restoring {1}".format(original_conf_directory, backup_conf_directory))
+ # remove the old symlink
+ Execute(("rm", original_conf_directory), sudo=True)
+ # rename the backup to the original name
+ Execute(("mv", backup_conf_directory, original_conf_directory), sudo=True)
def link_config(old_conf, link_conf):
http://git-wip-us.apache.org/repos/asf/ambari/blob/ce417eb1/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/test_ru_set_all.py b/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
index b102b4e..186b847 100644
--- a/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
+++ b/ambari-server/src/test/python/custom_actions/test_ru_set_all.py
@@ -26,6 +26,7 @@ from mock.mock import patch
from mock.mock import MagicMock
# Module imports
+import subprocess
from stacks.utils.RMFTestCase import *
from resource_management import Script, ConfigDictionary
from resource_management.libraries.functions.default import default
@@ -34,6 +35,8 @@ from resource_management.core.logger import Logger
from ambari_agent.AmbariConfig import AmbariConfig
from ambari_agent.FileCache import FileCache
from ambari_commons.os_check import OSCheck
+from resource_management.core import shell
+import pprint
def fake_call(command, **kwargs):
@@ -133,15 +136,19 @@ class TestRUSetAll(RMFTestCase):
@patch("os.path.islink")
+ @patch("os.path.isdir")
@patch("resource_management.core.shell.call")
@patch.object(Script, 'get_config')
@patch.object(OSCheck, 'is_redhat_family')
- def test_downgrade_unlink_configs(self, family_mock, get_config_mock, call_mock, islink_mock):
+ def test_downgrade_unlink_configs(self, family_mock, get_config_mock, call_mock,
+ isdir_mock, islink_mock):
"""
Tests downgrading from 2.3 to 2.2 to ensure that conf symlinks are removed and the backup
directories restored.
"""
+ isdir_mock.return_value = True
+
# required for the test to run since the Execute calls need this
from resource_management.core.environment import Environment
env = Environment(test_mode=True)
@@ -237,3 +244,37 @@ class TestRUSetAll(RMFTestCase):
# ensure it wasn't called this time
self.assertFalse(islink_mock.called)
+
+
+ @patch("os.path.isdir")
+ @patch("os.path.islink")
+ def test_unlink_configs_missing_backup(self, islink_mock, isdir_mock):
+
+ # required for the test to run since the Execute calls need this
+ from resource_management.core.environment import Environment
+ env = Environment(test_mode=True)
+ env._instances.append(env)
+
+ # Case: missing backup directory
+ isdir_mock.return_value = False
+ ru_execute = UpgradeSetAll()
+ self.assertEqual(len(env.resource_list), 0)
+ # Case: missing symlink
+ isdir_mock.reset_mock()
+ isdir_mock.return_value = True
+ islink_mock.return_value = False
+ ru_execute._unlink_config("/fake/config")
+ self.assertEqual(len(env.resource_list), 0)
+ # Case: missing symlink
+ isdir_mock.reset_mock()
+ isdir_mock.return_value = True
+ islink_mock.reset_mock()
+ islink_mock.return_value = True
+
+ ru_execute._unlink_config("/fake/config")
+ self.assertEqual(pprint.pformat(env.resource_list),
+ "[Execute[('rm', '/fake/config')],\n"
+ " Execute[('mv', '/fake/conf.backup', "
+ "'/fake/config')]]")
+
+