[Git][NTPsec/ntpsec][master] 4 commits: ntpd_row_limit is an instance variable of the ControlSession class

Eric S. Raymond gitlab at mg.gitlab.com
Wed Dec 7 17:38:18 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
ea45821e by Matt Selsky at 2016-12-07T09:09:58-05:00
ntpd_row_limit is an instance variable of the ControlSession class

- - - - -
60f5dadf by Matt Selsky at 2016-12-07T09:09:58-05:00
Add some tests for pylib/statfiles.py and fix bugs identified by the tests.

Including:
- missing import
- calling isdigit() on an int
- time.struct_time has no member m_isdst (and tm_isdst is read-only)
- posix_to_iso should return ISO 8601 in UTC

- - - - -
b10d1a27 by Matt Selsky at 2016-12-07T10:09:14-05:00
Check for getpassphrase() no longer needed since it was used for C ntpq

Related to "Drop C version of ntpq in favor of the Python version."

- - - - -
d6b8b3e6 by Matt Selsky at 2016-12-07T10:13:43-05:00
Typo

- - - - -


5 changed files:

- devel/ifdex-ignores
- pylib/packet.py
- pylib/statfiles.py
- + tests/pylib/test_statfiles.py
- wafhelpers/configure.py


Changes:

=====================================
devel/ifdex-ignores
=====================================
--- a/devel/ifdex-ignores
+++ b/devel/ifdex-ignores
@@ -181,7 +181,7 @@ USE_ROUTING_SOCKET
 YY_YY_NTP_PARSER_TAB_H_INCLUDED
 calloc			# In Unity
 close			# In Windows port config
-free			# Un Unity and ntpd/ntp_parser.tab.c
+free			# In Unity and ntpd/ntp_parser.tab.c
 malloc			# In Unity and ntpd/ntp_parser.tab.c
 in_addr6		# In Windows port config
 lifr_addrlen		# ISC interface-iterator code


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -1270,7 +1270,7 @@ class ControlSession:
                         else:
                             # ntpd has lower cap on row limit
                             self.ntpd_row_limit -= 1
-                            limit = min(limit, ntpd_row_limit)
+                            limit = min(limit, self.ntpd_row_limit)
                             if self.debug:
                                 warn("Row limit reduced to %d following CERR_BADVALUE.\n" % limit)
                     elif e.errorcode in (SERR_INCOMPLETE, SERR_TIMEOUT):
@@ -1339,7 +1339,7 @@ class ControlSession:
                         frags = min(MAXFRAGS, frags + 1)
                     else:
                         limit = min(3 * MAXFRAGS,
-                                    ntpd_row_limit,
+                                    self.ntpd_row_limit,
                                     max(limit + 1,
                                         limit * 33 / 32))
 


=====================================
pylib/statfiles.py
=====================================
--- a/pylib/statfiles.py
+++ b/pylib/statfiles.py
@@ -7,6 +7,7 @@ Requires GNUPLOT and liberation fonts installed.
 #SPDX-License-Identifier: BSD-2-Clause
 from __future__ import print_function, division
 
+import calendar
 import glob, gzip, os, socket, sys, time
 
 class NTPStats:
@@ -203,16 +204,15 @@ class NTPStats:
 
 def iso_to_posix(s):
     "Accept timestamps in ISO 8661 format or numeric POSIX time. UTC only."
-    if s.isdigit():
+    if str(s).isdigit():
         return int(s)
     else:
         t = time.strptime(s, "%Y-%m-%dT%H:%M:%S")
-        t.m_isdst = 0
         # don't use time.mktime() as that is local tz
-        return  calendar.timegm(t)
+        return calendar.timegm(t)
 
 def posix_to_iso(t):
-    "ISO 8601 string from Unix time."
-    return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(t))
+    "ISO 8601 string in UTC from Unix time."
+    return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(t))
 
 # end


=====================================
tests/pylib/test_statfiles.py
=====================================
--- /dev/null
+++ b/tests/pylib/test_statfiles.py
@@ -0,0 +1,20 @@
+import unittest
+import ntp.statfiles
+
+class TestPylibStatfilesMethods(unittest.TestCase):
+
+    def test_iso_to_posix(self):
+        self.assertEqual(ntp.statfiles.iso_to_posix(1480999786), 1480999786)
+        self.assertEqual(ntp.statfiles.iso_to_posix("2016-12-06T04:49:46"), 1480999786)
+
+    def test_posix_to_iso(self):
+        self.assertEqual(ntp.statfiles.posix_to_iso(1480999786), "2016-12-06T04:49:46")
+
+    def test_iso_to_posix_inverts_posix_to_iso(self):
+        self.assertEqual(ntp.statfiles.iso_to_posix(ntp.statfiles.posix_to_iso(1480999786)), 1480999786)
+
+    def test_posix_to_iso_inverts_iso_to_posix(self):
+        self.assertEqual(ntp.statfiles.posix_to_iso(ntp.statfiles.iso_to_posix("2016-12-06T04:49:46")), "2016-12-06T04:49:46")
+
+if __name__ == '__main__':
+    unittest.main()


=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -308,7 +308,6 @@ def cmd_configure(ctx, config):
                 ('clock_settime', ["time.h"], "RT"),
                 ('EVP_MD_do_all_sorted', ["openssl/evp.h"], "CRYPTO"),
                 ('getdtablesize', ["unistd.h"]),
-                ('getpassphrase', ["stdlib.h"]),                # Sun systems
                 ('getrusage', ["sys/time.h", "sys/resource.h"]),
                 ('MD5Init', ["md5.h"], "CRYPTO"),
                 ('ntp_adjtime', ["sys/time.h", "sys/timex.h"]),         # BSD



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/1edfa59c286ee900bda1adb45918c2326eb50036...d6b8b3e6fcb7052e633547e706ea142c3e28b8db
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161207/ccddbfe3/attachment.html>


More information about the vc mailing list