Skip to content

Commit

Permalink
Added install_agent_remote, which contains all install_agent_vctl fun…
Browse files Browse the repository at this point in the history
…ctionality.

Modified install_agent_vctl to be a wrapper. This allows isntall_agent_remote
to return the agent uuid.
Updated install_agent on VCP to include additional optional fileargs to
account for all install_agent_remote options.
  • Loading branch information
sgilbride committed Jan 12, 2022
1 parent 0d69d67 commit c5c0ccb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
4 changes: 3 additions & 1 deletion services/core/VolttronCentral/tests/test_webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ def test_installagent(auto_registered_local):
print(f"Package is {hold}")
filestr = "base64,"+base64.b64encode(hold).decode('utf-8')
print(f"file string is {filestr}")
vip_id = f"test_listener_{random.randint(1,100000)}"
file_props = dict(
file_name=os.path.basename(agent_wheel),
file=filestr,
vip_identity='bar.full.{}'.format(random.randint(1, 100000))
vip_identity=vip_id,
force=True
)
gevent.sleep(5)
platform = webapi.list_platforms()[0]
Expand Down
28 changes: 18 additions & 10 deletions services/core/VolttronCentralPlatform/vcplatform/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from enum import Enum

from volttron.platform.agent import utils
from volttron.platform.install_agents import install_agent_vctl
from volttron.platform.install_agents import install_agent_remote

utils.setup_logging()
_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -1149,6 +1149,14 @@ def _install_agent(self, fileargs):
try:
_log.debug('Installing agent FILEARGS: {}'.format(fileargs))
vip_identity = fileargs.get('vip_identity', None)
agent_tag = fileargs.get('tag', None)
agent_enable = fileargs.get('enable', None)
agent_start = fileargs.get('start', None)
agent_priority = fileargs.get('priority', -1)
agent_force = fileargs.get('force', False)
agent_csv = fileargs.get('csv', None)
agent_json = fileargs.get('json', None)
agent_st = fileargs.get('st', 5)
if 'local' in fileargs:
path = fileargs['file_name']
else:
Expand All @@ -1169,16 +1177,16 @@ def _install_agent(self, fileargs):
opts = Namespace(connection=self._vc_connection,
install_path=path,
vip_identity=vip_identity,
tag=None,
enable=None,
start=None,
priority=-1,
force=False,
csv=None,
json=None,
st=5
tag=agent_tag,
enable=agent_enable,
start=agent_start,
priority=agent_priority,
force=agent_force,
csv=agent_csv,
json=agent_json,
st=agent_st
)
uuid = install_agent_vctl(opts)
uuid = install_agent_remote(opts)
result = dict(uuid=uuid)
except Exception as e:
err_str = "EXCEPTION: " + str(e)
Expand Down
29 changes: 23 additions & 6 deletions volttron/platform/install_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def install_agent_directory(opts, publickey=None, secretkey=None):
if agent_default_id_file.is_file():
with open(str(agent_default_id_file)) as fin:
opts.vip_identity = fin.read().strip()
agent_uuid = None

# Verify and load agent_config up from the opts. agent_config will
# be a yaml config file.
Expand Down Expand Up @@ -141,7 +140,8 @@ def install_agent_directory(opts, publickey=None, secretkey=None):
except FileNotFoundError:
raise InstallRuntimeError(f"File not found: {config_file}")

_send_and_intialize_agent(opts, publickey, secretkey)
agent_uuid = _send_and_intialize_agent(opts, publickey, secretkey)
return agent_uuid


def _send_and_intialize_agent(opts, publickey, secretkey):
Expand Down Expand Up @@ -216,8 +216,21 @@ def _send_and_intialize_agent(opts, publickey, secretkey):

def install_agent_vctl(opts, publickey=None, secretkey=None, callback=None):
"""
The `install_agent_vctl` function is called from the volttron-ctl or vctl install
sub-parser.
The `install_agent_vctl` function is called from the volttron-ctl or
vctl install sub-parser.
"""

agent_uuid = install_agent_remote(opts, publickey=publickey,
secretkey=secretkey, callback=callback)
if agent_uuid:
return 0
else:
return 1


def install_agent_remote(opts, publickey=None, secretkey=None, callback=None):
"""
Used by install_agent_vctl and vc for installing agents.
"""
try:
install_path = opts.install_path
Expand All @@ -232,16 +245,20 @@ def install_agent_vctl(opts, publickey=None, secretkey=None, callback=None):
opts.connection.kill()
raise InstallRuntimeError("Identity already exists. Pass --force option to re-install.")

agent_uuid = None

if os.path.isdir(install_path):
install_agent_directory(opts, publickey, secretkey)
agent_uuid = install_agent_directory(opts, publickey, secretkey)
if opts.connection is not None:
opts.connection.kill()
else:
opts.package = opts.install_path
if not os.path.exists(opts.package):
opts.connection.kill()
raise FileNotFoundError(f"Invalid file {opts.package}")
_send_and_intialize_agent(opts, publickey, secretkey)
agent_uuid = _send_and_intialize_agent(opts, publickey, secretkey)

return agent_uuid


def send_agent(connection: "ControlConnection", wheel_file: str, vip_identity: str , publickey: str,
Expand Down

0 comments on commit c5c0ccb

Please sign in to comment.