~zulcss/cinder/cinder-ca-g2

« back to all changes in this revision

Viewing changes to cinder/tests/scheduler/test_scheduler_options.py

  • Committer: Chuck Short
  • Date: 2013-01-28 15:28:46 UTC
  • mfrom: (7.2.1 raring)
  • Revision ID: zulcss@ubuntu.com-20130128152846-1yl2iijulcbznp0g
* New upstream release for the Ubuntu Cloud Archive.
* debian/patches/series: Enable skip_failed_tests to fix FTBFS. 
* New upstream release. 
* debian/patches/avoid_setuptools_git_dependency.patch: Rediff
  due to upstream changes.
* debian/control: Add python-keystoneclient as a dependency
* Improve upstart configurations:
  - d/*.upstart: Switch to using start-stop-daemon instead of su,
    stop on [!2345] to catch all transitions.
* d/control: General tidy of package descriptions.
* d/control: Drop BD on python-all-dev as its not required.
* d/*.postrm: Dropped; update-rc.d calls for purge are handled by
  debhelper and are not require for upstart configurations.
* d/patches: removing hp3parclient dependency from tools/test-requires
* d/patches, d/control: adding stevedore dependency, merging deps patches
* d/patches: remove failing tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 OpenStack LLC.
 
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
Tests For PickledScheduler.
 
17
"""
 
18
 
 
19
import datetime
 
20
import StringIO
 
21
 
 
22
from cinder.openstack.common import jsonutils
 
23
from cinder.scheduler import scheduler_options
 
24
from cinder import test
 
25
 
 
26
 
 
27
class FakeSchedulerOptions(scheduler_options.SchedulerOptions):
 
28
    def __init__(self, last_checked, now, file_old, file_now, data, filedata):
 
29
        super(FakeSchedulerOptions, self).__init__()
 
30
        # Change internals ...
 
31
        self.last_modified = file_old
 
32
        self.last_checked = last_checked
 
33
        self.data = data
 
34
 
 
35
        # For overrides ...
 
36
        self._time_now = now
 
37
        self._file_now = file_now
 
38
        self._file_data = filedata
 
39
 
 
40
        self.file_was_loaded = False
 
41
 
 
42
    def _get_file_timestamp(self, filename):
 
43
        return self._file_now
 
44
 
 
45
    def _get_file_handle(self, filename):
 
46
        self.file_was_loaded = True
 
47
        return StringIO.StringIO(self._file_data)
 
48
 
 
49
    def _get_time_now(self):
 
50
        return self._time_now
 
51
 
 
52
 
 
53
class SchedulerOptionsTestCase(test.TestCase):
 
54
    def test_get_configuration_first_time_no_flag(self):
 
55
        last_checked = None
 
56
        now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
57
        file_old = None
 
58
        file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
59
 
 
60
        data = dict(a=1, b=2, c=3)
 
61
        jdata = jsonutils.dumps(data)
 
62
 
 
63
        fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
 
64
                                    {}, jdata)
 
65
        self.assertEquals({}, fake.get_configuration())
 
66
        self.assertFalse(fake.file_was_loaded)
 
67
 
 
68
    def test_get_configuration_first_time_empty_file(self):
 
69
        last_checked = None
 
70
        now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
71
        file_old = None
 
72
        file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
73
 
 
74
        data = dict(a=1, b=2, c=3)
 
75
        jdata = ""
 
76
 
 
77
        fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
 
78
                                    {}, jdata)
 
79
        self.assertEquals({}, fake.get_configuration('foo.json'))
 
80
        self.assertTrue(fake.file_was_loaded)
 
81
 
 
82
    def test_get_configuration_first_time_happy_day(self):
 
83
        last_checked = None
 
84
        now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
85
        file_old = None
 
86
        file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
87
 
 
88
        data = dict(a=1, b=2, c=3)
 
89
        jdata = jsonutils.dumps(data)
 
90
 
 
91
        fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
 
92
                                    {}, jdata)
 
93
        self.assertEquals(data, fake.get_configuration('foo.json'))
 
94
        self.assertTrue(fake.file_was_loaded)
 
95
 
 
96
    def test_get_configuration_second_time_no_change(self):
 
97
        last_checked = datetime.datetime(2011, 1, 1, 1, 1, 1)
 
98
        now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
99
        file_old = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
100
        file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
101
 
 
102
        data = dict(a=1, b=2, c=3)
 
103
        jdata = jsonutils.dumps(data)
 
104
 
 
105
        fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
 
106
                                    data, jdata)
 
107
        self.assertEquals(data, fake.get_configuration('foo.json'))
 
108
        self.assertFalse(fake.file_was_loaded)
 
109
 
 
110
    def test_get_configuration_second_time_too_fast(self):
 
111
        last_checked = datetime.datetime(2011, 1, 1, 1, 1, 1)
 
112
        now = datetime.datetime(2011, 1, 1, 1, 1, 2)
 
113
        file_old = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
114
        file_now = datetime.datetime(2013, 1, 1, 1, 1, 1)
 
115
 
 
116
        old_data = dict(a=1, b=2, c=3)
 
117
        data = dict(a=11, b=12, c=13)
 
118
        jdata = jsonutils.dumps(data)
 
119
 
 
120
        fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
 
121
                                    old_data, jdata)
 
122
        self.assertEquals(old_data, fake.get_configuration('foo.json'))
 
123
        self.assertFalse(fake.file_was_loaded)
 
124
 
 
125
    def test_get_configuration_second_time_change(self):
 
126
        last_checked = datetime.datetime(2011, 1, 1, 1, 1, 1)
 
127
        now = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
128
        file_old = datetime.datetime(2012, 1, 1, 1, 1, 1)
 
129
        file_now = datetime.datetime(2013, 1, 1, 1, 1, 1)
 
130
 
 
131
        old_data = dict(a=1, b=2, c=3)
 
132
        data = dict(a=11, b=12, c=13)
 
133
        jdata = jsonutils.dumps(data)
 
134
 
 
135
        fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
 
136
                                    old_data, jdata)
 
137
        self.assertEquals(data, fake.get_configuration('foo.json'))
 
138
        self.assertTrue(fake.file_was_loaded)