Skip to content

Commit 0b3ff72

Browse files
Merge pull request #12 from eclipsevortex/release/0.0.7
Release/0.0.7
2 parents 9f8daab + ac3a359 commit 0b3ff72

9 files changed

Lines changed: 86 additions & 158 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.6
1+
0.0.7

scripts/cleaner/clean_dumps.sh

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,16 @@ set -e
66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77
cd "$SCRIPT_DIR/../.."
88

9-
source ./scripts/utils/utils.sh
9+
# Load environment variables
10+
echo "🔍 Loading environment variables from .env..."
11+
export $(grep -v '^#' subvortex/auto_upgrader/.env | xargs)
1012

11-
show_help() {
12-
echo "Usage: $0"
13-
echo
14-
echo "Description:"
15-
echo " Clean all contents under the dump directory"
16-
echo
17-
echo "Options:"
18-
echo " -d, --dump-path Path of the dumps and cheksum directory. Reflect `dir` in redis.config". Default /var/tmp/dumps/redis
19-
exit 0
20-
}
13+
# Extract default DUMP_DIR from Redis config
14+
REDIS_CONF_PATH="./subvortex/auto_upgrader/template/template-subvortex-$SUBVORTEX_EXECUTION_ROLE-redis.conf"
15+
DUMP_DIR=$(grep -E '^\s*dir\s+' "$REDIS_CONF_PATH" | awk '{print $2}')
2116

22-
OPTIONS="d:h"
23-
LONGOPTIONS="dump-path:,help"
24-
25-
DUMP_DIR=/var/tmp/dumps/redis
26-
27-
# Parse arguments
28-
while [ "$#" -ge 1 ]; do
29-
case "$1" in
30-
-d|--dump-path)
31-
DUMP_DIR="$2"
32-
shift 2
33-
;;
34-
-h|--help)
35-
show_help
36-
exit 0
37-
;;
38-
--)
39-
shift
40-
break
41-
;;
42-
*)
43-
echo "❌ Unexpected argument: $1"
44-
show_help
45-
exit 1
46-
;;
47-
esac
48-
done
17+
# Fallback if not found
18+
DUMP_DIR=${DUMP_DIR:-/var/tmp/dumps/redis}
4919

5020
echo "🧹 Checking for dump directory at: $DUMP_DIR"
5121
if [[ -d "$DUMP_DIR" ]]; then

scripts/cleaner/clean_workspace.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ while [ "$#" -ge 1 ]; do
7272
esac
7373
done
7474

75-
TARGET_BASE="/var/tmp/subvortex"
75+
# Load environment variables
76+
echo "🔍 Loading environment variables from .env..."
77+
export $(grep -v '^#' subvortex/auto_upgrader/.env | xargs)
78+
79+
TARGET_BASE=${SUBVORTEX_WORKING_DIRECTORY:-/var/tmp/subvortex}
7680
SYMLINK_PATH="/root/subvortex"
7781

7882
if [ ! -d "$TARGET_BASE" ]; then

scripts/quick_clean.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ source ./scripts/utils/utils.sh
1010

1111
show_help() {
1212
echo "Usage:"
13-
echo " $0 [--execution=process|service] [--role=miner|validator] [--remove] [--force] [--workspace] [--dumps]"
13+
echo " $0 [--remove] [--force] [--workspace] [--dumps]"
1414
echo
1515
echo "Description:"
1616
echo " Cleans the Auto Upgrader workspace and/or dumps. Optionally removes or marks the current version for reinstall."
1717
echo
1818
echo "Options:"
19-
echo " --execution Execution method (default: from .env)"
20-
echo " --role Role of the Auto Upgrader: miner or validator (default: from .env)"
2119
echo " --workspace Clean workspace (default: false)"
2220
echo " --dumps Clean dumps (default: false)"
2321
echo " --remove Remove the current version (will stop the component)"
@@ -27,8 +25,6 @@ show_help() {
2725
}
2826

2927
# Default values
30-
EXECUTION="service"
31-
ROLE="miner"
3228
REMOVE_LATEST=false
3329
FORCE_REINSTALL=false
3430
CLEAN_WORKSPACE=false
@@ -37,14 +33,6 @@ CLEAN_DUMPS=false
3733
# Parse arguments
3834
while [ "$#" -ge 1 ]; do
3935
case "$1" in
40-
-e|--execution)
41-
EXECUTION="$2"
42-
shift 2
43-
;;
44-
-o|--role)
45-
ROLE="$2"
46-
shift 2
47-
;;
4836
--remove)
4937
REMOVE_LATEST=true
5038
shift
@@ -71,13 +59,6 @@ while [ "$#" -ge 1 ]; do
7159
esac
7260
done
7361

74-
check_required_args EXECUTION ROLE
75-
76-
# Stop component if --remove is passed
77-
if [[ "$REMOVE_LATEST" == "true" ]]; then
78-
"./scripts/$ROLE/quick_stop.sh" --execution "$EXECUTION"
79-
fi
80-
8162
# Build clean_workspace command
8263
if [[ "$CLEAN_WORKSPACE" == "true" || "$FORCE_REINSTALL" == "true" ]]; then
8364
CLEAN_CMD="./scripts/cleaner/clean_workspace.sh"

scripts/quick_stop.sh

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ source ./scripts/utils/utils.sh
1010

1111
show_help() {
1212
echo "Usage:"
13-
echo " $0 [--execution=process|service] [--role=miner|validator] [--clean_all] [--clean_workspace] [--clean_all_workspace] [--clean_dumps]"
13+
echo " $0 [--execution=process|service] [--role=miner|validator]"
1414
echo
1515
echo "Description:"
1616
echo " Gracefully stops and tears down the Auto Upgrader, and optionally"
@@ -20,21 +20,13 @@ show_help() {
2020
echo " --execution Set the execution method used to install the Auto Upgrader"
2121
echo " (choices: process, service; default: service)"
2222
echo " --role Role of the Auto Upgrader: miner or validator (default: miner)"
23-
echo " --clean_all Stop, teardown, and clean both workspace and dumps"
24-
echo " --clean_workspace Clean workspace (keep current version)"
25-
echo " --clean_all_workspace Clean workspace and remove the current version"
26-
echo " --clean_dumps Clean all dump files"
2723
echo " --help Show this help message and exit"
2824
exit 0
2925
}
3026

3127
# Defaults
3228
EXECUTION="service"
3329
ROLE="miner"
34-
CLEAN_ALL=false
35-
CLEAN_WORKSPACE=false
36-
CLEAN_ALL_WORKSPACE=false
37-
CLEAN_DUMPS=false
3830

3931
# Parse arguments
4032
while [ "$#" -ge 1 ]; do
@@ -47,22 +39,6 @@ while [ "$#" -ge 1 ]; do
4739
ROLE="$2"
4840
shift 2
4941
;;
50-
--clean_all)
51-
CLEAN_ALL=true
52-
shift
53-
;;
54-
--clean_workspace)
55-
CLEAN_WORKSPACE=true
56-
shift
57-
;;
58-
--clean_all_workspace)
59-
CLEAN_ALL_WORKSPACE=true
60-
shift
61-
;;
62-
--clean_dumps)
63-
CLEAN_DUMPS=true
64-
shift
65-
;;
6642
-h|--help)
6743
show_help
6844
;;
@@ -78,22 +54,3 @@ check_required_args EXECUTION ROLE
7854
# Stop and teardown
7955
./scripts/auto_upgrader/auto_upgrader_stop.sh --execution "$EXECUTION"
8056
./scripts/auto_upgrader/auto_upgrader_teardown.sh --execution "$EXECUTION"
81-
82-
# Cleanup via central clean script
83-
CLEAN_CMD="./scripts/auto_upgrader/clean.sh --execution $EXECUTION --role $ROLE"
84-
85-
if [ "$CLEAN_ALL" = true ]; then
86-
$CLEAN_CMD --workspace --dumps
87-
fi
88-
89-
if [ "$CLEAN_WORKSPACE" = true ]; then
90-
$CLEAN_CMD --workspace
91-
fi
92-
93-
if [ "$CLEAN_ALL_WORKSPACE" = true ]; then
94-
$CLEAN_CMD --workspace --remove
95-
fi
96-
97-
if [ "$CLEAN_DUMPS" = true ]; then
98-
$CLEAN_CMD --dumps
99-
fi

subvortex/auto_upgrader/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "subvortex-auto-upgrader"
7-
version = "0.0.6"
7+
version = "0.0.7"
88
description = "SubVortex Auto Upgrader"
99
authors = [{ name = "Eclipse Vortex", email = "subvortex.bt@gmail.com" }]
1010
readme = "README.md"

subvortex/auto_upgrader/src/github.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,57 @@ def _get_latest_container_version_old(self):
562562
return versions.get("version")
563563

564564
def _get_local_version(self):
565+
if not os.path.islink(sauc.SV_EXECUTION_DIR):
566+
btul.logging.warning(
567+
f"❌ {sauc.SV_EXECUTION_DIR} is not a symlink",
568+
prefix=sauc.SV_LOGGER_NAME,
569+
)
570+
return None
571+
572+
try:
573+
# Resolve the symlink target
574+
target_path = os.readlink(sauc.SV_EXECUTION_DIR)
575+
576+
# Extract version from the target path
577+
match = re.search(r"subvortex-(\d+\.\d+\.\d+(?:[ab]|rc)?\d*)", target_path)
578+
if not match:
579+
btul.logging.warning(
580+
f"⚠️ No valid version found in symlink: {target_path}",
581+
prefix=sauc.SV_LOGGER_NAME,
582+
)
583+
return None
584+
585+
version_str = match.group(1)
586+
587+
try:
588+
Version(version_str) # Just to validate format
589+
except InvalidVersion:
590+
btul.logging.warning(
591+
f"⚠️ Invalid version format in symlink: {version_str}",
592+
prefix=sauc.SV_LOGGER_NAME,
593+
)
594+
return None
595+
596+
# Check for optional force_reinstall flag
597+
version_dir = os.path.join(sauc.SV_ASSET_DIR, f"subvortex-{version_str}")
598+
marker_path = os.path.join(version_dir, "force_reinstall")
599+
if os.path.isfile(marker_path):
600+
btul.logging.warning(
601+
f"⚠️ Force reinstall marker found for version {version_str}",
602+
prefix=sauc.SV_LOGGER_NAME,
603+
)
604+
os.remove(marker_path)
605+
return None
606+
607+
return sauv.denormalize_version(version_str)
608+
609+
except OSError as e:
610+
btul.logging.warning(
611+
f"⚠️ Failed to read symlink: {e}", prefix=sauc.SV_LOGGER_NAME
612+
)
613+
return None
614+
615+
def _get_local_version_decommissioned(self):
565616
versions = []
566617

567618
if "PYTEST_CURRENT_TEST" not in os.environ:

subvortex/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.6"
1+
__version__ = "0.0.7"

tests/unit_tests/auto_upgrader/test_github.py

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,51 @@
99
from subvortex.auto_upgrader.src.github import Github
1010

1111

12-
@patch("subvortex.auto_upgrader.src.constants.SV_EXECUTION_METHOD", "service")
13-
@patch("subvortex.auto_upgrader.src.github.os.path.islink")
14-
@patch("subvortex.auto_upgrader.src.github.os.listdir")
15-
@patch("subvortex.auto_upgrader.src.github.os.path.isdir")
16-
@patch("subvortex.auto_upgrader.src.github.os.path.isfile")
17-
def test_get_local_version_service_returns_version(
18-
mock_isfile,
19-
mock_isdir,
20-
mock_listdir,
21-
mock_islink,
22-
):
12+
@patch("subvortex.auto_upgrader.src.github.os.readlink")
13+
@patch("subvortex.auto_upgrader.src.github.os.path.islink", return_value=True)
14+
@patch("subvortex.auto_upgrader.src.github.os.path.isfile", return_value=False)
15+
def test_get_local_version_symlink_returns_version(mock_isfile, mock_islink, mock_readlink):
2316
# Arrange
2417
github = Github()
25-
26-
# Simulate /var/tmp/subvortex directory listing
27-
mock_listdir.return_value = [
28-
"subvortex-1.2.3", # Valid version folder
29-
"subvortex-1.1.0", # Older valid version
30-
"random-folder", # Should be ignored
31-
]
32-
33-
# Simulate os.path.isdir always returning True
34-
mock_islink.side_effect = [False, False, False]
35-
mock_isdir.side_effect = [True, True, True, True]
36-
mock_isfile.side_effect = [False, False, False]
18+
mock_readlink.return_value = "/var/tmp/subvortex/subvortex-1.2.3"
3719

3820
# Act
3921
version = github.get_local_version()
4022

4123
# Assert
4224
assert version == "1.2.3"
43-
mock_listdir.assert_called_once_with("/var/tmp/subvortex")
44-
assert mock_isdir.call_count == 4
25+
mock_readlink.assert_called_once()
4526

4627

47-
@patch("subvortex.auto_upgrader.src.constants.SV_EXECUTION_METHOD", "service")
48-
@patch("subvortex.auto_upgrader.src.github.os.listdir")
49-
@patch("subvortex.auto_upgrader.src.github.os.path.isdir")
50-
def test_get_local_version_service_returns_none_when_no_valid_versions(
51-
mock_isdir, mock_listdir
52-
):
28+
@patch("subvortex.auto_upgrader.src.github.os.readlink")
29+
@patch("subvortex.auto_upgrader.src.github.os.path.islink", return_value=True)
30+
def test_get_local_version_symlink_invalid_path(mock_islink, mock_readlink):
5331
# Arrange
5432
github = Github()
55-
56-
# Simulate /var/tmp/subvortex directory listing with no valid versions
57-
mock_listdir.return_value = [
58-
"random-folder",
59-
"another-folder",
60-
"not-a-version",
61-
]
62-
63-
# Simulate os.path.isdir always returning True
64-
mock_isdir.return_value = True
33+
mock_readlink.return_value = "/some/unknown/path/no-version-here"
6534

6635
# Act
6736
version = github.get_local_version()
6837

6938
# Assert
7039
assert version is None
71-
mock_listdir.assert_called_once_with("/var/tmp/subvortex")
72-
assert mock_isdir.call_count == 4 # 1 check for base dir + 3 entries
7340

7441

75-
@patch("subvortex.auto_upgrader.src.constants.SV_EXECUTION_METHOD", "service")
76-
@patch("subvortex.auto_upgrader.src.github.os.path.isdir")
77-
def test_get_local_version_service_returns_none_when_asset_dir_does_not_exist(
78-
mock_isdir,
79-
):
42+
@patch("subvortex.auto_upgrader.src.github.os.readlink")
43+
@patch("subvortex.auto_upgrader.src.github.os.path.islink", return_value=True)
44+
@patch("subvortex.auto_upgrader.src.github.os.path.isfile", return_value=True)
45+
@patch("subvortex.auto_upgrader.src.github.os.remove")
46+
def test_get_local_version_symlink_force_marker(mock_remove, mock_isfile, mock_islink, mock_readlink):
8047
# Arrange
8148
github = Github()
82-
83-
# Simulate os.path.isdir always returning True
84-
mock_isdir.return_value = False
49+
mock_readlink.return_value = "/var/tmp/subvortex/subvortex-3.0.0a40"
8550

8651
# Act
8752
version = github.get_local_version()
8853

8954
# Assert
9055
assert version is None
91-
assert mock_isdir.call_count == 1
56+
mock_remove.assert_called_once()
9257

9358

9459
@patch("subvortex.auto_upgrader.src.github.requests.get")

0 commit comments

Comments
 (0)