Esempio n. 1
0
    def test_wipe_gluster_vol_excp4(self):
        self._driver._restart_gluster_vol = mock.Mock()
        self._driver._do_mount = mock.Mock()
        self._driver._do_umount = mock.Mock()
        shutil.rmtree = mock.Mock()
        test_args = [
            ('volume', 'set', 'gv1', 'client.ssl', 'off'),
            ('volume', 'set', 'gv1', 'server.ssl', 'off'),
            ('volume', 'set', 'gv1', 'client.ssl', 'on'),
            ('volume', 'set', 'gv1', 'server.ssl', 'on')]

        def raise_exception(*args, **kwargs):
            if(args == test_args[3]):
                raise exception.ProcessExecutionError()

        gmgr = glusterfs.GlusterManager
        gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None)
        self.mock_object(gmgr1, 'gluster_call',
                         mock.Mock(side_effect=raise_exception))

        expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete']

        self.assertRaises(exception.GlusterfsException,
                          self._driver._wipe_gluster_vol, gmgr1)
        self.assertEqual(
            [mock.call(*test_args[0]), mock.call(*test_args[1]),
             mock.call(*test_args[2]), mock.call(*test_args[3])],
            gmgr1.gluster_call.call_args_list)
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        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_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'])
Esempio n. 3
0
    def test_wipe_gluster_vol_umount_fail(self):
        self._driver._restart_gluster_vol = mock.Mock()
        self._driver._do_mount = mock.Mock()
        self._driver._do_umount = mock.Mock()
        self._driver._do_umount.side_effect = exception.GlusterfsException
        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')]

        expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete']

        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.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        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.assertFalse(shutil.rmtree.called)
Esempio n. 4
0
    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_wipe_gluster_vol_umount_fail(self):
        self._driver._restart_gluster_vol = mock.Mock()
        self._driver._do_mount = mock.Mock()
        self._driver._do_umount = mock.Mock()
        self._driver._do_umount.side_effect = exception.GlusterfsException
        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')]

        expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete']

        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.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        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.assertFalse(shutil.rmtree.called)
Esempio n. 6
0
 def test_get_gluster_vol_option_empty_volinfo(self):
     self._driver.gluster_address = mock.Mock(make_gluster_args=mock.Mock(
         return_value=(('true', ), {})))
     expected_exec = ['true']
     self.assertRaises(exception.GlusterfsException,
                       self._driver._get_gluster_vol_option, NFS_EXPORT_DIR)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
    def test_create_share(self, extra_args):
        exec_cmd1 = 'mkdir %s' % fake_local_share_path
        expected_exec = [exec_cmd1, ]
        expected_ret = '[email protected]:/testvol/fakename'
        self.mock_object(
            self._layout, '_get_local_share_path',
            mock.Mock(return_value=fake_local_share_path))
        gmgr = mock.Mock()
        self.mock_object(
            self._layout, '_glustermanager', mock.Mock(return_value=gmgr))
        self.mock_object(
            self._layout.driver, '_setup_via_manager',
            mock.Mock(return_value=expected_ret))

        ret = self._layout.create_share(self._context, self.share, *extra_args)

        self._layout._get_local_share_path.called_once_with(self.share)
        self._layout.gluster_manager.gluster_call.assert_called_once_with(
            'volume', 'quota', 'testvol', 'limit-usage', '/fakename', '1GB')
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        self._layout._glustermanager.assert_called_once_with(
            {'user': '******', 'host': '127.0.0.1',
             'volume': 'testvol', 'path': '/fakename'})
        self._layout.driver._setup_via_manager.assert_called_once_with(
            {'share': self.share, 'manager': gmgr})
        self.assertEqual(expected_ret, ret)
Esempio n. 8
0
    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_get_export_dir_list_empty_volinfo(self):
     self._driver.gluster_address = Mock(make_gluster_args=
         Mock(return_value=(('true',), {})))
     expected_exec = ['true']
     self.assertRaises(exception.GlusterfsException,
                       self._driver._get_export_dir_list)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 10
0
 def test_get_export_dir_dict_empty_volinfo(self):
     self._driver.gluster_address = Mock(
         make_gluster_args=Mock(return_value=(('true',), {})))
     expected_exec = ['true']
     self.assertRaises(exception.GlusterfsException,
                       self._driver._get_export_dir_dict)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 11
0
 def test_create_snapshot(self):
     self._driver.create_snapshot(self._context, self.snapshot)
     expected_exec = [
         ("lvcreate -L 1G --name fakesnapshotname --snapshot %s/fakename" %
          (CONF.share_volume_group,)),
     ]
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 12
0
    def test_wipe_gluster_vol_excp4(self):
        self._driver._restart_gluster_vol = mock.Mock()
        self._driver._do_mount = mock.Mock()
        self._driver._do_umount = mock.Mock()
        shutil.rmtree = mock.Mock()
        test_args = [
            ('volume', 'set', 'gv1', 'client.ssl', 'off'),
            ('volume', 'set', 'gv1', 'server.ssl', 'off'),
            ('volume', 'set', 'gv1', 'client.ssl', 'on'),
            ('volume', 'set', 'gv1', 'server.ssl', 'on')]

        def raise_exception(*args, **kwargs):
            if(args == test_args[3]):
                raise exception.ProcessExecutionError()

        gmgr = glusterfs.GlusterManager
        gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None)
        self.mock_object(gmgr1, 'gluster_call',
                         mock.Mock(side_effect=raise_exception))

        expected_exec = ['find /tmp/tmpKGHKJ -mindepth 1 -delete']

        self.assertRaises(exception.GlusterfsException,
                          self._driver._wipe_gluster_vol, gmgr1)
        self.assertEqual(
            [mock.call(*test_args[0]), mock.call(*test_args[1]),
             mock.call(*test_args[2]), mock.call(*test_args[3])],
            gmgr1.gluster_call.call_args_list)
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        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_create_share_from_snapshot(self):
        CONF.set_default('lvm_share_mirrors', 0)
        self._driver._mount_device = mock.Mock()
        snapshot_instance = {
            'snapshot_id': 'fakesnapshotid',
            'name': 'fakename'
        }
        mount_share = '/dev/mapper/fakevg-fakename'
        mount_snapshot = '/dev/mapper/fakevg-fakename'
        self._helper_nfs.create_export.return_value = 'fakelocation'
        self._driver.create_share_from_snapshot(self._context,
                                                self.share,
                                                snapshot_instance,
                                                self.share_server)

        self._driver._mount_device.assert_called_with(self.share,
                                                      mount_snapshot)
        expected_exec = [
            'lvcreate -L 1G -n fakename fakevg',
            'mkfs.ext4 /dev/mapper/fakevg-fakename',
            ("dd count=0 if=%s of=%s iflag=direct oflag=direct" %
             (mount_snapshot, mount_share)),
            ("dd if=%s of=%s count=1024 bs=1M iflag=direct oflag=direct" %
             (mount_snapshot, mount_share)),
        ]
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 14
0
    def test_do_umount(self):
        tmpdir = '/tmp/tmpKGHKJ'
        expected_exec = ['umount /tmp/tmpKGHKJ']

        self._driver._do_umount(tmpdir)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 15
0
    def test_create_share(self, extra_args):
        exec_cmd1 = 'mkdir %s' % fake_local_share_path
        expected_exec = [exec_cmd1, ]
        expected_ret = '[email protected]:/testvol/fakename'
        self.mock_object(
            self._layout, '_get_local_share_path',
            mock.Mock(return_value=fake_local_share_path))
        gmgr = mock.Mock()
        self.mock_object(
            self._layout, '_glustermanager', mock.Mock(return_value=gmgr))
        self.mock_object(
            self._layout.driver, '_setup_via_manager',
            mock.Mock(return_value=expected_ret))

        ret = self._layout.create_share(self._context, self.share, *extra_args)

        self._layout._get_local_share_path.called_once_with(self.share)
        self._layout.gluster_manager.gluster_call.assert_called_once_with(
            'volume', 'quota', 'testvol', 'limit-usage', '/fakename', '1GB')
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        self._layout._glustermanager.assert_called_once_with(
            {'user': '******', 'host': '127.0.0.1',
             'volume': 'testvol', 'path': '/fakename'})
        self._layout.driver._setup_via_manager.assert_called_once_with(
            {'share': self.share, 'manager': gmgr})
        self.assertEqual(expected_ret, ret)
Esempio n. 16
0
    def test_create_share_from_snapshot(self):
        CONF.set_default('lvm_share_mirrors', 0)
        self._driver._mount_device = mock.Mock()
        snapshot_instance = {
            'snapshot_id': 'fakesnapshotid',
            'name': 'fakename'
        }
        mount_share = '/dev/mapper/fakevg-fakename'
        mount_snapshot = '/dev/mapper/fakevg-fakename'
        self._helper_nfs.create_export.return_value = 'fakelocation'
        self._driver.create_share_from_snapshot(self._context, self.share,
                                                snapshot_instance,
                                                self.share_server)

        self._driver._mount_device.assert_called_with(self.share,
                                                      mount_snapshot)
        expected_exec = [
            'lvcreate -L 1G -n fakename fakevg',
            'mkfs.ext4 /dev/mapper/fakevg-fakename',
            'tune2fs -U random %s' % mount_share,
            ("dd count=0 if=%s of=%s iflag=direct oflag=direct" %
             (mount_snapshot, mount_share)),
            ("dd if=%s of=%s count=1024 bs=1M iflag=direct oflag=direct" %
             (mount_snapshot, mount_share)),
        ]
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 17
0
 def test_do_setup_error_already_enabled_creation_share_specific_size(self):
     attrs = {'volume': 'testvol',
              'gluster_call.side_effect': exception.ProcessExecutionError,
              'get_gluster_vol_option.return_value': 'on'}
     fake_gluster_manager = mock.Mock(**attrs)
     self.mock_object(glusterfs.LOG, 'error')
     methods = ('_ensure_gluster_vol_mounted', '_setup_helpers')
     for method in methods:
         self.mock_object(self._driver, method)
     self.mock_object(glusterfs, 'GlusterManager',
                      mock.Mock(return_value=fake_gluster_manager))
     expected_exec = ['mount.glusterfs']
     exec_cmd1 = 'mount.glusterfs'
     expected_exec = [exec_cmd1]
     args = ('volume', 'quota', 'testvol', 'enable')
     self._driver.do_setup(self._context)
     self.assertEqual(fake_gluster_manager, self._driver.gluster_manager)
     glusterfs.GlusterManager.assert_called_once_with(
         self._driver.configuration.glusterfs_target, self._execute,
         self._driver.configuration.glusterfs_path_to_private_key,
         self._driver.configuration.glusterfs_server_password)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self._driver.gluster_manager.gluster_call.assert_called_once_with(
         *args)
     (self._driver.gluster_manager.get_gluster_vol_option.
      assert_called_once_with('features.quota'))
     self.assertFalse(glusterfs.LOG.error.called)
     self._driver._setup_helpers.assert_called_once_with()
     self._driver._ensure_gluster_vol_mounted.assert_called_once_with()
Esempio n. 18
0
    def test_do_umount(self):
        tmpdir = '/tmp/tmpKGHKJ'
        expected_exec = ['umount /tmp/tmpKGHKJ']

        self._driver._do_umount(tmpdir)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 19
0
 def test_revert_to_snapshot(self):
     mock_update_access = self.mock_object(self._helper_nfs,
                                           'update_access')
     self._driver.revert_to_snapshot(self._context, self.snapshot, [], [],
                                     self.share_server)
     snap_lv = "%s/fakesnapshotname" % (CONF.lvm_share_volume_group)
     share_lv = "%s/fakename" % (CONF.lvm_share_volume_group)
     share_mount_path = self._get_mount_path(self.snapshot['share'])
     snapshot_mount_path = self._get_mount_path(self.snapshot)
     expected_exec = [
         ('umount -f %s' % snapshot_mount_path),
         ("rmdir %s" % snapshot_mount_path),
         ("umount -f %s" % share_mount_path),
         ("rmdir %s" % share_mount_path),
         ("lvconvert --merge %s" % snap_lv),
         ("lvcreate -L 1G --name fakesnapshotname --snapshot %s" %
          share_lv),
         ('tune2fs -U random /dev/mapper/%s-fakesnapshotname' %
          CONF.lvm_share_volume_group),
         ("mkdir -p %s" % share_mount_path),
         ("mount /dev/mapper/%s-fakename %s" %
          (CONF.lvm_share_volume_group, share_mount_path)),
         ("chmod 777 %s" % share_mount_path),
         ("mkdir -p %s" % snapshot_mount_path),
         ("mount /dev/mapper/fakevg-fakesnapshotname "
          "%s" % snapshot_mount_path),
         ("chmod 777 %s" % snapshot_mount_path),
     ]
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self.assertEqual(4, mock_update_access.call_count)
Esempio n. 20
0
 def test_do_setup_error_already_enabled_creation_share_specific_size(self):
     attrs = {
         'volume': 'testvol',
         'gluster_call.side_effect': exception.ProcessExecutionError,
         'get_gluster_vol_option.return_value': 'on'
     }
     fake_gluster_manager = mock.Mock(**attrs)
     self.mock_object(glusterfs.LOG, 'error')
     methods = ('_ensure_gluster_vol_mounted', '_setup_helpers')
     for method in methods:
         self.mock_object(self._driver, method)
     self.mock_object(glusterfs, 'GlusterManager',
                      mock.Mock(return_value=fake_gluster_manager))
     expected_exec = ['mount.glusterfs']
     exec_cmd1 = 'mount.glusterfs'
     expected_exec = [exec_cmd1]
     args = ('volume', 'quota', 'testvol', 'enable')
     self._driver.do_setup(self._context)
     self.assertEqual(fake_gluster_manager, self._driver.gluster_manager)
     glusterfs.GlusterManager.assert_called_once_with(
         self._driver.configuration.glusterfs_target, self._execute,
         self._driver.configuration.glusterfs_path_to_private_key,
         self._driver.configuration.glusterfs_server_password)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self._driver.gluster_manager.gluster_call.assert_called_once_with(
         *args)
     (self._driver.gluster_manager.get_gluster_vol_option.
      assert_called_once_with('features.quota'))
     self.assertFalse(glusterfs.LOG.error.called)
     self._driver._setup_helpers.assert_called_once_with()
     self._driver._ensure_gluster_vol_mounted.assert_called_once_with()
Esempio n. 21
0
 def test_revert_to_snapshot(self):
     mock_update_access = self.mock_object(self._helper_nfs,
                                           'update_access')
     self._driver.revert_to_snapshot(self._context, self.snapshot,
                                     [], [], self.share_server)
     snap_lv = "%s/fakesnapshotname" % (CONF.lvm_share_volume_group)
     share_lv = "%s/fakename" % (CONF.lvm_share_volume_group)
     share_mount_path = self._get_mount_path(self.snapshot['share'])
     snapshot_mount_path = self._get_mount_path(self.snapshot)
     expected_exec = [
         ('umount -f %s' % snapshot_mount_path),
         ("rmdir %s" % snapshot_mount_path),
         ("umount -f %s" % share_mount_path),
         ("rmdir %s" % share_mount_path),
         ("lvconvert --merge %s" % snap_lv),
         ("lvcreate -L 1G --name fakesnapshotname --snapshot %s" %
             share_lv),
         ("e2fsck -y -f /dev/mapper/%s-fakesnapshotname" %
             CONF.lvm_share_volume_group),
         ("tune2fs -U random /dev/mapper/%s-fakesnapshotname" %
             CONF.lvm_share_volume_group),
         ("mkdir -p %s" % share_mount_path),
         ("mount /dev/mapper/%s-fakename %s" %
             (CONF.lvm_share_volume_group, share_mount_path)),
         ("chmod 777 %s" % share_mount_path),
         ("mkdir -p %s" % snapshot_mount_path),
         ("mount /dev/mapper/fakevg-fakesnapshotname "
          "%s" % snapshot_mount_path),
         ("chmod 777 %s" % snapshot_mount_path),
     ]
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self.assertEqual(4, mock_update_access.call_count)
Esempio n. 22
0
    def test_wipe_gluster_vol(self, vers_minor, cmd):
        self._driver._restart_gluster_vol = mock.Mock()
        self._driver._do_mount = mock.Mock()
        self._driver._do_umount = mock.Mock()
        shutil.rmtree = mock.Mock()
        test_args = [
            ('volume', 'set', 'gv1', 'client.ssl', 'off'),
            ('volume', 'set', 'gv1', 'server.ssl', 'off'),
            ('volume', 'set', 'gv1', 'client.ssl', 'on'),
            ('volume', 'set', 'gv1', 'server.ssl', 'on')]

        gmgr = glusterfs.GlusterManager
        gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None)
        self._driver.glusterfs_versions = {
            self.glusterfs_server1: ('3', vers_minor)}
        expected_exec = [cmd]

        self._driver._wipe_gluster_vol(gmgr1)

        self.assertEqual(2, self._driver._restart_gluster_vol.call_count)
        self.assertEqual(
            [mock.call(*test_args[0]), mock.call(*test_args[1]),
             mock.call(*test_args[2]), mock.call(*test_args[3])],
            gmgr1.gluster_call.call_args_list)
        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        self.assertTrue(tempfile.mkdtemp.called)
        self.assertTrue(self._driver._do_mount.called)
        self.assertTrue(self._driver._do_umount.called)
        self.assertTrue(shutil.rmtree.called)
Esempio n. 23
0
    def test_wipe_gluster_vol_umount_fail(self):
        self._driver._restart_gluster_vol = mock.Mock()
        self._driver._do_mount = mock.Mock()
        self._driver._do_umount = mock.Mock()
        self._driver._do_umount.side_effect = exception.GlusterfsException
        shutil.rmtree = mock.Mock()

        gaddr = glusterfs.GlusterAddress
        gaddr1 = gaddr(self.gluster_target1)

        expected_exec = [
            'ssh root@host1 gluster volume set gv1 client.ssl off',
            'ssh root@host1 gluster volume set gv1 server.ssl off',
            'find /tmp/tmpKGHKJ -mindepth 1 -delete'
        ]

        self.assertRaises(exception.GlusterfsException,
                          self._driver._wipe_gluster_vol, gaddr1)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
        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.assertFalse(shutil.rmtree.called)
Esempio n. 24
0
 def test_cleanup_create_share_local_share_path_exists(self):
     expected_exec = ['rm -rf %s' % fake_local_share_path]
     self.mock_object(os.path, 'exists', mock.Mock(return_value=True))
     ret = self._driver._cleanup_create_share(fake_local_share_path,
                                              self.share['name'])
     os.path.exists.assert_called_once_with(fake_local_share_path)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self.assertEqual(None, ret)
Esempio n. 25
0
 def test_do_setup(self):
     self._driver._ensure_gluster_vol_mounted = mock.Mock()
     exec_cmd1 = 'mount.glusterfs'
     exec_cmd2 = 'gluster volume set testvol nfs.export-volumes off'
     expected_exec = [exec_cmd1, exec_cmd2]
     self._driver.do_setup(self._context)
     self._driver._ensure_gluster_vol_mounted.assert_called_once_with()
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 26
0
 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)
Esempio n. 27
0
 def test_create_snapshot(self):
     self._driver.create_snapshot(self._context, self.snapshot,
                                  self.share_server)
     expected_exec = [
         ("lvcreate -L 1G --name fakesnapshotname --snapshot "
          "%s/fakename" % (CONF.lvm_share_volume_group,)),
     ]
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 28
0
    def test_delete_share(self):
        self._driver._get_local_share_path =\
            mock.Mock(return_value='/mnt/nfs/testvol/fakename')

        expected_exec = ['rm -rf /mnt/nfs/testvol/fakename']

        self._driver.delete_share(self._context, self.share)
        self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 29
0
    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())
Esempio n. 30
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)
Esempio n. 31
0
 def test_delete_snapshot(self):
     expected_exec = [
         'umount -f ' + self._get_mount_path(self.snapshot),
         'lvremove -f fakevg/fakesnapshotname',
     ]
     self._driver.delete_snapshot(self._context, self.snapshot,
                                  self.share_server)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 32
0
 def test_cleanup_create_share_local_share_path_exists(self):
     expected_exec = ['rm -rf %s' % fake_local_share_path]
     self.mock_object(os.path, 'exists', mock.Mock(return_value=True))
     ret = self._driver._cleanup_create_share(fake_local_share_path,
                                              self.share['name'])
     os.path.exists.assert_called_once_with(fake_local_share_path)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self.assertEqual(None, ret)
Esempio n. 33
0
 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)
Esempio n. 34
0
 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_delete_share(self):
        self._layout._get_local_share_path =\
            mock.Mock(return_value='/mnt/nfs/testvol/fakename')

        self._layout.delete_share(self._context, self.share)

        self.assertEqual(['rm -rf /mnt/nfs/testvol/fakename'],
                         fake_utils.fake_execute_get_log())
Esempio n. 36
0
    def test_delete_share(self):
        self._driver._get_local_share_path =\
            Mock(return_value='/mnt/nfs/testvol/fakename')

        expected_exec = ['rm -rf /mnt/nfs/testvol/fakename']

        self._driver.delete_share(self._context, self.share)
        self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 37
0
    def test_delete_share(self):
        self._layout._get_local_share_path =\
            mock.Mock(return_value='/mnt/nfs/testvol/fakename')

        self._layout.delete_share(self._context, self.share)

        self.assertEqual(['rm -rf /mnt/nfs/testvol/fakename'],
                         fake_utils.fake_execute_get_log())
Esempio n. 38
0
 def test_delete_snapshot(self):
     expected_exec = [
         'umount -f ' + self._get_mount_path(self.snapshot),
         'lvremove -f fakevg/fakesnapshotname',
     ]
     self._driver.delete_snapshot(self._context, self.snapshot,
                                  self.share_server)
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 39
0
 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)
Esempio n. 40
0
 def test_do_setup(self):
     self._driver._read_gluster_vol_from_config =\
         Mock(return_value='[email protected]:/testvol/fakename')
     self._driver._ensure_gluster_vol_mounted = Mock()
     expected_exec = ['mount.glusterfs']
     self._driver.do_setup(self._context)
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
     self._driver._ensure_gluster_vol_mounted.assert_called_once_with()
Esempio n. 41
0
 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)
Esempio n. 42
0
 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)
Esempio n. 43
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)
Esempio n. 44
0
    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())
Esempio n. 45
0
    def test_create_share(self):
        self._driver._get_local_share_path =\
            Mock(return_value='/mnt/nfs/testvol/fakename')
        expected_exec = ['mkdir /mnt/nfs/testvol/fakename', ]
        expected_ret = '[email protected]:/testvol/fakename'

        ret = self._driver.create_share(self._context, self.share)
        self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
        self.assertEqual(ret, expected_ret)
Esempio n. 46
0
 def test_allocate_container_normal(self):
     CONF.set_default('share_lvm_mirrors', 0)
     self.mox.ReplayAll()
     ret = self._driver.allocate_container(self._context, self.share)
     expected_exec = [
         'lvcreate -L 1G -n fakename fakevg',
         'mkfs.ext4 /dev/mapper/fakevg-fakename',
     ]
     self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 47
0
    def test_do_mount(self):
        gaddr = glusterfs.GlusterAddress
        gaddr1 = gaddr(self.gluster_target1)
        tmpdir = '/tmp/tmpKGHKJ'
        expected_exec = ['mount -t glusterfs host1:/gv1 /tmp/tmpKGHKJ']

        self._driver._do_mount(gaddr1.export, tmpdir)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 48
0
 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)
Esempio n. 49
0
    def test_allow_access(self):
        self._helper.allow_access('/opt/nfs', 'volume-00001', 'ip', '10.0.0.*')

        export_string = '10.0.0.*:/opt/nfs'
        expected_exec = [
            'exportfs',
            'exportfs -o rw,no_subtree_check %s' % export_string,
        ]
        self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 50
0
    def test_allow_access_via_manager_invalid_access_type(self):
        access = {'access_type': 'invalid', 'access_to': 'client.example.com'}
        expected_exec = []

        self.assertRaises(exception.InvalidShareAccess,
                          self._driver._allow_access_via_manager, self.gmgr1,
                          self._context, self.share1, access)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 51
0
    def test_do_mount(self):
        gmgr = glusterfs.GlusterManager
        gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None)
        tmpdir = '/tmp/tmpKGHKJ'
        expected_exec = ['mount -t glusterfs host1:/gv1 /tmp/tmpKGHKJ']

        self._driver._do_mount(gmgr1.export, tmpdir)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 52
0
    def test_allow_access(self):
        self._helper.allow_access('/opt/nfs', 'volume-00001', 'ip', '10.0.0.*')

        export_string = '10.0.0.*:/opt/nfs'
        expected_exec = [
            'exportfs',
            'exportfs -o rw,no_subtree_check %s' % export_string,
        ]
        self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
Esempio n. 53
0
 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_allow_access_via_manager_invalid_access_type(self):
        access = {'access_type': 'invalid', 'access_to': 'client.example.com'}
        expected_exec = []

        self.assertRaises(exception.InvalidShareAccess,
                          self._driver._allow_access_via_manager,
                          self.gmgr1, self._context, self.share1, access)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 55
0
    def test_do_mount(self):
        gaddr = glusterfs.GlusterAddress
        gaddr1 = gaddr(self.gluster_target1)
        tmpdir = '/tmp/tmpKGHKJ'
        expected_exec = ['mount -t glusterfs host1:/gv1 /tmp/tmpKGHKJ']

        self._driver._do_mount(gaddr1.export, tmpdir)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 56
0
    def test_create_share(self):
        self._driver._get_local_share_path =\
            Mock(return_value='/mnt/nfs/testvol/fakename')
        expected_exec = ['mkdir /mnt/nfs/testvol/fakename', ]
        expected_ret = '[email protected]:/testvol/fakename'

        ret = self._driver.create_share(self._context, self.share)
        self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec)
        self.assertEqual(ret, expected_ret)
Esempio n. 57
0
    def test_do_mount(self):
        gmgr = glusterfs.GlusterManager
        gmgr1 = gmgr(self.glusterfs_target1, self._execute, None, None)
        tmpdir = '/tmp/tmpKGHKJ'
        expected_exec = ['mount -t glusterfs host1:/gv1 /tmp/tmpKGHKJ']

        self._driver._do_mount(gmgr1.export, tmpdir)

        self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
Esempio n. 58
0
    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)
Esempio n. 59
0
    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)
Esempio n. 60
0
 def test_mount_device(self):
     mount_path = self._get_mount_path(self.share)
     ret = self._driver._mount_device(self.share, 'fakedevice')
     expected_exec = [
         "mkdir -p %s" % (mount_path, ),
         "mount fakedevice %s" % (mount_path, ),
         "chmod 777 %s" % (mount_path, ),
     ]
     self.assertEqual(expected_exec, fake_utils.fake_execute_get_log())
     self.assertEqual(mount_path, ret)