File: storage.py

package info (click to toggle)
openstack-trove 2014.1.3-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,752 kB
  • ctags: 6,663
  • sloc: python: 37,317; xml: 1,485; sh: 281; makefile: 49
file content (115 lines) | stat: -rw-r--r-- 5,016 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#    Copyright 2011 OpenStack Foundation
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.


from nose.plugins.skip import SkipTest

from proboscis import before_class
from proboscis import test
from proboscis import asserts

from trove import tests
from trove.tests.api.instances import CheckInstance
from trove.tests.api.instances import instance_info
from trove.tests.util import test_config
from trove.tests.util import create_dbaas_client
from trove.tests.util.users import Requirements

FAKE_MODE = test_config.values['fake_mode']
GROUP = "dbaas.api.mgmt.storage"


@test(groups=[tests.DBAAS_API, GROUP, tests.PRE_INSTANCES],
      depends_on_groups=["services.initialize"])
class StorageBeforeInstanceCreation(object):

    @before_class
    def setUp(self):
        self.user = test_config.users.find_user(Requirements(is_admin=True))
        self.client = create_dbaas_client(self.user)

    @test
    def test_storage_on_host(self):
        if not FAKE_MODE:
            raise SkipTest("Volume driver currently not working.")
        storage = self.client.storage.index()
        print("storage : %r" % storage)
        for device in storage:
            asserts.assert_true(hasattr(device, 'name'),
                                "device.name: %r" % device.name)
            asserts.assert_true(hasattr(device, 'type'),
                                "device.type: %r" % device.name)
            asserts.assert_true(hasattr(device, 'used'),
                                "device.used: %r" % device.used)

            asserts.assert_true(hasattr(device, 'provision'),
                                "device.provision: %r" % device.provision)
            provision = device.provision
            asserts.assert_true('available' in provision,
                                "provision.available: "
                                + "%r" % provision['available'])
            asserts.assert_true('percent' in provision,
                                "provision.percent: %r" % provision['percent'])
            asserts.assert_true('total' in provision,
                                "provision.total: %r" % provision['total'])

            asserts.assert_true(hasattr(device, 'capacity'),
                                "device.capacity: %r" % device.capacity)
            capacity = device.capacity
            asserts.assert_true('available' in capacity,
                                "capacity.available: "
                                + "%r" % capacity['available'])
            asserts.assert_true('total' in capacity,
                                "capacity.total: %r" % capacity['total'])
        instance_info.storage = storage


@test(groups=[tests.INSTANCES, GROUP],
      depends_on_groups=["dbaas.listing"])
class StorageAfterInstanceCreation(object):

    @before_class
    def setUp(self):
        self.user = test_config.users.find_user(Requirements(is_admin=True))
        self.client = create_dbaas_client(self.user)

    @test
    def test_storage_on_host(self):
        if not FAKE_MODE:
            raise SkipTest("Volume driver currently not working.")
        storage = self.client.storage.index()
        print("storage : %r" % storage)
        print("instance_info.storage : %r" % instance_info.storage)
        expected_attrs = ['name', 'type', 'used', 'provision', 'capacity']
        for index, device in enumerate(storage):
            CheckInstance(None).attrs_exist(device._info, expected_attrs,
                                            msg="Storage")
            asserts.assert_equal(device.name,
                                 instance_info.storage[index].name)
            asserts.assert_equal(device.used,
                                 instance_info.storage[index].used)
            asserts.assert_equal(device.type,
                                 instance_info.storage[index].type)

            provision = instance_info.storage[index].provision
            asserts.assert_equal(device.provision['available'],
                                 provision['available'])
            asserts.assert_equal(device.provision['percent'],
                                 provision['percent'])
            asserts.assert_equal(device.provision['total'], provision['total'])

            capacity = instance_info.storage[index].capacity
            asserts.assert_equal(device.capacity['available'],
                                 capacity['available'])
            asserts.assert_equal(device.capacity['total'], capacity['total'])