Skip to content

Commit

Permalink
Merge pull request #234 from craig8/feature/v11-test-updates
Browse files Browse the repository at this point in the history
Feature/v11 test updates
  • Loading branch information
schandrika authored Oct 23, 2024
2 parents 8f3e912 + 1f417e7 commit 44e2927
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 192 deletions.
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-core"
version = "2.0.0rc1"
version = "2.0.0rc2"
description = "VOLTTRON™ is an open source platform for distributed sensing and control. The platform provides services for collecting and storing data from buildings and devices and provides an environment for developing applications which interact with that data."
authors = ["volttron <[email protected]>"]
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/volttron/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
from volttron.client.logs import setup_logging

__all__: List[str] = [
"AbstractAgent", "Core", "RPC", "Hello", "PeerList", "Ping", "PubSub", "Heartbeat", "Health", "ConfigStore", "Auth",
"Query", "setup_logging"
"Agent", "AbstractAgent", "Core", "RPC", "Hello", "PeerList", "Ping", "PubSub", "Heartbeat", "Health",
"ConfigStore", "Auth", "Query", "setup_logging"
]

_log = get_logger()
6 changes: 0 additions & 6 deletions src/volttron/client/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@

monkey.patch_all()

import logging

from volttron.utils import get_version

from volttron.client.logs import get_logger

_log = get_logger()

__version__ = get_version()

# def get_volttron_root():
Expand Down
58 changes: 7 additions & 51 deletions src/volttron/client/commands/auth_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@
import sys
import collections

#from volttron.platform import get_home, jsonapi
from volttron.utils import jsonapi
from volttron.client.known_identities import AUTH
from volttron.types.auth import AuthException

# from volttron.platform.agent.known_identities import AUTH
# from volttron.platform.auth import AuthEntry, AuthException
#from volttron.platform.control.control_utils import _ask_yes_no, _print_two_columns, _show_filtered_agents
#from volttron.platform.keystore import KeyStore, KnownHostsStore

# TODO Look and see what query subsystem is going to work
#from volttron.platform.vip.agent.subsystems.query import Query

Expand All @@ -45,52 +39,8 @@
_stdout = sys.stdout
_stderr = sys.stderr

# def gen_keypair(opts):
# keypair = KeyStore.generate_keypair_dict()
# _stdout.write("{}\n".format(jsonapi.dumps(keypair, indent=2)))
#
#
# def add_server_key(opts):
# store = KnownHostsStore()
# store.add(opts.host, opts.serverkey)
# _stdout.write("server key written to {}\n".format(store.filename))
#
#
# def list_known_hosts(opts):
# store = KnownHostsStore()
# entries = store.load()
# if entries:
# _print_two_columns(entries, "HOST", "CURVE KEY")
# else:
# _stdout.write("No entries in {}\n".format(store.filename))
#
#
# def remove_known_host(opts):
# store = KnownHostsStore()
# store.remove(opts.host)
# _stdout.write('host "{}" removed from {}\n'.format(opts.host, store.filename))

# def show_serverkey(opts):
# """
# write serverkey to standard out.
#
# return 0 if success, 1 if false
# """
# conn = opts.connection
# if not conn:
# _stderr.write("VOLTTRON is not running. This command "
# "requires VOLTTRON platform to be running\n")
# return 1
# q = Query(conn.server.core)
# pk = q.query("serverkey").get(timeout=2)
# del q
# if pk is not None:
# _stdout.write("%s\n" % pk)
# return 0
#
# return 1


# TODO: Re-evaluate for usage
def list_remotes(opts):
"""Lists remote certs and credentials.
Can be filters using the '--status' option, specifying
Expand All @@ -101,6 +51,7 @@ def list_remotes(opts):
status of the credential or cert (either APPROVED, DENIED, or PENDING)
"""

conn = opts.connection
if not conn:
_stderr.write("VOLTTRON is not running. This command "
Expand Down Expand Up @@ -189,6 +140,7 @@ def list_remotes(opts):
))


# TODO: Re-evaluate for usage
def approve_remote(opts):
"""Approves either a pending CSR or ZMQ credential.
The platform must be running for this command to succeed.
Expand All @@ -203,6 +155,7 @@ def approve_remote(opts):
conn.server.vip.rpc.call(AUTH, "approve_authorization", opts.user_id).get(timeout=4)


# TODO: Re-evaluate for usage
def deny_remote(opts):
"""Denies either a pending CSR or ZMQ credential.
The platform must be running for this command to succeed.
Expand All @@ -217,6 +170,7 @@ def deny_remote(opts):
conn.server.vip.rpc.call(AUTH, "deny_authorization", opts.user_id).get(timeout=4)


# TODO: Re-evaluate for usage
def delete_remote(opts):
"""Deletes either a pending CSR or ZMQ credential.
The platform must be running for this command to succeed.
Expand All @@ -239,6 +193,7 @@ def delete_remote(opts):
# _show_filtered_agents(opts, "PUBLICKEY", get_key)


# TODO: Re-evaluate for usage
def list_auth(opts, indices=None):
_stdout.write("This method is under development\n")
return
Expand All @@ -260,6 +215,7 @@ def list_auth(opts, indices=None):
# _stdout.write("No entries in {}\n".format(os.path.join(get_home(), "auth.json")))


# TODO: Re-evaluate for usage
def _ask_for_auth_fields(
domain=None,
address=None,
Expand Down
16 changes: 8 additions & 8 deletions src/volttron/client/commands/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ def _show_filtered_agents_status(opts, status_callback, health_callback, priorit
agent.uuid[:n],
agent.name,
name_width,
agent.vip_identity,
agent.identity,
identity_width,
agent.tag or "",
tag_width,
Expand Down Expand Up @@ -1490,17 +1490,17 @@ def _show_filtered_agents_status(opts, status_callback, health_callback, priorit
else:
json_obj = {}
for agent in agents:
json_obj[agent.vip_identity] = {
json_obj[agent.identity] = {
"agent_uuid": agent.uuid,
"name": agent.name,
"identity": agent.vip_identity,
"identity": agent.identity,
"agent_tag": agent.tag or "",
"status": status_callback(agent),
"health": health_callback(agent),
}
if cc.is_secure_mode():
json_obj[agent.vip_identity]["agent_user"] = (
agent.agent_user if json_obj[agent.vip_identity]["status"].startswith("running") else "")
json_obj[agent.identity]["agent_user"] = (
agent.agent_user if json_obj[agent.identity]["status"].startswith("running") else "")
_stdout.write(f"{jsonapi.dumps(json_obj, indent=2)}\n")


Expand Down Expand Up @@ -2417,9 +2417,9 @@ def add_parser(*args, **kwargs) -> argparse.ArgumentParser:

# with gevent.Timeout(opts.timeout):
# return opts.func(opts)
with gevent.Timeout(opts.timeout):
return opts.func(opts)
sys.exit(0)
# with gevent.Timeout(opts.timeout):
# return opts.func(opts)
# sys.exit(0)
try:
with gevent.Timeout(opts.timeout):
return opts.func(opts)
Expand Down
29 changes: 10 additions & 19 deletions src/volttron/client/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
T = TypeVar('T')


def factory_registration(registy_name: str,
protocol: T = None,
singleton: bool = True,
allow_many: bool = False):
def factory_registration(registry_name: str, protocol: T = None, singleton: bool = True, allow_many: bool = False):
"""
Create a factory registration function.
Expand Down Expand Up @@ -46,13 +43,11 @@ def register(cls, **kwargs):
lookup_key = cls.__name__

if lookup_key is None:
raise ValueError(
f"{cls.__name__} does not have an internal Meta class with identity or name.")
raise ValueError(f"{cls.__name__} does not have an internal Meta class with identity or name.")

# args = typing.get_args(protocol)
# if
if protocol is not None and not protocol in cls.__bases__ and not isinstance(
cls, protocol):
if protocol is not None and not protocol in cls.__bases__ and not isinstance(cls, protocol):
raise ValueError(f"{cls.__name__} doesn't implement {protocol}")

# if singleton:
Expand All @@ -67,19 +62,18 @@ def register(cls, **kwargs):
_log.warning("Lookup key is none!")
_log.debug(f"Registering {cls.__name__} as a {lookup_key}")
if lookup_key in register.registry:
raise ValueError(f"{lookup_key} already in register for {register.name}.")
_log.warning(f"{lookup_key} already in register for {register.registry_name}.")
#raise ValueError(f"{lookup_key} already in register for {register.registry_name}.")
register.registry[lookup_key] = cls
return cls

register.registy_name = registy_name
register.registry_name = registry_name
register.registry = {}
return register


core_builder = factory_registration("core_builder", protocol=CoreBuilder, singleton=True)
connection_builder = factory_registration("connection_bulider",
protocol=ConnectionBuilder,
singleton=True)
connection_builder = factory_registration("connection_bulider", protocol=ConnectionBuilder, singleton=True)
vctl_subparser = factory_registration("vctl_subparser", protocol=ControlParser)


Expand Down Expand Up @@ -118,8 +112,7 @@ def get_core_builder(name: Optional[str] = None, **kwargs) -> CoreBuilder:
zmq_core_builder_class = "ZmqCoreBuilder"
module = importlib.import_module(zmq_core_module)
__core_builder__ = __get_class_from_factory__(
registration=core_builder,
name=name) # __core_builder__ = getattr(module, zmq_core_builder_class)
registration=core_builder, name=name) # __core_builder__ = getattr(module, zmq_core_builder_class)

# __core_builder__ = importlib.import_module(new_package)

Expand All @@ -143,8 +136,7 @@ def get_server_credentials(address: Optional[str] = None) -> Credentials:
import os
from pathlib import Path

from volttron.types.auth import (Credentials, PKICredentials, PublicCredentials,
VolttronCredentials)
from volttron.types.auth import (Credentials, PKICredentials, PublicCredentials, VolttronCredentials)
from volttron.types.known_host import KnownHostProperties as known_host_properties
from volttron.client.known_identities import PLATFORM
from volttron.utils import jsonapi
Expand All @@ -153,8 +145,7 @@ def get_server_credentials(address: Optional[str] = None) -> Credentials:
if address is None or address.startswith('ipc'):
address = "@"

cred_path = Path(
os.environ['VOLTTRON_HOME']).expanduser() / f"credentials_store/{PLATFORM}.json"
cred_path = Path(os.environ['VOLTTRON_HOME']).expanduser() / f"credentials_store/{PLATFORM}.json"
return VolttronCredentials.load_from_file(cred_path)

new_path = Path(os.environ['VOLTTRON_HOME']) / "known_hosts.json"
Expand Down
7 changes: 5 additions & 2 deletions src/volttron/client/logs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import inspect
import logging
import warnings
from logging import Logger
import sys
import os

import volttron.utils.jsonapi as jsonapi
import volttron.utils as utils


def get_logger() -> Logger:
return utils.get_logger()
frame = inspect.stack()[1]
module = inspect.getmodule(frame[0])
return logging.getLogger(module.__name__)


def get_default_client_log_config(level=logging.DEBUG) -> dict:
Expand Down
Loading

0 comments on commit 44e2927

Please sign in to comment.