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

« back to all changes in this revision

Viewing changes to nova/tests/baremetal/db/test_bm_node.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
# Copyright (c) 2012 NTT DOCOMO, INC.
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
"""
 
17
Bare-Metal DB testcase for BareMetalNode
 
18
"""
 
19
 
 
20
from nova.tests.baremetal.db import base
 
21
from nova.tests.baremetal.db import utils
 
22
from nova.virt.baremetal import db
 
23
 
 
24
 
 
25
class BareMetalNodesTestCase(base.BMDBTestCase):
 
26
 
 
27
    def _create_nodes(self):
 
28
        nodes = [
 
29
            utils.new_bm_node(pm_address='0', service_host="host1",
 
30
                              memory_mb=100000, cpus=100, local_gb=10000),
 
31
            utils.new_bm_node(pm_address='1', service_host="host2",
 
32
                              instance_uuid='A',
 
33
                              memory_mb=100000, cpus=100, local_gb=10000),
 
34
            utils.new_bm_node(pm_address='2', service_host="host2",
 
35
                               memory_mb=1000, cpus=1, local_gb=1000),
 
36
            utils.new_bm_node(pm_address='3', service_host="host2",
 
37
                               memory_mb=1000, cpus=2, local_gb=1000),
 
38
            utils.new_bm_node(pm_address='4', service_host="host2",
 
39
                               memory_mb=2000, cpus=1, local_gb=1000),
 
40
            utils.new_bm_node(pm_address='5', service_host="host2",
 
41
                               memory_mb=2000, cpus=2, local_gb=1000),
 
42
        ]
 
43
        self.ids = []
 
44
        for n in nodes:
 
45
            ref = db.bm_node_create(self.context, n)
 
46
            self.ids.append(ref['id'])
 
47
 
 
48
    def test_get_all0(self):
 
49
        r = db.bm_node_get_all(self.context)
 
50
        self.assertEquals(r, [])
 
51
 
 
52
    def test_get_all(self):
 
53
        r = db.bm_node_get_all(self.context)
 
54
        self.assertEquals(r, [])
 
55
 
 
56
        self._create_nodes()
 
57
 
 
58
        r = db.bm_node_get_all(self.context)
 
59
        self.assertEquals(len(r), 6)
 
60
 
 
61
    def test_get(self):
 
62
        self._create_nodes()
 
63
 
 
64
        r = db.bm_node_get(self.context, self.ids[0])
 
65
        self.assertEquals(r['pm_address'], '0')
 
66
 
 
67
        r = db.bm_node_get(self.context, self.ids[1])
 
68
        self.assertEquals(r['pm_address'], '1')
 
69
 
 
70
        r = db.bm_node_get(self.context, -1)
 
71
        self.assertTrue(r is None)
 
72
 
 
73
    def test_get_by_service_host(self):
 
74
        self._create_nodes()
 
75
 
 
76
        r = db.bm_node_get_all(self.context, service_host=None)
 
77
        self.assertEquals(len(r), 6)
 
78
 
 
79
        r = db.bm_node_get_all(self.context, service_host="host1")
 
80
        self.assertEquals(len(r), 1)
 
81
        self.assertEquals(r[0]['pm_address'], '0')
 
82
 
 
83
        r = db.bm_node_get_all(self.context, service_host="host2")
 
84
        self.assertEquals(len(r), 5)
 
85
        pmaddrs = [x['pm_address'] for x in r]
 
86
        self.assertIn('1', pmaddrs)
 
87
        self.assertIn('2', pmaddrs)
 
88
        self.assertIn('3', pmaddrs)
 
89
        self.assertIn('4', pmaddrs)
 
90
        self.assertIn('5', pmaddrs)
 
91
 
 
92
        r = db.bm_node_get_all(self.context, service_host="host3")
 
93
        self.assertEquals(r, [])
 
94
 
 
95
    def test_destroy(self):
 
96
        self._create_nodes()
 
97
 
 
98
        db.bm_node_destroy(self.context, self.ids[0])
 
99
 
 
100
        r = db.bm_node_get(self.context, self.ids[0])
 
101
        self.assertTrue(r is None)
 
102
 
 
103
        r = db.bm_node_get_all(self.context)
 
104
        self.assertEquals(len(r), 5)
 
105
 
 
106
    def test_find_free(self):
 
107
        self._create_nodes()
 
108
        fn = db.bm_node_find_free(self.context, 'host2')
 
109
        self.assertEqual(fn['pm_address'], '2')
 
110
 
 
111
        fn = db.bm_node_find_free(self.context, 'host2',
 
112
                                  memory_mb=500, cpus=2, local_gb=100)
 
113
        self.assertEqual(fn['pm_address'], '3')
 
114
 
 
115
        fn = db.bm_node_find_free(self.context, 'host2',
 
116
                                  memory_mb=1001, cpus=1, local_gb=1000)
 
117
        self.assertEqual(fn['pm_address'], '4')
 
118
 
 
119
        fn = db.bm_node_find_free(self.context, 'host2',
 
120
                                  memory_mb=2000, cpus=1, local_gb=1000)
 
121
        self.assertEqual(fn['pm_address'], '4')
 
122
 
 
123
        fn = db.bm_node_find_free(self.context, 'host2',
 
124
                                  memory_mb=2000, cpus=2, local_gb=1000)
 
125
        self.assertEqual(fn['pm_address'], '5')
 
126
 
 
127
        # check memory_mb
 
128
        fn = db.bm_node_find_free(self.context, 'host2',
 
129
                                  memory_mb=2001, cpus=2, local_gb=1000)
 
130
        self.assertTrue(fn is None)
 
131
 
 
132
        # check cpus
 
133
        fn = db.bm_node_find_free(self.context, 'host2',
 
134
                                  memory_mb=2000, cpus=3, local_gb=1000)
 
135
        self.assertTrue(fn is None)
 
136
 
 
137
        # check local_gb
 
138
        fn = db.bm_node_find_free(self.context, 'host2',
 
139
                                  memory_mb=2000, cpus=2, local_gb=1001)
 
140
        self.assertTrue(fn is None)