コード例 #1
0
ファイル: test_stonith.py プロジェクト: jgrund/pcs
    def testNoStonithWarning(self):
        o, r = pcs(temp_cib, "status")
        assert "WARNING: no stonith devices and " in o

        o, r = pcs(
            temp_cib,
            "stonith create test_stonith fence_apc ipaddr=ip login=lgn,  pcmk_host_argument=node1"
        )
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "status")
        assert "WARNING: no stonith devices and " not in o

        self.assert_pcs_success("stonith delete test_stonith",
                                "Deleting Resource - test_stonith\n")

        o, r = pcs(
            temp_cib,
            "stonith create test_stonith fence_apc ipaddr=ip login=lgn,  pcmk_host_argument=node1"
        )
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "status")
        assert "WARNING: no stonith devices and " not in o
コード例 #2
0
ファイル: test_cluster.py プロジェクト: junaruga/pcs
    def test_node_add_rhel6_missing_fence_pcmk(self):
        if not utils.is_rhel6():
            return

        # chnage the fence device name to a value different that set by pcs
        with open(cluster_conf_file, "r") as f:
            data = f.read()
        data = data.replace('agent="fence_pcmk"', 'agent="fence_whatever"')
        with open(cluster_conf_tmp, "w") as f:
            f.write(data)

        # test a node is added correctly and uses the fence device
        output, returnVal = pcs(
            temp_cib,
            "cluster localnode add --cluster_conf={0} rh7-3.localhost"
            .format(cluster_conf_tmp)
        )
        ac(output, "rh7-3.localhost: successfully added!\n")
        self.assertEqual(returnVal, 0)
        with open(cluster_conf_tmp) as f:
            data = f.read()
            ac(data, """\
<cluster config_version="14" name="test99">
  <fence_daemon/>
  <clusternodes>
    <clusternode name="rh7-1" nodeid="1">
      <fence>
        <method name="pcmk-method">
          <device name="pcmk-redirect" port="rh7-1"/>
        </method>
      </fence>
    </clusternode>
    <clusternode name="rh7-2" nodeid="2">
      <fence>
        <method name="pcmk-method">
          <device name="pcmk-redirect" port="rh7-2"/>
        </method>
      </fence>
    </clusternode>
    <clusternode name="rh7-3.localhost" nodeid="3">
      <fence>
        <method name="pcmk-method">
          <device name="pcmk-redirect-1" port="rh7-3.localhost"/>
        </method>
      </fence>
    </clusternode>
  </clusternodes>
  <cman broadcast="no" transport="udpu"/>
  <fencedevices>
    <fencedevice agent="fence_whatever" name="pcmk-redirect"/>
    <fencedevice agent="fence_pcmk" name="pcmk-redirect-1"/>
  </fencedevices>
  <rm>
    <failoverdomains/>
    <resources/>
  </rm>
</cluster>
""")
コード例 #3
0
ファイル: test_cluster.py プロジェクト: junaruga/pcs
    def testNodeStandby(self):
        # only basic test, standby subcommands were moved to 'pcs node'
        output, returnVal = pcs(temp_cib, "cluster standby rh7-1")
        ac(output, "")
        assert returnVal == 0

        output, returnVal = pcs(temp_cib, "cluster unstandby rh7-1")
        ac(output, "")
        assert returnVal == 0
コード例 #4
0
 def test_empty_section(self):
     section = config_parser.Section("mySection")
     self.assertEqual(section.parent, None)
     self.assertEqual(section.get_root(), section)
     self.assertEqual(section.name, "mySection")
     self.assertEqual(section.get_attributes(), [])
     self.assertEqual(section.get_sections(), [])
     self.assertTrue(section.empty)
     ac(str(section), "")
コード例 #5
0
    def test_comment(self):
        string = """\
# junk1
name1: value1
  #junk2
name2: value2#junk3
name3: value3 #junk4
name4 # junk5: value4
#junk6 name5: value5
#junk7
"""
        parsed = """\
name1: value1
name2: value2#junk3
name3: value3 #junk4
name4 # junk5: value4
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
# junk1
section1 { # junk2
}
section2 # junk2 {
}
section3 {
} #junk3
"""
        parsed = """\
section1 {
}

section2 # junk2 {
}

section3 {
}
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
section {
#}
"""
        self.assertRaises(config_parser.MissingClosingBraceException,
                          config_parser.parse_string, string)

        string = """\
#section {
}
"""
        self.assertRaises(config_parser.UnexpectedClosingBraceException,
                          config_parser.parse_string, string)
コード例 #6
0
    def test_attributes(self):
        string = """\
name:value\
"""
        parsed = """\
name: value
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
name:value
name:value
"""
        parsed = """\
name: value
name: value
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
  name1:value1  
name2  :value2
name3:  value3
  name4  :  value4  
"""
        parsed = """\
name1: value1
name2: value2
name3: value3
name4: value4
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
name:foo:value
"""
        parsed = """\
name: foo:value
"""
        root = config_parser.parse_string(string)
        self.assertEqual(root.get_attributes(), [["name", "foo:value"]])
        ac(str(root), parsed)

        string = """\
name :  
"""
        parsed = """\
name: 
"""
        root = config_parser.parse_string(string)
        self.assertEqual(root.get_attributes(), [["name", ""]])
        ac(str(root), parsed)
コード例 #7
0
ファイル: test_stonith.py プロジェクト: jgrund/pcs
    def testPcmkHostList(self):
        self.assert_pcs_success(
            "stonith create F1 fence_apc 'pcmk_host_list=nodea nodeb' --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )

        output, returnVal = pcs(temp_cib, "stonith show F1")
        ac(
            output, """\
 Resource: F1 (class=stonith type=fence_apc)
  Attributes: pcmk_host_list="nodea nodeb"
  Operations: monitor interval=60s (F1-monitor-interval-60s)
""")
        assert returnVal == 0
コード例 #8
0
ファイル: test_stonith.py プロジェクト: jgrund/pcs
    def testPcmkHostAllowsMissingPort(self):
        # Test that port is not required when pcmk_host_argument or
        # pcmk_host_list or pcmk_host_map is specified
        # Port is temporarily an optional parameter. Once we are getting
        # metadata from pacemaker, this will be reviewed and fixed.
        output, returnVal = pcs(
            temp_cib, 'stonith create apc-1 fence_apc ipaddr="ip" login="******"')
        #        ac(output, """\
        #Error: missing required option(s): 'port' for resource type: stonith:fence_apc (use --force to override)
        #""")
        #        self.assertEquals(returnVal, 1)
        ac(output, "")
        self.assertEqual(returnVal, 0)

        output, returnVal = pcs(
            temp_cib,
            'stonith create apc-2 fence_apc ipaddr="ip" login="******" pcmk_host_map="buzz-01:1;buzz-02:2"'
        )
        ac(output, "")
        self.assertEqual(returnVal, 0)

        output, returnVal = pcs(
            temp_cib,
            'stonith create apc-3 fence_apc ipaddr="ip" login="******" pcmk_host_list="buzz-01,buzz-02"'
        )
        ac(output, "")
        self.assertEqual(returnVal, 0)

        output, returnVal = pcs(
            temp_cib,
            'stonith create apc-4 fence_apc ipaddr="ip" login="******" pcmk_host_argument="buzz-01"'
        )
        ac(output, "")
        self.assertEqual(returnVal, 0)
コード例 #9
0
ファイル: test_node.py プロジェクト: junaruga/pcs
    def test_node_utilization_set_invalid(self):
        output, returnVal = pcs(temp_cib, "node utilization rh7-1 test")
        expected_out = """\
Error: missing value of 'test' option
"""
        ac(expected_out, output)
        self.assertEqual(1, returnVal)

        output, returnVal = pcs(temp_cib, "node utilization rh7-1 =10")
        expected_out = """\
Error: missing key in '=10' option
"""
        ac(expected_out, output)
        self.assertEqual(1, returnVal)

        output, returnVal = pcs(temp_cib, "node utilization rh7-0 test=10")
        expected_out = """\
Error: Unable to find a node: rh7-0
"""
        ac(expected_out, output)
        self.assertEqual(1, returnVal)

        output, returnVal = pcs(temp_cib,
                                "node utilization rh7-1 test1=10 test=int")
        expected_out = """\
Error: Value of utilization attribute must be integer: 'test=int'
"""
        ac(expected_out, output)
        self.assertEqual(1, returnVal)
コード例 #10
0
ファイル: test_stonith.py プロジェクト: jgrund/pcs
    def test_stonith_create_provides_unfencing_rhel6(self):
        if not utils.is_rhel6():
            return

        output, returnVal = pcs(temp_cib,
                                "stonith create f1 fence_mpath key=abc")
        ac(output, "")
        self.assertEqual(0, returnVal)

        output, returnVal = pcs(
            temp_cib,
            "stonith create f2 fence_mpath key=abc meta provides=unfencing")
        ac(output, "")
        self.assertEqual(0, returnVal)

        output, returnVal = pcs(
            temp_cib,
            "stonith create f3 fence_mpath key=abc meta provides=something")
        ac(output, "")
        self.assertEqual(0, returnVal)

        output, returnVal = pcs(
            temp_cib, "stonith create f4 fence_xvm meta provides=something")
        ac(output, "")
        self.assertEqual(0, returnVal)

        output, returnVal = pcs(temp_cib, "stonith show --full")
        ac(
            output, """\
 Resource: f1 (class=stonith type=fence_mpath)
  Attributes: key=abc
  Meta Attrs: provides=unfencing 
  Operations: monitor interval=60s (f1-monitor-interval-60s)
 Resource: f2 (class=stonith type=fence_mpath)
  Attributes: key=abc
  Meta Attrs: provides=unfencing 
  Operations: monitor interval=60s (f2-monitor-interval-60s)
 Resource: f3 (class=stonith type=fence_mpath)
  Attributes: key=abc
  Meta Attrs: provides=unfencing 
  Operations: monitor interval=60s (f3-monitor-interval-60s)
 Resource: f4 (class=stonith type=fence_xvm)
  Meta Attrs: provides=something 
  Operations: monitor interval=60s (f4-monitor-interval-60s)
""")
        self.assertEqual(0, returnVal)
コード例 #11
0
ファイル: test_cluster.py プロジェクト: gmelikov/pcs
    def testClusterUpgrade(self):
        with open(temp_cib) as myfile:
            data = myfile.read()
            assert data.find("pacemaker-1.2") != -1
            assert data.find("pacemaker-2.") == -1

        o,r = pcs(temp_cib, "cluster cib-upgrade")
        ac(o,"Cluster CIB has been upgraded to latest version\n")
        assert r == 0

        with open(temp_cib) as myfile:
            data = myfile.read()
            assert data.find("pacemaker-1.2") == -1
            assert data.find("pacemaker-2.") == -1
            assert data.find("pacemaker-3.") != -1

        o,r = pcs(temp_cib, "cluster cib-upgrade")
        ac(o,"Cluster CIB has been upgraded to latest version\n")
        assert r == 0
コード例 #12
0
    def test_section_add(self):
        root = config_parser.Section("root")
        child1 = config_parser.Section("child1")
        child1a = config_parser.Section("child1a")
        child2 = config_parser.Section("child2")

        root.add_section(child1)
        child1.add_section(child1a)
        root.add_section(child2)
        self.assertEqual(root.parent, None)
        self.assertEqual(child1.parent.name, "root")
        self.assertEqual(child1a.parent.name, "child1")
        self.assertEqual(child2.parent.name, "root")
        ac(str(root), """\
child1 {
    child1a {
    }
}

child2 {
}
""")

        child2.add_section(child1a)
        self.assertEqual(child1a.parent.name, "child2")
        ac(str(root), """\
child1 {
}

child2 {
    child1a {
    }
}
""")

        self.assertRaises(config_parser.CircularParentshipException,
                          child1a.add_section, child1a)
        self.assertRaises(config_parser.CircularParentshipException,
                          child1a.add_section, child2)
        self.assertRaises(config_parser.CircularParentshipException,
                          child1a.add_section, root)
コード例 #13
0
    def testDefaults(self):
        output, returnVal = pcs(temp_cib, "property --defaults")
        prop_defaults = output
        assert returnVal == 0, 'Unable to list resources'
        assert output.startswith('Cluster Properties:\n batch-limit')

        output, returnVal = pcs(temp_cib, "property --all")
        assert returnVal == 0, 'Unable to list resources'
        assert output.startswith('Cluster Properties:\n batch-limit')
        ac(output, prop_defaults)

        output, returnVal = pcs(temp_cib, "property set blahblah=blah")
        assert returnVal == 1
        assert output == "Error: unknown cluster property: 'blahblah', (use --force to override)\n", [
            output
        ]

        output, returnVal = pcs(temp_cib, "property set blahblah=blah --force")
        assert returnVal == 0, output
        assert output == "", output

        output, returnVal = pcs(temp_cib, "property set stonith-enabled=false")
        assert returnVal == 0, output
        assert output == "", output

        output, returnVal = pcs(temp_cib, "property")
        assert returnVal == 0
        assert output == "Cluster Properties:\n blahblah: blah\n stonith-enabled: false\n", [
            output
        ]

        output, returnVal = pcs(temp_cib, "property --defaults")
        assert returnVal == 0, 'Unable to list resources'
        assert output.startswith('Cluster Properties:\n batch-limit')
        ac(output, prop_defaults)

        output, returnVal = pcs(temp_cib, "property --all")
        assert returnVal == 0, 'Unable to list resources'
        assert "blahblah: blah" in output
        assert "stonith-enabled: false" in output
        assert output.startswith('Cluster Properties:\n batch-limit')
コード例 #14
0
    def testUserGroupCreateDelete(self):
        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, "ACLs are disabled, run 'pcs acl enable' to enable\n\n")

        o, r = pcs(temp_cib, "acl user create user1")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl user create user2")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl user create user1")
        assert r == 1
        ac(o, "Error: 'user1' already exists\n")

        o, r = pcs(temp_cib, "acl group create group1")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl group create group2")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl group create group1")
        assert r == 1
        ac(o, "Error: 'group1' already exists\n")

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
User: user2
  Roles:
Group: group1
  Roles:
Group: group2
  Roles:
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl group delete user1")
        assert r == 1
        ac(o, "Error: 'user1' is not an ACL group\n")

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
User: user2
  Roles:
Group: group1
  Roles:
Group: group2
  Roles:
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl group delete group2")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
User: user2
  Roles:
Group: group1
  Roles:
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl group remove group1")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
User: user2
  Roles:
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl user delete user1")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user2
  Roles:
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl user remove user2")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, "ACLs are disabled, run 'pcs acl enable' to enable\n\n")
コード例 #15
0
    def testEnableDisable(self):
        o, r = pcs(temp_cib, "acl disable")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, "ACLs are disabled, run 'pcs acl enable' to enable\n\n")

        o, r = pcs(temp_cib, "acl enable")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, "ACLs are enabled\n\n")

        o, r = pcs(temp_cib, "acl disable")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, "ACLs are disabled, run 'pcs acl enable' to enable\n\n")
コード例 #16
0
    def test_set_property_validation_integer(self):
        output, returnVal = pcs(temp_cib, "property set migration-limit=0")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 migration-limit: 0
""")

        output, returnVal = pcs(temp_cib, "property set migration-limit=-10")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 migration-limit: -10
""")

        output, returnVal = pcs(temp_cib,
                                "property set migration-limit=0 --force")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 migration-limit: 0
""")

        output, returnVal = pcs(temp_cib, "property set migration-limit=0.1")
        ac(
            output, "Error: invalid value of property: "
            "'migration-limit=0.1', (use --force to override)\n")
        self.assertEqual(returnVal, 1)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 migration-limit: 0
""")

        output, returnVal = pcs(temp_cib,
                                "property set migration-limit=0.1 --force")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 migration-limit: 0.1
""")
コード例 #17
0
ファイル: test_stonith.py プロジェクト: jgrund/pcs
    def testStonithCreation(self):
        output, returnVal = pcs(temp_cib, "stonith create test1 fence_noxist")
        ac(
            output,
            "Error: Agent 'fence_noxist' is not installed or does not provide valid metadata: Metadata query for stonith:fence_noxist failed: -5, use --force to override\n"
        )
        assert returnVal == 1

        output, returnVal = pcs(temp_cib,
                                "stonith create test1 fence_noxist --force")
        ac(
            output,
            "Warning: Agent 'fence_noxist' is not installed or does not provide valid metadata: Metadata query for stonith:fence_noxist failed: -5\n"
        )
        self.assertEqual(returnVal, 0)

        self.assert_pcs_fail(
            "stonith create test2 fence_apc",
            "Error: required stonith options 'ipaddr', 'login' are missing, use --force to override\n"
        )

        self.assert_pcs_success(
            "stonith create test2 fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )

        self.assert_pcs_fail(
            "stonith create test3 fence_apc bad_argument=test",
            stdout_start="Error: invalid stonith option 'bad_argument',"
            " allowed options are:")

        self.assert_pcs_fail(
            "stonith create test9 fence_apc pcmk_status_action=xxx",
            "Error: required stonith options 'ipaddr', 'login' are missing, use --force to override\n"
        )

        self.assert_pcs_success(
            "stonith create test9 fence_apc pcmk_status_action=xxx --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )

        output, returnVal = pcs(temp_cib, "stonith show test9")
        ac(
            output, """\
 Resource: test9 (class=stonith type=fence_apc)
  Attributes: pcmk_status_action=xxx
  Operations: monitor interval=60s (test9-monitor-interval-60s)
""")
        assert returnVal == 0

        self.assert_pcs_success("stonith delete test9",
                                "Deleting Resource - test9\n")

        self.assert_pcs_fail(
            "stonith create test3 fence_ilo ipaddr=test",
            "Error: required stonith option 'login' is missing, use --force to override\n"
        )

        self.assert_pcs_success(
            "stonith create test3 fence_ilo ipaddr=test --force",
            "Warning: required stonith option 'login' is missing\n")

        # Testing that pcmk_host_check, pcmk_host_list & pcmk_host_map are allowed for
        # stonith agents
        self.assert_pcs_success(
            'stonith create apc-fencing fence_apc ipaddr="morph-apc" login="******" passwd="apc" switch="1" pcmk_host_map="buzz-01:1;buzz-02:2;buzz-03:3;buzz-04:4;buzz-05:5" pcmk_host_check="static-list" pcmk_host_list="buzz-01,buzz-02,buzz-03,buzz-04,buzz-05"',
        )

        output, returnVal = pcs(temp_cib, 'resource show apc-fencing')
        assert returnVal == 1
        assert output == 'Error: unable to find resource \'apc-fencing\'\n', [
            output
        ]

        self.assert_pcs_success(
            "stonith show apc-fencing",
            outdent("""\
             Resource: apc-fencing (class=stonith type=fence_apc)
              Attributes: ipaddr="morph-apc" login="******" passwd="apc" pcmk_host_check="static-list" pcmk_host_list="buzz-01,buzz-02,buzz-03,buzz-04,buzz-05" pcmk_host_map="buzz-01:1;buzz-02:2;buzz-03:3;buzz-04:4;buzz-05:5" switch="1"
              Operations: monitor interval=60s (apc-fencing-monitor-interval-60s)
            """))

        self.assert_pcs_success("stonith delete apc-fencing",
                                "Deleting Resource - apc-fencing\n")

        self.assert_pcs_fail(
            "stonith update test3 bad_ipaddr=test",
            stdout_regexp=(
                "^Error: invalid stonith option 'bad_ipaddr', allowed options"
                " are: [^\n]+, use --force to override\n$"))

        output, returnVal = pcs(temp_cib, "stonith update test3 login=testA")
        assert returnVal == 0
        assert output == "", [output]

        output, returnVal = pcs(temp_cib, "stonith show test2")
        assert returnVal == 0
        assert output == " Resource: test2 (class=stonith type=fence_apc)\n  Operations: monitor interval=60s (test2-monitor-interval-60s)\n", [
            output
        ]

        output, returnVal = pcs(temp_cib, "stonith show --full")
        ac(
            output, """\
 Resource: test1 (class=stonith type=fence_noxist)
  Operations: monitor interval=60s (test1-monitor-interval-60s)
 Resource: test2 (class=stonith type=fence_apc)
  Operations: monitor interval=60s (test2-monitor-interval-60s)
 Resource: test3 (class=stonith type=fence_ilo)
  Attributes: ipaddr=test login=testA
  Operations: monitor interval=60s (test3-monitor-interval-60s)
""")
        assert returnVal == 0

        self.assert_pcs_success(
            "stonith create test-fencing fence_apc 'pcmk_host_list=rhel7-node1 rhel7-node2' op monitor interval=61s --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )

        self.assert_pcs_success(
            "config show",
            outdent("""\
            Cluster Name: test99
            Corosync Nodes:
             rh7-1 rh7-2
            Pacemaker Nodes:

            Resources:

            Stonith Devices:
             Resource: test1 (class=stonith type=fence_noxist)
              Operations: monitor interval=60s (test1-monitor-interval-60s)
             Resource: test2 (class=stonith type=fence_apc)
              Operations: monitor interval=60s (test2-monitor-interval-60s)
             Resource: test3 (class=stonith type=fence_ilo)
              Attributes: ipaddr=test login=testA
              Operations: monitor interval=60s (test3-monitor-interval-60s)
             Resource: test-fencing (class=stonith type=fence_apc)
              Attributes: pcmk_host_list="rhel7-node1 rhel7-node2"
              Operations: monitor interval=61s (test-fencing-monitor-interval-61s)
            Fencing Levels:

            Location Constraints:
            Ordering Constraints:
            Colocation Constraints:
            Ticket Constraints:

            Alerts:
             No alerts defined

            Resources Defaults:
             No defaults set
            Operations Defaults:
             No defaults set

            Cluster Properties:

            Quorum:
              Options:
            """))
コード例 #18
0
    def test_section_get(self):
        root = config_parser.Section("")
        child1 = config_parser.Section("child1")
        child2 = config_parser.Section("child2")
        childa1 = config_parser.Section("childA")
        childa2 = config_parser.Section("childA")
        childa3 = config_parser.Section("childA")
        childa4 = config_parser.Section("childA")
        childb1 = config_parser.Section("childB")
        childb2 = config_parser.Section("childB")
        childa1.add_attribute("id", "1")
        childa2.add_attribute("id", "2")
        childa3.add_attribute("id", "3")
        childa4.add_attribute("id", "4")
        childb1.add_attribute("id", "5")
        childb2.add_attribute("id", "6")
        root.add_section(child1)
        root.add_section(child2)
        child1.add_section(childa1)
        child1.add_section(childa2)
        child1.add_section(childb1)
        child2.add_section(childa3)
        child2.add_section(childb2)
        child2.add_section(childa4)
        ac(
            str(root), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }

    childB {
        id: 5
    }
}

child2 {
    childA {
        id: 3
    }

    childB {
        id: 6
    }

    childA {
        id: 4
    }
}
""")

        ac(
            "---\n".join([str(x) for x in root.get_sections()]), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }

    childB {
        id: 5
    }
}
---
child2 {
    childA {
        id: 3
    }

    childB {
        id: 6
    }

    childA {
        id: 4
    }
}
""")

        ac(
            "---\n".join([str(x) for x in root.get_sections("child1")]), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }

    childB {
        id: 5
    }
}
""")

        ac("---\n".join([str(x) for x in child1.get_sections("childA")]), """\
childA {
    id: 1
}
---
childA {
    id: 2
}
""")

        ac("---\n".join([str(x) for x in child1.get_sections("child2")]), "")
コード例 #19
0
ファイル: test_stonith.py プロジェクト: jgrund/pcs
    def testStonithDeleteRemovesLevel(self):
        shutil.copy(rc("cib-empty-with3nodes.xml"), temp_cib)

        self.assert_pcs_success(
            "stonith create n1-ipmi fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success(
            "stonith create n2-ipmi fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success(
            "stonith create n1-apc1 fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success(
            "stonith create n1-apc2 fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success(
            "stonith create n2-apc1 fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success(
            "stonith create n2-apc2 fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success(
            "stonith create n2-apc3 fence_apc --force",
            "Warning: required stonith options 'ipaddr', 'login' are missing\n"
        )
        self.assert_pcs_success_all([
            "stonith level add 1 rh7-1 n1-ipmi",
            "stonith level add 2 rh7-1 n1-apc1,n1-apc2,n2-apc2",
            "stonith level add 1 rh7-2 n2-ipmi",
            "stonith level add 2 rh7-2 n2-apc1,n2-apc2,n2-apc3",
        ])

        output, returnVal = pcs(temp_cib, "stonith")
        self.assertEqual(returnVal, 0)
        ac(
            output, """\
 n1-ipmi\t(stonith:fence_apc):\tStopped
 n2-ipmi\t(stonith:fence_apc):\tStopped
 n1-apc1\t(stonith:fence_apc):\tStopped
 n1-apc2\t(stonith:fence_apc):\tStopped
 n2-apc1\t(stonith:fence_apc):\tStopped
 n2-apc2\t(stonith:fence_apc):\tStopped
 n2-apc3\t(stonith:fence_apc):\tStopped
 Target: rh7-1
   Level 1 - n1-ipmi
   Level 2 - n1-apc1,n1-apc2,n2-apc2
 Target: rh7-2
   Level 1 - n2-ipmi
   Level 2 - n2-apc1,n2-apc2,n2-apc3
""")

        self.assert_pcs_success("stonith delete n2-apc2",
                                "Deleting Resource - n2-apc2\n")

        output, returnVal = pcs(temp_cib, "stonith")
        self.assertEqual(returnVal, 0)
        ac(
            output, """\
 n1-ipmi\t(stonith:fence_apc):\tStopped
 n2-ipmi\t(stonith:fence_apc):\tStopped
 n1-apc1\t(stonith:fence_apc):\tStopped
 n1-apc2\t(stonith:fence_apc):\tStopped
 n2-apc1\t(stonith:fence_apc):\tStopped
 n2-apc3\t(stonith:fence_apc):\tStopped
 Target: rh7-1
   Level 1 - n1-ipmi
   Level 2 - n1-apc1,n1-apc2
 Target: rh7-2
   Level 1 - n2-ipmi
   Level 2 - n2-apc1,n2-apc3
""")

        self.assert_pcs_success("stonith delete n2-apc1",
                                "Deleting Resource - n2-apc1\n")

        output, returnVal = pcs(temp_cib, "stonith")
        self.assertEqual(returnVal, 0)
        ac(
            output, """\
 n1-ipmi\t(stonith:fence_apc):\tStopped
 n2-ipmi\t(stonith:fence_apc):\tStopped
 n1-apc1\t(stonith:fence_apc):\tStopped
 n1-apc2\t(stonith:fence_apc):\tStopped
 n2-apc3\t(stonith:fence_apc):\tStopped
 Target: rh7-1
   Level 1 - n1-ipmi
   Level 2 - n1-apc1,n1-apc2
 Target: rh7-2
   Level 1 - n2-ipmi
   Level 2 - n2-apc3
""")

        self.assert_pcs_success("stonith delete n2-apc3",
                                "Deleting Resource - n2-apc3\n")

        output, returnVal = pcs(temp_cib, "stonith")
        self.assertEqual(returnVal, 0)
        ac(
            output, """\
 n1-ipmi\t(stonith:fence_apc):\tStopped
 n2-ipmi\t(stonith:fence_apc):\tStopped
 n1-apc1\t(stonith:fence_apc):\tStopped
 n1-apc2\t(stonith:fence_apc):\tStopped
 Target: rh7-1
   Level 1 - n1-ipmi
   Level 2 - n1-apc1,n1-apc2
 Target: rh7-2
   Level 1 - n2-ipmi
""")

        self.assert_pcs_success("resource delete n1-apc1",
                                "Deleting Resource - n1-apc1\n")

        output, returnVal = pcs(temp_cib, "stonith")
        self.assertEqual(returnVal, 0)
        ac(
            output, """\
 n1-ipmi\t(stonith:fence_apc):\tStopped
 n2-ipmi\t(stonith:fence_apc):\tStopped
 n1-apc2\t(stonith:fence_apc):\tStopped
 Target: rh7-1
   Level 1 - n1-ipmi
   Level 2 - n1-apc2
 Target: rh7-2
   Level 1 - n2-ipmi
""")

        self.assert_pcs_success(
            "resource delete n1-apc2",
            outdent("""\
            Deleting Resource - n1-apc2
            """))

        output, returnVal = pcs(temp_cib, "stonith")
        self.assertEqual(returnVal, 0)
        ac(
            output, """\
 n1-ipmi\t(stonith:fence_apc):\tStopped
 n2-ipmi\t(stonith:fence_apc):\tStopped
 Target: rh7-1
   Level 1 - n1-ipmi
 Target: rh7-2
   Level 1 - n2-ipmi
""")
コード例 #20
0
    def test_str(self):
        root = config_parser.Section("root")
        ac(str(root), "")

        root.add_attribute("name1", "value1")
        ac(str(root), "name1: value1\n")

        root.add_attribute("name2", "value2")
        root.add_attribute("name2", "value2a")
        root.add_attribute("name3", "value3")
        ac(str(root), """\
name1: value1
name2: value2
name2: value2a
name3: value3
""")

        child1 = config_parser.Section("child1")
        root.add_section(child1)
        ac(
            str(root), """\
name1: value1
name2: value2
name2: value2a
name3: value3

child1 {
}
""")

        child1.add_attribute("name1.1", "value1.1")
        child1.add_attribute("name1.2", "value1.2")
        ac(
            str(root), """\
name1: value1
name2: value2
name2: value2a
name3: value3

child1 {
    name1.1: value1.1
    name1.2: value1.2
}
""")

        child2 = config_parser.Section("child2")
        child2.add_attribute("name2.1", "value2.1")
        root.add_section(child2)
        ac(
            str(root), """\
name1: value1
name2: value2
name2: value2a
name3: value3

child1 {
    name1.1: value1.1
    name1.2: value1.2
}

child2 {
    name2.1: value2.1
}
""")

        child2a = config_parser.Section("child2a")
        child2a.add_attribute("name2.a.1", "value2.a.1")
        child2.add_section(child2a)
        ac(
            str(root), """\
name1: value1
name2: value2
name2: value2a
name3: value3

child1 {
    name1.1: value1.1
    name1.2: value1.2
}

child2 {
    name2.1: value2.1

    child2a {
        name2.a.1: value2.a.1
    }
}
""")

        child3 = config_parser.Section("child3")
        root.add_section(child3)
        child3.add_section(config_parser.Section("child3a"))
        child3.add_section(config_parser.Section("child3b"))
        ac(
            str(root), """\
name1: value1
name2: value2
name2: value2a
name3: value3

child1 {
    name1.1: value1.1
    name1.2: value1.2
}

child2 {
    name2.1: value2.1

    child2a {
        name2.a.1: value2.a.1
    }
}

child3 {
    child3a {
    }

    child3b {
    }
}
""")
コード例 #21
0
    def test_section_del(self):
        root = config_parser.Section("")
        child1 = config_parser.Section("child1")
        child2 = config_parser.Section("child2")
        childa1 = config_parser.Section("childA")
        childa2 = config_parser.Section("childA")
        childa3 = config_parser.Section("childA")
        childa4 = config_parser.Section("childA")
        childb1 = config_parser.Section("childB")
        childb2 = config_parser.Section("childB")
        childa1.add_attribute("id", "1")
        childa2.add_attribute("id", "2")
        childa3.add_attribute("id", "3")
        childa4.add_attribute("id", "4")
        childb1.add_attribute("id", "5")
        childb2.add_attribute("id", "6")
        root.add_section(child1)
        root.add_section(child2)
        child1.add_section(childa1)
        child1.add_section(childa2)
        child1.add_section(childb1)
        child2.add_section(childa3)
        child2.add_section(childb2)
        child2.add_section(childa4)
        ac(
            str(root), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }

    childB {
        id: 5
    }
}

child2 {
    childA {
        id: 3
    }

    childB {
        id: 6
    }

    childA {
        id: 4
    }
}
""")

        child2.del_section(childb2)
        self.assertEqual(childb2.parent, None)
        ac(
            str(root), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }

    childB {
        id: 5
    }
}

child2 {
    childA {
        id: 3
    }

    childA {
        id: 4
    }
}
""")

        root.del_section(child2)
        self.assertEqual(child2.parent, None)
        ac(
            str(root), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }

    childB {
        id: 5
    }
}
""")

        self.assertRaises(ValueError, root.del_section, child2)

        self.assertEqual(childa1.parent.name, "child1")
        self.assertRaises(ValueError, child2.del_section, childa1)
        self.assertEqual(childa1.parent.name, "child1")

        child1.del_section(childb1)
        self.assertEqual(childb1.parent, None)
        ac(
            str(root), """\
child1 {
    childA {
        id: 1
    }

    childA {
        id: 2
    }
}
""")

        child1.del_section(childa1)
        self.assertEqual(childa1.parent, None)
        child1.del_section(childa2)
        self.assertEqual(childa2.parent, None)
        ac(str(root), """\
child1 {
}
""")

        root.del_section(child1)
        self.assertEqual(child1.parent, None)
        ac(str(root), "")
コード例 #22
0
    def testBadProperties(self):
        o, r = pcs(temp_cib, "property set xxxx=zzzz")
        self.assertEqual(r, 1)
        ac(
            o,
            "Error: unknown cluster property: 'xxxx', (use --force to override)\n"
        )
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")

        output, returnVal = pcs(temp_cib, "property set =5678 --force")
        ac(output, "Error: empty property name: '=5678'\n")
        self.assertEqual(returnVal, 1)
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")

        output, returnVal = pcs(temp_cib, "property set =5678")
        ac(output, "Error: empty property name: '=5678'\n")
        self.assertEqual(returnVal, 1)
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")

        output, returnVal = pcs(temp_cib, "property set bad_format")
        ac(output, "Error: invalid property format: 'bad_format'\n")
        self.assertEqual(returnVal, 1)
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")

        output, returnVal = pcs(temp_cib, "property set bad_format --force")
        ac(output, "Error: invalid property format: 'bad_format'\n")
        self.assertEqual(returnVal, 1)
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")

        o, r = pcs(temp_cib, "property unset zzzzz")
        self.assertEqual(r, 1)
        ac(o, "Error: can't remove property: 'zzzzz' that doesn't exist\n")
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")

        o, r = pcs(temp_cib, "property unset zzzz --force")
        self.assertEqual(r, 0)
        ac(o, "")
        o, _ = pcs(temp_cib, "property list")
        ac(o, "Cluster Properties:\n")
コード例 #23
0
    def testRoleCreateDelete(self):
        o, r = pcs(temp_cib, "acl role create role0 read")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 read //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 read xpath")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 read id")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 readX xpath //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 read xpathX //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 description=test read")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(
            temp_cib,
            "acl role create role0 description=test read //resources"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(
            temp_cib,
            "acl role create role0 description=test read xpath"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 description=test read id")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib,
            "acl role create role0 description=test readX xpath //resources"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib,
            "acl role create role0 description=test read xpathX //resources"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 desc=test read")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 desc=test read //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 desc=test read xpath")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl role create role0 desc=test read id")
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(
            temp_cib,
            "acl role create role0 desc=test readX xpath //resources"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(
            temp_cib,
            "acl role create role0 desc=test read xpathX //resources"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl role create..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl")
        ac(o, "ACLs are disabled, run 'pcs acl enable' to enable\n\n")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl role create role0")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl role create role0")
        ac(o, "Error: 'role0' already exists\n")
        assert r == 1

        o, r = pcs(temp_cib, "acl role create role0d description='empty role'")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl role create role1 read xpath /xpath/")
        ac(o, "")
        assert r == 0

        o, r = pcs(
            temp_cib,
            "acl role create role2 description='with description' "
                "READ XPATH /xpath/"
        )
        assert r == 0
        ac(o, "")

        o, r = pcs(
            temp_cib,
            "acl role create role3 Read XPath /xpath_query/ wRiTe xpATH "
                "/xpath_query2/ deny xpath /xpath_query3/"
        )
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role0
Role: role0d
  Description: empty role
Role: role1
  Permission: read xpath /xpath/ (role1-read)
Role: role2
  Description: with description
  Permission: read xpath /xpath/ (role2-read)
Role: role3
  Permission: read xpath /xpath_query/ (role3-read)
  Permission: write xpath /xpath_query2/ (role3-write)
  Permission: deny xpath /xpath_query3/ (role3-deny)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role delete role2")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role0
Role: role0d
  Description: empty role
Role: role1
  Permission: read xpath /xpath/ (role1-read)
Role: role3
  Permission: read xpath /xpath_query/ (role3-read)
  Permission: write xpath /xpath_query2/ (role3-write)
  Permission: deny xpath /xpath_query3/ (role3-deny)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role delete role2")
        assert r == 1
        ac(o, "Error: ACL role 'role2' does not exist\n")

        o, r = pcs(temp_cib, "acl role delete role1")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl role remove role3")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl role remove role0")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl role remove role0d")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        ac(o, "ACLs are disabled, run 'pcs acl enable' to enable\n\n")
        assert r == 0
コード例 #24
0
    def test_set_property_validation_boolean(self):
        output, returnVal = pcs(temp_cib, "property set enable-acl=TRUE")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 enable-acl: TRUE
""")

        output, returnVal = pcs(temp_cib, "property set enable-acl=no")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 enable-acl: no
""")

        output, returnVal = pcs(temp_cib,
                                "property set enable-acl=TRUE --force")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 enable-acl: TRUE
""")

        output, returnVal = pcs(temp_cib,
                                "property set enable-acl=not_valid_value")
        ac(
            output, "Error: invalid value of property: "
            "'enable-acl=not_valid_value', (use --force to override)\n")
        self.assertEqual(returnVal, 1)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 enable-acl: TRUE
""")

        output, returnVal = pcs(
            temp_cib, "property set enable-acl=not_valid_value --force")
        ac(output, "")
        self.assertEqual(returnVal, 0)
        o, _ = pcs(temp_cib, "property list")
        ac(o, """Cluster Properties:
 enable-acl: not_valid_value
""")
コード例 #25
0
    def testPermissionAddDelete(self):
        o, r = pcs(
            temp_cib,
            "acl role create role1 read xpath /xpath1/ write xpath /xpath2/"
        )
        ac(o, "")
        assert r == 0

        o, r = pcs(
            temp_cib,
            "acl role create role2 read xpath /xpath3/ write xpath /xpath4/"
        )
        ac(o, "")
        assert r == 0

        o, r = pcs(
            temp_cib,
            "acl role create role3 read xpath /xpath5/ write xpath /xpath6/"
        )
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl show")
        assert r == 0
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: read xpath /xpath3/ (role2-read)
  Permission: write xpath /xpath4/ (role2-write)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: write xpath /xpath6/ (role3-write)
""")

        o, r = pcs(temp_cib, "acl permission add role1 deny xpath /myxpath1/")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl permission add role4 deny xpath /myxpath2/")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl show")
        assert r == 0
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
  Permission: deny xpath /myxpath1/ (role1-deny)
Role: role2
  Permission: read xpath /xpath3/ (role2-read)
  Permission: write xpath /xpath4/ (role2-write)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: write xpath /xpath6/ (role3-write)
Role: role4
  Permission: deny xpath /myxpath2/ (role4-deny)
""")

        o, r = pcs(temp_cib, "acl permission delete role4-deny")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl permission delete role4-deny")
        ac(o, "Error: ACL permission 'role4-deny' does not exist\n")
        assert r == 1

        o, r = pcs(temp_cib, "acl permission remove role4-deny")
        ac(o, "Error: ACL permission 'role4-deny' does not exist\n")
        assert r == 1

        o, r = pcs(temp_cib, "acl show")
        assert r == 0
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
  Permission: deny xpath /myxpath1/ (role1-deny)
Role: role2
  Permission: read xpath /xpath3/ (role2-read)
  Permission: write xpath /xpath4/ (role2-write)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: write xpath /xpath6/ (role3-write)
Role: role4
""")

        o, r = pcs(temp_cib, "acl permission delete role3-read")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl permission delete role3-write")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
  Permission: deny xpath /myxpath1/ (role1-deny)
Role: role2
  Permission: read xpath /xpath3/ (role2-read)
  Permission: write xpath /xpath4/ (role2-write)
Role: role3
Role: role4
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl permission remove role1-read")
        ac(o, "")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl permission remove role1-write")
        ac(o, "")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl permission remove role1-deny")
        ac(o, "")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl permission remove role2-read")
        ac(o, "")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl permission remove role2-write")
        ac(o, "")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
Role: role2
Role: role3
Role: role4
""")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl permission add role1 read")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 read //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 read xpath")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 read id")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 readX xpath //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 read xpathX //resources")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 read id dummy read")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(
            temp_cib,
            "acl permission add role1 read id dummy read //resources"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(
            temp_cib,
            "acl permission add role1 read id dummy read xpath"
        )
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl permission add role1 read id dummy read id")
        self.assertTrue(o.startswith("\nUsage: pcs acl permission add..."))
        self.assertEqual(1, r)

        self.assert_pcs_fail(
          "acl permission add role1 read id dummy readX xpath //resources",
          stdout_start='\nUsage: pcs acl permission add...'
        )

        self.assert_pcs_fail(
          "acl permission add role1 read id dummy read xpathX //resources",
          stdout_start='\nUsage: pcs acl permission add...'
        )

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
Role: role2
Role: role3
Role: role4
""")
        self.assertEqual(0, r)
コード例 #26
0
 def test_empty(self):
     ac(str(config_parser.parse_string("")), "")
コード例 #27
0
    def testUserGroupCreateDeleteWithRoles(self):
        o, r = pcs(
            temp_cib,
            "acl role create role1 read xpath /xpath1/ write xpath /xpath2/"
        )
        assert r == 0
        ac(o, "")

        o, r = pcs(
            temp_cib,
            "acl role create role2 deny xpath /xpath3/ deny xpath /xpath4/"
        )
        assert r == 0
        ac(o, "")

        o, r = pcs(
            temp_cib,
            "acl role create role3 read xpath /xpath5/ read xpath /xpath6/"
        )
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl user create user1 roleX")
        ac(o, "Error: ACL role 'roleX' does not exist\n")
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl user create user1 role1 roleX")
        ac(o, "Error: ACL role 'roleX' does not exist\n")
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl group create group1 roleX")
        ac(o, "Error: ACL role 'roleX' does not exist\n")
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl group create group1 role1 roleX")
        ac(o, "Error: ACL role 'roleX' does not exist\n")
        self.assertEqual(1, r)

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: read xpath /xpath6/ (role3-read-1)
""")
        self.assertEqual(0, r)

        o, r = pcs(temp_cib, "acl user create user1 role1 role2")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl group create group1 role1 role3")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(
            o,
            """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role1 role2
Group: group1
  Roles: role1 role3
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: read xpath /xpath6/ (role3-read-1)
"""
        )

        o, r = pcs(temp_cib, "acl role create group1")
        assert r == 1
        ac(o, "Error: 'group1' already exists\n")

        o, r = pcs(temp_cib, "acl role create role1")
        assert r == 1
        ac(o, "Error: 'role1' already exists\n")

        o, r = pcs(temp_cib, "acl user create user1")
        assert r == 1
        ac(o, "Error: 'user1' already exists\n")

        o, r = pcs(temp_cib, "acl group create group1")
        assert r == 1
        ac(o, "Error: 'group1' already exists\n")

        o, r = pcs(temp_cib, "acl group create role1")
        assert r == 1
        ac(o, "Error: 'role1' already exists\n")

        o, r = pcs(temp_cib, "acl role assign role1 to noexist")
        assert r == 1
        ac(o, "Error: ACL group/ACL user 'noexist' does not exist\n")

        o, r = pcs(temp_cib, "acl role assign noexist to user1")
        assert r == 1
        ac(o, "Error: ACL role 'noexist' does not exist\n")

        o, r = pcs(temp_cib, "acl role assign role3 to user1")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role1 role2 role3
Group: group1
  Roles: role1 role3
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: read xpath /xpath6/ (role3-read-1)
""")

        o, r = pcs(temp_cib, "acl role unassign noexist from user1")
        assert r == 1
        ac(o, "Error: Role 'noexist' is not assigned to 'user1'\n")

        o, r = pcs(temp_cib, "acl role unassign role3 from noexist")
        assert r == 1
        ac(o, "Error: ACL group/ACL user 'noexist' does not exist\n")

        o, r = pcs(temp_cib, "acl role unassign role3 from user1")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role1 role2
Group: group1
  Roles: role1 role3
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: read xpath /xpath6/ (role3-read-1)
""")

        o, r = pcs(temp_cib, "acl role unassign role2 from user1")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl role unassign role1 from user1")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
Group: group1
  Roles: role1 role3
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
Role: role3
  Permission: read xpath /xpath5/ (role3-read)
  Permission: read xpath /xpath6/ (role3-read-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role delete role3")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
Group: group1
  Roles: role1
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role assign role2 to user1")
        assert r == 0
        ac(o, "")

        o, r = pcs(temp_cib, "acl")
        assert r == 0
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role2
Group: group1
  Roles: role1
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")

        o, r = pcs(temp_cib, "acl role assign role1 user1")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role2 role1
Group: group1
  Roles: role1
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role unassign role2 from user1 --autodelete")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role1
Group: group1
  Roles: role1
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role unassign role1 from user1 --autodelete")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

Group: group1
  Roles: role1
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl user create user1 role1 role2")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role1 role2
Group: group1
  Roles: role1
Role: role1
  Permission: read xpath /xpath1/ (role1-read)
  Permission: write xpath /xpath2/ (role1-write)
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role delete role1 --autodelete")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles: role2
Role: role2
  Permission: deny xpath /xpath3/ (role2-deny)
  Permission: deny xpath /xpath4/ (role2-deny-1)
""")
        assert r == 0

        o, r = pcs(temp_cib, "acl role delete role2")
        ac(o, "")
        assert r == 0

        o, r = pcs(temp_cib, "acl")
        ac(o, """\
ACLs are disabled, run 'pcs acl enable' to enable

User: user1
  Roles:
""")
        assert r == 0
コード例 #28
0
    def test_full(self):
        string = """\
# Please read the corosync.conf.5 manual page
totem {
	version: 2

	# crypto_cipher and crypto_hash: Used for mutual node authentication.
	# If you choose to enable this, then do remember to create a shared
	# secret with "corosync-keygen".
	# enabling crypto_cipher, requires also enabling of crypto_hash.
	crypto_cipher: none
	crypto_hash: none

	# interface: define at least one interface to communicate
	# over. If you define more than one interface stanza, you must
	# also set rrp_mode.
	interface {
                # Rings must be consecutively numbered, starting at 0.
		ringnumber: 0
		# This is normally the *network* address of the
		# interface to bind to. This ensures that you can use
		# identical instances of this configuration file
		# across all your cluster nodes, without having to
		# modify this option.
		bindnetaddr: 192.168.1.0
		# However, if you have multiple physical network
		# interfaces configured for the same subnet, then the
		# network address alone is not sufficient to identify
		# the interface Corosync should bind to. In that case,
		# configure the *host* address of the interface
		# instead:
		# bindnetaddr: 192.168.1.1
		# When selecting a multicast address, consider RFC
		# 2365 (which, among other things, specifies that
		# 239.255.x.x addresses are left to the discretion of
		# the network administrator). Do not reuse multicast
		# addresses across multiple Corosync clusters sharing
		# the same network.
		mcastaddr: 239.255.1.1
		# Corosync uses the port you specify here for UDP
		# messaging, and also the immediately preceding
		# port. Thus if you set this to 5405, Corosync sends
		# messages over UDP ports 5405 and 5404.
		mcastport: 5405
		# Time-to-live for cluster communication packets. The
		# number of hops (routers) that this ring will allow
		# itself to pass. Note that multicast routing must be
		# specifically enabled on most network routers.
		ttl: 1
	}
}

logging {
	# Log the source file and line where messages are being
	# generated. When in doubt, leave off. Potentially useful for
	# debugging.
	fileline: off
	# Log to standard error. When in doubt, set to no. Useful when
	# running in the foreground (when invoking "corosync -f")
	to_stderr: no
	# Log to a log file. When set to "no", the "logfile" option
	# must not be set.
	to_logfile: yes
	logfile: /var/log/cluster/corosync.log
	# Log to the system log daemon. When in doubt, set to yes.
	to_syslog: yes
	# Log debug messages (very verbose). When in doubt, leave off.
	debug: off
	# Log messages with time stamps. When in doubt, set to on
	# (unless you are only logging to syslog, where double
	# timestamps can be annoying).
	timestamp: on
	logger_subsys {
		subsys: QUORUM
		debug: off
	}
}

quorum {
	# Enable and configure quorum subsystem (default: off)
	# see also corosync.conf.5 and votequorum.5
	#provider: corosync_votequorum
}
"""
        parsed = """\
totem {
    version: 2
    crypto_cipher: none
    crypto_hash: none

    interface {
        ringnumber: 0
        bindnetaddr: 192.168.1.0
        mcastaddr: 239.255.1.1
        mcastport: 5405
        ttl: 1
    }
}

logging {
    fileline: off
    to_stderr: no
    to_logfile: yes
    logfile: /var/log/cluster/corosync.log
    to_syslog: yes
    debug: off
    timestamp: on

    logger_subsys {
        subsys: QUORUM
        debug: off
    }
}

quorum {
}
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
# Please read the corosync.conf.5 manual page
totem {
	version: 2

	crypto_cipher: none
	crypto_hash: none

	interface {
		ringnumber: 0
		bindnetaddr: 10.16.35.0
		mcastport: 5405
		ttl: 1
	}
	transport: udpu
}

logging {
	fileline: off
	to_logfile: yes
	to_syslog: yes
	logfile: /var/log/cluster/corosync.log
	debug: off
	timestamp: on
	logger_subsys {
		subsys: QUORUM
		debug: off
	}
}

nodelist {
	node {
		ring0_addr: 10.16.35.101
		nodeid: 1
	}

	node {
		ring0_addr: 10.16.35.102
		nodeid: 2
	}

	node {
		ring0_addr: 10.16.35.103
	}

	node {
		ring0_addr: 10.16.35.104
	}

	node {
		ring0_addr: 10.16.35.105
	}
}

quorum {
	# Enable and configure quorum subsystem (default: off)
	# see also corosync.conf.5 and votequorum.5
	#provider: corosync_votequorum
}
"""
        parsed = """\
totem {
    version: 2
    crypto_cipher: none
    crypto_hash: none
    transport: udpu

    interface {
        ringnumber: 0
        bindnetaddr: 10.16.35.0
        mcastport: 5405
        ttl: 1
    }
}

logging {
    fileline: off
    to_logfile: yes
    to_syslog: yes
    logfile: /var/log/cluster/corosync.log
    debug: off
    timestamp: on

    logger_subsys {
        subsys: QUORUM
        debug: off
    }
}

nodelist {
    node {
        ring0_addr: 10.16.35.101
        nodeid: 1
    }

    node {
        ring0_addr: 10.16.35.102
        nodeid: 2
    }

    node {
        ring0_addr: 10.16.35.103
    }

    node {
        ring0_addr: 10.16.35.104
    }

    node {
        ring0_addr: 10.16.35.105
    }
}

quorum {
}
"""
        ac(str(config_parser.parse_string(string)), parsed)
コード例 #29
0
    def testUIDGID(self):
        _pcs = partial(pcs,
                       None,
                       mock_settings={"corosync_uidgid_dir": self.uid_gid_dir})
        o, r = _pcs("cluster uidgid")
        ac(o, "No uidgids configured\n")
        assert r == 0

        o, r = _pcs("cluster uidgid add")
        assert r == 1
        assert o.startswith("\nUsage:")

        o, r = _pcs("cluster uidgid rm")
        assert r == 1
        assert o.startswith("\nUsage:")

        o, r = _pcs("cluster uidgid xx")
        assert r == 1
        assert o.startswith("\nUsage:")

        o, r = _pcs("cluster uidgid add uid=testuid gid=testgid")
        assert r == 0
        ac(o, "")

        o, r = _pcs("cluster uidgid add uid=testuid gid=testgid")
        ac(
            o,
            "Error: uidgid file with uid=testuid and gid=testgid already exists\n"
        )
        assert r == 1

        o, r = _pcs("cluster uidgid delete uid=testuid2 gid=testgid2")
        assert r == 1
        ac(
            o,
            "Error: no uidgid files with uid=testuid2 and gid=testgid2 found\n"
        )

        o, r = _pcs("cluster uidgid remove uid=testuid gid=testgid2")
        assert r == 1
        ac(o,
           "Error: no uidgid files with uid=testuid and gid=testgid2 found\n")

        o, r = _pcs("cluster uidgid rm uid=testuid2 gid=testgid")
        assert r == 1
        ac(
            o, "'pcs cluster uidgid rm' has been deprecated, use 'pcs cluster "
            "uidgid delete' or 'pcs cluster uidgid remove' instead\n"
            "Error: no uidgid files with uid=testuid2 and gid=testgid found\n")

        o, r = _pcs("cluster uidgid")
        assert r == 0
        ac(o, "UID/GID: uid=testuid gid=testgid\n")

        o, r = _pcs("cluster uidgid delete uid=testuid gid=testgid")
        ac(o, "")
        assert r == 0

        o, r = _pcs("cluster uidgid add uid=testuid gid=testgid")
        assert r == 0
        ac(o, "")

        o, r = _pcs("cluster uidgid")
        assert r == 0
        ac(o, "UID/GID: uid=testuid gid=testgid\n")

        o, r = _pcs("cluster uidgid remove uid=testuid gid=testgid")
        ac(o, "")
        assert r == 0

        o, r = _pcs("cluster uidgid add uid=testuid gid=testgid")
        assert r == 0
        ac(o, "")

        o, r = _pcs("cluster uidgid")
        assert r == 0
        ac(o, "UID/GID: uid=testuid gid=testgid\n")

        o, r = _pcs("cluster uidgid rm uid=testuid gid=testgid")
        ac(
            o, "'pcs cluster uidgid rm' has been deprecated, use 'pcs cluster "
            "uidgid delete' or 'pcs cluster uidgid remove' instead\n")
        assert r == 0

        o, r = _pcs("cluster uidgid")
        assert r == 0
        ac(o, "No uidgids configured\n")
コード例 #30
0
    def test_section(self):
        string = """\
section1 {
}\
"""
        parsed = """\
section1 {
}
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
section1 {
    section1a   {
  }
  section1b        {       
     }    
}
"""
        parsed = """\
section1 {
    section1a {
    }

    section1b {
    }
}
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
section1 {
    section1a junk1 { junk2
    junk3 } junk4
    section1b junk5{junk6
    junk7}junk8
}
section2 {
   section2a {
   }
   section2b {
   }
}
"""
        parsed = """\
section1 {
    section1a junk1 {
    }

    section1b junk5 {
    }
}

section2 {
    section2a {
    }

    section2b {
    }
}
"""
        ac(str(config_parser.parse_string(string)), parsed)

        string = """\
section1 {
    section1a {
    }

    section1b {
    }
}
}
"""
        self.assertRaises(config_parser.UnexpectedClosingBraceException,
                          config_parser.parse_string, string)

        string = """\
section1 {
    section1a {

    section1b {
    }
}
"""
        self.assertRaises(config_parser.MissingClosingBraceException,
                          config_parser.parse_string, string)

        string = """\
section1 {
"""
        self.assertRaises(config_parser.MissingClosingBraceException,
                          config_parser.parse_string, string)

        string = """\
}
"""
        self.assertRaises(config_parser.UnexpectedClosingBraceException,
                          config_parser.parse_string, string)