Skip to content

Commit

Permalink
Fix pep8 and UT issues
Browse files Browse the repository at this point in the history
tendrl-bug-id: Tendrl#62
Signed-off-by: nnDarshan <[email protected]>
  • Loading branch information
nnDarshan committed Jan 16, 2017
1 parent 7320a74 commit e46363b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
31 changes: 21 additions & 10 deletions tendrl/ceph_integration/persistence/persister.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
from tendrl.ceph_integration.persistence.sync_objects import SyncObject
from tendrl.commons.config import load_config
from tendrl.commons.etcdobj.etcdobj import Server as etcd_server
from tendrl.commons.persistence.etcd_persister import EtcdPersister

config = load_config(
"gluster-integration",
"/etc/tendrl/tendrl.conf"
)


class CephIntegrationEtcdPersister(EtcdPersister):
def __init__(self, config):
super(CephIntegrationEtcdPersister, self).__init__(config)
self._store = self.get_store()
def __init__(self):
etcd_kwargs = {
'port': int(config.get("commons", "etcd_port")),
'host': config.get("commons", "etcd_connection")
}
self.server = etcd_server(etcd_kwargs=etcd_kwargs)
super(CephIntegrationEtcdPersister, self).__init__()

def update_sync_object(
self,
Expand All @@ -18,7 +29,7 @@ def update_sync_object(
data,
cluster_id
):
self._store.save(
self.server.save(
SyncObject(
updated=updated,
fsid=fsid,
Expand All @@ -32,20 +43,20 @@ def update_sync_object(
)

def create_server(self, server):
self._store.save(server)
self.server.save(server)

def create_service(self, service):
self._store.save(service)
self.server.save(service)

def save_events(self, events):
for event in events:
self._store.save(event)
self.server.save(event)

def update_tendrl_context(self, context):
self._store.save(context)
self.server.save(context)

def update_tendrl_definitions(self, definition):
self._store.save(definition)
self.server.save(definition)

def update_pool(self, pool):
self._store.save(pool)
self.server.save(pool)
13 changes: 7 additions & 6 deletions tendrl/ceph_integration/tests/test_persister.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import sys
sys.modules['tendrl.commons.config'] = MagicMock()
from tendrl.ceph_integration.persistence import persister
del sys.modules['tendrl.commons.config']


class Test_Persister(object):
def setup_method(self, method):
persister.etcd_server = MagicMock()
self.Persister = persister.CephIntegrationEtcdPersister(MagicMock())
self.Persister._store = MagicMock()
self.Persister = persister.CephIntegrationEtcdPersister()
self.Persister.server = MagicMock()

def test_Persister_Creation(self):
assert self.Persister is not None
Expand All @@ -25,22 +26,22 @@ def test_update_sync_object(self):
cluster_id = "cluster_id"
self.Persister.update_sync_object(
updated, fsid, name, sync_type, version, when, data, cluster_id)
self.Persister._store.save.assert_called()
self.Persister.server.save.assert_called()

def test_create_server(self):
self.Persister.create_server("servers")
self.Persister._store.save.assert_called_with(
self.Persister.server.save.assert_called_with(
"servers"
)

def test_create_service(self):
self.Persister.create_service("service")
self.Persister._store.save.assert_called_with(
self.Persister.server.save.assert_called_with(
"service"
)

def test_save_events(self):
self.Persister.save_events(["Event1", "Event2"])
self.Persister._store.save.assert_called_with(
self.Persister.server.save.assert_called_with(
"Event2"
)

0 comments on commit e46363b

Please sign in to comment.