~ibmcharmers/ibm-db2-49

Owner: achittet
Status: Needs Review
Vote: +0 (+2 needed for approval)

CPP?: No
OIL?: No

ibm-db2 is a promulgated charm , so published to edge channel
Please review the charm move to stable channel


Tests

Substrate Status Results Last Updated
lxc RETRY 19 days ago
aws RETRY 19 days ago
gce RETRY 19 days ago

Add Comment

Login to comment/vote on this review.


Policy Checklist

Description Unreviewed Pass Fail

General

Must verify that any software installed or utilized is verified as coming from the intended source.
  • Any software installed from the Ubuntu or CentOS default archives satisfies this due to the apt and yum sources including cryptographic signing information.
  • Third party repositories must be listed as a configuration option that can be overridden by the user and not hard coded in the charm itself.
  • Launchpad PPAs are acceptable as the add-apt-repository command retrieves the keys securely.
  • Other third party repositories are acceptable if the signing key is embedded in the charm.
Must provide a means to protect users from known security vulnerabilities in a way consistent with best practices as defined by either operating system policies or upstream documentation.
Basically, this means there must be instructions on how to apply updates if you use software not from distribution channels.
Must have hooks that are idempotent.
Should be built using charm layers.
Should use Juju Resources to deliver required payloads.

Testing and Quality

charm proof must pass without errors or warnings.
Must include passing unit, functional, or integration tests.
Tests must exercise all relations.
Tests must exercise config.
set-config, unset-config, and re-set must be tested as a minimum
Must not use anything infrastructure-provider specific (i.e. querying EC2 metadata service).
Must be self contained unless the charm is a proxy for an existing cloud service, e.g. ec2-elb charm.
Must not use symlinks.
Bundles must only use promulgated charms, they cannot reference charms in personal namespaces.
Must call Juju hook tools (relation-*, unit-*, config-*, etc) without a hard coded path.
Should include a tests.yaml for all integration tests.

Metadata

Must include a full description of what the software does.
Must include a maintainer email address for a team or individual who will be responsive to contact.
Must include a license. Call the file 'copyright' and make sure all files' licenses are specified clearly.
Must be under a Free license.
Must have a well documented and valid README.md.
Must describe the service.
Must describe how it interacts with other services, if applicable.
Must document the interfaces.
Must show how to deploy the charm.
Must define external dependencies, if applicable.
Should link to a recommend production usage bundle and recommended configuration if this differs from the default.
Should reference and link to upstream documentation and best practices.

Security

Must not run any network services using default passwords.
Must verify and validate any external payload
  • Known and understood packaging systems that verify packages like apt, pip, and yum are ok.
  • wget | sh style is not ok.
Should make use of whatever Mandatory Access Control system is provided by the distribution.
Should avoid running services as root.

All changes | Changes since last revision

Source Diff

Files changed 84

Inline diff comments 0

No comments yet.

Back to file index

README.md

  1
--- README.md
  2
+++ README.md
  3
@@ -1,11 +1,11 @@
  4
-Charm for IBM DB2 10.5
  5
+Charm for IBM DB2 11.1.1
  6
 
  7
 Overview
  8
 --------
  9
 
 10
 IBM DB2
 11
 
 12
-IBM DB2 Enterprise Server Edition provides scalable database server software to handle the demanding workloads of large and midsize enterprise servers. It delivers high performance across multiple workloads, while helping to reduce administration, storage, development and server costs.
 13
+IBM DB2 Enterprise Server Edition provides scalable database server software to handle the demanding workloads of large and midsize enterprise servers. Itdelivers high performance across multiple workloads, while helping to reduce administration, storage, development and server costs.
 14
 DB2 Server is provided as part of this charm.
 15
 
 16
 For details on DB2, as well as information on purchasing, please visit:
 17
@@ -20,9 +20,9 @@
 18
 To acquire and download DB2, follow instructions available at [Product Page LUW][product-page-enterprise] or [Product Page Express][product-page-express].
 19
 The tab `Support&downloads` in [Product Page LUW][product-page-enterprise] gives different options for downloading the packages. 
 20
 
 21
-Download steps for IBM DB2 10.5 using [Passport Advantage][passport-advantage] is mentioned in [Downloading IBM DB2 10.5 for LUW][download-db2]. The Part Number used is CIXV0ML for X86-64 platform and that for Power is CN3YQML. To get more information on accessing [Passport Advantage][passport-advantage] please visit the link [Accessing Passport Advantage][access-passport-advantage].
 22
-
 23
-To install the downloaded binaries you must agree to the IBM license. You can view the full license for DB2 by visiting the [Software license agreements search website][license-info]. Search for "DB2 Enterprise Server Edition 10.5.0.5" and choose the license that applies to the version you are using.
 24
+Download steps for IBM DB2 11.1.1 using [Passport Advantage][passport-advantage] is mentioned in [Downloading IBM DB2 11.1.1 for LUW][download-db2]. To get more information on accessing [Passport Advantage][passport-advantage] please visit the link [Accessing Passport Advantage][access-passport-advantage].
 25
+
 26
+To install the downloaded binaries you must agree to the IBM license. You can view the full license for DB2 by visiting the [Software license agreements search website][license-info]. Search for "DB2 Enterprise Server Edition 11.1.1" and choose the license that applies to the version you are using.
 27
 
 28
 In case you already have an IBM account and cannot download the product or for other error during SW download, please refer to the [IBM Support Site][ibm-support] to solve the error.
 29
 
 30
@@ -49,40 +49,17 @@
 31
 
 32
 2. For deploying either use an existing machine, or create a new machine using
 33
 
 34
-        juju add-machine
 35
-        juju deploy --to <machine number> --repository=<path_to_charms_folder> local:trusty/ibm-db2
 36
-
 37
-3. Set all required config values like the curl__opts to log into the host machine and curl_url which specifies the url to download the packages, by using juju set command. To provide these run the following command: 
 38
-
 39
-        juju set ibm-db2 curl_opts=<login credentials>
 40
-        juju set ibm-db2 curl_url=<url to download package?shavalue>
 41
-
 42
-    For eg:
 43
-
 44
-        juju set ibm-db2 curl_opts="-u user:password"
 45
-        juju set ibm-db2 curl_url="http://<ipaddress>/debs/ibm-db2/DB2_Svr_10.5.0.3_Linux_x86-64.tar.gz?sha512=ae20be99e3cd2cef24d53a28331871d7193cfc7f7c24c580e6e78dc58c9ffb364cbcc69cb3773d2f0135b8c9be7ee40a7dc4e09fec0a4d731c4864bbba87d31e"
 46
-   
 47
-    The command to find the checksum value is `sha512sum <Package Name>`
 48
-
 49
-    In the above example sha512 is used, you can use sha256 or md5 as well.
 50
-Also in the above example, the packages are hosted on webserver, so http protocol is used, if you have placed the packages on sftp server, then replace the protocol with sftp.
 51
-
 52
-4. At this point DB2 install will wait for you to accept the License. To install the downloaded binaries you must agree to the IBM license.  The license file(s) can be found in the product binaries you downloaded.
 53
-
 54
-If you agree to the license, run the following command :
 55
-
 56
-    juju set ibm-db2 license_accepted=True
 57
+        juju deploy ibm-db2 --resource ibm_db2_installer=</path/to/installer.tar.gz>
 58
+
 59
+To use this charm, you must agree to the Terms of Use. You can view the full license for `ibm-db2`.
 60
+
 61
+This charm requires acceptance of Terms of Use. When deploying from the Charm Store, these terms will be presented to you for your consideration. To accept the terms:
 62
+
 63
+        juju agree ibmcharmers/ibm-db2/1
 64
 
 65
 
 66
 Juju deploy command will install db2 and will expose the hostname, port number, db2 instance, install path  and userid to the users. 
 67
 
 68
-
 69
-Uninstallation of IBM DB2
 70
----------------------------
 71
-
 72
-Setting the license_accepted to False will uninstall the product. 
 73
-
 74
-    juju set ibm-db2 license_accepted=False
 75
 
 76
 Additional configuration parameters 
 77
 -----------------------------------
 78
@@ -225,29 +202,22 @@
 79
 
 80
 [product-page-enterprise]: http://www-01.ibm.com/software/data/db2/linux-unix-windows/index.html
 81
 
 82
-[download-db2]: http://www-01.ibm.com/support/docview.wss?uid=swg21638030
 83
+[download-db2]: http://www-01.ibm.com/support/docview.wss?uid=swg21985358
 84
 
 85
 [passport-advantage]: http://www.ibm.com/software/howtobuy/passportadvantage
 86
 
 87
 [access-passport-advantage]: http://www-01.ibm.com/support/docview.wss?uid=swg21566554
 88
 
 89
-[ibm-db2]: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.kc.doc/welcome.html
 90
+[ibm-db2]: https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.kc.doc/welcome.html
 91
 
 92
 [license-info]: http://www-03.ibm.com/software/sla/sladb.nsf/search
 93
 
 94
 [passport-db2]: http://www-01.ibm.com/software/passportadvantage/
 95
 
 96
-[db2-knowledgecenter]: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.kc.doc/welcome.html
 97
+[db2-knowledgecenter]: https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.welcome.doc/doc/welcome.html
 98
 
 99
 [ibm-support]: https://www-947.ibm.com/support/entry/myportal/support
100
 
101
 [db2-BLU-acceleration]: http://www.ibm.com/developerworks/data/library/techarticle/dm-1309db2bluaccel/
102
 
103
-[db2-memory-disk-requirement]: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.qb.server.doc/doc/r0008877.html?cp=SSEPGG_9.7.0%2F
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
+[db2-memory-dsik-requirement]: https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.qb.server.doc/doc/r0008877.html
Back to file index

config.yaml

 1
--- config.yaml
 2
+++ config.yaml
 3
@@ -1,4 +1,30 @@
 4
 "options":
 5
+  "extra_packages":
 6
+    "description": "Space separated list of extra deb packages to install.\n"
 7
+    "type": "string"
 8
+    "default": ""
 9
+  "package_status":
10
+    "default": "install"
11
+    "type": "string"
12
+    "description": "The status of service-affecting packages will be set to this value\
13
+      \ in the dpkg database. Valid values are \"install\" and \"hold\".\n"
14
+  "install_sources":
15
+    "description": "List of extra apt sources, per charm-helpers standard format (a\
16
+      \ yaml list of strings encoded as a string). Each source may be either a line\
17
+      \ that can be added directly to sources.list(5), or in the form ppa:<user>/<ppa-name>\
18
+      \ for adding Personal Package Archives, or a distribution component to enable.\n"
19
+    "type": "string"
20
+    "default": ""
21
+  "install_keys":
22
+    "description": "List of signing keys for install_sources package sources, per\
23
+      \ charmhelpers standard format (a yaml list of strings encoded as a string).\
24
+      \ The keys should be the full ASCII armoured GPG public keys. While GPG key\
25
+      \ ids are also supported and looked up on a keyserver, operators should be aware\
26
+      \ that this mechanism is insecure. null can be used if a standard package signing\
27
+      \ key is used that will already be installed on the machine, and for PPA sources\
28
+      \ where the package signing key is securely retrieved from Launchpad.\n"
29
+    "type": "string"
30
+    "default": ""
31
   "curl_url":
32
     "type": "string"
33
     "default": ""
34
@@ -27,32 +53,6 @@
35
       can proceed. If required, setting this option to True indicates that you
36
       have read and accepted the IBM terms and conditions found in the license
37
       file referenced by the charm.
38
-  "extra_packages":
39
-    "description": "Space separated list of extra deb packages to install.\n"
40
-    "type": "string"
41
-    "default": ""
42
-  "package_status":
43
-    "default": "install"
44
-    "type": "string"
45
-    "description": "The status of service-affecting packages will be set to this value\
46
-      \ in the dpkg database. Valid values are \"install\" and \"hold\".\n"
47
-  "install_sources":
48
-    "description": "List of extra apt sources, per charm-helpers standard format (a\
49
-      \ yaml list of strings encoded as a string). Each source may be either a line\
50
-      \ that can be added directly to sources.list(5), or in the form ppa:<user>/<ppa-name>\
51
-      \ for adding Personal Package Archives, or a distribution component to enable.\n"
52
-    "type": "string"
53
-    "default": ""
54
-  "install_keys":
55
-    "description": "List of signing keys for install_sources package sources, per\
56
-      \ charmhelpers standard format (a yaml list of strings encoded as a string).\
57
-      \ The keys should be the full ASCII armoured GPG public keys. While GPG key\
58
-      \ ids are also supported and looked up on a keyserver, operators should be aware\
59
-      \ that this mechanism is insecure. null can be used if a standard package signing\
60
-      \ key is used that will already be installed on the machine, and for PPA sources\
61
-      \ where the package signing key is securely retrieved from Launchpad.\n"
62
-    "type": "string"
63
-    "default": ""
64
   "dftdbpath":
65
     "type": "string"
66
     "default": "/tmp"
Back to file index

deps/interface/trunk/README.md

 1
--- 
 2
+++ deps/interface/trunk/README.md
 3
@@ -0,0 +1,66 @@
 4
+# Overview
 5
+
 6
+This interface layer handles the communication between IBM DB2 and Consumer
 7
+charms. The provider end of this interface provides the IBM DB2 service. The
 8
+consumer part requires the existence of a provider to function.
 9
+
10
+## Usage
11
+
12
+### Provides
13
+
14
+This interface layer will set the following states, as appropriate:
15
+
16
+- `{relation_name}.connected`: The relation is established, but IBM DB2 may not
17
+yet have provided any connection or service information.
18
+
19
+- `{relation_name}.sshconfigured`: A consumer ssh key has been added to the
20
+IBM DB2 `authorized_keys` file.
21
+
22
+- `{relation_name}.ready`: IBM DB2 has established relation with the consumer
23
+charm and the SSH key has been exchanged. DB2 has provided its connection
24
+string information, and is ready to accept requests from the consumer.
25
+
26
+- `{relation_name}.departed`: The relation has been removed. Any cleanup
27
+related to the consumer charm should happen now on the IBM DB2 charm since the
28
+consumer is going away.
29
+
30
+
31
+### Requires
32
+
33
+Consumers like WAS, Mobile First Server, etc require this interface to connect
34
+to IBM DB2. This interface layer will set the following states, as appropriate:
35
+
36
+- `{relation_name}.connected`: The consumer charm has been related to IBM DB2.
37
+At this point, the consumer charm sends the SSH key to IBM DB2 charm.
38
+
39
+    For example, the consumer charm can send the ssh key to IBM DB2 charm as follows:
40
+
41
+    ```
42
+    @when 'db.connected'
43
+    @when_not 'db.sshconfigured'
44
+    function configure_sshkeys_dbs() {
45
+        SSH_PATH=/root/.ssh
46
+        if [ ! -f  $SSH_PATH/id_rsa.pub ]; then
47
+                juju-log "Setting up SSH keys."
48
+                ssh-keygen -t rsa -f $SSH_PATH/id_rsa -N ''
49
+        fi
50
+        key="`cat $SSH_PATH/id_rsa.pub`"
51
+        relation_call --state=db.connected set_ssh_keys "$key" || true
52
+    }
53
+    ```
54
+
55
+-  `{relation_name}.ready`: IBM DB2 is ready to send connection information.
56
+The consumer charm can access the IBM DB2 details from the interface using the
57
+following methods:
58
+
59
+   - get_db2_hostname() - host name of IBM DB2
60
+   - get_db2_port() - port number of IBM DB2
61
+   - get_db2_path() - the install location of IBM DB2
62
+   - get_dbusername() - User name created for the consumer service to connect to DB2
63
+   - get_dbuserpw() - Password for connecting to DB2
64
+   - get_db2_instance_name() - Instance name created for the consumer service
65
+
66
+
67
+- `{relation_name}.departed`: The relation has been removed. Any cleanup
68
+related to IBM DB2 should happen now on the consumer charm since IBM DB2 is
69
+going away.
Back to file index

deps/interface/trunk/interface.yaml

1
--- 
2
+++ deps/interface/trunk/interface.yaml
3
@@ -0,0 +1,4 @@
4
+name: db2
5
+summary: Facilitates communication between IBM DB2 and database consumers
6
+version: 1
7
+maintainer: "IBM Juju Support Team <jujusupp@us.ibm.com>"
Back to file index

deps/interface/trunk/provides.py

 1
--- 
 2
+++ deps/interface/trunk/provides.py
 3
@@ -0,0 +1,80 @@
 4
+from charms.reactive import hook
 5
+from charms.reactive import RelationBase
 6
+from charms.reactive import scopes
 7
+
 8
+
 9
+class db2Provides(RelationBase):
10
+    # Every unit connecting will get the same information
11
+    scope = scopes.SERVICE
12
+    # convenient way to provide accessor methods
13
+    auto_accessors = ['db2_path', 'db2_port']
14
+
15
+    @hook('{provides:db2}-relation-joined')
16
+    def joined(self):
17
+        conversation = self.conversation()
18
+        conversation.remove_state('{relation_name}.departed')
19
+        conversation.set_state('{relation_name}.connected')
20
+
21
+    @hook('{provides:db2}-relation-changed')
22
+    def changed(self):
23
+        conversation = self.conversation()
24
+        conversation.remove_state('{relation_name}.departed')
25
+        conversation.set_state('{relation_name}.connected')
26
+        if str(conversation.get_remote('ssh_key')) != "None":
27
+            conversation.set_state('{relation_name}.ready')
28
+
29
+    @hook('{provides:db2}-relation-departed')
30
+    def departed(self):
31
+        conversation = self.conversation()
32
+        conversation.remove_state('{relation_name}.connected')
33
+        conversation.remove_state('{relation_name}.ready')
34
+        conversation.set_state('{relation_name}.departed')
35
+
36
+    def dismiss(self, service):
37
+        conversation = self.conversation(service)
38
+        conversation.remove_state('{relation_name}.departed')
39
+
40
+    def reset_states(self, service):
41
+        conversation = self.conversation(service)
42
+        conversation.remove_state('{relation_name}.connected')
43
+        conversation.remove_state('{relation_name}.departed')
44
+        conversation.remove_state('{relation_name}.ready')
45
+
46
+    def set_db_details(self, service, db2_path, db2_port, hostname,
47
+                       dbusername, dbuserpw, db2_instance_name, dbs_created):
48
+        conversation = self.conversation(service)
49
+        conversation.set_remote(data={
50
+            'db2_ready': True,
51
+            'db2_path': db2_path,
52
+            'db2_port': db2_port,
53
+            'hostname': hostname,
54
+            'dbusername': dbusername,
55
+            'dbuserpw': dbuserpw,
56
+            'db2_instance_name': db2_instance_name,
57
+            'dbs_created': dbs_created,
58
+        })
59
+
60
+    def set_sshconfigured(self, service):
61
+        conversation = self.conversation(service)
62
+        conversation.set_state('{relation_name}.sshconfigured')
63
+
64
+    def dismiss_sshconfigured(self, service):
65
+        conversation = self.conversation(service)
66
+        conversation.remove_state('{relation_name}.sshconfigured')
67
+
68
+    def get_sshkeys(self, service):
69
+        conversation = self.conversation(service)
70
+        return conversation.get_remote('ssh_key')
71
+
72
+    def get_dbnames(self, service):
73
+        conversation = self.conversation(service)
74
+        return conversation.get_remote('db_names')
75
+
76
+    def services(self):
77
+        """
78
+        Return a list of services requesting databases.
79
+        """
80
+        service = []
81
+        for conversation in self.conversations():
82
+            service.append(conversation.scope)
83
+        return service
Back to file index

deps/interface/trunk/requires.py

 1
--- 
 2
+++ deps/interface/trunk/requires.py
 3
@@ -0,0 +1,65 @@
 4
+# Licensed under the Apache License, Version 2.0 (the "License");
 5
+# you may not use this file except in compliance with the License.
 6
+# You may obtain a copy of the License at
 7
+#
 8
+#     http://www.apache.org/licenses/LICENSE-2.0
 9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS,
12
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+# See the License for the specific language governing permissions and
14
+# limitations under the License.
15
+
16
+from charms.reactive import hook
17
+from charms.reactive import RelationBase
18
+from charms.reactive import scopes
19
+
20
+
21
+class db2Requires(RelationBase):
22
+    scope = scopes.GLOBAL
23
+    auto_accessors = ['ssh_key']
24
+
25
+    @hook('{requires:db2}-relation-joined')
26
+    def joined(self):
27
+        self.remove_state('{relation_name}.departed')
28
+        self.set_state('{relation_name}.connected')
29
+
30
+    @hook('{requires:db2}-relation-changed')
31
+    def changed(self):
32
+        self.remove_state('{relation_name}.departed')
33
+        self.set_state('{relation_name}.connected')
34
+        if str(self.get_remote('db2_port')) != "None":
35
+            self.set_state('{relation_name}.ready')
36
+
37
+    @hook('{requires:db2}-relation-departed')
38
+    def departed(self):
39
+        self.remove_state('{relation_name}.connected')
40
+        self.remove_state('{relation_name}.ready')
41
+        self.set_state('{relation_name}.departed')
42
+
43
+    def get_db2_port(self):
44
+        return self.get_remote('db2_port')
45
+
46
+    def get_db2_path(self):
47
+        return self.get_remote('db2_path')
48
+
49
+    def get_db2_hostname(self):
50
+        return self.get_remote('hostname')
51
+
52
+    def get_dbusername(self):
53
+        return self.get_remote('dbusername')
54
+
55
+    def get_dbuserpw(self):
56
+        return self.get_remote('dbuserpw')
57
+
58
+    def get_db2_instance_name(self):
59
+        return self.get_remote('db2_instance_name')
60
+
61
+    def get_db2_dbnames(self):
62
+        return self.get_remote('dbs_created')
63
+
64
+    def set_ssh_keys(self, ssh_key):
65
+        self.set_remote('ssh_key', ssh_key)
66
+
67
+    def set_dbs(self, db_names):
68
+        self.set_remote('db_names', db_names)
Back to file index

deps/layer/layer-apt/.gitignore

1
--- 
2
+++ deps/layer/layer-apt/.gitignore
3
@@ -0,0 +1,2 @@
4
+*~
5
+*.pyc
Back to file index

deps/layer/layer-apt/README.md

  1
--- 
  2
+++ deps/layer/layer-apt/README.md
  3
@@ -0,0 +1,168 @@
  4
+# Apt layer
  5
+
  6
+The Apt layer for Juju enables layered charms to more easily deal with
  7
+deb packages and apt sources in a simple and efficient manner. It
  8
+provides consistent configuration for operators, allowing them to
  9
+easily specify custom apt sources and additional debs required for
 10
+their particular installations.
 11
+
 12
+## Configuration
 13
+
 14
+The charm may provide defaults for these service configuration
 15
+(config.yaml) options, and the operator may override them as required.
 16
+
 17
+* `extra_packages`
 18
+
 19
+  A space separated list of additional deb packages to install on
 20
+  each unit.
 21
+
 22
+* `package_status`
 23
+
 24
+  'install' or 'hold'. When set to hold, packages installed using
 25
+  the Apt layer API will be pinned, so that they will not be
 26
+  automatically upgraded when package updates are performed. 'hold'
 27
+  is particularly useful for allowing a service such as Landscape
 28
+  to automatically apply security updates to most of the system,
 29
+  whilst holding back any potentially service affecting updates.
 30
+
 31
+* `install_sources`
 32
+
 33
+  A list of apt sources containing the packages that need to be installed.
 34
+  Each source may be either a line that can be added directly to
 35
+  sources.list(5), or in the form ppa:<user>/<ppa-name> for adding
 36
+  Personal Package Archives, or a distribution component to enable.
 37
+  The list is a yaml list, encoded as a string. The nicest way of
 38
+  declaring this in a yaml file looks like the following (in particular,
 39
+  the | character indicates that the value is a multiline string):
 40
+
 41
+  ```yaml
 42
+  install_sources: |
 43
+      - ppa:stub/cassandra
 44
+      - deb http://www.apache.org/dist/cassandra/debian 21x main
 45
+  ```
 46
+
 47
+* `install_keys`
 48
+
 49
+  A list of GPG signing keys to accept. There needs to be one entry
 50
+  per entry in install_sources. null may be used if no keep is
 51
+  needed, which is the case for PPAs and for the standard Ubuntu
 52
+  archives. Keys should be full ASCII armoured GPG public keys.
 53
+  GPG key ids are also accepted, but in most environments this
 54
+  mechanism is not secure. The install_keys list, like
 55
+  install_sources, must also be a yaml formatted list encoded as
 56
+  a string:
 57
+
 58
+  ```yaml
 59
+  install_keys: |
 60
+      - null
 61
+      - |
 62
+          -----BEGIN PGP PUBLIC KEY BLOCK-----
 63
+          Version: GnuPG v1
 64
+
 65
+          mQINBFQJvgUBEAC0KcYCTj0hd15p4fiXBsbob0sKgsvN5Lm7N9jzJWlGshJ0peMi
 66
+          kH8YhDXw5Lh+mPEHksL7t1L8CIr1a+ntns/Opt65ZPO38ENVkOqEVAn9Z5sIoZsb
 67
+          AUeLlJzSeRLTKhcOugK7UcsQD2FHnMBJz50bxis9X7pjmnc/tWpjAGJfaWdjDIo=
 68
+          =yiQ4
 69
+          -----END PGP PUBLIC KEY BLOCK-----
 70
+  ```
 71
+
 72
+## Usage
 73
+
 74
+Queue packages for installation, and have handlers waiting for
 75
+these packages to finish being installed:
 76
+
 77
+```python
 78
+import charms.apt
 79
+
 80
+@hook('install')
 81
+def install():
 82
+    charms.apt.queue_install(['git'])
 83
+
 84
+@when_not('apt.installed.gnupg')
 85
+def install_gnupg():
 86
+    charms.apt.queue_install(['gnupg'])
 87
+
 88
+@when('apt.installed.git')
 89
+@when('apt.installed.gnupg')
 90
+def grabit():
 91
+    clone_repo()
 92
+    validate_repo()
 93
+```
 94
+
 95
+### API
 96
+
 97
+Several methods are exposed in the charms.apt Python package.
 98
+
 99
+* `add_source(source, key=None)`
100
+
101
+  Add an apt source.
102
+
103
+  A source may be either a line that can be added directly to
104
+  sources.list(5), or in the form ppa:<user>/<ppa-name> for adding
105
+  Personal Package Archives, or a distribution component to enable.
106
+
107
+  The package signing key should be an ASCII armoured GPG key. While
108
+  GPG key ids are also supported, the retrieval mechanism is insecure.
109
+  There is no need to specify the package signing key for PPAs or for
110
+  the main Ubuntu archives.
111
+
112
+  It is preferable if charms do not call this directly to hard
113
+  coded apt sources, but instead have these sources listed
114
+  as defaults in the install_sources config option. This allows
115
+  operators to mirror your packages to internal archives and
116
+  deploy your charm in environments without network access.
117
+
118
+  Sets the `apt.needs_update` reactive state.
119
+
120
+* `queue_install(packages, options=None)`
121
+
122
+  Queue one or more deb packages for install. The actual package
123
+  installation will be performed later by a handler in the
124
+  apt layer. The `apt.installed.{name}` state will be set once
125
+  the package installed (one state for each package).
126
+
127
+  If a package has already been installed it will not be reinstalled.
128
+
129
+  If a package has already been queued it will not be requeued, and
130
+  the install options will not be changed.
131
+
132
+* `installed()`
133
+
134
+  Returns the set of deb packages installed by this layer.
135
+
136
+* `purge(packages)`
137
+
138
+  Purge one or more deb packages from the system
139
+
140
+
141
+### Extras
142
+
143
+These methods are called automatically by the reactive framework as
144
+reactive state demands. However, you can also invoke them directly
145
+if you want the operation done right now.
146
+
147
+* `update()`
148
+
149
+  Update the apt cache. Removes the `apt.needs_update` state.
150
+
151
+
152
+* `install_queued()`
153
+
154
+  Installs deb packages queued for installation. On success, removes
155
+  the `apt.queued_installs` state, sets the `apt.installed.{packagename}`
156
+  state for each installed package, and returns True. On failure,
157
+  sets the unit workload status to blocked and returns False.
158
+  The package installs remain queued.
159
+
160
+
161
+## Support
162
+
163
+This layer is maintained on Launchpad by
164
+Stuart Bishop (stuart.bishop@canonical.com).
165
+
166
+Code is available using git at git+ssh://git.launchpad.net/layer-apt.
167
+
168
+Bug reports can be made at https://bugs.launchpad.net/layer-apt.
169
+
170
+Queries and comments can be made on the Juju mailing list, Juju IRC
171
+channels, or at https://answers.launchpad.net/layer-apt.
Back to file index

deps/layer/layer-apt/config.yaml

 1
--- 
 2
+++ deps/layer/layer-apt/config.yaml
 3
@@ -0,0 +1,34 @@
 4
+options:
 5
+  extra_packages:
 6
+    description: >
 7
+        Space separated list of extra deb packages to install.
 8
+    type: string
 9
+    default: ""
10
+  package_status:
11
+    default: "install"
12
+    type: string
13
+    description: >
14
+        The status of service-affecting packages will be set to this
15
+        value in the dpkg database. Valid values are "install" and "hold".
16
+  install_sources:
17
+    description: >
18
+        List of extra apt sources, per charm-helpers standard
19
+        format (a yaml list of strings encoded as a string). Each source
20
+        may be either a line that can be added directly to
21
+        sources.list(5), or in the form ppa:<user>/<ppa-name> for adding
22
+        Personal Package Archives, or a distribution component to enable.
23
+    type: string
24
+    default: ""
25
+  install_keys:
26
+    description: >
27
+        List of signing keys for install_sources package sources, per
28
+        charmhelpers standard format (a yaml list of strings encoded as
29
+        a string). The keys should be the full ASCII armoured GPG public
30
+        keys. While GPG key ids are also supported and looked up on a
31
+        keyserver, operators should be aware that this mechanism is
32
+        insecure. null can be used if a standard package signing key is
33
+        used that will already be installed on the machine, and for PPA
34
+        sources where the package signing key is securely retrieved from
35
+        Launchpad.
36
+    type: string
37
+    default: ""
Back to file index

deps/layer/layer-apt/copyright

 1
--- 
 2
+++ deps/layer/layer-apt/copyright
 3
@@ -0,0 +1,15 @@
 4
+Copyright 2015-2016 Canonical Ltd.
 5
+
 6
+This file is part of the Apt layer for Juju.
 7
+
 8
+This program is free software: you can redistribute it and/or modify
 9
+it under the terms of the GNU General Public License version 3, as
10
+published by the Free Software Foundation.
11
+
12
+This program is distributed in the hope that it will be useful, but
13
+WITHOUT ANY WARRANTY; without even the implied warranties of
14
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+PURPOSE.  See the GNU General Public License for more details.
16
+
17
+You should have received a copy of the GNU General Public License
18
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
Back to file index

deps/layer/layer-apt/lib/charms/__init__.py

1
--- 
2
+++ deps/layer/layer-apt/lib/charms/__init__.py
3
@@ -0,0 +1,2 @@
4
+from pkgutil import extend_path
5
+__path__ = extend_path(__path__, __name__)
Back to file index

deps/layer/layer-apt/lib/charms/apt.py

  1
--- 
  2
+++ deps/layer/layer-apt/lib/charms/apt.py
  3
@@ -0,0 +1,180 @@
  4
+# Copyright 2015-2016 Canonical Ltd.
  5
+#
  6
+# This file is part of the Apt layer for Juju.
  7
+#
  8
+# This program is free software: you can redistribute it and/or modify
  9
+# it under the terms of the GNU General Public License version 3, as
 10
+# published by the Free Software Foundation.
 11
+#
 12
+# This program is distributed in the hope that it will be useful, but
 13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
 14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 15
+# PURPOSE.  See the GNU General Public License for more details.
 16
+#
 17
+# You should have received a copy of the GNU General Public License
 18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 19
+
 20
+'''
 21
+charms.reactive helpers for dealing with deb packages.
 22
+
 23
+Add apt package sources using add_source(). Queue deb packages for
 24
+installation with install(). Configure and work with your software
 25
+once the apt.installed.{packagename} state is set.
 26
+'''
 27
+import itertools
 28
+import subprocess
 29
+
 30
+from charmhelpers import fetch
 31
+from charmhelpers.core import hookenv, unitdata
 32
+from charms import reactive
 33
+
 34
+
 35
+__all__ = ['add_source', 'update', 'queue_install', 'install_queued',
 36
+           'installed', 'purge', 'ensure_package_status']
 37
+
 38
+
 39
+def add_source(source, key=None):
 40
+    '''Add an apt source.
 41
+
 42
+    Sets the apt.needs_update state.
 43
+
 44
+    A source may be either a line that can be added directly to
 45
+    sources.list(5), or in the form ppa:<user>/<ppa-name> for adding
 46
+    Personal Package Archives, or a distribution component to enable.
 47
+
 48
+    The package signing key should be an ASCII armoured GPG key. While
 49
+    GPG key ids are also supported, the retrieval mechanism is insecure.
 50
+    There is no need to specify the package signing key for PPAs or for
 51
+    the main Ubuntu archives.
 52
+    '''
 53
+    # Maybe we should remember which sources have been added already
 54
+    # so we don't waste time re-adding them. Is this time significant?
 55
+    fetch.add_source(source, key)
 56
+    reactive.set_state('apt.needs_update')
 57
+
 58
+
 59
+def queue_install(packages, options=None):
 60
+    """Queue one or more deb packages for install.
 61
+
 62
+    The `apt.installed.{name}` state is set once the package is installed.
 63
+
 64
+    If a package has already been installed it will not be reinstalled.
 65
+
 66
+    If a package has already been queued it will not be requeued, and
 67
+    the install options will not be changed.
 68
+
 69
+    Sets the apt.queued_installs state.
 70
+    """
 71
+    # Filter installed packages.
 72
+    store = unitdata.kv()
 73
+    queued_packages = store.getrange('apt.install_queue.', strip=True)
 74
+    packages = {package: options for package in packages
 75
+                if not (package in queued_packages or
 76
+                        reactive.helpers.is_state('apt.installed.' + package))}
 77
+    if packages:
 78
+        unitdata.kv().update(packages, prefix='apt.install_queue.')
 79
+        reactive.set_state('apt.queued_installs')
 80
+
 81
+
 82
+def installed():
 83
+    '''Return the set of deb packages completed install'''
 84
+    return set(state.split('.', 2)[2] for state in reactive.bus.get_states()
 85
+               if state.startswith('apt.installed.'))
 86
+
 87
+
 88
+def purge(packages):
 89
+    """Purge one or more deb packages from the system"""
 90
+    fetch.apt_purge(packages, fatal=True)
 91
+    store = unitdata.kv()
 92
+    store.unsetrange(packages, prefix='apt.install_queue.')
 93
+    for package in packages:
 94
+        reactive.remove_state('apt.installed.{}'.format(package))
 95
+
 96
+
 97
+def update():
 98
+    """Update the apt cache.
 99
+
100
+    Removes the apt.needs_update state.
101
+    """
102
+    status_set(None, 'Updating apt cache')
103
+    fetch.apt_update(fatal=True)  # Friends don't let friends set fatal=False
104
+    reactive.remove_state('apt.needs_update')
105
+
106
+
107
+def install_queued():
108
+    '''Installs queued deb packages.
109
+
110
+    Removes the apt.queued_installs state and sets the apt.installed state.
111
+
112
+    On failure, sets the unit's workload state to 'blocked' and returns
113
+    False. Package installs remain queued.
114
+
115
+    On success, sets the apt.installed.{packagename} state for each
116
+    installed package and returns True.
117
+    '''
118
+    store = unitdata.kv()
119
+    queue = sorted((options, package)
120
+                   for package, options in store.getrange('apt.install_queue.',
121
+                                                          strip=True).items())
122
+
123
+    installed = set()
124
+    for options, batch in itertools.groupby(queue, lambda x: x[0]):
125
+        packages = [b[1] for b in batch]
126
+        try:
127
+            status_set(None, 'Installing {}'.format(','.join(packages)))
128
+            fetch.apt_install(packages, options, fatal=True)
129
+            store.unsetrange(packages, prefix='apt.install_queue.')
130
+            installed.update(packages)
131
+        except subprocess.CalledProcessError:
132
+            status_set('blocked',
133
+                       'Unable to install packages {}'
134
+                       .format(','.join(packages)))
135
+            return False  # Without setting reactive state.
136
+
137
+    for package in installed:
138
+        reactive.set_state('apt.installed.{}'.format(package))
139
+
140
+    reactive.remove_state('apt.queued_installs')
141
+    return True
142
+
143
+
144
+def ensure_package_status():
145
+    '''Hold or unhold packages per the package_status configuration option.
146
+
147
+    All packages installed using this module and handlers are affected.
148
+
149
+    An mechanism may be added in the future to override this for a
150
+    subset of installed packages.
151
+    '''
152
+    packages = installed()
153
+    if not packages:
154
+        return
155
+    config = hookenv.config()
156
+    package_status = config['package_status']
157
+    changed = reactive.helpers.data_changed('apt.package_status',
158
+                                            (package_status, sorted(packages)))
159
+    if changed:
160
+        if package_status == 'hold':
161
+            hookenv.log('Holding packages {}'.format(','.join(packages)))
162
+            fetch.apt_hold(packages)
163
+        else:
164
+            hookenv.log('Unholding packages {}'.format(','.join(packages)))
165
+            fetch.apt_unhold(packages)
166
+    reactive.remove_state('apt.needs_hold')
167
+
168
+
169
+def status_set(state, message):
170
+    """Set the unit's workload status.
171
+
172
+    Set state == None to keep the same state and just change the message.
173
+    """
174
+    if state is None:
175
+        state = hookenv.status_get()[0]
176
+        if state == 'unknown':
177
+            state = 'maintenance'  # Guess
178
+    if state in ('error', 'blocked'):
179
+        lvl = hookenv.WARNING
180
+    else:
181
+        lvl = hookenv.INFO
182
+    hookenv.status_set(state, message)
183
+    hookenv.log('{}: {}'.format(state, message), lvl)
Back to file index

deps/layer/layer-apt/reactive/apt.py

  1
--- 
  2
+++ deps/layer/layer-apt/reactive/apt.py
  3
@@ -0,0 +1,98 @@
  4
+# Copyright 2015-2016 Canonical Ltd.
  5
+#
  6
+# This file is part of the Apt layer for Juju.
  7
+#
  8
+# This program is free software: you can redistribute it and/or modify
  9
+# it under the terms of the GNU General Public License version 3, as
 10
+# published by the Free Software Foundation.
 11
+#
 12
+# This program is distributed in the hope that it will be useful, but
 13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
 14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 15
+# PURPOSE.  See the GNU General Public License for more details.
 16
+#
 17
+# You should have received a copy of the GNU General Public License
 18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 19
+
 20
+'''
 21
+charms.reactive helpers for dealing with deb packages.
 22
+
 23
+Add apt package sources using add_source(). Queue deb packages for
 24
+installation with install(). Configure and work with your software
 25
+once the apt.installed.{packagename} state is set.
 26
+'''
 27
+from charmhelpers import fetch
 28
+from charmhelpers.core import hookenv
 29
+from charms import reactive
 30
+from charms.reactive import when, when_not
 31
+
 32
+import charms.apt
 33
+# Aliases for backwards compatibility
 34
+from charms.apt import add_source, queue_install, installed, purge
 35
+
 36
+
 37
+__all__ = ['add_source', 'update', 'queue_install', 'install_queued',
 38
+           'installed', 'purge', 'ensure_package_status']
 39
+
 40
+
 41
+@when('apt.needs_update')
 42
+def update():
 43
+    charms.apt.update()
 44
+
 45
+
 46
+@when('apt.queued_installs')
 47
+@when_not('apt.needs_update')
 48
+def install_queued():
 49
+    charms.apt.install_queued()
 50
+
 51
+
 52
+@when_not('apt.queued_installs')
 53
+def ensure_package_status():
 54
+    charms.apt.ensure_package_status()
 55
+
 56
+
 57
+def configure_sources():
 58
+    """Add user specified package sources from the service configuration.
 59
+
 60
+    See charmhelpers.fetch.configure_sources for details.
 61
+    """
 62
+    hookenv.log('Initializing Apt Layer')
 63
+    config = hookenv.config()
 64
+
 65
+    # We don't have enums, so we need to validate this ourselves.
 66
+    package_status = config.get('package_status')
 67
+    if package_status not in ('hold', 'install'):
 68
+        charms.apt.status_set('blocked',
 69
+                              'Unknown package_status {}'
 70
+                              ''.format(package_status))
 71
+        # Die before further hooks are run. This isn't very nice, but
 72
+        # there is no other way to inform the operator that they have
 73
+        # invalid configuration.
 74
+        raise SystemExit(0)
 75
+
 76
+    sources = config.get('install_sources')
 77
+    keys = config.get('install_keys')
 78
+    if reactive.helpers.data_changed('apt.configure_sources', (sources, keys)):
 79
+        fetch.configure_sources(update=False,
 80
+                                sources_var='install_sources',
 81
+                                keys_var='install_keys')
 82
+        reactive.set_state('apt.needs_update')
 83
+
 84
+    extra_packages = sorted(config.get('extra_packages', '').split())
 85
+    if extra_packages:
 86
+        queue_install(extra_packages)
 87
+
 88
+
 89
+# Per https://github.com/juju-solutions/charms.reactive/issues/33,
 90
+# this module may be imported multiple times so ensure the
 91
+# initialization hook is only registered once. I have to piggy back
 92
+# onto the namespace of a module imported before reactive discovery
 93
+# to do this.
 94
+if not hasattr(reactive, '_apt_registered'):
 95
+    # We need to register this to run every hook, not just during install
 96
+    # and config-changed, to protect against race conditions. If we don't
 97
+    # do this, then the config in the hook environment may show updates
 98
+    # to running hooks well before the config-changed hook has been invoked
 99
+    # and the intialization provided an opertunity to be run.
100
+    hookenv.atstart(configure_sources)
101
+    reactive._apt_registered = True
Back to file index

deps/layer/layer-basic/.gitignore

1
--- 
2
+++ deps/layer/layer-basic/.gitignore
3
@@ -0,0 +1,5 @@
4
+*.pyc
5
+*~
6
+.ropeproject
7
+.settings
8
+.tox
Back to file index

deps/layer/layer-basic/Makefile

 1
--- 
 2
+++ deps/layer/layer-basic/Makefile
 3
@@ -0,0 +1,24 @@
 4
+#!/usr/bin/make
 5
+
 6
+all: lint unit_test
 7
+
 8
+
 9
+.PHONY: clean
10
+clean:
11
+	@rm -rf .tox
12
+
13
+.PHONY: apt_prereqs
14
+apt_prereqs:
15
+	@# Need tox, but don't install the apt version unless we have to (don't want to conflict with pip)
16
+	@which tox >/dev/null || (sudo apt-get install -y python-pip && sudo pip install tox)
17
+
18
+.PHONY: lint
19
+lint: apt_prereqs
20
+	@tox --notest
21
+	@PATH=.tox/py34/bin:.tox/py35/bin flake8 $(wildcard hooks reactive lib unit_tests tests)
22
+	@charm proof
23
+
24
+.PHONY: unit_test
25
+unit_test: apt_prereqs
26
+	@echo Starting tests...
27
+	tox
Back to file index

deps/layer/layer-basic/README.md

  1
--- 
  2
+++ deps/layer/layer-basic/README.md
  3
@@ -0,0 +1,221 @@
  4
+# Overview
  5
+
  6
+This is the base layer for all charms [built using layers][building].  It
  7
+provides all of the standard Juju hooks and runs the
  8
+[charms.reactive.main][charms.reactive] loop for them.  It also bootstraps the
  9
+[charm-helpers][] and [charms.reactive][] libraries and all of their
 10
+dependencies for use by the charm.
 11
+
 12
+# Usage
 13
+
 14
+To create a charm layer using this base layer, you need only include it in
 15
+a `layer.yaml` file:
 16
+
 17
+```yaml
 18
+includes: ['layer:basic']
 19
+```
 20
+
 21
+This will fetch this layer from [interfaces.juju.solutions][] and incorporate
 22
+it into your charm layer.  You can then add handlers under the `reactive/`
 23
+directory.  Note that **any** file under `reactive/` will be expected to
 24
+contain handlers, whether as Python decorated functions or [executables][non-python]
 25
+using the [external handler protocol][].
 26
+
 27
+### Charm Dependencies
 28
+
 29
+Each layer can include a `wheelhouse.txt` file with Python requirement lines.
 30
+For example, this layer's `wheelhouse.txt` includes:
 31
+
 32
+```
 33
+pip>=7.0.0,<8.0.0
 34
+charmhelpers>=0.4.0,<1.0.0
 35
+charms.reactive>=0.1.0,<2.0.0
 36
+```
 37
+
 38
+All of these dependencies from each layer will be fetched (and updated) at build
 39
+time and will be automatically installed by this base layer before any reactive
 40
+handlers are run.
 41
+
 42
+Note that the `wheelhouse.txt` file is intended for **charm** dependencies only.
 43
+That is, for libraries that the charm code itself needs to do its job of deploying
 44
+and configuring the payload.  If the payload itself has Python dependencies, those
 45
+should be handled separately, by the charm.
 46
+
 47
+See [PyPI][pypi charms.X] for packages under the `charms.` namespace which might
 48
+be useful for your charm.
 49
+
 50
+### Layer Namespace
 51
+
 52
+Each layer has a reserved section in the `charms.layer.` Python package namespace,
 53
+which it can populate by including a `lib/charms/layer/<layer-name>.py` file or
 54
+by placing files under `lib/charms/layer/<layer-name>/`.  (If the layer name
 55
+includes hyphens, replace them with underscores.)  These can be helpers that the
 56
+layer uses internally, or it can expose classes or functions to be used by other
 57
+layers to interact with that layer.
 58
+
 59
+For example, a layer named `foo` could include a `lib/charms/layer/foo.py` file
 60
+with some helper functions that other layers could access using:
 61
+
 62
+```python
 63
+from charms.layer.foo import my_helper
 64
+```
 65
+
 66
+### Layer Options
 67
+
 68
+Any layer can define options in its `layer.yaml`.  Those options can then be set
 69
+by other layers to change the behavior of your layer.  The options are defined
 70
+using [jsonschema][], which is the same way that [action paramters][] are defined.
 71
+
 72
+For example, the `foo` layer could include the following option definitons:
 73
+
 74
+```yaml
 75
+includes: ['layer:basic']
 76
+defines:  # define some options for this layer (the layer "foo")
 77
+  enable-bar:  # define an "enable-bar" option for this layer
 78
+    description: If true, enable support for "bar".
 79
+    type: boolean
 80
+    default: false
 81
+```
 82
+
 83
+A layer using `foo` could then set it:
 84
+
 85
+```yaml
 86
+includes: ['layer:foo']
 87
+options:
 88
+  foo:  # setting options for the "foo" layer
 89
+    enable-bar: true  # set the "enable-bar" option to true
 90
+```
 91
+
 92
+The `foo` layer can then use the `charms.layer.options` helper to load the values
 93
+for the options that it defined.  For example:
 94
+
 95
+```python
 96
+from charms import layer
 97
+
 98
+@when('state')
 99
+def do_thing():
100
+  layer_opts = layer.options('foo')  # load all of the options for the "foo" layer
101
+  if layer_opts['enable-bar']:  # check the value of the "enable-bar" option
102
+      hookenv.log("Bar is enabled")
103
+```
104
+
105
+You can also access layer options in other handlers, such as Bash, using
106
+the command-line interface:
107
+
108
+```bash
109
+. charms.reactive.sh
110
+
111
+@when 'state'
112
+function do_thing() {
113
+    if layer_option foo enable-bar; then
114
+        juju-log "Bar is enabled"
115
+        juju-log "bar-value is: $(layer_option foo bar-value)"
116
+    fi
117
+}
118
+
119
+reactive_handler_main
120
+```
121
+
122
+Note that options of type `boolean` will set the exit code, while other types
123
+will be printed out.
124
+
125
+# Hooks
126
+
127
+This layer provides hooks that other layers can react to using the decorators
128
+of the [charms.reactive][] library:
129
+
130
+  * `config-changed`
131
+  * `install`
132
+  * `leader-elected`
133
+  * `leader-settings-changed`
134
+  * `start`
135
+  * `stop`
136
+  * `upgrade-charm`
137
+  * `update-status`
138
+
139
+Other hooks are not implemented at this time. A new layer can implement storage
140
+or relation hooks in their own layer by putting them in the `hooks` directory.
141
+
142
+**Note:** Because `update-status` is invoked every 5 minutes, you should take
143
+care to ensure that your reactive handlers only invoke expensive operations
144
+when absolutely necessary.  It is recommended that you use helpers like
145
+[`@only_once`][], [`@when_file_changed`][], and [`data_changed`][] to ensure
146
+that handlers run only when necessary.
147
+
148
+# Layer Configuration
149
+
150
+This layer supports the following options, which can be set in `layer.yaml`:
151
+
152
+  * **packages**  A list of system packages to be installed before the reactive
153
+    handlers are invoked.
154
+
155
+  * **use_venv**  If set to true, the charm dependencies from the various
156
+    layers' `wheelhouse.txt` files will be installed in a Python virtualenv
157
+    located at `$CHARM_DIR/../.venv`.  This keeps charm dependencies from
158
+    conflicting with payload dependencies, but you must take care to preserve
159
+    the environment and interpreter if using `execl` or `subprocess`.
160
+
161
+  * **include_system_packages**  If set to true and using a venv, include
162
+    the `--system-site-packages` options to make system Python libraries
163
+    visible within the venv.
164
+
165
+An example `layer.yaml` using these options might be:
166
+
167
+```yaml
168
+includes: ['layer:basic']
169
+options:
170
+  basic:
171
+    packages: ['git']
172
+    use_venv: true
173
+    include_system_packages: true
174
+```
175
+
176
+
177
+# Reactive States
178
+
179
+This layer will set the following states:
180
+
181
+  * **`config.changed`**  Any config option has changed from its previous value.
182
+    This state is cleared automatically at the end of each hook invocation.
183
+
184
+  * **`config.changed.<option>`** A specific config option has changed.
185
+    **`<option>`** will be replaced by the config option name from `config.yaml`.
186
+    This state is cleared automatically at the end of each hook invocation.
187
+
188
+  * **`config.set.<option>`** A specific config option has a True or non-empty
189
+    value set.  **`<option>`** will be replaced by the config option name from
190
+    `config.yaml`.  This state is cleared automatically at the end of each hook
191
+    invocation.
192
+
193
+  * **`config.default.<option>`** A specific config option is set to its
194
+    default value.  **`<option>`** will be replaced by the config option name
195
+    from `config.yaml`.  This state is cleared automatically at the end of
196
+    each hook invocation.
197
+
198
+An example using the config states would be:
199
+
200
+```python
201
+@when('config.changed.my-opt')
202
+def my_opt_changed():
203
+    update_config()
204
+    restart_service()
205
+```
206
+
207
+
208
+# Actions
209
+
210
+This layer currently does not define any actions.
211
+
212
+
213
+[building]: https://jujucharms.com/docs/devel/authors-charm-building
214
+[charm-helpers]: https://pythonhosted.org/charmhelpers/
215
+[charms.reactive]: https://pythonhosted.org/charms.reactive/
216
+[interfaces.juju.solutions]: http://interfaces.juju.solutions/
217
+[non-python]: https://pythonhosted.org/charms.reactive/#non-python-reactive-handlers
218
+[external handler protocol]: https://pythonhosted.org/charms.reactive/charms.reactive.bus.html#charms.reactive.bus.ExternalHandler
219
+[jsonschema]: http://json-schema.org/
220
+[action paramters]: https://jujucharms.com/docs/stable/authors-charm-actions
221
+[pypi charms.X]: https://pypi.python.org/pypi?%3Aaction=search&term=charms.&submit=search
222
+[`@only_once`]: https://pythonhosted.org/charms.reactive/charms.reactive.decorators.html#charms.reactive.decorators.only_once
223
+[`@when_file_changed`]: https://pythonhosted.org/charms.reactive/charms.reactive.decorators.html#charms.reactive.decorators.when_file_changed
224
+[`data_changed`]: https://pythonhosted.org/charms.reactive/charms.reactive.helpers.html#charms.reactive.helpers.data_changed
Back to file index

deps/layer/layer-basic/bin/layer_option

 1
--- 
 2
+++ deps/layer/layer-basic/bin/layer_option
 3
@@ -0,0 +1,24 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+import sys
 7
+sys.path.append('lib')
 8
+
 9
+import argparse
10
+from charms.layer import options
11
+
12
+
13
+parser = argparse.ArgumentParser(description='Access layer options.')
14
+parser.add_argument('section',
15
+                    help='the section, or layer, the option is from')
16
+parser.add_argument('option',
17
+                    help='the option to access')
18
+
19
+args = parser.parse_args()
20
+value = options(args.section).get(args.option, '')
21
+if isinstance(value, bool):
22
+    sys.exit(0 if value else 1)
23
+elif isinstance(value, list):
24
+    for val in value:
25
+        print(val)
26
+else:
27
+    print(value)
Back to file index

deps/layer/layer-basic/copyright

 1
--- 
 2
+++ deps/layer/layer-basic/copyright
 3
@@ -0,0 +1,9 @@
 4
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
 5
+
 6
+Files: *
 7
+Copyright: 2015, Canonical Ltd.
 8
+License: GPL-3
 9
+
10
+License: GPL-3
11
+ On Debian GNU/Linux system you can find the complete text of the
12
+ GPL-3 license in '/usr/share/common-licenses/GPL-3'
Back to file index

deps/layer/layer-basic/hooks/config-changed

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/config-changed
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/hook.template

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/hook.template
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/install

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/install
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/leader-elected

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/leader-elected
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/leader-settings-changed

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/leader-settings-changed
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/start

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/start
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/stop

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/stop
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/update-status

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/update-status
 3
@@ -0,0 +1,19 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer import basic
11
+basic.bootstrap_charm_deps()
12
+basic.init_config_states()
13
+
14
+
15
+# This will load and run the appropriate @hook and other decorated
16
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
17
+# and $CHARM_DIR/hooks/relations.
18
+#
19
+# See https://jujucharms.com/docs/stable/authors-charm-building
20
+# for more information on this pattern.
21
+from charms.reactive import main
22
+main()
Back to file index

deps/layer/layer-basic/hooks/upgrade-charm

 1
--- 
 2
+++ deps/layer/layer-basic/hooks/upgrade-charm
 3
@@ -0,0 +1,28 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import os
 8
+import sys
 9
+sys.path.append('lib')
10
+
11
+# This is an upgrade-charm context, make sure we install latest deps
12
+if not os.path.exists('wheelhouse/.upgrade'):
13
+    open('wheelhouse/.upgrade', 'w').close()
14
+    if os.path.exists('wheelhouse/.bootstrapped'):
15
+        os.unlink('wheelhouse/.bootstrapped')
16
+else:
17
+    os.unlink('wheelhouse/.upgrade')
18
+
19
+from charms.layer import basic
20
+basic.bootstrap_charm_deps()
21
+basic.init_config_states()
22
+
23
+
24
+# This will load and run the appropriate @hook and other decorated
25
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
26
+# and $CHARM_DIR/hooks/relations.
27
+#
28
+# See https://jujucharms.com/docs/stable/authors-charm-building
29
+# for more information on this pattern.
30
+from charms.reactive import main
31
+main()
Back to file index

deps/layer/layer-basic/layer.yaml

 1
--- 
 2
+++ deps/layer/layer-basic/layer.yaml
 3
@@ -0,0 +1,18 @@
 4
+defines:
 5
+  packages:
 6
+    type: array
 7
+    default: []
 8
+    description: Additional packages to be installed at time of bootstrap
 9
+  use_venv:
10
+    type: boolean
11
+    default: false
12
+    description: >
13
+      Install charm dependencies (wheelhouse) into a Python virtual environment
14
+      to help avoid conflicts with other charms or libraries on the machine.
15
+  include_system_packages:
16
+    type: boolean
17
+    default: false
18
+    description: >
19
+      If using a virtual environment, allow the venv to see Python packages
20
+      installed at the system level.  This reduces isolation, but is necessary
21
+      to use Python packages installed via apt-get.
Back to file index

deps/layer/layer-basic/lib/charms/layer/__init__.py

 1
--- 
 2
+++ deps/layer/layer-basic/lib/charms/layer/__init__.py
 3
@@ -0,0 +1,21 @@
 4
+import os
 5
+
 6
+
 7
+class LayerOptions(dict):
 8
+    def __init__(self, layer_file, section=None):
 9
+        import yaml  # defer, might not be available until bootstrap
10
+        with open(layer_file) as f:
11
+            layer = yaml.safe_load(f.read())
12
+        opts = layer.get('options', {})
13
+        if section and section in opts:
14
+            super(LayerOptions, self).__init__(opts.get(section))
15
+        else:
16
+            super(LayerOptions, self).__init__(opts)
17
+
18
+
19
+def options(section=None, layer_file=None):
20
+    if not layer_file:
21
+        base_dir = os.environ.get('CHARM_DIR', os.getcwd())
22
+        layer_file = os.path.join(base_dir, 'layer.yaml')
23
+
24
+    return LayerOptions(layer_file, section)
Back to file index

deps/layer/layer-basic/lib/charms/layer/basic.py

  1
--- 
  2
+++ deps/layer/layer-basic/lib/charms/layer/basic.py
  3
@@ -0,0 +1,159 @@
  4
+import os
  5
+import sys
  6
+import shutil
  7
+import platform
  8
+from glob import glob
  9
+from subprocess import check_call
 10
+
 11
+from charms.layer.execd import execd_preinstall
 12
+
 13
+
 14
+def bootstrap_charm_deps():
 15
+    """
 16
+    Set up the base charm dependencies so that the reactive system can run.
 17
+    """
 18
+    # execd must happen first, before any attempt to install packages or
 19
+    # access the network, because sites use this hook to do bespoke
 20
+    # configuration and install secrets so the rest of this bootstrap
 21
+    # and the charm itself can actually succeed. This call does nothing
 22
+    # unless the operator has created and populated $CHARM_DIR/exec.d.
 23
+    execd_preinstall()
 24
+    # ensure that $CHARM_DIR/bin is on the path, for helper scripts
 25
+    os.environ['PATH'] += ':%s' % os.path.join(os.environ['CHARM_DIR'], 'bin')
 26
+    venv = os.path.abspath('../.venv')
 27
+    vbin = os.path.join(venv, 'bin')
 28
+    vpip = os.path.join(vbin, 'pip')
 29
+    vpy = os.path.join(vbin, 'python')
 30
+    if os.path.exists('wheelhouse/.bootstrapped'):
 31
+        from charms import layer
 32
+        cfg = layer.options('basic')
 33
+        if cfg.get('use_venv') and '.venv' not in sys.executable:
 34
+            # activate the venv
 35
+            os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']])
 36
+            reload_interpreter(vpy)
 37
+        return
 38
+    # bootstrap wheelhouse
 39
+    if os.path.exists('wheelhouse'):
 40
+        with open('/root/.pydistutils.cfg', 'w') as fp:
 41
+            # make sure that easy_install also only uses the wheelhouse
 42
+            # (see https://github.com/pypa/pip/issues/410)
 43
+            charm_dir = os.environ['CHARM_DIR']
 44
+            fp.writelines([
 45
+                "[easy_install]\n",
 46
+                "allow_hosts = ''\n",
 47
+                "find_links = file://{}/wheelhouse/\n".format(charm_dir),
 48
+            ])
 49
+        apt_install(['python3-pip', 'python3-setuptools', 'python3-yaml'])
 50
+        from charms import layer
 51
+        cfg = layer.options('basic')
 52
+        # include packages defined in layer.yaml
 53
+        apt_install(cfg.get('packages', []))
 54
+        # if we're using a venv, set it up
 55
+        if cfg.get('use_venv'):
 56
+            if not os.path.exists(venv):
 57
+                distname, version, series = platform.linux_distribution()
 58
+                if series in ('precise', 'trusty'):
 59
+                    apt_install(['python-virtualenv'])
 60
+                else:
 61
+                    apt_install(['virtualenv'])
 62
+                cmd = ['virtualenv', '-ppython3', '--never-download', venv]
 63
+                if cfg.get('include_system_packages'):
 64
+                    cmd.append('--system-site-packages')
 65
+                check_call(cmd)
 66
+            os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']])
 67
+            pip = vpip
 68
+        else:
 69
+            pip = 'pip3'
 70
+            # save a copy of system pip to prevent `pip3 install -U pip`
 71
+            # from changing it
 72
+            if os.path.exists('/usr/bin/pip'):
 73
+                shutil.copy2('/usr/bin/pip', '/usr/bin/pip.save')
 74
+        # need newer pip, to fix spurious Double Requirement error:
 75
+        # https://github.com/pypa/pip/issues/56
 76
+        check_call([pip, 'install', '-U', '--no-index', '-f', 'wheelhouse',
 77
+                    'pip'])
 78
+        # install the rest of the wheelhouse deps
 79
+        check_call([pip, 'install', '-U', '--no-index', '-f', 'wheelhouse'] +
 80
+                   glob('wheelhouse/*'))
 81
+        if not cfg.get('use_venv'):
 82
+            # restore system pip to prevent `pip3 install -U pip`
 83
+            # from changing it
 84
+            if os.path.exists('/usr/bin/pip.save'):
 85
+                shutil.copy2('/usr/bin/pip.save', '/usr/bin/pip')
 86
+                os.remove('/usr/bin/pip.save')
 87
+        os.remove('/root/.pydistutils.cfg')
 88
+        # flag us as having already bootstrapped so we don't do it again
 89
+        open('wheelhouse/.bootstrapped', 'w').close()
 90
+        # Ensure that the newly bootstrapped libs are available.
 91
+        # Note: this only seems to be an issue with namespace packages.
 92
+        # Non-namespace-package libs (e.g., charmhelpers) are available
 93
+        # without having to reload the interpreter. :/
 94
+        reload_interpreter(vpy if cfg.get('use_venv') else sys.argv[0])
 95
+
 96
+
 97
+def reload_interpreter(python):
 98
+    """
 99
+    Reload the python interpreter to ensure that all deps are available.
100
+
101
+    Newly installed modules in namespace packages sometimes seemt to
102
+    not be picked up by Python 3.
103
+    """
104
+    os.execle(python, python, sys.argv[0], os.environ)
105
+
106
+
107
+def apt_install(packages):
108
+    """
109
+    Install apt packages.
110
+
111
+    This ensures a consistent set of options that are often missed but
112
+    should really be set.
113
+    """
114
+    if isinstance(packages, (str, bytes)):
115
+        packages = [packages]
116
+
117
+    env = os.environ.copy()
118
+
119
+    if 'DEBIAN_FRONTEND' not in env:
120
+        env['DEBIAN_FRONTEND'] = 'noninteractive'
121
+
122
+    cmd = ['apt-get',
123
+           '--option=Dpkg::Options::=--force-confold',
124
+           '--assume-yes',
125
+           'install']
126
+    check_call(cmd + packages, env=env)
127
+
128
+
129
+def init_config_states():
130
+    import yaml
131
+    from charmhelpers.core import hookenv
132
+    from charms.reactive import set_state
133
+    from charms.reactive import toggle_state
134
+    config = hookenv.config()
135
+    config_defaults = {}
136
+    config_defs = {}
137
+    config_yaml = os.path.join(hookenv.charm_dir(), 'config.yaml')
138
+    if os.path.exists(config_yaml):
139
+        with open(config_yaml) as fp:
140
+            config_defs = yaml.load(fp).get('options', {})
141
+            config_defaults = {key: value.get('default')
142
+                               for key, value in config_defs.items()}
143
+    for opt in config_defs.keys():
144
+        if config.changed(opt):
145
+            set_state('config.changed')
146
+            set_state('config.changed.{}'.format(opt))
147
+        toggle_state('config.set.{}'.format(opt), config.get(opt))
148
+        toggle_state('config.default.{}'.format(opt),
149
+                     config.get(opt) == config_defaults[opt])
150
+    hookenv.atexit(clear_config_states)
151
+
152
+
153
+def clear_config_states():
154
+    from charmhelpers.core import hookenv, unitdata
155
+    from charms.reactive import remove_state
156
+    config = hookenv.config()
157
+    remove_state('config.changed')
158
+    for opt in config.keys():
159
+        remove_state('config.changed.{}'.format(opt))
160
+        remove_state('config.set.{}'.format(opt))
161
+        remove_state('config.default.{}'.format(opt))
162
+    unitdata.kv().flush()
Back to file index

deps/layer/layer-basic/lib/charms/layer/execd.py

  1
--- 
  2
+++ deps/layer/layer-basic/lib/charms/layer/execd.py
  3
@@ -0,0 +1,138 @@
  4
+# Copyright 2014-2016 Canonical Limited.
  5
+#
  6
+# This file is part of layer-basic, the reactive base layer for Juju.
  7
+#
  8
+# charm-helpers is free software: you can redistribute it and/or modify
  9
+# it under the terms of the GNU Lesser General Public License version 3 as
 10
+# published by the Free Software Foundation.
 11
+#
 12
+# charm-helpers is distributed in the hope that it will be useful,
 13
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 14
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15
+# GNU Lesser General Public License for more details.
 16
+#
 17
+# You should have received a copy of the GNU Lesser General Public License
 18
+# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
 19
+
 20
+# This module may only import from the Python standard library.
 21
+import os
 22
+import sys
 23
+import subprocess
 24
+import time
 25
+
 26
+'''
 27
+execd/preinstall
 28
+
 29
+It is often necessary to configure and reconfigure machines
 30
+after provisioning, but before attempting to run the charm.
 31
+Common examples are specialized network configuration, enabling
 32
+of custom hardware, non-standard disk partitioning and filesystems,
 33
+adding secrets and keys required for using a secured network.
 34
+
 35
+The reactive framework's base layer invokes this mechanism as
 36
+early as possible, before any network access is made or dependencies
 37
+unpacked or non-standard modules imported (including the charms.reactive
 38
+framework itself).
 39
+
 40
+Operators needing to use this functionality may branch a charm and
 41
+create an exec.d directory in it. The exec.d directory in turn contains
 42
+one or more subdirectories, each of which contains an executable called
 43
+charm-pre-install and any other required resources. The charm-pre-install
 44
+executables are run, and if successful, state saved so they will not be
 45
+run again.
 46
+
 47
+    $CHARM_DIR/exec.d/mynamespace/charm-pre-install
 48
+
 49
+An alternative to branching a charm is to compose a new charm that contains
 50
+the exec.d directory, using the original charm as a layer,
 51
+
 52
+A charm author could also abuse this mechanism to modify the charm
 53
+environment in unusual ways, but for most purposes it is saner to use
 54
+charmhelpers.core.hookenv.atstart().
 55
+'''
 56
+
 57
+
 58
+def default_execd_dir():
 59
+    return os.path.join(os.environ['CHARM_DIR'], 'exec.d')
 60
+
 61
+
 62
+def execd_module_paths(execd_dir=None):
 63
+    """Generate a list of full paths to modules within execd_dir."""
 64
+    if not execd_dir:
 65
+        execd_dir = default_execd_dir()
 66
+
 67
+    if not os.path.exists(execd_dir):
 68
+        return
 69
+
 70
+    for subpath in os.listdir(execd_dir):
 71
+        module = os.path.join(execd_dir, subpath)
 72
+        if os.path.isdir(module):
 73
+            yield module
 74
+
 75
+
 76
+def execd_submodule_paths(command, execd_dir=None):
 77
+    """Generate a list of full paths to the specified command within exec_dir.
 78
+    """
 79
+    for module_path in execd_module_paths(execd_dir):
 80
+        path = os.path.join(module_path, command)
 81
+        if os.access(path, os.X_OK) and os.path.isfile(path):
 82
+            yield path
 83
+
 84
+
 85
+def execd_sentinel_path(submodule_path):
 86
+    module_path = os.path.dirname(submodule_path)
 87
+    execd_path = os.path.dirname(module_path)
 88
+    module_name = os.path.basename(module_path)
 89
+    submodule_name = os.path.basename(submodule_path)
 90
+    return os.path.join(execd_path,
 91
+                        '.{}_{}.done'.format(module_name, submodule_name))
 92
+
 93
+
 94
+def execd_run(command, execd_dir=None, stop_on_error=True, stderr=None):
 95
+    """Run command for each module within execd_dir which defines it."""
 96
+    if stderr is None:
 97
+        stderr = sys.stdout
 98
+    for submodule_path in execd_submodule_paths(command, execd_dir):
 99
+        # Only run each execd once. We cannot simply run them in the
100
+        # install hook, as potentially storage hooks are run before that.
101
+        # We cannot rely on them being idempotent.
102
+        sentinel = execd_sentinel_path(submodule_path)
103
+        if os.path.exists(sentinel):
104
+            continue
105
+
106
+        try:
107
+            subprocess.check_call([submodule_path], stderr=stderr,
108
+                                  universal_newlines=True)
109
+            with open(sentinel, 'w') as f:
110
+                f.write('{} ran successfully {}\n'.format(submodule_path,
111
+                                                          time.ctime()))
112
+                f.write('Removing this file will cause it to be run again\n')
113
+        except subprocess.CalledProcessError as e:
114
+            # Logs get the details. We can't use juju-log, as the
115
+            # output may be substantial and exceed command line
116
+            # length limits.
117
+            print("ERROR ({}) running {}".format(e.returncode, e.cmd),
118
+                  file=stderr)
119
+            print("STDOUT<<EOM", file=stderr)
120
+            print(e.output, file=stderr)
121
+            print("EOM", file=stderr)
122
+
123
+            # Unit workload status gets a shorter fail message.
124
+            short_path = os.path.relpath(submodule_path)
125
+            block_msg = "Error ({}) running {}".format(e.returncode,
126
+                                                       short_path)
127
+            try:
128
+                subprocess.check_call(['status-set', 'blocked', block_msg],
129
+                                      universal_newlines=True)
130
+                if stop_on_error:
131
+                    sys.exit(0)  # Leave unit in blocked state.
132
+            except Exception:
133
+                pass  # We care about the exec.d/* failure, not status-set.
134
+
135
+            if stop_on_error:
136
+                sys.exit(e.returncode or 1)  # Error state for pre-1.24 Juju
137
+
138
+
139
+def execd_preinstall(execd_dir=None):
140
+    """Run charm-pre-install for each module within execd_dir."""
141
+    execd_run('charm-pre-install', execd_dir=execd_dir)
Back to file index

deps/layer/layer-basic/metadata.yaml

1
--- 
2
+++ deps/layer/layer-basic/metadata.yaml
3
@@ -0,0 +1 @@
4
+{}
Back to file index

deps/layer/layer-basic/requirements.txt

1
--- 
2
+++ deps/layer/layer-basic/requirements.txt
3
@@ -0,0 +1,2 @@
4
+flake8
5
+pytest
Back to file index

deps/layer/layer-basic/tox.ini

 1
--- 
 2
+++ deps/layer/layer-basic/tox.ini
 3
@@ -0,0 +1,12 @@
 4
+[tox]
 5
+skipsdist=True
 6
+envlist = py34, py35
 7
+skip_missing_interpreters = True
 8
+
 9
+[testenv]
10
+commands = py.test -v
11
+deps =
12
+    -r{toxinidir}/requirements.txt
13
+
14
+[flake8]
15
+exclude=docs
Back to file index

deps/layer/layer-basic/wheelhouse.txt

1
--- 
2
+++ deps/layer/layer-basic/wheelhouse.txt
3
@@ -0,0 +1,3 @@
4
+pip>=7.0.0,<8.2.0
5
+charmhelpers>=0.4.0,<1.0.0
6
+charms.reactive>=0.1.0,<2.0.0
Back to file index

deps/layer/layer-leadership/.gitignore

1
--- 
2
+++ deps/layer/layer-leadership/.gitignore
3
@@ -0,0 +1,2 @@
4
+*~
5
+*.pyc
Back to file index

deps/layer/layer-leadership/README.md

 1
--- 
 2
+++ deps/layer/layer-leadership/README.md
 3
@@ -0,0 +1,88 @@
 4
+# Leadership Layer for Juju Charms
 5
+
 6
+The Leadership layer is for charm-tools and 'charm build', making it
 7
+easier for layered charms to deal with Juju leadership.
 8
+
 9
+This layer will initialize charms.reactive states, allowing you to
10
+write handlers that will be activated by these states. It allows you
11
+to completely avoid writing leader-elected and leader-settings-changed
12
+hooks. As a simple example, these two handlers are all that is required
13
+to make the leader unit generate a password if it is not already set,
14
+and have the shared password stored in a file on all units:
15
+
16
+```python
17
+import charms.leadership
18
+from charmhelpers.core.host import pwgen
19
+
20
+
21
+@when('leadership.is_leader')
22
+@when_not('leadership.set.admin_password')
23
+def generate_secret():
24
+    charms.leadership.leader_set(admin_password=pwgen())
25
+
26
+
27
+@when('leadership.changed.admin_password')
28
+def store_secret():
29
+    write_file('/etc/foopass', leader_get('admin_password'))
30
+```
31
+
32
+
33
+## States
34
+
35
+The following states are set appropriately on startup, before any @hook
36
+decorated methods are invoked:
37
+
38
+* `leadership.is_leader`
39
+
40
+  This state is set when the unit is the leader. The unit will remain
41
+  the leader for the remainder of the hook, but may not be leader in
42
+  future hooks.
43
+
44
+* `leadership.set.{varname}`
45
+
46
+  This state is set for each leadership setting (ie. the
47
+  `leadership.set.foo` state will be set if the leader has set
48
+  the foo leadership setting to any value). It will remain
49
+  set for the remainder of the hook, unless the unit is the leader
50
+  and calls `reactive.leadership.leader_set()` and resets the value
51
+  to None.
52
+
53
+* `leadership.changed.{varname}`
54
+
55
+  This state is set for each leadership setting that has changed
56
+  since the last hook. It will remain set for the remainder of the
57
+  hook. It will not be set in the next hook, unless the leader has
58
+  changed the leadership setting yet again.
59
+
60
+* `leadership.changed`
61
+
62
+  One or more leadership settings has changed since the last hook.
63
+  This state will remain set for the remainder of the hook. It will
64
+  not be set in the next hook, unless the leader has made further
65
+  changes.
66
+
67
+
68
+## Methods
69
+
70
+The `charms.leadership` module exposes the `leader_set()` and
71
+`leader_get()` methods, which match the methods found in the
72
+`charmhelpers.core.hookenv` module. `reactive.leadership.leader_set()`
73
+should be used instead of the charmhelpers function to ensure that
74
+the reactive state is updated when the leadership settings are. If you
75
+do not do this, then you risk handlers waiting on these states to not
76
+be run on the leader (because when the leader changes settings, it 
77
+triggers leader-settings-changed hooks on the follower units but
78
+no hooks on itself).
79
+
80
+
81
+## Support
82
+
83
+This layer is maintained on Launchpad by
84
+Stuart Bishop (stuart.bishop@canonical.com).
85
+
86
+Code is available using git at git+ssh://git.launchpad.net/layer-leadership.
87
+
88
+Bug reports can be made at https://bugs.launchpad.net/layer-leadership.
89
+
90
+Queries and comments can be made on the Juju mailing list, Juju IRC
91
+channels, or at https://answers.launchpad.net/layer-leadership.
Back to file index

deps/layer/layer-leadership/copyright

 1
--- 
 2
+++ deps/layer/layer-leadership/copyright
 3
@@ -0,0 +1,15 @@
 4
+Copyright 2015-2016 Canonical Ltd.
 5
+
 6
+This file is part of the Leadership Layer for Juju.
 7
+
 8
+This program is free software: you can redistribute it and/or modify
 9
+it under the terms of the GNU General Public License version 3, as
10
+published by the Free Software Foundation.
11
+
12
+This program is distributed in the hope that it will be useful, but
13
+WITHOUT ANY WARRANTY; without even the implied warranties of
14
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+PURPOSE.  See the GNU General Public License for more details.
16
+
17
+You should have received a copy of the GNU General Public License
18
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
Back to file index

deps/layer/layer-leadership/hooks/leader-elected

 1
--- 
 2
+++ deps/layer/layer-leadership/hooks/leader-elected
 3
@@ -0,0 +1,18 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer.basic import bootstrap_charm_deps
11
+bootstrap_charm_deps()
12
+
13
+
14
+# This will load and run the appropriate @hook and other decorated
15
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
16
+# and $CHARM_DIR/hooks/relations.
17
+#
18
+# See https://jujucharms.com/docs/stable/authors-charm-building
19
+# for more information on this pattern.
20
+from charms.reactive import main
21
+main()
Back to file index

deps/layer/layer-leadership/hooks/leader-settings-changed

 1
--- 
 2
+++ deps/layer/layer-leadership/hooks/leader-settings-changed
 3
@@ -0,0 +1,18 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+# Load modules from $CHARM_DIR/lib
 7
+import sys
 8
+sys.path.append('lib')
 9
+
10
+from charms.layer.basic import bootstrap_charm_deps
11
+bootstrap_charm_deps()
12
+
13
+
14
+# This will load and run the appropriate @hook and other decorated
15
+# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
16
+# and $CHARM_DIR/hooks/relations.
17
+#
18
+# See https://jujucharms.com/docs/stable/authors-charm-building
19
+# for more information on this pattern.
20
+from charms.reactive import main
21
+main()
Back to file index

deps/layer/layer-leadership/layer.yaml

 1
--- 
 2
+++ deps/layer/layer-leadership/layer.yaml
 3
@@ -0,0 +1,17 @@
 4
+# Copyright 2015-2016 Canonical Ltd.
 5
+#
 6
+# This file is part of the Leadership Layer for Juju.
 7
+#
 8
+# This program is free software: you can redistribute it and/or modify
 9
+# it under the terms of the GNU General Public License version 3, as
10
+# published by the Free Software Foundation.
11
+#
12
+# This program is distributed in the hope that it will be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+# PURPOSE.  See the GNU General Public License for more details.
16
+#
17
+# You should have received a copy of the GNU General Public License
18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+includes:
20
+    - layer:basic
Back to file index

deps/layer/layer-leadership/lib/charms/__init__.py

1
--- 
2
+++ deps/layer/layer-leadership/lib/charms/__init__.py
3
@@ -0,0 +1,2 @@
4
+from pkgutil import extend_path
5
+__path__ = extend_path(__path__, __name__)
Back to file index

deps/layer/layer-leadership/lib/charms/leadership.py

 1
--- 
 2
+++ deps/layer/layer-leadership/lib/charms/leadership.py
 3
@@ -0,0 +1,58 @@
 4
+# Copyright 2015-2016 Canonical Ltd.
 5
+#
 6
+# This file is part of the Leadership Layer for Juju.
 7
+#
 8
+# This program is free software: you can redistribute it and/or modify
 9
+# it under the terms of the GNU General Public License version 3, as
10
+# published by the Free Software Foundation.
11
+#
12
+# This program is distributed in the hope that it will be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+# PURPOSE.  See the GNU General Public License for more details.
16
+#
17
+# You should have received a copy of the GNU General Public License
18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+
20
+from charmhelpers.core import hookenv
21
+from charmhelpers.core import unitdata
22
+
23
+from charms import reactive
24
+from charms.reactive import not_unless
25
+
26
+
27
+__all__ = ['leader_get', 'leader_set']
28
+
29
+
30
+@not_unless('leadership.is_leader')
31
+def leader_set(settings=None, **kw):
32
+    '''Change leadership settings, per charmhelpers.core.hookenv.leader_set.
33
+
34
+    The leadership.set.{key} reactive state will be set while the
35
+    leadership hook environment setting remains set.
36
+
37
+    Changed leadership settings will set the leadership.changed.{key}
38
+    and leadership.changed states. These states will remain set until
39
+    the following hook.
40
+
41
+    These state changes take effect immediately on the leader, and
42
+    in future hooks run on non-leaders. In this way both leaders and
43
+    non-leaders can share handlers, waiting on these states.
44
+    '''
45
+    settings = settings or {}
46
+    settings.update(kw)
47
+    previous = unitdata.kv().getrange('leadership.settings.', strip=True)
48
+
49
+    for key, value in settings.items():
50
+        if value != previous.get(key):
51
+            reactive.set_state('leadership.changed.{}'.format(key))
52
+            reactive.set_state('leadership.changed')
53
+        reactive.helpers.toggle_state('leadership.set.{}'.format(key),
54
+                                      value is not None)
55
+    hookenv.leader_set(settings)
56
+    unitdata.kv().update(settings, prefix='leadership.settings.')
57
+
58
+
59
+def leader_get(attribute=None):
60
+    '''Return leadership settings, per charmhelpers.core.hookenv.leader_get.'''
61
+    return hookenv.leader_get(attribute)
Back to file index

deps/layer/layer-leadership/reactive/leadership.py

 1
--- 
 2
+++ deps/layer/layer-leadership/reactive/leadership.py
 3
@@ -0,0 +1,68 @@
 4
+# Copyright 2015-2016 Canonical Ltd.
 5
+#
 6
+# This file is part of the Leadership Layer for Juju.
 7
+#
 8
+# This program is free software: you can redistribute it and/or modify
 9
+# it under the terms of the GNU General Public License version 3, as
10
+# published by the Free Software Foundation.
11
+#
12
+# This program is distributed in the hope that it will be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranties of
14
+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
+# PURPOSE.  See the GNU General Public License for more details.
16
+#
17
+# You should have received a copy of the GNU General Public License
18
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+
20
+from charmhelpers.core import hookenv
21
+from charmhelpers.core import unitdata
22
+
23
+from charms import reactive
24
+from charms.leadership import leader_get, leader_set
25
+
26
+
27
+__all__ = ['leader_get', 'leader_set']  # Backwards compatibility
28
+
29
+
30
+def initialize_leadership_state():
31
+    '''Initialize leadership.* states from the hook environment.
32
+
33
+    Invoked by hookenv.atstart() so states are available in
34
+    @hook decorated handlers.
35
+    '''
36
+    is_leader = hookenv.is_leader()
37
+    if is_leader:
38
+        hookenv.log('Initializing Leadership Layer (is leader)')
39
+    else:
40
+        hookenv.log('Initializing Leadership Layer (is follower)')
41
+
42
+    reactive.helpers.toggle_state('leadership.is_leader', is_leader)
43
+
44
+    previous = unitdata.kv().getrange('leadership.settings.', strip=True)
45
+    current = hookenv.leader_get()
46
+
47
+    # Handle deletions.
48
+    for key in set(previous.keys()) - set(current.keys()):
49
+        current[key] = None
50
+
51
+    any_changed = False
52
+    for key, value in current.items():
53
+        reactive.helpers.toggle_state('leadership.changed.{}'.format(key),
54
+                                      value != previous.get(key))
55
+        if value != previous.get(key):
56
+            any_changed = True
57
+        reactive.helpers.toggle_state('leadership.set.{}'.format(key),
58
+                                      value is not None)
59
+    reactive.helpers.toggle_state('leadership.changed', any_changed)
60
+
61
+    unitdata.kv().update(current, prefix='leadership.settings.')
62
+
63
+
64
+# Per https://github.com/juju-solutions/charms.reactive/issues/33,
65
+# this module may be imported multiple times so ensure the
66
+# initialization hook is only registered once. I have to piggy back
67
+# onto the namespace of a module imported before reactive discovery
68
+# to do this.
69
+if not hasattr(reactive, '_leadership_registered'):
70
+    hookenv.atstart(initialize_leadership_state)
71
+    reactive._leadership_registered = True
Back to file index

deps/layer/trunk/README.md

 1
--- 
 2
+++ deps/layer/trunk/README.md
 3
@@ -0,0 +1,57 @@
 4
+# IBM base layer
 5
+
 6
+The IBM base layer is a common starting point for IBM related charms. Use this
 7
+layer if you are building a layered charm with IBM software.
 8
+
 9
+## Usage
10
+
11
+This charm is a base layer and not meant to be built as a charm on its own.
12
+
13
+To use this layer, simply include the following in the runtime charm's
14
+layer.yaml file
15
+
16
+```yaml
17
+includes: ['layer:ibm-base']
18
+```
19
+
20
+## Configuration
21
+
22
+**curl_url** - Location of the IBM product installation file(s). This should be a
23
+URL that curl can use to download files. Multiple URLs should be separated
24
+by a space.
25
+
26
+**NOTE**: cryptographic verification is required and must be
27
+specified as part of the URL query string with the key a valid hash
28
+algorithms md5, sha256, or sha512, and the the checksum value itself
29
+(`http://<url>?[md5|sha256|sha512]=<checksum>`).
30
+
31
+For example:  
32
+
33
+* `http://example.com/file.tgz?sha256=<sum>`
34
+* `"sftp://example.com/file1.tgz?md5=<sum> ftp://example.com/file2.tgz?md5=<sum>"`
35
+
36
+**curl_options** - The options passed to the 'curl' command when fetching files
37
+from curl_url.
38
+
39
+For example:  
40
+
41
+* `"-u <user:password>"`
42
+
43
+**license_accepted** - Some IBM charms require acceptance of a license before
44
+installation can proceed. If required, setting this option to True indicates
45
+that you have read and accepted the IBM terms and conditions found in the
46
+license file referenced by the charm.
47
+
48
+## States
49
+
50
+**ibm-base.curl.resource.fetched** - When this state is set the IBM base layer has
51
+downloaded and verified the resources configured by curl_url. If the charm
52
+does not require any curl resources this state can be ignored.
53
+
54
+**ibm-base.license.accepted** - When this state is set the user has signified
55
+their acceptance of the license found in the charm. If the charm implements
56
+the Juju 'terms' feature this state can be safely ignored.
57
+
58
+## Contacts
59
+
60
+IBM Juju Support Team <jujusupp@us.ibm.com>
Back to file index

deps/layer/trunk/config.yaml

 1
--- 
 2
+++ deps/layer/trunk/config.yaml
 3
@@ -0,0 +1,29 @@
 4
+options:
 5
+  curl_url:
 6
+    type: string
 7
+    default: ''
 8
+    description: |
 9
+      Location of the IBM product installation file(s). This should be a URL
10
+      that curl can use to download files. Multiple URLs should be separated
11
+      by a space. NOTE: cryptographic verification is required and must be
12
+      specified as part of the URL query string with the key a valid hash
13
+      algorithms md5, sha256, or sha512, and the the checksum value itself
14
+      (http://<url>?[md5|sha256|sha512]=<checksum>).
15
+      For example:
16
+        'http://example.com/file.tgz?sha256=<sum>'
17
+        'sftp://example.com/file1.tgz?md5=<sum> ftp://example.com/file2.tgz?md5=<sum>'
18
+  curl_opts:
19
+    type: string
20
+    default: ''
21
+    description: |
22
+      The options passed to the 'curl' command when fetching files from
23
+      curl_url. For example:
24
+        '-u <user:password>'
25
+  license_accepted:
26
+    type: boolean
27
+    default: False
28
+    description: |
29
+      Some IBM charms require acceptance of a license before installation
30
+      can proceed. If required, setting this option to True indicates that you
31
+      have read and accepted the IBM terms and conditions found in the license
32
+      file referenced by the charm.
Back to file index

deps/layer/trunk/layer.yaml

 1
--- 
 2
+++ deps/layer/trunk/layer.yaml
 3
@@ -0,0 +1,9 @@
 4
+includes:
 5
+  - 'layer:basic'
 6
+  - 'layer:apt'
 7
+  - 'layer:leadership'
 8
+options:
 9
+  basic:
10
+    # Setting options for the basic layer.
11
+    packages:
12
+      - curl
Back to file index

deps/layer/trunk/metadata.yaml

 1
--- 
 2
+++ deps/layer/trunk/metadata.yaml
 3
@@ -0,0 +1,15 @@
 4
+name: ibm-base
 5
+summary: This layer provides a common base for IBM charms to build off of.
 6
+maintainer: IBM Juju Support Team <jujusupp@us.ibm.com>
 7
+description: |
 8
+  This layer provides license acceptance using the terms feature, it also
 9
+  provides apt support from the apt layer, and Juju leadership from the
10
+  leadership layer.
11
+min-juju-version: '2.0-beta1'
12
+series:
13
+  - trusty
14
+  - xenial
15
+tags:
16
+  - ibm
17
+  - apt
18
+  - leadership
Back to file index

deps/layer/trunk/reactive/ibm-base.sh

  1
--- 
  2
+++ deps/layer/trunk/reactive/ibm-base.sh
  3
@@ -0,0 +1,107 @@
  4
+#!/bin/bash
  5
+source charms.reactive.sh
  6
+set -e
  7
+
  8
+
  9
+# Utility function to verify a downloaded resource
 10
+# :param: file name
 11
+# :param: checksum type
 12
+# :param: checksum value
 13
+function verify_curl_resource() {
 14
+  local FILE=$1
 15
+  local TYPE=$2
 16
+  local EXPECTED_SUM=$3
 17
+  local CALCULATED_SUM=""
 18
+  local PROG=""
 19
+
 20
+  if [ ! -r ${FILE} ]; then
 21
+    status-set blocked "ibm-base: could not read ${FILE}"
 22
+    juju-log "Could not verify the downloaded resource. File could not be read: ${FILE}"
 23
+  fi
 24
+
 25
+  # Set our checksum utility based on the requested type
 26
+  case "${TYPE}" in
 27
+    md5)
 28
+      PROG='md5sum'
 29
+      ;;
 30
+    sha256)
 31
+      PROG='sha256sum'
 32
+      ;;
 33
+    sha512)
 34
+      PROG='sha512sum'
 35
+      ;;
 36
+    *)
 37
+      status-set blocked "ibm-base: checksum type must be md5, sha215, or sha512"
 38
+      juju-log "Could not verify the downloaded resource ${FILE}. Unknown checksum type: ${TYPE}"
 39
+      return 1
 40
+  esac
 41
+
 42
+  CALCULATED_SUM=`${PROG} ${FILE} | awk '{print $1}'`
 43
+  if [ "${CALCULATED_SUM}" = "${EXPECTED_SUM}" ]; then
 44
+    juju-log "Checksum verified for ${FILE}."
 45
+    return 0
 46
+  else
 47
+    status-set blocked "ibm-base: checksums did not match"
 48
+    juju-log "Checksum mismatch for ${FILE}. Expected ${EXPECTED_SUM}, got ${CALCULATED_SUM}"
 49
+    return 1
 50
+  fi
 51
+}
 52
+
 53
+
 54
+# Fetch curl resources if a URL is configured
 55
+@when 'config.set.curl_url'
 56
+@when_any 'config.new.curl_url' 'config.changed.curl_url' 'config.new.curl_opts' 'config.changed.curl_opts'
 57
+function fetch_curl_resource() {
 58
+  local ARCHIVE_DIR="${CHARM_DIR}/files/archives"
 59
+  local CURL_URL=$(config-get 'curl_url')
 60
+  local CURL_OPTS=$(config-get 'curl_opts')
 61
+
 62
+  status-set maintenance "ibm-base: fetching resource(s)"
 63
+
 64
+  mkdir -p ${ARCHIVE_DIR}
 65
+  cd ${ARCHIVE_DIR}
 66
+  # Multiple URLs may be separated by a space, so loop.
 67
+  for URL_STRING in ${CURL_URL}
 68
+  do
 69
+    # For each URL_STRING, set the url, checksum type, and checksum value.
 70
+    local URL=${URL_STRING%%\?*}        # string before the first '?'
 71
+    local FILE_NAME=${URL##*\/}         # string after the last '/'
 72
+    local SUM_STRING=${URL_STRING#*\?}  # string after the first '?'
 73
+    local SUM_TYPE=${SUM_STRING%%\=*}   # string before the first '='
 74
+    local SUM_VALUE=${SUM_STRING#*\=}   # string after the first '='
 75
+
 76
+    if [ -z ${FILE_NAME} ]; then
 77
+      FILE_NAME="juju-${RANDOM}"
 78
+    fi
 79
+    curl --silent --show-error ${CURL_OPTS} -o ${FILE_NAME} ${URL}
 80
+
 81
+    # Verify our resource checksum. If this fails, let verify_resource log
 82
+    # the reason and exit successfully. Exiting non-zero would fail the hook,
 83
+    # so return 0 and simply inform the user that verification failed.
 84
+    verify_curl_resource ${FILE_NAME} ${SUM_TYPE} ${SUM_VALUE} || return 0
 85
+  done
 86
+  cd -
 87
+
 88
+  set_state 'ibm-base.curl.resource.fetched'
 89
+  status-set active "ibm-base: curl resource(s) fetched"
 90
+  juju-log 'Curl resource fetched'
 91
+}
 92
+
 93
+
 94
+# Handle license acceptance
 95
+@when 'config.changed.license_accepted'
 96
+function check_license_acceptance() {
 97
+  local LIC_ACCEPTED=$(config-get 'license_accepted')
 98
+
 99
+  # compare lowercase LIC_ACCEPTED (requires bash > 4)
100
+  if [ "${LIC_ACCEPTED,,}" = "true" ]; then
101
+    set_state 'ibm-base.license.accepted'
102
+    juju-log 'License accepted'
103
+  else
104
+    remove_state 'ibm-base.license.accepted'
105
+    juju-log 'License NOT accepted'
106
+  fi
107
+}
108
+
109
+# Main reactive entry point
110
+reactive_handler_main
Back to file index

files/archives/db2server_z.rsp

 1
--- 
 2
+++ files/archives/db2server_z.rsp
 3
@@ -0,0 +1,64 @@
 4
+*--------------------------------------------------------
 5
+* The response file is generated by the db2rspgn command 
 6
+*--------------------------------------------------------
 7
+*--------------------------
 8
+* Product Installation
 9
+*--------------------------
10
+PROD = DB2_SERVER_EDITION
11
+FILE = /opt/ibm/db2/V10.5
12
+LIC_AGREEMENT = ACCEPT
13
+INSTALL_TYPE = CUSTOM
14
+COMP = BASE_CLIENT
15
+COMP = JAVA_SUPPORT
16
+COMP = SQL_PROCEDURES
17
+COMP = BASE_DB2_ENGINE
18
+COMP = CONNECT_SUPPORT
19
+COMP = DB2_DATA_SOURCE_SUPPORT
20
+COMP = SPATIAL_EXTENDER_SERVER_SUPPORT
21
+COMP = JDK
22
+COMP = LDAP_EXPLOITATION
23
+COMP = INSTANCE_SETUP_SUPPORT
24
+*COMP = ACS
25
+COMP = SPATIAL_EXTENDER_CLIENT_SUPPORT
26
+COMP = COMMUNICATION_SUPPORT_TCPIP
27
+COMP = APPLICATION_DEVELOPMENT_TOOLS
28
+COMP = DB2_UPDATE_SERVICE
29
+COMP = REPL_CLIENT
30
+COMP = DB2_SAMPLE_DATABASE
31
+*COMP = TEXT_SEARCH
32
+COMP = INFORMIX_DATA_SOURCE_SUPPORT
33
+COMP = ORACLE_DATA_SOURCE_SUPPORT
34
+COMP = FIRST_STEPS
35
+COMP = GUARDIUM_INST_MNGR_CLIENT
36
+*--------------------------
37
+* Installed Languages
38
+*--------------------------
39
+LANG = EN
40
+*--------------------------
41
+* Instance Properties
42
+*--------------------------
43
+INSTANCE = db2inst1
44
+db2inst1.NAME = db2inst1
45
+db2inst1.UID = db2inst1_uid
46
+db2inst1.GROUP_NAME = db2grp1
47
+db2inst1.GID = db2inst1_gid
48
+db2inst1.HOME_DIRECTORY = /home/db2inst1_homedir
49
+db2inst1.PASSWORD = db2inst1_password
50
+db2inst1.CLIENT_IMPORT_PROFILE = db2inst1.INS
51
+db2inst1.TYPE = ese
52
+db2inst1.FENCED_USERNAME = db2fenc1
53
+db2inst1.FENCED_UID = db2fenc1_uid
54
+db2inst1.FENCED_GROUP_NAME = db2fgrp1
55
+db2inst1.FENCED_GID = db2fenc1_gid
56
+db2inst1.FENCED_HOME_DIRECTORY = /home/db2fenc1
57
+db2inst1.FENCED_PASSWORD = db2fenc1
58
+db2inst1.CONFIGURE_TEXT_SEARCH = NO
59
+*--------------------------
60
+* DAS Properties
61
+*__________________________
62
+DAS_USERNAME = dasusr1
63
+DAS_UID = das_uid
64
+DAS_GROUP_NAME = dasadm1
65
+DAS_GID = das_gid
66
+DAS_HOME_DIRECTORY = /home/dasusr1
67
+DAS_PASSWORD = dasusr1
Back to file index

hooks/relations/db2/provides.py

 1
--- hooks/relations/db2/provides.py
 2
+++ hooks/relations/db2/provides.py
 3
@@ -54,14 +54,6 @@
 4
             'dbs_created': dbs_created,
 5
         })
 6
 
 7
-    def set_db_password(self, service, dbuserpw):
 8
-        conversation = self.conversation(service)
 9
-        conversation.set_local('dbuserpw', dbuserpw)
10
-
11
-    def get_db_password(self, service):
12
-        conversation = self.conversation(service)
13
-        return conversation.get_local('dbuserpw')
14
-
15
     def set_sshconfigured(self, service):
16
         conversation = self.conversation(service)
17
         conversation.set_state('{relation_name}.sshconfigured')
Back to file index

layer.yaml

 1
--- layer.yaml
 2
+++ layer.yaml
 3
@@ -1,14 +1,7 @@
 4
-"includes":
 5
-- "layer:basic"
 6
-- "layer:apt"
 7
-- "layer:leadership"
 8
-- "layer:basic"
 9
-- "layer:ibm-base"
10
-- "interface:db2"
11
 "options":
12
   "basic":
13
-    # Setting options for the basic layer.
14
     "packages":
15
+    - "curl"
16
     - "curl"
17
     - "binutils"
18
     - "pwgen"
19
@@ -20,5 +13,18 @@
20
   "ibm-db2": {}
21
   "apt":
22
     "packages": []
23
-"repo": "bzr+ssh://bazaar.launchpad.net/~ibmcharmers/charms/trusty/layer-ibm-db2/trunk/"
24
+    "version_package": ""
25
+    "full_version": !!bool "false"
26
+"includes":
27
+- "layer:basic"
28
+- "layer:basic"
29
+- "layer:apt"
30
+- "layer:leadership"
31
+- "layer:basic"
32
+- "layer:apt"
33
+- "layer:leadership"
34
+- "layer:basic"
35
+- "layer:ibm-base"
36
+- "interface:db2"
37
+"repo": "bzr+ssh://bazaar.launchpad.net/~ibmcharmers/charms/xenial/ibm-db2/trunk/"
38
 "is": "ibm-db2"
Back to file index

lib/charms/apt.py

 1
--- lib/charms/apt.py
 2
+++ lib/charms/apt.py
 3
@@ -22,11 +22,12 @@
 4
 once the apt.installed.{packagename} state is set.
 5
 '''
 6
 import itertools
 7
+import re
 8
 import subprocess
 9
 
10
 from charmhelpers import fetch
11
 from charmhelpers.core import hookenv, unitdata
12
-from charms import reactive
13
+from charms import layer, reactive
14
 
15
 
16
 __all__ = ['add_source', 'update', 'queue_install', 'install_queued',
17
@@ -135,9 +136,43 @@
18
 
19
     for package in installed:
20
         reactive.set_state('apt.installed.{}'.format(package))
21
-
22
     reactive.remove_state('apt.queued_installs')
23
+
24
+    reset_application_version()
25
+
26
     return True
27
+
28
+
29
+def get_package_version(package, full_version=False):
30
+    '''Return the version of an installed package.
31
+
32
+    If `full_version` is True, returns the full Debian package version.
33
+    Otherwise, returns the shorter 'upstream' version number.
34
+    '''
35
+    # Don't use fetch.get_upstream_version, as it depends on python-apt
36
+    # and not available if the basic layer's use_site_packages option is off.
37
+    cmd = ['dpkg-query', '--show', r'--showformat=${Version}\n', package]
38
+    full = subprocess.check_output(cmd, universal_newlines=True).strip()
39
+    if not full_version:
40
+        # Attempt to strip off Debian style metadata from the end of the
41
+        # version number.
42
+        m = re.search('^([\d.a-z]+)', full, re.I)
43
+        if m is not None:
44
+            return m.group(1)
45
+    return full
46
+
47
+
48
+def reset_application_version():
49
+    '''Set the Juju application version, per settings in layer.yaml'''
50
+    # Reset the application version. We call this after installing
51
+    # packages to initialize the version. We also call this every
52
+    # hook, incase the version has changed (eg. Landscape upgraded
53
+    # the package).
54
+    opts = layer.options().get('apt', {})
55
+    pkg = opts.get('version_package')
56
+    if pkg and pkg in installed():
57
+        ver = get_package_version(pkg, opts.get('full_version', False))
58
+        hookenv.application_version_set(ver)
59
 
60
 
61
 def ensure_package_status():
62
@@ -152,7 +187,7 @@
63
     if not packages:
64
         return
65
     config = hookenv.config()
66
-    package_status = config['package_status']
67
+    package_status = config.get('package_status') or ''
68
     changed = reactive.helpers.data_changed('apt.package_status',
69
                                             (package_status, sorted(packages)))
70
     if changed:
71
@@ -166,10 +201,10 @@
72
 
73
 
74
 def status_set(state, message):
75
-    """Set the unit's workload status.
76
+    '''Set the unit's workload status.
77
 
78
     Set state == None to keep the same state and just change the message.
79
-    """
80
+    '''
81
     if state is None:
82
         state = hookenv.status_get()[0]
83
         if state == 'unknown':
Back to file index

lib/charms/layer/basic.py

  1
--- lib/charms/layer/basic.py
  2
+++ lib/charms/layer/basic.py
  3
@@ -1,11 +1,20 @@
  4
 import os
  5
 import sys
  6
 import shutil
  7
-import platform
  8
 from glob import glob
  9
 from subprocess import check_call
 10
 
 11
 from charms.layer.execd import execd_preinstall
 12
+
 13
+
 14
+def lsb_release():
 15
+    """Return /etc/lsb-release in a dict"""
 16
+    d = {}
 17
+    with open('/etc/lsb-release', 'r') as lsb:
 18
+        for l in lsb:
 19
+            k, v = l.split('=')
 20
+            d[k.strip()] = v.strip()
 21
+    return d
 22
 
 23
 
 24
 def bootstrap_charm_deps():
 25
@@ -25,12 +34,7 @@
 26
     vpip = os.path.join(vbin, 'pip')
 27
     vpy = os.path.join(vbin, 'python')
 28
     if os.path.exists('wheelhouse/.bootstrapped'):
 29
-        from charms import layer
 30
-        cfg = layer.options('basic')
 31
-        if cfg.get('use_venv') and '.venv' not in sys.executable:
 32
-            # activate the venv
 33
-            os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']])
 34
-            reload_interpreter(vpy)
 35
+        activate_venv()
 36
         return
 37
     # bootstrap wheelhouse
 38
     if os.path.exists('wheelhouse'):
 39
@@ -43,7 +47,12 @@
 40
                 "allow_hosts = ''\n",
 41
                 "find_links = file://{}/wheelhouse/\n".format(charm_dir),
 42
             ])
 43
-        apt_install(['python3-pip', 'python3-setuptools', 'python3-yaml'])
 44
+        apt_install([
 45
+            'python3-pip',
 46
+            'python3-setuptools',
 47
+            'python3-yaml',
 48
+            'python3-dev',
 49
+        ])
 50
         from charms import layer
 51
         cfg = layer.options('basic')
 52
         # include packages defined in layer.yaml
 53
@@ -51,7 +60,7 @@
 54
         # if we're using a venv, set it up
 55
         if cfg.get('use_venv'):
 56
             if not os.path.exists(venv):
 57
-                distname, version, series = platform.linux_distribution()
 58
+                series = lsb_release()['DISTRIB_CODENAME']
 59
                 if series in ('precise', 'trusty'):
 60
                     apt_install(['python-virtualenv'])
 61
                 else:
 62
@@ -89,6 +98,34 @@
 63
         # Non-namespace-package libs (e.g., charmhelpers) are available
 64
         # without having to reload the interpreter. :/
 65
         reload_interpreter(vpy if cfg.get('use_venv') else sys.argv[0])
 66
+
 67
+
 68
+def activate_venv():
 69
+    """
 70
+    Activate the venv if enabled in ``layer.yaml``.
 71
+
 72
+    This is handled automatically for normal hooks, but actions might
 73
+    need to invoke this manually, using something like:
 74
+
 75
+        # Load modules from $CHARM_DIR/lib
 76
+        import sys
 77
+        sys.path.append('lib')
 78
+
 79
+        from charms.layer.basic import activate_venv
 80
+        activate_venv()
 81
+
 82
+    This will ensure that modules installed in the charm's
 83
+    virtual environment are available to the action.
 84
+    """
 85
+    venv = os.path.abspath('../.venv')
 86
+    vbin = os.path.join(venv, 'bin')
 87
+    vpy = os.path.join(vbin, 'python')
 88
+    from charms import layer
 89
+    cfg = layer.options('basic')
 90
+    if cfg.get('use_venv') and '.venv' not in sys.executable:
 91
+        # activate the venv
 92
+        os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']])
 93
+        reload_interpreter(vpy)
 94
 
 95
 
 96
 def reload_interpreter(python):
 97
@@ -134,7 +171,7 @@
 98
     config_yaml = os.path.join(hookenv.charm_dir(), 'config.yaml')
 99
     if os.path.exists(config_yaml):
100
         with open(config_yaml) as fp:
101
-            config_defs = yaml.load(fp).get('options', {})
102
+            config_defs = yaml.safe_load(fp).get('options', {})
103
             config_defaults = {key: value.get('default')
104
                                for key, value in config_defs.items()}
105
     for opt in config_defs.keys():
Back to file index

metadata.yaml

 1
--- metadata.yaml
 2
+++ metadata.yaml
 3
@@ -5,18 +5,24 @@
 4
   IBM DB2 Enterprise Server Edition provides scalable database server software to handle the demanding workloads of large and midsize enterprise servers.
 5
 "tags":
 6
 - "ibm"
 7
-- "apt"
 8
-- "leadership"
 9
 - "ibm"
10
+- "ibm-z"
11
 - "db2"
12
 - "database"
13
 - "misc"
14
 "provides":
15
   "db":
16
     "interface": "db2"
17
+"min-juju-version": "2.0-beta1"
18
+"resources":
19
+  "ibm_db2_installer":
20
+    "type": "file"
21
+    "filename": "ibm_db2_installer.tar.gz"
22
+    "description": "IBM DB2 installer archive"
23
 "series":
24
 - "trusty"
25
 - "xenial"
26
 "subordinate": !!bool "false"
27
 "terms":
28
-- "lorem-ipsum/1"
29
+- "ibmcharmers/ibm-db2/1"
30
+
Back to file index

reactive/apt.py

  1
--- reactive/apt.py
  2
+++ reactive/apt.py
  3
@@ -21,19 +21,16 @@
  4
 installation with install(). Configure and work with your software
  5
 once the apt.installed.{packagename} state is set.
  6
 '''
  7
+import subprocess
  8
+
  9
 from charmhelpers import fetch
 10
 from charmhelpers.core import hookenv
 11
+from charmhelpers.core.hookenv import WARNING
 12
 from charms import layer
 13
 from charms import reactive
 14
 from charms.reactive import when, when_not
 15
 
 16
 import charms.apt
 17
-# Aliases for backwards compatibility
 18
-from charms.apt import add_source, queue_install, installed, purge
 19
-
 20
-
 21
-__all__ = ['add_source', 'update', 'queue_install', 'install_queued',
 22
-           'installed', 'purge', 'ensure_package_status']
 23
 
 24
 
 25
 @when('apt.needs_update')
 26
@@ -52,16 +49,35 @@
 27
     charms.apt.ensure_package_status()
 28
 
 29
 
 30
+def filter_installed_packages(packages):
 31
+    # Don't use fetch.filter_installed_packages, as it depends on python-apt
 32
+    # and not available if the basic layer's use_site_packages option is off
 33
+    cmd = ['dpkg-query', '--show', r'--showformat=${Package}\n']
 34
+    installed = set(subprocess.check_output(cmd,
 35
+                                            universal_newlines=True).split())
 36
+    return set(packages) - installed
 37
+
 38
+
 39
+def clear_removed_package_states():
 40
+    """On hook startup, clear install states for removed packages."""
 41
+    removed = filter_installed_packages(charms.apt.installed())
 42
+    if removed:
 43
+        hookenv.log('{} missing packages ({})'.format(len(removed),
 44
+                                                      ','.join(removed)),
 45
+                    WARNING)
 46
+        for package in removed:
 47
+            reactive.remove_state('apt.installed.{}'.format(package))
 48
+
 49
+
 50
 def configure_sources():
 51
     """Add user specified package sources from the service configuration.
 52
 
 53
     See charmhelpers.fetch.configure_sources for details.
 54
     """
 55
-    hookenv.log('Initializing Apt Layer')
 56
     config = hookenv.config()
 57
 
 58
     # We don't have enums, so we need to validate this ourselves.
 59
-    package_status = config.get('package_status')
 60
+    package_status = config.get('package_status') or ''
 61
     if package_status not in ('hold', 'install'):
 62
         charms.apt.status_set('blocked',
 63
                               'Unknown package_status {}'
 64
@@ -71,17 +87,18 @@
 65
         # invalid configuration.
 66
         raise SystemExit(0)
 67
 
 68
-    sources = config.get('install_sources')
 69
-    keys = config.get('install_keys')
 70
+    sources = config.get('install_sources') or ''
 71
+    keys = config.get('install_keys') or ''
 72
     if reactive.helpers.data_changed('apt.configure_sources', (sources, keys)):
 73
         fetch.configure_sources(update=False,
 74
                                 sources_var='install_sources',
 75
                                 keys_var='install_keys')
 76
         reactive.set_state('apt.needs_update')
 77
 
 78
-    extra_packages = sorted(config.get('extra_packages', '').split())
 79
+    # Clumsy 'config.get() or' per Bug #1641362
 80
+    extra_packages = sorted((config.get('extra_packages') or '').split())
 81
     if extra_packages:
 82
-        queue_install(extra_packages)
 83
+        charms.apt.queue_install(extra_packages)
 84
 
 85
 
 86
 def queue_layer_packages():
 87
@@ -93,7 +110,7 @@
 88
     opts = layer.options()
 89
     for section in ['basic', 'apt']:
 90
         if section in opts and 'packages' in opts[section]:
 91
-            queue_install(opts[section]['packages'])
 92
+            charms.apt.queue_install(opts[section]['packages'])
 93
 
 94
 
 95
 # Per https://github.com/juju-solutions/charms.reactive/issues/33,
 96
@@ -107,6 +124,9 @@
 97
     # do this, then the config in the hook environment may show updates
 98
     # to running hooks well before the config-changed hook has been invoked
 99
     # and the intialization provided an opertunity to be run.
100
+    hookenv.atstart(hookenv.log, 'Initializing Apt Layer')
101
+    hookenv.atstart(clear_removed_package_states)
102
     hookenv.atstart(configure_sources)
103
     hookenv.atstart(queue_layer_packages)
104
+    hookenv.atstart(charms.apt.reset_application_version)
105
     reactive._apt_registered = True
Back to file index

reactive/ibm-db2.sh

  1
--- reactive/ibm-db2.sh
  2
+++ reactive/ibm-db2.sh
  3
@@ -12,7 +12,7 @@
  4
 DB2_DAS_USER_PW=`pwgen -N 1 15`
  5
 DB2_FENCE_USER=db2fenc1
  6
 DB2_FENCE_USER_PW=`pwgen -N 1 15`
  7
-DB2_INSTALL_PATH=/opt/ibm/db2/V10.5
  8
+DB2_INSTALL_PATH=/opt/ibm/db2/V11.1
  9
 AUTH_KEY_FILE=/root/.ssh/authorized_keys
 10
 TEMP_KEY_FILE=key.txt
 11
 
 12
@@ -242,8 +242,8 @@
 13
 edit_responsefile()
 14
 {
 15
 	rsp_file=db2server_temp.rsp
 16
-	if [ "$ARCHITECTURE" = "x86_64" ]; then
 17
-		orgrsp_file=db2server.rsp
 18
+	if [ "$ARCHITECTURE" = "s390x" ]; then
 19
+		orgrsp_file=db2server_z.rsp
 20
 	else
 21
 		orgrsp_file=db2server_ppcle.rsp
 22
 	fi
 23
@@ -542,33 +542,6 @@
 24
 }
 25
 
 26
 
 27
-@when_not 'config.set.license_accepted'
 28
-function report_missing_license(){
 29
-	juju-log "IBM DB2: license_accepted is not set."
 30
-	status-set blocked "license_accepted must be set"
 31
-}
 32
-
 33
-
 34
-@when_not 'config.set.curl_url'
 35
-function report_missing_curl(){
 36
-	juju-log "IBM DB2: curl config options are not set."
 37
-	status-set blocked "curl options must be set"
 38
-}
 39
-
 40
-
 41
-@when 'ibm-db2.installed'
 42
-@when_not 'ibm-base.license.accepted'
 43
-function uninstall(){
 44
-	juju-log "IBM DB2: Removing IBM DB2 (if installed) as the license agreement is not accepted."
 45
-	status-set maintenance "IBM DB2 is getting uninstalled"
 46
-	remove_software
 47
-	remove_state 'ibm-db2.installed'
 48
-	status-set maintenance "IBM DB2 is uninstalled"
 49
-	rm -rf $TEMP_KEY_FILE
 50
-
 51
-}
 52
-
 53
-#Setting the interface states after uninstall
 54
 @when 'db.connected'
 55
 @when_not 'ibm-db2.installed'
 56
 function reset_interface_states(){
 57
@@ -584,8 +557,8 @@
 58
 
 59
 @when_not 'ibm-db2.prereqsinstalled'
 60
 function init() {
 61
-	if [ "$ARCHITECTURE" != "x86_64" -a "$ARCHITECTURE" != "ppc64le" ]; then
 62
-		juju-log "IBM DB2: Unsupported platform. IBM DB2 installed with this Charm supports only the x86_64 and POWER LE (ppc64le) platforms."
 63
+	if [ "$ARCHITECTURE" != "x86_64" -a "$ARCHITECTURE" != "ppc64le" -a "$ARCHITECTURE" != "s390x" ]; then
 64
+		juju-log "IBM DB2: Unsupported platform. IBM DB2 installed with this Charm supports only the x86_64 and POWER LE (ppc64le) and s390x platforms."
 65
 		exit 1
 66
 	fi
 67
 	set -e
 68
@@ -596,11 +569,22 @@
 69
 	if [ "$ARCHITECTURE" == "x86_64" ]; then
 70
 		juju-log "IBM DB2: Installing 32 bit libstdc++.so.6"
 71
 		apt-get install lib32stdc++6 -y
 72
+                apt-get install rpm
 73
 		juju-log "IBM DB2: Installed 32 bit libstdc++.so.6"
 74
+	fi
 75
+	if [ "$ARCHITECTURE" == "s390x" ]; then
 76
+                juju-log "IBM DB2: Installing 32 bit libstdc++.so.6"
 77
+                apt-get install lib32stdc++6 -y
 78
+                juju-log "IBM DB2: Installed 32 bit libstdc++.so.6"
 79
+
 80
+                juju-log "IBM DB2: Installing libaio1 and binutils "
 81
+		apt-get install libaio1 
 82
+		juju-log "IBM DB2: Installed libaio1 and binutils"
 83
 	fi
 84
 	if [ "$ARCHITECTURE" == "ppc64le" ]; then
 85
 		juju-log "IBM DB2:  Installing libnuma package for POWER LE (ppc64le) platforms."
 86
 		apt-get install libnuma-dev -y
 87
+                apt-get install rpm
 88
 		#Installing XL compiler runtime packages for Linux on Power as this is one of the prerequisite software/configuration requirements
 89
 		echo "deb http://public.dhe.ibm.com/software/server/POWER/Linux/rte/xlcpp/le/ubuntu $(lsb_release -s -c) main" | tee -a /etc/apt/sources.list.d/ibm-xlcpp-rte.list
 90
 		apt-get update
 91
@@ -626,29 +610,47 @@
 92
 
 93
 }
 94
 
 95
-
 96
-@when 'ibm-db2.prereqsinstalled' 'ibm-base.license.accepted' 'ibm-base.curl.resource.fetched'
 97
+@when 'ibm-db2.prereqsinstalled'
 98
 @when_not 'ibm-db2.installed'
 99
 function install() {
100
+        # Get the installable db2 resources
101
+        juju-log "IBM DB2: fetching the ibm_db2 _installer resource"
102
+        status-set maintenance "IBM DB2: fetching the ibm_db2 _installer resource"
103
+        db2_pkg_name=`resource-get 'ibm_db2_installer' || echo unavailable`
104
+        ibm_db2_installer_isempty=`file $db2_pkg_name | { grep -q empty && echo "True"; } || echo "False"`
105
+        # If we don't have a package, report blocked status; we can't proceed.
106
+        if [ "$db2_pkg_name" = "unavailable" ]; then
107
+              juju-log "IBM DB2: missing required ibm_db2_installer resource"
108
+              status-set blocked "missing required ibm_db2_installer resource"
109
+              return 0
110
+        fi
111
+                if [ "$ibm_db2_installer_isempty" = "True" ]; then
112
+                        juju-log "IBM DB2: missing required ibm_db2_installer resource, found empty packages"
113
+                        status-set blocked "missing required ibm_db2_installer resource, provide actual ibm_db2_installer resource."
114
+                        return 0
115
+                fi
116
+
117
+        ARCHIVE_DIR1=`dirname $db2_pkg_name`
118
+        echo "$ARCHIVE_DIR1"
119
 	juju-log "IBM DB2: License accepted"
120
 	db2_inst=`is_db2_installed`
121
-	if [[ ! -d $ARCHIVE_DIR ]]; then
122
-		mkdir $ARCHIVE_DIR
123
+	if [[ ! -d $ARCHIVE_DIR1 ]]; then
124
+		mkdir $ARCHIVE_DIR1
125
 	fi
126
 	#Install if download succeeded
127
 	if  [ $db2_inst == "False" ]; then
128
-		if [ -f  $ARCHIVE_DIR/*.gz ]; then
129
+		if [ -f  $ARCHIVE_DIR1/*.gz ]; then
130
 
131
 			cd $CHARM_DIR/files/archives
132
-			tar -zxvf $ARCHIVE_DIR/*.gz
133
+			tar -zxvf $ARCHIVE_DIR1/*.gz
134
 			if [ $? -ne 0 ]; then
135
 				juju-log "IBM DB2: Unable to extract the DB2 package content. Verify whether the package is corrupt."
136
 				status-set maintenance "Unable to extract the DB2 package content"
137
 				#Remove corrupt archive file
138
-				rm -rf $ARCHIVE_DIR/*.gz
139
+				rm -rf $ARCHIVE_DIR1/*.gz
140
 				exit 0
141
 			fi
142
-			if [ "$ARCHITECTURE" = "x86_64" ]; then
143
+			if [ "$ARCHITECTURE" = "s390x" ]; then
144
 				rsp_file=db2server.rsp
145
 			else
146
 				rsp_file=db2server_ppcle.rsp
147
@@ -813,4 +815,5 @@
148
 		relation_call --state=db.departed dismiss $service || true
149
 	done
150
 }
151
+
152
 reactive_handler_main
Back to file index

tests/00-setup

 1
--- tests/00-setup
 2
+++ 
 3
@@ -1,17 +0,0 @@
 4
-#!/bin/bash
 5
-
 6
-
 7
-DB2_CURL_URL=${DB2_CURL_URL?Error: IBM IM  curl_url be defined in tests/00-setup}
 8
-DB2_CURL_OPTS=${DB2_CURL_OPTS?Error: IBM IM  curl_OPTS be defined in tests/00-setup}
 9
-
10
-
11
-# Add a local configuration file
12
-cat << EOF > local.yaml
13
-ibm-repo:
14
-    db2_curl_url: "$DB2_CURL_URL"
15
-    db2_curl_opts: "$DB2_CURL_OPTS"
16
-EOF
17
-
18
-sudo add-apt-repository ppa:juju/stable -y
19
-sudo apt-get update
20
-sudo apt-get install amulet python3 -y
Back to file index

tests/01-deploy.py

 1
--- 
 2
+++ tests/01-deploy.py
 3
@@ -0,0 +1,52 @@
 4
+#!/usr/bin/env python3
 5
+
 6
+import amulet
 7
+import re
 8
+import unittest
 9
+
10
+seconds_to_wait = 20000
11
+
12
+
13
+class TestDeploy(unittest.TestCase):
14
+    """
15
+    Deployment test for the IBM DB2 charm.
16
+    """
17
+    def setUp(self):
18
+        self.d = amulet.Deployment(series='xenial')
19
+        self.d.add('ibm-db2', '/root/charms/xenial/ibm-db2')
20
+        self.d.setup(seconds_to_wait)
21
+        self.d.sentry.wait(seconds_to_wait)
22
+
23
+    def test_deploy_with_placeholder_resource(self):
24
+        # The status message when using placeholder resources will include the
25
+        # string "ibm_db2_installer resource". If we see that, the test is
26
+        # successful.
27
+        sentry_re = re.compile('ibm_db2_installer resource')
28
+        self.d.sentry.wait_for_messages({"ibm-db2": sentry_re})
29
+
30
+    def test_deployed(self):
31
+        """ Test to see if the bundle deployed successfully. """
32
+        self.assertTrue(self.d.deployed)
33
+
34
+        db2_unit = self.d.sentry['ibm-db2'][0]
35
+        # Get the port num where db2 is running and check for netstat
36
+        output, code = db2_unit.run("su - db2inst1 -c 'db2 get dbm cfg'"
37
+                                    " | grep -i svce | cut -d'=' -f2")
38
+        if code != 0:
39
+            message = 'Unable to get the port number where DB2 is running.'
40
+            ' Exiting before completing'
41
+            'rest of the verification tests.'
42
+            amulet.raise_status(amulet.FAIL, msg=message)
43
+        print('DB2 running in port num : %s' % output)
44
+        print('Checking netstat command')
45
+        cmd = "su - db2inst1 -c 'netstat -an' | grep LISTEN | grep %s" % output
46
+        output, code = db2_unit.run(cmd)
47
+        if code != 0:
48
+            message = 'Unable to get the port number where DB2 is running.'\
49
+                   ' Exiting before completing rest of the verification tests.'
50
+            amulet.raise_status(amulet.FAIL, msg=message)
51
+        print('Output of netstat command id %s' % output)
52
+
53
+
54
+if __name__ == '__main__':
55
+    unittest.main()
Back to file index

tests/10-bundles-test.py

 1
--- tests/10-bundles-test.py
 2
+++ 
 3
@@ -1,73 +0,0 @@
 4
-#!/usr/bin/env python3
 5
-
 6
-# This amulet test deploys the bundles.yaml file in this directory.
 7
-
 8
-import os
 9
-import unittest
10
-import yaml
11
-import amulet
12
-import sys
13
-import time
14
-import requests
15
-
16
-seconds_to_wait = 20000
17
-
18
-
19
-class BundleTest(unittest.TestCase):
20
-    """ Create a class for testing the charm in the unit test framework. """
21
-    @classmethod
22
-    def setUpClass(cls):
23
-        """ Set up an amulet deployment using the bundle. """
24
-        d = amulet.Deployment(juju_env='local', series='trusty')
25
-        # We have a contextual test, if no config is present, initialze the
26
-        # test with an empty configuration set
27
-        config = {}
28
-        local_path = os.path.join(os.path.dirname(__file__), 'local.yaml')
29
-        with open(local_path, "r") as fd:
30
-           config = yaml.safe_load(fd)
31
-
32
-        curl_url = config.get('ibm-repo').get('db2_curl_url')
33
-        if not curl_url:
34
-             message = 'Please provide the curl url from where the package can be downloaded.'
35
-             amulet.raise_status(amulet.FAIL, msg=message)
36
-             sys.exit(1)
37
-        
38
-        curl_opts =  config.get('ibm-repo').get('db2_curl_opts')
39
-        if not curl_opts:
40
-             message = 'Please provide the curl_opts to specify the credentials to download the packages.'
41
-             amulet.raise_status(amulet.FAIL, msg=message)
42
-             sys.exit(1)
43
-
44
-
45
-        d.add('ibm-db2')
46
-
47
-        d.configure('ibm-db2', { 'license_accepted': True, 
48
-                                 'curl_url': curl_url, 
49
-                                 'curl_opts': curl_opts })
50
-        d.setup(seconds_to_wait)
51
-        d.sentry.wait(seconds_to_wait)
52
-        cls.d = d
53
-
54
-
55
-
56
-    def test_deployed(self):
57
-        """ Test to see if the bundle deployed successfully. """
58
-        self.assertTrue(self.d.deployed)
59
-
60
-        db2_unit = self.d.sentry['ibm-db2'][0]
61
-        # Get the port num where db2 is running and check for netstat
62
-        output, code = db2_unit.run("su - db2inst1 -c 'db2 get dbm cfg' | grep -i svce | cut -d'=' -f2")
63
-        if code != 0:
64
-          message = 'Unable to get the port number where DB2 is running. Exiting before completing rest of the verification tests.'
65
-          amulet.raise_status(amulet.FAIL, msg=message)
66
-        print('DB2 running in port num : %s' % output)
67
-        print('Checking netstat command')
68
-        cmd = "su - db2inst1 -c 'netstat -an' | grep LISTEN | grep %s" % output
69
-        output, code = db2_unit.run(cmd)
70
-        if code != 0:
71
-         message = 'Unable to get the port number where DB2 is running. Exiting before completing rest of the verification tests.'
72
-         amulet.raise_status(amulet.FAIL, msg=message)
73
-        print('Output of netstat command id %s' % output)
74
-
75
-if __name__ == '__main__':
76
-    unittest.main()
Back to file index

tests/bundles.yaml

 1
--- tests/bundles.yaml
 2
+++ 
 3
@@ -1,10 +0,0 @@
 4
-ibm-db2-bundle: 
 5
-  services: 
 6
-    "ibm-db2": 
 7
-      charm: "ibm-db2"
 8
-      num_units: 1
 9
-      annotations: 
10
-        "gui-x": "300"
11
-        "gui-y": "300"
12
-  relations: []
13
-  series: trusty
Back to file index

tests/tests.yaml

1
--- 
2
+++ tests/tests.yaml
3
@@ -0,0 +1,5 @@
4
+packages:
5
+  - amulet
6
+  - python3
7
+  - unzip
8
+  - pwgen