From 55cfc975811584bb533211253b8506028dbbb958 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 7 May 2020 09:37:48 -0400 Subject: [PATCH] rbd: Correct local_attach disconnect test and showmapped arguments Id507109df80391699074773f4787f74507c4b882 introduced the showmapped command when attempting to disconnect locally attached rbd volumes. Unfortunately at the time the test changes incorrectly attempted to assert the commands made by using has_calls instead of the valid assert_has_calls method. This change now corrects this, ensures _get_rbd_args is called to populate all of the required arguments for the showmapped command and finally corrects the name stored within the fake showmapped output in the test. Change-Id: I7e761828b3799cef720e15ca7896e8e8d6f98182 (cherry picked from commit 71331b0e06a713a0883f0c1199923e0943adcf09) --- os_brick/initiator/connectors/rbd.py | 1 + os_brick/tests/initiator/connectors/test_rbd.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/os_brick/initiator/connectors/rbd.py b/os_brick/initiator/connectors/rbd.py index 0f34728f3..9257a260c 100644 --- a/os_brick/initiator/connectors/rbd.py +++ b/os_brick/initiator/connectors/rbd.py @@ -217,6 +217,7 @@ class RBDConnector(base.BaseLinuxConnector): """ __, volume = connection_properties['name'].split('/') cmd = ['rbd', 'showmapped', '--format=json'] + cmd += self._get_rbd_args(connection_properties) (out, err) = self._execute(*cmd, root_helper=self._root_helper, run_as_root=True) for index, mapping in jsonutils.loads(out).items(): diff --git a/os_brick/tests/initiator/connectors/test_rbd.py b/os_brick/tests/initiator/connectors/test_rbd.py index f8ba41666..0fd284c23 100644 --- a/os_brick/tests/initiator/connectors/test_rbd.py +++ b/os_brick/tests/initiator/connectors/test_rbd.py @@ -258,8 +258,8 @@ class RBDConnectorTestCase(test_connector.ConnectorTestCase): 'hosts': ['192.168.10.2'], 'ports': ['6789']} mock_execute.side_effect = [(""" -{"0":{"pool":"pool","device":"/dev/rbd0","name":"pool-image"}, - "1":{"pool":"pool","device":"/dev/rdb1","name":"pool-image_2"}}""", None), +{"0":{"pool":"pool","device":"/dev/rbd0","name":"image"}, + "1":{"pool":"pool","device":"/dev/rdb1","name":"image_2"}}""", None), (None, None)] show_cmd = ['rbd', 'showmapped', '--format=json', '--id', 'fake_user', '--mon_host', '192.168.10.2:6789'] @@ -269,7 +269,7 @@ class RBDConnectorTestCase(test_connector.ConnectorTestCase): rbd_connector.disconnect_volume(conn, None) # Assert that showmapped is used before we unmap the root device - mock_execute.has_calls([ + mock_execute.assert_has_calls([ mock.call(*show_cmd, root_helper=None, run_as_root=True), mock.call(*unmap_cmd, root_helper=None, run_as_root=True)])