-
Notifications
You must be signed in to change notification settings - Fork 304
/
cart_iv_two_node.py
executable file
·300 lines (234 loc) · 10.4 KB
/
cart_iv_two_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/python
'''
(C) Copyright 2018-2021 Intel Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
'''
from __future__ import print_function
import sys
import time
import tempfile
import json
import os
import struct
import codecs
import subprocess
import shlex
from apricot import TestWithoutServers
sys.path.append('./util')
# Can't all this import before setting sys.path
# pylint: disable=wrong-import-position
from cart_utils import CartUtils
def _check_value(expected_value, received_value):
"""
Checks that the received value (a hex string) contains the expected
value (a string). If the received value is longer than the expected
value, make sure any remaining characters are zeros
returns True if the values match, False otherwise
"""
char = None
# Comparisons are lower case
received_value = received_value.lower()
# Convert the expected value to hex characters
expected_value_hex = "".join("{:02x}".format(ord(c)) \
for c in expected_value).lower()
# Make sure received value is at least as long as expected
if len(received_value) < len(expected_value_hex):
return False
# Make sure received value starts with the expected value
if expected_value_hex not in received_value[:len(expected_value_hex)]:
return False
# Make sure all characters after the expected value are zeros (if any)
for char in received_value[len(expected_value_hex):]:
if char != "0":
return False
return True
def _check_key(key_rank, key_idx, received_key_hex):
"""
Checks that the received key is the same as the sent key
key_rank and key_idx are 32-bit integers
received_key_hex is hex(key_rank|key_idx)
"""
if len(received_key_hex) != 16:
return False
rank = struct.unpack("<I",
codecs.decode(received_key_hex[:8], "hex"))[0]
idx = struct.unpack("<I",
codecs.decode(received_key_hex[8:], "hex"))[0]
return (rank == key_rank) and (idx == key_idx)
class CartIvTwoNodeTest(TestWithoutServers):
"""
Runs basic CaRT tests on one-node
:avocado: recursive
"""
def setUp(self):
""" Test setup """
print("Running setup\n")
self.utils = CartUtils()
self.env = self.utils.get_env(self)
def tearDown(self):
""" Tear down """
self.report_timeout()
self._teardown_errors.extend(self.utils.cleanup_processes())
super().tearDown()
def _verify_action(self, action):
"""verify the action"""
if (('operation' not in action) or
('rank' not in action) or
('key' not in action)):
self.utils.print("Error happened during action check")
raise ValueError("Each action must contain an operation," \
" rank, and key")
if len(action['key']) != 2:
self.utils.print("Error key should be tuple of (rank, idx)")
raise ValueError("key should be a tuple of (rank, idx)")
def _verify_fetch_operation(self, action):
"""verify fetch operation"""
if (('return_code' not in action) or
('expected_value' not in action)):
self.utils.print("Error: fetch operation was malformed")
raise ValueError("Fetch operation malformed")
def _iv_test_actions(self, cmd, actions):
#pylint: disable=too-many-locals
"""Go through each action and perform the test"""
for action in actions:
clicmd = cmd
command = 'tests/iv_client'
self._verify_action(action)
operation = action['operation']
rank = int(action['rank'])
key_rank = int(action['key'][0])
key_idx = int(action['key'][1])
if "fetch" in operation:
self._verify_fetch_operation(action)
expected_rc = int(action['return_code'])
# Create a temporary file for iv_client to write the results to
log_path_dir = os.environ['HOME']
if os.environ['DAOS_TEST_SHARED_DIR']:
log_path_dir = os.environ['DAOS_TEST_SHARED_DIR']
log_fd, log_path = tempfile.mkstemp(dir=log_path_dir)
command = " {!s} -o '{!s}' -r '{!s}' -k '{!s}:{!s}' -l '{!s}'" \
.format(command, operation, rank, key_rank, key_idx,
log_path)
clicmd += command
self.utils.print("\nClient cmd : %s\n" % clicmd)
cli_rtn = subprocess.call(shlex.split(clicmd))
if cli_rtn != 0:
raise ValueError('Error code {!s} running command "{!s}"' \
.format(cli_rtn, command))
# Read the result into test_result and remove the temp file
log_file = open(log_path)
test_result = json.load(log_file)
log_file.close()
os.close(log_fd)
os.remove(log_path)
# Parse return code and make sure it matches
if expected_rc != test_result["return_code"]:
raise ValueError("Fetch returned return code {!s} != " \
"expected value {!s}".format(
test_result["return_code"],
expected_rc))
# Other values will be invalid if return code is failure
if expected_rc != 0:
continue
# Check that returned key matches expected one
if not _check_key(key_rank, key_idx, test_result["key"]):
raise ValueError("Fetch returned unexpected key")
# Check that returned value matches expected one
if not _check_value(action['expected_value'],
test_result["value"]):
raise ValueError("Fetch returned unexpected value")
if "update" in operation:
if 'value' not in action:
raise ValueError("Update operation requires value")
command = " {!s} -o '{!s}' -r '{!s}' -k '{!s}:{!s}' -v '{!s}'" \
.format(command, operation, rank, key_rank, key_idx,
action['value'])
clicmd += command
self.utils.print("\nClient cmd : %s\n" % clicmd)
cli_rtn = subprocess.call(shlex.split(clicmd))
if cli_rtn != 0:
raise ValueError('Error code {!s} running command "{!s}"' \
.format(cli_rtn, command))
if "invalidate" in operation:
command = " {!s} -o '{!s}' -r '{!s}' -k '{!s}:{!s}'".format(
command, operation, rank, key_rank, key_idx)
clicmd += command
self.utils.print("\nClient cmd : %s\n" % clicmd)
cli_rtn = subprocess.call(shlex.split(clicmd))
if cli_rtn != 0:
raise ValueError('Error code {!s} running command "{!s}"' \
.format(cli_rtn, command))
def test_cart_iv(self):
"""
Test CaRT IV
:avocado: tags=all,cart,pr,daily_regression,iv,two_node
"""
srvcmd = self.utils.build_cmd(self, self.env, "test_servers")
try:
srv_rtn = self.utils.launch_cmd_bg(self, srvcmd)
# pylint: disable=broad-except
except Exception as e:
self.utils.print("Exception in launching server : {}".format(e))
self.fail("Test failed.\n")
# Verify the server is still running.
if not self.utils.check_process(srv_rtn):
procrtn = self.utils.stop_process(srv_rtn)
self.fail("Server did not launch, return code %s" \
% procrtn)
actions = [
# Fetch, expect fail, no variable yet
{"operation":"fetch", "rank":0, "key":(0, 42), "return_code":-1,
"expected_value":""},
# Add variable 0:42
{"operation":"update", "rank":0, "key":(0, 42), "value":"potato"},
# Fetch the value and verify it
{"operation":"fetch", "rank":0, "key":(0, 42), "return_code":0,
"expected_value":"potato"},
# Invalidate the value
{"operation":"invalidate", "rank":0, "key":(0, 42)},
# Fetch the value again expecting failure
{"operation":"fetch", "rank":0, "key":(0, 42), "return_code":-1,
"expected_value":""},
]
time.sleep(2)
failed = False
clicmd = self.utils.build_cmd(self, self.env, "test_clients")
########## Launch Client Actions ##########
try:
self._iv_test_actions(clicmd, actions)
except ValueError as exception:
failed = True
self.utils.print("TEST FAILED: %s" % str(exception))
########## Shutdown Servers ##########
num_servers = self.utils.get_srv_cnt(self, "test_servers")
srv_ppn = self.params.get("test_servers_ppn", '/run/tests/*/')
# Note: due to CART-408 issue, rank 0 needs to shutdown last
# Request each server shut down gracefully
for rank in reversed(range(1, int(srv_ppn) * num_servers)):
clicmd += " -o shutdown -r " + str(rank)
self.utils.print("\nClient cmd : %s\n" % clicmd)
try:
subprocess.call(shlex.split(clicmd))
# pylint: disable=broad-except
except Exception as e:
failed = True
self.utils.print("Exception in launching client : {}".format(e))
time.sleep(1)
# Shutdown rank 0 separately
clicmd += " -o shutdown -r 0"
self.utils.print("\nClient cmd : %s\n" % clicmd)
try:
subprocess.call(shlex.split(clicmd))
# pylint: disable=broad-except
except Exception as e:
failed = True
self.utils.print("Exception in launching client : {}".format(e))
time.sleep(2)
# Stop the server if it is still running
if self.utils.check_process(srv_rtn):
# Return value is meaningless with --continuous
self.utils.stop_process(srv_rtn)
if failed:
self.fail("Test failed.\n")
if __name__ == "__main__":
main()