コード例 #1
0
ファイル: tests.py プロジェクト: StackOps/horizon
    def test_launch_keypairlist_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)).AndReturn(self.flavors.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        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)
コード例 #2
0
ファイル: tests.py プロジェクト: codeoedoc/horizon
    def test_attached_volume(self):
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest)) \
                .AndReturn(self.volumes.list()[1:3])

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
            'nova/instances_and_volumes/index.html')
        instances = res.context['instances_table'].data
        resp_volumes = res.context['volumes_table'].data

        self.assertItemsEqual(instances, self.servers.list())
        self.assertItemsEqual(resp_volumes, self.volumes.list()[1:3])

        self.assertContains(res, ">My Volume<", 1, 200)
        self.assertContains(res, ">30GB<", 1, 200)
        self.assertContains(res, ">3b189ac8-9166-ac7f-90c9-16c8bf9e01ac<",
                            1,
                            200)
        self.assertContains(res, ">10GB<", 1, 200)
        self.assertContains(res, ">In-Use<", 2, 200)
        self.assertContains(res, "on /dev/hda", 1, 200)
        self.assertContains(res, "on /dev/hdk", 1, 200)
コード例 #3
0
ファイル: tests.py プロジェクト: codeoedoc/horizon
    def test_index_flavor_list_exception(self):
        servers = self.servers.list()
        flavors = self.flavors.list()
        volumes = self.volumes.list()
        full_flavors = SortedDict([(f.id, f) for f in flavors])

        api.server_list(IsA(http.HttpRequest)).AndReturn(servers)
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        for server in servers:
            api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \
                                AndReturn(full_flavors[server.flavor["id"]])
        api.volume_list(IsA(http.HttpRequest)).AndReturn(volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
            'nova/instances_and_volumes/index.html')
        instances = res.context['instances_table'].data
        volumes = res.context['volumes_table'].data

        self.assertItemsEqual(instances, self.servers.list())
        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #4
0
ファイル: tests.py プロジェクト: bn-emailops/horizon
    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)
コード例 #5
0
    def test_delete_volume_error_existing_snapshot(self):
        volume = self.volumes.first()
        formData = {'action':
                    'volumes__delete__%s' % volume.id}
        exc = self.exceptions.cinder.__class__(400,
                                               "error: dependent snapshots")

        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.volume_delete(IsA(http.HttpRequest), volume.id). \
                          AndRaise(exc)
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:volumes:index')
        res = self.client.post(url, formData, follow=True)
        self.assertMessageCount(res, error=1)
        self.assertEqual(list(res.context['messages'])[0].message,
                         u'Unable to delete volume "%s". '
                         u'One or more snapshots depend on it.' %
                         volume.display_name)
コード例 #6
0
ファイル: tests.py プロジェクト: kumarcv/openstack-nf
    def test_delete_volume_error_existing_snapshot(self):
        volume = self.volumes.first()
        formData = {'action':
                    'volumes__delete__%s' % volume.id}
        exc = self.exceptions.cinder.__class__(400,
                                               "error: dependent snapshots")

        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.volume_delete(IsA(http.HttpRequest), volume.id). \
                          AndRaise(exc)
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:volumes:index')
        res = self.client.post(url, formData, follow=True)
        self.assertMessageCount(res, error=1)
        self.assertEqual(list(res.context['messages'])[0].message,
                         u'Unable to delete volume "%s". '
                         u'One or more snapshots depend on it.' %
                         volume.display_name)
コード例 #7
0
ファイル: tests.py プロジェクト: codeoedoc/horizon
    def test_index_flavor_get_exception(self):
        servers = self.servers.list()
        flavors = self.flavors.list()
        volumes = self.volumes.list()
        max_id = max([int(flavor.id) for flavor in flavors])
        for server in servers:
            max_id += 1
            server.flavor["id"] = max_id

        api.server_list(IsA(http.HttpRequest)).AndReturn(servers)
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors)
        for server in servers:
            api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \
                                AndRaise(self.exceptions.nova)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        instances = res.context['instances_table'].data
        volumes = res.context['volumes_table'].data

        self.assertTemplateUsed(res,
            'nova/instances_and_volumes/index.html')
        self.assertMessageCount(res, error=len(servers))
        self.assertItemsEqual(instances, self.servers.list())
        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #8
0
ファイル: tests.py プロジェクト: StackOps/horizon
    def test_launch_post(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
        block_device_mapping = {device_name: u"%s::0" % volume_choice}

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

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.volumes.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(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_create(IsA(http.HttpRequest),
                          server.name,
                          image.id,
                          flavor.id,
                          keypair.name,
                          USER_DATA,
                          [sec_group.name],
                          block_device_mapping,
                          instance_count=IsA(int))
        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': 1}
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res,
                 reverse('horizon:nova:instances_and_volumes:index'))
コード例 #9
0
    def test_launch_post(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
        block_device_mapping = {device_name: u"%s::0" % volume_choice}

        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, 'server_create')
        self.mox.StubOutWithMock(api, 'volume_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.server_create(IsA(http.HttpRequest),
                          server.name,
                          image.id,
                          flavor.id,
                          keypair.name,
                          USER_DATA, [sec_group.name],
                          block_device_mapping,
                          instance_count=IsA(int))
        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': 1
        }
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(
            res, reverse('horizon:nova:instances_and_volumes:index'))
コード例 #10
0
ファイル: tests.py プロジェクト: mshabdiz/horizon
    def test_index(self):
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:syspanel:volumes:index'))

        self.assertTemplateUsed(res, 'syspanel/volumes/index.html')
        volumes = res.context['volumes_table'].data

        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #11
0
ファイル: tests.py プロジェクト: hien/horizon
    def test_index(self):
        api.volume_list(IsA(http.HttpRequest), search_opts={"all_tenants": 1}).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        res = self.client.get(reverse("horizon:admin:volumes:index"))

        self.assertTemplateUsed(res, "admin/volumes/index.html")
        volumes = res.context["volumes_table"].data

        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #12
0
ファイル: tests.py プロジェクト: MrRagga-/horizon
    def test_index(self):
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:syspanel:volumes:index'))

        self.assertTemplateUsed(res, 'syspanel/volumes/index.html')
        volumes = res.context['volumes_table'].data

        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #13
0
    def test_launch_post(self):
        FLAVOR_ID = self.flavors[0].id
        IMAGE_ID = '1'
        keypair = self.keypairs[0].name
        SERVER_NAME = 'serverName'
        USER_DATA = 'userData'
        volume = self.volumes[0].id
        device_name = 'vda'
        BLOCK_DEVICE_MAPPING = {device_name: "1:::0"}

        form_data = {'method': 'LaunchForm',
                     'flavor': FLAVOR_ID,
                     'image_id': IMAGE_ID,
                     'keypair': keypair,
                     'name': SERVER_NAME,
                     'user_data': USER_DATA,
                     'count': 1,
                     'tenant_id': self.TEST_TENANT,
                     'security_groups': 'default',
                     'volume': volume,
                     'device_name': device_name
                     }

        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, 'server_create')
        self.mox.StubOutWithMock(api, 'volume_list')

        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)
        api.image_get_meta(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)
        api.server_create(IsA(http.HttpRequest), SERVER_NAME,
                          str(IMAGE_ID), str(FLAVOR_ID),
                          keypair, USER_DATA, [self.security_groups[0].name],
                          BLOCK_DEVICE_MAPPING,
                          instance_count=IsA(int))

        self.mox.ReplayAll()

        res = self.client.post(
                    reverse('horizon:nova:images_and_snapshots:images:launch',
                            args=[IMAGE_ID]),
                            form_data)

        self.assertRedirectsNoFollow(res,
                 reverse('horizon:nova:instances_and_volumes:index'))
コード例 #14
0
    def test_launch_form_keystone_exception(self):
        FLAVOR_ID = self.flavors[0].id
        IMAGE_ID = '1'
        keypair = self.keypairs[0].name
        SERVER_NAME = 'serverName'
        USER_DATA = 'userData'

        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, 'server_create')
        self.mox.StubOutWithMock(api, 'volume_list')

        form_data = {'method': 'LaunchForm',
                     'flavor': FLAVOR_ID,
                     'image_id': IMAGE_ID,
                     'keypair': keypair,
                     'name': SERVER_NAME,
                     'tenant_id': self.TEST_TENANT,
                     'user_data': USER_DATA,
                     'count': int(1),
                     'security_groups': 'default'}

        api.flavor_list(IgnoreArg()).AndReturn(self.flavors)
        api.keypair_list(IgnoreArg()).AndReturn(self.keypairs)
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)
        api.image_get_meta(IgnoreArg(),
                      IMAGE_ID).AndReturn(self.visibleImage)
        api.volume_list(IgnoreArg()).AndReturn(self.volumes)

        exception = keystone_exceptions.ClientException('Failed')
        api.server_create(IsA(http.HttpRequest),
                          SERVER_NAME,
                          IMAGE_ID,
                          str(FLAVOR_ID),
                          keypair,
                          USER_DATA,
                          [group.name for group in self.security_groups],
                          None,
                          instance_count=IsA(int)).AndRaise(exception)

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

        self.mox.ReplayAll()
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[IMAGE_ID])
        res = self.client.post(url, form_data)

        self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
コード例 #15
0
ファイル: tests.py プロジェクト: codeoedoc/horizon
    def test_index_server_list_exception(self):
        api.server_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        res = self.client.get(
                reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
                'nova/instances_and_volumes/index.html')
        self.assertEqual(len(res.context['instances_table'].data), 0)
コード例 #16
0
ファイル: tests.py プロジェクト: liangxiaobi/chinahorizon
    def test_index(self):
        api.volume_list(IsA(http.HttpRequest), search_opts={
            'all_tenants': 1
        }).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:admin:volumes:index'))

        self.assertTemplateUsed(res, 'admin/volumes/index.html')
        volumes = res.context['volumes_table'].data

        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #17
0
ファイル: tests.py プロジェクト: ehazlett/horizon
    def test_index(self):
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
            'nova/instances_and_volumes/index.html')
        self.assertItemsEqual(res.context['instances'], self.servers)
コード例 #18
0
ファイル: tests.py プロジェクト: bn-emailops/horizon
    def test_pause_instance(self):
        server = self.servers.first()

        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_pause(IsA(http.HttpRequest), server.id)

        self.mox.ReplayAll()

        formData = {'action': 'instances__pause__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #19
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res, 'nova/instances_and_volumes/index.html')
        instances = res.context['instances_table'].data
        self.assertItemsEqual(instances, self.servers)
コード例 #20
0
    def test_index_server_list_exception(self):
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        exception = novaclient_exceptions.ClientException('apiException')
        api.server_list(IsA(http.HttpRequest)).AndRaise(exception)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res, 'nova/instances_and_volumes/index.html')
        self.assertEqual(len(res.context['instances_table'].data), 0)
コード例 #21
0
ファイル: tests.py プロジェクト: StackOps/horizon
    def test_launch_form_keystone_exception(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'userData'

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

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.volumes.list())
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
        api.keypair_list(IgnoreArg()).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get(IgnoreArg(), image.id).AndReturn(image)
        api.volume_list(IgnoreArg()).AndReturn(self.volumes.list())
        api.server_create(IsA(http.HttpRequest),
                          server.name,
                          image.id,
                          flavor.id,
                          keypair.name,
                          USER_DATA,
                          [sec_group.name],
                          None,
                          instance_count=IsA(int)) \
                      .AndRaise(self.exceptions.keystone)
        self.mox.ReplayAll()

        form_data = {'method': 'LaunchForm',
                     'flavor': flavor.id,
                     'image_id': image.id,
                     'keypair': keypair.name,
                     'name': server.name,
                     'tenant_id': self.tenant.id,
                     'user_data': USER_DATA,
                     'count': 1,
                     'security_groups': sec_group.name}
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
コード例 #22
0
ファイル: tests.py プロジェクト: haluomao/horizon
    def test_pause_instance_exception(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, "volume_list")
        self.mox.StubOutWithMock(api, "server_pause")
        self.mox.StubOutWithMock(api, "server_list")
        self.mox.StubOutWithMock(api, "flavor_list")
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_pause(IsA(http.HttpRequest), server.id).AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {"action": "instances__pause__%s" % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #23
0
ファイル: tests.py プロジェクト: pplu/horizon
    def test_index_server_list_exception(self):
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        exception = api_exceptions.ApiException('apiException')
        api.server_list(IsA(http.HttpRequest)).AndRaise(exception)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

        self.mox.ReplayAll()

        res = self.client.get(
                reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
                'nova/instances_and_volumes/index.html')
        self.assertEqual(len(res.context['instances_table'].data), 0)
コード例 #24
0
ファイル: tests.py プロジェクト: hagix9/horizon
    def test_terminate_instance(self):
        server = self.servers.first()
        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.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
        api.server_delete(IsA(http.HttpRequest), server.id)
        self.mox.ReplayAll()

        formData = {'action': 'instances__terminate__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #25
0
    def test_pause_instance(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_pause')
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_pause(IsA(http.HttpRequest), server.id)
        self.mox.ReplayAll()

        formData = {'action': 'instances__pause__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #26
0
ファイル: tests.py プロジェクト: haluomao/horizon
    def test_suspend_instance(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, "server_suspend")
        self.mox.StubOutWithMock(api, "server_list")
        self.mox.StubOutWithMock(api, "volume_list")
        self.mox.StubOutWithMock(api, "flavor_list")
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_suspend(IsA(http.HttpRequest), unicode(server.id))
        self.mox.ReplayAll()

        formData = {"action": "instances__suspend__%s" % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #27
0
ファイル: tests.py プロジェクト: bn-emailops/horizon
    def test_resume_instance(self):
        server = self.servers.first()
        server.status = "SUSPENDED"

        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_resume(IsA(http.HttpRequest), unicode(server.id))

        self.mox.ReplayAll()

        formData = {'action': 'instances__suspend__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #28
0
ファイル: views.py プロジェクト: jeffreycoho/horizon
    def get_volumes_data(self):
        # Gather our volumes
        try:
            volumes = api.volume_list(self.request)
            instances = SortedDict([(inst.id, inst) for inst in
                                    self._get_instances()])
            for volume in volumes:
                # Truncate the description for proper display.
                if len(getattr(volume, 'display_description', '')) > 33:
                    truncated_string = volume.display_description[:30].strip()
                    # Remove non-word, and underscore characters, from the end
                    # of the string before we add the ellepsis.
                    truncated_string = re.sub(ur'[^\w\s]+$',
                                              '',
                                              truncated_string)

                    volume.display_description = truncated_string + u'...'

                for att in volume.attachments:
                    server_id = att.get('server_id', None)
                    att['instance'] = instances.get(server_id, None)
        except:
            volumes = []
            exceptions.handle(self.request,
                              _('Unable to retrieve volume list.'))
        return volumes
コード例 #29
0
    def get_volumes_data(self):
        # Gather our volumes
        try:
            volumes = api.volume_list(self.request)
            instances = SortedDict([(inst.id, inst)
                                    for inst in self._get_instances()])
            for volume in volumes:
                # Truncate the description for proper display.
                if len(getattr(volume, 'display_description', '')) > 33:
                    truncated_string = volume.display_description[:30].strip()
                    # Remove non-word, and underscore characters, from the end
                    # of the string before we add the ellepsis.
                    truncated_string = re.sub(ur'[^\w\s]+$', '',
                                              truncated_string)

                    volume.display_description = truncated_string + u'...'

                for att in volume.attachments:
                    server_id = att.get('server_id', None)
                    att['instance'] = instances.get(server_id, None)
        except:
            volumes = []
            exceptions.handle(self.request,
                              _('Unable to retrieve volume list.'))
        return volumes
コード例 #30
0
ファイル: views.py プロジェクト: colinmcnamara/horizon
    def get_data(self):
        # Gather our volumes
        try:
            volumes = api.volume_list(self.request)
        except:
            volumes = []
            exceptions.handle(self.request,
                              _('Unable to retrieve volume list.'))
        try:
            instance_list = api.server_list(self.request)
        except:
            instance_list = []
            exceptions.handle(self.request,
                              _("Unable to retrieve volume/instance "
                                "attachment information"))

        instances = SortedDict([(inst.id, inst) for inst in instance_list])
        for volume in volumes:
            # It is possible to create a volume with no name through the
            # EC2 API, use the ID in those cases.
            if not volume.display_name:
                volume.display_name = volume.id

            for att in volume.attachments:
                server_id = att.get('server_id', None)
                att['instance'] = instances.get(server_id, None)
        return volumes
コード例 #31
0
ファイル: tests.py プロジェクト: hagix9/horizon
    def test_suspend_instance_exception(self):
        server = self.servers.first()
        self.mox.StubOutWithMock(api, 'server_suspend')
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_suspend(IsA(http.HttpRequest),
                          unicode(server.id)).AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'action': 'instances__suspend__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #32
0
    def test_terminate_instance_exception(self):
        server = self.servers.first()
        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.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
        api.server_delete(IsA(http.HttpRequest), server.id) \
                          .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'action': 'instances__terminate__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #33
0
    def get_data(self):
        # Gather our volumes
        try:
            volumes = api.volume_list(self.request)
        except:
            volumes = []
            exceptions.handle(self.request,
                              _('Unable to retrieve volume list.'))
        try:
            instance_list = api.server_list(self.request)
        except:
            instance_list = []
            exceptions.handle(
                self.request,
                _("Unable to retrieve volume/instance "
                  "attachment information"))

        instances = SortedDict([(inst.id, inst) for inst in instance_list])
        for volume in volumes:
            # It is possible to create a volume with no name through the
            # EC2 API, use the ID in those cases.
            if not volume.display_name:
                volume.display_name = volume.id

            for att in volume.attachments:
                server_id = att.get('server_id', None)
                att['instance'] = instances.get(server_id, None)
        return volumes
コード例 #34
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)
コード例 #35
0
ファイル: tests.py プロジェクト: kitshinghk/horizon
    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)
コード例 #36
0
    def test_launch_form_keystone_exception(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'userData'

        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, 'server_create')
        self.mox.StubOutWithMock(api, 'volume_list')

        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
        api.keypair_list(IgnoreArg()).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get_meta(IgnoreArg(), image.id).AndReturn(image)
        api.volume_list(IgnoreArg()).AndReturn(self.volumes.list())
        exc = keystone_exceptions.ClientException('Failed')
        api.server_create(IsA(http.HttpRequest),
                          server.name,
                          image.id,
                          flavor.id,
                          keypair.name,
                          USER_DATA, [sec_group.name],
                          None,
                          instance_count=IsA(int)).AndRaise(exc)
        self.mox.ReplayAll()

        form_data = {
            'method': 'LaunchForm',
            'flavor': flavor.id,
            'image_id': image.id,
            'keypair': keypair.name,
            'name': server.name,
            'tenant_id': self.tenant.id,
            'user_data': USER_DATA,
            'count': 1,
            'security_groups': sec_group.name
        }
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
コード例 #37
0
    def test_resume_instance_exception(self):
        server = self.servers.first()
        server.status = "SUSPENDED"
        self.mox.StubOutWithMock(api, 'server_resume')
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.server_resume(IsA(http.HttpRequest),
                          unicode(server.id)).AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'action': 'instances__suspend__%s' % server.id}
        res = self.client.post(INDEX_URL, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
コード例 #38
0
ファイル: tests.py プロジェクト: liangxiaobi/chinahorizon
    def test_delete_volume(self):
        volume = self.volumes.first()
        formData = {'action': 'volumes__delete__%s' % volume.id}

        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.volume_delete(IsA(http.HttpRequest), volume.id)
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:index')
        res = self.client.post(url, formData, follow=True)
        self.assertMessageCount(res, count=0)
コード例 #39
0
 def get_volumes_data(self):
     # Gather our volumes
     try:
         volumes = api.volume_list(self.request)
     except novaclient_exceptions.ClientException, e:
         volumes = []
         LOG.exception("ClientException in volume index")
         messages.error(self.request, _('Unable to fetch volumes: %s') % e)
コード例 #40
0
ファイル: views.py プロジェクト: nimbis/horizon
 def get_volumes_data(self):
     # Gather our volumes
     try:
         volumes = api.volume_list(self.request)
     except novaclient_exceptions.ClientException, e:
         volumes = []
         LOG.exception("ClientException in volume index")
         messages.error(self.request, _("Unable to fetch volumes: %s") % e)
コード例 #41
0
ファイル: tests.py プロジェクト: codeoedoc/horizon
    def test_index(self):
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
            'nova/instances_and_volumes/index.html')
        instances = res.context['instances_table'].data
        volumes = res.context['volumes_table'].data

        self.assertItemsEqual(instances, self.servers.list())
        self.assertItemsEqual(volumes, self.volumes.list())
コード例 #42
0
ファイル: tests.py プロジェクト: kumarcv/openstack-nf
    def test_delete_volume(self):
        volume = self.volumes.first()
        formData = {'action':
                    'volumes__delete__%s' % volume.id}

        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.volume_delete(IsA(http.HttpRequest), volume.id)
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest), search_opts=None).\
                                 AndReturn(self.volumes.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())

        self.mox.ReplayAll()

        url = reverse('horizon:nova:volumes:index')
        res = self.client.post(url, formData, follow=True)
        self.assertMessageCount(res, count=0)
コード例 #43
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 sortable">'
            'Snapshotting</td>', 1)
コード例 #44
0
ファイル: tests.py プロジェクト: AsylumCorp/horizon
    def test_attached_volume(self):
        volumes = deepcopy(self.volumes.list())
        attached_volume = deepcopy(self.volumes.list()[0])
        attached_volume.id = "2"
        attached_volume.display_name = "Volume2 name"
        attached_volume.size = "80"
        attached_volume.status = "in-use"
        attached_volume.attachments = [{"server_id": "1",
                                        "device": "/dev/hdn"}]
        volumes.append(attached_volume)

        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
            'nova/instances_and_volumes/index.html')
        instances = res.context['instances_table'].data
        resp_volumes = res.context['volumes_table'].data

        self.assertItemsEqual(instances, self.servers.list())
        self.assertItemsEqual(resp_volumes, volumes)

        self.assertContains(res, ">Volume name<", 1, 200)
        self.assertContains(res, ">40 GB<", 1, 200)
        self.assertContains(res, ">Available<", 1, 200)

        self.assertContains(res, ">Volume2 name<", 1, 200)
        self.assertContains(res, ">80 GB<", 1, 200)
        self.assertContains(res, ">In-Use<", 1, 200)
        self.assertContains(res,
                            ">Instance server_1 (1)</a>&nbsp;on /dev/hdn",
                            1, 200)
コード例 #45
0
    def test_attached_volume(self):
        volumes = deepcopy(self.volumes.list())
        attached_volume = deepcopy(self.volumes.list()[0])
        attached_volume.id = "2"
        attached_volume.display_name = "Volume2 name"
        attached_volume.size = "80"
        attached_volume.status = "in-use"
        attached_volume.attachments = [{
            "server_id": "1",
            "device": "/dev/hdn"
        }]
        volumes.append(attached_volume)

        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
        api.volume_list(IsA(http.HttpRequest)).AndReturn(volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:instances_and_volumes:index'))

        self.assertTemplateUsed(res, 'nova/instances_and_volumes/index.html')
        instances = res.context['instances_table'].data
        resp_volumes = res.context['volumes_table'].data

        self.assertItemsEqual(instances, self.servers.list())
        self.assertItemsEqual(resp_volumes, volumes)

        self.assertContains(res, ">Volume name<", 1, 200)
        self.assertContains(res, ">40GB<", 1, 200)
        self.assertContains(res, ">Available<", 1, 200)

        self.assertContains(res, ">Volume2 name<", 1, 200)
        self.assertContains(res, ">80GB<", 1, 200)
        self.assertContains(res, ">In-Use<", 1, 200)
        self.assertContains(res, ">server_1<", 2, 200)
        self.assertContains(res, "on /dev/hdn", 1, 200)
コード例 #46
0
ファイル: views.py プロジェクト: OpenStack-Kha/horizon
 def volume_list(self):
     try:
         volumes = [v for v in api.volume_list(self.request) \
                 if v.status == api.VOLUME_STATE_AVAILABLE]
         volume_sel = [(v.id, ("%s (%s GB)" % (v.displayName, v.size))) \
                 for v in volumes]
         volume_sel.insert(0, ("", "Select Volume"))
     except:
         exceptions.handle(self.request,
                           _('Unable to retrieve list of volumes'))
         volume_sel = []
     return volume_sel
コード例 #47
0
ファイル: views.py プロジェクト: OpenStack-Kha/horizon
 def volume_list(self):
     try:
         volumes = [v for v in api.volume_list(self.request) \
                 if v.status == api.VOLUME_STATE_AVAILABLE]
         volume_sel = [(v.id, ("%s (%s GB)" % (v.displayName, v.size))) \
                 for v in volumes]
         volume_sel.insert(0, ("", "Select Volume"))
     except:
         exceptions.handle(self.request,
                           _('Unable to retrieve list of volumes'))
         volume_sel = []
     return volume_sel
コード例 #48
0
 def get_volumes_data(self):
     # Gather our volumes
     try:
         volumes = api.volume_list(self.request)
         instances = SortedDict([(inst.id, inst) for inst in
                                 self._get_instances()])
         for volume in volumes:
             for att in volume.attachments:
                 att['instance'] = instances[att['server_id']]
     except novaclient_exceptions.ClientException, e:
         volumes = []
         LOG.exception("ClientException in volume index")
         messages.error(self.request, _('Unable to fetch volumes: %s') % e)
コード例 #49
0
def index(request):
    delete_form, handled = DeleteForm.maybe_handle(request)
    detach_form, handled = DetachForm.maybe_handle(request)

    if handled:
        return handled

    create_form = CreateForm()

    try:
        volumes = api.volume_list(request)
    except novaclient_exceptions.ClientException, e:
        volumes = []
        LOG.exception("ClientException in volume index")
        messages.error(request, _('Error fetching volumes: %s') % e.message)
コード例 #50
0
ファイル: views.py プロジェクト: ehazlett/horizon
def index(request):
    for f in (TerminateInstance, RebootInstance, DeleteForm, DetachForm):
        form, handled = f.maybe_handle(request)
        if handled:
            return handled

    # Gather our instances
    try:
        instances = api.server_list(request)
    except api_exceptions.ApiException as e:
        instances = []
        LOG.exception(_('Exception in instance index'))
        messages.error(request, _('Unable to fetch instances: %s') % e.message)

    # Gather our volumes
    try:
        volumes = api.volume_list(request)
    except novaclient_exceptions.ClientException, e:
        volumes = []
        LOG.exception("ClientException in volume index")
        messages.error(request, _('Unable to fetch volumes: %s') % e.message)
コード例 #51
0
ファイル: views.py プロジェクト: jtopjian/horizon-2012.1.3
    def volume_list(self):
        volume_options = [("", _("Select Volume"))]

        def _get_volume_select_item(volume):
            if hasattr(volume, "volume_id"):
                vol_type = "snap"
                visible_label = _("Snapshot")
            else:
                vol_type = "vol"
                visible_label = _("Volume")
            return (("%s:%s" % (volume.id, vol_type)),
                    ("%s - %s GB (%s)" % (volume.display_name,
                                         volume.size,
                                         visible_label)))

        # First add volumes to the list
        try:
            volumes = [v for v in api.volume_list(self.request) \
                       if v.status == api.VOLUME_STATE_AVAILABLE]
            volume_options.extend(
                    [_get_volume_select_item(vol) for vol in volumes])
        except:
            exceptions.handle(self.request,
                              _('Unable to retrieve list of volumes'))

        # Next add volume snapshots to the list
        try:
            snapshots = api.volume_snapshot_list(self.request)
            snapshots = [s for s in snapshots \
                         if s.status == api.VOLUME_STATE_AVAILABLE]
            volume_options.extend(
                    [_get_volume_select_item(snap) for snap in snapshots])
        except:
            exceptions.handle(self.request,
                              _('Unable to retrieve list of volumes'))

        return volume_options
コード例 #52
0
ファイル: views.py プロジェクト: zhang-hua/horizon
 def _get_volumes(self, search_opts=None):
     try:
         return api.volume_list(self.request, search_opts=search_opts)
     except:
         exceptions.handle(self.request,
                           _('Unable to retrieve volume list.'))