~ibmcharmers/charms/trusty/layer-ibm-platform-lsf-server/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3

import unittest
import amulet
import time
import re

# Lots of prereqs on this charm (eg: java), so give it a large timeout
seconds_to_wait = 20000


class BundleTest(unittest.TestCase):
    """ Create a class for testing the charm in the unit test framework. """
    @classmethod
    def setUpClass(self):
        """
        Deployment test for IBM Platform LSF Server
        """
        self.d = amulet.Deployment(series='trusty')
        self.d.add('ibm-platform-lsf-storage',
                   'cs:~ibmcharmers/trusty/ibm-platform-lsf-storage')
        self.d.add('ibm-platform-lsf-master',
                   'cs:~ibmcharmers/trusty/ibm-platform-lsf-master')
        self.d.add('ibm-platform-lsf-server',
                   'cs:~ibmcharmers/trusty/ibm-platform-lsf-server')
        self.d.relate('ibm-platform-lsf-storage:storage',
                      'ibm-platform-lsf-master:storage')
        self.d.relate('ibm-platform-lsf-storage:storage',
                      'ibm-platform-lsf-server:storage')
        time.sleep(100)
        self.d.relate('ibm-platform-lsf-storage:master',
                      'ibm-platform-lsf-server:master')
        self.d.setup(seconds_to_wait)

    def test_deploy_with_placeholder_resource(self):
        # The status message when using placeholder resources will include the
        # string "ibm_lsf_installer resource".
        # If we see that, the test is successful.
        sentry_re = re.compile('ibm_lsf_installer resource')
        self.d.sentry.wait_for_messages({"ibm-platform-lsf-storage":
                                        sentry_re})

    def test_unit_deployed(self):
        # verify unit
        self.assertTrue(self.d.deployed)
        unit_server_0 = self.d.sentry['ibm-platform-lsf-server'][0]
        state_server = unit_server_0.info['agent-state']
        print('Server state is %s' % state_server)
        server_ip = unit_server_0.info['public-address']
        print('Server IP is %s' % server_ip)
        cmd1, code = unit_server_0.run(". /usr/share/lsf/conf/profile.lsf;\
                                       /usr/share/lsf/*/*/bin/bhosts")
        if code != 0:
            message = 'bhosts command failed to run , may be LSF is down.'
            amulet.raise_status(amulet.FAIL, msg=message)
        print('The output of running bhosts command on server host is \n')
        print(str(cmd1))


if __name__ == '__main__':
    unittest.main()