Fix parsing config file for freezer job

Config parsers do not guess datatypes of values
in configuration files, always storing them internally
as strings. So, we need to test if action_v is not NoneType,
and if it is not, retype to String. Retype is needed if
we get boolean value.

Change-Id: I2ddade105a9825a82e18aaf27650d769aedee4cf
This commit is contained in:
Michal Arbet 2020-01-31 19:52:02 +01:00
parent a440501ab6
commit c446ec389b
2 changed files with 29 additions and 1 deletions

View File

@ -209,7 +209,8 @@ class Job(object):
parser = configparser.ConfigParser()
parser.add_section('action')
for action_k, action_v in action.items():
parser.set('action', action_k, action_v)
if action_v is not None:
parser.set('action', action_k, str(action_v))
parser.write(f)
f.seek(0)

View File

@ -12,10 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import tempfile
import unittest
from freezer.scheduler import scheduler_job
action = {"action": "backup", "storage": "local",
"mode": "fs", "backup_name": "test",
"container": "/tmp/backuped",
"path_to_backup": "/tmp/to_backup"}
class TestSchedulerJob(unittest.TestCase):
def setUp(self):
@ -23,3 +30,23 @@ class TestSchedulerJob(unittest.TestCase):
def test(self):
scheduler_job.RunningState.stop(self.job, {})
def test_save_action_to_disk(self):
with tempfile.NamedTemporaryFile(mode='w',
delete=False) as config_file:
self.job.save_action_to_file(action, config_file)
self.assertTrue(os.path.exists(config_file.name))
def test_save_action_with_none_value_to_disk(self):
action.update({"log_file": None})
with tempfile.NamedTemporaryFile(mode='w',
delete=False) as config_file:
self.job.save_action_to_file(action, config_file)
self.assertTrue(os.path.exists(config_file.name))
def test_save_action_with_bool_value_to_disk(self):
action.update({"no_incremental": False})
with tempfile.NamedTemporaryFile(mode='w',
delete=False) as config_file:
self.job.save_action_to_file(action, config_file)
self.assertTrue(os.path.exists(config_file.name))