~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to test/probe/test_running_with_each_type_down.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Soren Hansen, Chuck Short
  • Date: 2012-09-07 19:02:36 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20120907190236-fqrmbzm7v6zivs8d
Tags: 1.7.0-0ubuntu1
[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Run unit tests at build time.
* Fix Launchpad URLs in debian/watch.

[ Chuck Short ]
* New upstream release
* debian/control: Add pubthon-moc as a build dep
* debian/rules: Dont fail if testsuite fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python -u
2
 
# Copyright (c) 2010-2012 OpenStack, LLC.
3
 
#
4
 
# Licensed under the Apache License, Version 2.0 (the "License");
5
 
# you may not use this file except in compliance with the License.
6
 
# You may obtain 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,
12
 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
 
# implied.
14
 
# See the License for the specific language governing permissions and
15
 
# limitations under the License.
16
 
 
17
 
import unittest
18
 
from os import kill
19
 
from signal import SIGTERM
20
 
from subprocess import Popen
21
 
from time import sleep
22
 
 
23
 
from swiftclient import client
24
 
 
25
 
from test.probe.common import get_to_final_state, kill_pids, reset_environment
26
 
 
27
 
 
28
 
class TestRunningWithEachTypeDown(unittest.TestCase):
29
 
 
30
 
    def setUp(self):
31
 
        self.pids, self.port2server, self.account_ring, self.container_ring, \
32
 
            self.object_ring, self.url, self.token, self.account = \
33
 
                reset_environment()
34
 
 
35
 
    def tearDown(self):
36
 
        kill_pids(self.pids)
37
 
 
38
 
    def test_main(self):
39
 
        # TODO: This test "randomly" pass or doesn't pass; need to find out why
40
 
        return
41
 
        apart, anodes = self.account_ring.get_nodes(self.account)
42
 
        kill(self.pids[self.port2server[anodes[0]['port']]], SIGTERM)
43
 
        cpart, cnodes = \
44
 
            self.container_ring.get_nodes(self.account, 'container1')
45
 
        kill(self.pids[self.port2server[cnodes[0]['port']]], SIGTERM)
46
 
        opart, onodes = \
47
 
            self.object_ring.get_nodes(self.account, 'container1', 'object1')
48
 
        kill(self.pids[self.port2server[onodes[0]['port']]], SIGTERM)
49
 
 
50
 
        try:
51
 
            client.put_container(self.url, self.token, 'container1')
52
 
        except client.ClientException, err:
53
 
            # This might 503 if one of the up container nodes tries to update
54
 
            # the down account node. It'll still be saved on one node, but we
55
 
            # can't assure the user.
56
 
            pass
57
 
        client.put_object(self.url, self.token, 'container1', 'object1', '1234')
58
 
        get_to_final_state()
59
 
        headers, containers = client.head_account(self.url, self.token)
60
 
        self.assertEquals(headers['x-account-container-count'], '1')
61
 
        self.assertEquals(headers['x-account-object-count'], '1')
62
 
        self.assertEquals(headers['x-account-bytes-used'], '4')
63
 
        found1 = False
64
 
        for container in containers:
65
 
            if container['name'] == 'container1':
66
 
                found1 = True
67
 
                self.assertEquals(container['count'], 1)
68
 
                self.assertEquals(container['bytes'], 4)
69
 
        self.assert_(found1)
70
 
        found1 = False
71
 
        for obj in client.get_container(self.url, self.token, 'container1')[1]:
72
 
            if obj['name'] == 'object1':
73
 
                found1 = True
74
 
                self.assertEquals(obj['bytes'], 4)
75
 
        self.assert_(found1)
76
 
 
77
 
        self.pids[self.port2server[anodes[0]['port']]] = \
78
 
            Popen(['swift-account-server',
79
 
                   '/etc/swift/account-server/%d.conf' %
80
 
                    ((anodes[0]['port'] - 6002) / 10)]).pid
81
 
        self.pids[self.port2server[cnodes[0]['port']]] = \
82
 
            Popen(['swift-container-server',
83
 
                   '/etc/swift/container-server/%d.conf' %
84
 
                    ((cnodes[0]['port'] - 6001) / 10)]).pid
85
 
        self.pids[self.port2server[onodes[0]['port']]] = \
86
 
            Popen(['swift-object-server',
87
 
                   '/etc/swift/object-server/%d.conf' %
88
 
                    ((onodes[0]['port'] - 6000) / 10)]).pid
89
 
        sleep(2)
90
 
        headers, containers = client.head_account(self.url, self.token)
91
 
        self.assertEquals(headers['x-account-container-count'], '1')
92
 
        self.assertEquals(headers['x-account-object-count'], '1')
93
 
        self.assertEquals(headers['x-account-bytes-used'], '4')
94
 
        found1 = False
95
 
        for container in containers:
96
 
            if container['name'] == 'container1':
97
 
                found1 = True
98
 
        # The account node was previously down.
99
 
        self.assert_(not found1)
100
 
        found1 = False
101
 
        for obj in client.get_container(self.url, self.token, 'container1')[1]:
102
 
            if obj['name'] == 'object1':
103
 
                found1 = True
104
 
                self.assertEquals(obj['bytes'], 4)
105
 
        # The first container node 404s, but the proxy will try the next node
106
 
        # and succeed.
107
 
        self.assert_(found1)
108
 
 
109
 
        get_to_final_state()
110
 
        headers, containers = client.head_account(self.url, self.token)
111
 
        self.assertEquals(headers['x-account-container-count'], '1')
112
 
        self.assertEquals(headers['x-account-object-count'], '1')
113
 
        self.assertEquals(headers['x-account-bytes-used'], '4')
114
 
        found1 = False
115
 
        for container in containers:
116
 
            if container['name'] == 'container1':
117
 
                found1 = True
118
 
                self.assertEquals(container['count'], 1)
119
 
                self.assertEquals(container['bytes'], 4)
120
 
        self.assert_(found1)
121
 
        found1 = False
122
 
        for obj in client.get_container(self.url, self.token, 'container1')[1]:
123
 
            if obj['name'] == 'object1':
124
 
                found1 = True
125
 
                self.assertEquals(obj['bytes'], 4)
126
 
        self.assert_(found1)
127
 
 
128
 
 
129
 
if __name__ == '__main__':
130
 
    unittest.main()