Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mpsd-software-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MPSD Computational Science
mpsd-software-manager
Commits
63272b40
Commit
63272b40
authored
1 year ago
by
Ashwin Kumar Karnad
Browse files
Options
Downloads
Patches
Plain Diff
test cmd log generation
parent
f60b6edb
No related branches found
Branches containing commit
No related tags found
2 merge requests
!19
Move linux-debian11 into main
,
!1
Resolve "First draft for user interface for top level install command"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
install-mpsd-software-environment.py
+45
-2
45 additions, 2 deletions
install-mpsd-software-environment.py
tests.py
+30
-2
30 additions, 2 deletions
tests.py
with
76 additions
and
4 deletions
.gitignore
+
1
−
0
View file @
63272b40
.vscode
**/*.pyc
logs
\ No newline at end of file
This diff is collapsed.
Click to expand it.
install-mpsd-software-environment.py
+
45
−
2
View file @
63272b40
...
...
@@ -2,6 +2,7 @@
import
os
import
subprocess
import
time
import
datetime
import
argparse
import
sys
from
pathlib
import
Path
...
...
@@ -70,9 +71,34 @@ class builder:
self
.
cmd_log_file
=
"
logs/install-software-environment.log
"
self
.
build_log_file
=
f
"
build_toolchains_
{
self
.
mpsd_spack_ver
}
_
{
time
.
strftime
(
'
%Y%m%d-%H%M%S
'
)
}
.log
"
# Setup the log file for commands
self
.
setup_log_cmd
()
# run the script
# self.run() # better to call this seperately after creating the object
def
setup_log_cmd
(
self
):
# Create log directory if it doesn't exist
if
not
os
.
path
.
exists
(
"
logs
"
):
os
.
makedirs
(
"
logs
"
)
# Write to the log file with the following format
# --------------------------------------------------
# 2023-02-29T23:32:01, install-software-environment.py --release dev-23a --install ALL
# Software environment installer branch: script_branch (commit hash: script_commit_hash)
# Spack environments branch: dev-23a (commit hash: spe_commit_hash)
with
open
(
self
.
cmd_log_file
,
"
a
"
)
as
f
:
f
.
write
(
"
-
"
*
50
+
"
\n
"
)
cmd_line
=
"
"
.
join
(
sys
.
argv
)
f
.
write
(
f
"
{
datetime
.
datetime
.
now
().
isoformat
()
}
, install-software-environment.py
{
cmd_line
}
\n
"
)
f
.
write
(
f
"
Software environment installer branch:
{
self
.
script_branch
}
(commit hash:
{
self
.
script_commit_hash
}
)
\n
"
)
f
.
write
(
f
"
Spack environments branch:
{
self
.
spe_branch
}
(commit hash:
{
self
.
spe_commit_hash
}
)
\n
"
)
def
run
(
self
):
if
self
.
run_mode
==
"
remove
"
:
self
.
remove_toolchains
()
...
...
@@ -84,6 +110,13 @@ class builder:
self
.
prepare_env
()
def
prepare_env
(
self
):
# ensure required arguments are not None
if
self
.
toolchain_base_dir
is
None
:
raise
ValueError
(
"
Error: Please specify the target directory
"
)
if
self
.
mpsd_spack_ver
is
None
:
raise
ValueError
(
"
Error: Please specify the release version to install
"
)
if
self
.
toolchain_base_dir
is
None
:
raise
ValueError
(
"
Error: Please specify the target directory for installation
"
)
if
not
os
.
path
.
exists
(
self
.
toolchain_base_dir
):
os
.
makedirs
(
self
.
toolchain_base_dir
)
else
:
...
...
@@ -104,9 +137,19 @@ class builder:
subprocess
.
run
([
"
git
"
,
"
checkout
"
,
self
.
mpsd_spack_ver
])
def
install_toolchains
(
release
,
install
,
target_dir
,
force_reinstall
,
skip_build_cache
,
skip_dir_check
self
,
release
,
install
,
target_dir
,
force_reinstall
,
skip_build_cache
,
skip_dir_check
,
):
prepare_env
(
release
,
target_dir
,
skip_dir_check
)
# ensure required arguments are not None
if
self
.
toolchain_list
is
None
:
raise
ValueError
(
"
Error: Please specify the toolchains to install
"
)
self
.
prepare_env
()
def
start_new_env
(
set_up
,
from_release
):
pass
...
...
This diff is collapsed.
Click to expand it.
tests.py
+
30
−
2
View file @
63272b40
...
...
@@ -4,7 +4,11 @@ import importlib
import
subprocess
import
time
import
shutil
mod
=
importlib
.
import_module
(
"
install-mpsd-software-environment
"
)
test_release_path
=
(
"
/tmp/test_prepare_env
"
# temporary directory for testing used by multiple tests
)
def
test_os_chdir
():
...
...
@@ -30,7 +34,6 @@ def test_prepare_env():
# simulate running ./install-software-environment.py --release dev-23a --target-directory /tmp/test_prepare_env
# prepare_env is run when cmd is not specified, we can test cmd='prepare' and cmd=None to check both cases
test_release_path
=
"
/tmp/test_prepare_env
"
# if the directory exists, remove it
if
os
.
path
.
exists
(
test_release_path
):
shutil
.
rmtree
(
test_release_path
)
...
...
@@ -56,7 +59,9 @@ def test_prepare_env():
"
cd /tmp/test_prepare_env/spack-environments && git branch
"
,
shell
=
True
,
capture_output
=
True
,
).
stdout
.
decode
(
"
utf-8
"
).
split
(
"
\n
"
)[
0
]
)
.
stdout
.
decode
(
"
utf-8
"
)
.
split
(
"
\n
"
)[
0
]
==
"
* dev-23a
"
)
# make sure running the command again raises ValueError
...
...
@@ -80,3 +85,26 @@ def test_prepare_env():
run
.
run
()
# clean up the temporary directory
shutil
.
rmtree
(
test_release_path
)
def
test_setup_log_cmd
():
# check that logs/install-software-environment.log is updated when the module is run
log_file
=
"
logs/install-software-environment.log
"
if
os
.
path
.
exists
(
log_file
):
initial_bytes
=
os
.
path
.
getsize
(
log_file
)
else
:
initial_bytes
=
0
# run the prepare_env functionality
run
=
mod
.
builder
(
release
=
"
dev-23a
"
,
cmd
=
None
,
target_dir
=
test_release_path
,
skip_build_cache
=
False
,
)
run
.
skip_dir_check
=
True
run
.
run
()
# check that logs/install-software-environment.log is updated
assert
os
.
path
.
exists
(
"
logs/install-software-environment.log
"
)
assert
os
.
path
.
getsize
(
"
logs/install-software-environment.log
"
)
>
initial_bytes
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment