From 836de93669fad67bbf51db00f4320180c30a929d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henar=20Mu=C3=B1oz=20Frutos?= Date: Thu, 16 Apr 2015 10:07:54 +0200 Subject: [PATCH] Folder Not Found with Git Downloadable File When there is a downloadable type file which is a git repository, a folder not found error appears: No such file or directory Also updated unit tests to work on Windows Closes Bug: #1444862 Change-Id: I5ebb01b8d2c324e4e603a90142433b2abbbd62a2 --- muranoagent/files_manager.py | 24 +++++++++++++++----- muranoagent/tests/unit/test_files_manager.py | 10 ++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/muranoagent/files_manager.py b/muranoagent/files_manager.py index abe43b29..edf174e7 100644 --- a/muranoagent/files_manager.py +++ b/muranoagent/files_manager.py @@ -18,13 +18,13 @@ import git import os import requests import shutil -import subprocess import urlparse from muranoagent.common import config - +from muranoagent.openstack.common import log as logging CONF = config.CONF +LOG = logging.getLogger(__name__) class FilesManager(object): @@ -104,11 +104,23 @@ class FilesManager(object): folder = self._get_file_folder(url_file, file_def['Name']) - if self._is_git_repository(url_file): - if not os.path.isdir(folder): + if not os.path.isdir(folder): + os.makedirs(folder) + + try: + if self._is_git_repository(url_file): git.Git().clone(url_file, folder) - else: - self._download_file(url_file, folder) + else: + self._download_file(url_file, folder) + except Exception as e: + if self._is_git_repository(url_file): + mns = ("Error to clone the git repository {0}: {1}". + format(url_file, e.message)) + else: + mns = ("Error to download the file {0}: {1}". + format(url_file, e.message)) + LOG.warn(mns) + raise ValueError(mns) def clear(self): shutil.rmtree(self._cache_folder, ignore_errors=True) diff --git a/muranoagent/tests/unit/test_files_manager.py b/muranoagent/tests/unit/test_files_manager.py index 9ebdaded..da2bae7d 100644 --- a/muranoagent/tests/unit/test_files_manager.py +++ b/muranoagent/tests/unit/test_files_manager.py @@ -13,8 +13,8 @@ # under the License. import bunch -import git import mock +import os.path from muranoagent.common import config as cfg from muranoagent import files_manager @@ -41,7 +41,8 @@ class TestFileManager(base.MuranoAgentTestCase): mock_path.return_value = None files = files_manager.FilesManager(self.get_template_downloable()) folder = files._get_file_folder("http://tomcat.git", "tomcat") - self.assertEqual(folder, "cache/files/ID/files/tomcat") + self.assertEqual(folder, + os.path.normpath("cache/files/ID/files/tomcat")) @mock.patch('os.makedirs') def test_get_folder_not_git(self, mock_path): @@ -49,7 +50,8 @@ class TestFileManager(base.MuranoAgentTestCase): mock_path.return_value = None files = files_manager.FilesManager(self.get_template_downloable()) folder = files._get_file_folder("http://tomcat", "tomcat") - self.assertEqual(folder, "cache/files/ID/files/tomcat") + self.assertEqual(folder, + os.path.normpath("cache/files/ID/files/tomcat")) @mock.patch("git.Git") @mock.patch('os.path.isdir') @@ -107,7 +109,7 @@ class TestFileManager(base.MuranoAgentTestCase): @mock.patch("git.Git") @mock.patch('os.path.isdir') @mock.patch('os.makedirs') - def test_putfile_downloable(self, mock_makedir, mock_git, path): + def test_putfile_downloable(self, mock_makedir, path, mock_git): """It tests the putfile method when the file is a git URL. """