Exemplo n.º 1
0
    def test_create_snapshot_post(self):
        SNAPSHOT_NAME = 'snappy'

        new_snapshot = self.mox.CreateMock(api.Image)
        new_snapshot.name = SNAPSHOT_NAME

        formData = {'method': 'CreateSnapshot',
                    'tenant_id': self.TEST_TENANT,
                    'instance_id': self.good_server.id,
                    'name': SNAPSHOT_NAME}

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')

        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)
        api.snapshot_create(IsA(http.HttpRequest),
                            str(self.good_server.id), SNAPSHOT_NAME).\
                            AndReturn(new_snapshot)
        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)

        self.mox.ReplayAll()

        res = self.client.post(
                reverse('horizon:nova:images_and_snapshots:snapshots:create',
                        args=[self.good_server.id]),
                        formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 2
0
    def test_create_snapshot_post(self):
        SNAPSHOT_NAME = 'snappy'

        new_snapshot = self.mox.CreateMock(api.Image)
        new_snapshot.name = SNAPSHOT_NAME

        formData = {
            'method': 'CreateSnapshot',
            'tenant_id': self.TEST_TENANT,
            'instance_id': self.good_server.id,
            'name': SNAPSHOT_NAME
        }

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')

        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)
        api.snapshot_create(IsA(http.HttpRequest),
                            str(self.good_server.id), SNAPSHOT_NAME).\
                            AndReturn(new_snapshot)
        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:nova:images_and_snapshots:snapshots:create',
                    args=[self.good_server.id]), formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 3
0
    def test_create_snapshot_post_exception(self):
        SNAPSHOT_NAME = 'snappy'

        new_snapshot = self.mox.CreateMock(api.Image)
        new_snapshot.name = SNAPSHOT_NAME

        formData = {
            'method': 'CreateSnapshot',
            'tenant_id': self.TEST_TENANT,
            'instance_id': self.good_server.id,
            'name': SNAPSHOT_NAME
        }

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')

        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)
        exception = novaclient_exceptions.ClientException(
            'apiException', message='apiException')
        api.snapshot_create(IsA(http.HttpRequest),
                            str(self.good_server.id), SNAPSHOT_NAME).\
                            AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:nova:images_and_snapshots:snapshots:create',
                    args=[self.good_server.id]), formData)

        url = reverse("horizon:nova:instances_and_volumes:index")
        self.assertRedirectsNoFollow(res, url)
Exemplo n.º 4
0
    def test_create_snapshot_post(self):
        SNAPSHOT_NAME = "snappy"

        new_snapshot = self.mox.CreateMock(api.Image)
        new_snapshot.name = SNAPSHOT_NAME

        formData = {
            "method": "CreateSnapshot",
            "tenant_id": self.TEST_TENANT,
            "instance_id": self.good_server.id,
            "name": SNAPSHOT_NAME,
        }

        self.mox.StubOutWithMock(api, "server_get")
        api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndReturn(self.good_server)

        self.mox.StubOutWithMock(api, "snapshot_create")
        api.snapshot_create(IsA(http.HttpRequest), str(self.good_server.id), SNAPSHOT_NAME).AndReturn(new_snapshot)

        self.mox.ReplayAll()

        res = self.client.post(reverse("horizon:nova:snapshots:create", args=[self.good_server.id]), formData)

        self.assertRedirectsNoFollow(res, reverse("horizon:nova:snapshots:index"))

        self.mox.VerifyAll()
Exemplo n.º 5
0
    def test_create_instance_snapshot(self):
        server = self.servers.first()
        snapshot_server = deepcopy(server)
        setattr(snapshot_server, 'OS-EXT-STS:task_state',
                "IMAGE_SNAPSHOT")

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest),
                            server.id,
                            "snapshot1")
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        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([])
        api.server_list(IsA(http.HttpRequest)).AndReturn([snapshot_server])
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())

        self.mox.ReplayAll()

        formData = {'instance_id': server.id,
                    'method': 'CreateSnapshot',
                    'tenant_id': server.tenant_id,
                    'name': 'snapshot1'}
        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        redir_url = reverse('horizon:nova:images_and_snapshots:index')
        res = self.client.post(url, formData)
        self.assertRedirects(res, redir_url)

        res = self.client.get(INDEX_URL)
        self.assertContains(res, '<td class="status_unknown sortable">'
                                 'Snapshotting</td>', 1)
Exemplo n.º 6
0
    def test_create_snapshot_post_exception(self):
        SNAPSHOT_NAME = 'snappy'

        new_snapshot = self.mox.CreateMock(api.Image)
        new_snapshot.name = SNAPSHOT_NAME

        formData = {'method': 'CreateSnapshot',
                    'tenant_id': self.TEST_TENANT,
                    'instance_id': self.good_server.id,
                    'name': SNAPSHOT_NAME}

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')

        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)
        exception = novaclient_exceptions.ClientException('apiException',
                                                message='apiException')
        api.snapshot_create(IsA(http.HttpRequest),
                            str(self.good_server.id), SNAPSHOT_NAME).\
                            AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(
                reverse('horizon:nova:images_and_snapshots:snapshots:create',
                        args=[self.good_server.id]),
                        formData)

        url = reverse("horizon:nova:instances_and_volumes:index")
        self.assertRedirectsNoFollow(res, url)
Exemplo n.º 7
0
    def test_create_instance_snapshot(self):
        server = self.servers.first()
        snapshot_server = deepcopy(server)
        setattr(snapshot_server, 'OS-EXT-STS:task_state',
                "IMAGE_SNAPSHOT")

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest),
                            server.id,
                            "snapshot1")
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        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([])
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn([snapshot_server])
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())

        self.mox.ReplayAll()

        formData = {'instance_id': server.id,
                    'method': 'CreateSnapshot',
                    'tenant_id': server.tenant_id,
                    'name': 'snapshot1'}
        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        redir_url = reverse('horizon:nova:images_and_snapshots:index')
        res = self.client.post(url, formData)
        self.assertRedirects(res, redir_url)

        res = self.client.get(INDEX_URL)
        self.assertContains(res, '<td class="status_unknown sortable">'
                                 'Snapshotting</td>', 1)
Exemplo n.º 8
0
 def handle(self, request, data):
     try:
         api.snapshot_create(request, data["instance_id"], data["name"])
         # NOTE(gabriel): This API call is only to display a pretty name.
         instance = api.server_get(request, data["instance_id"])
         vals = {"name": data["name"], "inst": instance.name}
         messages.success(request, _('Snapshot "%(name)s" created for ' 'instance "%(inst)s"') % vals)
         return shortcuts.redirect("horizon:nova:images_and_snapshots:" "index")
     except:
         redirect = reverse("horizon:nova:instances_and_volumes:index")
         exceptions.handle(request, _("Unable to create snapshot."), redirect=redirect)
Exemplo n.º 9
0
 def handle(self, request, data):
     try:
         api.snapshot_create(request, data['instance_id'], data['name'])
         # NOTE(gabriel): This API call is only to display a pretty name.
         instance = api.server_get(request, data['instance_id'])
         vals = {"name": data['name'], "inst": instance.name}
         messages.success(request, _('Snapshot "%(name)s" created for '
                                     'instance "%(inst)s"') % vals)
         return shortcuts.redirect('horizon:nova:images_and_snapshots:'
                                   'index')
     except:
         redirect = reverse("horizon:nova:instances_and_volumes:index")
         exceptions.handle(request,
                           _('Unable to create snapshot.'),
                           redirect=redirect)
Exemplo n.º 10
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)
Exemplo n.º 11
0
    def test_create_snapshot_post_exception(self):
        server = self.servers.first()
        snapshot = self.snapshots.first()

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')
        api.snapshot_create(IsA(http.HttpRequest), server.id, snapshot.name) \
                            .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'method': 'CreateSnapshot',
                    'tenant_id': self.tenant.id,
                    'instance_id': server.id,
                    'name': snapshot.name}
        url = reverse('horizon:project:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.post(url, formData)
        redirect = reverse("horizon:project:instances:index")
        self.assertRedirectsNoFollow(res, redirect)
Exemplo n.º 12
0
    def test_create_snapshot_post(self):
        server = self.servers.first()
        snapshot = self.snapshots.first()

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest), server.id, snapshot.name) \
                            .AndReturn(snapshot)
        self.mox.ReplayAll()

        formData = {'method': 'CreateSnapshot',
                    'tenant_id': self.tenant.id,
                    'instance_id': server.id,
                    'name': snapshot.name}
        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 13
0
    def test_create_snapshot_post_exception(self):
        server = self.servers.first()
        snapshot = self.snapshots.first()

        self.mox.StubOutWithMock(api, 'server_get')
        self.mox.StubOutWithMock(api, 'snapshot_create')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest), server.id, snapshot.name) \
                            .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'method': 'CreateSnapshot',
                    'tenant_id': self.tenant.id,
                    'instance_id': server.id,
                    'name': snapshot.name}
        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.post(url, formData)
        redirect = reverse("horizon:nova:instances:index")
        self.assertRedirectsNoFollow(res, redirect)
Exemplo n.º 14
0
    def test_create_instance_snapshot(self):
        server = self.servers.first()
        snapshot_server = deepcopy(server)
        setattr(snapshot_server, "OS-EXT-STS:task_state", "IMAGE_SNAPSHOT")
        self.mox.StubOutWithMock(api, "server_get")
        self.mox.StubOutWithMock(api, "snapshot_create")
        self.mox.StubOutWithMock(api, "snapshot_list_detailed")
        self.mox.StubOutWithMock(api, "image_list_detailed")
        self.mox.StubOutWithMock(api, "volume_snapshot_list")
        self.mox.StubOutWithMock(api, "server_list")
        self.mox.StubOutWithMock(api, "flavor_list")
        self.mox.StubOutWithMock(api, "server_delete")
        self.mox.StubOutWithMock(api, "volume_list")
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.snapshot_create(IsA(http.HttpRequest), server.id, "snapshot1")
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        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([])

        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn([snapshot_server])
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
        self.mox.ReplayAll()

        formData = {
            "instance_id": server.id,
            "method": "CreateSnapshot",
            "tenant_id": server.tenant_id,
            "name": "snapshot1",
        }
        url = reverse("horizon:nova:images_and_snapshots:snapshots:create", args=[server.id])
        redir_url = reverse("horizon:nova:images_and_snapshots:index")
        res = self.client.post(url, formData)
        self.assertRedirects(res, redir_url)
        res = self.client.get(INDEX_URL)
        self.assertContains(res, '<td  class="status_unknown">' "Snapshotting</td>", 1)
Exemplo n.º 15
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:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        redir_url = reverse('horizon:nova:images_and_snapshots:index')
        res = self.client.post(url, formData)
        self.assertRedirects(res, redir_url)
Exemplo n.º 16
0
 def handle(self, request, data):
     try:
         snapshot = api.snapshot_create(request,
                                        data['instance_id'],
                                        data['name'])
         # NOTE(gabriel): This API call is only to display a pretty name.
         instance = api.server_get(request, data['instance_id'])
         vals = {"name": data['name'], "inst": instance.name}
         messages.success(request, _('Snapshot "%(name)s" created for '
                                     'instance "%(inst)s"') % vals)
         return snapshot
     except:
         redirect = reverse("horizon:project:instances:index")
         exceptions.handle(request,
                           _('Unable to create snapshot.'),
                           redirect=redirect)
Exemplo n.º 17
0
    def handle(self, request, data):
        try:
            LOG.info('Creating snapshot "%s"' % data['name'])
            snapshot = api.snapshot_create(request,
                    data['instance_id'],
                    data['name'])
            instance = api.server_get(request, data['instance_id'])

            messages.info(request,
                     _('Snapshot "%(name)s" created for instance "%(inst)s"') %
                    {"name": data['name'], "inst": instance.name})
            return shortcuts.redirect('horizon:nova:images_and_snapshots:snapshots:index')
        except api_exceptions.ApiException, e:
            msg = _('Error Creating Snapshot: %s') % e.message
            LOG.exception(msg)
            messages.error(request, msg)
            return shortcuts.redirect(request.build_absolute_uri())