Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5_rtl_support
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
erp5_rtl_support
Commits
175d0604
Commit
175d0604
authored
Aug 30, 2013
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5.util.testnode: delete git repos if url has changed
parent
9ef58d41
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
10 deletions
+77
-10
erp5/tests/testERP5TestNode.py
erp5/tests/testERP5TestNode.py
+39
-0
erp5/util/testnode/Updater.py
erp5/util/testnode/Updater.py
+35
-2
erp5/util/testnode/testnode.py
erp5/util/testnode/testnode.py
+3
-8
No files found.
erp5/tests/testERP5TestNode.py
View file @
175d0604
...
...
@@ -3,6 +3,7 @@ from unittest import TestCase
from
erp5.util.testnode.testnode
import
TestNode
from
erp5.util.testnode.testnode
import
SlapOSInstance
from
erp5.util.testnode.ProcessManager
import
ProcessManager
,
SubprocessError
from
erp5.util.testnode.Updater
import
Updater
from
erp5.util.testnode.SlapOSControler
import
SlapOSControler
from
erp5.util.testnode.SlapOSControler
import
createFolder
...
...
@@ -268,6 +269,44 @@ branch = foo
output
=
call
(
"git branch"
.
split
()).
strip
()
self
.
assertTrue
(
"* bar"
in
output
.
split
(
'
\
n
'
))
def
test_05c_changeRepositoryUrl
(
self
):
"""
It could happen that the url is changed for a repository (new place, or
change of username and password). testnode must be able to erase and clone
again the repository
"""
commit_dict
=
self
.
generateTestRepositoryList
(
add_third_repository
=
True
)
test_node
=
self
.
getTestNode
()
node_test_suite
=
test_node
.
getNodeTestSuite
(
'foo'
)
self
.
updateNodeTestSuiteData
(
node_test_suite
)
rev_list
=
test_node
.
getAndUpdateFullRevisionList
(
node_test_suite
)
self
.
assertEquals
(
2
,
len
(
rev_list
))
self
.
assertEquals
(
2
,
len
(
node_test_suite
.
vcs_repository_list
))
# patch deleteRepository to make sure it will be called once for the wrong
# repos, and not for the repos which has not changed
deleted_repository_path_list
=
[]
original_deleteRepository
=
Updater
.
deleteRepository
try
:
def
deleteRepository
(
self
):
deleted_repository_path_list
.
append
(
self
.
repository_path
)
original_deleteRepository
(
self
)
Updater
.
deleteRepository
=
deleteRepository
# change the url of the first repository
vcs_repository_info
=
node_test_suite
.
vcs_repository_list
[
0
]
vcs_repository_info
[
"url"
]
=
self
.
remote_repository2
rep0_clone_path
=
[
x
[
'repository_path'
]
for
x
in
\
node_test_suite
.
vcs_repository_list
\
if
x
[
'repository_path'
].
endswith
(
"rep0"
)][
0
]
call
=
self
.
getCaller
(
cwd
=
rep0_clone_path
)
self
.
assertEquals
(
call
(
"git config --get remote.origin.url"
.
split
()).
strip
(),
self
.
remote_repository0
)
rev_list
=
test_node
.
getAndUpdateFullRevisionList
(
node_test_suite
)
self
.
assertEquals
(
call
(
"git config --get remote.origin.url"
.
split
()).
strip
(),
self
.
remote_repository2
)
self
.
assertEquals
([
rep0_clone_path
],
deleted_repository_path_list
)
finally
:
Updater
.
deleteRepository
=
original_deleteRepository
def
test_06_checkRevision
(
self
):
"""
Check if we are able to restore older commit hash if master decide so
...
...
erp5/util/testnode/Updater.py
View file @
175d0604
...
...
@@ -27,6 +27,7 @@
import
errno
import
os
import
re
import
shutil
import
subprocess
import
sys
import
threading
...
...
@@ -46,7 +47,8 @@ class Updater(object):
stdin = file(os.devnull)
def __init__(self, repository_path, log, revision=None, git_binary=None,
branch=None, realtime_output=True, process_manager=None):
branch=None, realtime_output=True, process_manager=None, url=None,
working_directory=None):
self.log = log
self.revision = revision
self._path_list = []
...
...
@@ -55,6 +57,8 @@ class Updater(object):
self.git_binary = git_binary
self.realtime_output = realtime_output
self.process_manager = process_manager
self.url = url
self.working_directory = working_directory
def getRepositoryPath(self):
return self.repository_path
...
...
@@ -88,9 +92,12 @@ class Updater(object):
raise
def spawn(self, *args, **kw):
cwd = kw.pop("cwd", None)
if cwd is None:
cwd = self.getRepositoryPath()
return self.process_manager.spawn(*args,
log_prefix='
git
',
cwd=
self.getRepositoryPath()
,
cwd=
cwd
,
**kw)
def _git(self, *args, **kw):
...
...
@@ -120,7 +127,33 @@ class Updater(object):
return str(max(map(int, SVN_CHANGED_REV.findall(stdout))))
raise NotImplementedError
def deleteRepository(self):
self.log("Wrong repository or wrong url, deleting repos %s" %
\
self.repository_path)
shutil.rmtree(self.repository_path)
def checkRepository(self):
# make sure that the repository is like we expect
if self.url:
if os.path.exists(self.repository_path):
correct_url = False
try:
remote_url = self._git("config", "--get", "remote.origin.url")
if remote_url == self.url:
correct_url = True
except (SubprocessError,) as e:
self.log("SubprocessError", exc_info=sys.exc_info())
if not(correct_url):
self.deleteRepository()
if not os.path.exists(self.repository_path):
parameter_list = ['
clone
', self.url]
if self.branch is not None:
parameter_list.extend(['
-
b', self.branch])
parameter_list.append(self.repository_path)
self._git(*parameter_list, cwd=self.working_directory)
def checkout(self, *path_list):
self.checkRepository()
if not path_list:
path_list = '
.
',
revision = self.revision
...
...
erp5/util/testnode/testnode.py
View file @
175d0604
...
...
@@ -214,16 +214,11 @@ branch = %(branch)s
repository_path
=
vcs_repository
[
'repository_path'
]
repository_id
=
vcs_repository
[
'repository_id'
]
branch
=
vcs_repository
.
get
(
'branch'
)
if
not
os
.
path
.
exists
(
repository_path
):
parameter_list
=
[
config
[
'git_binary'
],
'clone'
,
vcs_repository
[
'url'
]]
if
branch
is
not
None
:
parameter_list
.
extend
([
'-b'
,
branch
])
parameter_list
.
append
(
repository_path
)
log
(
subprocess
.
check_output
(
parameter_list
,
stderr
=
subprocess
.
STDOUT
))
# Make sure we have local repository
updater
=
Updater
(
repository_path
,
git_binary
=
config
[
'git_binary'
],
branch
=
branch
,
log
=
log
,
process_manager
=
self
.
process_manager
)
branch
=
branch
,
log
=
log
,
process_manager
=
self
.
process_manager
,
working_directory
=
node_test_suite
.
working_directory
,
url
=
vcs_repository
[
"url"
])
updater
.
checkout
()
revision
=
"-"
.
join
(
updater
.
getRevision
())
full_revision_list
.
append
(
'%s=%s'
%
(
repository_id
,
revision
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment