iotest 147: add cases to test new @name parameter of nbd-server-add

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180119135719.24745-4-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2018-01-19 16:57:17 +03:00 committed by Eric Blake
parent a3b0dc7582
commit 549084eaed
2 changed files with 57 additions and 15 deletions

View File

@ -38,8 +38,8 @@ def flatten_sock_addr(crumpled_address):
class NBDBlockdevAddBase(iotests.QMPTestCase): class NBDBlockdevAddBase(iotests.QMPTestCase):
def blockdev_add_options(self, address, export=None): def blockdev_add_options(self, address, export, node_name):
options = { 'node-name': 'nbd-blockdev', options = { 'node-name': node_name,
'driver': 'raw', 'driver': 'raw',
'file': { 'file': {
'driver': 'nbd', 'driver': 'nbd',
@ -50,23 +50,28 @@ class NBDBlockdevAddBase(iotests.QMPTestCase):
options['file']['export'] = export options['file']['export'] = export
return options return options
def client_test(self, filename, address, export=None): def client_test(self, filename, address, export=None,
bao = self.blockdev_add_options(address, export) node_name='nbd-blockdev', delete=True):
bao = self.blockdev_add_options(address, export, node_name)
result = self.vm.qmp('blockdev-add', **bao) result = self.vm.qmp('blockdev-add', **bao)
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
found = False
result = self.vm.qmp('query-named-block-nodes') result = self.vm.qmp('query-named-block-nodes')
for node in result['return']: for node in result['return']:
if node['node-name'] == 'nbd-blockdev': if node['node-name'] == node_name:
found = True
if isinstance(filename, str): if isinstance(filename, str):
self.assert_qmp(node, 'image/filename', filename) self.assert_qmp(node, 'image/filename', filename)
else: else:
self.assert_json_filename_equal(node['image']['filename'], self.assert_json_filename_equal(node['image']['filename'],
filename) filename)
break break
self.assertTrue(found)
result = self.vm.qmp('blockdev-del', node_name='nbd-blockdev') if delete:
self.assert_qmp(result, 'return', {}) result = self.vm.qmp('blockdev-del', node_name=node_name)
self.assert_qmp(result, 'return', {})
class QemuNBD(NBDBlockdevAddBase): class QemuNBD(NBDBlockdevAddBase):
@ -125,26 +130,63 @@ class BuiltinNBD(NBDBlockdevAddBase):
except OSError: except OSError:
pass pass
def _server_up(self, address): def _server_up(self, address, export_name=None, export_name2=None):
result = self.server.qmp('nbd-server-start', addr=address) result = self.server.qmp('nbd-server-start', addr=address)
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
result = self.server.qmp('nbd-server-add', device='nbd-export') if export_name is None:
result = self.server.qmp('nbd-server-add', device='nbd-export')
else:
result = self.server.qmp('nbd-server-add', device='nbd-export',
name=export_name)
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
if export_name2 is not None:
result = self.server.qmp('nbd-server-add', device='nbd-export',
name=export_name2)
self.assert_qmp(result, 'return', {})
def _server_down(self): def _server_down(self):
result = self.server.qmp('nbd-server-stop') result = self.server.qmp('nbd-server-stop')
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
def test_inet(self): def do_test_inet(self, export_name=None):
address = { 'type': 'inet', address = { 'type': 'inet',
'data': { 'data': {
'host': 'localhost', 'host': 'localhost',
'port': str(NBD_PORT) 'port': str(NBD_PORT)
} } } }
self._server_up(address) self._server_up(address, export_name)
self.client_test('nbd://localhost:%i/nbd-export' % NBD_PORT, export_name = export_name or 'nbd-export'
flatten_sock_addr(address), 'nbd-export') self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, export_name),
flatten_sock_addr(address), export_name)
self._server_down()
def test_inet_default_export_name(self):
self.do_test_inet()
def test_inet_same_export_name(self):
self.do_test_inet('nbd-export')
def test_inet_different_export_name(self):
self.do_test_inet('shadow')
def test_inet_two_exports(self):
address = { 'type': 'inet',
'data': {
'host': 'localhost',
'port': str(NBD_PORT)
} }
self._server_up(address, 'exp1', 'exp2')
self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp1'),
flatten_sock_addr(address), 'exp1', 'node1', False)
self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp2'),
flatten_sock_addr(address), 'exp2', 'node2', False)
result = self.vm.qmp('blockdev-del', node_name='node1')
self.assert_qmp(result, 'return', {})
result = self.vm.qmp('blockdev-del', node_name='node2')
self.assert_qmp(result, 'return', {})
self._server_down() self._server_down()
def test_inet6(self): def test_inet6(self):

View File

@ -1,5 +1,5 @@
...... .........
---------------------------------------------------------------------- ----------------------------------------------------------------------
Ran 6 tests Ran 9 tests
OK OK