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)
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)
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)
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())
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)
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)
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)
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)
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)" )
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)")
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)")
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 []
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)
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)
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)
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)
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)
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)")
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)