forked from Tendrl/gluster-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added post checks to check if object are available in etcd post create
tendrl-bug-id: Tendrl#296 Signed-off-by: Shubhendu <shtripat@redhat.com>
- Loading branch information
Shubhendu
committed
Jun 14, 2017
1 parent
525aedc
commit 62b55dd
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tendrl/gluster_integration/objects/volume/atoms/check_volume_available/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import etcd | ||
import gevent | ||
import subprocess | ||
|
||
from tendrl.commons.event import Event | ||
from tendrl.commons.message import Message | ||
from tendrl.commons import objects | ||
from tendrl.commons.objects import AtomExecutionFailedError | ||
from tendrl.gluster_integration.objects.volume import Volume | ||
|
||
|
||
class CheckVolumeAvailable(objects.BaseAtom): | ||
def __init__(self, *args, **kwargs): | ||
super(CheckVolumeAvailable, self).__init__(*args, **kwargs) | ||
|
||
def run(self): | ||
retry_count = 0 | ||
while True: | ||
try: | ||
volumes = NS._int.client.read( | ||
"clusters/%s/Volumes" % NS.tendrl_context.integration_id | ||
) | ||
except etcd.EtcdKeyNotFound: | ||
# ignore as no volumes available till now | ||
pass | ||
|
||
if volumes: | ||
for entry in volumes.leaves: | ||
volume = Volume(vol_id=entry.key.split("Volumes/")[-1]).load() | ||
if volume.name == self.parameters['Volume.volname']: | ||
return True | ||
|
||
retry_count += 1 | ||
gevent.sleep(1) | ||
if retry_count == 20: | ||
Event( | ||
Message( | ||
priority="error", | ||
publisher=NS.publisher_id, | ||
payload={ | ||
"message": "Volume %s not reflected in tendrl yet. Timing out" % | ||
self.parameters['Volume.volname'] | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
cluster_id=NS.tendrl_context.integration_id, | ||
) | ||
) | ||
raise AtomExecutionFailedError( | ||
"Volume %s not reflected in tendrl yet. Timing out" % | ||
self.parameters['Volume.volname'] | ||
) |