Skip to content

Commit

Permalink
Merge pull request #30847 from terminalmage/bp-30844
Browse files Browse the repository at this point in the history
Backport #30844 to 2015.8 branch
  • Loading branch information
Mike Place committed Feb 3, 2016
2 parents e511824 + 58c4c01 commit 0338f44
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
42 changes: 28 additions & 14 deletions salt/utils/gitfs.py
Expand Up @@ -570,6 +570,8 @@ def init_remote(self):
# to the git config at once, go ahead and pass over it since
# this is the only write. This should place a lock down.
pass
else:
new = True
return new

def dir_list(self, tgt_env):
Expand Down Expand Up @@ -942,6 +944,8 @@ def init_remote(self):
# to the git config at once, go ahead and pass over it since
# this is the only write. This should place a lock down.
pass
else:
new = True
return new

def dir_list(self, tgt_env):
Expand Down Expand Up @@ -1613,10 +1617,24 @@ def init_remote(self):
new = False
if not os.listdir(self.cachedir):
# Repo cachedir is empty, initialize a new repo there
self.repo = dulwich.repo.Repo.init(self.cachedir)
new = True
else:
# Repo cachedir exists, try to attach
try:
self.repo = dulwich.repo.Repo(self.cachedir)
except dulwich.repo.NotGitRepository:
log.error(_INVALID_REPO.format(self.cachedir, self.url))
return new

self.lockfile = os.path.join(self.repo.path, 'update.lk')

# Read in config file and look for the remote
try:
conf = self.get_conf()
conf.get(('remote', 'origin'), 'url')
except KeyError:
try:
self.repo = dulwich.repo.Repo.init(self.cachedir)
new = True
conf = self.get_conf()
conf.set('http', 'sslVerify', self.ssl_verify)
# Add remote manually, there is no function/object to do this
conf.set(
Expand All @@ -1629,17 +1647,10 @@ def init_remote(self):
conf.write_to_path()
except os.error:
pass
else:
# Repo cachedir exists, try to attach
try:
self.repo = dulwich.repo.Repo(self.cachedir)
except dulwich.repo.NotGitRepository:
log.error(_INVALID_REPO.format(self.cachedir, self.url))
return new

self.lockfile = os.path.join(self.repo.path, 'update.lk')

# No way to interact with remotes, so just assume success
else:
new = True
except os.error:
pass
return new

def walk_tree(self, tree, path):
Expand Down Expand Up @@ -1747,6 +1758,9 @@ def init_remotes(self, remotes, per_remote_overrides):
repo_obj.root = repo_obj.root.rstrip(os.path.sep)
# Sanity check and assign the credential parameter
repo_obj.verify_auth()
if self.opts['__role'] == 'minion' and repo_obj.new:
# Perform initial fetch
repo_obj.fetch()
self.remotes.append(repo_obj)

# Don't allow collisions in cachedir naming
Expand Down
12 changes: 8 additions & 4 deletions tests/integration/fileserver/gitfs_test.py
Expand Up @@ -93,7 +93,8 @@ def setUp(self):

with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
gitfs.update()

def tearDown(self):
Expand All @@ -108,23 +109,26 @@ def tearDown(self):
def test_file_list(self):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
ret = gitfs.file_list(LOAD)
self.assertIn('testfile', ret)

#@skipIf(True, 'Skipping tests temporarily')
def test_dir_list(self):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
ret = gitfs.dir_list(LOAD)
self.assertIn('grail', ret)

#@skipIf(True, 'Skipping tests temporarily')
def test_envs(self):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
ret = gitfs.envs()
self.assertIn('base', ret)

Expand Down

0 comments on commit 0338f44

Please sign in to comment.