Merge ~ltrager/maas:lp1869958_2.6 into maas:2.6

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 70d095b5bf75e8a17192826648532b84fe5fbfbf
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1869958_2.6
Merge into: maas:2.6
Diff against target: 85 lines (+28/-10)
2 files modified
src/metadataserver/builtin_scripts/fio.py (+21/-5)
src/metadataserver/builtin_scripts/tests/test_fio.py (+7/-5)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+384056@code.launchpad.net

Commit message

Backport of 9424d23 LP: #1869958 - Run fio using the native block size of the disk.

To post a comment you must log in.
Revision history for this message
Lee Trager (ltrager) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/builtin_scripts/fio.py b/src/metadataserver/builtin_scripts/fio.py
2index 451e278..9ab18d5 100644
3--- a/src/metadataserver/builtin_scripts/fio.py
4+++ b/src/metadataserver/builtin_scripts/fio.py
5@@ -5,7 +5,7 @@
6 # Author: Newell Jensen <newell.jensen@canonical.com>
7 # Lee Trager <lee.trager@canonical.com>
8 #
9-# Copyright (C) 2017-2018 Canonical
10+# Copyright (C) 2017-2020 Canonical
11 #
12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Affero General Public License as
14@@ -78,9 +78,17 @@ import yaml
15 # When given --output-format=normal,json fio > 3 outputs both normal
16 # and json format. Older versions just output the normal format.
17 CMD = [
18- 'sudo', '-n', 'fio', '--randrepeat=1', '--ioengine=libaio',
19- '--direct=1', '--gtod_reduce=1', '--name=fio_test', '--bs=4k',
20- '--iodepth=64', '--size=4G', '--output-format=normal,json'
21+ "sudo",
22+ "-n",
23+ "fio",
24+ "--randrepeat=1",
25+ "--ioengine=libaio",
26+ "--direct=1",
27+ "--gtod_reduce=1",
28+ "--name=fio_test",
29+ "--iodepth=64",
30+ "--size=4G",
31+ "--output-format=normal,json",
32 ]
33
34
35@@ -99,6 +107,13 @@ REGEX = re.compile(r'''
36 ''', re.MULTILINE | re.DOTALL | re.VERBOSE)
37
38
39+def get_blocksize(blockdevice):
40+ """Return the block size of the block device."""
41+ blockname = os.path.basename(blockdevice)
42+ with open("/sys/block/%s/queue/physical_block_size" % blockname, "r") as f:
43+ return int(f.read())
44+
45+
46 def run_cmd(readwrite, result_break=True):
47 """Execute `CMD` and return output or exit if error."""
48 cmd = deepcopy(CMD)
49@@ -162,7 +177,8 @@ def run_fio(blockdevice):
50
51 Performs random and sequential read and write tests.
52 """
53- CMD.append('--filename=%s' % blockdevice)
54+ CMD.append("--filename=%s" % blockdevice)
55+ CMD.append("--bs=%s" % get_blocksize(blockdevice))
56 random_read = run_cmd("randread")
57 sequential_read = run_cmd("read")
58 random_write = run_cmd("randwrite")
59diff --git a/src/metadataserver/builtin_scripts/tests/test_fio.py b/src/metadataserver/builtin_scripts/tests/test_fio.py
60index be7876f..dc624ab 100644
61--- a/src/metadataserver/builtin_scripts/tests/test_fio.py
62+++ b/src/metadataserver/builtin_scripts/tests/test_fio.py
63@@ -1,4 +1,4 @@
64-# Copyright 2017-2018 Canonical Ltd. This software is licensed under the
65+# Copyright 2017-2020 Canonical Ltd. This software is licensed under the
66 # GNU Affero General Public License version 3 (see the file LICENSE).
67
68 """Test builtin_script fio."""
69@@ -172,10 +172,12 @@ class TestFioTestRunFio(MAASTestCase):
70
71 def setUp(self):
72 super().setUp()
73- self.mock_print = self.patch(fio, 'print')
74- self.mock_stdout_write = self.patch(fio.sys.stdout, 'write')
75- self.mock_stderr_write = self.patch(fio.sys.stderr, 'write')
76- self.mock_check_output = self.patch(fio, 'check_output')
77+ self.mock_print = self.patch(fio, "print")
78+ self.mock_stdout_write = self.patch(fio.sys.stdout, "write")
79+ self.mock_stderr_write = self.patch(fio.sys.stderr, "write")
80+ self.mock_check_output = self.patch(fio, "check_output")
81+ self.mock_get_blocksize = self.patch(fio, "get_blocksize")
82+ self.mock_get_blocksize.return_value = 512
83
84 def test_run_fio_writes_yaml_file(self):
85 tmp_path = Path(self.useFixture(TempDirectory()).path)

Subscribers

People subscribed via source and target branches