Verify consistent timestamp format

All timestamps in Vitrage should be of the same format:
'%Y-%m-%dT%H:%M:%SZ'

This is needed so webhooks will know what format to expect.

Change-Id: I27624b28e8aa1770d805ee68982509894522b8e6
Story: 1776181
Task: 28541
This commit is contained in:
Ifat Afek 2018-12-17 11:35:09 +00:00
parent 1e881b6b88
commit 32c4e62fbb
2 changed files with 20 additions and 0 deletions

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from datetime import datetime
import json
from networkx.readwrite import json_graph
import six
@ -314,6 +315,23 @@ class BaseVitrageTempest(base.BaseTestCase):
self.assertEqual(num_entities, graph.num_vertices())
self.assertEqual(num_edges, graph.num_edges())
self._validate_timestamps(graph)
def _validate_timestamps(self, graph):
self._validate_timestamp(graph, VProps.UPDATE_TIMESTAMP)
self._validate_timestamp(graph, VProps.VITRAGE_SAMPLE_TIMESTAMP)
def _validate_timestamp(self, graph, timestamp_name):
for vertex in graph.get_vertices():
timestamp = vertex.get(timestamp_name)
if timestamp:
try:
datetime.strptime(timestamp, utils.TIMESTAMP_FORMAT)
except ValueError:
self.fail('Unexpected timestamp format of \'%s\' in: %s\n'
'The format should be: %s' %
(timestamp_name, vertex, utils.TIMESTAMP_FORMAT))
@staticmethod
def _get_value(item, key):
return utils.uni2str(item[key])

View File

@ -26,6 +26,8 @@ import subprocess
LOG = logging.getLogger(__name__)
TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
def get_from_terminal(command):
proc = os.popen(command)