Skip to content

Commit

Permalink
Check tanner version (#78)
Browse files Browse the repository at this point in the history
* check tanner compatibility

* use class for version checker

* Message format
  • Loading branch information
afeena authored Jan 8, 2018
1 parent db274cc commit 6b0bb7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions snare.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
"""

import argparse
import asyncio
import configparser
Expand All @@ -27,7 +26,7 @@
import uuid
from concurrent.futures import ProcessPoolExecutor
from urllib.parse import urlparse, unquote, parse_qsl

from versions_manager import VersionManager
import aiohttp
import git
import mimetypes
Expand Down Expand Up @@ -385,11 +384,15 @@ def parse_timeout(timeout):


@asyncio.coroutine
def check_tanner_connection():
def check_tanner():
vm = VersionManager()
with aiohttp.ClientSession() as client:
req_url = 'http://{}:8090'.format(args.tanner)
req_url = 'http://{}:8090/version'.format(args.tanner)
try:
resp = yield from client.get(req_url)
result = yield from resp.json()
version = result["version"]
vm.check_compatibility(version)
except aiohttp.errors.ClientOSError:
print("Can't connect to tanner host {}".format(req_url))
exit(1)
Expand Down Expand Up @@ -444,7 +447,7 @@ def check_tanner_connection():
else:
add_meta_tag(args.page_dir, args.index_page)
loop = asyncio.get_event_loop()
loop.run_until_complete(check_tanner_connection())
loop.run_until_complete(check_tanner())

pool = ProcessPoolExecutor(max_workers=multiprocessing.cpu_count())
compare_version_fut = None
Expand Down
15 changes: 15 additions & 0 deletions versions_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from distutils.version import StrictVersion


class VersionManager:
def __init__(self):
self.version = "0.1.0"
self.version_mapper = {
"0.1.0": "0.4.0"
}

def check_compatibility(self, tanner_version):
max_version = self.version_mapper[self.version]
if not StrictVersion(tanner_version) <= StrictVersion(max_version):
print("Wrong tanner version: {}. Need version: {} or less".format(tanner_version, max_version))
exit(1)

0 comments on commit 6b0bb7c

Please sign in to comment.