Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build
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
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.recipe.build
Commits
2957dd9b
Commit
2957dd9b
authored
Jan 15, 2019
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up, add function for setting git config and follow convention
parent
0216d4b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
26 deletions
+44
-26
slapos/recipe/build/tests.py
slapos/recipe/build/tests.py
+44
-26
No files found.
slapos/recipe/build/tests.py
View file @
2957dd9b
...
...
@@ -35,8 +35,11 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self
.
dir
=
os
.
path
.
realpath
(
tempfile
.
mkdtemp
())
self
.
parts_directory_path
=
os
.
path
.
join
(
self
.
dir
,
'test_parts'
)
def
setUpSubmoduleRepo
(
self
):
# Create a main repo as well as a submodule repo
def
setUpSubmoduleRepository
(
self
):
"""
Create a main repo as well as a submodule repository and add files and
commit then. Then add submodule to the main repository
"""
# Add files in both main as well as submodule repo
subprocess
.
check_call
(
'mkdir main_repo'
,
cwd
=
self
.
dir
,
shell
=
True
)
subprocess
.
check_call
(
'mkdir submodule_repo'
,
cwd
=
self
.
dir
,
shell
=
True
)
...
...
@@ -46,24 +49,26 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# Add files in submodule repo and initialize git in it
subprocess
.
check_call
(
'cd submodule_repo'
,
cwd
=
self
.
dir
,
shell
=
True
)
subprocess
.
check_call
(
'git init'
,
cwd
=
self
.
submodule_dir
,
shell
=
True
)
self
.
setUpGitConfig
(
self
.
submodule_dir
)
subprocess
.
check_call
(
'touch file1.py'
,
cwd
=
self
.
submodule_dir
,
shell
=
True
)
self
.
git
_a
dd
(
self
.
submodule_dir
)
self
.
git
_c
ommit
(
self
.
submodule_dir
,
msg
=
'Add file1 in submodule repo'
)
self
.
git
A
dd
(
self
.
submodule_dir
)
self
.
git
C
ommit
(
self
.
submodule_dir
,
msg
=
'Add file1 in submodule repo'
)
# Add files and folder in main repo and initialize git in it
subprocess
.
check_call
(
'cd main_repo'
,
cwd
=
self
.
dir
,
shell
=
True
)
subprocess
.
check_call
(
'git init'
,
cwd
=
self
.
project_dir
,
shell
=
True
)
self
.
setUpGitConfig
(
self
.
project_dir
)
subprocess
.
check_call
(
'mkdir dir1'
,
cwd
=
self
.
project_dir
,
shell
=
True
)
subprocess
.
check_call
(
'touch file1.py'
,
cwd
=
self
.
project_dir
,
shell
=
True
)
self
.
git
_a
dd
(
self
.
project_dir
)
self
.
git
_c
ommit
(
self
.
project_dir
,
msg
=
'Add file and folder in main repo'
)
self
.
git
A
dd
(
self
.
project_dir
)
self
.
git
C
ommit
(
self
.
project_dir
,
msg
=
'Add file and folder in main repo'
)
# Add submodule to main repo
subprocess
.
check_call
(
'cd dir1'
,
cwd
=
self
.
project_dir
,
shell
=
True
)
submodule_dir_main_repo
=
os
.
path
.
join
(
self
.
project_dir
,
'dir1'
)
subprocess
.
check_call
(
'git submodule add %s'
%
self
.
submodule_dir
,
cwd
=
submodule_dir_main_repo
,
shell
=
True
)
self
.
git
_c
ommit
(
self
.
project_dir
,
msg
=
'Add submodule repo'
)
self
.
git
C
ommit
(
self
.
project_dir
,
msg
=
'Add submodule repo'
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
dir
)
...
...
@@ -79,7 +84,18 @@ class GitCloneNonInformativeTests(unittest.TestCase):
os
.
chmod
(
path
,
mode
)
return
path
def
git_add
(
self
,
proj_dir
,
update
=
False
):
def
setUpGitConfig
(
self
,
proj_dir
):
"""
Setup user and email for given git repository
"""
subprocess
.
check_call
(
"git config user.email 'test@example.com'"
,
cwd
=
proj_dir
,
shell
=
True
)
subprocess
.
check_call
(
"git config user.name 'Test'"
,
cwd
=
proj_dir
,
shell
=
True
)
def
gitAdd
(
self
,
proj_dir
,
update
=
False
):
"""runs a 'git add .' in the provided git repo
:param proj_dir: path to a git repo
:update: if True, will run 'git add -u'
...
...
@@ -91,16 +107,18 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# XXX: This is ugly and old. Change it before review
logging
.
error
(
"'git add .' failed with '{}'"
.
format
(
e
.
returncode
))
def
git
_c
ommit
(
self
,
proj_dir
,
msg
):
def
git
C
ommit
(
self
,
proj_dir
,
msg
):
"""runs a 'git commit -m msg' in the provided git repo
:param proj_dir: path to a git repo
"""
try
:
subprocess
.
check_call
(
'git commit -m "{}"'
.
format
(
msg
),
cwd
=
proj_dir
,
shell
=
True
)
subprocess
.
check_call
(
'git commit -m "{}"'
.
format
(
msg
),
cwd
=
proj_dir
,
shell
=
True
)
except
subprocess
.
CalledProcessError
as
e
:
logging
.
error
(
"'git commit' failed with '{}'"
.
format
(
e
.
returncode
))
def
get
_repo_head_c
ommit
(
self
,
proj_dir
,
branch
=
'master'
):
def
get
RepositoryHeadC
ommit
(
self
,
proj_dir
,
branch
=
'master'
):
"""
Returns the sha of HEAD of a git repo
"""
...
...
@@ -173,7 +191,7 @@ class GitCloneNonInformativeTests(unittest.TestCase):
Main repo (M3) ---references---> Submodule(S2)
Install should be M3+S2
"""
self
.
setUpSubmoduleRepo
()
self
.
setUpSubmoduleRepo
sitory
()
# STEP I: Clone repositories in status M1 and S1 (M1---->S1)
recipe
=
self
.
makeGitCloneRecipe
(
{
...
...
@@ -189,16 +207,16 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self
.
assertTrue
(
os
.
listdir
(
submodule_repo_path
))
# Get the head commit of the submodule repo
head_commit_submodule_after_clone
=
self
.
get
_repo_head_c
ommit
(
head_commit_submodule_after_clone
=
self
.
get
RepositoryHeadC
ommit
(
submodule_repo_path
)
# Update submodule repository and main repo separately
subprocess
.
check_call
(
'touch file2.py'
,
cwd
=
self
.
project_dir
,
shell
=
True
)
self
.
git
_a
dd
(
self
.
project_dir
)
self
.
git
_c
ommit
(
self
.
project_dir
,
msg
=
'Add file2 in main repo'
)
self
.
git
A
dd
(
self
.
project_dir
)
self
.
git
C
ommit
(
self
.
project_dir
,
msg
=
'Add file2 in main repo'
)
subprocess
.
check_call
(
'touch file2.py'
,
cwd
=
self
.
submodule_dir
,
shell
=
True
)
self
.
git
_a
dd
(
self
.
submodule_dir
)
self
.
git
_c
ommit
(
self
.
submodule_dir
,
msg
=
'Add file2 in submodule repo'
)
self
.
git
A
dd
(
self
.
submodule_dir
)
self
.
git
C
ommit
(
self
.
submodule_dir
,
msg
=
'Add file2 in submodule repo'
)
# STEP II: Clone repositories in status M2 and S2 (M2---->S1)
# Update the recipe with new revision which still point to the submodule
...
...
@@ -206,7 +224,7 @@ class GitCloneNonInformativeTests(unittest.TestCase):
recipe
=
self
.
makeGitCloneRecipe
(
{
'repository'
:
self
.
project_dir
,
'revision'
:
str
(
self
.
get
_repo_head_c
ommit
(
self
.
project_dir
))
'revision'
:
str
(
self
.
get
RepositoryHeadC
ommit
(
self
.
project_dir
))
}
)
recipe
.
update
()
...
...
@@ -215,22 +233,22 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self
.
assertTrue
(
os
.
listdir
(
submodule_repo_path
))
# Get the head commit of the submodule repo
head_commit_submodule_after_first_update
=
self
.
get
_repo_head_c
ommit
(
head_commit_submodule_after_first_update
=
self
.
get
RepositoryHeadC
ommit
(
submodule_repo_path
)
# Update main repo with changes of submodule
submodule_dir_main_repo
=
os
.
path
.
join
(
self
.
project_dir
,
'dir1'
,
'submodule_repo'
)
subprocess
.
check_call
(
'git checkout master'
,
cwd
=
submodule_dir_main_repo
,
shell
=
True
)
subprocess
.
check_call
(
'git pull'
,
cwd
=
submodule_dir_main_repo
,
shell
=
True
)
self
.
git
_a
dd
(
self
.
project_dir
)
self
.
git
_c
ommit
(
self
.
project_dir
,
msg
=
'Update submodule version'
)
self
.
git
A
dd
(
self
.
project_dir
)
self
.
git
C
ommit
(
self
.
project_dir
,
msg
=
'Update submodule version'
)
# STEP II: Clone repositories in status M3 and S2 (M3---->S2)
# Update the recipe with new revision which points to submodule new revision
recipe
=
self
.
makeGitCloneRecipe
(
{
'repository'
:
self
.
project_dir
,
'revision'
:
str
(
self
.
get
_repo_head_c
ommit
(
self
.
project_dir
))
'revision'
:
str
(
self
.
get
RepositoryHeadC
ommit
(
self
.
project_dir
))
}
)
recipe
.
update
()
...
...
@@ -238,11 +256,11 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# Check if the submodule is not empty
self
.
assertTrue
(
os
.
listdir
(
submodule_repo_path
))
# Get the head commit of the submodule repo
head_commit_submodule_after_second_update
=
self
.
get
_repo_head_c
ommit
(
head_commit_submodule_after_second_update
=
self
.
get
RepositoryHeadC
ommit
(
submodule_repo_path
)
# Check the HEAD of the submodule
submodule_head_commit
=
self
.
get
_repo_head_c
ommit
(
self
.
submodule_dir
)
submodule_head_commit
=
self
.
get
RepositoryHeadC
ommit
(
self
.
submodule_dir
)
self
.
assertEqual
(
head_commit_submodule_after_clone
,
head_commit_submodule_after_first_update
)
...
...
@@ -288,7 +306,7 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self
.
test_ignore_ssl_certificate
(
ignore_ssl_certificate
=
False
)
def
test_clone_submodules_by_default
(
self
,
ignore_cloning_submodules
=
False
):
self
.
setUpSubmoduleRepo
()
self
.
setUpSubmoduleRepo
sitory
()
recipe
=
self
.
makeGitCloneRecipe
(
{
'repository'
:
self
.
project_dir
,
'ignore-cloning-submodules'
:
str
(
ignore_cloning_submodules
).
lower
()}
...
...
@@ -313,7 +331,7 @@ class GitCloneNonInformativeTests(unittest.TestCase):
should udpate the main repo as well as submodule repo if the reference of
submodule in main repo has been udpated.
"""
self
.
setUpSubmoduleRepo
()
self
.
setUpSubmoduleRepo
sitory
()
recipe
=
self
.
makeGitCloneRecipe
(
{
'repository'
:
self
.
project_dir
}
)
...
...
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