Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
erp5
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
Hide 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
...
@@ -3,6 +3,7 @@ from unittest import TestCase
from
erp5.util.testnode.testnode
import
TestNode
from
erp5.util.testnode.testnode
import
TestNode
from
erp5.util.testnode.testnode
import
SlapOSInstance
from
erp5.util.testnode.testnode
import
SlapOSInstance
from
erp5.util.testnode.ProcessManager
import
ProcessManager
,
SubprocessError
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
SlapOSControler
from
erp5.util.testnode.SlapOSControler
import
createFolder
from
erp5.util.testnode.SlapOSControler
import
createFolder
...
@@ -268,6 +269,44 @@ branch = foo
...
@@ -268,6 +269,44 @@ branch = foo
output
=
call
(
"git branch"
.
split
()).
strip
()
output
=
call
(
"git branch"
.
split
()).
strip
()
self
.
assertTrue
(
"* bar"
in
output
.
split
(
'
\
n
'
))
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
):
def
test_06_checkRevision
(
self
):
"""
"""
Check if we are able to restore older commit hash if master decide so
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 @@
...
@@ -27,6 +27,7 @@
import
errno
import
errno
import
os
import
os
import
re
import
re
import
shutil
import
subprocess
import
subprocess
import
sys
import
sys
import
threading
import
threading
...
@@ -46,7 +47,8 @@ class Updater(object):
...
@@ -46,7 +47,8 @@ class Updater(object):
stdin = file(os.devnull)
stdin = file(os.devnull)
def __init__(self, repository_path, log, revision=None, git_binary=None,
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.log = log
self.revision = revision
self.revision = revision
self._path_list = []
self._path_list = []
...
@@ -55,6 +57,8 @@ class Updater(object):
...
@@ -55,6 +57,8 @@ class Updater(object):
self.git_binary = git_binary
self.git_binary = git_binary
self.realtime_output = realtime_output
self.realtime_output = realtime_output
self.process_manager = process_manager
self.process_manager = process_manager
self.url = url
self.working_directory = working_directory
def getRepositoryPath(self):
def getRepositoryPath(self):
return self.repository_path
return self.repository_path
...
@@ -88,9 +92,12 @@ class Updater(object):
...
@@ -88,9 +92,12 @@ class Updater(object):
raise
raise
def spawn(self, *args, **kw):
def spawn(self, *args, **kw):
cwd = kw.pop("cwd", None)
if cwd is None:
cwd = self.getRepositoryPath()
return self.process_manager.spawn(*args,
return self.process_manager.spawn(*args,
log_prefix='
git
',
log_prefix='
git
',
cwd=
self.getRepositoryPath()
,
cwd=
cwd
,
**kw)
**kw)
def _git(self, *args, **kw):
def _git(self, *args, **kw):
...
@@ -120,7 +127,33 @@ class Updater(object):
...
@@ -120,7 +127,33 @@ class Updater(object):
return str(max(map(int, SVN_CHANGED_REV.findall(stdout))))
return str(max(map(int, SVN_CHANGED_REV.findall(stdout))))
raise NotImplementedError
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):
def checkout(self, *path_list):
self.checkRepository()
if not path_list:
if not path_list:
path_list = '
.
',
path_list = '
.
',
revision = self.revision
revision = self.revision
...
...
erp5/util/testnode/testnode.py
View file @
175d0604
...
@@ -214,16 +214,11 @@ branch = %(branch)s
...
@@ -214,16 +214,11 @@ branch = %(branch)s
repository_path
=
vcs_repository
[
'repository_path'
]
repository_path
=
vcs_repository
[
'repository_path'
]
repository_id
=
vcs_repository
[
'repository_id'
]
repository_id
=
vcs_repository
[
'repository_id'
]
branch
=
vcs_repository
.
get
(
'branch'
)
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
# Make sure we have local repository
updater
=
Updater
(
repository_path
,
git_binary
=
config
[
'git_binary'
],
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
()
updater
.
checkout
()
revision
=
"-"
.
join
(
updater
.
getRevision
())
revision
=
"-"
.
join
(
updater
.
getRevision
())
full_revision_list
.
append
(
'%s=%s'
%
(
repository_id
,
revision
))
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