Example #1
0
    def test_create_cgroup_from_snapshot(self):
        cgroup = self.cinder_consistencygroups.first()
        cg_snapshot = self.cinder_cg_snapshots.first()
        formData = {
            'cg_snapshot_id': cg_snapshot.id,
            'name': 'test CG SS Create',
            'description': 'test desc'
        }

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndReturn(cg_snapshot)
        cinder.volume_cgroup_create_from_source(
            IsA(http.HttpRequest),
            formData['name'],
            source_cgroup_id=formData['cg_snapshot_id'],
            description=formData['description'])\
            .AndReturn(cgroup)
        self.mox.ReplayAll()

        url = reverse(
            'horizon:compute_user:volume2:cg_snapshots:create_cgroup',
            args=[cg_snapshot.id])
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
Example #2
0
    def test_create_cgroup_from_snapshot_exception(self):
        cg_snapshot = self.cinder_cg_snapshots.first()
        new_cg_name = 'test CG SS Create'
        formData = {'cg_snapshot_id': cg_snapshot.id,
                    'name': new_cg_name,
                    'description': 'test desc'}

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndReturn(cg_snapshot)
        cinder.volume_cgroup_create_from_source(
            IsA(http.HttpRequest),
            formData['name'],
            source_cgroup_id=formData['cg_snapshot_id'],
            description=formData['description'])\
            .AndRaise(self.exceptions.cinder)
        self.mox.ReplayAll()

        url = reverse('horizon:project:cg_snapshots:create_cgroup',
                      args=[cg_snapshot.id])
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        # There are a bunch of backslashes for formatting in the message from
        # the response, so remove them when validating the error message.
        self.assertIn('Unable to create consistency group "%s" from snapshot.'
                      % new_cg_name,
                      res.cookies.output().replace('\\', ''))
        self.assertRedirectsNoFollow(res, INDEX_URL)
Example #3
0
    def test_create_cgroup_from_snapshot_exception(self):
        cg_snapshot = self.cinder_cg_snapshots.first()
        new_cg_name = 'test CG SS Create'
        formData = {'cg_snapshot_id': cg_snapshot.id,
                    'name': new_cg_name,
                    'description': 'test desc'}

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndReturn(cg_snapshot)
        cinder.volume_cgroup_create_from_source(
            IsA(http.HttpRequest),
            formData['name'],
            source_cgroup_id=formData['cg_snapshot_id'],
            description=formData['description'])\
            .AndRaise(self.exceptions.cinder)
        self.mox.ReplayAll()

        url = reverse('horizon:project:cg_snapshots:create_cgroup',
                      args=[cg_snapshot.id])
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        # There are a bunch of backslashes for formatting in the message from
        # the response, so remove them when validating the error message.
        self.assertIn('Unable to create consistency group "%s" from snapshot.'
                      % new_cg_name,
                      res.cookies.output().replace('\\', ''))
        self.assertRedirectsNoFollow(res, INDEX_URL)
Example #4
0
    def test_detail_view_with_exception(self):
        cg_snapshot = self.cinder_cg_snapshots.first()

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndRaise(self.exceptions.cinder)

        self.mox.ReplayAll()

        url = reverse(
            'horizon:project:cg_snapshots:cg_snapshot_detail',
            args=[cg_snapshot.id])
        res = self.client.get(url)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Example #5
0
    def test_detail_view_with_exception(self):
        cg_snapshot = self.cinder_cg_snapshots.first()

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndRaise(self.exceptions.cinder)

        self.mox.ReplayAll()

        url = reverse(
            'horizon:project:cg_snapshots:cg_snapshot_detail',
            args=[cg_snapshot.id])
        res = self.client.get(url)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Example #6
0
    def get_context_data(self, **kwargs):
        context = super(CreateCGroupView, self).get_context_data(**kwargs)
        context['cg_snapshot_id'] = self.kwargs['cg_snapshot_id']
        args = (self.kwargs['cg_snapshot_id'],)
        context['submit_url'] = reverse(self.submit_url, args=args)
        try:
            # get number of volumes we will be creating
            cg_snapshot = cinder.volume_cg_snapshot_get(
                self.request, context['cg_snapshot_id'])

            cgroup_id = cg_snapshot.consistencygroup_id

            search_opts = {'consistencygroup_id': cgroup_id}
            volumes = api.cinder.volume_list(self.request,
                                             search_opts=search_opts)
            num_volumes = len(volumes)
            usages = quotas.tenant_limit_usages(self.request)

            if usages['volumesUsed'] + num_volumes > \
                    usages['maxTotalVolumes']:
                raise ValueError(_('Unable to create consistency group due to '
                                   'exceeding volume quota limit.'))
            else:
                usages['numRequestedItems'] = num_volumes
                context['usages'] = usages

        except ValueError as e:
            exceptions.handle(self.request, e.message)
            return None
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve consistency '
                                'group information.'))
        return context
Example #7
0
    def get_context_data(self, **kwargs):
        context = super(CreateCGroupView, self).get_context_data(**kwargs)
        context['cg_snapshot_id'] = self.kwargs['cg_snapshot_id']
        args = (self.kwargs['cg_snapshot_id'],)
        context['submit_url'] = reverse(self.submit_url, args=args)
        try:
            # get number of volumes we will be creating
            cg_snapshot = cinder.volume_cg_snapshot_get(
                self.request, context['cg_snapshot_id'])

            cgroup_id = cg_snapshot.consistencygroup_id

            search_opts = {'consistencygroup_id': cgroup_id}
            volumes = api.cinder.volume_list(self.request,
                                             search_opts=search_opts)
            num_volumes = len(volumes)
            usages = quotas.tenant_quota_usages(
                self.request, targets=('volumes', 'gigabytes'))
            if (usages['volumes']['used'] + num_volumes >
                    usages['volumes']['quota']):
                raise ValueError(_('Unable to create consistency group due to '
                                   'exceeding volume quota limit.'))
            else:
                context['numRequestedItems'] = num_volumes
                context['usages'] = usages

        except ValueError as e:
            exceptions.handle(self.request, e.message)
            return None
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve consistency '
                                'group information.'))
        return context
Example #8
0
 def prepare_snapshot_source_field(self, request, cg_snapshot_id):
     try:
         cg_snapshot = cinder.volume_cg_snapshot_get(request,
                                                     cg_snapshot_id)
         self.fields['snapshot_source'].choices = ((cg_snapshot_id,
                                                    cg_snapshot),)
     except Exception:
         exceptions.handle(request,
                           _('Unable to load the specified snapshot.'))
Example #9
0
 def prepare_snapshot_source_field(self, request, cg_snapshot_id):
     try:
         cg_snapshot = cinder.volume_cg_snapshot_get(request,
                                                     cg_snapshot_id)
         self.fields['snapshot_source'].choices = ((cg_snapshot_id,
                                                    cg_snapshot),)
     except Exception:
         exceptions.handle(request,
                           _('Unable to load the specified snapshot.'))
Example #10
0
    def test_create_cgroup_from_snapshot(self):
        cgroup = self.cinder_consistencygroups.first()
        cg_snapshot = self.cinder_cg_snapshots.first()
        formData = {'cg_snapshot_id': cg_snapshot.id,
                    'name': 'test CG SS Create',
                    'description': 'test desc'}

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndReturn(cg_snapshot)
        cinder.volume_cgroup_create_from_source(
            IsA(http.HttpRequest),
            formData['name'],
            source_cgroup_id=formData['cg_snapshot_id'],
            description=formData['description'])\
            .AndReturn(cgroup)
        self.mox.ReplayAll()

        url = reverse('horizon:project:cg_snapshots:create_cgroup',
                      args=[cg_snapshot.id])
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Example #11
0
    def test_detail_view(self):
        cg_snapshot = self.cinder_cg_snapshots.first()
        cgroup = self.cinder_consistencygroups.first()
        volume_type = self.cinder_volume_types.first()
        volumes = self.cinder_volumes.list()

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndReturn(cg_snapshot)
        cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
            AndReturn(cgroup)
        cinder.volume_type_get(IsA(http.HttpRequest), volume_type.id).\
            MultipleTimes().AndReturn(volume_type)
        search_opts = {'consistencygroup_id': cgroup.id}
        cinder.volume_list(IsA(http.HttpRequest), search_opts=search_opts).\
            AndReturn(volumes)

        self.mox.ReplayAll()

        url = reverse(
            'horizon:project:cg_snapshots:cg_snapshot_detail',
            args=[cg_snapshot.id])
        res = self.client.get(url)
        self.assertNoFormErrors(res)
        self.assertEqual(res.status_code, 200)
Example #12
0
    def test_detail_view(self):
        cg_snapshot = self.cinder_cg_snapshots.first()
        cgroup = self.cinder_consistencygroups.first()
        volume_type = self.cinder_volume_types.first()
        volumes = self.cinder_volumes.list()

        cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
            AndReturn(cg_snapshot)
        cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
            AndReturn(cgroup)
        cinder.volume_type_get(IsA(http.HttpRequest), volume_type.id).\
            MultipleTimes().AndReturn(volume_type)
        search_opts = {'consistencygroup_id': cgroup.id}
        cinder.volume_list(IsA(http.HttpRequest), search_opts=search_opts).\
            AndReturn(volumes)

        self.mox.ReplayAll()

        url = reverse(
            'horizon:project:cg_snapshots:cg_snapshot_detail',
            args=[cg_snapshot.id])
        res = self.client.get(url)
        self.assertNoFormErrors(res)
        self.assertEqual(res.status_code, 200)
Example #13
0
 def get_data(self, request, cg_snapshot_id):
     cg_snapshot = cinder.volume_cg_snapshot_get(request, cg_snapshot_id)
     return cg_snapshot
Example #14
0
 def get_data(self, request, cg_snapshot_id):
     cg_snapshot = cinder.volume_cg_snapshot_get(request, cg_snapshot_id)
     return cg_snapshot