Skip to content

Commit 9f4148e

Browse files
authored
Merge pull request #74 from ClaireM2/issue/get_host_entry_by_ID
get host entry by ID, all excess, YML files removed
2 parents 4059546 + b5ac52f commit 9f4148e

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

inventory/hosts.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
all:
2+
hosts:
3+
test_instance:
4+
ansible_connection: ssh
5+
ansible_host: 172.18.65.126
6+
ansible_port: 22
7+
ansible_user: installer
8+
ansible_ssh_private_key_file: ~/.ssh/id_rsa
9+
id: test_instance
10+
volttron_home: ~/.volttron
11+
instance1:
12+
ansible_connection: ssh
13+
ansible_host: 172.18.65.126
14+
ansible_port: 22
15+
ansible_user: installer
16+
ansible_ssh_private_key_file: ~/.ssh/id_rsa
17+
id: instance1
18+
volttron_home: ~/.volt1
19+
20+
instance2:
21+
ansible_connection: ssh
22+
ansible_host: 172.18.65.126
23+
ansible_port: 22
24+
ansible_user: installer
25+
ansible_ssh_private_key_file: ~/.ssh/id_rsa
26+
id: instance2
27+
volttron_home: ~/.volt2
28+
29+
30+
31+

tests/backend/test_ansible_installation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import re
66
import os
7+
import yaml
78

89
def test_ansible_version():
910
"""Test that ansible version is >= 2.9"""
@@ -456,3 +457,26 @@ async def test_host_key_verification_with_ssh_options():
456457
known_hosts.unlink()
457458
if backup_path and backup_path.exists():
458459
backup_path.rename(known_hosts)
460+
461+
@pytest.mark.asyncio
462+
async def test_host_location_given_host_id():
463+
test_pass_existence = False
464+
#gets a known test case
465+
with open(Path.home() /'.volttron_installer_data/inventory.yml', 'r') as file:
466+
data = yaml.safe_load(file)
467+
468+
host_id = 'test_host' #set existing host id
469+
temp_string = str(data)
470+
471+
assert host_id in temp_string
472+
473+
if host_id in temp_string:
474+
user=data['all']['hosts'][host_id]['ansible_user']
475+
port=data['all']['hosts'][host_id]['ansible_port']
476+
477+
if 'ansible_password' in temp_string:
478+
test_pass_existence = True
479+
480+
assert test_pass_existence == False
481+
assert user == "user"#is proper information from test_host
482+
assert port == 22

volttron_installer/backend/services/ansible_service.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .. services.platform_service import get_platform_service, PlatformService
88
import json
99
import os
10+
import yaml
1011
from loguru import logger
1112

1213
class AnsibleService:
@@ -271,9 +272,16 @@ async def get_host_entry_by_id(self, host_id: str) -> 'HostEntry':
271272
Returns:
272273
HostEntry object
273274
"""
275+
with open(Path.home()/".volttron_user_data/inventory.yml", "r") as file:
276+
data = yaml.safe_load(file)
274277
# Implement the logic to retrieve the HostEntry by its ID
275278
# This is a placeholder implementation
276-
return HostEntry(host="example.com", user="user", port=22, password="password")
279+
tmp_str = str(data)
280+
if "ansible_password" in tmp_str:
281+
password = data['all']['hosts'][host_id]['ansible_password']
282+
return HostEntry(host=host_id, user=data['all']['hosts'][host_id]['ansible_user'], port=data['all']['hosts'][host_id]['ansible_port'], password = data['all']['hosts'][host_id]['ansible_password'])
283+
284+
return HostEntry(host=host_id, user=data['all']['hosts'][host_id]['ansible_user'], port=data['all']['hosts'][host_id]['ansible_port'])
277285

278286
__ansible_service__ = AnsibleService()
279287

volttron_installer/pages/platform_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def configuration_tab_content() -> rx.Component:
170170
form_entry.form_entry(
171171
"Host",
172172
rx.input(
173-
value= working_platform.host.id,
173+
value= working_platform.host.ansible_host,
174174
on_change=lambda v: State.update_detail("id", v),
175175
size="3",
176176
required=True,

0 commit comments

Comments
 (0)