From f40d9c3f1122228645f01880797b01e5e7617092 Mon Sep 17 00:00:00 2001 From: Ahmed Bilal <49-ahmedbilal@users.noreply.code.ungleich.ch> Date: Tue, 3 Sep 2019 18:06:41 +0200 Subject: [PATCH] Wip --- .gitignore | 0 Pipfile | 3 +++ Pipfile.lock | 0 config.py | 4 ++++ helper.py | 5 +---- main.py | 6 ++---- tests/test_basics.py | 5 ++--- tests/test_dead_host_mechanism.py | 6 ++---- 8 files changed, 14 insertions(+), 15 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 Pipfile mode change 100644 => 100755 Pipfile.lock create mode 100644 config.py mode change 100644 => 100755 helper.py mode change 100644 => 100755 main.py mode change 100644 => 100755 tests/test_basics.py mode change 100644 => 100755 tests/test_dead_host_mechanism.py diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Pipfile b/Pipfile old mode 100644 new mode 100755 index b89aadf..a12130c --- a/Pipfile +++ b/Pipfile @@ -7,12 +7,15 @@ verify_ssl = true bandit = "*" flake8 = "*" black = "==19.3b0" +pylint = "*" [packages] python-decouple = "*" pytest = "*" coverage = "*" +grpcio = "*" python-etcd3 = {editable = true,git = "https://github.com/kragniz/python-etcd3"} +pylint = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock old mode 100644 new mode 100755 diff --git a/config.py b/config.py new file mode 100644 index 0000000..2694fae --- /dev/null +++ b/config.py @@ -0,0 +1,4 @@ +from decouple import config +from etcd3_wrapper import Etcd3Wrapper + +etcd_client = Etcd3Wrapper(host=config("ETCD_URL")) diff --git a/helper.py b/helper.py old mode 100644 new mode 100755 index 2dc2dff..b2f99be --- a/helper.py +++ b/helper.py @@ -5,12 +5,9 @@ from ucloud_common.vm import VmPool, VMStatus from ucloud_common.host import HostPool, HostStatus from ucloud_common.request import RequestEntry, RequestPool, RequestType -from etcd3_wrapper import Etcd3Wrapper from decouple import config +from config import etcd_client as client -client = Etcd3Wrapper( - host=config("ETCD_HOST"), port=int(config("ETCD_PORT")) - ) vm_pool = VmPool(client, config("VM_PREFIX")) host_pool = HostPool(client, config("HOST_PREFIX")) request_pool = RequestPool(client, config("REQUEST_PREFIX")) diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 79fbe4b..c54751e --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ import logging from decouple import config -from etcd3_wrapper import Etcd3Wrapper +from config import etcd_client as client from ucloud_common.vm import VmPool from ucloud_common.host import HostPool @@ -28,9 +28,7 @@ logging.basicConfig( def main(vm_prefix, host_prefix, request_prefix): logging.info(f"{'*' * 5} SESSION STARTED {'*' * 5}") - client = Etcd3Wrapper( - host=config("ETCD_HOST"), port=int(config("ETCD_PORT")) - ) + vm_pool = VmPool(client, vm_prefix) host_pool = HostPool(client, host_prefix) request_pool = RequestPool(client, request_prefix) diff --git a/tests/test_basics.py b/tests/test_basics.py old mode 100644 new mode 100755 index edb3de6..227e84b --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -20,13 +20,12 @@ from main import ( main, ) -from etcd3_wrapper import Etcd3Wrapper - +from config import etcd_client class TestFunctions(unittest.TestCase): @classmethod def setUpClass(cls): - cls.client = Etcd3Wrapper() + cls.client = etcd_client cls.host_prefix = "/test/host" cls.vm_prefix = "/test/vm" diff --git a/tests/test_dead_host_mechanism.py b/tests/test_dead_host_mechanism.py old mode 100644 new mode 100755 index 477ae29..33bed23 --- a/tests/test_dead_host_mechanism.py +++ b/tests/test_dead_host_mechanism.py @@ -16,14 +16,12 @@ from main import ( dead_host_detection, dead_host_mitigation, main, + config ) -from etcd3_wrapper import Etcd3Wrapper - - class TestDeadHostMechanism(unittest.TestCase): def setUp(self): - self.client = Etcd3Wrapper() + self.client = config.etcd_client self.host_prefix = "/test/host" self.vm_prefix = "/test/vm"