- Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtest_cmd_line_parameters.py
118 lines (96 loc) · 3.58 KB
/
test_cmd_line_parameters.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
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""Tests that ensure the correctness of the command line parameters."""
importsubprocess
frompathlibimportPath
importpytest
fromframework.utilsimportcheck_output
fromhost_tools.fcmetricsimportvalidate_fc_metrics
deftest_describe_snapshot_all_versions(
microvm_factory, guest_kernel, rootfs, firecracker_release
):
"""
Test `--describe-snapshot` correctness for all snapshot versions.
For each release create a snapshot and verify the data version of the
snapshot state file.
"""
target_version=firecracker_release.snapshot_version
vm=microvm_factory.build(
guest_kernel,
rootfs,
fc_binary_path=firecracker_release.path,
jailer_binary_path=firecracker_release.jailer,
)
vm.spawn()
vm.basic_config(track_dirty_pages=True)
vm.start()
snapshot=vm.snapshot_diff()
print("========== Firecracker create snapshot log ==========")
print(vm.log_data)
vm.kill()
# Fetch Firecracker binary
fc_binary=microvm_factory.fc_binary_path
# Verify the output of `--describe-snapshot` command line parameter
cmd= [fc_binary] + ["--describe-snapshot", snapshot.vmstate]
_, stdout, stderr=check_output(cmd)
assertstderr==""
asserttarget_versioninstdout
deftest_cli_metrics_path(uvm_plain):
"""
Test --metrics-path parameter
"""
microvm=uvm_plain
metrics_path=Path(microvm.path) /"my_metrics.ndjson"
microvm.spawn(metrics_path=metrics_path)
microvm.basic_config()
microvm.start()
metrics=microvm.flush_metrics()
validate_fc_metrics(metrics)
deftest_cli_metrics_path_if_metrics_initialized_twice_fail(uvm_plain):
"""
Given: a running firecracker with metrics configured with the CLI option
When: Configure metrics via API
Then: API returns an error
"""
microvm=uvm_plain
# First configure the µvm metrics with --metrics-path
metrics_path=Path(microvm.path) /"metrics.ndjson"
metrics_path.touch()
microvm.spawn(metrics_path=metrics_path)
# Then try to configure it with PUT /metrics
metrics2_path=Path(microvm.path) /"metrics2.ndjson"
metrics2_path.touch()
# It should fail with because it's already configured
withpytest.raises(RuntimeError, match="Reinitialization of metrics not allowed."):
microvm.api.metrics.put(
metrics_path=microvm.create_jailed_resource(metrics2_path)
)
deftest_cli_metrics_if_resume_no_metrics(uvm_plain, microvm_factory):
"""
Check that metrics configuration is not part of the snapshot
"""
# Given: a snapshot of a FC with metrics configured with the CLI option
uvm1=uvm_plain
metrics_path=Path(uvm1.path) /"metrics.ndjson"
metrics_path.touch()
uvm1.spawn(metrics_path=metrics_path)
uvm1.basic_config()
uvm1.start()
snapshot=uvm1.snapshot_full()
# When: restoring from the snapshot
uvm2=microvm_factory.build_from_snapshot(snapshot)
# Then: the old metrics configuration does not exist
metrics2=Path(uvm2.jailer.chroot_path()) /metrics_path.name
assertnotmetrics2.exists()
deftest_cli_no_params(microvm_factory):
"""
Test running firecracker with no parameters should work
"""
fc_binary=microvm_factory.fc_binary_path
process=subprocess.Popen(fc_binary)
try:
process.communicate(timeout=3)
assertprocess.returncodeisNone
exceptsubprocess.TimeoutExpired:
# The good case
process.kill()