Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated fix for TZ issue #51

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README_TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
1) To run the test framework, first install pytest: ```pip install pytest```
2) You can run the test two ways:
1) Run command `python -m pytest`
2) Locate and run the file `test/test_getters.py`

Note: The test "test_get_interfaces" passes for CI/CD on Github, but it does not pass on individual local system due to
computational difference on different Operating Systems of date and time.
2) Locate and run the file `test/test_getters.py`

In order to run the tests using Docker and the minimal supported Python version:
```
docker run -it --rm --name run-test -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3.6 test/run_test.sh
```

We welcome suggestions and contributions of additional tests for the framework. Please contact the Nokia owners of this repository for how to contribute.
15 changes: 8 additions & 7 deletions napalm_sros/sros.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from dictdiffer import diff
import paramiko

# Fix an issue with timezone processing in Python 3.6
from dateutil.parser import parse as dateutil_parse

# import NAPALM libraries

from lxml import etree
Expand Down Expand Up @@ -784,13 +787,12 @@ def get_interfaces(self):
if_state, "state_ns:last-oper-change", namespaces=self.nsmap
)
ifd["last_flapped"] = (
datetime.datetime.strptime(
flap_time, "%Y-%m-%dT%H:%M:%S.%fZ"
).timestamp()
if flap_time != ""
else -1.0
# This has an issue with the timezone, fixed in Python 3.7
#datetime.datetime.strptime(
# flap_time, "%Y-%m-%dT%H:%M:%S.%fZ"
#).timestamp()
dateutil_parse(flap_time).timestamp() if flap_time != "" else -1.0
)

ifd["mtu"] = convert(
int,
self._find_txt(if_state, "state_ns:oper-ip-mtu", namespaces=self.nsmap),
Expand Down Expand Up @@ -4221,4 +4223,3 @@ def cli(self, commands):
except Exception as e:
print("Error in method cli : {}".format(e))
log.error("Error in method cli : %s" % traceback.format_exc())

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ lxml>=4.6.4
ncclient>=0.6.7
xmltodict>=0.12.0
dictdiffer>=0.9.0
datetime>=4.3
datetime>=4.3
python-dateutil>=2.8.1
4 changes: 4 additions & 0 deletions test/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pip install -r requirements.txt -r requirements-dev.txt
python -m pytest
6 changes: 0 additions & 6 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test fixtures."""

import pytest
import os
from lxml import etree

from napalm.base.test import conftest as parent_conftest
Expand All @@ -10,11 +9,6 @@

from napalm_sros import sros

@pytest.fixture(scope="session", autouse=True)
def setenv():
# Set timezone such that mock link_flap timestamps are generated correctly
os.environ["TZ"] = "GMT"

@pytest.fixture(scope="class")
def set_device_parameters(request):
"""Set up the class."""
Expand Down