def test_attach_fail_mount_and_detach(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_ensure_tree, mock_do_mount): class TestException1(Exception): pass class TestException2(Exception): pass mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_cinder_workflow.attach_volume.return_value = self.fake_devpath mock_get_mountpoint.return_value = self.fake_mountpoint mock_do_mount.side_effect = TestException1() mock_cinder_workflow.detach_volume.side_effect = TestException2() volume_driver = driver.Cinder() self.volmap.connection_info = None self.assertRaises(TestException1, volume_driver.attach, self.context, self.volmap) mock_cinder_workflow.attach_volume.assert_called_once_with(self.volmap) mock_get_mountpoint.assert_called_once_with(self.fake_uuid) mock_do_mount.assert_called_once_with( self.fake_devpath, self.fake_mountpoint, CONF.volume.fstype) mock_cinder_workflow.detach_volume.assert_called_once_with( self.context, self.volmap)
def test_attach_unknown_provider(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_ensure_tree, mock_do_mount): volume_driver = driver.Cinder() self.volmap.volume_provider = 'unknown' self.assertRaises(exception.ZunException, volume_driver.attach, self.context, self.volmap)
def test_delete(self, mock_cinder_workflow_cls, mock_read_mounts): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_cinder_workflow.delete_volume.return_value = self.fake_volume_id volume_driver = driver.Cinder() volume_driver.delete(self.context, self.volume) mock_cinder_workflow.delete_volume.assert_called_once_with(self.volume)
def test_bind_mount(self, mock_cinder_workflow_cls, mock_get_mountpoint): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_get_mountpoint.return_value = self.fake_mountpoint volume_driver = driver.Cinder(self.context, 'cinder') source, destination = volume_driver.bind_mount(self.volume) self.assertEqual(self.fake_mountpoint, source) self.assertEqual(self.fake_container_path, destination) mock_get_mountpoint.assert_called_once_with(self.fake_volume_id)
def test_detach(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_do_unmount, mock_rmtree): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_get_mountpoint.return_value = self.fake_mountpoint volume_driver = driver.Cinder() volume_driver.detach(self.context, self.volmap) mock_cinder_workflow.detach_volume.\ assert_called_once_with(self.context, self.volmap) mock_get_mountpoint.assert_called_once_with(self.fake_uuid) mock_do_unmount.assert_called_once_with(self.fake_mountpoint) mock_rmtree.assert_called_once_with(self.fake_mountpoint)
def test_detach(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_do_unmount): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_cinder_workflow.detach_volume.return_value = self.fake_devpath mock_get_mountpoint.return_value = self.fake_mountpoint volume_driver = driver.Cinder(self.context, 'cinder') volume_driver.detach(self.volume) mock_cinder_workflow.detach_volume.assert_called_once_with(self.volume) mock_get_mountpoint.assert_called_once_with(self.fake_volume_id) mock_do_unmount.assert_called_once_with( self.fake_devpath, self.fake_mountpoint)
def test_attach(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_ensure_tree, mock_do_mount): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_cinder_workflow.attach_volume.return_value = self.fake_devpath mock_get_mountpoint.return_value = self.fake_mountpoint volume_driver = driver.Cinder() self.volmap.connection_info = None volume_driver.attach(self.context, self.volmap) mock_cinder_workflow.attach_volume.assert_called_once_with(self.volmap) mock_get_mountpoint.assert_called_once_with(self.fake_uuid) mock_do_mount.assert_called_once_with( self.fake_devpath, self.fake_mountpoint, CONF.volume.fstype) mock_cinder_workflow.detach_volume.assert_not_called()
def test_attach_fail_attach(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_ensure_tree, mock_do_mount): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_cinder_workflow.attach_volume.side_effect = \ exception.ZunException() mock_get_mountpoint.return_value = self.fake_mountpoint volume_driver = driver.Cinder() self.assertRaises(exception.ZunException, volume_driver.attach, self.context, self.volume) mock_cinder_workflow.attach_volume.assert_called_once_with(self.volume) mock_get_mountpoint.assert_not_called() mock_do_mount.assert_not_called() mock_cinder_workflow.detach_volume.assert_not_called()
def test_attach_fail_mount(self, mock_cinder_workflow_cls, mock_get_mountpoint, mock_ensure_tree, mock_do_mount): mock_cinder_workflow = mock.MagicMock() mock_cinder_workflow_cls.return_value = mock_cinder_workflow mock_cinder_workflow.attach_volume.return_value = self.fake_devpath mock_get_mountpoint.return_value = self.fake_mountpoint mock_do_mount.side_effect = exception.ZunException() volume_driver = driver.Cinder(self.context, 'cinder') self.assertRaises(exception.ZunException, volume_driver.attach, self.volume) mock_cinder_workflow.attach_volume.assert_called_once_with(self.volume) mock_get_mountpoint.assert_called_once_with(self.fake_volume_id) mock_do_mount.assert_called_once_with( self.fake_devpath, self.fake_mountpoint, CONF.volume.fstype) mock_cinder_workflow.detach_volume.assert_called_once_with(self.volume)