- Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtest_metrics.py
87 lines (66 loc) · 2.56 KB
/
test_metrics.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
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""Tests the metrics system."""
importos
importhost_tools.driveasdrive_tools
fromhost_tools.fcmetricsimportFcDeviceMetrics, validate_fc_metrics
deftest_flush_metrics(uvm_plain):
"""
Check the `FlushMetrics` vmm action.
"""
microvm=uvm_plain
microvm.spawn()
microvm.basic_config()
microvm.start()
metrics=microvm.flush_metrics()
validate_fc_metrics(metrics)
deftest_net_metrics(uvm_plain):
"""
Validate that NetDeviceMetrics doesn't have a breaking change
and "net" is aggregate of all "net_*" in the json object.
"""
test_microvm=uvm_plain
test_microvm.spawn()
# Set up a basic microVM.
test_microvm.basic_config()
# randomly selected 10 as the number of net devices to test
num_net_devices=10
net_metrics=FcDeviceMetrics("net", num_net_devices)
# create more than 1 net devices to test aggregation
for_inrange(num_net_devices):
test_microvm.add_net_iface()
test_microvm.start()
# check that the started microvm has "net" and "NUM_NET_DEVICES" number of "net_" metrics
net_metrics.validate(test_microvm)
foriinrange(num_net_devices):
# Test that network devices attached are operational.
# Verify if guest can run commands.
exit_code, _, _=test_microvm.ssh_iface(i).run("sync")
# test that we get metrics while interacting with different interfaces
net_metrics.validate(test_microvm)
assertexit_code==0
deftest_block_metrics(uvm_plain):
"""
Validate that BlockDeviceMetrics doesn't have a breaking change
and "block" is aggregate of all "block_*" in the json object.
"""
test_microvm=uvm_plain
test_microvm.spawn()
# Add first scratch block device.
fs1=drive_tools.FilesystemFile(
os.path.join(test_microvm.fsfiles, "scratch1"), size=128
)
test_microvm.add_drive("scratch1", fs1.path)
# Set up a basic microVM.
# (this is the second block device added).
test_microvm.basic_config()
# Add the third block device.
fs2=drive_tools.FilesystemFile(
os.path.join(test_microvm.fsfiles, "scratch2"), size=512
)
test_microvm.add_drive("scratch2", fs2.path)
num_block_devices=3
block_metrics=FcDeviceMetrics("block", num_block_devices)
test_microvm.start()
# check that the started microvm has "block" and "num_block_devices" number of "block_" metrics
block_metrics.validate(test_microvm)