2012-11-01 05:33:07 +00:00
|
|
|
'''
|
|
|
|
Tests for the Git state
|
|
|
|
'''
|
|
|
|
import os
|
|
|
|
import shutil
|
2012-12-22 03:41:07 +00:00
|
|
|
import socket
|
2013-06-24 19:06:49 +00:00
|
|
|
try:
|
|
|
|
import integration
|
|
|
|
except ImportError:
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
sys.path.insert(
|
|
|
|
0, os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(__file__), '../../'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import integration
|
2012-11-01 05:33:07 +00:00
|
|
|
|
|
|
|
|
2012-12-07 16:33:38 +00:00
|
|
|
class GitTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
2012-11-01 05:33:07 +00:00
|
|
|
'''
|
|
|
|
Validate the git state
|
|
|
|
'''
|
|
|
|
|
2012-12-22 03:41:07 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(GitTest, self).setUp()
|
|
|
|
self.__domain = 'github.com'
|
|
|
|
try:
|
|
|
|
if hasattr(socket, 'setdefaulttimeout'):
|
|
|
|
# 10 second dns timeout
|
|
|
|
socket.setdefaulttimeout(10)
|
|
|
|
socket.gethostbyname(self.__domain)
|
|
|
|
except socket.error:
|
|
|
|
msg = 'error resolving {0}, possible network issue?'
|
|
|
|
self.skipTest(msg.format(self.__domain))
|
|
|
|
|
2012-11-01 05:33:07 +00:00
|
|
|
def test_latest(self):
|
|
|
|
'''
|
|
|
|
git.latest
|
|
|
|
'''
|
|
|
|
name = os.path.join(integration.TMP, 'salt_repo')
|
2012-11-04 09:58:05 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'git.latest',
|
2013-01-15 05:49:49 +00:00
|
|
|
name='https://{0}/saltstack/salt-bootstrap.git'.format(self.__domain),
|
2012-11-04 09:58:05 +00:00
|
|
|
rev='develop',
|
|
|
|
target=name,
|
|
|
|
submodules=True
|
|
|
|
)
|
2012-12-07 16:33:38 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-04 09:58:05 +00:00
|
|
|
self.assertTrue(os.path.isdir(os.path.join(name, '.git')))
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(name, ignore_errors=True)
|
2012-11-01 05:33:07 +00:00
|
|
|
|
2012-11-01 05:41:43 +00:00
|
|
|
def test_latest_failure(self):
|
|
|
|
'''
|
|
|
|
git.latest
|
|
|
|
'''
|
|
|
|
name = os.path.join(integration.TMP, 'salt_repo')
|
2012-11-04 09:58:05 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'git.latest',
|
|
|
|
name='https://youSpelledGithubWrong.com/saltstack/salt.git',
|
|
|
|
rev='develop',
|
|
|
|
target=name,
|
|
|
|
submodules=True
|
|
|
|
)
|
2012-12-07 16:33:38 +00:00
|
|
|
self.assertSaltFalseReturn(ret)
|
2012-11-04 09:58:05 +00:00
|
|
|
self.assertFalse(os.path.isdir(os.path.join(name, '.git')))
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(name, ignore_errors=True)
|
2012-11-01 05:41:43 +00:00
|
|
|
|
2012-11-01 06:50:08 +00:00
|
|
|
def test_latest_empty_dir(self):
|
|
|
|
'''
|
|
|
|
git.latest
|
|
|
|
'''
|
|
|
|
name = os.path.join(integration.TMP, 'salt_repo')
|
2012-11-04 09:58:05 +00:00
|
|
|
if not os.path.isdir(name):
|
|
|
|
os.mkdir(name)
|
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'git.latest',
|
2013-01-15 05:49:49 +00:00
|
|
|
name='https://{0}/saltstack/salt-bootstrap.git'.format(self.__domain),
|
2012-11-04 09:58:05 +00:00
|
|
|
rev='develop',
|
|
|
|
target=name,
|
|
|
|
submodules=True
|
|
|
|
)
|
2012-12-07 16:33:38 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-04 09:58:05 +00:00
|
|
|
self.assertTrue(os.path.isdir(os.path.join(name, '.git')))
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(name, ignore_errors=True)
|
2012-11-01 06:50:08 +00:00
|
|
|
|
2012-11-01 05:33:07 +00:00
|
|
|
def test_present(self):
|
|
|
|
'''
|
|
|
|
git.present
|
|
|
|
'''
|
|
|
|
name = os.path.join(integration.TMP, 'salt_repo')
|
2012-11-04 09:58:05 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'git.present',
|
|
|
|
name=name,
|
|
|
|
bare=True
|
|
|
|
)
|
2012-12-07 16:33:38 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-04 09:58:05 +00:00
|
|
|
self.assertTrue(os.path.isfile(os.path.join(name, 'HEAD')))
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(name, ignore_errors=True)
|
2012-11-01 05:33:07 +00:00
|
|
|
|
2012-11-01 05:41:43 +00:00
|
|
|
def test_present_failure(self):
|
|
|
|
'''
|
|
|
|
git.present
|
|
|
|
'''
|
|
|
|
name = os.path.join(integration.TMP, 'salt_repo')
|
2012-11-04 09:58:05 +00:00
|
|
|
if not os.path.isdir(name):
|
|
|
|
os.mkdir(name)
|
|
|
|
try:
|
|
|
|
fname = os.path.join(name, 'stoptheprocess')
|
|
|
|
with file(fname, 'a'):
|
|
|
|
pass
|
|
|
|
ret = self.run_state(
|
|
|
|
'git.present',
|
|
|
|
name=name,
|
|
|
|
bare=True
|
|
|
|
)
|
2012-12-07 16:33:38 +00:00
|
|
|
self.assertSaltFalseReturn(ret)
|
2012-11-04 09:58:05 +00:00
|
|
|
self.assertFalse(os.path.isfile(os.path.join(name, 'HEAD')))
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(name, ignore_errors=True)
|
2012-11-01 05:41:43 +00:00
|
|
|
|
2012-11-01 06:50:08 +00:00
|
|
|
def test_present_empty_dir(self):
|
|
|
|
'''
|
|
|
|
git.present
|
|
|
|
'''
|
|
|
|
name = os.path.join(integration.TMP, 'salt_repo')
|
2012-11-04 09:58:05 +00:00
|
|
|
if not os.path.isdir(name):
|
|
|
|
os.mkdir(name)
|
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'git.present',
|
|
|
|
name=name,
|
|
|
|
bare=True
|
|
|
|
)
|
2012-12-07 16:33:38 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-04 09:58:05 +00:00
|
|
|
self.assertTrue(os.path.isfile(os.path.join(name, 'HEAD')))
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(name, ignore_errors=True)
|
2012-11-01 06:50:08 +00:00
|
|
|
|
2012-11-01 05:41:43 +00:00
|
|
|
|
2012-11-01 05:33:07 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(GitTest)
|