Ejemplo n.º 1
0
    def test_create_cgroup_exception(self):
        volume_types = self.volume_types.list()
        az = self.cinder_availability_zones.first().zoneName
        formData = {
            'volume_types': '1',
            'name': 'test CG',
            'description': 'test desc',
            'availability_zone': az
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.volume_cgroup_list(IsA(
            http.HttpRequest)).\
            AndReturn(self.cinder_consistencygroups.list())
        cinder.volume_cgroup_create(
            IsA(http.HttpRequest),
            formData['volume_types'],
            formData['name'],
            formData['description'],
            availability_zone=formData['availability_zone'])\
            .AndRaise(self.exceptions.cinder)
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:cgroups:create')
        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
Ejemplo n.º 2
0
    def test_create_cgroup_exception(self):
        volume_types = self.cinder_volume_types.list()
        volume_type_id = self.cinder_volume_types.first().id
        az = self.cinder_availability_zones.first().zoneName
        formData = {'volume_types': '1',
                    'name': 'test CG',
                    'description': 'test desc',
                    'availability_zone': az,
                    'add_vtypes_to_cgroup_role_member': [volume_type_id]}

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(volume_types)
        cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.volume_cgroup_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_consistencygroups.list())
        cinder.volume_cgroup_create(
            IsA(http.HttpRequest),
            formData['volume_types'],
            formData['name'],
            formData['description'],
            availability_zone=formData['availability_zone'])\
            .AndRaise(self.exceptions.cinder)
        self.mox.ReplayAll()

        url = reverse('horizon:project:cgroups:create')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
        self.assertIn("Unable to create consistency group.",
                      res.cookies.output())
Ejemplo n.º 3
0
    def test_create_cgroup_exception(self):
        volume_types = self.cinder_volume_types.list()
        az = self.cinder_availability_zones.first().zoneName
        formData = {'volume_types': '1',
                    'name': 'test CG',
                    'description': 'test desc',
                    'availability_zone': az}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.volume_cgroup_list(IsA(
            http.HttpRequest)).\
            AndReturn(self.cinder_consistencygroups.list())
        cinder.volume_cgroup_create(
            IsA(http.HttpRequest),
            formData['volume_types'],
            formData['name'],
            formData['description'],
            availability_zone=formData['availability_zone'])\
            .AndRaise(self.exceptions.cinder)
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:cgroups:create')
        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
Ejemplo n.º 4
0
    def test_create_cgroup_exception(self):
        volume_types = self.cinder_volume_types.list()
        volume_type_id = self.cinder_volume_types.first().id
        az = self.cinder_availability_zones.first().zoneName
        formData = {'volume_types': '1',
                    'name': 'test CG',
                    'description': 'test desc',
                    'availability_zone': az,
                    'add_vtypes_to_cgroup_role_member': [volume_type_id]}

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(volume_types)
        cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.volume_cgroup_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_consistencygroups.list())
        cinder.volume_cgroup_create(
            IsA(http.HttpRequest),
            formData['volume_types'],
            formData['name'],
            formData['description'],
            availability_zone=formData['availability_zone'])\
            .AndRaise(self.exceptions.cinder)
        self.mox.ReplayAll()

        url = reverse('horizon:project:cgroups:create')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
        self.assertIn("Unable to create consistency group.",
                      res.cookies.output())
Ejemplo n.º 5
0
    def test_create_cgroup(self):
        cgroup = self.cinder_consistencygroups.first()
        volume_types = self.cinder_volume_types.list()
        az = self.cinder_availability_zones.first().zoneName
        formData = {'volume_types': '1',
                    'name': 'test CG',
                    'description': 'test desc',
                    'availability_zone': az}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.volume_cgroup_list(IsA(
            http.HttpRequest)).\
            AndReturn(self.cinder_consistencygroups.list())
        cinder.volume_cgroup_create(
            IsA(http.HttpRequest),
            formData['volume_types'],
            formData['name'],
            formData['description'],
            availability_zone=formData['availability_zone'])\
            .AndReturn(cgroup)
        self.mox.ReplayAll()

        url = reverse('horizon:virtual:volumes:cgroups:create')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
Ejemplo n.º 6
0
    def test_create_cgroup(self):
        cgroup = self.cinder_consistencygroups.first()
        volume_types = self.cinder_volume_types.list()
        az = self.cinder_availability_zones.first().zoneName
        formData = {
            'volume_types': '1',
            'name': 'test CG',
            'description': 'test desc',
            'availability_zone': az
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
            AndReturn(volume_types)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.volume_cgroup_list(IsA(
            http.HttpRequest)).\
            AndReturn(self.cinder_consistencygroups.list())
        cinder.volume_cgroup_create(
            IsA(http.HttpRequest),
            formData['volume_types'],
            formData['name'],
            formData['description'],
            availability_zone=formData['availability_zone'])\
            .AndReturn(cgroup)
        self.mox.ReplayAll()

        url = reverse('horizon:virtual:volumes:cgroups:create')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
Ejemplo n.º 7
0
    def handle(self, request, context):
        selected_vol_types = context['volume_types']

        try:
            vol_types = cinder.volume_type_list_with_qos_associations(
                request)
        except Exception:
            msg = _('Unable to get volume type list')
            exceptions.check_message(["Connection", "refused"], msg)
            return False

        # ensure that all selected volume types share same backend name
        backend_name = None
        invalid_backend = False
        for selected_vol_type in selected_vol_types:
            if invalid_backend:
                continue
            for vol_type in vol_types:
                if selected_vol_type != vol_type.id:
                    continue
                if (hasattr(vol_type, "extra_specs") and
                        'volume_backend_name' in vol_type.extra_specs):
                    vol_type_backend = \
                        vol_type.extra_specs['volume_backend_name']
                    if vol_type_backend is None:
                        invalid_backend = True
                        break
                    if backend_name is None:
                        backend_name = vol_type_backend
                    if vol_type_backend != backend_name:
                        invalid_backend = True
                        break
                else:
                    invalid_backend = True
                    break

        if invalid_backend:
            msg = _('All selected volume types must be associated '
                    'with the same volume backend name.')
            exceptions.handle(request, msg)
            return False

        try:
            vtypes_str = ",".join(context['volume_types'])
            self.object = \
                cinder.volume_cgroup_create(
                    request,
                    vtypes_str,
                    context['name'],
                    description=context['description'],
                    availability_zone=context['availability_zone'])
        except Exception:
            exceptions.handle(request, _('Unable to create consistency '
                                         'group.'))
            return False

        return True