|
@@ -26,6 +26,7 @@ from mock.mock import patch
|
|
from mock.mock import MagicMock
|
|
from mock.mock import MagicMock
|
|
|
|
|
|
# Module imports
|
|
# Module imports
|
|
|
|
+import subprocess
|
|
from stacks.utils.RMFTestCase import *
|
|
from stacks.utils.RMFTestCase import *
|
|
from resource_management import Script, ConfigDictionary
|
|
from resource_management import Script, ConfigDictionary
|
|
from resource_management.libraries.functions.default import default
|
|
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.AmbariConfig import AmbariConfig
|
|
from ambari_agent.FileCache import FileCache
|
|
from ambari_agent.FileCache import FileCache
|
|
from ambari_commons.os_check import OSCheck
|
|
from ambari_commons.os_check import OSCheck
|
|
|
|
+from resource_management.core import shell
|
|
|
|
+import pprint
|
|
|
|
|
|
|
|
|
|
def fake_call(command, **kwargs):
|
|
def fake_call(command, **kwargs):
|
|
@@ -133,15 +136,19 @@ class TestRUSetAll(RMFTestCase):
|
|
|
|
|
|
|
|
|
|
@patch("os.path.islink")
|
|
@patch("os.path.islink")
|
|
|
|
+ @patch("os.path.isdir")
|
|
@patch("resource_management.core.shell.call")
|
|
@patch("resource_management.core.shell.call")
|
|
@patch.object(Script, 'get_config')
|
|
@patch.object(Script, 'get_config')
|
|
@patch.object(OSCheck, 'is_redhat_family')
|
|
@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
|
|
Tests downgrading from 2.3 to 2.2 to ensure that conf symlinks are removed and the backup
|
|
directories restored.
|
|
directories restored.
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+ isdir_mock.return_value = True
|
|
|
|
+
|
|
# required for the test to run since the Execute calls need this
|
|
# required for the test to run since the Execute calls need this
|
|
from resource_management.core.environment import Environment
|
|
from resource_management.core.environment import Environment
|
|
env = Environment(test_mode=True)
|
|
env = Environment(test_mode=True)
|
|
@@ -237,3 +244,37 @@ class TestRUSetAll(RMFTestCase):
|
|
|
|
|
|
# ensure it wasn't called this time
|
|
# ensure it wasn't called this time
|
|
self.assertFalse(islink_mock.called)
|
|
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')]]")
|
|
|
|
+
|
|
|
|
+
|