2
2
import os
3
3
import sys
4
4
import re
5
- import time
5
+ import time
6
6
import utils as u
7
7
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
+
8
15
@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 :
10
17
11
18
"""
12
- Test to validate connection of observe-agent to Observe
19
+ Test to validate connection of observe-agent to Observe
13
20
14
21
Args:
15
- remote_host (Host): instance to ssh into
22
+ remote_host (Host): instance to ssh into
16
23
env_vars (dict): environment variables passed into for testing
17
24
18
25
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
20
27
"""
21
-
28
+
22
29
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" ])
23
30
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
26
33
result = remote_host .run_command (init_command )
27
34
28
35
#Check diagnose command
29
36
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 :
37
40
print (result )
38
41
raise ValueError (f"❌ Failed: observe-agent -> observe validation" )
39
-
40
- pass
42
+
43
+ pass
41
44
42
45
@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 :
44
47
docker_prefix = 'sudo docker run \
45
48
--mount type=bind,source=/proc,target=/hostfs/proc,readonly \
46
49
--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:
50
53
--mount type=bind,source=$(pwd)/observe-agent.yaml,target=/etc/observe-agent/observe-agent.yaml \
51
54
--pid host \
52
55
$(sudo docker images --format "{{.Repository}}:{{.Tag}}" | grep SNAPSHOT)'
53
-
56
+
54
57
init_command = 'init-config --token {} --observe_url {}' .format (env_vars ["observe_token" ], env_vars ["observe_url" ])
55
58
diagnose_command = 'diagnose'
56
59
57
- #Set up correct config with observe url and token
60
+ #Set up correct config with observe url and token
58
61
result = remote_host .run_command (docker_prefix + ' ' + init_command )
59
62
60
63
#Check diagnose command
61
64
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 :
69
68
print (result )
70
69
raise ValueError (f"❌ Failed: observe-agent -> observe validation" )
71
70
72
71
73
72
pass
74
73
75
74
@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 :
77
76
78
77
"""
79
- Test to validate connection of observe-agent to Observe
78
+ Test to validate connection of observe-agent to Observe
80
79
81
80
Args:
82
- remote_host (Host): instance to ssh into
81
+ remote_host (Host): instance to ssh into
83
82
env_vars (dict): environment variables passed into for testing
84
83
85
84
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
87
86
"""
88
87
89
88
init_command = 'sudo observe-agent init-config --token {} --observe_url {}' .format (env_vars ["observe_token" ], env_vars ["observe_url" ])
90
89
diagnose_command = 'observe-agent diagnose'
91
90
92
- #Set up correct config with observe url and token
91
+ #Set up correct config with observe url and token
93
92
result = remote_host .run_command (init_command )
94
93
95
94
#Check diagnose command
96
95
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 :
104
99
print (result )
105
100
raise ValueError (f"❌ Failed: observe-agent -> observe validation" )
106
-
101
+
107
102
108
103
if __name__ == '__main__' :
109
104
110
105
env_vars = u .get_env_vars (need_observe = True )
111
106
remote_host = u .Host (host_ip = env_vars ["host" ],
112
107
username = env_vars ["user" ],
113
108
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" ]))
118
113
119
114
if "redhat" in env_vars ["machine_config" ]["distribution" ] or "debian" in env_vars ["machine_config" ]["distribution" ]:
120
115
run_test_linux (remote_host , env_vars )
@@ -123,6 +118,6 @@ def run_test_linux(remote_host: u.Host, env_vars: dict) -> None:
123
118
elif "docker" in env_vars ["machine_config" ]["distribution" ]:
124
119
run_test_docker (remote_host , env_vars )
125
120
126
- pass
121
+ pass
127
122
128
123
0 commit comments