~ibmcharmers/charms/trusty/layer-ibm-mobilefirst-server/devel

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3

import amulet
import re
import unittest
import os
import yaml
import sys
import requests


class TestDeploy(unittest.TestCase):
    """
    Deployment test for the IBM IM charm.

    This charm doesn't do much by itself, so we expect functional
    tests to happen in the charms that use this layer (for example, websphere).
    """
    def setUp(self):
        self.d = amulet.Deployment(series='trusty')
        local_path = os.path.join(os.path.dirname(__file__), 'local.yaml')
        with open(local_path, "r") as fd:
            config = yaml.safe_load(fd)

        curl_url = config.get('ibm-repo').get('db2_curl_url')
        if not curl_url:
            message = 'Please provide the curl url from where the ' \
                      'package can be downloaded.'
            amulet.raise_status(amulet.FAIL, msg=message)
            sys.exit(1)

        curl_opts = config.get('ibm-repo').get('db2_curl_opts')
        if not curl_opts:
            message = 'Please provide the curl_opts to specify the ' \
                      'credentials to download the packages.'
            amulet.raise_status(amulet.FAIL, msg=message)
            sys.exit(1)

        self.d.add('ibm-db2', 'cs:trusty/ibm-db2')
#        self.d.add('ibm-db2', 'cs:~shilkaul/trusty/ibm-db2-0')
        self.d.add('websphere-liberty',
                   'cs:trusty/websphere-liberty-4')
        self.d.add('ibm-mobilefirst-server',
                   'cs:~ibmcharmers/trusty/ibm-mobilefirst-server')
#        self.d.add('ibm-mobilefirst-server',
#                   'cs:~shilkaul/trusty/ibm-mobilefirst-server-0')
        self.d.configure('websphere-liberty',
                         {'accept-ibm-websphere-license': True})
        self.d.configure('websphere-liberty',
                         {'accept-ibm-java-license': True})
        self.d.configure('websphere-liberty',
                         {'ibm-liberty-version': "8.5.5.8"})
        self.d.configure('websphere-liberty',
                         {'sha_wlp': "a0497da259cf6ad972500ceedbb1227c0ac72de \
                          4adc50a0fa6edc60ea044ab3a32d4f390533c98dee72ad1f36f \
                          a54d09591bb0d0ec6e6245b602e091bf7ea3de"})

        self.d.configure('ibm-db2', {'license_accepted': True,
                         'curl_url': curl_url, 'curl_opts': curl_opts})

        self.d.relate('websphere-liberty:website',
                      'ibm-mobilefirst-server:website')
        self.d.relate('ibm-db2:db',
                      'ibm-mobilefirst-server:mobilefirstserverdb')

        self.d.setup(timeout=1200)
        self.d.sentry.wait(timeout=1200)

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

    def test_mobilefirst_server_deployed(self):
        self.assertTrue(self.d.deployed)
        unit = self.d.sentry['ibm-mobilefirst-server'][0]
        url = 'http://%s:9081/appcenterconsole' % unit.info['public-address']
        url1 = 'https://%s:9443/appcenterconsole' % unit.info['public-address']
        print('Url is %s' % url)
        response = requests.get(url, verify=False)
        response = requests.get(url1, verify=False)
        # Raise an exception if the url was not a valid web page.
        response.raise_for_status()


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