def test_get_export_dir_list(self): self._driver.gluster_address = Mock(make_gluster_args= Mock(return_value=(('true',), {}))) def exec_runner(*ignore_args, **ignore_kwargs): return """\ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <cliOutput> <volInfo> <volumes> <volume> <options> <option> <name>nfs.export-dir</name> <value>foo,bar</value> </option> </options> </volume> <count>1</count> </volumes> </volInfo> </cliOutput> """, '' expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) ret = self._driver._get_export_dir_list() self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertEqual(ret, ['foo', 'bar'])
def test_allow_access_excp(self): self._driver._restart_gluster_vol = mock.Mock() access = {'access_type': 'cert', 'access_to': 'client.example.com'} gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) gaddr2 = gaddr(self.gluster_target2) self._driver.gluster_used_vols_dict = {gaddr1.export: gaddr1} self._driver.gluster_unused_vols_dict = {gaddr2.export: gaddr2} share = fake_db_share1()[0] def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'ssh root@host1 gluster volume set gv1 ' 'auth.ssl-allow client.example.com'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver.allow_access, self._context, share, access) self.assertFalse(self._driver._restart_gluster_vol.called)
def test_deny_access_excp(self): self._driver._restart_gluster_vol = mock.Mock() access = {'access_type': 'cert', 'access_to': 'NotApplicable'} gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) gaddr2 = gaddr(self.gluster_target2) self._driver.gluster_used_vols_dict = {gaddr1.export: gaddr1} self._driver.gluster_unused_vols_dict = {gaddr2.export: gaddr2} share = fake_db_share1()[0] expected_exec = [ 'ssh root@host1 gluster volume reset gv1 auth.ssl-allow' ] def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver.deny_access, self._context, share, access) self.assertFalse(self._driver._restart_gluster_vol.called)
def test_wipe_gluster_vol_excp5(self): self._driver._restart_gluster_vol = mock.Mock() self._driver._do_mount = mock.Mock() self._driver._do_umount = mock.Mock() shutil.rmtree = mock.Mock() gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'find /tmp/tmpKGHKJ -mindepth 1 -delete'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._wipe_gluster_vol, gaddr1) self.assertTrue(self._driver._restart_gluster_vol.called) self.assertTrue(tempfile.mkdtemp.called) self.assertTrue(self._driver._do_mount.called) self.assertTrue(self._driver._do_umount.called) self.assertTrue(shutil.rmtree.called)
def test_wipe_gluster_vol_excp5(self): self._driver._restart_gluster_vol = mock.Mock() self._driver._do_mount = mock.Mock() self._driver._do_umount = mock.Mock() shutil.rmtree = mock.Mock() gmgr = glusterfs.GlusterManager gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None) test_args = [ ('volume', 'set', 'gv1', 'client.ssl', 'off'), ('volume', 'set', 'gv1', 'server.ssl', 'off')] def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'find /tmp/tmpKGHKJ -mindepth 1 -delete'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._wipe_gluster_vol, gmgr1) self.assertEqual( [mock.call(*test_args[0]), mock.call(*test_args[1])], gmgr1.gluster_call.call_args_list) self.assertTrue(self._driver._restart_gluster_vol.called) self.assertTrue(tempfile.mkdtemp.called) self.assertTrue(self._driver._do_mount.called) self.assertTrue(self._driver._do_umount.called) self.assertTrue(shutil.rmtree.called)
def test_wipe_gluster_vol_excp5(self): self._driver._restart_gluster_vol = mock.Mock() self._driver._do_mount = mock.Mock() self._driver._do_umount = mock.Mock() shutil.rmtree = mock.Mock() gmgr = glusterfs.GlusterManager gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None) test_args = [ ('volume', 'set', 'gv1', 'client.ssl', 'off'), ('volume', 'set', 'gv1', 'server.ssl', 'off')] def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'find /tmp/tmpKGHKJ -mindepth 1 -delete'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._wipe_gluster_vol, gmgr1) self.assertEqual( [mock.call(*test_args[0]), mock.call(*test_args[1])], gmgr1.gluster_call.call_args_list) self.assertTrue(self._driver._restart_gluster_vol.called) self.assertTrue(tempfile.mkdtemp.called) self.assertTrue(self._driver._do_mount.called) self.assertTrue(self._driver._do_umount.called) self.assertTrue(shutil.rmtree.called)
def test_wipe_gluster_vol_excp2(self): self._driver._restart_gluster_vol = mock.Mock() self._driver._do_mount = mock.Mock() self._driver._do_umount = mock.Mock() shutil.rmtree = mock.Mock() gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'ssh root@host1 gluster volume set gv1 server.ssl off' ] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._wipe_gluster_vol, gaddr1) self.assertFalse(self._driver._restart_gluster_vol.called) self.assertFalse(tempfile.mkdtemp.called) self.assertFalse(self._driver._do_mount.called) self.assertFalse(self._driver._do_umount.called) self.assertFalse(shutil.rmtree.called)
def test_get_export_dir_dict(self): self._driver.gluster_address = Mock( make_gluster_args=Mock(return_value=(('true',), {}))) def exec_runner(*ignore_args, **ignore_kwargs): return """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <cliOutput> <volInfo> <volumes> <volume> <options> <option> <name>nfs.export-dir</name> <value>/foo(10.0.0.1|10.0.0.2),/bar(10.0.0.1)</value> </option> </options> </volume> <count>1</count> </volumes> </volInfo> </cliOutput>""", '' expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) ret = self._driver._get_export_dir_dict() self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertEqual(ret, {'foo': ['10.0.0.1', '10.0.0.2'], 'bar': ['10.0.0.1']} )
def test_wipe_gluster_vol_excp2(self): self._driver._restart_gluster_vol = mock.Mock() self._driver._do_mount = mock.Mock() self._driver._do_umount = mock.Mock() shutil.rmtree = mock.Mock() gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'ssh root@host1 gluster volume set gv1 server.ssl off'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._wipe_gluster_vol, gaddr1) self.assertFalse(self._driver._restart_gluster_vol.called) self.assertFalse(tempfile.mkdtemp.called) self.assertFalse(self._driver._do_mount.called) self.assertFalse(self._driver._do_umount.called) self.assertFalse(shutil.rmtree.called)
def test_setup_gluster_vol_error_enabling_creation_share_specific_size( self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='fake error') args1 = ('volume', 'set', 'testvol', 'nfs.export-volumes', 'off') args2 = ('volume', 'quota', 'testvol', 'enable') cmd_join = lambda args: 'gluster ' + ' '.join(arg for arg in args) expected_exec = [cmd_join(args1), cmd_join(args2)] self.stubs.Set( self._driver.gluster_address, 'make_gluster_args', mock.Mock(side_effect=[(('gluster', ) + args1, {}), (('gluster', ) + args2, {})])) self.stubs.Set(glusterfs.LOG, 'error', mock.Mock()) self.stubs.Set(self._driver, '_get_gluster_vol_option', mock.Mock(return_value='off')) fake_utils.fake_execute_set_repliers([(expected_exec[1], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._setup_gluster_vol) self._driver.gluster_address.make_gluster_args.has_calls( mock.call(args1), mock.call(args2)) self.assertEqual(expected_exec, fake_utils.fake_execute_get_log()) self._driver._get_gluster_vol_option.assert_called_once_with( 'features.quota') glusterfs.LOG.error.assert_called_once_with(mock.ANY, mock.ANY)
def test_do_mount_fail_ensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise RuntimeError('fake error') expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(RuntimeError, self._driver._do_mount, expected_exec, True) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_mount_gluster_vol_fail(self, ensure): def exec_runner(*ignore_args, **ignore_kwargs): raise RuntimeError('fake error') expected_exec = self._mount_exec(fakeexport, fakemnt) fake_utils.fake_execute_set_repliers([('mount', exec_runner)]) self.assertRaises(RuntimeError, common._mount_gluster_vol, self._execute, fakeexport, fakemnt, ensure) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_umount_gluster_vol_fail(self, in_exc, out_exc): def exec_runner(*ignore_args, **ignore_kwargs): raise in_exc('fake error') expected_exec = ['umount %s' % fakemnt] fake_utils.fake_execute_set_repliers([('umount', exec_runner)]) self.assertRaises(out_exc, common._umount_gluster_vol, self._execute, fakemnt) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_mount_gluster_vol_fail(self, ensure): def exec_runner(*ignore_args, **ignore_kwargs): raise RuntimeError('fake error') expected_exec = self._mount_exec(fakeexport, fakemnt) fake_utils.fake_execute_set_repliers([('mount', exec_runner)]) self.assertRaises(RuntimeError, common._mount_gluster_vol, self._execute, fakeexport, fakemnt, ensure) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_umount_gluster_vol_fail(self, in_exc, out_exc): def exec_runner(*ignore_args, **ignore_kwargs): raise in_exc('fake error') expected_exec = ['umount %s' % fakemnt] fake_utils.fake_execute_set_repliers([('umount', exec_runner)]) self.assertRaises(out_exc, common._umount_gluster_vol, self._execute, fakemnt) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_do_mount_mounted_noensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._do_mount, expected_exec, False) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_do_mount_fail_ensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise RuntimeError('fake error') expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(RuntimeError, self._driver._do_mount, expected_exec, True) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_allow_access_negative(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n/opt/nfs\t\t10.0.0.*\n', '' fake_utils.fake_execute_set_repliers([('exportfs', exec_runner)]) self.assertRaises(exception.ShareAccessExists, self._helper.allow_access, '/opt/nfs', 'volume-00001', 'ip', '10.0.0.*')
def test_do_mount_mounted_noensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._do_mount, expected_exec, False) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_check_for_setup_error_no_vg(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake0\n fake1\n fake2\n', '' fake_utils.fake_execute_set_repliers([('sudo vgs --noheadings -o name', exec_runner)]) self.assertRaises(exception.InvalidParameterValue, self._driver.check_for_setup_error)
def test_check_for_setup_error(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake1\n fakevg\n fake2\n', '' expected_exec = ['vgs --noheadings -o name'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self._driver.check_for_setup_error() self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
def test_allow_access_negative(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n/opt/nfs\t\t10.0.0.*\n', '' fake_utils.fake_execute_set_repliers([('exportfs', exec_runner)]) self.assertRaises(exception.ShareAccessExists, self._helper.allow_access, '/opt/nfs', 'volume-00001', 'ip', '10.0.0.*')
def test_check_for_setup_error_no_vg(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake0\n fake1\n fake2\n', '' fake_utils.fake_execute_set_repliers([('vgs --noheadings -o name', exec_runner)]) self.assertRaises(exception.InvalidParameterValue, self._driver.check_for_setup_error)
def test_check_for_setup_error(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake1\n fakevg\n fake2\n', '' expected_exec = ['vgs --noheadings -o name'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self._driver.check_for_setup_error() self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
def test_mount_gluster_vol_mounted_noensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = self._mount_exec(fakeexport, fakemnt) fake_utils.fake_execute_set_repliers([('mount', exec_runner)]) self.assertRaises(exception.GlusterfsException, common._mount_gluster_vol, self._execute, fakeexport, fakemnt, False) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_check_for_setup_error_deprecated_export_ip(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake1\n fakevg\n fake2\n', '' fake_utils.fake_execute_set_repliers([('vgs --noheadings -o name', exec_runner)]) CONF.set_default('lvm_share_export_ip', CONF.lvm_share_export_ips[0]) CONF.set_default('lvm_share_export_ips', None) self.assertIsNone(self._driver.check_for_setup_error())
def test_do_setup_mount_glusterfs_not_installed(self): def exec_runner(*ignore_args, **ignore_kwargs): raise OSError(errno.ENOENT, os.strerror(errno.ENOENT)) expected_exec = ['mount.glusterfs'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver.do_setup, self._context)
def test_check_for_setup_error_both_export_ip_and_ips(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake1\n fakevg\n fake2\n', '' fake_utils.fake_execute_set_repliers([('vgs --noheadings -o name', exec_runner)]) CONF.set_default('lvm_share_export_ip', CONF.lvm_share_export_ips[0]) self.assertRaises(exception.InvalidParameterValue, self._driver.check_for_setup_error)
def test_mount_gluster_vol_mounted_noensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = self._mount_exec(fakeexport, fakemnt) fake_utils.fake_execute_set_repliers([('mount', exec_runner)]) self.assertRaises(exception.GlusterfsException, common._mount_gluster_vol, self._execute, fakeexport, fakemnt, False) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_check_for_setup_error_deprecated_export_ip(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake1\n fakevg\n fake2\n', '' fake_utils.fake_execute_set_repliers([('vgs --noheadings -o name', exec_runner)]) CONF.set_default('lvm_share_export_ip', CONF.lvm_share_export_ips[0]) CONF.set_default('lvm_share_export_ips', None) self.assertIsNone(self._driver.check_for_setup_error())
def test_check_for_setup_error_no_export_ip(self): def exec_runner(*ignore_args, **ignore_kwargs): return '\n fake1\n fakevg\n fake2\n', '' fake_utils.fake_execute_set_repliers([('sudo vgs --noheadings -o name', exec_runner)]) CONF.set_default('lvm_share_export_ip', None) self.assertRaises(exception.InvalidParameterValue, self._driver.check_for_setup_error)
def test_do_setup_mount_glusterfs_not_installed(self): def exec_runner(*ignore_args, **ignore_kwargs): raise OSError(errno.ENOENT, os.strerror(errno.ENOENT)) expected_exec = ['mount.glusterfs'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver.do_setup, self._context)
def test_get_export_dir_dict_failing_volinfo(self): self._driver.gluster_address = Mock( make_gluster_args=Mock(return_value=(('true',), {}))) def exec_runner(*ignore_args, **ignore_kwargs): raise RuntimeError('fake error') expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(RuntimeError, self._driver._get_export_dir_dict) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_get_export_dir_list_failing_volinfo(self): self._driver.gluster_address = Mock(make_gluster_args= Mock(return_value=(('true',), {}))) def exec_runner(*ignore_args, **ignore_kwargs): raise RuntimeError('fake error') expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(RuntimeError, self._driver._get_export_dir_list) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
def test_check_mount_glusterfs_not_installed(self, _errno, _exception): fake_conf = mock.Mock() _layout = self.FakeLayout(self.fake_driver, configuration=fake_conf) def exec_runner(*ignore_args, **ignore_kwargs): raise OSError(_errno, os.strerror(_errno)) expected_exec = ['mount.glusterfs'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(_exception, _layout._check_mount_glusterfs)
def test_cannot_delete_share(self): self._driver._get_local_share_path =\ mock.Mock(return_value='/mnt/nfs/testvol/fakename') def exec_runner(*ignore_args, **ignore_kw): raise exception.ProcessExecutionError expected_exec = ['rm -rf %s' % (self._driver._get_local_share_path())] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.ProcessExecutionError, self._driver.delete_share, self._context, self.share)
def test_do_umount_excp(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError tmpdir = '/tmp/tmpKGHKJ' expected_exec = ['umount /tmp/tmpKGHKJ'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._do_umount, tmpdir)
def test_cannot_delete_share(self): self._driver._get_local_share_path =\ Mock(return_value='/mnt/nfs/testvol/fakename') def exec_runner(*ignore_args, **ignore_kw): raise exception.ProcessExecutionError expected_exec = ['rm -rf %s' % (self._driver._get_local_share_path())] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.ProcessExecutionError, self._driver.delete_share, self._context, self.share)
def test__unmount_device_rmdir_error(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='fake error') mount_path = self._get_mount_path(self.share) self._os.path.exists.return_value = True cmd = "rmdir %s" % (mount_path) fake_utils.fake_execute_set_repliers([(cmd, exec_runner)]) self.assertRaises(processutils.ProcessExecutionError, self._driver._unmount_device, self.share) self._os.path.exists.assert_called_with(mount_path)
def test_do_setup_mount_glusterfs_not_installed(self): self._driver._read_gluster_vol_from_config =\ Mock(return_value='[email protected]:/testvol/fakename') def exec_runner(*ignore_args, **ignore_kw): raise OSError(errno.ENOENT, os.strerror(errno.ENOENT)) expected_exec = ['mount.glusterfs'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver.do_setup, self._context)
def test_do_mount_mounted_ensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = ['true'] glusterfs.LOG.warn = Mock() fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) ret = self._driver._do_mount(expected_exec, True) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertEqual(ret, None) glusterfs.LOG.warn.assert_called_with( "%s is already mounted", self._driver.gluster_address.export)
def test_do_mount_mounted_ensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = ['true'] glusterfs.LOG.warn = Mock() fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) ret = self._driver._do_mount(expected_exec, True) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertEqual(ret, None) glusterfs.LOG.warn.assert_called_with( "%s is already mounted", self._driver.gluster_address.export)
def test_check_mount_glusterfs_not_installed(self, _errno, _exception): fake_conf = mock.Mock() _layout = self.FakeLayout(self.fake_driver, configuration=fake_conf) def exec_runner(*ignore_args, **ignore_kwargs): raise OSError(_errno, os.strerror(_errno)) expected_exec = ['mount.glusterfs'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(_exception, _layout._check_mount_glusterfs)
def test__unmount_device_rmdir_error(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='fake error') mount_path = self._get_mount_path(self.share) self._os.path.exists.return_value = True cmd = "rmdir %s" % (mount_path) fake_utils.fake_execute_set_repliers([(cmd, exec_runner)]) self.assertRaises(processutils.ProcessExecutionError, self._driver._unmount_device, self.share) self._os.path.exists.assert_called_with(mount_path)
def test_do_umount_excp(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError tmpdir = '/tmp/tmpKGHKJ' expected_exec = ['umount /tmp/tmpKGHKJ'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._do_umount, tmpdir)
def test_remove_export_error(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='fake error') mount_path = self._get_mount_path(self.share) expected_exec = [ "umount -f %s" % (mount_path), ] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self._os.path.exists.return_value = True self._driver._remove_export(self._context, self.share) self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
def test_mount_device_error(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='fake error') mount_path = self._get_mount_path(self.share) expected_exec = [ "mkdir -p %s" % (mount_path,), "mount fakedevice %s" % (mount_path,), ] fake_utils.fake_execute_set_repliers([(expected_exec[1], exec_runner)]) self.assertRaises(exception.ProcessExecutionError, self._driver._mount_device, self.share, 'fakedevice')
def test_delete_share_error(self): self._driver.gluster_address = mock.Mock(make_gluster_args=mock.Mock( return_value=(('true', ), {}))) def exec_runner(*ignore_args, **ignore_kw): raise exception.ProcessExecutionError expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.ProcessExecutionError, self._driver.delete_share, self._context, self.share)
def test_mount_gluster_vol_mounted_ensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = self._mount_exec(fakeexport, fakemnt) common.LOG.warning = mock.Mock() fake_utils.fake_execute_set_repliers([('mount', exec_runner)]) ret = common._mount_gluster_vol(self._execute, fakeexport, fakemnt, True) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertIsNone(ret) common.LOG.warning.assert_called_with( "%s is already mounted.", fakeexport)
def test_mount_device_error(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='fake error') mount_path = self._get_mount_path(self.share) expected_exec = [ "mkdir -p %s" % (mount_path, ), "mount fakedevice %s" % (mount_path, ), ] fake_utils.fake_execute_set_repliers([(expected_exec[1], exec_runner)]) self.assertRaises(exception.ProcessExecutionError, self._driver._mount_device, self.share, 'fakedevice')
def test_restart_gluster_vol_excp2(self): gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = ['ssh root@host1 gluster volume start gv1'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._restart_gluster_vol, gaddr1)
def test_do_setup_mount_glusterfs_not_installed(self): self._driver._read_gluster_vol_from_config =\ Mock(return_value='127.0.0.1:/testvol') self._driver._ensure_gluster_vol_mounted = Mock() def exec_runner(*ignore_args, **ignore_kwargs): raise OSError(errno.ENOENT, os.strerror(errno.ENOENT)) expected_exec = ['mount.glusterfs'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver.do_setup, self._context)
def test_delete_share_error(self): self._driver.gluster_address = mock.Mock( make_gluster_args=mock.Mock(return_value=(('true',), {}))) def exec_runner(*ignore_args, **ignore_kw): raise exception.ProcessExecutionError expected_exec = ['true'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.ProcessExecutionError, self._driver.delete_share, self._context, self.share)
def test_mount_gluster_vol_mounted_ensure(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') expected_exec = self._mount_exec(fakeexport, fakemnt) common.LOG.warning = mock.Mock() fake_utils.fake_execute_set_repliers([('mount', exec_runner)]) ret = common._mount_gluster_vol(self._execute, fakeexport, fakemnt, True) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertIsNone(ret) common.LOG.warning.assert_called_with( "%s is already mounted.", fakeexport)
def test_restart_gluster_vol_excp2(self): gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError expected_exec = [ 'ssh root@host1 gluster volume start gv1'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._restart_gluster_vol, gaddr1)
def test_do_mount_excp(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) tmpdir = '/tmp/tmpKGHKJ' expected_exec = ['mount -t glusterfs host1:/gv1 /tmp/tmpKGHKJ'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._do_mount, gaddr1.export, tmpdir)
def test_cleanup_create_share_cannot_cleanup_unusable_share(self): def exec_runner(*ignore_args, **ignore_kw): raise exception.ProcessExecutionError expected_exec = ['rm -rf %s' % fake_local_share_path] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.mock_object(glusterfs.LOG, 'error') self.mock_object(os.path, 'exists', mock.Mock(return_value=True)) self.assertRaises(exception.GlusterfsException, self._driver._cleanup_create_share, fake_local_share_path, self.share['name']) os.path.exists.assert_called_once_with(fake_local_share_path) glusterfs.LOG.error.assert_called_once_with(mock.ANY, mock.ANY)
def test_do_mount_excp(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError gaddr = glusterfs.GlusterAddress gaddr1 = gaddr(self.gluster_target1) tmpdir = '/tmp/tmpKGHKJ' expected_exec = ['mount -t glusterfs host1:/gv1 /tmp/tmpKGHKJ'] fake_utils.fake_execute_set_repliers([(expected_exec[0], exec_runner)]) self.assertRaises(exception.GlusterfsException, self._driver._do_mount, gaddr1.export, tmpdir)
def test_mount_device_already(self): def exec_runner(*ignore_args, **ignore_kwargs): raise exception.ProcessExecutionError(stderr='already mounted') mount_path = self._get_mount_path(self.share) expected_exec = [ "mkdir -p %s" % (mount_path,), "mount fakedevice %s" % (mount_path,), ] fake_utils.fake_execute_set_repliers([(expected_exec[1], exec_runner)]) ret = self._driver._mount_device(self.share, 'fakedevice') self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) self.assertEqual(ret, mount_path)