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

Bug/51 no volttron log #52

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "volttron-testing"
version = "0.5.0rc0"
version = "0.5.0rc1"
description = "The volttron-testing library contains classes and utilities for interacting with a VOLTTRON instance."
authors = ["VOLTTRON Team <[email protected]>"]
license = "Apache License 2.0"
Expand Down
12 changes: 3 additions & 9 deletions src/volttrontesting/platformwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,7 @@ def _setup_testing_environment(self):
except CalledProcessError as e:
print(f"Error:\n{e.output}")
raise
print(output)
print("Woot env installed!")
self.logit(output)

def startup_platform(self, timeout:int = 30):
"""
Expand Down Expand Up @@ -704,7 +703,7 @@ def capture_stdout(queue: Queue, process):
if self.is_running():
raise PlatformWrapperError("Already running platform")

cmd = [self._volttron_exe, '-vv'] # , "-l", self._log_path]
cmd = [self._volttron_exe, '-vv', "-l", self._log_path]

from pprint import pprint
print('process environment: ')
Expand Down Expand Up @@ -1422,7 +1421,7 @@ def cleanup(self):
self.logit("Skipping cleanup")
return

shutil.rmtree(self.volttron_home, ignore_errors=True)
self.__remove_environment_directory__()


def shutdown_platform(self):
Expand Down Expand Up @@ -1500,11 +1499,6 @@ def __str__(self):
data.append('volttron_home: {}'.format(self.volttron_home))
return '\n'.join(data)

def cleanup(self):
if self.is_running():
raise ValueError("Shutdown platform before cleaning directory.")
self.__remove_environment_directory__()

def restart_agent(self, agent_uuid: AgentUUID):
cmd = f"vctl restart {agent_uuid}"
self._virtual_env.run(cmd, capture=True, env=self._platform_environment)
Expand Down
124 changes: 82 additions & 42 deletions tests/test_platformwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,36 @@


def test_can_enable_sys_queue(get_pyproject_toml):
options = create_server_options()

p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, enable_sys_queue=True)
p = None
try:
options = create_server_options()

for data in p.pop_stdout_queue():
assert data
p.shutdown_platform()
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, enable_sys_queue=True)

p.cleanup()
for data in p.pop_stdout_queue():
assert data
p.shutdown_platform()
finally:
p.cleanup()


def test_value_error_raised_sys_queue(get_pyproject_toml):
options = create_server_options()

p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml)

with pytest.raises(ValueError):
for data in p.pop_stdout_queue():
pass
p = None
try:
options = create_server_options()

with pytest.raises(ValueError):
for data in p.clear_stdout_queue():
pass
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml)

p.shutdown_platform()
with pytest.raises(ValueError):
for data in p.pop_stdout_queue():
pass

p.cleanup()
with pytest.raises(ValueError):
for data in p.clear_stdout_queue():
pass
finally:
p.shutdown_platform()
p.cleanup()


def test_install_library(get_pyproject_toml):
Expand Down Expand Up @@ -88,35 +91,72 @@ def test_will_update_environ():
# False
])
def test_can_create_platform_wrapper(auth_enabled: bool, get_pyproject_toml: Path):
options = create_server_options()
options.auth_enabled = auth_enabled
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml)
p = None
try:
assert p.is_running()
assert p.volttron_home.startswith("/tmp/tmp")
finally:
p.shutdown_platform()
options = create_server_options()
options.auth_enabled = auth_enabled
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml)
try:
assert p.is_running()
assert p.volttron_home.startswith("/tmp/tmp")
finally:
p.shutdown_platform()

assert not p.is_running()
p.cleanup()
assert not p.is_running()
finally:
p.__remove_environment_directory__()

def test_not_cleanup_works(get_pyproject_toml: Path):
options = create_server_options()
options.auth_enabled = True
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, skip_cleanup=True)
p = None
try:
assert p.is_running()
assert p.volttron_home.startswith("/tmp/tmp")
agent_uuid = p.install_from_github(org="eclipse-volttron", repo="volttron-listener", branch="v10")
assert agent_uuid
options = create_server_options()
options.auth_enabled = True
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, skip_cleanup=True)
try:
assert p.is_running()
assert p.volttron_home.startswith("/tmp/tmp")
agent_uuid = p.install_from_github(org="eclipse-volttron", repo="volttron-listener", branch="v10")
assert agent_uuid
finally:
if p:
p.shutdown_platform()
assert Path(p.volttron_home).exists()
for d in p._added_from_github:
assert d.exists()
assert not p.is_running()
p.cleanup()
finally:
if p:
p.shutdown_platform()
assert Path(p.volttron_home).exists()
for d in p._added_from_github:
assert d.exists()
assert not p.is_running()
p.cleanup()
p.__remove_environment_directory__()

def test_not_cleanup_works_with_env_debug(get_pyproject_toml: Path, monkeypatch):
p = None
try:
monkeypatch.setenv("DEBUG", "1")
assert os.environ['DEBUG'] == "1"

options = create_server_options()
options.auth_enabled = True
p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, skip_cleanup=True)
try:
assert p.is_running()
assert p.volttron_home.startswith("/tmp/tmp")
agent_uuid = p.install_from_github(org="eclipse-volttron", repo="volttron-listener", branch="v10")
assert agent_uuid
finally:
if p:
p.shutdown_platform()
assert Path(p.volttron_home).exists()
for d in p._added_from_github:
assert d.exists()
assert not p.is_running()
# volttron.log is outside volttron home for these.
assert (Path(p.volttron_home).parent / "volttron.log").exists()
p.cleanup()
assert (Path(p.volttron_home).parent / "volttron.log").exists()
finally:
# Use the internal really clean up everything command.
p.__remove_environment_directory__()


def test_fixture_creation(volttron_instance):
vi = volttron_instance
Expand Down
Loading