Exemplo n.º 1
0
    def test_create_volume(self):
        volume = self.volumes.first()
        usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 6}}
        formData = {
            'name': u'A Volume I Am Making',
            'description': u'This is a volume I am making for a test.',
            'method': u'CreateForm',
            'size': 50,
            'snapshot_source': ''
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).\
                                 AndReturn(self.volume_snapshots.list())
        api.volume_create(IsA(http.HttpRequest),
                          formData['size'],
                          formData['name'],
                          formData['description'],
                          snapshot_id=None).AndReturn(volume)

        self.mox.ReplayAll()

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

        redirect_url = reverse('horizon:project:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)
Exemplo n.º 2
0
    def test_launch_flavorlist_error(self):
        image = self.images.first()

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')
        self.mox.StubOutWithMock(api, 'volume_list')

        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.volumes.list())
        api.image_get(IsA(http.HttpRequest),
                           image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(
                self.quota_usages.first())
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res,
                                'nova/images_and_snapshots/images/launch.html')
Exemplo n.º 3
0
    def test_create_volume_number_over_alloted_quota(self):
        usage = {
            'gigabytes': {
                'available': 100,
                'used': 20
            },
            'volumes': {
                'available': 0
            }
        }
        formData = {
            'name': u'Too Many...',
            'description': u'We have no volumes left!',
            'method': u'CreateForm',
            'size': 10
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

        url = reverse('horizon:nova: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)
Exemplo n.º 4
0
    def test_launch_get(self):
        image = self.images.first()
        quota_usages = self.quota_usages.first()

        self.mox.StubOutWithMock(api, 'image_get_meta')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quota_usages)
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        form = res.context['form']
        self.assertTemplateUsed(res,
                                'nova/images_and_snapshots/images/launch.html')
        self.assertEqual(res.context['image'].name, image.name)
        self.assertIn(self.flavors.first().name,
                      form.fields['flavor'].choices[0][1])
        self.assertEqual(self.keypairs.first().name,
                         form.fields['keypair'].choices[1][0])
Exemplo n.º 5
0
    def test_launch_keypairlist_error(self):
        image = self.images.first()

        self.mox.StubOutWithMock(api, 'image_get_meta')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(
                self.quota_usages.first())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        exception = keystone_exceptions.ClientException('Failed.')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res,
                                'nova/images_and_snapshots/images/launch.html')
        self.assertEqual(len(res.context['form'].fields['keypair'].choices), 1)
Exemplo n.º 6
0
    def test_create_volume_from_snapshot_invalid_size(self):
        usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 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
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.nova.volume_snapshot_get(IsA(http.HttpRequest),
                                     str(snapshot.id)).AndReturn(snapshot)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        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)")
Exemplo n.º 7
0
    def test_create_volume_from_snapshot(self):
        volume = self.volumes.first()
        usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 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': 50,
            'snapshot_source': snapshot.id
        }

        # first call- with url param
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.nova.volume_snapshot_get(IsA(http.HttpRequest),
                                     str(snapshot.id)).AndReturn(snapshot)
        api.volume_create(IsA(http.HttpRequest),
                          formData['size'],
                          formData['name'],
                          formData['description'],
                          snapshot_id=snapshot.id).\
                          AndReturn(volume)
        # second call- with dropdown
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).\
                                 AndReturn(self.volume_snapshots.list())
        api.nova.volume_snapshot_get(IsA(http.HttpRequest),
                                     str(snapshot.id)).AndReturn(snapshot)
        api.volume_create(IsA(http.HttpRequest),
                          formData['size'],
                          formData['name'],
                          formData['description'],
                          snapshot_id=snapshot.id).\
                          AndReturn(volume)

        self.mox.ReplayAll()

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

        redirect_url = reverse('horizon:project:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)

        # get snapshot 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)
Exemplo n.º 8
0
    def test_create_volume_from_snapshot(self):
        volume = self.volumes.first()
        usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 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': 50, 'snapshot_source': snapshot.id}

        # first call- with url param
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.nova.volume_snapshot_get(IsA(http.HttpRequest),
                        str(snapshot.id)).AndReturn(snapshot)
        api.volume_create(IsA(http.HttpRequest),
                          formData['size'],
                          formData['name'],
                          formData['description'],
                          snapshot_id=snapshot.id).\
                          AndReturn(volume)
        # second call- with dropdown
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).\
                                 AndReturn(self.volume_snapshots.list())
        api.nova.volume_snapshot_get(IsA(http.HttpRequest),
                        str(snapshot.id)).AndReturn(snapshot)
        api.volume_create(IsA(http.HttpRequest),
                          formData['size'],
                          formData['name'],
                          formData['description'],
                          snapshot_id=snapshot.id).\
                          AndReturn(volume)

        self.mox.ReplayAll()

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

        redirect_url = reverse('horizon:nova:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)

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

        redirect_url = reverse('horizon:nova:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)
Exemplo n.º 9
0
    def handle(self, request, data):
        try:
            # FIXME(johnp): Nova (cinderclient) currently returns a useless
            # error message when the quota is exceeded when trying to create
            # a volume, so we need to check for that scenario here before we
            # send it off to Nova to try and create.
            usages = api.tenant_quota_usages(request)

            if type(data["size"]) is str:
                data["size"] = int(data["size"])

            if usages["gigabytes"]["available"] < data["size"]:
                error_message = _(
                    "A volume of %(req)iGB cannot be created as "
                    "you only have %(avail)iGB of your quota "
                    "available."
                )
                params = {"req": data["size"], "avail": usages["gigabytes"]["available"]}
                raise ValidationError(error_message % params)
            elif usages["volumes"]["available"] <= 0:
                error_message = _("You are already using all of your available" " volumes.")
                raise ValidationError(error_message)

            api.volume_create(request, data["size"], data["name"], data["description"])
            message = 'Creating volume "%s"' % data["name"]

            messages.info(request, message)
        except ValidationError, e:
            return self.api_error(e.messages[0])
Exemplo n.º 10
0
 def get_context_data(self, **kwargs):
     context = super(CreateView, self).get_context_data(**kwargs)
     try:
         context['usages'] = api.tenant_quota_usages(self.request)
     except:
         exceptions.handle(self.request)
     return context
Exemplo n.º 11
0
    def handle(self, request, data):
        try:
            # FIXME(johnp): Nova (cinderclient) currently returns a useless
            # error message when the quota is exceeded when trying to create
            # a volume, so we need to check for that scenario here before we
            # send it off to Nova to try and create.
            usages = api.tenant_quota_usages(request)

            if type(data['size']) is str:
                data['size'] = int(data['size'])

            if usages['gigabytes']['available'] < data['size']:
                error_message = _('A volume of %iGB cannot be created as you'
                                  ' only have %iGB of your quota available.'
                                  % (data['size'],
                                     usages['gigabytes']['available'],))
                raise ValidationError(error_message)
            elif usages['volumes']['available'] <= 0:
                error_message = _('You are already using all of your available'
                                  ' volumes.')
                raise ValidationError(error_message)

            api.volume_create(request, data['size'], data['name'],
                              data['description'])
            message = 'Creating volume "%s"' % data['name']

            messages.info(request, message)
        except ValidationError, e:
            return self.api_error(e.messages[0])
Exemplo n.º 12
0
    def handle(self, request, data):
        try:
            # FIXME(johnp): Nova (cinderclient) currently returns a useless
            # error message when the quota is exceeded when trying to create
            # a volume, so we need to check for that scenario here before we
            # send it off to Nova to try and create.
            usages = api.tenant_quota_usages(request)

            if type(data['size']) is str:
                data['size'] = int(data['size'])

            if usages['gigabytes']['available'] < data['size']:
                error_message = _('A volume of %(req)iGB cannot be created as '
                                  'you only have %(avail)iGB of your quota '
                                  'available.')
                params = {
                    'req': data['size'],
                    'avail': usages['gigabytes']['available']
                }
                raise ValidationError(error_message % params)
            elif usages['volumes']['available'] <= 0:
                error_message = _('You are already using all of your available'
                                  ' volumes.')
                raise ValidationError(error_message)

            api.volume_create(request, data['size'], data['name'],
                              data['description'])
            message = 'Creating volume "%s"' % data['name']

            messages.info(request, message)
        except ValidationError, e:
            return self.api_error(e.messages[0])
Exemplo n.º 13
0
    def test_tenant_quota_usages(self):
        servers = self.servers.list()
        flavors = self.flavors.list()
        quotas = self.quotas.first()
        novaclient = self.stub_novaclient()

        novaclient.servers = self.mox.CreateMockAnything()
        novaclient.servers.list(True, {'project_id': '1'}).AndReturn(servers)
        novaclient.flavors = self.mox.CreateMockAnything()
        novaclient.flavors.list().AndReturn(flavors)
        novaclient.quotas = self.mox.CreateMockAnything()
        novaclient.quotas.get(self.tenant.id).AndReturn(quotas)
        self.mox.ReplayAll()

        quota_usages = api.tenant_quota_usages(self.request)

        self.assertIsInstance(quota_usages, dict)
        self.assertEquals(quota_usages,
                          {'gigabytes': {'available': 1000,
                                         'used': 0,
                                         'flavor_fields': ['disk',
                                                           'ephemeral'],
                                         'quota': 1000},
                           'instances': {'available': 8,
                                         'used': 2,
                                         'flavor_fields': [],
                                         'quota': 10},
                           'ram': {'available': 8976,
                                   'used': 1024,
                                   'flavor_fields': ['ram'],
                                   'quota': 10000},
                           'cores': {'available': 8,
                                     'used': 2,
                                     'flavor_fields': ['vcpus'],
                                     'quota': 10}})
Exemplo n.º 14
0
 def get_context_data(self, **kwargs):
     context = super(AllocateView, self).get_context_data(**kwargs)
     try:
         context['usages'] = api.tenant_quota_usages(self.request)
     except:
         exceptions.handle(self.request)
     return context
Exemplo n.º 15
0
    def test_launch_form_instance_count_error(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        volume = self.volumes.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'user data'
        device_name = u'vda'
        volume_choice = "%s:vol" % volume.id

        self.mox.StubOutWithMock(api, 'image_get_meta')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')

        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([])
        api.tenant_quota_usages(IsA(http.HttpRequest)) \
                                .AndReturn(self.quota_usages.first())
        self.mox.ReplayAll()

        form_data = {'method': 'LaunchForm',
                     'flavor': flavor.id,
                     'image_id': image.id,
                     'keypair': keypair.name,
                     'name': server.name,
                     'user_data': USER_DATA,
                     'tenant_id': self.tenants.first().id,
                     'security_groups': sec_group.name,
                     'volume': volume_choice,
                     'device_name': device_name,
                     'count': 0}
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertFormErrors(res, count=1)
Exemplo n.º 16
0
    def test_launch_form_instance_count_error(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        volume = self.volumes.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'user data'
        device_name = u'vda'
        volume_choice = "%s:vol" % volume.id

        self.mox.StubOutWithMock(api, 'image_get_meta')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')

        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([])
        api.tenant_quota_usages(IsA(http.HttpRequest)) \
                                .AndReturn(self.quota_usages.first())
        self.mox.ReplayAll()

        form_data = {
            'method': 'LaunchForm',
            'flavor': flavor.id,
            'image_id': image.id,
            'keypair': keypair.name,
            'name': server.name,
            'user_data': USER_DATA,
            'tenant_id': self.tenants.first().id,
            'security_groups': sec_group.name,
            'volume': volume_choice,
            'device_name': device_name,
            'count': 0
        }
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertFormErrors(res, count=1)
Exemplo n.º 17
0
    def test_create_volume_gb_used_over_alloted_quota(self):
        usage = {'gigabytes': {'available': 100, 'used': 20}}
        formData = {'name': u'This Volume Is Huge!',
                    'description': u'This is a volume that is just too big!',
                    'method': u'CreateForm',
                    'size': 5000}

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

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

        expected_error = [u'A volume of 5000GB cannot be created as you only'
                          ' have 100GB of your quota available.']
        self.assertEqual(res.context['form'].errors['__all__'], expected_error)
Exemplo n.º 18
0
    def test_create_volume_number_over_alloted_quota(self):
        usage = {'gigabytes': {'available': 100, 'used': 20},
                 'volumes': {'available': 0}}
        formData = {'name': u'Too Many...',
                    'description': u'We have no volumes left!',
                    'method': u'CreateForm',
                    'size': 10}

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

        url = reverse('horizon:nova: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)
Exemplo n.º 19
0
 def get_context_data(self, **kwargs):
     context = super(LaunchView, self).get_context_data(**kwargs)
     try:
         context['usages'] = api.tenant_quota_usages(self.request)
         context['usages_json'] = json.dumps(context['usages'])
         flavors = json.dumps(
                 [f._info for f in api.flavor_list(self.request)])
         context['flavors'] = flavors
     except:
         exceptions.handle(self.request)
     return context
Exemplo n.º 20
0
    def test_create_volume_gb_used_over_alloted_quota(self):
        usage = {"gigabytes": {"available": 100, "used": 20}}
        formData = {
            "name": u"This Volume Is Huge!",
            "description": u"This is a volume that is just too big!",
            "method": u"CreateForm",
            "size": 5000,
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.volume_snapshots.list())
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

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

        expected_error = [u"A volume of 5000GB cannot be created as you only" " have 100GB of your quota available."]
        self.assertEqual(res.context["form"].errors["__all__"], expected_error)
Exemplo n.º 21
0
    def test_create_volume_number_over_alloted_quota(self):
        usage = {"gigabytes": {"available": 100, "used": 20}, "volumes": {"available": 0}}
        formData = {
            "name": u"Too Many...",
            "description": u"We have no volumes left!",
            "method": u"CreateForm",
            "size": 10,
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.volume_snapshots.list())
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

        url = reverse("horizon:nova: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)
Exemplo n.º 22
0
    def test_create_volume_gb_used_over_alloted_quota(self):
        usage = {'gigabytes': {'available': 100, 'used': 20}}
        formData = {'name': u'This Volume Is Huge!',
                    'description': u'This is a volume that is just too big!',
                    'method': u'CreateForm',
                    'size': 5000}

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).\
                                 AndReturn(self.volume_snapshots.list())
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

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

        expected_error = [u'A volume of 5000GB cannot be created as you only'
                          ' have 100GB of your quota available.']
        self.assertEqual(res.context['form'].errors['__all__'], expected_error)
Exemplo n.º 23
0
    def test_create_volume(self):
        usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 6}}
        formData = {'name': u'A Volume I Am Making',
                    'description': u'This is a volume I am making for a test.',
                    'method': u'CreateForm',
                    'size': 50}

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_create(IsA(http.HttpRequest),
                          formData['size'],
                          formData['name'],
                          formData['description'])

        self.mox.ReplayAll()

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

        redirect_url = reverse('horizon:nova:volumes:index')
        self.assertRedirectsNoFollow(res, redirect_url)
Exemplo n.º 24
0
    def test_create_volume_from_snapshot(self):
        volume = self.volumes.first()
        usage = {"gigabytes": {"available": 250}, "volumes": {"available": 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": 50,
            "snapshot_source": snapshot.id,
        }

        # first call- with url param
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.nova.volume_snapshot_get(IsA(http.HttpRequest), str(snapshot.id)).AndReturn(snapshot)
        api.volume_create(
            IsA(http.HttpRequest), formData["size"], formData["name"], formData["description"], snapshot_id=snapshot.id
        ).AndReturn(volume)
        # second call- with dropdown
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.volume_snapshots.list())
        api.nova.volume_snapshot_get(IsA(http.HttpRequest), str(snapshot.id)).AndReturn(snapshot)
        api.volume_create(
            IsA(http.HttpRequest), formData["size"], formData["name"], formData["description"], snapshot_id=snapshot.id
        ).AndReturn(volume)

        self.mox.ReplayAll()

        # get snapshot from url
        url = reverse("horizon:nova:volumes:create")
        res = self.client.post("?".join([url, "snapshot_id=" + str(snapshot.id)]), formData)

        redirect_url = reverse("horizon:nova:volumes:index")
        self.assertRedirectsNoFollow(res, redirect_url)

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

        redirect_url = reverse("horizon:nova:volumes:index")
        self.assertRedirectsNoFollow(res, redirect_url)
Exemplo n.º 25
0
    def test_tenant_quota_usages(self):
        servers = self.servers.list()
        flavors = self.flavors.list()
        floating_ips = self.floating_ips.list()
        quotas = self.quotas.first()
        novaclient = self.stub_novaclient()

        novaclient.servers = self.mox.CreateMockAnything()
        novaclient.servers.list(True, {'project_id': '1'}).AndReturn(servers)
        novaclient.flavors = self.mox.CreateMockAnything()
        novaclient.flavors.list().AndReturn(flavors)
        novaclient.floating_ips = self.mox.CreateMockAnything()
        novaclient.floating_ips.list().AndReturn(floating_ips)
        novaclient.quotas = self.mox.CreateMockAnything()
        novaclient.quotas.get(self.tenant.id).AndReturn(quotas)
        self.mox.ReplayAll()

        quota_usages = api.tenant_quota_usages(self.request)

        self.assertIsInstance(quota_usages, dict)
        self.assertEquals(
            quota_usages, {
                'gigabytes': {
                    'available': 1000,
                    'used': 0,
                    'flavor_fields': ['disk', 'OS-FLV-EXT-DATA:ephemeral'],
                    'quota': 1000
                },
                'instances': {
                    'available': 8,
                    'used': 2,
                    'flavor_fields': [],
                    'quota': 10
                },
                'ram': {
                    'available': 8976,
                    'used': 1024,
                    'flavor_fields': ['ram'],
                    'quota': 10000
                },
                'cores': {
                    'available': 8,
                    'used': 2,
                    'flavor_fields': ['vcpus'],
                    'quota': 10
                },
                'floating_ips': {
                    'available': -1,
                    'used': 2,
                    'flavor_fields': [],
                    'quota': 1
                }
            })
Exemplo n.º 26
0
    def test_create_volume_from_snapshot_invalid_size(self):
        usage = {"gigabytes": {"available": 250}, "volumes": {"available": 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,
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.nova.volume_snapshot_get(IsA(http.HttpRequest), str(snapshot.id)).AndReturn(snapshot)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

        url = reverse("horizon:nova: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)")
Exemplo n.º 27
0
    def test_create_volume_from_snapshot_invalid_size(self):
        usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 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}

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.nova.volume_snapshot_get(IsA(http.HttpRequest),
                        str(snapshot.id)).AndReturn(snapshot)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)

        self.mox.ReplayAll()

        url = reverse('horizon:nova: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)")
Exemplo n.º 28
0
    def test_launch_flavorlist_error(self):
        image = self.images.first()

        self.mox.StubOutWithMock(api, 'image_get_meta')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(
            self.quota_usages.first())
        exc = keystone_exceptions.ClientException('Failed.')
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(exc)
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        self.assertTemplateUsed(
            res, 'nova/images_and_snapshots/images/launch.html')
Exemplo n.º 29
0
    def test_create_volume(self):
        volume = self.volumes.first()
        usage = {"gigabytes": {"available": 250}, "volumes": {"available": 6}}
        formData = {
            "name": u"A Volume I Am Making",
            "description": u"This is a volume I am making for a test.",
            "method": u"CreateForm",
            "size": 50,
            "snapshot_source": "",
        }

        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(usage)
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn(self.volume_snapshots.list())
        api.volume_create(
            IsA(http.HttpRequest), formData["size"], formData["name"], formData["description"], snapshot_id=None
        ).AndReturn(volume)

        self.mox.ReplayAll()

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

        redirect_url = reverse("horizon:nova:volumes:index")
        self.assertRedirectsNoFollow(res, redirect_url)
Exemplo n.º 30
0
    def handle(self, request, data):
        try:
            # FIXME(johnp): cinderclient currently returns a useless
            # error message when the quota is exceeded when trying to create
            # a volume, so we need to check for that scenario here before we
            # send it off to try and create.
            usages = api.tenant_quota_usages(request)

            snapshot_id = None
            if (data.get("snapshot_source", None)):
                # Create from Snapshot
                snapshot = self.get_snapshot(request, data["snapshot_source"])
                snapshot_id = snapshot.id
                if (data['size'] < snapshot.size):
                    error_message = _('The volume size cannot be less than '
                                      'the snapshot size (%sGB)' %
                                      snapshot.size)
                    raise ValidationError(error_message)
            else:
                if type(data['size']) is str:
                    data['size'] = int(data['size'])

            if usages['gigabytes']['available'] < data['size']:
                error_message = _('A volume of %(req)iGB cannot be created as '
                                  'you only have %(avail)iGB of your quota '
                                  'available.')
                params = {
                    'req': data['size'],
                    'avail': usages['gigabytes']['available']
                }
                raise ValidationError(error_message % params)
            elif usages['volumes']['available'] <= 0:
                error_message = _('You are already using all of your available'
                                  ' volumes.')
                raise ValidationError(error_message)

            volume = api.volume_create(request,
                                       data['size'],
                                       data['name'],
                                       data['description'],
                                       snapshot_id=snapshot_id)
            message = 'Creating volume "%s"' % data['name']
            messages.info(request, message)
            return volume
        except ValidationError, e:
            return self.api_error(e.messages[0])
Exemplo n.º 31
0
    def handle(self, request, data):
        try:
            # FIXME(johnp): Nova (cinderclient) currently returns a useless
            # error message when the quota is exceeded when trying to create
            # a volume, so we need to check for that scenario here before we
            # send it off to Nova to try and create.
            usages = api.tenant_quota_usages(request)

            snapshot_id = None
            if (data.get("snapshot_source", None)):
                # Create from Snapshot
                snapshot = self.get_snapshot(request,
                                             data["snapshot_source"])
                snapshot_id = snapshot.id
                if (data['size'] < snapshot.size):
                    error_message = _('The volume size cannot be less than '
                                      'the snapshot size (%sGB)' %
                                      snapshot.size)
                    raise ValidationError(error_message)
            else:
                if type(data['size']) is str:
                    data['size'] = int(data['size'])

            if usages['gigabytes']['available'] < data['size']:
                error_message = _('A volume of %(req)iGB cannot be created as '
                                  'you only have %(avail)iGB of your quota '
                                  'available.')
                params = {'req': data['size'],
                          'avail': usages['gigabytes']['available']}
                raise ValidationError(error_message % params)
            elif usages['volumes']['available'] <= 0:
                error_message = _('You are already using all of your available'
                                  ' volumes.')
                raise ValidationError(error_message)

            volume = api.volume_create(request,
                                       data['size'],
                                       data['name'],
                                       data['description'],
                                       snapshot_id=snapshot_id)
            message = 'Creating volume "%s"' % data['name']
            messages.info(request, message)
            return volume
        except ValidationError, e:
            return self.api_error(e.messages[0])
Exemplo n.º 32
0
    def test_tenant_quota_usages_unlimited_quota(self):
        inf_quota = self.quotas.first()
        inf_quota.ram = -1

        api.nova.flavor_list(IsA(http.HttpRequest)) \
            .AndReturn(self.flavors.list())
        api.nova.tenant_quota_get(IsA(http.HttpRequest), '1') \
            .AndReturn(inf_quota)
        api.nova.tenant_floating_ip_list(IsA(http.HttpRequest)) \
            .AndReturn(self.floating_ips.list())
        api.nova.server_list(IsA(http.HttpRequest)) \
            .AndReturn(self.servers.list())
        api.nova.volume_list(IsA(http.HttpRequest)) \
            .AndReturn(self.volumes.list())

        self.mox.ReplayAll()

        quota_usages = api.tenant_quota_usages(self.request)
        expected_output = {'gigabytes': {
                                'used': 80,
                                'flavor_fields': [],
                                'quota': 1000},
                           'ram': {
                                'available': float("inf"),
                                'used': 1024,
                                'flavor_fields': ['ram'],
                                'quota': float("inf")},
                           'floating_ips': {
                                'used': 2,
                                'flavor_fields': [],
                                'quota': 1},
                           'instances': {
                                'used': 2,
                                'flavor_fields': [],
                                'quota': 10},
                           'volumes': {
                                'used': 3,
                                'flavor_fields': [],
                                'quota': 1},
                           'cores': {
                                'used': 2,
                                'flavor_fields': ['vcpus'],
                                'quota': 10}}

        self.assertEquals(quota_usages, expected_output)
Exemplo n.º 33
0
    def test_tenant_quota_usages(self):
        api.nova.flavor_list(IsA(http.HttpRequest)) \
            .AndReturn(self.flavors.list())
        api.nova.tenant_quota_get(IsA(http.HttpRequest), '1') \
            .AndReturn(self.quotas.first())
        api.nova.tenant_floating_ip_list(IsA(http.HttpRequest)) \
            .AndReturn(self.floating_ips.list())
        api.nova.server_list(IsA(http.HttpRequest)) \
            .AndReturn(self.servers.list())
        api.nova.volume_list(IsA(http.HttpRequest)) \
            .AndReturn(self.volumes.list())

        self.mox.ReplayAll()

        quota_usages = api.tenant_quota_usages(self.request)
        expected_output = {'gigabytes': {
                                'used': 80,
                                'flavor_fields': [],
                                'quota': 1000},
                           'ram': {
                                'available': 8976,
                                'used': 1024,
                                'flavor_fields': ['ram'],
                                'quota': 10000},
                           'floating_ips': {
                                'used': 2,
                                'flavor_fields': [],
                                'quota': 1},
                           'instances': {
                                'used': 2,
                                'flavor_fields': [],
                                'quota': 10},
                           'volumes': {
                                'used': 3,
                                'flavor_fields': [],
                                'quota': 1},
                           'cores': {
                                'used': 2,
                                'flavor_fields': ['vcpus'],
                                'quota': 10}}

        self.assertEquals(quota_usages, expected_output)
Exemplo n.º 34
0
    def test_tenant_quota_usages(self):
        api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.nova.tenant_quota_get(IsA(http.HttpRequest), "1").AndReturn(self.quotas.first())
        api.nova.tenant_floating_ip_list(IsA(http.HttpRequest)).AndReturn(self.floating_ips.list())
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.nova.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())

        self.mox.ReplayAll()

        quota_usages = api.tenant_quota_usages(self.request)
        expected_output = {
            "gigabytes": {"used": 80, "flavor_fields": [], "quota": 1000},
            "ram": {"available": 8976, "used": 1024, "flavor_fields": ["ram"], "quota": 10000},
            "floating_ips": {"used": 2, "flavor_fields": [], "quota": 1},
            "instances": {"used": 2, "flavor_fields": [], "quota": 10},
            "volumes": {"used": 3, "flavor_fields": [], "quota": 1},
            "cores": {"used": 2, "flavor_fields": ["vcpus"], "quota": 10},
        }

        self.assertEquals(quota_usages, expected_output)
Exemplo n.º 35
0
    def handle(self, request, data):
        try:
            # FIXME(johnp): cinderclient currently returns a useless
            # error message when the quota is exceeded when trying to create
            # a volume, so we need to check for that scenario here before we
            # send it off to try and create.
            usages = api.tenant_quota_usages(request)

            snapshot_id = None
            if data.get("snapshot_source", None):
                # Create from Snapshot
                snapshot = self.get_snapshot(request, data["snapshot_source"])
                snapshot_id = snapshot.id
                if data["size"] < snapshot.size:
                    error_message = _("The volume size cannot be less than " "the snapshot size (%sGB)" % snapshot.size)
                    raise ValidationError(error_message)
            else:
                if type(data["size"]) is str:
                    data["size"] = int(data["size"])

            if usages["gigabytes"]["available"] < data["size"]:
                error_message = _(
                    "A volume of %(req)iGB cannot be created as "
                    "you only have %(avail)iGB of your quota "
                    "available."
                )
                params = {"req": data["size"], "avail": usages["gigabytes"]["available"]}
                raise ValidationError(error_message % params)
            elif usages["volumes"]["available"] <= 0:
                error_message = _("You are already using all of your available" " volumes.")
                raise ValidationError(error_message)

            volume = api.volume_create(
                request, data["size"], data["name"], data["description"], snapshot_id=snapshot_id
            )
            message = 'Creating volume "%s"' % data["name"]
            messages.info(request, message)
            return volume
        except ValidationError, e:
            return self.api_error(e.messages[0])