Ubuntu Pastebin

Paste from 10-deploy.py at Tue, 12 Jan 2016 18:29:26 +0000

Download as text
  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import os
import unittest
import yaml
import amulet
import sys
import time
import requests

# Lots of prereqs on this charm so give it a large timeout accordingly
seconds_to_wait = 20000


class BundleTest(unittest.TestCase):
    """ Create a class for testing the charm in the unit test framework. """
    @classmethod
    def setUpClass(cls):
        """ Set up an amulet deployment using the bundle. """
        d = amulet.Deployment(juju_env='local', 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)

        host = config.get('java').get('java_host')
        print('Using Host  %s' % host)
        # Test if a IBM Java SDK host for the repository is defined
        if not host:
            print("You need to define a host for the IBM Java SDK  packages repository.\n"
                  "Edit local.yaml or tests/00-setup and run it again.")
            sys.exit(1)

        package_dir = config.get('java').get('java_package_dir')
        print('Using package_dir  %s' % package_dir)
        # Test if a SDK package_dir for the repository is defined
        if not package_dir:
            print("You need to define a package_dir for the IBM Java SDK packages"
                  " repository.\n Edit local.yaml or tests/00-setup"
                  " and run it again.")
            sys.exit(1)

        java_username = config.get('java').get('java_username')
        print('Using java_username  %s' % java_username)
        if not java_username:
            print("You need to define a java_username for the IBM Java SDK packages"
                  " repository.\n Edit local.yaml or tests/00-setup"
                  " and run it again.")
            sys.exit(1)

        java_password = config.get('java').get('java_password')
        print('Using java_password  %s' % java_password)
        # Test if a password for the repository is defined
        if not java_password:
            print("You need to define a java_password for the IBM Java SDK packages"
                  " repository.\n Edit local.yaml or tests/00-setup"
                  " and run it again.")
            sys.exit(1)


        license = config.get('java').get('java_accept-ibm-java-license')
        print('Using IBM Java SDK EULA value %s' % license)
        if not license:
            print("You need to set EULA valus for IBM Java SDK.\n"
                  "Edit local.yaml or tests/00-setup and run it again.")
            sys.exit(1)

        itype = config.get('java').get('java_install-type')
        print('Using IBM Java Install type value %s' % itype)
        if not itype:
            print("You need to define installtion type for IBM Java.\n"
                  "Edit local.yaml or tests/00-setup and run it again.")
            sys.exit(1)

        bundle_path = os.path.join(os.path.dirname(__file__), 'bundles.yaml')
        with open(bundle_path, 'r') as bundle_file:
            contents = yaml.safe_load(bundle_file)
            d.load(contents)

        d.add('ubuntu')
        d.setup(seconds_to_wait)
        d.sentry.wait(seconds_to_wait)
        cls.d = d
        # Software doesn't actually install until you accept the license
        d.configure('ibm-java', {'accept-ibm-java-license': license,
                                 'host': host,
                                 'package_dir': package_dir,
                                 'username': java_username,
                                 'password': java_password,
                                 'install-type': itype})
        d.relate('ibm-java:java', 'ubuntu:java')

        d.setup(seconds_to_wait)
        d.sentry.wait(seconds_to_wait)
        cls.d = d

    def test_deployed(self):
        """ Test to see if the bundle deployed successfully. """
        self.assertTrue(self.d.deployed)
        ibmjava_unit = self.d.sentry['ibm-java'][0]
        itype = config.get('java').get('java_install-type')
        if itype == 'full':
            # Create a simple java program
            ibmjava_unit.run('sudo mkdir -m a=rwx /home/test')
            ibmjava_unit.run('echo "import java.util.Date;" >> /home/test/Simple.java')
            ibmjava_unit.run('echo "public class Simple{" >> /home/test/Simple.java')
            ibmjava_unit.run('echo "public static void main(String args[]){" >> /home/test/Simple.java')
            ibmjava_unit.run('echo "Date date = new Date();" >> /home/test/Simple.java')
            ibmjava_unit.run('echo "System.out.println(date.toString());" >> /home/test/Simple.java')
            ibmjava_unit.run('echo "}" >> /home/test/Simple.java')
            ibmjava_unit.run('echo "}" >> /home/test/Simple.java')
            ibmjava_unit.run('sudo chmod -R 777 /home/test/Simple.java')
            ibmjava_unit.run('javac -d /home/test/ /home/test/Simple.java')
            cmd = "java -cp /home/test Simple"
            output, code = ibmjava_unit.run(cmd)
            if code != 0:
                message = 'Unable to run Java Program: As java is not installed or appropriate path variable is not set.'
                amulet.raise_status(amulet.FAIL, msg=message)
            print('Output of simple java program is  %s' % output)
        else:
            cmd = "java -version"
            output, code = ibmjava_unit.run(cmd)
            if code != 0:
                message = 'Unable to run Java Program: As java is not installed or appropriate path variable is not set.'
                amulet.raise_status(amulet.FAIL, msg=message)
            print('Output of simple java program is  %s' % output)


if __name__ == '__main__':
Download as text