Commit 47f4f8a6 authored by Kirill Smelkov's avatar Kirill Smelkov

promise/plugin/check_cpri_lock: test: Factor common code to write to log and...

promise/plugin/check_cpri_lock: test: Factor common code to write to log and promise into common place

We are going to add more tests. Keeping the code to initialize test
environment duplicated over and over will be not convenient.

/cc @jhuge, @tomo, @xavier_thompson, @Daetalus
/reviewed-by @lu.xu
/reviewed-on !127
parent 6db7895c
......@@ -28,6 +28,7 @@
import mock
import os
import time
import json
from datetime import datetime
from datetime import timedelta
from slapos.grid.promise import PromiseError
......@@ -41,39 +42,33 @@ class TestCheckCpriLock(TestPromisePluginMixin):
def setUp(self):
super(TestCheckCpriLock, self).setUp()
self.amarisoft_rf_info_log = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'amarisoft_rf_info.json.log')
def writeLog(self, data):
with open(self.amarisoft_rf_info_log, 'w') as f:
f.write(
"""{"time": "%s", "log_level": "INFO", "message": "RF info", "data": %s}""" %
((datetime.now() - timedelta(seconds=5)).strftime("%Y-%m-%d %H:%M:%S")[:-3], json.dumps(data)))
def writePromise(self, **kw):
kw.update({'amarisoft-rf-info-log': self.amarisoft_rf_info_log,
# 'stats-period': 100,
})
super(TestCheckCpriLock, self).writePromise(self.promise_name,
"from %s import %s\nextra_config_dict = %r\n"
% (RunPromise.__module__, RunPromise.__name__, kw))
def test_promise_success(self):
self.amarisoft_rf_info_log = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'amarisoft_rf_info.json.log')
with open(self.amarisoft_rf_info_log, 'w') as f:
f.write(
"""
{"time": "%s", "log_level": "INFO", "message": "RF info", "data": {'rf_info': "CPRI: x16 HW SW"}}
""" % ((datetime.now() - timedelta(seconds=5)).strftime("%Y-%m-%d %H:%M:%S")[:-3],))
self.writePromise(**{
'amarisoft-rf-info-log': self.amarisoft_rf_info_log,
# 'stats-period': 100,
})
self.writeLog({'rf_info': "CPRI: x16 HW SW"})
self.writePromise()
self.configureLauncher()
self.launcher.run()
def test_promise_fail(self):
self.amarisoft_rf_info_log = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'amarisoft_rf_info.json.log')
with open(self.amarisoft_rf_info_log, 'w') as f:
f.write(
"""
{"time": "%s", "log_level": "INFO", "message": "RF info", "data": {'rf_info': "CPRI: x16\\n"}}
""" % ((datetime.now() - timedelta(seconds=5)).strftime("%Y-%m-%d %H:%M:%S")[:-3],))
self.writePromise(**{
'amarisoft-rf-info-log': self.amarisoft_rf_info_log,
# 'stats-period': 100,
})
self.writeLog({'rf_info': "CPRI: x16\\n"})
self.writePromise()
self.configureLauncher()
with self.assertRaises(PromiseError):
self.launcher.run()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment