Skip to content

Commit 38f7215

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

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

integration/scripts/test_configure.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,48 @@
22
import os
33
import sys
44
import re
5-
import time
5+
import time
66
import utils as u
77

8+
def _diagnose_result_is_successful(result: u.Result) -> bool:
9+
test_re = re.compile(r'All \d+ checks passed')
10+
for line in result.stdout.splitlines():
11+
if test_re.search(line) is not None:
12+
return True
13+
return False
14+
815
@u.print_test_decorator
9-
def run_test_windows(remote_host: u.Host, env_vars: dict) -> None:
16+
def run_test_windows(remote_host: u.Host, env_vars: dict) -> None:
1017

1118
"""
12-
Test to validate connection of observe-agent to Observe
19+
Test to validate connection of observe-agent to Observe
1320
1421
Args:
15-
remote_host (Host): instance to ssh into
22+
remote_host (Host): instance to ssh into
1623
env_vars (dict): environment variables passed into for testing
1724
1825
Raises:
19-
ValueError: Something failed with initial config or observe-agent -> observe connection
26+
ValueError: Something failed with initial config or observe-agent -> observe connection
2027
"""
21-
28+
2229
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"])
2330
diagnose_command='Set-Location "C:\Program Files\Observe\observe-agent"; ./observe-agent diagnose'
24-
25-
#Set up correct config with observe url and token
31+
32+
#Set up correct config with observe url and token
2633
result = remote_host.run_command(init_command)
2734

2835
#Check diagnose command
2936
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:
37+
if _diagnose_result_is_successful(result):
38+
print (" ✅ observe-agent -> observe validation passed! ")
39+
else:
3740
print(result)
3841
raise ValueError(f"❌ Failed: observe-agent -> observe validation")
39-
40-
pass
42+
43+
pass
4144

4245
@u.print_test_decorator
43-
def run_test_docker(remote_host: u.Host, env_vars: dict) -> None:
46+
def run_test_docker(remote_host: u.Host, env_vars: dict) -> None:
4447
docker_prefix='sudo docker run \
4548
--mount type=bind,source=/proc,target=/hostfs/proc,readonly \
4649
--mount type=bind,source=/snap,target=/hostfs/snap,readonly \
@@ -50,71 +53,63 @@ def run_test_docker(remote_host: u.Host, env_vars: dict) -> None:
5053
--mount type=bind,source=$(pwd)/observe-agent.yaml,target=/etc/observe-agent/observe-agent.yaml \
5154
--pid host \
5255
$(sudo docker images --format "{{.Repository}}:{{.Tag}}" | grep SNAPSHOT)'
53-
56+
5457
init_command='init-config --token {} --observe_url {}'.format(env_vars["observe_token"], env_vars["observe_url"])
5558
diagnose_command='diagnose'
5659

57-
#Set up correct config with observe url and token
60+
#Set up correct config with observe url and token
5861
result = remote_host.run_command(docker_prefix + ' ' + init_command)
5962

6063
#Check diagnose command
6164
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:
65+
if _diagnose_result_is_successful(result):
66+
print (" ✅ observe-agent -> observe validation passed! ")
67+
else:
6968
print(result)
7069
raise ValueError(f"❌ Failed: observe-agent -> observe validation")
7170

7271

7372
pass
7473

7574
@u.print_test_decorator
76-
def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
75+
def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
7776

7877
"""
79-
Test to validate connection of observe-agent to Observe
78+
Test to validate connection of observe-agent to Observe
8079
8180
Args:
82-
remote_host (Host): instance to ssh into
81+
remote_host (Host): instance to ssh into
8382
env_vars (dict): environment variables passed into for testing
8483
8584
Raises:
86-
ValueError: Something failed with initial config or observe-agent -> observe connection
85+
ValueError: Something failed with initial config or observe-agent -> observe connection
8786
"""
8887

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

92-
#Set up correct config with observe url and token
91+
#Set up correct config with observe url and token
9392
result = remote_host.run_command(init_command)
9493

9594
#Check diagnose command
9695
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:
96+
if _diagnose_result_is_successful(result):
97+
print (" ✅ observe-agent -> observe validation passed! ")
98+
else:
10499
print(result)
105100
raise ValueError(f"❌ Failed: observe-agent -> observe validation")
106-
101+
107102

108103
if __name__ == '__main__':
109104

110105
env_vars = u.get_env_vars(need_observe=True)
111106
remote_host = u.Host(host_ip=env_vars["host"],
112107
username=env_vars["user"],
113108
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"]))
109+
password=env_vars["password"])
110+
111+
#Test SSH Connection before starting test of interest
112+
remote_host.test_conection(int(env_vars["machine_config"]["sleep"]))
118113

119114
if "redhat" in env_vars["machine_config"]["distribution"] or "debian" in env_vars["machine_config"]["distribution"]:
120115
run_test_linux(remote_host, env_vars)
@@ -123,6 +118,6 @@ def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
123118
elif "docker" in env_vars["machine_config"]["distribution"]:
124119
run_test_docker(remote_host, env_vars)
125120

126-
pass
121+
pass
127122

128123

0 commit comments

Comments
 (0)