Fix dict conversion in tempest.conf
[functest.git] / functest / opnfv_tests / openstack / tempest / tempest.py
index bd337ce..f30bbc5 100644 (file)
@@ -306,9 +306,9 @@ class TempestCommon(singlevm.VmReady2):
         """Set image name as tempest img_name_regex"""
         rconfig = configparser.RawConfigParser()
         rconfig.read(rally_conf)
-        if not rconfig.has_section('tempest'):
-            rconfig.add_section('tempest')
-        rconfig.set('tempest', 'img_name_regex', '^{}$'.format(
+        if not rconfig.has_section('openstack'):
+            rconfig.add_section('openstack')
+        rconfig.set('openstack', 'img_name_regex', '^{}$'.format(
             self.image.name))
         with open(rally_conf, 'wb') as config_file:
             rconfig.write(config_file)
@@ -320,9 +320,9 @@ class TempestCommon(singlevm.VmReady2):
             return
         rconfig = configparser.RawConfigParser()
         rconfig.read(rally_conf)
-        if not rconfig.has_section('tempest'):
-            rconfig.add_section('tempest')
-        rconfig.set('tempest', 'swift_operator_role', role.name)
+        if not rconfig.has_section('openstack'):
+            rconfig.add_section('openstack')
+        rconfig.set('openstack', 'swift_operator_role', role.name)
         with open(rally_conf, 'wb') as config_file:
             rconfig.write(config_file)
 
@@ -342,10 +342,10 @@ class TempestCommon(singlevm.VmReady2):
         """Clean Rally config"""
         rconfig = configparser.RawConfigParser()
         rconfig.read(rally_conf)
-        if rconfig.has_option('tempest', 'img_name_regex'):
-            rconfig.remove_option('tempest', 'img_name_regex')
-        if rconfig.has_option('tempest', 'swift_operator_role'):
-            rconfig.remove_option('tempest', 'swift_operator_role')
+        if rconfig.has_option('openstack', 'img_name_regex'):
+            rconfig.remove_option('openstack', 'img_name_regex')
+        if rconfig.has_option('openstack', 'swift_operator_role'):
+            rconfig.remove_option('openstack', 'swift_operator_role')
         if rconfig.has_option('DEFAULT', 'log-file'):
             rconfig.remove_option('DEFAULT', 'log-file')
         if rconfig.has_option('DEFAULT', 'log_dir'):
@@ -353,6 +353,29 @@ class TempestCommon(singlevm.VmReady2):
         with open(rally_conf, 'wb') as config_file:
             rconfig.write(config_file)
 
+    def update_scenario_section(self):
+        """Update scenario section in tempest.conf"""
+        rconfig = configparser.RawConfigParser()
+        rconfig.read(self.conf_file)
+        filename = getattr(
+            config.CONF, '{}_image'.format(self.case_name), self.filename)
+        if not rconfig.has_section('scenario'):
+            rconfig.add_section('scenario')
+        rconfig.set('scenario', 'img_file', os.path.basename(filename))
+        rconfig.set('scenario', 'img_dir', os.path.dirname(filename))
+        rconfig.set('scenario', 'img_disk_format', getattr(
+            config.CONF, '{}_image_format'.format(self.case_name),
+            self.image_format))
+        extra_properties = self.extra_properties.copy()
+        extra_properties.update(
+            getattr(config.CONF, '{}_extra_properties'.format(
+                self.case_name), {}))
+        rconfig.set(
+            'scenario', 'img_properties',
+            conf_utils.convert_dict_to_ini(extra_properties))
+        with open(self.conf_file, 'wb') as config_file:
+            rconfig.write(config_file)
+
     def configure(self, **kwargs):  # pylint: disable=unused-argument
         """
         Create all openstack resources for tempest-based testcases and write
@@ -375,6 +398,7 @@ class TempestCommon(singlevm.VmReady2):
             image_alt_id=self.image_alt.id,
             flavor_alt_id=self.flavor_alt.id,
             domain_name=self.cloud.auth.get("project_domain_name", "Default"))
+        self.update_scenario_section()
         self.backup_tempest_config(self.conf_file, self.res_dir)
 
     def run(self, **kwargs):