Example #1
0
    def test_volume_types_tab(self):
        encryption_list = (self.cinder_volume_encryption_types.list()[0],
                           self.cinder_volume_encryption_types.list()[1])
        cinder.volume_type_list_with_qos_associations(
            IsA(http.HttpRequest)).\
            AndReturn(self.volume_types.list())
        cinder.qos_spec_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_qos_specs.list())
        cinder.volume_encryption_type_list(IsA(http.HttpRequest))\
            .AndReturn(encryption_list)
        cinder.extension_supported(IsA(http.HttpRequest),
                                   'VolumeTypeEncryption').MultipleTimes()\
            .AndReturn(True)

        self.mox.ReplayAll()
        res = self.client.get(reverse(
            'horizon:admin:volumes:volume_types_tab'))

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(
            res, 'admin/volumes/volume_types/volume_types_tables.html')
        volume_types = res.context['volume_types_table'].data
        self.assertItemsEqual(volume_types, self.volume_types.list())
        qos_specs = res.context['qos_specs_table'].data
        self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
Example #2
0
 def test_manage_volume(self):
     metadata = {"key": u"k1", "value": u"v1"}
     formData = {
         "host": "host-1",
         "identifier": "vol-1",
         "id_type": u"source-name",
         "name": "name-1",
         "description": "manage a volume",
         "volume_type": "vol_type_1",
         "availability_zone": "nova",
         "metadata": metadata["key"] + "=" + metadata["value"],
         "bootable": False,
     }
     cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volume_types.list())
     cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(self.availability_zones.list())
     cinder.extension_supported(IsA(http.HttpRequest), "AvailabilityZones").AndReturn(True)
     cinder.volume_manage(
         IsA(http.HttpRequest),
         host=formData["host"],
         identifier=formData["identifier"],
         id_type=formData["id_type"],
         name=formData["name"],
         description=formData["description"],
         volume_type=formData["volume_type"],
         availability_zone=formData["availability_zone"],
         metadata={metadata["key"]: metadata["value"]},
         bootable=formData["bootable"],
     )
     self.mox.ReplayAll()
     res = self.client.post(reverse("horizon:admin:volumes:volumes:manage"), formData)
     self.assertNoFormErrors(res)
Example #3
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())
Example #4
0
    def test_delete_volume_type_encryption(self):
        volume_type = self.volume_types.first()
        volume_type.id = u'1'
        formData = {'action': 'volume_types__delete_encryption__%s' %
                    volume_type.id}
        encryption_list = (self.cinder_volume_encryption_types.list()[0],
                           self.cinder_volume_encryption_types.list()[1])

        cinder.extension_supported(IsA(http.HttpRequest),
                                   'VolumeTypeEncryption')\
            .AndReturn(True)
        cinder.volume_type_list_with_qos_associations(
            IsA(http.HttpRequest))\
            .AndReturn(self.volume_types.list())
        cinder.qos_spec_list(IsA(http.HttpRequest))\
            .AndReturn(self.cinder_qos_specs.list())
        cinder.volume_encryption_type_list(IsA(http.HttpRequest))\
            .AndReturn(encryption_list)
        cinder.volume_encryption_type_delete(IsA(http.HttpRequest),
                                             volume_type.id)
        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:admin:volumes:volume_types_tab'),
            formData)

        redirect = reverse('horizon:admin:volumes:volume_types_tab')
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, redirect)
Example #5
0
    def test_delete_volume_type_encryption(self):
        volume_type = self.cinder_volume_types.first()
        volume_type.id = u'1'
        formData = {
            'action': 'volume_types__delete_encryption__%s' % volume_type.id
        }
        encryption_list = (self.cinder_volume_encryption_types.list()[0],
                           self.cinder_volume_encryption_types.list()[1])

        cinder.extension_supported(IsA(http.HttpRequest),
                                   'VolumeTypeEncryption')\
            .AndReturn(True)
        cinder.volume_type_list_with_qos_associations(
            IsA(http.HttpRequest))\
            .AndReturn(self.cinder_volume_types.list())
        cinder.qos_spec_list(IsA(http.HttpRequest))\
            .AndReturn(self.cinder_qos_specs.list())
        cinder.volume_encryption_type_list(IsA(http.HttpRequest))\
            .AndReturn(encryption_list)
        cinder.volume_encryption_type_delete(IsA(http.HttpRequest),
                                             volume_type.id)
        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:admin:volumes:volume_types_tab'), formData)

        redirect = reverse('horizon:admin:volumes:volume_types_tab')
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, redirect)
    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)
Example #7
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())
Example #8
0
    def test_create_volume_from_image_dropdown(self):
        volume = self.volumes.first()
        usage_limit = {
            'maxTotalVolumeGigabytes': 200,
            'gigabytesUsed': 20,
            'volumesUsed': len(self.volumes.list()),
            'maxTotalVolumes': 6
        }
        image = self.images.first()
        formData = {
            'name': u'A Volume I Am Making',
            'description': u'This is a volume I am making for a test.',
            'method': u'CreateForm',
            'size': 30,
            'type': '',
            'volume_source_type': 'image_source',
            'snapshot_source': self.volume_snapshots.first().id,
            'image_source': image.id
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
                                 AndReturn(self.volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        quotas.tenant_limit_usages(IsA(http.HttpRequest)) \
                  .AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        cinder.volume_create(IsA(http.HttpRequest),
                             formData['size'],
                             formData['name'],
                             formData['description'],
                             '',
                             metadata={},
                             snapshot_id=None,
                             image_id=image.id,
                             availability_zone=None).AndReturn(volume)

        self.mox.ReplayAll()

        # get image from dropdown list
        url = reverse('horizon:project:volumes:create')
        res = self.client.post(url, formData)

        redirect_url = reverse('horizon:project:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)
Example #9
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)
Example #10
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)
Example #11
0
    def test_create_volume_from_image_under_image_min_disk_size(self):
        usage_limit = {'maxTotalVolumeGigabytes': 100,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.cinder_volumes.list()),
                       'maxTotalVolumes': 6}
        image = self.images.get(name="protected_images")
        image.min_disk = 30
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 5, 'image_source': image.id}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:volumes:create')
        res = self.client.post("?".join([url,
                                         "image_id=" + str(image.id)]),
                               formData, follow=True)
        self.assertEqual(res.redirect_chain, [])
        self.assertFormError(res, 'form', None,
                             "The volume size cannot be less than the "
                             "image minimum disk size (30GB)")
Example #12
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)
Example #13
0
    def test_create_volume_number_over_alloted_quota(self):
        usage_limit = {
            "maxTotalVolumeGigabytes": 100,
            "gigabytesUsed": 20,
            "volumesUsed": len(self.cinder_volumes.list()),
            "maxTotalVolumes": len(self.cinder_volumes.list()),
        }
        formData = {
            "name": u"Too Many...",
            "description": u"We have no volumes left!",
            "method": u"CreateForm",
            "size": 10,
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(
            IsA(http.HttpRequest), filters={"is_public": True, "status": "active"}
        ).AndReturn([self.images.list(), False, False])
        api.glance.image_list_detailed(
            IsA(http.HttpRequest), filters={"property-owner_id": self.tenant.id, "status": "active"}
        ).AndReturn([[], False, False])
        cinder.volume_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volumes.list())
        cinder.extension_supported(IsA(http.HttpRequest), "AvailabilityZones").AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)

        self.mox.ReplayAll()

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

        expected_error = [u"You are already using all of your available" " volumes."]
        self.assertEqual(res.context["form"].errors["__all__"], expected_error)
Example #14
0
    def test_create_volume_gb_used_over_alloted_quota(self):
        usage_limit = {
            "maxTotalVolumeGigabytes": 100,
            "gigabytesUsed": 80,
            "volumesUsed": len(self.cinder_volumes.list()),
            "maxTotalVolumes": 6,
        }
        formData = {
            "name": u"This Volume Is Huge!",
            "description": u"This is a volume that is just too big!",
            "method": u"CreateForm",
            "size": 5000,
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(
            IsA(http.HttpRequest), filters={"is_public": True, "status": "active"}
        ).AndReturn([self.images.list(), False, False])
        api.glance.image_list_detailed(
            IsA(http.HttpRequest), filters={"property-owner_id": self.tenant.id, "status": "active"}
        ).AndReturn([[], False, False])
        cinder.volume_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volumes.list())
        cinder.extension_supported(IsA(http.HttpRequest), "AvailabilityZones").AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)

        self.mox.ReplayAll()

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

        expected_error = [u"A volume of 5000GB cannot be created as you only" " have 20GB of your quota available."]
        self.assertEqual(res.context["form"].errors["__all__"], expected_error)
Example #15
0
    def test_volume_types_tab(self):
        encryption_list = (self.cinder_volume_encryption_types.list()[0],
                           self.cinder_volume_encryption_types.list()[1])
        cinder.volume_type_list_with_qos_associations(
            IsA(http.HttpRequest)).\
            AndReturn(self.cinder_volume_types.list())
        cinder.qos_spec_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_qos_specs.list())
        cinder.volume_encryption_type_list(IsA(http.HttpRequest))\
            .AndReturn(encryption_list)
        cinder.extension_supported(IsA(http.HttpRequest),
                                   'VolumeTypeEncryption').MultipleTimes()\
            .AndReturn(True)

        self.mox.ReplayAll()
        res = self.client.get(
            reverse('horizon:admin:volumes:volume_types_tab'))

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(
            res, 'admin/volumes/volume_types/volume_types_tables.html')
        volume_types = res.context['volume_types_table'].data
        self.assertItemsEqual(volume_types, self.cinder_volume_types.list())
        qos_specs = res.context['qos_specs_table'].data
        self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
Example #16
0
    def test_create_volume_from_image_under_image_min_disk_size(self):
        usage_limit = {
            "maxTotalVolumeGigabytes": 100,
            "gigabytesUsed": 20,
            "volumesUsed": len(self.cinder_volumes.list()),
            "maxTotalVolumes": 6,
        }
        image = self.images.get(name="protected_images")
        image.min_disk = 30
        formData = {
            "name": u"A Volume I Am Making",
            "description": u"This is a volume I am making for a test.",
            "method": u"CreateForm",
            "size": 5,
            "image_source": image.id,
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest), str(image.id)).AndReturn(image)
        cinder.extension_supported(IsA(http.HttpRequest), "AvailabilityZones").AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse("horizon:project:volumes:volumes:create")
        res = self.client.post("?".join([url, "image_id=" + str(image.id)]), formData, follow=True)
        self.assertEqual(res.redirect_chain, [])
        self.assertFormError(
            res, "form", None, "The volume size cannot be less than the " "image minimum disk size (30GB)"
        )
Example #17
0
    def test_create_volume_from_image_dropdown(self):
        volume = self.cinder_volumes.first()
        usage_limit = {'maxTotalVolumeGigabytes': 200,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.cinder_volumes.list()),
                       'maxTotalVolumes': 6}
        image = self.images.first()
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 30,
                    'type': '',
                    'volume_source_type': 'image_source',
                    'snapshot_source': self.cinder_volume_snapshots.first().id,
                    'image_source': image.id}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
                                 AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        cinder.volume_list(IsA(
            http.HttpRequest)).AndReturn(self.cinder_volumes.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)) \
                  .AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        cinder.volume_create(IsA(http.HttpRequest),
                             formData['size'],
                             formData['name'],
                             formData['description'],
                             '',
                             metadata={},
                             snapshot_id=None,
                             image_id=image.id,
                             availability_zone=None,
                             source_volid=None).AndReturn(volume)

        self.mox.ReplayAll()

        # get image from dropdown list
        url = reverse('horizon:project:volumes:volumes:create')
        res = self.client.post(url, formData)

        redirect_url = VOLUME_VOLUMES_TAB_URL
        self.assertRedirectsNoFollow(res, redirect_url)
Example #18
0
    def test_create_volume_from_volume(self):
        volume = self.volumes.first()
        usage_limit = {'maxTotalVolumeGigabytes': 250,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.volumes.list()),
                       'maxTotalVolumes': 6}

        formData = {'name': u'A copy of a volume',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 50,
                    'type': '',
                    'volume_source_type': 'volume_source',
                    'volume_source': volume.id}

        cinder.volume_list(IsA(http.HttpRequest)).\
                AndReturn(self.volumes.list())
        cinder.volume_type_list(IsA(http.HttpRequest)).\
                AndReturn(self.volume_types.list())
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
                AndReturn(self.volume_snapshots.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                AndReturn(usage_limit)

        cinder.volume_get(IsA(http.HttpRequest),
                          volume.id).AndReturn(self.volumes.first())
        cinder.extension_supported(IsA(http.HttpRequest),
                                   'AvailabilityZones').AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])

        cinder.volume_create(IsA(http.HttpRequest),
                             formData['size'],
                             formData['name'],
                             formData['description'],
                             '',
                             metadata={},
                             snapshot_id=None,
                             image_id=None,
                             availability_zone=None,
                             source_volid=volume.id).AndReturn(volume)
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:volumes:create')
        redirect_url = reverse('horizon:project:volumes:index')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertMessageCount(info=1)
        self.assertRedirectsNoFollow(res, redirect_url)
Example #19
0
    def test_create_volume(self):
        volume = self.cinder_volumes.first()
        volume_type = self.volume_types.first()
        az = self.cinder_availability_zones.first().zoneName
        usage_limit = {'maxTotalVolumeGigabytes': 250,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.cinder_volumes.list()),
                       'maxTotalVolumes': 6}
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'type': volume_type.name,
                    'size': 50,
                    'snapshot_source': '',
                    'availability_zone': az}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.volume_list(IsA(
            http.HttpRequest)).AndReturn(self.cinder_volumes.list())

        cinder.volume_create(IsA(http.HttpRequest),
                             formData['size'],
                             formData['name'],
                             formData['description'],
                             formData['type'],
                             metadata={},
                             snapshot_id=None,
                             image_id=None,
                             availability_zone=formData['availability_zone'],
                             source_volid=None)\
            .AndReturn(volume)

        self.mox.ReplayAll()

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

        redirect_url = VOLUME_VOLUMES_TAB_URL
        self.assertRedirectsNoFollow(res, redirect_url)
Example #20
0
    def test_create_volume_from_image_dropdown(self):
        volume = self.cinder_volumes.first()
        usage_limit = {
            "maxTotalVolumeGigabytes": 200,
            "gigabytesUsed": 20,
            "volumesUsed": len(self.cinder_volumes.list()),
            "maxTotalVolumes": 6,
        }
        image = self.images.first()
        formData = {
            "name": u"A Volume I Am Making",
            "description": u"This is a volume I am making for a test.",
            "method": u"CreateForm",
            "size": 30,
            "type": "",
            "volume_source_type": "image_source",
            "snapshot_source": self.cinder_volume_snapshots.first().id,
            "image_source": image.id,
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(self.volume_types.list())
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(
            IsA(http.HttpRequest), filters={"is_public": True, "status": "active"}
        ).AndReturn([self.images.list(), False, False])
        api.glance.image_list_detailed(
            IsA(http.HttpRequest), filters={"property-owner_id": self.tenant.id, "status": "active"}
        ).AndReturn([[], False, False])
        cinder.volume_list(IsA(http.HttpRequest)).AndReturn(self.cinder_volumes.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest), str(image.id)).AndReturn(image)

        cinder.extension_supported(IsA(http.HttpRequest), "AvailabilityZones").AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(self.cinder_availability_zones.list())

        cinder.volume_create(
            IsA(http.HttpRequest),
            formData["size"],
            formData["name"],
            formData["description"],
            "",
            metadata={},
            snapshot_id=None,
            image_id=image.id,
            availability_zone=None,
            source_volid=None,
        ).AndReturn(volume)

        self.mox.ReplayAll()

        # get image from dropdown list
        url = reverse("horizon:project:volumes:volumes:create")
        res = self.client.post(url, formData)

        redirect_url = VOLUME_VOLUMES_TAB_URL
        self.assertRedirectsNoFollow(res, redirect_url)
Example #21
0
    def test_create_volume_from_image(self):
        volume = self.volumes.first()
        usage_limit = {
            'maxTotalVolumeGigabytes': 200,
            'gigabytesUsed': 20,
            'volumesUsed': len(self.volumes.list()),
            'maxTotalVolumes': 6
        }
        image = self.images.first()
        formData = {
            'name': u'A Volume I Am Making',
            'description': u'This is a volume I am making for a test.',
            'method': u'CreateForm',
            'size': 40,
            'type': '',
            'image_source': image.id
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        cinder.volume_create(IsA(http.HttpRequest),
                             formData['size'],
                             formData['name'],
                             formData['description'],
                             '',
                             metadata={},
                             snapshot_id=None,
                             image_id=image.id,
                             availability_zone=None,
                             source_volid=None).AndReturn(volume)

        self.mox.ReplayAll()

        # get image from url
        url = reverse('horizon:project:volumes:volumes:create')
        res = self.client.post("?".join([url, "image_id=" + str(image.id)]),
                               formData)

        redirect_url = reverse('horizon:project:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)
Example #22
0
def cinder_az_supported(request):
    try:
        return cinder.extension_supported(request, 'AvailabilityZones')
    except Exception:
        exceptions.handle(request, _('Unable to determine if availability '
                                     'zones extension is supported.'))
        return False
Example #23
0
def cinder_az_supported(request):
    try:
        return cinder.extension_supported(request, 'AvailabilityZones')
    except Exception:
        exceptions.handle(request, _('Unable to determine if availability '
                                     'zones extension is supported.'))
        return False
Example #24
0
    def test_create_volume_gb_used_over_alloted_quota(self):
        usage_limit = {
            'maxTotalVolumeGigabytes': 100,
            'gigabytesUsed': 80,
            'volumesUsed': len(self.volumes.list()),
            'maxTotalVolumes': 6
        }
        formData = {
            'name': u'This Volume Is Huge!',
            'description': u'This is a volume that is just too big!',
            'method': u'CreateForm',
            'size': 5000
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        cinder.volume_list(IsA(http.HttpRequest)).AndReturn(
            self.volumes.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

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

        expected_error = [
            u'A volume of 5000GB cannot be created as you only'
            ' have 20GB of your quota available.'
        ]
        self.assertEqual(res.context['form'].errors['__all__'], expected_error)
Example #25
0
    def test_create_volume_from_image(self):
        volume = self.volumes.first()
        usage_limit = {'maxTotalVolumeGigabytes': 200,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.volumes.list()),
                       'maxTotalVolumes': 6}
        image = self.images.first()
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 40,
                    'type': '',
                    'image_source': image.id}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        cinder.volume_create(IsA(http.HttpRequest),
                             formData['size'],
                             formData['name'],
                             formData['description'],
                             '',
                             metadata={},
                             snapshot_id=None,
                             image_id=image.id,
                             availability_zone=None,
                             source_volid=None).AndReturn(volume)

        self.mox.ReplayAll()

        # get image from url
        url = reverse('horizon:project:volumes:volumes:create')
        res = self.client.post("?".join([url,
                                         "image_id=" + str(image.id)]),
                               formData)

        redirect_url = reverse('horizon:project:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)
Example #26
0
    def test_create_volume_from_image_under_image_size(self):
        usage_limit = {
            'maxTotalVolumeGigabytes': 100,
            'gigabytesUsed': 20,
            'volumesUsed': len(self.volumes.list()),
            'maxTotalVolumes': 6
        }
        image = self.images.first()
        formData = {
            'name': u'A Volume I Am Making',
            'description': u'This is a volume I am making for a test.',
            'method': u'CreateForm',
            'size': 1,
            'image_source': image.id
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:volumes:create')
        res = self.client.post("?".join([url, "image_id=" + str(image.id)]),
                               formData,
                               follow=True)
        self.assertEqual(res.redirect_chain, [])

        # in django 1.6 filesizeformat replaces all spaces with
        # non-breaking space characters
        if django.VERSION >= (1, 6):
            msg = (u"The volume size cannot be less than the "
                   u"image size (20.0\xa0GB)")
        else:
            msg = (u"The volume size cannot be less than the "
                   u"image size (20.0 GB)")

        self.assertFormError(res, 'form', None, msg)
Example #27
0
    def test_create_volume_number_over_alloted_quota(self):
        usage_limit = {
            'maxTotalVolumeGigabytes': 100,
            'gigabytesUsed': 20,
            'volumesUsed': len(self.volumes.list()),
            'maxTotalVolumes': len(self.volumes.list())
        }
        formData = {
            'name': u'Too Many...',
            'description': u'We have no volumes left!',
            'method': u'CreateForm',
            'size': 10
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
                                    AndReturn(self.volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        cinder.volume_list(IsA(http.HttpRequest)).AndReturn(
            self.volumes.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

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

        expected_error = [
            u'You are already using all of your available'
            ' volumes.'
        ]
        self.assertEqual(res.context['form'].errors['__all__'], expected_error)
Example #28
0
def _is_vol_type_enc_possible(request):
    try:
        supported = cinder.extension_supported(request,
                                               'VolumeTypeEncryption')
    except Exception:
        exceptions.handle(request, _('Unable to determine if volume type '
                                     'encryption is supported.'))
        return False
    return supported
Example #29
0
def _is_vol_type_enc_possible(request):
    try:
        supported = cinder.extension_supported(request,
                                               'VolumeTypeEncryption')
    except Exception:
        exceptions.handle(request, _('Unable to determine if volume type '
                                     'encryption is supported.'))
        return False
    return supported
Example #30
0
    def test_create_volume_from_snapshot_invalid_size(self):
        usage_limit = {
            'maxTotalVolumeGigabytes': 100,
            'gigabytesUsed': 20,
            'volumesUsed': len(self.volumes.list()),
            'maxTotalVolumes': 6
        }
        snapshot = self.volume_snapshots.first()
        formData = {
            'name': u'A Volume I Am Making',
            'description': u'This is a volume I am making for a test.',
            'method': u'CreateForm',
            'size': 20,
            'snapshot_source': snapshot.id
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_get(IsA(http.HttpRequest),
                                   str(snapshot.id)).AndReturn(snapshot)
        cinder.volume_get(IsA(http.HttpRequest), snapshot.volume_id).\
                          AndReturn(self.volumes.first())

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:create')
        res = self.client.post("?".join(
            [url, "snapshot_id=" + str(snapshot.id)]),
                               formData,
                               follow=True)
        self.assertEqual(res.redirect_chain, [])
        self.assertFormError(
            res, 'form', None, "The volume size cannot be less than the "
            "snapshot size (40GB)")
Example #31
0
def volume_availability_zone_list(request):
    """Utility method to retrieve a list of volume availability zones."""
    try:
        if cinder.extension_supported(request, 'AvailabilityZones'):
            return cinder.availability_zone_list(request)
        return []
    except Exception:
        exceptions.handle(request,
                          _('Unable to retrieve volumes availability zones.'))
        return []
Example #32
0
    def test_create_volume_from_image_under_image_size(self):
        usage_limit = {'maxTotalVolumeGigabytes': 100,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.cinder_volumes.list()),
                       'maxTotalVolumes': 6}
        image = self.images.first()
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 1, 'image_source': image.id}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest),
                             str(image.id)).AndReturn(image)
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:volumes:create')
        res = self.client.post("?".join([url,
                                         "image_id=" + str(image.id)]),
                               formData, follow=True)
        self.assertEqual(res.redirect_chain, [])

        # in django 1.6 filesizeformat replaces all spaces with
        # non-breaking space characters
        if django.VERSION >= (1, 6):
            msg = (u"The volume size cannot be less than the "
                   u"image size (20.0\xa0GB)")
        else:
            msg = (u"The volume size cannot be less than the "
                   u"image size (20.0 GB)")

        self.assertFormError(res, 'form', None, msg)
Example #33
0
    def test_create_volume_number_over_alloted_quota(self):
        usage_limit = {'maxTotalVolumeGigabytes': 100,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.cinder_volumes.list()),
                       'maxTotalVolumes': len(self.cinder_volumes.list())}
        formData = {'name': u'Too Many...',
                    'description': u'We have no volumes left!',
                    'method': u'CreateForm',
                    'size': 10}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        cinder.volume_list(IsA(
            http.HttpRequest)).AndReturn(self.cinder_volumes.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

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

        expected_error = [u'You are already using all of your available'
                          ' volumes.']
        self.assertEqual(res.context['form'].errors['__all__'], expected_error)
Example #34
0
    def test_create_volume_gb_used_over_alloted_quota(self):
        usage_limit = {'maxTotalVolumeGigabytes': 100,
                       'gigabytesUsed': 80,
                       'volumesUsed': len(self.cinder_volumes.list()),
                       'maxTotalVolumes': 6}
        formData = {'name': u'This Volume Is Huge!',
                    'description': u'This is a volume that is just too big!',
                    'method': u'CreateForm',
                    'size': 5000}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_list(IsA(http.HttpRequest)).\
            AndReturn(self.cinder_volume_snapshots.list())
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                                       filters={'is_public': True,
                                                'status': 'active'}) \
                  .AndReturn([self.images.list(), False])
        api.glance.image_list_detailed(IsA(http.HttpRequest),
                            filters={'property-owner_id': self.tenant.id,
                                     'status': 'active'}) \
                  .AndReturn([[], False])
        cinder.volume_list(IsA(
            http.HttpRequest)).AndReturn(self.cinder_volumes.list())
        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

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

        expected_error = [u'A volume of 5000GB cannot be created as you only'
                          ' have 20GB of your quota available.']
        self.assertEqual(res.context['form'].errors['__all__'], expected_error)
Example #35
0
 def test_manage_volume(self):
     metadata = {'key': u'k1',
                 'value': u'v1'}
     formData = {'host': 'host-1',
                 'identifier': 'vol-1',
                 'id_type': u'source-name',
                 'name': 'name-1',
                 'description': 'manage a volume',
                 'volume_type': 'vol_type_1',
                 'availability_zone': 'nova',
                 'metadata': metadata['key'] + '=' + metadata['value'],
                 'bootable': False}
     cinder.volume_type_list(
         IsA(http.HttpRequest)). \
         AndReturn(self.cinder_volume_types.list())
     cinder.availability_zone_list(
         IsA(http.HttpRequest)). \
         AndReturn(self.availability_zones.list())
     cinder.extension_supported(
         IsA(http.HttpRequest),
         'AvailabilityZones'). \
         AndReturn(True)
     cinder.volume_manage(
         IsA(http.HttpRequest),
         host=formData['host'],
         identifier=formData['identifier'],
         id_type=formData['id_type'],
         name=formData['name'],
         description=formData['description'],
         volume_type=formData['volume_type'],
         availability_zone=formData['availability_zone'],
         metadata={metadata['key']: metadata['value']},
         bootable=formData['bootable'])
     self.mox.ReplayAll()
     res = self.client.post(
         reverse('horizon:admin:volumes:manage'),
         formData)
     self.assertNoFormErrors(res)
Example #36
0
 def test_manage_volume(self):
     metadata = {'key': u'k1',
                 'value': u'v1'}
     formData = {'host': 'host-1',
                 'identifier': 'vol-1',
                 'id_type': u'source-name',
                 'name': 'name-1',
                 'description': 'manage a volume',
                 'volume_type': 'vol_type_1',
                 'availability_zone': 'nova',
                 'metadata': metadata['key'] + '=' + metadata['value'],
                 'bootable': False}
     cinder.volume_type_list(
         IsA(http.HttpRequest)).\
         AndReturn(self.cinder_volume_types.list())
     cinder.availability_zone_list(
         IsA(http.HttpRequest)).\
         AndReturn(self.availability_zones.list())
     cinder.extension_supported(
         IsA(http.HttpRequest),
         'AvailabilityZones').\
         AndReturn(True)
     cinder.volume_manage(
         IsA(http.HttpRequest),
         host=formData['host'],
         identifier=formData['identifier'],
         id_type=formData['id_type'],
         name=formData['name'],
         description=formData['description'],
         volume_type=formData['volume_type'],
         availability_zone=formData['availability_zone'],
         metadata={metadata['key']: metadata['value']},
         bootable=formData['bootable'])
     self.mox.ReplayAll()
     res = self.client.post(
         reverse('horizon:admin:volumes:volumes:manage'),
         formData)
     self.assertNoFormErrors(res)
Example #37
0
    def test_create_volume_from_snapshot_invalid_size(self):
        usage_limit = {'maxTotalVolumeGigabytes': 100,
                       'gigabytesUsed': 20,
                       'volumesUsed': len(self.volumes.list()),
                       'maxTotalVolumes': 6}
        snapshot = self.volume_snapshots.first()
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 20, 'snapshot_source': snapshot.id}

        cinder.volume_type_list(IsA(http.HttpRequest)).\
                                AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)
        cinder.volume_snapshot_get(IsA(http.HttpRequest),
                                   str(snapshot.id)).AndReturn(snapshot)
        cinder.volume_get(IsA(http.HttpRequest), snapshot.volume_id).\
                          AndReturn(self.volumes.first())

        cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
            .AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
            self.cinder_availability_zones.list())

        quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
                                AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:create')
        res = self.client.post("?".join([url,
                                         "snapshot_id=" + str(snapshot.id)]),
                               formData, follow=True)
        self.assertEqual(res.redirect_chain, [])
        self.assertFormError(res, 'form', None,
                             "The volume size cannot be less than the "
                             "snapshot size (40GB)")
Example #38
0
    def test_create_volume_from_image_under_image_size(self):
        usage_limit = {
            "maxTotalVolumeGigabytes": 100,
            "gigabytesUsed": 20,
            "volumesUsed": len(self.cinder_volumes.list()),
            "maxTotalVolumes": 6,
        }
        image = self.images.first()
        formData = {
            "name": u"A Volume I Am Making",
            "description": u"This is a volume I am making for a test.",
            "method": u"CreateForm",
            "size": 1,
            "image_source": image.id,
        }

        cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(self.volume_types.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)
        api.glance.image_get(IsA(http.HttpRequest), str(image.id)).AndReturn(image)
        cinder.extension_supported(IsA(http.HttpRequest), "AvailabilityZones").AndReturn(True)
        cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(self.cinder_availability_zones.list())
        quotas.tenant_limit_usages(IsA(http.HttpRequest)).AndReturn(usage_limit)

        self.mox.ReplayAll()

        url = reverse("horizon:project:volumes:volumes:create")
        res = self.client.post("?".join([url, "image_id=" + str(image.id)]), formData, follow=True)
        self.assertEqual(res.redirect_chain, [])

        # in django 1.6 filesizeformat replaces all spaces with
        # non-breaking space characters
        if django.VERSION >= (1, 6):
            msg = u"The volume size cannot be less than the " u"image size (20.0\xa0GB)"
        else:
            msg = u"The volume size cannot be less than the " u"image size (20.0 GB)"

        self.assertFormError(res, "form", None, msg)
Example #39
0
 def cinder_az_supported(self, request):
     try:
         return cinder.extension_supported(request, "AvailabilityZones")
     except Exception:
         exceptions.handle(request, _("Unable to determine if " "availability zones extension " "is supported."))
         return False