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

« back to all changes in this revision

Viewing changes to nova/tests/test_volume_utils.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 OpenStack LLC.
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
 
"""Tests For miscellaneous util methods used with volume."""
19
 
 
20
 
from nova import context
21
 
from nova import db
22
 
from nova import flags
23
 
from nova.openstack.common import importutils
24
 
from nova.openstack.common import log as logging
25
 
from nova.openstack.common.notifier import api as notifier_api
26
 
from nova.openstack.common.notifier import test_notifier
27
 
from nova import test
28
 
from nova.tests import fake_network
29
 
from nova.volume import utils as volume_utils
30
 
 
31
 
 
32
 
LOG = logging.getLogger(__name__)
33
 
FLAGS = flags.FLAGS
34
 
 
35
 
 
36
 
class UsageInfoTestCase(test.TestCase):
37
 
 
38
 
    def setUp(self):
39
 
        super(UsageInfoTestCase, self).setUp()
40
 
        self.flags(compute_driver='nova.virt.fake.FakeDriver',
41
 
                   host='fake',
42
 
                   notification_driver=[test_notifier.__name__])
43
 
        fake_network.set_stub_network_methods(self.stubs)
44
 
 
45
 
        self.volume = importutils.import_object(FLAGS.volume_manager)
46
 
        self.user_id = 'fake'
47
 
        self.project_id = 'fake'
48
 
        self.snapshot_id = 'fake'
49
 
        self.volume_size = 0
50
 
        self.context = context.RequestContext(self.user_id, self.project_id)
51
 
        test_notifier.NOTIFICATIONS = []
52
 
 
53
 
    def tearDown(self):
54
 
        notifier_api._reset_drivers()
55
 
        super(UsageInfoTestCase, self).tearDown()
56
 
 
57
 
    def _create_volume(self, params={}):
58
 
        """Create a test volume"""
59
 
        vol = {}
60
 
        vol['snapshot_id'] = self.snapshot_id
61
 
        vol['user_id'] = self.user_id
62
 
        vol['project_id'] = self.project_id
63
 
        vol['host'] = FLAGS.host
64
 
        vol['availability_zone'] = FLAGS.storage_availability_zone
65
 
        vol['status'] = "creating"
66
 
        vol['attach_status'] = "detached"
67
 
        vol['size'] = self.volume_size
68
 
        vol.update(params)
69
 
        return db.volume_create(self.context, vol)['id']
70
 
 
71
 
    def test_notify_usage_exists(self):
72
 
        """Ensure 'exists' notification generates appropriate usage data."""
73
 
        volume_id = self._create_volume()
74
 
        volume = db.volume_get(self.context, volume_id)
75
 
        volume_utils.notify_usage_exists(self.context, volume)
76
 
        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
77
 
        msg = test_notifier.NOTIFICATIONS[0]
78
 
        self.assertEquals(msg['priority'], 'INFO')
79
 
        self.assertEquals(msg['event_type'], 'volume.exists')
80
 
        payload = msg['payload']
81
 
        self.assertEquals(payload['tenant_id'], self.project_id)
82
 
        self.assertEquals(payload['user_id'], self.user_id)
83
 
        self.assertEquals(payload['snapshot_id'], self.snapshot_id)
84
 
        self.assertEquals(payload['volume_id'], volume.id)
85
 
        self.assertEquals(payload['size'], self.volume_size)
86
 
        for attr in ('display_name', 'created_at', 'launched_at',
87
 
                     'status', 'audit_period_beginning',
88
 
                     'audit_period_ending'):
89
 
            self.assertTrue(attr in payload,
90
 
                            msg="Key %s not in payload" % attr)
91
 
        db.volume_destroy(context.get_admin_context(), volume['id'])