Ejemplo n.º 1
0
    def test_create_share_from_snapshot_empty_snapshot(self):
        self.mock_object(driver.HitachiHNASDriver, "_check_fs_mounted",
                         mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "vvol_create", mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "quota_add", mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "tree_clone", mock.Mock(
            side_effect=exception.HNASNothingToCloneException('msg')))
        self.mock_object(ssh.HNASSSHBackend, "nfs_export_add", mock.Mock())

        result = self._driver.create_share_from_snapshot('context', share_nfs,
                                                         snapshot_nfs)
        expected = [
            self._get_export(
                share_nfs, self._driver.hnas_evs_ip, False),
            self._get_export(
                share_nfs, self._driver.hnas_admin_network_ip, True)]

        self.assertEqual(expected, result)
        self.assertTrue(self.mock_log.warning.called)
        ssh.HNASSSHBackend.vvol_create.assert_called_once_with(share_nfs['id'])
        ssh.HNASSSHBackend.quota_add.assert_called_once_with(share_nfs['id'],
                                                             share_nfs['size'])
        ssh.HNASSSHBackend.tree_clone.assert_called_once_with(
            '/snapshots/' + share_nfs['id'] + '/' + snapshot_nfs['id'],
            '/shares/' + share_nfs['id'])
        ssh.HNASSSHBackend.nfs_export_add.assert_called_once_with(
            share_nfs['id'])
Ejemplo n.º 2
0
    def test_create_snapshot_first_snapshot(self):
        self.mock_object(hds_hnas.HDSHNASDriver, "_get_hnas_share_id",
                         mock.Mock(return_value=share['id']))
        self.mock_object(ssh.HNASSSHBackend, "get_host_list", mock.Mock(
            return_value=['172.24.44.200(rw)']))
        self.mock_object(ssh.HNASSSHBackend, "update_access_rule", mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "tree_clone", mock.Mock(
            side_effect=exception.HNASNothingToCloneException('msg')))
        self.mock_object(ssh.HNASSSHBackend, "create_directory", mock.Mock())

        self._driver.create_snapshot('context', snapshot)

        self.assertTrue(self.mock_log.warning.called)
        ssh.HNASSSHBackend.get_host_list.assert_called_once_with(share['id'])
        ssh.HNASSSHBackend.update_access_rule.assert_any_call(
            share['id'], ['172.24.44.200(ro)'])
        ssh.HNASSSHBackend.update_access_rule.assert_any_call(
            share['id'], ['172.24.44.200(rw)'])
        ssh.HNASSSHBackend.create_directory.assert_called_once_with(
            '/snapshots/' + share['id'] + '/' + snapshot['id'])
Ejemplo n.º 3
0
    def test_create_share_from_snapshot_empty_snapshot(self):
        self.mock_object(hds_hnas.HDSHNASDriver, "_check_fs_mounted",
                         mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "vvol_create", mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "quota_add", mock.Mock())
        self.mock_object(ssh.HNASSSHBackend, "tree_clone", mock.Mock(
            side_effect=exception.HNASNothingToCloneException('msg')))
        self.mock_object(ssh.HNASSSHBackend, "nfs_export_add", mock.Mock())

        result = self._driver.create_share_from_snapshot('context', share,
                                                         snapshot)

        self.assertEqual('172.24.44.10:/shares/' + share['id'], result)
        self.assertTrue(self.mock_log.warning.called)
        ssh.HNASSSHBackend.vvol_create.assert_called_once_with(share['id'])
        ssh.HNASSSHBackend.quota_add.assert_called_once_with(share['id'],
                                                             share['size'])
        ssh.HNASSSHBackend.tree_clone.assert_called_once_with(
            '/snapshots/' + snapshot['share_id'] + '/' + snapshot['id'],
            '/shares/' + share['id'])
        ssh.HNASSSHBackend.nfs_export_add.assert_called_once_with(share['id'])
Ejemplo n.º 4
0
    def tree_clone(self, src_path, dest_path):
        command = [
            'tree-clone-job-submit', '-e', '-f', self.fs_name, src_path,
            dest_path
        ]
        try:
            output, err = self._execute(command)
        except processutils.ProcessExecutionError as e:
            if ('Cannot find any clonable files in the source directory'
                    in e.stderr):
                msg = _("Source path %s is empty.") % src_path
                LOG.debug(msg)
                raise exception.HNASNothingToCloneException(msg=msg)
            else:
                msg = _("Could not submit tree clone job to clone from %(src)s"
                        " to %(dest)s.") % {
                            'src': src_path,
                            'dest': dest_path
                        }
                LOG.exception(msg)
                raise exception.HNASBackendException(msg=msg)

        job_submit = JobSubmit(output)
        if job_submit.request_status == 'Request submitted successfully':
            job_id = job_submit.job_id

            job_status = None
            progress = ''
            job_rechecks = 0
            starttime = time.time()
            deadline = starttime + self.job_timeout
            while (not job_status
                   or job_status.job_state != "Job was completed"):

                command = ['tree-clone-job-status', job_id]
                output, err = self._execute(command)
                job_status = JobStatus(output)

                if job_status.job_state == 'Job failed':
                    break

                old_progress = progress
                progress = job_status.data_bytes_processed

                if old_progress == progress:
                    job_rechecks += 1
                    now = time.time()
                    if now > deadline:
                        command = ['tree-clone-job-abort', job_id]
                        self._execute(command)
                        LOG.error("Timeout in snapshot creation from "
                                  "source path %s." % src_path)
                        msg = _("Share snapshot of source path %s "
                                "was not created.") % src_path
                        raise exception.HNASBackendException(msg=msg)
                    else:
                        time.sleep(job_rechecks**2)
                else:
                    job_rechecks = 0

            if (job_status.job_state, job_status.job_status,
                    job_status.directories_missing,
                    job_status.files_missing) == ("Job was completed",
                                                  "Success", '0', '0'):

                LOG.debug(
                    "Snapshot of source path %(src)s to destination "
                    "path %(dest)s created successfully.", {
                        'src': src_path,
                        'dest': dest_path
                    })
            else:
                LOG.error('Error creating snapshot of source path %s.',
                          src_path)
                msg = _('Snapshot of source path %s was not '
                        'created.') % src_path
                raise exception.HNASBackendException(msg=msg)