Example #1
0
    def test_delete_volume_snapshot(self):
        vol_snapshots = self.volume_snapshots.list()
        snapshot = self.volume_snapshots.first()

        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn(([], False))
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn(([], False))
        api.volume_snapshot_list(IsA(http.HttpRequest)). \
                                 AndReturn(vol_snapshots)
        api.volume_snapshot_delete(IsA(http.HttpRequest), snapshot.id)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn(([], False))
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn(([], False))
        api.volume_snapshot_list(IsA(http.HttpRequest)). \
                                 AndReturn([])
        self.mox.ReplayAll()

        formData = {'action':
                    'volume_snapshots__delete__%s' % snapshot.id}
        res = self.client.post(INDEX_URL, formData, follow=True)

        self.assertIn("Scheduled deletion of Volume Snapshot: test snapshot",
                      [m.message for m in res.context['messages']])
Example #2
0
    def test_index(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('images_table', res.context)
        images = res.context['images_table'].data
        filter_func = lambda im: im.container_format not in ['aki', 'ari']
        filtered_images = filter(filter_func, images)
        self.assertItemsEqual(images, filtered_images)
Example #3
0
    def test_create_instance_snapshot(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest), server.id,
                            "snapshot1").AndReturn(self.snapshots.first())

        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn([[], False])
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([[], False])
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([])

        self.mox.ReplayAll()

        formData = {
            'instance_id': server.id,
            'method': 'CreateSnapshot',
            'name': 'snapshot1'
        }
        url = reverse('horizon:project:images_and_snapshots:snapshots:create',
                      args=[server.id])
        redir_url = reverse('horizon:project:images_and_snapshots:index')
        res = self.client.post(url, formData)
        self.assertRedirects(res, redir_url)
Example #4
0
    def test_index(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('images_table', res.context)
        images = res.context['images_table'].data
        filter_func = lambda im: im.container_format not in ['aki', 'ari']
        filtered_images = filter(filter_func, images)
        self.assertItemsEqual(images, filtered_images)
Example #5
0
    def test_queued_snapshot_actions(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('snapshots_table', res.context)
        snaps = res.context['snapshots_table']
        self.assertEqual(len(snaps.get_rows()), 3)

        row_actions = snaps.get_row_actions(snaps.data[0])

        # first instance - status active, owned
        self.assertEqual(len(row_actions), 3)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")
        self.assertEqual(row_actions[1].verbose_name, u"Edit")
        self.assertEqual(row_actions[2].verbose_name, u"Delete Snapshot")

        row_actions = snaps.get_row_actions(snaps.data[1])

        # second instance - status active, not owned
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")

        row_actions = snaps.get_row_actions(snaps.data[2])
        # third instance - status queued, only delete is available
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(unicode(row_actions[0].verbose_name),
                         u"Delete Snapshot")
        self.assertEqual(str(row_actions[0]), "<DeleteSnapshot: delete>")
Example #6
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)
Example #7
0
    def test_queued_snapshot_actions(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('snapshots_table', res.context)
        snaps = res.context['snapshots_table']
        self.assertEqual(len(snaps.get_rows()), 3)

        row_actions = snaps.get_row_actions(snaps.data[0])

        # first instance - status active, owned
        self.assertEqual(len(row_actions), 3)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")
        self.assertEqual(row_actions[1].verbose_name, u"Edit")
        self.assertEqual(row_actions[2].verbose_name, u"Delete Snapshot")

        row_actions = snaps.get_row_actions(snaps.data[1])

        # second instance - status active, not owned
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")

        row_actions = snaps.get_row_actions(snaps.data[2])
        # third instance - status queued, only delete is available
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(unicode(row_actions[0].verbose_name),
                         u"Delete Snapshot")
        self.assertEqual(str(row_actions[0]), "<DeleteSnapshot: delete>")
Example #8
0
 def get_volume_snapshots_data(self):
     try:
         snapshots = api.volume_snapshot_list(self.request)
     except:
         snapshots = []
         exceptions.handle(self.request, _("Unable to retrieve " "volume snapshots."))
     return snapshots
Example #9
0
 def __init__(self, request, *args, **kwargs):
     super(CreateForm, self).__init__(request, *args, **kwargs)
     if ("snapshot_id" in request.GET):
         try:
             snapshot = self.get_snapshot(request,
                                          request.GET["snapshot_id"])
             self.fields['name'].initial = snapshot.display_name
             self.fields['size'].initial = snapshot.size
             self.fields['snapshot_source'].choices = ((snapshot.id,
                                                        snapshot), )
             self.fields['size'].help_text = _(
                 'Volume size must be equal '
                 'to or greater than the snapshot size (%sGB)' %
                 snapshot.size)
         except:
             exceptions.handle(request,
                               _('Unable to load the specified snapshot.'))
     else:
         try:
             snapshots = api.volume_snapshot_list(request)
             if snapshots:
                 choices = [('', _("Choose a snapshot"))] + \
                           [(s.id, s) for s in snapshots]
                 self.fields['snapshot_source'].choices = choices
             else:
                 del self.fields['snapshot_source']
         except:
             exceptions.handle(request,
                               _("Unable to retrieve "
                                 "volume snapshots."))
Example #10
0
 def __init__(self, request, *args, **kwargs):
     super(CreateForm, self).__init__(request, *args, **kwargs)
     if ("snapshot_id" in request.GET):
         try:
             snapshot = self.get_snapshot(request,
                                          request.GET["snapshot_id"])
             self.fields['name'].initial = snapshot.display_name
             self.fields['size'].initial = snapshot.size
             self.fields['snapshot_source'].choices = ((snapshot.id,
                                                        snapshot),)
             self.fields['size'].help_text = _('Volume size must be equal '
                             'to or greater than the snapshot size (%sGB)'
                             % snapshot.size)
         except:
             exceptions.handle(request,
                               _('Unable to load the specified snapshot.'))
     else:
         try:
             snapshots = api.volume_snapshot_list(request)
             if snapshots:
                 choices = [('', _("Choose a snapshot"))] + \
                           [(s.id, s) for s in snapshots]
                 self.fields['snapshot_source'].choices = choices
             else:
                 del self.fields['snapshot_source']
         except:
             exceptions.handle(request, _("Unable to retrieve "
                     "volume snapshots."))
Example #11
0
    def test_create_instance_snapshot(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest), server.id, "snapshot1").AndReturn(self.snapshots.first())

        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None).AndReturn([[], False])
        api.image_list_detailed(IsA(http.HttpRequest), marker=None).AndReturn([[], False])
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([])

        self.mox.ReplayAll()

        formData = {"instance_id": server.id, "method": "CreateSnapshot", "name": "snapshot1"}
        url = reverse("horizon:project:images_and_snapshots:snapshots:create", args=[server.id])
        redir_url = reverse("horizon:project:images_and_snapshots:index")
        res = self.client.post(url, formData)
        self.assertRedirects(res, redir_url)
Example #12
0
 def get_volume_snapshots_data(self):
     try:
         snapshots = api.volume_snapshot_list(self.request)
     except:
         snapshots = []
         exceptions.handle(self.request,
                           _("Unable to retrieve "
                             "volume snapshots."))
     return snapshots
Example #13
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:project: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)
Example #14
0
 def get_volume_snapshots_data(self):
     if is_service_enabled(self.request, 'volume'):
         try:
             snapshots = api.volume_snapshot_list(self.request)
         except:
             snapshots = []
             exceptions.handle(self.request, _("Unable to retrieve "
                                               "volume snapshots."))
     else:
         snapshots = []
     return snapshots
Example #15
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:project: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 #16
0
    def test_index_error(self):
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndRaise(self.exceptions.glance)
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([self.snapshots.list(), False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
Example #17
0
    def test_index_no_images(self):
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([(), False])
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([self.snapshots.list(), False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
Example #18
0
    def test_delete_volume_snapshot(self):
        vol_snapshots = self.volume_snapshots.list()
        snapshot = self.volume_snapshots.first()

        api.image_list_detailed(IsA(http.HttpRequest), marker=None).AndReturn(
            ([], False))
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn(([], False))
        api.volume_snapshot_list(IsA(http.HttpRequest)). \
                                 AndReturn(vol_snapshots)
        api.volume_snapshot_delete(IsA(http.HttpRequest), snapshot.id)
        api.image_list_detailed(IsA(http.HttpRequest), marker=None).AndReturn(
            ([], False))
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn(([], False))
        api.volume_snapshot_list(IsA(http.HttpRequest)). \
                                 AndReturn([])
        self.mox.ReplayAll()

        formData = {'action': 'volume_snapshots__delete__%s' % snapshot.id}
        res = self.client.post(INDEX_URL, formData, follow=True)

        self.assertIn("Scheduled deletion of Volume Snapshot: test snapshot",
                      [m.message for m in res.context['messages']])
Example #19
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)