~simpoir/landscape-client-charm/sync-charmhelpers-and-keys

« back to all changes in this revision

Viewing changes to tests/10-deploy-register.py

  • Committer: David Britton
  • Date: 2014-12-17 23:42:31 UTC
  • mfrom: (49.1.11 fix-integration-tests)
  • Revision ID: dpb@canonical.com-20141217234231-1mlmxjnv8ghnv8qp
Merging fix-integration-tests. [f=1399312] [r=andreas,blackboxsw]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
# This amulet test deploys the bundles.yaml file in this directory.
 
4
 
 
5
import os
 
6
import unittest
 
7
import yaml
 
8
import amulet
 
9
import time
 
10
 
 
11
seconds_to_wait = 1200
 
12
 
 
13
 
 
14
class BundleTest(unittest.TestCase):
 
15
    """Create a class for testing the charm in the unit test framework."""
 
16
    @classmethod
 
17
    def setUpClass(cls):
 
18
        """Set up an amulet deployment using the bundle."""
 
19
        origin = os.environ.get('LANDSCAPE_CLIENT_CHARM_ORIGIN', None)
 
20
        d = amulet.Deployment()
 
21
        bundle_path = os.path.join(os.path.dirname(__file__), 'bundles.yaml')
 
22
        with open(bundle_path, 'r') as bundle_file:
 
23
            contents = yaml.safe_load(bundle_file)
 
24
            d.load(contents)
 
25
        if origin is not None:
 
26
            d.configure("landscape-client", {"origin": origin})
 
27
        d.setup(seconds_to_wait)
 
28
        d.sentry.wait(seconds_to_wait)
 
29
        cls.d = d
 
30
 
 
31
    def test_deployed(self):
 
32
        """Test to see if the bundle deployed successfully."""
 
33
        self.assertTrue(self.d.deployed)
 
34
 
 
35
    def test_wait_for_success_in_log(self):
 
36
        """landscape-client should successfully register."""
 
37
        logfile = "/var/log/juju/unit-landscape-client*.log"
 
38
        grep = "grep 'System successfully registered'"
 
39
        # Only principal units are addressable in this way.
 
40
        for i in range(20):
 
41
            result = self.d.sentry.unit['ubuntu/0'].run(
 
42
                "%s %s" % (grep, logfile))
 
43
            if result[1] != 0:
 
44
                time.sleep(10)
 
45
            else:
 
46
                # success, fall through
 
47
                break
 
48
        else:
 
49
            raise AssertionError("Could not verify registration of the client")
 
50
 
 
51
 
 
52
if __name__ == '__main__':
 
53
    unittest.main()