コード例 #1
0
ファイル: test_config.py プロジェクト: pombredanne/lunr
    def test_parse_config_file(self):
        conf = None

        conf_str = "[DEFAULT]\n" \
                   "foo = bar\n" \
                   "[foo]\n" \
                   "foo = baz\n" \
                   "[foo]\n" \
                   "fog = buz\n" \
                   "[fiz]\n" \
                   "bang = bazt\n" \
                   "[casts]\n" \
                   "size = 25\n" \
                   "flush = True\n"

        with temp_disk_file(conf_str) as file:
            conf = LunrConfig.from_conf(file)
            self.assertEquals(conf.string('default', '__file__', ''), file)

        # All parsed options default to string
        value = conf.string('default', 'foo', '')
        self.assertEquals(value, 'bar')
        value = conf.string('foo', 'foo', '')
        self.assertEquals(value, 'baz')
        value = conf.string('foo', 'fog', '')
        self.assertEquals(value, 'buz')
        value = conf.string('fiz', 'bang', '')
        self.assertEquals(value, 'bazt')

        # Non-string casts
        value = conf.int('casts', 'size', 1)
        self.assertEquals(value, 25)
        value = conf.bool('casts', 'flush', False)
        self.assertEquals(value, True)
コード例 #2
0
ファイル: test_config.py プロジェクト: pombredanne/lunr
 def test_parse_config_bad_section(self):
     conf_str = "[DEFAULT]\n" \
                "foo = bar\n" \
                "[__file__]\n" \
                "foo = baz\n"
     with temp_disk_file(conf_str) as file:
         self.assertRaises(BadSectionNameError, LunrConfig.from_conf, file)
コード例 #3
0
ファイル: test_config.py プロジェクト: rackerlabs/lunr
 def test_parse_syntax_error(self):
     conf_str = dedent("""
         DEFAULT]
         foo = bar
         """)
     with temp_disk_file(conf_str) as file:
         self.assertRaises(InvalidConfigError, LunrConfig.from_conf, file)
コード例 #4
0
ファイル: test_manifest.py プロジェクト: pombredanne/lunr
    def test_integer_backup_id(self):
        size = 2
        m = manifest.Manifest.blank(size)
        backup = m.create_backup(0)
        for blockno in range(size):
            backup[blockno] = '0000'
        backup = m.create_backup(1)
        for blockno in range(0, size, 10):
            backup[blockno] = '1111'
        backup = m.create_backup('id2')
        for blockno in range(0, size, 10):
            backup[blockno] = '2222'

        c = MockConnection()
        with temp_disk_file() as lock_file:
            manifest.save_manifest(m, c, 'vol1', lock_file)

            expected = dict(m)
            vol1 = m.get_backup(1)
            vol1_str = m.get_backup('1')
            vol2 = m.get_backup('id2')

            m = manifest.load_manifest(c, 'vol1', lock_file)
            self.assertEquals(m, expected)

            self.assertEquals(m.get_backup(1), vol1)
            self.assertEquals(m.get_backup('1'), vol1_str)
            self.assertEquals(vol1, vol1_str)
            self.assertEquals(m.get_backup('id2'), vol2)
コード例 #5
0
ファイル: test_manifest.py プロジェクト: audip/lunr
    def test_integer_backup_id(self):
        size = 2
        m = manifest.Manifest.blank(size)
        backup = m.create_backup(0)
        for blockno in range(size):
            backup[blockno] = '0000'
        backup = m.create_backup(1)
        for blockno in range(0, size, 10):
            backup[blockno] = '1111'
        backup = m.create_backup('id2')
        for blockno in range(0, size, 10):
            backup[blockno] = '2222'

        c = MockConnection()
        with temp_disk_file() as lock_file:
            manifest.save_manifest(m, c, 'vol1', lock_file)

            expected = dict(m)
            vol1 = m.get_backup(1)
            vol1_str = m.get_backup('1')
            vol2 = m.get_backup('id2')

            m = manifest.load_manifest(c, 'vol1', lock_file)
            self.assertEquals(m, expected)

            self.assertEquals(m.get_backup(1), vol1)
            self.assertEquals(m.get_backup('1'), vol1_str)
            self.assertEquals(vol1, vol1_str)
            self.assertEquals(m.get_backup('id2'), vol2)
コード例 #6
0
ファイル: test_manifest.py プロジェクト: pombredanne/lunr
 def test_version_mismatch(self):
     m = manifest.Manifest.blank(1)
     c = MockConnection()
     stuff = {0: [], 'backups': {}, 'version': '2.0'}
     c.put_object('vol1', 'manifest', json.dumps(stuff))
     with temp_disk_file() as lock_file:
         self.assertRaises(manifest.ManifestVersionError,
                           manifest.load_manifest, c, 'vol1', lock_file)
コード例 #7
0
ファイル: test_config.py プロジェクト: pombredanne/lunr
 def test_parse_syntax_error(self):
     conf_str = dedent(
         """
         DEFAULT]
         foo = bar
         """
     )
     with temp_disk_file(conf_str) as file:
         self.assertRaises(InvalidConfigError, LunrConfig.from_conf, file)
コード例 #8
0
ファイル: test_manifest.py プロジェクト: pombredanne/lunr
 def test_load_default_salt(self):
     m = manifest.Manifest.blank(1)
     c = MockConnection()
     salt = 'salty!'
     stuff = {0: [], 'backups': {}, 'version': '1.0'}
     c.put_object('vol1', 'manifest', json.dumps(stuff))
     with temp_disk_file() as lock_file:
         m = manifest.load_manifest(c, 'vol1', lock_file)
     self.assertEquals(m.salt, '')
コード例 #9
0
ファイル: test_manifest.py プロジェクト: audip/lunr
 def test_version_mismatch(self):
     m = manifest.Manifest.blank(1)
     c = MockConnection()
     stuff = {
         0: [],
         'backups': {},
         'version': '2.0'
     }
     c.put_object('vol1', 'manifest', json.dumps(stuff))
     with temp_disk_file() as lock_file:
         self.assertRaises(manifest.ManifestVersionError,
                           manifest.load_manifest, c, 'vol1', lock_file)
コード例 #10
0
ファイル: test_config.py プロジェクト: rackerlabs/lunr
 def test_from_storage_conf(self):
     conf_str = dedent("""
         [DEFAULT]
         foo = bar
         """)
     with temp_disk_file(conf_str) as file:
         with patch(LunrConfig, 'lunr_storage_config', file):
             conf = LunrConfig.from_storage_conf()
             self.assertEquals(conf.lunr_storage_config, file)
             self.assertEquals(conf.string('default', '__file__', ''),
                               conf.lunr_storage_config)
             self.assertEquals(conf.string('default', 'foo', ''), 'bar')
コード例 #11
0
ファイル: test_manifest.py プロジェクト: audip/lunr
 def test_load_default_salt(self):
     m = manifest.Manifest.blank(1)
     c = MockConnection()
     salt = 'salty!'
     stuff = {
         0: [],
         'backups': {},
         'version': '1.0'
     }
     c.put_object('vol1', 'manifest', json.dumps(stuff))
     with temp_disk_file() as lock_file:
         m = manifest.load_manifest(c, 'vol1', lock_file)
     self.assertEquals(m.salt, '')
コード例 #12
0
ファイル: test_config.py プロジェクト: pombredanne/lunr
 def test_from_storage_conf(self):
     conf_str = dedent(
         """
         [DEFAULT]
         foo = bar
         """
     )
     with temp_disk_file(conf_str) as file:
         with patch(LunrConfig, 'lunr_storage_config', file):
             conf = LunrConfig.from_storage_conf()
             self.assertEquals(conf.lunr_storage_config, file)
             self.assertEquals(conf.string('default', '__file__', ''),
                               conf.lunr_storage_config)
             self.assertEquals(conf.string('default', 'foo', ''), 'bar')
コード例 #13
0
ファイル: test_config.py プロジェクト: rackerlabs/lunr
 def test_case_sensitive_parser(self):
     conf_str = dedent("""
         [vtype-mapping]
         SATA = STANDARD
         SSD = HIGH
         """)
     with temp_disk_file(conf_str) as f:
         conf = LunrConfig.from_conf(f)
         section = conf.section('vtype-mapping')
         expected = {
             'SATA': 'STANDARD',
             'SSD': 'HIGH',
         }
         self.assertEquals(section, expected)
コード例 #14
0
ファイル: test_config.py プロジェクト: pombredanne/lunr
 def test_case_sensitive_parser(self):
     conf_str = dedent(
         """
         [vtype-mapping]
         SATA = STANDARD
         SSD = HIGH
         """
     )
     with temp_disk_file(conf_str) as f:
         conf = LunrConfig.from_conf(f)
         section = conf.section('vtype-mapping')
         expected = {
             'SATA': 'STANDARD',
             'SSD': 'HIGH',
         }
         self.assertEquals(section, expected)
コード例 #15
0
ファイル: test_manifest.py プロジェクト: pombredanne/lunr
    def test_basic_store(self):
        size = 2
        m = manifest.Manifest.blank(size)
        backup = m.create_backup('id0')
        for blockno in range(size):
            backup[blockno] = '0000'
        backup = m.create_backup('id1')
        for blockno in range(0, size, 10):
            backup[blockno] = '1111'

        c = MockConnection()
        with temp_disk_file() as lock_file:
            manifest.save_manifest(m, c, 'vol1', lock_file)

            expected = dict(m)
            vol1 = m.get_backup('id1')

            m = manifest.load_manifest(c, 'vol1', lock_file)
            self.assertEquals(m, expected)
            self.assertEquals(m.get_backup('id1'), vol1)
            self.assertEquals(m.version, self.VERSION)
コード例 #16
0
ファイル: test_manifest.py プロジェクト: audip/lunr
    def test_basic_store(self):
        size = 2
        m = manifest.Manifest.blank(size)
        backup = m.create_backup('id0')
        for blockno in range(size):
            backup[blockno] = '0000'
        backup = m.create_backup('id1')
        for blockno in range(0, size, 10):
            backup[blockno] = '1111'

        c = MockConnection()
        with temp_disk_file() as lock_file:
            manifest.save_manifest(m, c, 'vol1', lock_file)

            expected = dict(m)
            vol1 = m.get_backup('id1')

            m = manifest.load_manifest(c, 'vol1', lock_file)
            self.assertEquals(m, expected)
            self.assertEquals(m.get_backup('id1'), vol1)
            self.assertEquals(m.version, self.VERSION)