From da7511330305b0275e94385290985687a5786e0d Mon Sep 17 00:00:00 2001 From: Genadi Date: Tue, 4 Sep 2018 15:10:08 +0300 Subject: [PATCH] Function for updating configMap This function should be used for port pool feature for updating the values in configMap Change-Id: I324eace65fb999cfed9ab4bdaf51b66431677bc1 --- kuryr_tempest_plugin/tests/scenario/base.py | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/kuryr_tempest_plugin/tests/scenario/base.py b/kuryr_tempest_plugin/tests/scenario/base.py index 7eb6271d..514ea106 100644 --- a/kuryr_tempest_plugin/tests/scenario/base.py +++ b/kuryr_tempest_plugin/tests/scenario/base.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import six.moves + import json from multiprocessing import pool import time @@ -670,3 +672,24 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): ip = self.get_pod_ip(name) self.assertIsNotNone(ip) self.assertTrue(self.ping_ip_address(ip)) + + def update_config_map_ini_section( + self, name, conf_to_update, section, + namespace=CONF.kuryr_kubernetes.kube_system_namespace, **kwargs): + # TODO(gcheresh): Check what happens if two tests try to update + # the config map simultaneously. + + # update the config map ini part with the new values + conf_map = self.k8s_client.CoreV1Api().read_namespaced_config_map( + namespace=namespace, name=name) + data_to_update = conf_map.data[conf_to_update] + conf_parser = six.moves.configparser.ConfigParser() + conf_parser.readfp(six.moves.StringIO(data_to_update)) + for key, value in kwargs.iteritems(): + conf_parser.set(section, key, value) + str_obj = six.moves.StringIO() + conf_parser.write(str_obj) + updated_string = str_obj.getvalue() + conf_map.data[conf_to_update] = updated_string + self.k8s_client.CoreV1Api().replace_namespaced_config_map( + namespace=namespace, name=name, body=conf_map)