Make set_configs.py work with symlinks
Closes-Bug: #1702305 Change-Id: I92a404b8d301937dc1847d42576e30db43951990
This commit is contained in:
parent
db38eef3ae
commit
f54f340630
@ -75,12 +75,16 @@ class ConfigFile(object):
|
|||||||
self._delete_path(dest)
|
self._delete_path(dest)
|
||||||
# dest endswith / means copy the <source> to <dest> folder
|
# dest endswith / means copy the <source> to <dest> folder
|
||||||
LOG.info('Copying %s to %s', source, dest)
|
LOG.info('Copying %s to %s', source, dest)
|
||||||
shutil.copy(source, dest)
|
if os.path.islink(source):
|
||||||
self._set_properties(source, dest)
|
link_target = os.readlink(source)
|
||||||
|
os.symlink(link_target, dest)
|
||||||
|
else:
|
||||||
|
shutil.copy(source, dest)
|
||||||
|
self._set_properties(source, dest)
|
||||||
|
|
||||||
def _merge_directories(self, source, dest):
|
def _merge_directories(self, source, dest):
|
||||||
if os.path.isdir(source):
|
if os.path.isdir(source):
|
||||||
if os.path.exists(dest) and not os.path.isdir(dest):
|
if os.path.lexists(dest) and not os.path.isdir(dest):
|
||||||
self._delete_path(dest)
|
self._delete_path(dest)
|
||||||
if not os.path.isdir(dest):
|
if not os.path.isdir(dest):
|
||||||
LOG.info('Creating directory %s', dest)
|
LOG.info('Creating directory %s', dest)
|
||||||
@ -95,7 +99,7 @@ class ConfigFile(object):
|
|||||||
self._copy_file(source, dest)
|
self._copy_file(source, dest)
|
||||||
|
|
||||||
def _delete_path(self, path):
|
def _delete_path(self, path):
|
||||||
if not os.path.exists(path):
|
if not os.path.lexists(path):
|
||||||
return
|
return
|
||||||
LOG.info('Deleting %s', path)
|
LOG.info('Deleting %s', path)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
|
@ -77,41 +77,41 @@ FAKE_CONFIG_FILE = FAKE_CONFIG_FILES[0]
|
|||||||
|
|
||||||
class ConfigFileTest(base.BaseTestCase):
|
class ConfigFileTest(base.BaseTestCase):
|
||||||
|
|
||||||
@mock.patch('os.path.exists', return_value=False)
|
@mock.patch('os.path.lexists', return_value=False)
|
||||||
def test_delete_path_not_exists(self, mock_exists):
|
def test_delete_path_not_exists(self, mock_lexists):
|
||||||
|
|
||||||
config_file = copy.deepcopy(FAKE_CONFIG_FILE)
|
config_file = copy.deepcopy(FAKE_CONFIG_FILE)
|
||||||
config_file._delete_path(config_file.dest)
|
config_file._delete_path(config_file.dest)
|
||||||
|
|
||||||
mock_exists.assert_called_with(config_file.dest)
|
mock_lexists.assert_called_with(config_file.dest)
|
||||||
|
|
||||||
@mock.patch('os.path.exists', return_value=True)
|
@mock.patch('os.path.lexists', return_value=True)
|
||||||
@mock.patch('os.path.isdir', return_value=True)
|
@mock.patch('os.path.isdir', return_value=True)
|
||||||
@mock.patch('shutil.rmtree')
|
@mock.patch('shutil.rmtree')
|
||||||
def test_delete_path_exist_dir(self,
|
def test_delete_path_exist_dir(self,
|
||||||
mock_rmtree,
|
mock_rmtree,
|
||||||
mock_isdir,
|
mock_isdir,
|
||||||
mock_exists):
|
mock_lexists):
|
||||||
|
|
||||||
config_file = copy.deepcopy(FAKE_CONFIG_FILE)
|
config_file = copy.deepcopy(FAKE_CONFIG_FILE)
|
||||||
config_file._delete_path(config_file.dest)
|
config_file._delete_path(config_file.dest)
|
||||||
|
|
||||||
mock_exists.assert_called_with(config_file.dest)
|
mock_lexists.assert_called_with(config_file.dest)
|
||||||
mock_isdir.assert_called_with(config_file.dest)
|
mock_isdir.assert_called_with(config_file.dest)
|
||||||
mock_rmtree.assert_called_with(config_file.dest)
|
mock_rmtree.assert_called_with(config_file.dest)
|
||||||
|
|
||||||
@mock.patch('os.path.exists', return_value=True)
|
@mock.patch('os.path.lexists', return_value=True)
|
||||||
@mock.patch('os.path.isdir', return_value=False)
|
@mock.patch('os.path.isdir', return_value=False)
|
||||||
@mock.patch('os.remove')
|
@mock.patch('os.remove')
|
||||||
def test_delete_path_exist_file(self,
|
def test_delete_path_exist_file(self,
|
||||||
mock_remove,
|
mock_remove,
|
||||||
mock_isdir,
|
mock_isdir,
|
||||||
mock_exists):
|
mock_lexists):
|
||||||
|
|
||||||
config_file = copy.deepcopy(FAKE_CONFIG_FILE)
|
config_file = copy.deepcopy(FAKE_CONFIG_FILE)
|
||||||
config_file._delete_path(config_file.dest)
|
config_file._delete_path(config_file.dest)
|
||||||
|
|
||||||
mock_exists.assert_called_with(config_file.dest)
|
mock_lexists.assert_called_with(config_file.dest)
|
||||||
mock_isdir.assert_called_with(config_file.dest)
|
mock_isdir.assert_called_with(config_file.dest)
|
||||||
mock_remove.assert_called_with(config_file.dest)
|
mock_remove.assert_called_with(config_file.dest)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user