/pcsd/test/test_corosyncconf.rb

https://github.com/feist/pcs · Ruby · 1302 lines · 1098 code · 144 blank · 60 comment · 0 complexity · 6f6d62a548a2dfcc74cdc8e5e77dbf5f MD5 · raw file

  1. require 'test/unit'
  2. require 'settings.rb'
  3. require 'pcsd_test_utils.rb'
  4. require 'corosyncconf.rb'
  5. class TestCorosyncConfSection < Test::Unit::TestCase
  6. def test_empty_section
  7. section = CorosyncConf::Section.new('mySection')
  8. assert_nil(section.parent)
  9. assert_equal(section, section.root)
  10. assert_equal('mySection', section.name)
  11. assert_equal([], section.attributes)
  12. assert_equal([], section.sections)
  13. assert_equal('', section.text)
  14. end
  15. def test_attribute_add
  16. section = CorosyncConf::Section.new('mySection')
  17. section.add_attribute('name1', 'value1')
  18. assert_equal(
  19. [
  20. ['name1', 'value1'],
  21. ],
  22. section.attributes
  23. )
  24. section.add_attribute('name2', 'value2')
  25. assert_equal(
  26. [
  27. ['name1', 'value1'],
  28. ['name2', 'value2'],
  29. ],
  30. section.attributes
  31. )
  32. section.add_attribute('name2', 'value2')
  33. assert_equal(
  34. [
  35. ['name1', 'value1'],
  36. ['name2', 'value2'],
  37. ['name2', 'value2'],
  38. ],
  39. section.attributes
  40. )
  41. end
  42. def test_attribute_get
  43. section = CorosyncConf::Section.new('mySection')
  44. section.add_attribute('name1', 'value1')
  45. section.add_attribute('name2', 'value2')
  46. section.add_attribute('name3', 'value3')
  47. section.add_attribute('name2', 'value2a')
  48. assert_equal(
  49. [
  50. ['name1', 'value1'],
  51. ['name2', 'value2'],
  52. ['name3', 'value3'],
  53. ['name2', 'value2a'],
  54. ],
  55. section.attributes
  56. )
  57. assert_equal(
  58. [
  59. ['name1', 'value1'],
  60. ],
  61. section.attributes('name1')
  62. )
  63. assert_equal(
  64. [
  65. ['name2', 'value2'],
  66. ['name2', 'value2a'],
  67. ],
  68. section.attributes('name2')
  69. )
  70. assert_equal(
  71. [],
  72. section.attributes('nameX')
  73. )
  74. end
  75. def test_attribute_set
  76. section = CorosyncConf::Section.new('mySection')
  77. section.set_attribute('name1', 'value1')
  78. assert_equal(
  79. [
  80. ['name1', 'value1'],
  81. ],
  82. section.attributes
  83. )
  84. section.set_attribute('name1', 'value1')
  85. assert_equal(
  86. [
  87. ['name1', 'value1'],
  88. ],
  89. section.attributes
  90. )
  91. section.set_attribute('name1', 'value1a')
  92. assert_equal(
  93. [
  94. ['name1', 'value1a'],
  95. ],
  96. section.attributes
  97. )
  98. section.set_attribute('name2', 'value2')
  99. assert_equal(
  100. [
  101. ['name1', 'value1a'],
  102. ['name2', 'value2'],
  103. ],
  104. section.attributes
  105. )
  106. section.set_attribute('name1', 'value1')
  107. assert_equal(
  108. [
  109. ['name1', 'value1'],
  110. ['name2', 'value2'],
  111. ],
  112. section.attributes
  113. )
  114. section.add_attribute('name3', 'value3')
  115. section.add_attribute('name2', 'value2')
  116. assert_equal(
  117. [
  118. ['name1', 'value1'],
  119. ['name2', 'value2'],
  120. ['name3', 'value3'],
  121. ['name2', 'value2'],
  122. ],
  123. section.attributes
  124. )
  125. section.set_attribute('name2', 'value2a')
  126. assert_equal(
  127. [
  128. ['name1', 'value1'],
  129. ['name2', 'value2a'],
  130. ['name3', 'value3'],
  131. ],
  132. section.attributes
  133. )
  134. section.add_attribute('name1', 'value1')
  135. section.add_attribute('name1', 'value1')
  136. section.set_attribute('name1', 'value1')
  137. assert_equal(
  138. [
  139. ['name1', 'value1'],
  140. ['name2', 'value2a'],
  141. ['name3', 'value3'],
  142. ],
  143. section.attributes
  144. )
  145. end
  146. def test_attribute_change
  147. section = CorosyncConf::Section.new('mySection')
  148. section.add_attribute('name1', 'value1')
  149. section.add_attribute('name2', 'value2')
  150. section.add_attribute('name3', 'value3')
  151. section.add_attribute('name2', 'value2')
  152. attrib = section.attributes[1]
  153. attrib[0] = 'name2a'
  154. attrib[1] = 'value2a'
  155. assert_equal(
  156. [
  157. ['name1', 'value1'],
  158. ['name2a', 'value2a'],
  159. ['name3', 'value3'],
  160. ['name2', 'value2'],
  161. ],
  162. section.attributes
  163. )
  164. end
  165. def test_attribute_del
  166. section = CorosyncConf::Section.new('mySection')
  167. section.add_attribute('name1', 'value1')
  168. section.add_attribute('name2', 'value2')
  169. section.add_attribute('name3', 'value3')
  170. section.add_attribute('name2', 'value2')
  171. section.del_attribute(section.attributes[1])
  172. assert_equal(
  173. [
  174. ['name1', 'value1'],
  175. ['name3', 'value3'],
  176. ],
  177. section.attributes
  178. )
  179. section.del_attribute(['name3', 'value3'])
  180. assert_equal(
  181. [
  182. ['name1', 'value1'],
  183. ],
  184. section.attributes
  185. )
  186. section.del_attribute(['name3', 'value3'])
  187. assert_equal(
  188. [
  189. ['name1', 'value1'],
  190. ],
  191. section.attributes
  192. )
  193. end
  194. def test_attribute_del_by_name
  195. section = CorosyncConf::Section.new('mySection')
  196. section.add_attribute('name1', 'value1')
  197. section.add_attribute('name2', 'value2')
  198. section.add_attribute('name3', 'value3')
  199. section.add_attribute('name2', 'value2')
  200. section.del_attributes_by_name('nameX')
  201. assert_equal(
  202. [
  203. ['name1', 'value1'],
  204. ['name2', 'value2'],
  205. ['name3', 'value3'],
  206. ['name2', 'value2'],
  207. ],
  208. section.attributes
  209. )
  210. section.del_attributes_by_name('name2', 'value2')
  211. assert_equal(
  212. [
  213. ['name1', 'value1'],
  214. ['name3', 'value3'],
  215. ],
  216. section.attributes
  217. )
  218. section.add_attribute('name2', 'value2')
  219. section.add_attribute('name2', 'value2a')
  220. assert_equal(
  221. [
  222. ['name1', 'value1'],
  223. ['name3', 'value3'],
  224. ['name2', 'value2'],
  225. ['name2', 'value2a'],
  226. ],
  227. section.attributes
  228. )
  229. section.del_attributes_by_name('name2', 'value2')
  230. assert_equal(
  231. [
  232. ['name1', 'value1'],
  233. ['name3', 'value3'],
  234. ['name2', 'value2a'],
  235. ],
  236. section.attributes
  237. )
  238. section.add_attribute('name3', 'value3a')
  239. assert_equal(
  240. [
  241. ['name1', 'value1'],
  242. ['name3', 'value3'],
  243. ['name2', 'value2a'],
  244. ['name3', 'value3a'],
  245. ],
  246. section.attributes
  247. )
  248. section.del_attributes_by_name('name3')
  249. assert_equal(
  250. [
  251. ['name1', 'value1'],
  252. ['name2', 'value2a'],
  253. ],
  254. section.attributes
  255. )
  256. end
  257. def test_section_add
  258. root = CorosyncConf::Section.new('root')
  259. child1 = CorosyncConf::Section.new('child1')
  260. child1a = CorosyncConf::Section.new('child1a')
  261. child2 = CorosyncConf::Section.new('child2')
  262. root.add_section(child1)
  263. child1.add_section(child1a)
  264. root.add_section(child2)
  265. assert_nil(root.parent)
  266. assert_equal('root', child1.parent.name)
  267. assert_equal('child1', child1a.parent.name)
  268. assert_equal('root', child2.parent.name)
  269. assert_equal("\
  270. child1 {
  271. child1a {
  272. }
  273. }
  274. child2 {
  275. }
  276. ",
  277. root.text
  278. )
  279. child2.add_section(child1a)
  280. assert_equal('child2', child1a.parent.name)
  281. assert_equal("\
  282. child1 {
  283. }
  284. child2 {
  285. child1a {
  286. }
  287. }
  288. ",
  289. root.text
  290. )
  291. assert_raise CorosyncConf::CircularParentshipException do
  292. child1a.add_section(child1a)
  293. end
  294. assert_raise CorosyncConf::CircularParentshipException do
  295. child1a.add_section(child2)
  296. end
  297. assert_raise CorosyncConf::CircularParentshipException do
  298. child1a.add_section(root)
  299. end
  300. end
  301. def test_section_get
  302. root = CorosyncConf::Section.new('root')
  303. child1 = CorosyncConf::Section.new('child1')
  304. child2 = CorosyncConf::Section.new('child2')
  305. childa1 = CorosyncConf::Section.new('childA')
  306. childa2 = CorosyncConf::Section.new('childA')
  307. childa3 = CorosyncConf::Section.new('childA')
  308. childa4 = CorosyncConf::Section.new('childA')
  309. childb1 = CorosyncConf::Section.new('childB')
  310. childb2 = CorosyncConf::Section.new('childB')
  311. childa1.add_attribute('id', '1')
  312. childa2.add_attribute('id', '2')
  313. childa3.add_attribute('id', '3')
  314. childa4.add_attribute('id', '4')
  315. childb1.add_attribute('id', '5')
  316. childb2.add_attribute('id', '6')
  317. root.add_section(child1)
  318. root.add_section(child2)
  319. child1.add_section(childa1)
  320. child1.add_section(childa2)
  321. child1.add_section(childb1)
  322. child2.add_section(childa3)
  323. child2.add_section(childb2)
  324. child2.add_section(childa4)
  325. assert_equal("\
  326. child1 {
  327. childA {
  328. id: 1
  329. }
  330. childA {
  331. id: 2
  332. }
  333. childB {
  334. id: 5
  335. }
  336. }
  337. child2 {
  338. childA {
  339. id: 3
  340. }
  341. childB {
  342. id: 6
  343. }
  344. childA {
  345. id: 4
  346. }
  347. }
  348. ",
  349. root.text
  350. )
  351. assert_equal("\
  352. child1 {
  353. childA {
  354. id: 1
  355. }
  356. childA {
  357. id: 2
  358. }
  359. childB {
  360. id: 5
  361. }
  362. }
  363. ---
  364. child2 {
  365. childA {
  366. id: 3
  367. }
  368. childB {
  369. id: 6
  370. }
  371. childA {
  372. id: 4
  373. }
  374. }
  375. ",
  376. root.sections.collect { |section| section.text }.join("---\n")
  377. )
  378. assert_equal("\
  379. child1 {
  380. childA {
  381. id: 1
  382. }
  383. childA {
  384. id: 2
  385. }
  386. childB {
  387. id: 5
  388. }
  389. }
  390. ",
  391. root.sections('child1').collect { |section| section.text }.join("---\n")
  392. )
  393. assert_equal("\
  394. childA {
  395. id: 1
  396. }
  397. ---
  398. childA {
  399. id: 2
  400. }
  401. ",
  402. child1.sections('childA').collect { |section| section.text }.join("---\n")
  403. )
  404. assert_equal(
  405. '',
  406. child1.sections('child2').collect { |section| section.text }.join("---\n")
  407. )
  408. end
  409. def test_section_del
  410. root = CorosyncConf::Section.new('')
  411. child1 = CorosyncConf::Section.new('child1')
  412. child2 = CorosyncConf::Section.new('child2')
  413. childa1 = CorosyncConf::Section.new('childA')
  414. childa2 = CorosyncConf::Section.new('childA')
  415. childa3 = CorosyncConf::Section.new('childA')
  416. childa4 = CorosyncConf::Section.new('childA')
  417. childb1 = CorosyncConf::Section.new('childB')
  418. childb2 = CorosyncConf::Section.new('childB')
  419. childa1.add_attribute('id', '1')
  420. childa2.add_attribute('id', '2')
  421. childa3.add_attribute('id', '3')
  422. childa4.add_attribute('id', '4')
  423. childb1.add_attribute('id', '5')
  424. childb2.add_attribute('id', '6')
  425. root.add_section(child1)
  426. root.add_section(child2)
  427. child1.add_section(childa1)
  428. child1.add_section(childa2)
  429. child1.add_section(childb1)
  430. child2.add_section(childa3)
  431. child2.add_section(childb2)
  432. child2.add_section(childa4)
  433. assert_equal("\
  434. child1 {
  435. childA {
  436. id: 1
  437. }
  438. childA {
  439. id: 2
  440. }
  441. childB {
  442. id: 5
  443. }
  444. }
  445. child2 {
  446. childA {
  447. id: 3
  448. }
  449. childB {
  450. id: 6
  451. }
  452. childA {
  453. id: 4
  454. }
  455. }
  456. ",
  457. root.text
  458. )
  459. child2.del_section(childb2)
  460. assert_nil(childb2.parent)
  461. assert_equal("\
  462. child1 {
  463. childA {
  464. id: 1
  465. }
  466. childA {
  467. id: 2
  468. }
  469. childB {
  470. id: 5
  471. }
  472. }
  473. child2 {
  474. childA {
  475. id: 3
  476. }
  477. childA {
  478. id: 4
  479. }
  480. }
  481. ",
  482. root.text
  483. )
  484. root.del_section(child2)
  485. assert_nil(child2.parent)
  486. assert_equal("\
  487. child1 {
  488. childA {
  489. id: 1
  490. }
  491. childA {
  492. id: 2
  493. }
  494. childB {
  495. id: 5
  496. }
  497. }
  498. ",
  499. root.text
  500. )
  501. root.del_section(child2)
  502. assert_equal('child1', childa1.parent.name)
  503. child2.del_section(childa1)
  504. assert_equal('child1', childa1.parent.name)
  505. child1.del_section(childb1)
  506. assert_nil(childb1.parent)
  507. assert_equal("\
  508. child1 {
  509. childA {
  510. id: 1
  511. }
  512. childA {
  513. id: 2
  514. }
  515. }
  516. ",
  517. root.text
  518. )
  519. child1.del_section(childa1)
  520. assert_nil(childa1.parent)
  521. child1.del_section(childa2)
  522. assert_nil(childa2.parent)
  523. assert_equal("\
  524. child1 {
  525. }
  526. ",
  527. root.text
  528. )
  529. root.del_section(child1)
  530. assert_nil(child1.parent)
  531. assert_equal('', root.text)
  532. end
  533. def test_get_root
  534. root = CorosyncConf::Section.new('root')
  535. child1 = CorosyncConf::Section.new('child1')
  536. child1a = CorosyncConf::Section.new('child1a')
  537. root.add_section(child1)
  538. child1.add_section(child1a)
  539. assert_equal('root', root.root.name)
  540. assert_equal('root', child1.root.name)
  541. assert_equal('root', child1a.root.name)
  542. end
  543. def test_text
  544. root = CorosyncConf::Section.new('root')
  545. assert_equal('', root.text)
  546. root.add_attribute("name1", "value1")
  547. assert_equal("name1: value1\n", root.text)
  548. root.add_attribute("name2", "value2")
  549. root.add_attribute("name2", "value2a")
  550. root.add_attribute("name3", "value3")
  551. assert_equal("\
  552. name1: value1
  553. name2: value2
  554. name2: value2a
  555. name3: value3
  556. ",
  557. root.text
  558. )
  559. child1 = CorosyncConf::Section.new('child1')
  560. root.add_section(child1)
  561. assert_equal("\
  562. name1: value1
  563. name2: value2
  564. name2: value2a
  565. name3: value3
  566. child1 {
  567. }
  568. ",
  569. root.text
  570. )
  571. child1.add_attribute("name1.1", "value1.1")
  572. child1.add_attribute("name1.2", "value1.2")
  573. assert_equal("\
  574. name1: value1
  575. name2: value2
  576. name2: value2a
  577. name3: value3
  578. child1 {
  579. name1.1: value1.1
  580. name1.2: value1.2
  581. }
  582. ",
  583. root.text
  584. )
  585. child2 = CorosyncConf::Section.new('child2')
  586. child2.add_attribute("name2.1", "value2.1")
  587. root.add_section(child2)
  588. assert_equal("\
  589. name1: value1
  590. name2: value2
  591. name2: value2a
  592. name3: value3
  593. child1 {
  594. name1.1: value1.1
  595. name1.2: value1.2
  596. }
  597. child2 {
  598. name2.1: value2.1
  599. }
  600. ",
  601. root.text
  602. )
  603. child2a = CorosyncConf::Section.new('child2a')
  604. child2a.add_attribute("name2.a.1", "value2.a.1")
  605. child2.add_section(child2a)
  606. assert_equal("\
  607. name1: value1
  608. name2: value2
  609. name2: value2a
  610. name3: value3
  611. child1 {
  612. name1.1: value1.1
  613. name1.2: value1.2
  614. }
  615. child2 {
  616. name2.1: value2.1
  617. child2a {
  618. name2.a.1: value2.a.1
  619. }
  620. }
  621. ",
  622. root.text
  623. )
  624. child3 = CorosyncConf::Section.new('child3')
  625. root.add_section(child3)
  626. child3.add_section(CorosyncConf::Section.new('child3a'))
  627. child3.add_section(CorosyncConf::Section.new('child3b'))
  628. assert_equal("\
  629. name1: value1
  630. name2: value2
  631. name2: value2a
  632. name3: value3
  633. child1 {
  634. name1.1: value1.1
  635. name1.2: value1.2
  636. }
  637. child2 {
  638. name2.1: value2.1
  639. child2a {
  640. name2.a.1: value2.a.1
  641. }
  642. }
  643. child3 {
  644. child3a {
  645. }
  646. child3b {
  647. }
  648. }
  649. ",
  650. root.text
  651. )
  652. end
  653. end
  654. class TestCorosyncConfParser < Test::Unit::TestCase
  655. def test_empty
  656. assert_equal('', CorosyncConf::parse_string('').text)
  657. end
  658. def test_attributes_one_attribute
  659. string = "\
  660. name:value\
  661. "
  662. parsed = "\
  663. name: value
  664. "
  665. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  666. end
  667. def test_attributes_two_attributes_same_name
  668. string = "\
  669. name:value
  670. name:value
  671. "
  672. parsed = "\
  673. name: value
  674. name: value
  675. "
  676. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  677. end
  678. def test_attributes_more_attributes_whitespace
  679. string = "\
  680. name1:value1
  681. name2 :value2
  682. name3: value3
  683. name4 : value4
  684. "
  685. parsed = "\
  686. name1: value1
  687. name2: value2
  688. name3: value3
  689. name4: value4
  690. "
  691. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  692. end
  693. def test_attributes_colon_in_value
  694. string = "\
  695. name:foo:value
  696. "
  697. parsed = "\
  698. name: foo:value
  699. "
  700. root = CorosyncConf::parse_string(string)
  701. assert_equal(
  702. [['name', 'foo:value']],
  703. root.attributes
  704. )
  705. assert_equal(parsed, root.text)
  706. end
  707. def test_attributes_empty_value
  708. string = "\
  709. name :
  710. "
  711. parsed = "\
  712. name:
  713. "
  714. root = CorosyncConf::parse_string(string)
  715. assert_equal(
  716. [['name', '']],
  717. root.attributes
  718. )
  719. assert_equal(parsed, root.text)
  720. end
  721. def test_sections_empty_section
  722. string = "\
  723. section1 {
  724. }\
  725. "
  726. parsed = "\
  727. section1 {
  728. }
  729. "
  730. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  731. end
  732. def test_sections_empty_section_in_section_whitespace
  733. string = "\
  734. section1 {
  735. section1a {
  736. }
  737. section1b {
  738. }
  739. }
  740. "
  741. parsed = "\
  742. section1 {
  743. section1a {
  744. }
  745. section1b {
  746. }
  747. }
  748. "
  749. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  750. end
  751. def test_sections_no_name_before_opening
  752. string = "\
  753. section1 {
  754. {
  755. }
  756. }
  757. section2 {
  758. section2a {
  759. }
  760. section2b {
  761. }
  762. }
  763. "
  764. assert_raise CorosyncConf::ParseErrorException do
  765. CorosyncConf::parse_string(string)
  766. end
  767. end
  768. def test_sections_junk_after_opening
  769. string = "\
  770. section1 {
  771. section1a {junk
  772. }
  773. }
  774. section2 {
  775. section2a {
  776. }
  777. section2b {
  778. }
  779. }
  780. "
  781. assert_raise CorosyncConf::ParseErrorException do
  782. CorosyncConf::parse_string(string)
  783. end
  784. end
  785. def test_sections_comment_junk_after_opening
  786. string = "\
  787. section1 {
  788. section1a { #junk
  789. }
  790. }
  791. section2 {
  792. section2a {
  793. }
  794. section2b {
  795. }
  796. }
  797. "
  798. assert_raise CorosyncConf::ParseErrorException do
  799. CorosyncConf::parse_string(string)
  800. end
  801. end
  802. def test_sections_junk_before_closing
  803. string = "\
  804. section1 {
  805. section1a {
  806. junk}
  807. }
  808. section2 {
  809. section2a {
  810. }
  811. section2b {
  812. }
  813. }
  814. "
  815. assert_raise CorosyncConf::ParseErrorException do
  816. CorosyncConf::parse_string(string)
  817. end
  818. end
  819. def test_sections_junk_after_closing
  820. string = "\
  821. section1 {
  822. section1a {
  823. }junk
  824. }
  825. section2 {
  826. section2a {
  827. }
  828. section2b {
  829. }
  830. }
  831. "
  832. assert_raise CorosyncConf::ParseErrorException do
  833. CorosyncConf::parse_string(string)
  834. end
  835. end
  836. def test_sections_comment_junk_after_closing
  837. string = "\
  838. section1 {
  839. section1a {
  840. } #junk
  841. }
  842. section2 {
  843. section2a {
  844. }
  845. section2b {
  846. }
  847. }
  848. "
  849. assert_raise CorosyncConf::ParseErrorException do
  850. CorosyncConf::parse_string(string)
  851. end
  852. end
  853. def test_sections_unexpected_closing_brace
  854. string = "\
  855. }
  856. "
  857. assert_raise CorosyncConf::ParseErrorException do
  858. CorosyncConf::parse_string(string)
  859. end
  860. end
  861. def test_sections_unexpected_closing_brace_inner_section
  862. string = "\
  863. section1 {
  864. section1a {
  865. }
  866. section1b {
  867. }
  868. }
  869. }
  870. "
  871. assert_raise CorosyncConf::ParseErrorException do
  872. CorosyncConf::parse_string(string)
  873. end
  874. end
  875. def test_sections_missing_closing_brace
  876. string = "\
  877. section1 {
  878. "
  879. assert_raise CorosyncConf::ParseErrorException do
  880. CorosyncConf::parse_string(string)
  881. end
  882. end
  883. def test_sections_missing_closing_brace_inner_section
  884. string = "\
  885. section1 {
  886. section1a {
  887. section1b {
  888. }
  889. }
  890. "
  891. assert_raise CorosyncConf::ParseErrorException do
  892. CorosyncConf::parse_string(string)
  893. end
  894. end
  895. def test_junk_line
  896. string = "\
  897. name1: value1
  898. section1 {
  899. section1a {
  900. name1a: value1a
  901. }
  902. junk line
  903. section1b {
  904. }
  905. }
  906. "
  907. assert_raise CorosyncConf::ParseErrorException do
  908. CorosyncConf::parse_string(string)
  909. end
  910. end
  911. def test_comments_attributes
  912. string= "\
  913. # junk1
  914. name1: value1
  915. #junk2
  916. name2: value2#junk3
  917. name3: value3 #junk4
  918. name4 # junk5: value4
  919. #junk6 name5: value5
  920. #junk7
  921. "
  922. parsed = "\
  923. name1: value1
  924. name2: value2#junk3
  925. name3: value3 #junk4
  926. name4 # junk5: value4
  927. "
  928. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  929. end
  930. def test_comments_sections_closing_brace
  931. string = "\
  932. section {
  933. #}
  934. "
  935. assert_raise CorosyncConf::ParseErrorException do
  936. CorosyncConf::parse_string(string)
  937. end
  938. end
  939. def test_comments_sections_opening_brace
  940. string = "\
  941. #section {
  942. }
  943. """
  944. assert_raise CorosyncConf::ParseErrorException do
  945. CorosyncConf::parse_string(string)
  946. end
  947. end
  948. def test_full
  949. string = "\
  950. # Please read the corosync.conf.5 manual page
  951. totem {
  952. version: 2
  953. # crypto_cipher and crypto_hash: Used for mutual node authentication.
  954. # If you choose to enable this, then do remember to create a shared
  955. # secret with 'corosync-keygen'.
  956. # enabling crypto_cipher, requires also enabling of crypto_hash.
  957. crypto_cipher: none
  958. crypto_hash: none
  959. # interface: define at least one interface to communicate
  960. # over. If you define more than one interface stanza, you must
  961. # also set rrp_mode.
  962. interface {
  963. # Rings must be consecutively numbered, starting at 0.
  964. ringnumber: 0
  965. # This is normally the *network* address of the
  966. # interface to bind to. This ensures that you can use
  967. # identical instances of this configuration file
  968. # across all your cluster nodes, without having to
  969. # modify this option.
  970. bindnetaddr: 192.168.1.0
  971. # However, if you have multiple physical network
  972. # interfaces configured for the same subnet, then the
  973. # network address alone is not sufficient to identify
  974. # the interface Corosync should bind to. In that case,
  975. # configure the *host* address of the interface
  976. # instead:
  977. # bindnetaddr: 192.168.1.1
  978. # When selecting a multicast address, consider RFC
  979. # 2365 (which, among other things, specifies that
  980. # 239.255.x.x addresses are left to the discretion of
  981. # the network administrator). Do not reuse multicast
  982. # addresses across multiple Corosync clusters sharing
  983. # the same network.
  984. mcastaddr: 239.255.1.1
  985. # Corosync uses the port you specify here for UDP
  986. # messaging, and also the immediately preceding
  987. # port. Thus if you set this to 5405, Corosync sends
  988. # messages over UDP ports 5405 and 5404.
  989. mcastport: 5405
  990. # Time-to-live for cluster communication packets. The
  991. # number of hops (routers) that this ring will allow
  992. # itself to pass. Note that multicast routing must be
  993. # specifically enabled on most network routers.
  994. ttl: 1
  995. }
  996. }
  997. logging {
  998. # Log the source file and line where messages are being
  999. # generated. When in doubt, leave off. Potentially useful for
  1000. # debugging.
  1001. fileline: off
  1002. # Log to standard error. When in doubt, set to no. Useful when
  1003. # running in the foreground (when invoking 'corosync -f')
  1004. to_stderr: no
  1005. # Log to a log file. When set to 'no', the 'logfile' option
  1006. # must not be set.
  1007. to_logfile: yes
  1008. logfile: #{COROSYNC_LOG_FILE}
  1009. # Log to the system log daemon. When in doubt, set to yes.
  1010. to_syslog: yes
  1011. # Log debug messages (very verbose). When in doubt, leave off.
  1012. debug: off
  1013. # Log messages with time stamps. When in doubt, set to on
  1014. # (unless you are only logging to syslog, where double
  1015. # timestamps can be annoying).
  1016. timestamp: on
  1017. logger_subsys {
  1018. subsys: QUORUM
  1019. debug: off
  1020. }
  1021. }
  1022. quorum {
  1023. # Enable and configure quorum subsystem (default: off)
  1024. # see also corosync.conf.5 and votequorum.5
  1025. #provider: corosync_votequorum
  1026. }
  1027. "
  1028. parsed = "\
  1029. totem {
  1030. version: 2
  1031. crypto_cipher: none
  1032. crypto_hash: none
  1033. interface {
  1034. ringnumber: 0
  1035. bindnetaddr: 192.168.1.0
  1036. mcastaddr: 239.255.1.1
  1037. mcastport: 5405
  1038. ttl: 1
  1039. }
  1040. }
  1041. logging {
  1042. fileline: off
  1043. to_stderr: no
  1044. to_logfile: yes
  1045. logfile: #{COROSYNC_LOG_FILE}
  1046. to_syslog: yes
  1047. debug: off
  1048. timestamp: on
  1049. logger_subsys {
  1050. subsys: QUORUM
  1051. debug: off
  1052. }
  1053. }
  1054. quorum {
  1055. }
  1056. "
  1057. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  1058. string = "\
  1059. # Please read the corosync.conf.5 manual page
  1060. totem {
  1061. version: 2
  1062. crypto_cipher: none
  1063. crypto_hash: none
  1064. interface {
  1065. ringnumber: 0
  1066. bindnetaddr: 10.16.35.0
  1067. mcastport: 5405
  1068. ttl: 1
  1069. }
  1070. transport: udpu
  1071. }
  1072. logging {
  1073. fileline: off
  1074. to_logfile: yes
  1075. to_syslog: yes
  1076. logfile: #{COROSYNC_LOG_FILE}
  1077. debug: off
  1078. timestamp: on
  1079. logger_subsys {
  1080. subsys: QUORUM
  1081. debug: off
  1082. }
  1083. }
  1084. nodelist {
  1085. node {
  1086. ring0_addr: 10.16.35.101
  1087. nodeid: 1
  1088. }
  1089. node {
  1090. ring0_addr: 10.16.35.102
  1091. nodeid: 2
  1092. }
  1093. node {
  1094. ring0_addr: 10.16.35.103
  1095. }
  1096. node {
  1097. ring0_addr: 10.16.35.104
  1098. }
  1099. node {
  1100. ring0_addr: 10.16.35.105
  1101. }
  1102. }
  1103. quorum {
  1104. # Enable and configure quorum subsystem (default: off)
  1105. # see also corosync.conf.5 and votequorum.5
  1106. #provider: corosync_votequorum
  1107. }
  1108. "
  1109. parsed = "\
  1110. totem {
  1111. version: 2
  1112. crypto_cipher: none
  1113. crypto_hash: none
  1114. transport: udpu
  1115. interface {
  1116. ringnumber: 0
  1117. bindnetaddr: 10.16.35.0
  1118. mcastport: 5405
  1119. ttl: 1
  1120. }
  1121. }
  1122. logging {
  1123. fileline: off
  1124. to_logfile: yes
  1125. to_syslog: yes
  1126. logfile: #{COROSYNC_LOG_FILE}
  1127. debug: off
  1128. timestamp: on
  1129. logger_subsys {
  1130. subsys: QUORUM
  1131. debug: off
  1132. }
  1133. }
  1134. nodelist {
  1135. node {
  1136. ring0_addr: 10.16.35.101
  1137. nodeid: 1
  1138. }
  1139. node {
  1140. ring0_addr: 10.16.35.102
  1141. nodeid: 2
  1142. }
  1143. node {
  1144. ring0_addr: 10.16.35.103
  1145. }
  1146. node {
  1147. ring0_addr: 10.16.35.104
  1148. }
  1149. node {
  1150. ring0_addr: 10.16.35.105
  1151. }
  1152. }
  1153. quorum {
  1154. }
  1155. "
  1156. assert_equal(parsed, CorosyncConf::parse_string(string).text)
  1157. end
  1158. end