summaryrefslogtreecommitdiffstats
path: root/tests/formats/simpleconfig.py
blob: 887dd5d38fcc0af71062f1e372016be93755cf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: UTF-8 -*-
# Copyright 2015 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""Testing simpleconfig format"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"

from os.path import join, dirname as d; execfile(join(d(d((__file__))), '_go'))

from unittest import TestCase

from .format_manager import FormatManager
simpleconfig = FormatManager.init_lookup('simpleconfig').formats['simpleconfig']


class FormatsSimpleConfigTestCase(TestCase):

    bytestring = """\
nodelist {
	node {
		nodeid: 1
		ring0_addr: virt-063
	}
	node {
		nodeid: 2
		ring0_addr: virt-064
	}
	node {
		nodeid: 3
		ring0_addr: virt-069
	}
}
quorum {
	provider: corosync_votequorum
}
totem {
	cluster_name: STSRHTS29624
	consensus: 600
	join: 60
	key: _NOT_SECRET--f646V_a6vNwwvqYSy4cYSxPp1DizBakKJ9UULEAXswc
	token: 3000
	version: 2
}
"""

    struct = \
        ('',
          [],
          [('nodelist',
            [],
            [('node', [('nodeid', '1'), ('ring0_addr', 'virt-063')], []),
             ('node', [('nodeid', '2'), ('ring0_addr', 'virt-064')], []),
             ('node', [('nodeid', '3'), ('ring0_addr', 'virt-069')], [])]),
           ('quorum', [('provider', 'corosync_votequorum')], []),
           ('totem',
            [('cluster_name', 'STSRHTS29624'),
             ('consensus', '600'),
             ('join', '60'),
             ('key', '_NOT_SECRET--f646V_a6vNwwvqYSy4cYSxPp1DizBakKJ9UULEAXswc'),
             ('token', '3000'),
             ('version', '2')],
            [])]
        )

    def testStruct2Bytestring(self):
        sc = simpleconfig('struct', self.struct)
        #print sc.BYTESTRING()
        self.assertEqual(sc.BYTESTRING(), self.bytestring)

    def testBytestring2Struct(self):
        sc = simpleconfig('bytestring', self.bytestring)
        #from pprint import pprint
        #pprint(sc.STRUCT())
        self.assertEqual(sc.STRUCT(), self.struct)


from os.path import join, dirname as d; execfile(join(d(d(__file__)), '_gone'))