From: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
To: Nikita Lapshin <nikita.lapshin@openvz.org>, qemu-devel@nongnu.org
Cc: den@openvz.org, Nikita Lapshin <nikita.lapshin@virtuozzo.com>
Subject: Re: [PATCH v1 8/8] migration: Test for RAM and vmstate parts
Date: Wed, 23 Mar 2022 17:05:18 +0300 [thread overview]
Message-ID: <42a78664-b45f-a8a6-2476-08fa5d3e8034@mail.ru> (raw)
In-Reply-To: <20220323105400.17649-9-nikita.lapshin@openvz.org>
23.03.2022 13:54, Nikita Lapshin wrote:
> From: Nikita Lapshin <nikita.lapshin@virtuozzo.com>
>
> All other parts works just like existed capabilities.
> Though RAM and vmstate are new so here is new test for
> that parts.
>
> Signed-off-by: Nikita Lapshin <nikita.lapshin@openvz.org>
> ---
> .../tests/migrate-ram-stream-content-test | 96 +++++++++++++++++++
> .../tests/migrate-ram-stream-content-test.out | 5 +
> 2 files changed, 101 insertions(+)
> create mode 100755 tests/qemu-iotests/tests/migrate-ram-stream-content-test
> create mode 100644 tests/qemu-iotests/tests/migrate-ram-stream-content-test.out
>
> diff --git a/tests/qemu-iotests/tests/migrate-ram-stream-content-test b/tests/qemu-iotests/tests/migrate-ram-stream-content-test
> new file mode 100755
> index 0000000000..2855ca4a64
> --- /dev/null
> +++ b/tests/qemu-iotests/tests/migrate-ram-stream-content-test
> @@ -0,0 +1,96 @@
> +#!/usr/bin/env python3
> +# group: rw migration
> +#
> +# Tests for 'no-ram' and 'ram-only' capabilities
> +#
> +# Copyright (c) 2021 Virtuozzo International GmbH.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +
> +import os
> +import json
> +import subprocess
> +import iotests
> +
> +img = os.path.join(iotests.test_dir, 'disk.img')
> +
> +class TestRamCapabilities(iotests.QMPTestCase):
> + def setUp(self):
> + iotests.qemu_img('create', '-f', iotests.imgfmt, img, '10M')
> + self.vm = iotests.VM()
> + self.vm.launch()
> + self.vm.qmp('migrate-set-capabilities', capabilities=[
> + {
> + 'capability': 'events',
> + 'state': True
> + }
> + ])
> +
> + def tearDown(self):
> + self.vm.shutdown()
> + os.remove(img)
> +
> + def check_ram_only(self, output):
> + str_json = output.decode()
> + json_obj = json.loads(str_json)
> +
> + success = False
> + for key in json_obj:
> + self.assertTrue("ram" in key)
> + success = True
> + self.assertTrue(success)
I'd write it like this:
self.assertTrue(len(json_obj) > 0)
self.assertTrue(all('ram' in key for key in json_obj))
> +
> + def run_migration(self, no_ram, tmp_stream):
> + if no_ram:
> + output = self.vm.qmp('migrate-set-parameters',
> + stream_content_list = ['vmstate'])
> + else:
> + self.vm.qmp('migrate-set-parameters',
> + stream_content_list = ['ram'])
It would look better if just pass stream_content list argument to the function.
> +
> + self.vm.qmp('migrate', uri='exec:cat>' + tmp_stream)
> +
> + while True:
> + event = self.vm.event_wait('MIGRATION')
> +
> + if event['data']['status'] == 'completed':
> + break
> +
> +
> + def test_no_ram(self):
> + with iotests.FilePath('tmp_stream') as tmp_stream:
> + self.run_migration(True, tmp_stream)
> + output = subprocess.run(
> + ['../../../scripts/analyze-migration.py', '-f', tmp_stream],
> + stdout=subprocess.PIPE,
> + stderr=subprocess.STDOUT,
> + check=False).stdout
> +
> + self.assertFalse('ram' in output.decode())
> +
> + def test_ram_only(self):
> + with iotests.FilePath('tmp_stream') as tmp_stream:
> + self.run_migration(False, tmp_stream)
> + output = subprocess.run(
> + ['../../../scripts/analyze-migration.py', '-f', tmp_stream,
> + '--ram-only'],
> + stdout=subprocess.PIPE,
> + stderr=subprocess.STDOUT,
> + check=False).stdout
> +
> + self.check_ram_only(output)
Hmm both test cases are mostly the same - may be refactored a bit mor eto not duplicate.
> +
> +if __name__ == '__main__':
> + iotests.main(supported_protocols=['file'])
> diff --git a/tests/qemu-iotests/tests/migrate-ram-stream-content-test.out b/tests/qemu-iotests/tests/migrate-ram-stream-content-test.out
> new file mode 100644
> index 0000000000..fbc63e62f8
> --- /dev/null
> +++ b/tests/qemu-iotests/tests/migrate-ram-stream-content-test.out
> @@ -0,0 +1,5 @@
> +..
> +----------------------------------------------------------------------
> +Ran 2 tests
> +
> +OK
Looks good in general
--
Best regards,
Vladimir
prev parent reply other threads:[~2022-03-23 14:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220323105400.17649-1-nikita.lapshin@openvz.org>
[not found] ` <20220323105400.17649-2-nikita.lapshin@openvz.org>
2022-03-23 12:28 ` [PATCH v1 1/8] migration: Implemented new parameter stream_content Vladimir Sementsov-Ogievskiy
[not found] ` <20220323105400.17649-3-nikita.lapshin@openvz.org>
2022-03-23 12:34 ` [PATCH v1 2/8] migration: should_skip() implemented Vladimir Sementsov-Ogievskiy
[not found] ` <20220323105400.17649-4-nikita.lapshin@openvz.org>
2022-03-23 12:40 ` [PATCH v1 3/8] migration: Add vmstate part of migration stream Vladimir Sementsov-Ogievskiy
2022-03-23 12:49 ` Vladimir Sementsov-Ogievskiy
[not found] ` <f03bf2db-a424-17e2-38f1-1608c004c0e4@openvz.org>
2022-03-23 14:07 ` Vladimir Sementsov-Ogievskiy
[not found] ` <20220323105400.17649-5-nikita.lapshin@openvz.org>
2022-03-23 12:49 ` [PATCH v1 4/8] migration: Add dirty-bitmaps " Vladimir Sementsov-Ogievskiy
[not found] ` <20220323105400.17649-6-nikita.lapshin@openvz.org>
2022-03-23 12:50 ` [PATCH v1 5/8] migration: Add block " Vladimir Sementsov-Ogievskiy
[not found] ` <20220323105400.17649-7-nikita.lapshin@openvz.org>
2022-03-23 13:52 ` [PATCH v1 6/8] migration: Add RAM " Vladimir Sementsov-Ogievskiy
[not found] ` <20220323105400.17649-8-nikita.lapshin@openvz.org>
2022-03-23 13:57 ` [PATCH v1 7/8] migration: analyze-migration script changed Vladimir Sementsov-Ogievskiy
2022-03-23 14:38 ` Nikita Lapshin
[not found] ` <20220323105400.17649-9-nikita.lapshin@openvz.org>
2022-03-23 14:05 ` Vladimir Sementsov-Ogievskiy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42a78664-b45f-a8a6-2476-08fa5d3e8034@mail.ru \
--to=v.sementsov-og@mail.ru \
--cc=den@openvz.org \
--cc=nikita.lapshin@openvz.org \
--cc=nikita.lapshin@virtuozzo.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).