Example #1
0
    def update_share_usage_size(self, context, shares):
        updated_shares = []
        out, err = self._execute('df', '-l', '--output=target,used',
                                 '--block-size=g')
        gathered_at = timeutils.utcnow()

        for share in shares:
            try:
                mount_path = self._get_mount_path(share)
                if os.path.exists(mount_path):
                    used_size = (re.findall(mount_path + "\s*[0-9.]+G",
                                            out)[0].split(' ')[-1][:-1])
                    updated_shares.append({
                        'id': share['id'],
                        'used_size': used_size,
                        'gathered_at': gathered_at
                    })
                else:
                    raise exception.NotFound(
                        _("Share mount path %s could not be "
                          "found.") % mount_path)
            except Exception:
                LOG.exception("Failed to gather 'used_size' for share %s.",
                              share['id'])

        return updated_shares
Example #2
0
    def test_share_server_migration_start_new_share_network_not_found(self):
        server = db_utils.create_share_server(
            id='fake_server_id', status=constants.STATUS_ACTIVE)
        req = self._get_server_migration_request(server['id'])
        context = req.environ['manila.context']

        body = {
            'migration_start': {
                'host': 'fake_host',
                'preserve_metadata': True,
                'preserve_snapshots': True,
                'writable': True,
                'nondisruptive': True,
                'new_share_network_id': 'nonexistent'}}

        self.mock_object(db_api, 'share_network_get',
                         mock.Mock(side_effect=exception.NotFound()))
        self.mock_object(db_api, 'share_server_get',
                         mock.Mock(return_value=server))

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.share_server_migration_start,
                          req, server['id'], body)
        db_api.share_network_get.assert_called_once_with(context,
                                                         'nonexistent')
        db_api.share_server_get.assert_called_once_with(context,
                                                        server['id'])
Example #3
0
    def create(self, context, size, name, description, snapshot=None,
               image_id=None, volume_type=None, metadata=None,
               availability_zone=None):

        if snapshot is not None:
            snapshot_id = snapshot['id']
        else:
            snapshot_id = None

        kwargs = dict(snapshot_id=snapshot_id,
                      display_name=name,
                      display_description=description,
                      volume_type=volume_type,
                      user_id=context.user_id,
                      project_id=context.project_id,
                      availability_zone=availability_zone,
                      metadata=metadata,
                      imageRef=image_id)

        try:
            item = cinderclient(context).volumes.create(size, **kwargs)
            return _untranslate_volume_summary_view(context, item)
        except cinder_exception.BadRequest as e:
            raise exception.InvalidInput(reason=e.message)
        except cinder_exception.NotFound:
            raise exception.NotFound(
                _("Error in creating cinder "
                  "volume. Cinder volume type %s not exist. Check parameter "
                  "cinder_volume_type in configuration file.") % volume_type)
        except Exception as e:
            raise exception.ManilaException(e.message)
Example #4
0
    def test_deny_migration_access_not_found(self):

        access = {'access_to': 'fake_ip', 'access_type': 'fake_type'}

        access_active = db_utils.create_access(share_id=self.share['id'],
                                               access_to='fake_ip')

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(side_effect=exception.NotFound('fake')))

        self.helper.deny_migration_access(access_active, access)
Example #5
0
    def _find_performance_counter_timestamp(self,
                                            counters,
                                            counter_name,
                                            instance_name=None):
        """Given a counter set, return the timestamp of a named instance."""

        for counter in counters:
            if counter_name in counter:
                if (instance_name is None
                        or counter['instance-name'] == instance_name):
                    return counter['timestamp']
        else:
            raise exception.NotFound(_('Counter %s not found') % counter_name)
Example #6
0
    def _deny_access(self, req, id, body):
        """Remove access rule."""
        context = req.environ['manila.context']

        access_id = body['os-deny_access']['access_id']

        try:
            access = self.share_api.access_get(context, access_id)
            if access.share_id != id:
                raise exception.NotFound()
            share = self.share_api.get(context, id)
        except exception.NotFound as error:
            raise webob.exc.HTTPNotFound(explanation=six.text_type(error))
        self.share_api.deny_access(context, share, access)
        return webob.Response(status_int=202)
Example #7
0
    def test_deny_migration_access_exception(self):

        access = {'access_to': 'fake_ip', 'access_type': 'fake_type'}

        access_active = db_utils.create_access(share_id=self.share['id'],
                                               access_to='fake_ip')

        self.mock_object(self.helper.api, 'access_get',
                         mock.Mock(return_value=access_active))

        self.mock_object(self.helper.api, 'deny_access',
                         mock.Mock(side_effect=[exception.NotFound('fake')]))

        self.assertRaises(exception.NotFound,
                          self.helper.deny_migration_access, access_active,
                          access)
Example #8
0
    def _get_ems_log_destination_vserver(self):
        """Returns the best vserver destination for EMS messages."""
        major, minor = self.get_ontapi_version(cached=True)

        if (major > 1) or (major == 1 and minor > 15):
            # Prefer admin Vserver (requires cluster credentials).
            admin_vservers = self.list_vservers(vserver_type='admin')
            if admin_vservers:
                return admin_vservers[0]

            # Fall back to data Vserver.
            data_vservers = self.list_vservers(vserver_type='data')
            if data_vservers:
                return data_vservers[0]

        # If older API version, or no other Vservers found, use node Vserver.
        node_vservers = self.list_vservers(vserver_type='node')
        if node_vservers:
            return node_vservers[0]

        raise exception.NotFound("No Vserver found to receive EMS messages.")
Example #9
0
    def _deny_access(self, req, id, body):
        """Remove share access rule."""
        context = req.environ['manila.context']

        access_id = body.get('deny_access',
                             body.get('os-deny_access'))['access_id']

        share = self.share_api.get(context, id)
        share_network_id = share.get('share_network_id', None)

        if share_network_id:
            share_network = db.share_network_get(context, share_network_id)
            common.check_share_network_is_active(share_network)

        try:
            access = self.share_api.access_get(context, access_id)
            if access.share_id != id:
                raise exception.NotFound()
            share = self.share_api.get(context, id)
        except exception.NotFound as error:
            raise webob.exc.HTTPNotFound(explanation=six.text_type(error))
        self.share_api.deny_access(context, share, access)
        return webob.Response(status_int=http_client.ACCEPTED)
Example #10
0
    def test_delete_instance_and_wait(self):

        # mocks
        self.mock_object(share_api.API, 'delete_instance')
        self.mock_object(
            db, 'share_instance_get',
            mock.Mock(side_effect=[self.share_instance,
                                   exception.NotFound()]))
        self.mock_object(time, 'sleep')

        # run
        self.helper.delete_instance_and_wait(self.share_instance)

        # asserts
        share_api.API.delete_instance.assert_called_once_with(
            self.context, self.share_instance, True)

        db.share_instance_get.assert_has_calls([
            mock.call(self.context, self.share_instance['id']),
            mock.call(self.context, self.share_instance['id'])
        ])

        time.sleep.assert_called_once_with(1)
Example #11
0
def fake_service_get_by_args(*args, **kwargs):
    raise exception.NotFound()
Example #12
0
 def _check_dir_exists(self, path):
     if not os.path.exists(path):
         raise exception.NotFound("Folder %s could not be found." % path)
Example #13
0
 def _fake_deny_access(self, *args, **kwargs):
     raise exception.NotFound()
Example #14
0
 def _fake_create_delete_snapshot(self, *args, **kwargs):
     raise exception.NotFound()
Example #15
0
 def _raise_not_found(self, *args, **kwargs):
     raise exception.NotFound()
Example #16
0
def return_share_nonexistent(context, share_id):
    raise exception.NotFound('bogus test message')
Example #17
0
 def test_not_found(self):
     # Verify response code for exception.NotFound
     e = exception.NotFound()
     self.assertEqual(404, e.code)
Example #18
0
 def _fake_delete_share(self, *args, **kwargs):
     raise exception.NotFound()