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
This commit is contained in:
parent
9a3ec32cc5
commit
836de93669
|
@ -18,13 +18,13 @@ import git
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from muranoagent.common import config
|
from muranoagent.common import config
|
||||||
|
from muranoagent.openstack.common import log as logging
|
||||||
|
|
||||||
CONF = config.CONF
|
CONF = config.CONF
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FilesManager(object):
|
class FilesManager(object):
|
||||||
|
@ -104,11 +104,23 @@ class FilesManager(object):
|
||||||
|
|
||||||
folder = self._get_file_folder(url_file, file_def['Name'])
|
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)
|
git.Git().clone(url_file, folder)
|
||||||
else:
|
else:
|
||||||
self._download_file(url_file, folder)
|
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):
|
def clear(self):
|
||||||
shutil.rmtree(self._cache_folder, ignore_errors=True)
|
shutil.rmtree(self._cache_folder, ignore_errors=True)
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import bunch
|
import bunch
|
||||||
import git
|
|
||||||
import mock
|
import mock
|
||||||
|
import os.path
|
||||||
|
|
||||||
from muranoagent.common import config as cfg
|
from muranoagent.common import config as cfg
|
||||||
from muranoagent import files_manager
|
from muranoagent import files_manager
|
||||||
|
@ -41,7 +41,8 @@ class TestFileManager(base.MuranoAgentTestCase):
|
||||||
mock_path.return_value = None
|
mock_path.return_value = None
|
||||||
files = files_manager.FilesManager(self.get_template_downloable())
|
files = files_manager.FilesManager(self.get_template_downloable())
|
||||||
folder = files._get_file_folder("http://tomcat.git", "tomcat")
|
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')
|
@mock.patch('os.makedirs')
|
||||||
def test_get_folder_not_git(self, mock_path):
|
def test_get_folder_not_git(self, mock_path):
|
||||||
|
@ -49,7 +50,8 @@ class TestFileManager(base.MuranoAgentTestCase):
|
||||||
mock_path.return_value = None
|
mock_path.return_value = None
|
||||||
files = files_manager.FilesManager(self.get_template_downloable())
|
files = files_manager.FilesManager(self.get_template_downloable())
|
||||||
folder = files._get_file_folder("http://tomcat", "tomcat")
|
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("git.Git")
|
||||||
@mock.patch('os.path.isdir')
|
@mock.patch('os.path.isdir')
|
||||||
|
@ -107,7 +109,7 @@ class TestFileManager(base.MuranoAgentTestCase):
|
||||||
@mock.patch("git.Git")
|
@mock.patch("git.Git")
|
||||||
@mock.patch('os.path.isdir')
|
@mock.patch('os.path.isdir')
|
||||||
@mock.patch('os.makedirs')
|
@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
|
"""It tests the putfile method when the file is a git
|
||||||
URL.
|
URL.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue