Skip to content

Commit a5e49b3

Browse files
fix test check for successful diagnose output
1 parent 4020788 commit a5e49b3

File tree

2 files changed

+44
-47
lines changed

2 files changed

+44
-47
lines changed

integration/scripts/test_configure.py

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
#!/usr/bin/env python3
2+
3+
from fabric import Result
4+
25
import os
36
import sys
47
import re
5-
import time
8+
import time
69
import utils as u
710

11+
12+
DIAGNOSE_PASSED_RE = re.compile(r'All \d+ checks passed')
13+
14+
def _diagnose_result_is_successful(result: Result) -> bool:
15+
return DIAGNOSE_PASSED_RE.search(result.stdout) is not None
16+
817
@u.print_test_decorator
9-
def run_test_windows(remote_host: u.Host, env_vars: dict) -> None:
18+
def run_test_windows(remote_host: u.Host, env_vars: dict) -> None:
1019

1120
"""
12-
Test to validate connection of observe-agent to Observe
21+
Test to validate connection of observe-agent to Observe
1322
1423
Args:
15-
remote_host (Host): instance to ssh into
24+
remote_host (Host): instance to ssh into
1625
env_vars (dict): environment variables passed into for testing
1726
1827
Raises:
19-
ValueError: Something failed with initial config or observe-agent -> observe connection
28+
ValueError: Something failed with initial config or observe-agent -> observe connection
2029
"""
21-
30+
2231
init_command='Set-Location "C:\Program Files\Observe\observe-agent"; ./observe-agent init-config --token {} --observe_url {}'.format(env_vars["observe_token"], env_vars["observe_url"])
2332
diagnose_command='Set-Location "C:\Program Files\Observe\observe-agent"; ./observe-agent diagnose'
24-
25-
#Set up correct config with observe url and token
33+
34+
#Set up correct config with observe url and token
2635
result = remote_host.run_command(init_command)
2736

2837
#Check diagnose command
2938
result = remote_host.run_command(diagnose_command)
30-
observe_val = False
31-
for line in result.stdout.splitlines():
32-
if "Request to test URL responded with response code 200" in line:
33-
print (" ✅ observe-agent -> observe validation passed! ")
34-
observe_val = True
35-
break
36-
if not observe_val:
39+
if _diagnose_result_is_successful(result):
40+
print (" ✅ observe-agent -> observe validation passed! ")
41+
else:
3742
print(result)
3843
raise ValueError(f"❌ Failed: observe-agent -> observe validation")
39-
40-
pass
44+
45+
pass
4146

4247
@u.print_test_decorator
43-
def run_test_docker(remote_host: u.Host, env_vars: dict) -> None:
48+
def run_test_docker(remote_host: u.Host, env_vars: dict) -> None:
4449
docker_prefix='sudo docker run \
4550
--mount type=bind,source=/proc,target=/hostfs/proc,readonly \
4651
--mount type=bind,source=/snap,target=/hostfs/snap,readonly \
@@ -50,71 +55,63 @@ def run_test_docker(remote_host: u.Host, env_vars: dict) -> None:
5055
--mount type=bind,source=$(pwd)/observe-agent.yaml,target=/etc/observe-agent/observe-agent.yaml \
5156
--pid host \
5257
$(sudo docker images --format "{{.Repository}}:{{.Tag}}" | grep SNAPSHOT)'
53-
58+
5459
init_command='init-config --token {} --observe_url {}'.format(env_vars["observe_token"], env_vars["observe_url"])
5560
diagnose_command='diagnose'
5661

57-
#Set up correct config with observe url and token
62+
#Set up correct config with observe url and token
5863
result = remote_host.run_command(docker_prefix + ' ' + init_command)
5964

6065
#Check diagnose command
6166
result = remote_host.run_command(docker_prefix + ' ' + diagnose_command)
62-
observe_val = False
63-
for line in result.stdout.splitlines():
64-
if "Request to test URL responded with response code 200" in line:
65-
print (" ✅ observe-agent -> observe validation passed! ")
66-
observe_val = True
67-
break
68-
if not observe_val:
67+
if _diagnose_result_is_successful(result):
68+
print (" ✅ observe-agent -> observe validation passed! ")
69+
else:
6970
print(result)
7071
raise ValueError(f"❌ Failed: observe-agent -> observe validation")
7172

7273

7374
pass
7475

7576
@u.print_test_decorator
76-
def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
77+
def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
7778

7879
"""
79-
Test to validate connection of observe-agent to Observe
80+
Test to validate connection of observe-agent to Observe
8081
8182
Args:
82-
remote_host (Host): instance to ssh into
83+
remote_host (Host): instance to ssh into
8384
env_vars (dict): environment variables passed into for testing
8485
8586
Raises:
86-
ValueError: Something failed with initial config or observe-agent -> observe connection
87+
ValueError: Something failed with initial config or observe-agent -> observe connection
8788
"""
8889

8990
init_command='sudo observe-agent init-config --token {} --observe_url {}'.format(env_vars["observe_token"], env_vars["observe_url"])
9091
diagnose_command='observe-agent diagnose'
9192

92-
#Set up correct config with observe url and token
93+
#Set up correct config with observe url and token
9394
result = remote_host.run_command(init_command)
9495

9596
#Check diagnose command
9697
result = remote_host.run_command(diagnose_command)
97-
observe_val = False
98-
for line in result.stdout.splitlines():
99-
if "Request to test URL responded with response code 200" in line:
100-
print (" ✅ observe-agent -> observe validation passed! ")
101-
observe_val = True
102-
break
103-
if not observe_val:
98+
if _diagnose_result_is_successful(result):
99+
print (" ✅ observe-agent -> observe validation passed! ")
100+
else:
104101
print(result)
105102
raise ValueError(f"❌ Failed: observe-agent -> observe validation")
106-
103+
107104

108105
if __name__ == '__main__':
109106

110107
env_vars = u.get_env_vars(need_observe=True)
111108
remote_host = u.Host(host_ip=env_vars["host"],
112109
username=env_vars["user"],
113110
key_file_path=env_vars["key_filename"],
114-
password=env_vars["password"])
115-
116-
#Test SSH Connection before starting test of interest
117-
remote_host.test_conection(int(env_vars["machine_config"]["sleep"]))
111+
password=env_vars["password"])
112+
113+
#Test SSH Connection before starting test of interest
114+
remote_host.test_conection(int(env_vars["machine_config"]["sleep"]))
118115

119116
if "redhat" in env_vars["machine_config"]["distribution"] or "debian" in env_vars["machine_config"]["distribution"]:
120117
run_test_linux(remote_host, env_vars)
@@ -123,6 +120,6 @@ def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
123120
elif "docker" in env_vars["machine_config"]["distribution"]:
124121
run_test_docker(remote_host, env_vars)
125122

126-
pass
123+
pass
127124

128125

integration/scripts/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from socket import error as socket_error
22

3-
from fabric import Connection
3+
from fabric import Connection, Result
44
from paramiko.ssh_exception import AuthenticationException, NoValidConnectionsError
55

66
import os
@@ -136,7 +136,7 @@ def _get_connection(self) -> Connection:
136136
return Connection(host=self.host_ip, user=self.username, port=22,
137137
connect_kwargs=connect_kwargs)
138138

139-
def run_command(self, command):
139+
def run_command(self, command) -> Result:
140140
try:
141141
with self._get_connection() as connection:
142142
print('Running `{0}` on {1}'.format(command, self.host_ip))

0 commit comments

Comments
 (0)