~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/integrated/test_volumes.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2011 Justin Santa Barbara
4
 
# All Rights Reserved.
5
 
#
6
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 
#    not use this file except in compliance with the License. You may obtain
8
 
#    a copy of the License at
9
 
#
10
 
#         http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
#    Unless required by applicable law or agreed to in writing, software
13
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 
#    License for the specific language governing permissions and limitations
16
 
#    under the License.
17
 
 
18
 
import time
19
 
import unittest
20
 
 
21
 
from nova.openstack.common.log import logging
22
 
from nova import service
23
 
from nova.tests.integrated.api import client
24
 
from nova.tests.integrated import integrated_helpers
25
 
from nova.volume import driver
26
 
 
27
 
 
28
 
LOG = logging.getLogger(__name__)
29
 
 
30
 
 
31
 
class VolumesTest(integrated_helpers._IntegratedTestBase):
32
 
    def setUp(self):
33
 
        super(VolumesTest, self).setUp()
34
 
        driver.LoggingVolumeDriver.clear_logs()
35
 
 
36
 
    def _start_api_service(self):
37
 
        self.osapi = service.WSGIService("osapi_volume")
38
 
        self.osapi.start()
39
 
        self.auth_url = 'http://%s:%s/v1' % (self.osapi.host, self.osapi.port)
40
 
        LOG.warn(self.auth_url)
41
 
 
42
 
    def _get_flags(self):
43
 
        f = super(VolumesTest, self)._get_flags()
44
 
        f['use_local_volumes'] = False  # Avoids calling local_path
45
 
        f['volume_driver'] = 'nova.volume.driver.LoggingVolumeDriver'
46
 
        return f
47
 
 
48
 
    def test_get_volumes_summary(self):
49
 
        """Simple check that listing volumes works."""
50
 
        volumes = self.api.get_volumes(False)
51
 
        for volume in volumes:
52
 
            LOG.debug("volume: %s" % volume)
53
 
 
54
 
    def test_get_volumes(self):
55
 
        """Simple check that listing volumes works."""
56
 
        volumes = self.api.get_volumes()
57
 
        for volume in volumes:
58
 
            LOG.debug("volume: %s" % volume)
59
 
 
60
 
    def _poll_while(self, volume_id, continue_states, max_retries=5):
61
 
        """Poll (briefly) while the state is in continue_states."""
62
 
        retries = 0
63
 
        while True:
64
 
            try:
65
 
                found_volume = self.api.get_volume(volume_id)
66
 
            except client.OpenStackApiNotFoundException:
67
 
                found_volume = None
68
 
                LOG.debug("Got 404, proceeding")
69
 
                break
70
 
 
71
 
            LOG.debug("Found %s" % found_volume)
72
 
 
73
 
            self.assertEqual(volume_id, found_volume['id'])
74
 
 
75
 
            if not found_volume['status'] in continue_states:
76
 
                break
77
 
 
78
 
            time.sleep(1)
79
 
            retries = retries + 1
80
 
            if retries > max_retries:
81
 
                break
82
 
        return found_volume
83
 
 
84
 
    def test_create_and_delete_volume(self):
85
 
        """Creates and deletes a volume."""
86
 
 
87
 
        # Create volume
88
 
        created_volume = self.api.post_volume({'volume': {'size': 1}})
89
 
        LOG.debug("created_volume: %s" % created_volume)
90
 
        self.assertTrue(created_volume['id'])
91
 
        created_volume_id = created_volume['id']
92
 
 
93
 
        # Check it's there
94
 
        found_volume = self.api.get_volume(created_volume_id)
95
 
        self.assertEqual(created_volume_id, found_volume['id'])
96
 
 
97
 
        # It should also be in the all-volume list
98
 
        volumes = self.api.get_volumes()
99
 
        volume_names = [volume['id'] for volume in volumes]
100
 
        self.assertTrue(created_volume_id in volume_names)
101
 
 
102
 
        # Wait (briefly) for creation. Delay is due to the 'message queue'
103
 
        found_volume = self._poll_while(created_volume_id, ['creating'])
104
 
 
105
 
        # It should be available...
106
 
        self.assertEqual('available', found_volume['status'])
107
 
 
108
 
        # Delete the volume
109
 
        self.api.delete_volume(created_volume_id)
110
 
 
111
 
        # Wait (briefly) for deletion. Delay is due to the 'message queue'
112
 
        found_volume = self._poll_while(created_volume_id, ['deleting'])
113
 
 
114
 
        # Should be gone
115
 
        self.assertFalse(found_volume)
116
 
 
117
 
        LOG.debug("Logs: %s" % driver.LoggingVolumeDriver.all_logs())
118
 
 
119
 
        create_actions = driver.LoggingVolumeDriver.logs_like(
120
 
                            'create_volume',
121
 
                            id=created_volume_id)
122
 
        LOG.debug("Create_Actions: %s" % create_actions)
123
 
 
124
 
        self.assertEquals(1, len(create_actions))
125
 
        create_action = create_actions[0]
126
 
        self.assertEquals(create_action['id'], created_volume_id)
127
 
        self.assertEquals(create_action['availability_zone'], 'nova')
128
 
        self.assertEquals(create_action['size'], 1)
129
 
 
130
 
        export_actions = driver.LoggingVolumeDriver.logs_like(
131
 
                            'create_export',
132
 
                            id=created_volume_id)
133
 
        self.assertEquals(1, len(export_actions))
134
 
        export_action = export_actions[0]
135
 
        self.assertEquals(export_action['id'], created_volume_id)
136
 
        self.assertEquals(export_action['availability_zone'], 'nova')
137
 
 
138
 
        delete_actions = driver.LoggingVolumeDriver.logs_like(
139
 
                            'delete_volume',
140
 
                            id=created_volume_id)
141
 
        self.assertEquals(1, len(delete_actions))
142
 
        delete_action = export_actions[0]
143
 
        self.assertEquals(delete_action['id'], created_volume_id)
144
 
 
145
 
    def test_create_volume_with_metadata(self):
146
 
        """Creates a volume with metadata."""
147
 
 
148
 
        # Create volume
149
 
        metadata = {'key1': 'value1',
150
 
                    'key2': 'value2'}
151
 
        created_volume = self.api.post_volume(
152
 
            {'volume': {'size': 1,
153
 
                        'metadata': metadata}})
154
 
        LOG.debug("created_volume: %s" % created_volume)
155
 
        self.assertTrue(created_volume['id'])
156
 
        created_volume_id = created_volume['id']
157
 
 
158
 
        # Check it's there and metadata present
159
 
        found_volume = self.api.get_volume(created_volume_id)
160
 
        self.assertEqual(created_volume_id, found_volume['id'])
161
 
        self.assertEqual(metadata, found_volume['metadata'])
162
 
 
163
 
    def test_create_volume_in_availability_zone(self):
164
 
        """Creates a volume in availability_zone."""
165
 
 
166
 
        # Create volume
167
 
        availability_zone = 'zone1:host1'
168
 
        created_volume = self.api.post_volume(
169
 
            {'volume': {'size': 1,
170
 
                        'availability_zone': availability_zone}})
171
 
        LOG.debug("created_volume: %s" % created_volume)
172
 
        self.assertTrue(created_volume['id'])
173
 
        created_volume_id = created_volume['id']
174
 
 
175
 
        # Check it's there and availability zone present
176
 
        found_volume = self.api.get_volume(created_volume_id)
177
 
        self.assertEqual(created_volume_id, found_volume['id'])
178
 
        self.assertEqual(availability_zone, found_volume['availability_zone'])
179
 
 
180
 
if __name__ == "__main__":
181
 
    unittest.main()