diff --git a/.circleci/config.yml b/.circleci/config.yml index ea7c329..867bf88 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: docker: # specify the version you desire here # 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 @@ -25,10 +25,11 @@ jobs: - run: name: install dependencies command: | - sudo pip install virtualenv + sudo pip3 install virtualenv virtualenv . source bin/activate - pip install -r dev_requirements.txt + pip3 install -r dev_requirements.txt + python3 setup.py install - save_cache: paths: @@ -39,7 +40,10 @@ jobs: name: run tests command: | . bin/activate - py.test tests + py.test tests --junitxml=test-reports/junit.xml + + - store_test_results: + path: test-reports - store_artifacts: path: test-reports diff --git a/.gitignore b/.gitignore index fb9467c..d82f6b3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ dist/ .idea .pytest_cache/ pip-selfcheck.json +.eggs +test-reports/ diff --git a/Dockerfile b/Dockerfile index 83f407d..e77426d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,17 @@ -FROM python:2.7-alpine +FROM python:3.7.2-alpine MAINTAINER Mitsuo Takaki WORKDIR /usr/src/app -COPY requirements.txt /usr/src/app/ -RUN pip install --no-cache-dir -r requirements.txt +RUN python3.7 -m pip install --upgrade pip +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/ 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"] diff --git a/README.md b/README.md index 39e674d..5235ecf 100644 --- a/README.md +++ b/README.md @@ -83,16 +83,9 @@ $ python cachet_url_monitor/scheduler.py config.yml ## 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: - -``` -$ 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): +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 pull mtakaki/cachet-url-monitor diff --git a/cachet_url_monitor/configuration.py b/cachet_url_monitor/configuration.py index efa991b..94730a5 100644 --- a/cachet_url_monitor/configuration.py +++ b/cachet_url_monitor/configuration.py @@ -10,8 +10,8 @@ import requests from yaml import dump from yaml import load -import latency_unit -import status as st +import cachet_url_monitor.latency_unit as latency_unit +import cachet_url_monitor.status as st # This is the mandatory fields that must be in the configuration file in this # same exact structure. @@ -80,7 +80,7 @@ class Configuration(object): def __init__(self, config_file): self.logger = logging.getLogger('cachet_url_monitor.configuration.Configuration') 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.trigger_update = True @@ -146,7 +146,7 @@ class Configuration(object): ConfigurationValidationError is raised. Otherwise nothing will happen. """ 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: configuration_errors.append(key) diff --git a/cachet_url_monitor/scheduler.py b/cachet_url_monitor/scheduler.py index 02af7b6..8b672e6 100644 --- a/cachet_url_monitor/scheduler.py +++ b/cachet_url_monitor/scheduler.py @@ -5,7 +5,7 @@ import time import schedule -from configuration import Configuration +from cachet_url_monitor.configuration import Configuration class Agent(object): @@ -84,7 +84,7 @@ if __name__ == "__main__": handler.addFilter(logging.Filter('cachet_url_monitor')) 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) scheduler = Scheduler(sys.argv[1]) diff --git a/dev_requirements.txt b/dev_requirements.txt index cbe1a52..69db5f2 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,9 +1,9 @@ -PyYAML==3.12 +PyYAML==4.2b1 codacy-coverage==1.2.18 ipython==4.2.0 mock==2.0.0 pudb==2016.1 pytest==3.4.2 pytest-cov==2.5.1 -requests==2.18.4 +requests==2.21.0 schedule==0.5.0 diff --git a/setup.cfg b/setup.cfg index b88034e..67f710d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,9 @@ [metadata] description-file = README.md + +[aliases] +test=pytest + +[tool:pytest] +addopts = --verbose +python_files = tests/*.py \ No newline at end of file diff --git a/setup.py b/setup.py index 2b66aba..a564090 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ #!/usr/bin/env python -from distutils.core import setup +#from distutils.core import setup +from setuptools import setup setup(name='cachet-url-monitor', - version='0.4', + version='1.4', description='Cachet URL monitor plugin', author='Mitsuo Takaki', author_email='mitsuotakaki@gmail.com', @@ -13,5 +14,7 @@ setup(name='cachet-url-monitor', 'requests', 'yaml', 'schedule', - ] - ) + ], + setup_requires=["pytest-runner"], + tests_require=["pytest"] + ) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_configuration.py b/tests/test_configuration.py index d65b84d..012aa12 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -10,10 +10,11 @@ import cachet_url_monitor.status sys.modules['requests'] = mock.Mock() sys.modules['logging'] = mock.Mock() from cachet_url_monitor.configuration import Configuration -from test.test_support import EnvironmentVarGuard +import os class ConfigurationTest(unittest.TestCase): + @mock.patch.dict(os.environ, {'CACHET_TOKEN': 'token2'}) def setUp(self): def getLogger(name): self.mock_logger = mock.Mock() @@ -30,9 +31,6 @@ class ConfigurationTest(unittest.TestCase): sys.modules['requests'].get = get - self.env = EnvironmentVarGuard() - self.env.set('CACHET_TOKEN', 'token2') - self.configuration = Configuration('config.yml') sys.modules['requests'].Timeout = Timeout sys.modules['requests'].ConnectionError = ConnectionError