Пример #1
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)
Пример #2
0
    def test_instance_details_volumes(self):
        server = self.servers.first()
        volumes = deepcopy(self.volumes.list())
        volumes[0].device = "/dev/hdk"
        second_vol = deepcopy(volumes[0])
        second_vol.id = 2
        second_vol.device = "/dev/hdb"
        volumes.append(second_vol)

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.volume_instance_list(IsA(http.HttpRequest),
                               server.id).AndReturn(volumes)
        api.flavor_get(IsA(http.HttpRequest),
                       server.flavor['id']).AndReturn(self.flavors.first())
        api.server_security_groups(IsA(http.HttpRequest),
                       server.id).AndReturn(self.security_groups.first())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances_and_volumes:instances:detail',
                      args=[server.id])
        res = self.client.get(url)
        self.assertItemsEqual(res.context['instance'].volumes, volumes)
        # Test device ordering
        self.assertEquals(res.context['instance'].volumes[0].device,
                          "/dev/hdb")
        self.assertEquals(res.context['instance'].volumes[1].device,
                          "/dev/hdk")
Пример #3
0
    def test_terminate_instance_exception(self):
        formData = {'method': 'TerminateInstance',
                    'instance': self.servers[0].id,
                    }

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.servers[0].id)).AndReturn(self.servers[0])

        exception = api_exceptions.ApiException('ApiException',
                                                message='apiException')
        self.mox.StubOutWithMock(api, 'server_delete')
        api.server_delete(IsA(http.HttpRequest),
                          self.servers[0]).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(unicode))

        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:instances:index'),
                               formData)

        self.assertRedirectsNoFollow(res,
                                     reverse('horizon:nova:instances:index'))

        self.mox.VerifyAll()
Пример #4
0
    def test_instance_details_volumes(self):
        server = self.servers.first()
        volumes = deepcopy(self.volumes.list())
        volumes[0].device = "/dev/hdk"
        second_vol = deepcopy(volumes[0])
        second_vol.id = 2
        second_vol.device = "/dev/hdb"
        volumes.append(second_vol)

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.volume_instance_list(IsA(http.HttpRequest),
                                 server.id).AndReturn(volumes)
        api.flavor_get(IsA(http.HttpRequest),
                       server.flavor['id']).AndReturn(self.flavors.first())
        api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(
            self.security_groups.first())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances_and_volumes:instances:detail',
                      args=[server.id])
        res = self.client.get(url)
        self.assertItemsEqual(res.context['instance'].volumes, volumes)
        # Test device ordering
        self.assertEquals(res.context['instance'].volumes[0].device,
                          "/dev/hdb")
        self.assertEquals(res.context['instance'].volumes[1].device,
                          "/dev/hdk")
Пример #5
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()
Пример #6
0
    def test_terminate_instance_exception(self):
        formData = {
            'method': 'TerminateInstance',
            'instance': self.servers[0].id,
        }

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.servers[0].id)).AndReturn(self.servers[0])

        exception = api_exceptions.ApiException('ApiException',
                                                message='apiException')
        self.mox.StubOutWithMock(api, 'server_delete')
        api.server_delete(IsA(http.HttpRequest),
                          self.servers[0]).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(unicode))

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:nova:instances_and_volumes:instances:index'),
            formData)

        self.assertRedirectsNoFollow(
            res, reverse('horizon:nova:instances_and_volumes:instances:index'))
Пример #7
0
    def test_instance_update_post_api_exception(self):
        INSTANCE_ID = self.servers[0].id
        NAME = 'myname'
        formData = {'method': 'UpdateInstance',
                    'instance': INSTANCE_ID,
                    'name': NAME,
                    'tenant_id': self.TEST_TENANT}

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                           unicode(INSTANCE_ID)).AndReturn(self.servers[0])

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'server_update')
        api.server_update(IsA(http.HttpRequest),
                          str(INSTANCE_ID), NAME).\
                          AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:instances:update',
                                       args=[INSTANCE_ID]),
                               formData)

        self.assertRedirectsNoFollow(res,
                                     reverse('horizon:nova:instances:index'))

        self.mox.VerifyAll()
Пример #8
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)
Пример #9
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)
Пример #10
0
    def test_ajax_loading_instances(self):
        server = self.servers.first()
        flavor = self.flavors.list()[0]
        tenant = self.tenants.list()[0]

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.flavor_get(IsA(http.HttpRequest),
                       server.flavor['id']).AndReturn(flavor)
        api.keystone.tenant_get(IsA(http.HttpRequest),
                                server.tenant_id,
                                admin=True).AndReturn(tenant)
        self.mox.ReplayAll()

        url = reverse('horizon:admin:instances:index') + \
                "?action=row_update&table=instances&obj_id=" + server.id

        res = self.client.get(url, {},
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertTemplateUsed(res, "horizon/common/_data_table_row.html")

        self.assertContains(res, "test_tenant", 1, 200)
        self.assertContains(res, "instance-host", 1, 200)
        self.assertContains(res, "server_1", 1, 200)
        self.assertContains(res, "10.0.0.1", 1, 200)
        self.assertContains(res, "512MB RAM | 1 VCPU | 0 Disk", 1, 200)
        self.assertContains(res, "Active", 1, 200)
        self.assertContains(res, "Running", 1, 200)
Пример #11
0
    def test_instance_update_post_api_exception(self):
        SERVER = self.servers[0]

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

        api.server_get(IsA(http.HttpRequest), unicode(SERVER.id)) \
                      .AndReturn(self.servers[0])
        exception = nova_exceptions.ClientException(500)
        api.server_update(IsA(http.HttpRequest), str(SERVER.id), SERVER.name) \
                          .AndRaise(exception)

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateInstance',
            'instance': SERVER.id,
            'name': SERVER.name,
            'tenant_id': self.TEST_TENANT
        }
        url = reverse('horizon:nova:instances_and_volumes:instances:update',
                      args=[SERVER.id])
        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #12
0
    def test_instance_update_post_api_exception(self):
        INSTANCE_ID = self.servers[0].id
        NAME = 'myname'
        formData = {
            'method': 'UpdateInstance',
            'instance': INSTANCE_ID,
            'name': NAME,
            'tenant_id': self.TEST_TENANT
        }

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       unicode(INSTANCE_ID)).AndReturn(self.servers[0])

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'server_update')
        api.server_update(IsA(http.HttpRequest),
                          str(INSTANCE_ID), NAME).\
                          AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('horizon:nova:instances_and_volumes:instances:update',
                    args=[INSTANCE_ID]), formData)

        self.assertRedirectsNoFollow(
            res, reverse('horizon:nova:instances_and_volumes:instances:index'))
Пример #13
0
    def test_instance_details_metadata(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.volume_instance_list(IsA(http.HttpRequest),
                               server.id).AndReturn([])
        api.flavor_get(IsA(http.HttpRequest),
                       server.flavor['id']).AndReturn(self.flavors.first())
        api.server_security_groups(IsA(http.HttpRequest),
                       server.id).AndReturn(self.security_groups.list())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances:detail',
                      args=[server.id])
        tg = InstanceDetailTabs(self.request, instance=server)
        qs = "?%s=%s" % (tg.param_name, tg.get_tab("overview").get_id())
        res = self.client.get(url + qs)

        self.assertContains(res, "<dd>keyName</dd>", 1)
        self.assertContains(res, "<dt>someMetaLabel</dt>", 1)
        self.assertContains(res, "<dd>someMetaData</dd>", 1)
        self.assertContains(res, "<dt>some&lt;b&gt;html&lt;/b&gt;label</dt>",
                            1)
        self.assertContains(res, "<dd>&lt;!--</dd>", 1)
        self.assertContains(res, "<dt>empty</dt>", 1)
        self.assertContains(res, "<dd><em>N/A</em></dd>", 1)
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
0
    def test_instance_update_get_server_get_exception(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, "server_get")
        api.server_get(IsA(http.HttpRequest), server.id).AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        url = reverse("horizon:nova:instances_and_volumes:instances:update", args=[server.id])
        res = self.client.get(url)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #18
0
    def test_instance_update_get(self):
        server = self.servers.first()

        self.mox.StubOutWithMock(api, "server_get")
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        self.mox.ReplayAll()

        url = reverse("horizon:nova:instances_and_volumes:instances:update", args=[server.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res, "nova/instances_and_volumes/instances/update.html")
Пример #19
0
    def test_create_snapshot_get(self):
        self.mox.StubOutWithMock(api, "server_get")
        api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndReturn(self.good_server)

        self.mox.ReplayAll()

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

        self.assertTemplateUsed(res, "nova/snapshots/create.html")
        self.mox.VerifyAll()
Пример #20
0
    def test_create_snapshot_get_with_invalid_status(self):
        self.mox.StubOutWithMock(api, "server_get")
        api.server_get(IsA(http.HttpRequest), str(self.bad_server.id)).AndReturn(self.bad_server)

        self.mox.ReplayAll()

        res = self.client.get(reverse("horizon:nova:snapshots:create", args=[self.bad_server.id]))

        self.assertRedirectsNoFollow(res, reverse("horizon:nova:instances:index"))
        self.mox.VerifyAll()
Пример #21
0
    def test_create_snapshot_get(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res,
                            'nova/images_and_snapshots/snapshots/create.html')
Пример #22
0
    def test_instance_update_get(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)

        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances:update', args=[server.id])
        res = self.client.get(url)

        self.assertTemplateUsed(res, 'nova/instances/update.html')
Пример #23
0
    def test_create_snapshot_get_with_invalid_status(self):
        server = self.servers.get(status='BUILD')
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.get(url)
        redirect = reverse("horizon:nova:instances_and_volumes:index")
        self.assertRedirectsNoFollow(res, redirect)
Пример #24
0
    def test_instance_update_get_server_get_exception(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id) \
                        .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances_and_volumes:instances:update',
                      args=[server.id])
        res = self.client.get(url)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #25
0
    def test_create_snapshot_get_with_invalid_status(self):
        server = self.servers.get(status='BUILD')
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.get(url)
        redirect = reverse("horizon:nova:instances:index")
        self.assertRedirectsNoFollow(res, redirect)
Пример #26
0
    def test_create_snapshot_get(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        self.mox.ReplayAll()

        url = reverse('horizon:project:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.get(url)
        self.assertTemplateUsed(
            res, 'project/images_and_snapshots/snapshots/create.html')
Пример #27
0
    def test_create_get_server_exception(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id) \
                    .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.get(url)
        redirect = reverse("horizon:nova:instances_and_volumes:index")
        self.assertRedirectsNoFollow(res, redirect)
Пример #28
0
    def test_create_get_server_exception(self):
        self.mox.StubOutWithMock(api, "server_get")
        exception = api_exceptions.ApiException("apiException")
        api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndRaise(exception)

        self.mox.ReplayAll()

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

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

        self.mox.VerifyAll()
Пример #29
0
    def test_create_snapshot_get(self):
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndReturn(self.good_server)

        self.mox.ReplayAll()

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

        self.assertTemplateUsed(res, 'nova/snapshots/create.html')
Пример #30
0
    def test_create_get_server_exception(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id) \
                    .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        url = reverse('horizon:project:images_and_snapshots:snapshots:create',
                      args=[server.id])
        res = self.client.get(url)
        redirect = reverse("horizon:project:instances:index")
        self.assertRedirectsNoFollow(res, redirect)
Пример #31
0
    def test_instance_update_post(self):
        server = self.servers.first()

        self.mox.StubOutWithMock(api, "server_get")
        self.mox.StubOutWithMock(api, "server_update")
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.server_update(IsA(http.HttpRequest), server.id, server.name)
        self.mox.ReplayAll()

        formData = {"method": "UpdateInstance", "instance": server.id, "name": server.name, "tenant_id": self.tenant.id}
        url = reverse("horizon:nova:instances_and_volumes:instances:update", args=[server.id])
        res = self.client.post(url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #32
0
    def test_create_snapshot_get_with_invalid_status(self):
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.bad_server.id)).AndReturn(self.bad_server)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:snapshots:create',
                    args=[self.bad_server.id]))

        self.assertRedirectsNoFollow(res,
                                     reverse('horizon:nova:instances:index'))
Пример #33
0
    def test_instance_update_post_api_exception(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.server_update(IsA(http.HttpRequest), server.id, server.name).AndRaise(self.exceptions.nova)

        self.mox.ReplayAll()

        formData = {"method": "UpdateInstance", "instance": server.id, "name": server.name, "tenant_id": self.tenant.id}
        url = reverse("horizon:project:instances:update", args=[server.id])
        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #34
0
    def test_instance_update_get_server_get_exception(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id) \
                        .AndRaise(self.exceptions.nova)

        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances:update',
                      args=[server.id])
        res = self.client.get(url)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #35
0
    def test_create_get_server_exception(self):
        self.mox.StubOutWithMock(api, 'server_get')
        exception = novaclient_exceptions.ClientException('apiException')
        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndRaise(exception)

        self.mox.ReplayAll()

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

        url = reverse("horizon:nova:instances_and_volumes:index")
        self.assertRedirectsNoFollow(res, url)
Пример #36
0
    def test_instance_update_get(self):
        INSTANCE_ID = self.servers[0].id

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                           unicode(INSTANCE_ID)).AndReturn(self.servers[0])

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:instances:update',
                                      args=[INSTANCE_ID]))

        self.assertTemplateUsed(res,
                'nova/instances/update.html')
Пример #37
0
    def test_instance_update_get(self):
        INSTANCE_ID = self.servers[0].id

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                           unicode(INSTANCE_ID)).AndReturn(self.servers[0])

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:instances:update',
                                      args=[INSTANCE_ID]))

        self.assertTemplateUsed(res,
                'nova/instances/update.html')
Пример #38
0
    def test_create_get_server_exception(self):
        self.mox.StubOutWithMock(api, 'server_get')
        exception = novaclient_exceptions.ClientException('apiException')
        api.server_get(IsA(http.HttpRequest),
                       str(self.good_server.id)).AndRaise(exception)

        self.mox.ReplayAll()

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

        url = reverse("horizon:nova:instances_and_volumes:index")
        self.assertRedirectsNoFollow(res, url)
Пример #39
0
    def test_instance_update_get_server_get_exception(self):
        INSTANCE_ID = self.servers[0].id

        exception = nova_exceptions.ClientException(500)
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       unicode(INSTANCE_ID)).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:instances:update',
                    args=[INSTANCE_ID]))

        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #40
0
    def test_instance_update_get_server_get_exception(self):
        INSTANCE_ID = self.servers[0].id

        exception = nova_exceptions.ClientException(500)
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                           unicode(INSTANCE_ID)).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(
                reverse('horizon:nova:instances_and_volumes:instances:update',
                        args=[INSTANCE_ID]))

        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #41
0
    def test_instance_details_volumes(self):
        server = self.servers.first()
        volumes = [self.volumes.list()[1]]

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.volume_instance_list(IsA(http.HttpRequest), server.id).AndReturn(volumes)
        api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]).AndReturn(self.flavors.first())
        api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(self.security_groups.first())

        self.mox.ReplayAll()

        url = reverse("horizon:project:instances:detail", args=[server.id])
        res = self.client.get(url)

        self.assertItemsEqual(res.context["instance"].volumes, volumes)
Пример #42
0
def detail(request, instance_id):
    tenant_id = request.user.tenant_id
    try:
        instance = api.server_get(request, instance_id)
        volumes = api.volume_instance_list(request, instance_id)
        try:
            console = api.console_create(request, instance_id, 'vnc')
            vnc_url = "%s&title=%s(%s)" % (console.output, instance.name,
                                           instance_id)
        except api_exceptions.ApiException, e:
            LOG.exception(
                _('ApiException while fetching instance vnc \
                           connection'))
            messages.error(
                request,
                _('Unable to get vnc console for instance %(inst)s: %(msg)s') %
                {
                    "inst": instance_id,
                    "msg": e.message
                })
            return shortcuts.redirect(
                'horizon:nova:instances_and_volumes:instances:index')
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException while fetching instance info'))
        messages.error(
            request,
            _('Unable to get information for instance %(inst)s: %(msg)s') % {
                "inst": instance_id,
                "msg": e.message
            })
        return shortcuts.redirect(
            'horizon:nova:instances_and_volumes:instances:index')
Пример #43
0
def detail(request, instance_id):
    tenant_id = request.user.tenant_id
    try:
        instance = api.server_get(request, instance_id)
        volumes = api.volume_instance_list(request, instance_id)
	LOG.debug(("KDS: instance-name: %s instance-ip: %s" %(instance.name, instance.ip)))
        try:
            console = api.console_create(request, instance_id, 'vnc')
            vnc_url = "%s&title=%s(%s)" % (console.output,
                                           instance.name,
                                           instance_id)
        except api_exceptions.ApiException, e:
            LOG.exception(_('ApiException while fetching instance vnc \
                           connection'))
            messages.error(request,
                _('Unable to get vnc console for instance %(inst)s: %(msg)s') %
                {"inst": instance_id, "msg": e.message})
            return shortcuts.redirect(
                          'horizon:nova:instances_and_volumes:instances:index')
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException while fetching instance info'))
        messages.error(request,
            _('Unable to get information for instance %(inst)s: %(msg)s') %
            {"inst": instance_id, "msg": e.message})
        return shortcuts.redirect(
                          'horizon:nova:instances_and_volumes:instances:index')
Пример #44
0
def detail(request, instance_id):
    try:
        instance = api.server_get(request, instance_id)
        try:
            console = api.console_create(request, instance_id, 'vnc')
            vnc_url = "%s&title=%s(%s)" % (console.output, instance.name,
                                           instance_id)
        except api_exceptions.ApiException, e:
            LOG.exception('ApiException while fetching instance vnc \
                           connection')
            messages.error(
                request,
                _('Unable to get vnc console for instance %(inst)s: %(message)s'
                  ) % {
                      "inst": instance_id,
                      "message": e.message
                  })
            return redirect('horizon:syspanel:instances:index', tenant_id)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while fetching instance info')
        messages.error(
            request,
            _('Unable to get information for instance %(inst)s: %(message)s') %
            {
                "inst": instance_id,
                "message": e.message
            })
        return redirect('horizon:syspanel:instances:index', tenant_id)
Пример #45
0
    def get_data(self, request, context, *args, **kwargs):
        instance_id = kwargs["instance_id"]

        if "show" in request.GET:
            show_tab = request.GET["show"]
        else:
            show_tab = "overview"

        try:
            instance = api.server_get(request, instance_id)
            volumes = api.volume_instance_list(request, instance_id)

            # Gather our flavors and images and correlate our instances to
            # them. Exception handling happens in the parent class.
            flavors = api.flavor_list(request)
            full_flavors = SortedDict([(str(flavor.id), flavor) for flavor in flavors])
            instance.full_flavor = full_flavors[instance.flavor["id"]]

            context.update({"instance": instance, "volumes": volumes})
        except:
            redirect = reverse("horizon:nova:instances_and_volumes:index")
            exceptions.handle(
                request, _("Unable to retrieve details for " 'instance "%s".') % instance_id, redirect=redirect
            )
        if show_tab == "vnc":
            try:
                console = api.server_vnc_console(request, instance_id)
                vnc_url = "%s&title=%s(%s)" % (console.url, getattr(instance, "name", ""), instance_id)
                context.update({"vnc_url": vnc_url})
            except:
                exceptions.handle(request, _("Unable to get vnc console for " 'instance "%s".') % instance_id)

        context.update({"show_tab": show_tab})

        return context
Пример #46
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)
Пример #47
0
    def test_instance_update_get_server_get_exception(self):
        INSTANCE_ID = self.servers[0].id

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                           unicode(INSTANCE_ID)).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:instances:update',
                                      args=[INSTANCE_ID]))

        self.assertRedirectsNoFollow(res,
                                     reverse('horizon:nova:instances:index'))

        self.mox.VerifyAll()
Пример #48
0
    def test_instance_update_post(self):
        server = self.servers.first()

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

        formData = {'method': 'UpdateInstance',
                    'instance': server.id,
                    'name': server.name,
                    'tenant_id': self.tenant.id}
        url = reverse('horizon:nova:instances_and_volumes:instances:update',
                      args=[server.id])
        res = self.client.post(url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #49
0
    def test_instance_update_post(self):
        server = self.servers.first()

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.server_update(IsA(http.HttpRequest), server.id, server.name)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateInstance',
                    'instance': server.id,
                    'name': server.name,
                    'tenant_id': self.tenant.id}
        url = reverse('horizon:nova:instances:update',
                      args=[server.id])
        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
Пример #50
0
    def test_instance_vnc(self):
        server = self.servers.first()
        CONSOLE_OUTPUT = '/vncserver'

        console_mock = self.mox.CreateMock(api.VNCConsole)
        console_mock.url = CONSOLE_OUTPUT

        self.mox.StubOutWithMock(api, 'server_vnc_console')
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.server_vnc_console(IgnoreArg(), server.id).AndReturn(console_mock)
        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances:vnc',
                      args=[server.id])
        res = self.client.get(url)
        redirect = CONSOLE_OUTPUT + '&title=%s(1)' % server.name
        self.assertRedirectsNoFollow(res, redirect)
Пример #51
0
    def test_instance_details_volumes(self):
        server = self.servers.first()
        volumes = [self.volumes.list()[1]]

        api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
        api.volume_instance_list(IsA(http.HttpRequest),
                               server.id).AndReturn(volumes)
        api.flavor_get(IsA(http.HttpRequest),
                       server.flavor['id']).AndReturn(self.flavors.first())
        api.server_security_groups(IsA(http.HttpRequest),
                       server.id).AndReturn(self.security_groups.first())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:instances:detail',
                      args=[server.id])
        res = self.client.get(url)

        self.assertItemsEqual(res.context['instance'].volumes, volumes)
Пример #52
0
def vnc(request, instance_id):
    try:
        console = api.server_vnc_console(request, instance_id)
        instance = api.server_get(request, instance_id)
        return shortcuts.redirect(console.url + ("&title=%s(%s)" %
                                                 (instance.name, instance_id)))
    except:
        redirect = reverse("horizon:nova:instances:index")
        msg = _('Unable to get VNC console for instance "%s".') % instance_id
        exceptions.handle(request, msg, redirect=redirect)
    def test_server_get(self):
        server = self.servers.first()

        novaclient = self.stub_novaclient()
        novaclient.servers = self.mox.CreateMockAnything()
        novaclient.servers.get(server.id).AndReturn(server)
        self.mox.ReplayAll()

        ret_val = api.server_get(self.request, server.id)
        self.assertIsInstance(ret_val, api.nova.Server)
Пример #54
0
    def test_terminate_instance(self):
        formData = {'method': 'TerminateInstance',
                    'instance': self.servers[0].id,
                    }

        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.servers[0].id)).AndReturn(self.servers[0])
        self.mox.StubOutWithMock(api, 'server_delete')
        api.server_delete(IsA(http.HttpRequest),
                          self.servers[0])

        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:instances:index'),
                               formData)

        self.assertRedirectsNoFollow(res,
                                     reverse('horizon:nova:instances:index'))
Пример #55
0
 def get_object(self, *args, **kwargs):
     if not hasattr(self, "object"):
         instance_id = self.kwargs['instance_id']
         try:
             self.object = api.server_get(self.request, instance_id)
         except:
             redirect = reverse("horizon:nova:instances:index")
             msg = _('Unable to retrieve instance details.')
             exceptions.handle(self.request, msg, redirect=redirect)
     return self.object
Пример #56
0
 def get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = api.server_get(self.request,
                                           self.kwargs["instance_id"])
         except:
             redirect = reverse('horizon:project:instances:index')
             exceptions.handle(self.request,
                               _("Unable to retrieve instance."),
                               redirect=redirect)
     return self._object
Пример #57
0
    def test_instance_update_post_api_exception(self):
        server = self.servers.first()

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

        formData = {
            'method': 'UpdateInstance',
            'instance': server.id,
            'name': server.name,
            'tenant_id': self.tenant.id
        }
        url = reverse('horizon:nova:instances_and_volumes:instances:update',
                      args=[server.id])
        res = self.client.post(url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)