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

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/compute/contrib/test_services.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 2012 IBM
 
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
from datetime import datetime
 
18
from nova.api.openstack.compute.contrib import services
 
19
from nova import context
 
20
from nova import db
 
21
from nova import exception
 
22
from nova.openstack.common import timeutils
 
23
from nova import test
 
24
from nova.tests.api.openstack import fakes
 
25
 
 
26
 
 
27
fake_services_list = [{'binary': 'nova-scheduler',
 
28
                       'host': 'host1',
 
29
                       'availability_zone': 'nova',
 
30
                       'id': 1,
 
31
                       'disabled': True,
 
32
                       'updated_at': datetime(2012, 10, 29, 13, 42, 2),
 
33
                       'created_at': datetime(2012, 9, 18, 2, 46, 27)},
 
34
                      {'binary': 'nova-compute',
 
35
                       'host': 'host1',
 
36
                       'availability_zone': 'nova',
 
37
                       'id': 2,
 
38
                       'disabled': True,
 
39
                       'updated_at': datetime(2012, 10, 29, 13, 42, 5),
 
40
                       'created_at': datetime(2012, 9, 18, 2, 46, 27)},
 
41
                      {'binary': 'nova-scheduler',
 
42
                       'host': 'host2',
 
43
                       'availability_zone': 'nova',
 
44
                       'id': 3,
 
45
                       'disabled': False,
 
46
                       'updated_at': datetime(2012, 9, 19, 6, 55, 34),
 
47
                       'created_at': datetime(2012, 9, 18, 2, 46, 28)},
 
48
                      {'binary': 'nova-compute',
 
49
                       'host': 'host2',
 
50
                       'availability_zone': 'nova',
 
51
                       'id': 4,
 
52
                       'disabled': True,
 
53
                       'updated_at': datetime(2012, 9, 18, 8, 3, 38),
 
54
                       'created_at': datetime(2012, 9, 18, 2, 46, 28)},
 
55
                      ]
 
56
 
 
57
 
 
58
class FakeRequest(object):
 
59
        environ = {"nova.context": context.get_admin_context()}
 
60
        GET = {}
 
61
 
 
62
 
 
63
class FakeRequestWithSevice(object):
 
64
        environ = {"nova.context": context.get_admin_context()}
 
65
        GET = {"service": "nova-compute"}
 
66
 
 
67
 
 
68
class FakeRequestWithHost(object):
 
69
        environ = {"nova.context": context.get_admin_context()}
 
70
        GET = {"host": "host1"}
 
71
 
 
72
 
 
73
class FakeRequestWithHostService(object):
 
74
        environ = {"nova.context": context.get_admin_context()}
 
75
        GET = {"host": "host1", "service": "nova-compute"}
 
76
 
 
77
 
 
78
def fake_servcie_get_all(context):
 
79
    return fake_services_list
 
80
 
 
81
 
 
82
def fake_service_get_by_host_binary(context, host, binary):
 
83
    for service in fake_services_list:
 
84
        if service['host'] == host and service['binary'] == binary:
 
85
            return service
 
86
    return None
 
87
 
 
88
 
 
89
def fake_service_get_by_id(value):
 
90
    for service in fake_services_list:
 
91
        if service['id'] == value:
 
92
            return service
 
93
    return None
 
94
 
 
95
 
 
96
def fake_service_update(context, service_id, values):
 
97
    service = fake_service_get_by_id(service_id)
 
98
    if service is None:
 
99
        raise exception.ServiceNotFound(service_id=service_id)
 
100
    else:
 
101
        {'host': 'host1', 'service': 'nova-compute',
 
102
         'disabled': values['disabled']}
 
103
 
 
104
 
 
105
def fake_utcnow():
 
106
    return datetime(2012, 10, 29, 13, 42, 11)
 
107
 
 
108
 
 
109
class ServicesTest(test.TestCase):
 
110
 
 
111
    def setUp(self):
 
112
        super(ServicesTest, self).setUp()
 
113
 
 
114
        self.stubs.Set(db, "service_get_all", fake_servcie_get_all)
 
115
        self.stubs.Set(timeutils, "utcnow", fake_utcnow)
 
116
        self.stubs.Set(db, "service_get_by_args",
 
117
                       fake_service_get_by_host_binary)
 
118
        self.stubs.Set(db, "service_update", fake_service_update)
 
119
 
 
120
        self.context = context.get_admin_context()
 
121
        self.controller = services.ServiceController()
 
122
 
 
123
    def tearDown(self):
 
124
        super(ServicesTest, self).tearDown()
 
125
 
 
126
    def test_services_list(self):
 
127
        req = FakeRequest()
 
128
        res_dict = self.controller.index(req)
 
129
 
 
130
        response = {'services': [{'binary': 'nova-scheduler',
 
131
                    'host': 'host1', 'zone': 'nova',
 
132
                    'status': 'disabled', 'state': 'up',
 
133
                    'updated_at': datetime(2012, 10, 29, 13, 42, 2)},
 
134
                    {'binary': 'nova-compute',
 
135
                     'host': 'host1', 'zone': 'nova',
 
136
                     'status': 'disabled', 'state': 'up',
 
137
                     'updated_at': datetime(2012, 10, 29, 13, 42, 5)},
 
138
                    {'binary': 'nova-scheduler', 'host': 'host2',
 
139
                     'zone': 'nova',
 
140
                     'status': 'enabled', 'state': 'down',
 
141
                     'updated_at': datetime(2012, 9, 19, 6, 55, 34)},
 
142
                    {'binary': 'nova-compute', 'host': 'host2',
 
143
                     'zone': 'nova',
 
144
                     'status': 'disabled', 'state': 'down',
 
145
                     'updated_at': datetime(2012, 9, 18, 8, 3, 38)}]}
 
146
        self.assertEqual(res_dict, response)
 
147
 
 
148
    def test_services_list_with_host(self):
 
149
        req = FakeRequestWithHost()
 
150
        res_dict = self.controller.index(req)
 
151
 
 
152
        response = {'services': [{'binary': 'nova-scheduler', 'host': 'host1',
 
153
                    'zone': 'nova',
 
154
                    'status': 'disabled', 'state': 'up',
 
155
                    'updated_at': datetime(2012, 10, 29, 13, 42, 2)},
 
156
                   {'binary': 'nova-compute', 'host': 'host1',
 
157
                    'zone': 'nova',
 
158
                    'status': 'disabled', 'state': 'up',
 
159
                    'updated_at': datetime(2012, 10, 29, 13, 42, 5)}]}
 
160
        self.assertEqual(res_dict, response)
 
161
 
 
162
    def test_services_list_with_service(self):
 
163
        req = FakeRequestWithSevice()
 
164
        res_dict = self.controller.index(req)
 
165
 
 
166
        response = {'services': [{'binary': 'nova-compute', 'host': 'host1',
 
167
                    'zone': 'nova',
 
168
                    'status': 'disabled', 'state': 'up',
 
169
                    'updated_at': datetime(2012, 10, 29, 13, 42, 5)},
 
170
                    {'binary': 'nova-compute', 'host': 'host2',
 
171
                     'zone': 'nova',
 
172
                     'status': 'disabled', 'state': 'down',
 
173
                     'updated_at': datetime(2012, 9, 18, 8, 3, 38)}]}
 
174
        self.assertEqual(res_dict, response)
 
175
 
 
176
    def test_services_list_with_host_service(self):
 
177
        req = FakeRequestWithHostService()
 
178
        res_dict = self.controller.index(req)
 
179
 
 
180
        response = {'services': [{'binary': 'nova-compute', 'host': 'host1',
 
181
                    'zone': 'nova',
 
182
                    'status': 'disabled', 'state': 'up',
 
183
                    'updated_at': datetime(2012, 10, 29, 13, 42, 5)}]}
 
184
        self.assertEqual(res_dict, response)
 
185
 
 
186
    def test_services_enable(self):
 
187
        body = {'host': 'host1', 'service': 'nova-compute'}
 
188
        req = fakes.HTTPRequest.blank('/v2/fake/os-services/enable')
 
189
        res_dict = self.controller.update(req, "enable", body)
 
190
 
 
191
        self.assertEqual(res_dict['disabled'], False)
 
192
 
 
193
    def test_services_disable(self):
 
194
        req = fakes.HTTPRequest.blank('/v2/fake/os-services/disable')
 
195
        body = {'host': 'host1', 'service': 'nova-compute'}
 
196
        res_dict = self.controller.update(req, "disable", body)
 
197
 
 
198
        self.assertEqual(res_dict['disabled'], True)