Beispiel #1
0
 def test_print_ring_locations_container(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         contring = ring.Ring(self.testdir, ring_name='container')
         print_ring_locations(contring, 'dir', 'acct', 'con')
     exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '1',
                           'fe6', '63e70955d78dfc62821edc07d6ec1fe6')
     self.assertTrue(exp_db in out.getvalue())
Beispiel #2
0
 def test_print_ring_locations_obj(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         objring = ring.Ring(self.testdir, ring_name='object')
         print_ring_locations(objring, 'dir', 'acct', 'con', 'obj')
     exp_obj = os.path.join('${DEVICE:-/srv/node*}', 'sda1', 'dir', '1',
                            '117', '4a16154fc15c75e26ba6afadf5b1c117')
     self.assertTrue(exp_obj in out.getvalue())
Beispiel #3
0
 def test_print_ring_locations_obj(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         objring = ring.Ring(self.testdir, ring_name='object')
         print_ring_locations(objring, 'dir', 'acct', 'con', 'obj')
     exp_obj = os.path.join('${DEVICE:-/srv/node*}', 'sda1', 'dir', '1',
                            '117', '4a16154fc15c75e26ba6afadf5b1c117')
     self.assertTrue(exp_obj in out.getvalue())
Beispiel #4
0
 def test_print_ring_locations_container(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         contring = ring.Ring(self.testdir, ring_name='container')
         print_ring_locations(contring, 'dir', 'acct', 'con')
     exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '1',
                           'fe6', '63e70955d78dfc62821edc07d6ec1fe6')
     self.assertTrue(exp_db in out.getvalue())
Beispiel #5
0
 def test_print_ring_locations_account(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         acctring = ring.Ring(self.testdir, ring_name='account')
         print_ring_locations(acctring, 'dir', 'acct')
     exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '3',
                           'b47', 'dc5be2aa4347a22a0fee6bc7de505b47')
     self.assertTrue(exp_db in out.getvalue())
     self.assertTrue('127.0.0.1' in out.getvalue())
     self.assertTrue('127.0.0.2' in out.getvalue())
Beispiel #6
0
 def test_print_ring_locations_account(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         acctring = ring.Ring(self.testdir, ring_name='account')
         print_ring_locations(acctring, 'dir', 'acct')
     exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '3',
                           'b47', 'dc5be2aa4347a22a0fee6bc7de505b47')
     self.assertTrue(exp_db in out.getvalue())
     self.assertTrue('127.0.0.1' in out.getvalue())
     self.assertTrue('127.0.0.2' in out.getvalue())
Beispiel #7
0
 def test_print_ring_locations_partition_number(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         objring = ring.Ring(self.testdir, ring_name='object')
         print_ring_locations(objring, 'objects', None, tpart='1')
     exp_obj1 = os.path.join('${DEVICE:-/srv/node*}', 'sda1',
                             'objects', '1')
     exp_obj2 = os.path.join('${DEVICE:-/srv/node*}', 'sdb1',
                             'objects', '1')
     self.assertTrue(exp_obj1 in out.getvalue())
     self.assertTrue(exp_obj2 in out.getvalue())
Beispiel #8
0
 def test_print_ring_locations_partition_number(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         objring = ring.Ring(self.testdir, ring_name='object')
         print_ring_locations(objring, 'objects', None, tpart='1')
     exp_obj1 = os.path.join('${DEVICE:-/srv/node*}', 'sda1', 'objects',
                             '1')
     exp_obj2 = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'objects',
                             '1')
     self.assertTrue(exp_obj1 in out.getvalue())
     self.assertTrue(exp_obj2 in out.getvalue())
Beispiel #9
0
    def test_print_ring_locations(self):
        self.assertRaisesMessage(ValueError, 'None type', print_ring_locations,
                                 None, 'dir', 'acct')
        self.assertRaisesMessage(ValueError, 'None type', print_ring_locations,
                                 [], None, 'acct')
        self.assertRaisesMessage(ValueError, 'None type', print_ring_locations,
                                 [], 'dir', None)
        self.assertRaisesMessage(ValueError, 'Ring error',
                                 print_ring_locations,
                                 [], 'dir', 'acct', 'con')

        out = StringIO()
        with mock.patch('sys.stdout', out):
            acctring = ring.Ring(self.testdir, ring_name='account')
            print_ring_locations(acctring, 'dir', 'acct')
        exp_db2 = os.path.join('/srv', 'node', 'sdb1', 'dir', '3', 'b47',
                               'dc5be2aa4347a22a0fee6bc7de505b47',
                               'dc5be2aa4347a22a0fee6bc7de505b47.db')
        exp_db1 = os.path.join('/srv', 'node', 'sda1', 'dir', '3', 'b47',
                               'dc5be2aa4347a22a0fee6bc7de505b47',
                               'dc5be2aa4347a22a0fee6bc7de505b47.db')
        exp_out = ('Ring locations:\n  127.0.0.2:43 - %s\n'
                   '  127.0.0.1:42 - %s\n'
                   '\nnote: /srv/node is used as default value of `devices`,'
                   ' the real value is set in the account config file on'
                   ' each storage node.' % (exp_db2, exp_db1))
        self.assertEquals(out.getvalue().strip(), exp_out)

        out = StringIO()
        with mock.patch('sys.stdout', out):
            contring = ring.Ring(self.testdir, ring_name='container')
            print_ring_locations(contring, 'dir', 'acct', 'con')
        exp_db4 = os.path.join('/srv', 'node', 'sdb1', 'dir', '1', 'fe6',
                               '63e70955d78dfc62821edc07d6ec1fe6',
                               '63e70955d78dfc62821edc07d6ec1fe6.db')
        exp_db3 = os.path.join('/srv', 'node', 'sda1', 'dir', '1', 'fe6',
                               '63e70955d78dfc62821edc07d6ec1fe6',
                               '63e70955d78dfc62821edc07d6ec1fe6.db')
        exp_out = ('Ring locations:\n  127.0.0.4:43 - %s\n'
                   '  127.0.0.3:42 - %s\n'
                   '\nnote: /srv/node is used as default value of `devices`,'
                   ' the real value is set in the container config file on'
                   ' each storage node.' % (exp_db4, exp_db3))
        self.assertEquals(out.getvalue().strip(), exp_out)
Beispiel #10
0
    def test_print_ring_locations(self):
        self.assertRaisesMessage(ValueError, "None type", print_ring_locations, None, "dir", "acct")
        self.assertRaisesMessage(ValueError, "None type", print_ring_locations, [], None, "acct")
        self.assertRaisesMessage(ValueError, "None type", print_ring_locations, [], "dir", None)
        self.assertRaisesMessage(ValueError, "Ring error", print_ring_locations, [], "dir", "acct", "con")

        out = StringIO()
        with mock.patch("sys.stdout", out):
            acctring = ring.Ring(self.testdir, ring_name="account")
            print_ring_locations(acctring, "dir", "acct")
        exp_db2 = os.path.join(
            "/srv",
            "node",
            "sdb1",
            "dir",
            "3",
            "b47",
            "dc5be2aa4347a22a0fee6bc7de505b47",
            "dc5be2aa4347a22a0fee6bc7de505b47.db",
        )
        exp_db1 = os.path.join(
            "/srv",
            "node",
            "sda1",
            "dir",
            "3",
            "b47",
            "dc5be2aa4347a22a0fee6bc7de505b47",
            "dc5be2aa4347a22a0fee6bc7de505b47.db",
        )
        exp_out = (
            "Ring locations:\n  127.0.0.2:43 - %s\n"
            "  127.0.0.1:42 - %s\n"
            "\nnote: /srv/node is used as default value of `devices`,"
            " the real value is set in the account config file on"
            " each storage node." % (exp_db2, exp_db1)
        )
        self.assertEquals(out.getvalue().strip(), exp_out)

        out = StringIO()
        with mock.patch("sys.stdout", out):
            contring = ring.Ring(self.testdir, ring_name="container")
            print_ring_locations(contring, "dir", "acct", "con")
        exp_db4 = os.path.join(
            "/srv",
            "node",
            "sdb1",
            "dir",
            "1",
            "fe6",
            "63e70955d78dfc62821edc07d6ec1fe6",
            "63e70955d78dfc62821edc07d6ec1fe6.db",
        )
        exp_db3 = os.path.join(
            "/srv",
            "node",
            "sda1",
            "dir",
            "1",
            "fe6",
            "63e70955d78dfc62821edc07d6ec1fe6",
            "63e70955d78dfc62821edc07d6ec1fe6.db",
        )
        exp_out = (
            "Ring locations:\n  127.0.0.4:43 - %s\n"
            "  127.0.0.3:42 - %s\n"
            "\nnote: /srv/node is used as default value of `devices`,"
            " the real value is set in the container config file on"
            " each storage node." % (exp_db4, exp_db3)
        )
        self.assertEquals(out.getvalue().strip(), exp_out)