DevStack supporting tools in python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_localconf_merge.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Copyright 2017 IBM
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. # Implementation of ini add / remove for devstack. We don't use the
  15. # python ConfigFile parser because that ends up rewriting the entire
  16. # file and doesn't ensure comments remain.
  17. import fixtures
  18. import os.path
  19. import testtools
  20. from devstack import dsconf
  21. BASIC = """
  22. [[local|localrc]]
  23. a=b
  24. c=d
  25. f=1
  26. [[post-config|$NEUTRON_CONF]]
  27. [DEFAULT]
  28. global_physnet_mtu=1450
  29. [[post-config|$NOVA_CONF]]
  30. [upgrade_levels]
  31. compute = auto
  32. """
  33. LC1 = """
  34. [[local|localrc]]
  35. a=5
  36. g=2
  37. [[post-config|$NEUTRON_CONF]]
  38. [DEFAULT]
  39. global_physnet_mtu=1400
  40. [[post-config|$GLANCE_CONF]]
  41. [upgrade_levels]
  42. compute = auto
  43. """
  44. LC2 = """
  45. [[local|localrc]]
  46. # some other comment
  47. enable_plugin ironic https://github.com/openstack/ironic
  48. TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
  49. """
  50. RESULT1 = """
  51. [[local|localrc]]
  52. a=b
  53. c=d
  54. f=1
  55. a=5
  56. g=2
  57. [[post-config|$NEUTRON_CONF]]
  58. [DEFAULT]
  59. global_physnet_mtu = 1400
  60. [[post-config|$NOVA_CONF]]
  61. [upgrade_levels]
  62. compute = auto
  63. [[post-config|$GLANCE_CONF]]
  64. [upgrade_levels]
  65. compute = auto
  66. """
  67. RESULT2 = """
  68. [[local|localrc]]
  69. a=b
  70. c=d
  71. f=1
  72. # some other comment
  73. enable_plugin ironic https://github.com/openstack/ironic
  74. TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
  75. [[post-config|$NEUTRON_CONF]]
  76. [DEFAULT]
  77. global_physnet_mtu=1450
  78. [[post-config|$NOVA_CONF]]
  79. [upgrade_levels]
  80. compute = auto
  81. """
  82. class TestLcMerge(testtools.TestCase):
  83. def setUp(self):
  84. super(TestLcMerge, self).setUp()
  85. self._path = self.useFixture(fixtures.TempDir()).path
  86. self._path += "/local.conf"
  87. with open(self._path, "w") as f:
  88. f.write(BASIC)
  89. def test_merge_lc1(self):
  90. dirname = self.useFixture(fixtures.TempDir()).path
  91. lc1 = os.path.join(dirname, "local1.conf")
  92. with open(lc1, "w+") as f:
  93. f.write(LC1)
  94. conf = dsconf.LocalConf(self._path)
  95. conf.merge_lc(lc1)
  96. with open(self._path) as f:
  97. content = f.read()
  98. self.assertEqual(content, RESULT1)
  99. def test_merge_lc2(self):
  100. dirname = self.useFixture(fixtures.TempDir()).path
  101. lc2 = os.path.join(dirname, "local2.conf")
  102. with open(lc2, "w+") as f:
  103. f.write(LC2)
  104. conf = dsconf.LocalConf(self._path)
  105. conf.merge_lc(lc2)
  106. with open(self._path) as f:
  107. content = f.read()
  108. self.assertEqual(content, RESULT2)