Upgrading to python3 (#60)

* Migrating to python 3.7.2, but docker image is not working properly.

Need to continue investigating why it's not properly running.

* Trying to fix the build and fixing logging in the scheduler initialization.

* Trying to fix the build

* Collecting test results

* Fixing the dockerfile

* Updating the development dependencies
This commit is contained in:
mtakaki
2019-02-22 02:17:13 -08:00
committed by GitHub
parent ea4b8ccd4e
commit 10e0141454
11 changed files with 44 additions and 34 deletions

View File

@@ -8,7 +8,7 @@ jobs:
docker: docker:
# specify the version you desire here # specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- image: circleci/python:2.7 - image: circleci/python:3.7.2
working_directory: ~/repo working_directory: ~/repo
@@ -25,10 +25,11 @@ jobs:
- run: - run:
name: install dependencies name: install dependencies
command: | command: |
sudo pip install virtualenv sudo pip3 install virtualenv
virtualenv . virtualenv .
source bin/activate source bin/activate
pip install -r dev_requirements.txt pip3 install -r dev_requirements.txt
python3 setup.py install
- save_cache: - save_cache:
paths: paths:
@@ -39,7 +40,10 @@ jobs:
name: run tests name: run tests
command: | command: |
. bin/activate . bin/activate
py.test tests py.test tests --junitxml=test-reports/junit.xml
- store_test_results:
path: test-reports
- store_artifacts: - store_artifacts:
path: test-reports path: test-reports

2
.gitignore vendored
View File

@@ -13,3 +13,5 @@ dist/
.idea .idea
.pytest_cache/ .pytest_cache/
pip-selfcheck.json pip-selfcheck.json
.eggs
test-reports/

View File

@@ -1,14 +1,17 @@
FROM python:2.7-alpine FROM python:3.7.2-alpine
MAINTAINER Mitsuo Takaki <mitsuotakaki@gmail.com> MAINTAINER Mitsuo Takaki <mitsuotakaki@gmail.com>
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/ RUN python3.7 -m pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt
COPY cachet_url_monitor/* /usr/src/app/cachet_url_monitor/ COPY cachet_url_monitor/*.py /usr/src/app/cachet_url_monitor/
COPY setup.py /usr/src/app/
RUN python3.7 setup.py install
COPY config.yml /usr/src/app/config/ COPY config.yml /usr/src/app/config/
VOLUME /usr/src/app/config/ VOLUME /usr/src/app/config/
CMD ["python", "cachet_url_monitor/scheduler.py", "config/config.yml"] CMD ["python3.7", "./cachet_url_monitor/scheduler.py", "config/config.yml"]

View File

@@ -83,16 +83,9 @@ $ python cachet_url_monitor/scheduler.py config.yml
## Docker ## Docker
You can run the agent in docker, so you won't need to worry about installing python, virtualenv, or any other dependency into your OS. The `Dockerfile` and `docker-compose.yml` files are already checked in and it's ready to be used. You can run the agent in docker, so you won't need to worry about installing python, virtualenv, or any other dependency into your OS. The `Dockerfile` is already checked in and it's ready to be used.
To start the agent in a container using docker compose: You have two choices, checking this repo out and building the docker image or it can be pulled directly from [dockerhub](https://hub.docker.com/r/mtakaki/cachet-url-monitor/). You will need to create your own custom `config.yml` file and run (it will pull latest):
```
$ docker-compose build
$ docker-compose up
```
Or pulling directly from [dockerhub](https://hub.docker.com/r/mtakaki/cachet-url-monitor/). You will need to create your own custom `config.yml` file and run (it will pull latest):
``` ```
$ docker pull mtakaki/cachet-url-monitor $ docker pull mtakaki/cachet-url-monitor

View File

@@ -10,8 +10,8 @@ import requests
from yaml import dump from yaml import dump
from yaml import load from yaml import load
import latency_unit import cachet_url_monitor.latency_unit as latency_unit
import status as st import cachet_url_monitor.status as st
# This is the mandatory fields that must be in the configuration file in this # This is the mandatory fields that must be in the configuration file in this
# same exact structure. # same exact structure.
@@ -80,7 +80,7 @@ class Configuration(object):
def __init__(self, config_file): def __init__(self, config_file):
self.logger = logging.getLogger('cachet_url_monitor.configuration.Configuration') self.logger = logging.getLogger('cachet_url_monitor.configuration.Configuration')
self.config_file = config_file self.config_file = config_file
self.data = load(file(self.config_file, 'r')) self.data = load(open(self.config_file, 'r'))
self.current_fails = 0 self.current_fails = 0
self.trigger_update = True self.trigger_update = True
@@ -146,7 +146,7 @@ class Configuration(object):
ConfigurationValidationError is raised. Otherwise nothing will happen. ConfigurationValidationError is raised. Otherwise nothing will happen.
""" """
configuration_errors = [] configuration_errors = []
for key, sub_entries in configuration_mandatory_fields.iteritems(): for key, sub_entries in configuration_mandatory_fields.items():
if key not in self.data: if key not in self.data:
configuration_errors.append(key) configuration_errors.append(key)

View File

@@ -5,7 +5,7 @@ import time
import schedule import schedule
from configuration import Configuration from cachet_url_monitor.configuration import Configuration
class Agent(object): class Agent(object):
@@ -84,7 +84,7 @@ if __name__ == "__main__":
handler.addFilter(logging.Filter('cachet_url_monitor')) handler.addFilter(logging.Filter('cachet_url_monitor'))
if len(sys.argv) <= 1: if len(sys.argv) <= 1:
logging.fatal('Missing configuration file argument') logging.getLogger('cachet_url_monitor.scheduler').fatal('Missing configuration file argument')
sys.exit(1) sys.exit(1)
scheduler = Scheduler(sys.argv[1]) scheduler = Scheduler(sys.argv[1])

View File

@@ -1,9 +1,9 @@
PyYAML==3.12 PyYAML==4.2b1
codacy-coverage==1.2.18 codacy-coverage==1.2.18
ipython==4.2.0 ipython==4.2.0
mock==2.0.0 mock==2.0.0
pudb==2016.1 pudb==2016.1
pytest==3.4.2 pytest==3.4.2
pytest-cov==2.5.1 pytest-cov==2.5.1
requests==2.18.4 requests==2.21.0
schedule==0.5.0 schedule==0.5.0

View File

@@ -1,2 +1,9 @@
[metadata] [metadata]
description-file = README.md description-file = README.md
[aliases]
test=pytest
[tool:pytest]
addopts = --verbose
python_files = tests/*.py

View File

@@ -1,8 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
from distutils.core import setup #from distutils.core import setup
from setuptools import setup
setup(name='cachet-url-monitor', setup(name='cachet-url-monitor',
version='0.4', version='1.4',
description='Cachet URL monitor plugin', description='Cachet URL monitor plugin',
author='Mitsuo Takaki', author='Mitsuo Takaki',
author_email='mitsuotakaki@gmail.com', author_email='mitsuotakaki@gmail.com',
@@ -13,5 +14,7 @@ setup(name='cachet-url-monitor',
'requests', 'requests',
'yaml', 'yaml',
'schedule', 'schedule',
] ],
setup_requires=["pytest-runner"],
tests_require=["pytest"]
) )

View File

View File

@@ -10,10 +10,11 @@ import cachet_url_monitor.status
sys.modules['requests'] = mock.Mock() sys.modules['requests'] = mock.Mock()
sys.modules['logging'] = mock.Mock() sys.modules['logging'] = mock.Mock()
from cachet_url_monitor.configuration import Configuration from cachet_url_monitor.configuration import Configuration
from test.test_support import EnvironmentVarGuard import os
class ConfigurationTest(unittest.TestCase): class ConfigurationTest(unittest.TestCase):
@mock.patch.dict(os.environ, {'CACHET_TOKEN': 'token2'})
def setUp(self): def setUp(self):
def getLogger(name): def getLogger(name):
self.mock_logger = mock.Mock() self.mock_logger = mock.Mock()
@@ -30,9 +31,6 @@ class ConfigurationTest(unittest.TestCase):
sys.modules['requests'].get = get sys.modules['requests'].get = get
self.env = EnvironmentVarGuard()
self.env.set('CACHET_TOKEN', 'token2')
self.configuration = Configuration('config.yml') self.configuration = Configuration('config.yml')
sys.modules['requests'].Timeout = Timeout sys.modules['requests'].Timeout = Timeout
sys.modules['requests'].ConnectionError = ConnectionError sys.modules['requests'].ConnectionError = ConnectionError