← Back to team overview

yellow team mailing list archive

[Merge] lp:~yellow/charm-tools/trunk into lp:charm-tools

 

Brad Crittenden has proposed merging lp:~yellow/charm-tools/trunk into lp:charm-tools.

Requested reviews:
  Juan L. Negron (negronjl)

For more details, see:
https://code.launchpad.net/~yellow/charm-tools/trunk/+merge/101554

Update parsing of 'juju status' output to account for change in tokens ('state' -> 'agent-state').
-- 
https://code.launchpad.net/~yellow/charm-tools/trunk/+merge/101554
Your team Yellow Squad is subscribed to branch lp:~yellow/charm-tools/trunk.
=== modified file 'helpers/python/charmhelpers/__init__.py'
--- helpers/python/charmhelpers/__init__.py	2012-03-16 15:11:45 +0000
+++ helpers/python/charmhelpers/__init__.py	2012-08-31 13:20:31 +0000
@@ -12,6 +12,10 @@
     'relation_get',
     'relation_set',
     'unit_info',
+    'wait_for_machine',
+    'wait_for_page_contents',
+    'wait_for_relation',
+    'wait_for_unit',
     ]
 
 from collections import namedtuple
@@ -19,7 +23,6 @@
 import operator
 from shelltoolbox import (
     command,
-    run,
     script_name,
     )
 import tempfile
@@ -28,6 +31,7 @@
 import yaml
 
 
+SLEEP_AMOUNT = 0.1
 Env = namedtuple('Env', 'uid gid home')
 log = command('juju-log')
 # We create a juju_status Command here because it makes testing much,
@@ -125,14 +129,14 @@
         if len(non_zookeeper_machines) >= num_machines:
             all_machines_running = True
             for machine in non_zookeeper_machines:
-                if machine['instance-state'] != 'running':
+                if machine.get('instance-state') != 'running':
                     all_machines_running = False
                     break
             if all_machines_running:
                 break
         if time.time() - start_time >= timeout:
             raise RuntimeError('timeout waiting for service to start')
-        time.sleep(0.1)
+        time.sleep(SLEEP_AMOUNT)
     return num_machines, time.time() - start_time
 
 
@@ -141,14 +145,14 @@
     wait_for_machine(num_machines=1)
     start_time = time.time()
     while True:
-        state = unit_info(service_name, 'state')
+        state = unit_info(service_name, 'agent-state')
         if 'error' in state or state == 'started':
             break
         if time.time() - start_time >= timeout:
             raise RuntimeError('timeout waiting for service to start')
-        time.sleep(0.1)
+        time.sleep(SLEEP_AMOUNT)
     if state != 'started':
-        raise RuntimeError('unit did not start, state: ' + state)
+        raise RuntimeError('unit did not start, agent-state: ' + state)
 
 
 def wait_for_relation(service_name, relation_name, timeout=120):
@@ -160,7 +164,7 @@
             break
         if time.time() - start_time >= timeout:
             raise RuntimeError('timeout waiting for relation to be up')
-        time.sleep(0.1)
+        time.sleep(SLEEP_AMOUNT)
 
 
 def wait_for_page_contents(url, contents, timeout=120, validate=None):
@@ -178,4 +182,4 @@
                 return page
         if time.time() - start_time >= timeout:
             raise RuntimeError('timeout waiting for contents of ' + url)
-        time.sleep(0.1)
+        time.sleep(SLEEP_AMOUNT)

=== modified file 'helpers/python/charmhelpers/tests/test_charmhelpers.py'
--- helpers/python/charmhelpers/tests/test_charmhelpers.py	2012-03-19 11:50:05 +0000
+++ helpers/python/charmhelpers/tests/test_charmhelpers.py	2012-08-31 13:20:31 +0000
@@ -1,6 +1,5 @@
 # Tests for Python charm helpers.
 
-import charmhelpers
 import unittest
 import yaml
 
@@ -8,6 +7,13 @@
 from StringIO import StringIO
 from testtools import TestCase
 
+import sys
+# Path hack to ensure we test the local code, not a version installed in
+# /usr/local/lib.  This is necessary since /usr/local/lib is prepended before
+# what is specified in PYTHONPATH.
+sys.path.insert(0, 'helpers/python')
+import charmhelpers
+
 
 class CharmHelpersTestCase(TestCase):
     """A basic test case for Python charm helpers."""
@@ -56,7 +62,7 @@
                 'relations': {
                     'db': {'state': 'up'},
                     },
-                'state': unit_state,
+                'agent-state': unit_state,
                 }
             service_data['units']['{}/{}'.format(service_name, i)] = (
                 unit_data)
@@ -131,9 +137,9 @@
         self.patch(charmhelpers, 'juju_status', mock_juju_status)
         self.assertEqual(
             'pending',
-            charmhelpers.unit_info('test-service', 'state'))
+            charmhelpers.unit_info('test-service', 'agent-state'))
 
-    def test_unit_info_returns_empty_for_nonexistant_service(self):
+    def test_unit_info_returns_empty_for_nonexistent_service(self):
         # If the service passed to unit_info() has not yet started (or
         # otherwise doesn't exist), unit_info() will return an empty
         # string.

=== modified file 'setup.py'
--- setup.py	2012-03-14 22:13:47 +0000
+++ setup.py	2012-08-31 13:20:31 +0000
@@ -10,7 +10,7 @@
 
 from setuptools import setup, find_packages
 
-__version__ = '0.0.1'
+__version__ = '0.0.3'
 
 
 setup(


Follow ups