Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine(v3.7.x): refine bootctrl.common CMDHelperFuncs #289

Merged
merged 29 commits into from
Apr 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
00f40fc
common.subprocess_*: now become a single function
Bodong-Yang Apr 21, 2024
f94ade5
grub: integrate updated CMDHelperFuncs
Bodong-Yang Apr 21, 2024
2cf5f0c
rpi_boot: integrate new CMDHelperFuncs
Bodong-Yang Apr 21, 2024
13f7f9a
remove cboot
Bodong-Yang Apr 21, 2024
751dfb0
remove cboot
Bodong-Yang Apr 21, 2024
3597bf9
boot_control.common: refactor
Bodong-Yang Apr 21, 2024
5134c8c
remove boot_control.errors as not used
Bodong-Yang Apr 21, 2024
796c5b8
minor typing
Bodong-Yang Apr 21, 2024
2f8e098
boot_control.selecter: minor fix
Bodong-Yang Apr 21, 2024
b3aceae
rpi_boot: check new CMDHelperFunc integration again
Bodong-Yang Apr 21, 2024
d27f9bb
grub: use mp_control's prepare_standby_dev
Bodong-Yang Apr 21, 2024
e7266ed
test-grub: minor fix
Bodong-Yang Apr 21, 2024
374abe7
ota_client_stub: minor fix
Bodong-Yang Apr 21, 2024
36a6bb4
bootctrl.common: add -F option to mkfs.ext4
Bodong-Yang Apr 21, 2024
616e90f
bootctrl.common: subprocess_check_output now has default=""
Bodong-Yang Apr 21, 2024
d815fb5
bootctrl.common.cmdhelperfuncs: now all funcs except reboot by defaul…
Bodong-Yang Apr 21, 2024
d4bffdf
bootctrl.common.cmdhelperfuncs: refine mount related
Bodong-Yang Apr 21, 2024
b0bce15
minor update
Bodong-Yang Apr 21, 2024
58a54a3
common.subprocess_*: refine
Bodong-Yang Apr 21, 2024
fc3641c
common.subprocess_*: minor fix
Bodong-Yang Apr 21, 2024
fa25c11
fix ota_client_stub
Bodong-Yang Apr 21, 2024
736e4fc
otaclient_stub: fix related to mount external cache storage
Bodong-Yang Apr 21, 2024
afe4f82
otaclient_stub: fix related to mount external cache storage
Bodong-Yang Apr 22, 2024
9220161
common: minor docstring update
Bodong-Yang Apr 24, 2024
f73f08e
common: update copytree_identical, now it will create dst if dst does…
Bodong-Yang Apr 24, 2024
afcbf33
(WIP) update docstring of cmdhelperfuncs
Bodong-Yang Apr 24, 2024
192e36b
boot_control.common: update a lot of docstrings
Bodong-Yang Apr 25, 2024
d157e60
fix typo
Bodong-Yang Apr 25, 2024
7a483ad
test_common: refine subprocess_* methods test
Bodong-Yang Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test_common: refine subprocess_* methods test
  • Loading branch information
Bodong-Yang committed Apr 25, 2024
commit 7a483ade8e1754a9533020d554ee03f0e03b1cbe
94 changes: 57 additions & 37 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import pytest
import random
import logging
from concurrent.futures import ThreadPoolExecutor
from functools import partial
from hashlib import sha256
from multiprocessing import Process
Expand All @@ -38,11 +37,10 @@
subprocess_call,
subprocess_check_output,
verify_file,
wait_with_backoff,
write_str_to_file_sync,
)
from tests.utils import compare_dir
from tests.conftest import cfg, run_http_server
from tests.conftest import run_http_server

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -97,39 +95,6 @@ def test_write_to_file_sync(tmp_path: Path):
assert _path.read_text() == _TEST_FILE_CONTENT


def test_subprocess_call():
with pytest.raises(subprocess.CalledProcessError) as e:
subprocess_call("ls /non-existed", raise_exception=True)
_origin_e = e.value
assert _origin_e.returncode == 2
assert (
_origin_e.stderr.decode().strip()
== "ls: cannot access '/non-existed': No such file or directory"
)

subprocess_call("ls /non-existed", raise_exception=False)


def test_subprocess_check_output(file_t: Tuple[str, str, int]):
_path, _, _ = file_t
with pytest.raises(subprocess.CalledProcessError) as e:
subprocess_check_output("cat /non-existed", raise_exception=True)
_origin_e = e.value
assert _origin_e.returncode == 1
assert (
_origin_e.stderr.decode().strip()
== "cat: /non-existed: No such file or directory"
)

assert (
subprocess_check_output(
"cat /non-existed", raise_exception=False, default="abc"
)
== "abc"
)
assert subprocess_check_output(f"cat {_path}") == _TEST_FILE_CONTENT


class Test_copytree_identical:
@pytest.fixture(autouse=True)
def setup(self, tmp_path: Path):
Expand Down Expand Up @@ -266,7 +231,7 @@ def test_symlink_to_directory(self, tmp_path: Path):


class _RetryTaskMapTestErr(Exception):
...
""""""


class TestRetryTaskMap:
Expand Down Expand Up @@ -445,3 +410,58 @@ def test_probing_delayed_online_server(self, subprocess_launch_server):
)
# probing should cost at least <LAUNCH_DELAY> seconds
assert int(time.time()) >= start_time + self.LAUNCH_DELAY


class TestSubprocessCall:
TEST_FILE_CONTENTS = "test file contents"

@pytest.fixture(autouse=True)
def setup_test(self, tmp_path: Path):
test_file = tmp_path / "test_file"
test_file.write_text(self.TEST_FILE_CONTENTS)
self.existed_file = test_file
self.non_existed_file = tmp_path / "non_existed_file"

def test_subprocess_call_failed(self):
cmd = ["ls", str(self.non_existed_file)]
with pytest.raises(subprocess.CalledProcessError) as e:
subprocess_call(cmd, raise_exception=True)
origin_exc: subprocess.CalledProcessError = e.value

assert origin_exc.returncode == 2
assert (
origin_exc.stderr.decode().strip()
== f"ls: cannot access '{self.non_existed_file}': No such file or directory"
)

# test exception supressed
subprocess_call(cmd, raise_exception=False)

def test_subprocess_call_succeeded(self):
cmd = ["ls", str(self.existed_file)]
subprocess_call(cmd, raise_exception=True)

def test_subprocess_check_output_failed(self):
cmd = ["cat", str(self.non_existed_file)]

with pytest.raises(subprocess.CalledProcessError) as e:
subprocess_check_output(cmd, raise_exception=True)
origin_exc: subprocess.CalledProcessError = e.value
assert origin_exc.returncode == 1
assert (
origin_exc.stderr.decode().strip()
== f"cat: {self.non_existed_file}: No such file or directory"
)

# test exception supressed
default_value = "test default_value"
output = subprocess_check_output(
cmd, default=default_value, raise_exception=False
)
assert output == default_value

def test_subprocess_check_output_succeeded(self):
cmd = ["cat", str(self.existed_file)]

output = subprocess_check_output(cmd, raise_exception=True)
assert output == self.TEST_FILE_CONTENTS
Loading