~ibmcharmers/charms/trusty/ibm-wxs/devel

« back to all changes in this revision

Viewing changes to tests/10-bundles-test.py

  • Committer: anitanayak at ibm
  • Date: 2017-03-05 12:18:48 UTC
  • Revision ID: anitanayak@in.ibm.com-20170305121848-m86blq9hoetsy2y3
deprecating the charm

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 sys
10
 
import requests
11
 
import time 
12
 
 
13
 
# Lots of prereqs on this charm (eg: java), so give it a large timeout
14
 
seconds_to_wait = 1000
15
 
 
16
 
 
17
 
class BundleTest(unittest.TestCase):
18
 
    """ Create a class for testing the charm in the unit test framework. """
19
 
    @classmethod
20
 
    def setUpClass(cls):
21
 
        """ Set up an amulet deployment using the bundle. """
22
 
        d = amulet.Deployment(juju_env='local', series='trusty')
23
 
    # We have a contextual test, if no config is present, initialze the
24
 
    # test with an empty configuration set
25
 
        config = {}
26
 
        local_path = os.path.join(os.path.dirname(__file__), 'local.yaml')
27
 
        with open(local_path, "r") as fd:
28
 
            config = yaml.safe_load(fd)
29
 
 
30
 
        host = config.get('wxs').get('wxs_host')
31
 
        print('Using HOST  %s' % host)
32
 
        # Test if a WXS host for the repository is defined
33
 
        if not host:
34
 
            print("You need to define a host for the IBMWXS packages"
35
 
                  " repository.\n Edit local.yaml or tests/00-setup"
36
 
                  " and run it again.")
37
 
            sys.exit(1)
38
 
 
39
 
        package_dir = config.get('wxs').get('wxs_package_dir')
40
 
        print('Using package_dir  %s' % package_dir)
41
 
        # Test if a WXS package_dir for the repository is defined
42
 
        if not package_dir:
43
 
            print("You need to define a package_dir for the IBMWXS packages"
44
 
                  " repository.\n Edit local.yaml or tests/00-setup"
45
 
                  " and run it again.")
46
 
            sys.exit(1)
47
 
 
48
 
        wxs_username = config.get('wxs').get('wxs_username')
49
 
        print('Using wxs_username  %s' % wxs_username)
50
 
        # Test if a WXS wxs_username for the repository is defined
51
 
        if not wxs_username:
52
 
            print("You need to define a wxs_username for the IBMWXS packages"
53
 
                  " repository.\n Edit local.yaml or tests/00-setup"
54
 
                  " and run it again.")
55
 
            sys.exit(1)
56
 
 
57
 
        wxs_password = config.get('wxs').get('wxs_password')
58
 
        print('Using wxs_password  %s' % wxs_password)
59
 
        # Test if a WXS  for the repository is defined
60
 
        if not wxs_password:
61
 
            print("You need to define a wxs_password for the IBMWXS packages"
62
 
                  " repository.\n Edit local.yaml or tests/00-setup"
63
 
                  " and run it again.")
64
 
            sys.exit(1)
65
 
 
66
 
        basepkg = config.get('wxs').get('wxs_base_package')
67
 
        print('Using IBMWXS base package %s' % basepkg)
68
 
        if not basepkg:
69
 
            print("You need to define a base package name for IBM WXS.\n"
70
 
                  " Edit local.yaml or tests/00-setup and run it again.")
71
 
            sys.exit(1)
72
 
 
73
 
        fixpkg = config.get('wxs').get('wxs_fix_pkg')
74
 
        print('Using IBMWXS fix package %s' % fixpkg)
75
 
        if not fixpkg:
76
 
            print("You need to define a fix package name for IBM WXS.\n"
77
 
                  " Edit local.yaml or tests/00-setup and run it again.")
78
 
            sys.exit(1)
79
 
 
80
 
        imname = config.get('wxs').get('im_name')
81
 
        print('Using IBMWXS IM package %s' % imname)
82
 
        if not imname:
83
 
            print("You need to define a IM package name for IBM WXS.\n"
84
 
                  " Edit local.yaml or tests/00-setup and run it again.")
85
 
            sys.exit(1)
86
 
        sha_base_pkg = config.get('wxs').get('sha_base_pkg')
87
 
        print('Using IBMWXS sha base package %s' % sha_base_pkg)
88
 
        if not sha_base_pkg:
89
 
            print("You need to define a SHA Base package  for IBM WXS.\n"
90
 
                  " Edit local.yaml or tests/00-setup and run it again.")
91
 
            sys.exit(1)
92
 
        sha_fix_pkg = config.get('wxs').get('sha_fix_pkg')
93
 
        print('Using IBMWXS sha fix package %s' % sha_fix_pkg)
94
 
        if not sha_fix_pkg:
95
 
            print("You need to define a SHA FIX package for IBM WXS.\n"
96
 
                  " Edit local.yaml or tests/00-setup and run it again.")
97
 
            sys.exit(1)
98
 
        sha_im_pkg = config.get('wxs').get('sha_im_pkg')
99
 
        print('Using IBMWXS sha IM  package %s' % sha_im_pkg)
100
 
        if not sha_im_pkg:
101
 
            print("You need to define a SHA IM package  for IBM WXS.\n"
102
 
                  " Edit local.yaml or tests/00-setup and run it again.")
103
 
            sys.exit(1)
104
 
        # Software doesn't actually install until you accept the license
105
 
        d.add('ibmwxs')
106
 
        d.configure('ibmwxs', { 'accept-ibm-wxs-license': True,
107
 
                               'accept-ibm-im-license': True,
108
 
                               'host': host,
109
 
                               'package_dir': package_dir,
110
 
                               'username': wxs_username,
111
 
                               'password': wxs_password,
112
 
                               'wxs_base_file_name': basepkg,
113
 
                               'wxs_fixpack_file_name': fixpkg,
114
 
                               'im_file_name': imname,
115
 
                               'sha_base': sha_base_pkg,
116
 
                               'sha_fixpack': sha_fix_pkg,
117
 
                               'sha_im': sha_im_pkg })
118
 
 
119
 
        d.setup(seconds_to_wait)
120
 
        d.sentry.wait(seconds_to_wait)
121
 
        cls.d = d
122
 
 
123
 
    def test_deployed(self):
124
 
        """ Test to see if the bundle deployed successfully. """
125
 
        self.assertTrue(self.d.deployed)
126
 
        ibmwxs_unit = self.d.sentry.unit['ibmwxs/0']
127
 
    # Checking the WXS
128
 
        cmd = "/opt/ibm/WXS/ObjectGrid/gettingstarted/runclient.sh g key1"
129
 
        ibmwxs_unit.run(cmd)
130
 
 
131
 
if __name__ == '__main__':
132
 
    unittest.main()