Merge lp:~veebers/juju-ci-tools/add-dumm-storage-charm into lp:juju-ci-tools/repository

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 88
Proposed branch: lp:~veebers/juju-ci-tools/add-dumm-storage-charm
Merge into: lp:juju-ci-tools/repository
Diff against target: 160 lines (+122/-0)
7 files modified
charms/dummy-storage/config.yaml (+10/-0)
charms/dummy-storage/hooks/config-changed (+59/-0)
charms/dummy-storage/hooks/install (+13/-0)
charms/dummy-storage/hooks/multi-fs-storage-attached (+7/-0)
charms/dummy-storage/hooks/single-fs-storage-attached (+5/-0)
charms/dummy-storage/hooks/start (+5/-0)
charms/dummy-storage/metadata.yaml (+23/-0)
To merge this branch: bzr merge lp:~veebers/juju-ci-tools/add-dumm-storage-charm
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+319890@code.launchpad.net

This proposal supersedes a proposal from 2017-03-14.

Commit message

Dummy charm that allows storing a token value to storage.

Description of the change

Dummy charm that allows storing a token value to storage.

This is an attempt at making a charm that we can use to test persistent storage.
It will be used to make sure that data persists when detached (either directly or through application removal) and re-attached to an application.

e.g.
  - deploy and set token for the single filesystem.
  - check token value in the file stored on disk
  - remove application
  - deploy again, this time using the existing storage unit
  - check token values etc.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

I have a question in line and a few suggestions

review: Needs Information (code)
78. By Christopher Lee

Remove missleading 'blocked' term from status.

79. By Christopher Lee

Remove and shuffle series.

80. By Christopher Lee

Remove revision file.

Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'charms/dummy-storage'
=== added file 'charms/dummy-storage/config.yaml'
--- charms/dummy-storage/config.yaml 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/config.yaml 2017-03-16 02:26:57 +0000
@@ -0,0 +1,10 @@
1options:
2 # Will be tokens for each storage type.
3 single-fs-token:
4 type: string
5 default: ''
6 description: Token used to prove data stored is persistent
7 multi-fs-token:
8 type: string
9 default: ''
10 description: Token used to prove data stored is persistent
011
=== added directory 'charms/dummy-storage/hooks'
=== added file 'charms/dummy-storage/hooks/config-changed'
--- charms/dummy-storage/hooks/config-changed 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/hooks/config-changed 2017-03-16 02:26:57 +0000
@@ -0,0 +1,59 @@
1#!/bin/bash
2set -x
3
4juju-log -l INFO "Getting file fs token details."
5status-set maintenance "Getting file fs token details." || true
6
7function set_token() {
8 token_name=$1 # i.e. single-fs-token
9 fs_path=$2 # i.e. /srv/single-fs/ or /srv/multi-fs/multi-fs/13
10
11 token="$(config-get $token_name)"
12 token_file="$fs_path/token"
13
14 juju-log -l INFO "Token file: $token_file"
15
16 if [ -f $token_file ]; then
17 juju-log -l INFO "Using stored token details."
18
19 # If we have a token and we have a token file, check the contents if the differ update it otherwise use it.
20 current_file_token=$(cat $token_file | grep "$token_name" | head -1 | cut -d":" -f2)
21 if [ "$current_file_token" != "$token" ]; then
22 token=$token
23 else
24 token=$(cat $token_file)
25 fi
26 fi
27
28 if [[ -z $token ]]; then
29 fs_token="not set"
30 juju-log -l WARNING "$fs_token"
31 else
32 fs_token="$token"
33 echo "$token" > $token_file
34 juju-log -l INFO "$fs_token"
35 fi
36
37 # Return the token value.
38 echo "$fs_token"
39}
40
41# Clear any previous tokens or state.
42echo > /tmp/status
43
44# First the single token
45single_fs_token=$(set_token "single-fs-token" "/srv/single-fs")
46
47juju-log -l INFO "Setting single token details."
48echo "single-fs-token:$single_fs_token" >> /tmp/status
49
50# Then the multi-fs token
51for unit in $(storage-list multi-fs); do
52 fs_path=$(storage-get -s $unit | grep "^location:\ " | cut -d: -f2 | tr -d ' ')
53 multi_fs_token=$(set_token "multi-fs-token" "$fs_path")
54 juju-log -l INFO "Setting multi token details."
55 unit_token_number=$(echo $unit | cut -f2 -d"/")
56 echo "multi-fs-token/$unit_token_number:$multi_fs_token" >> /tmp/status
57done
58
59status-set active "Stored token: /tmp/status" || true
060
=== added file 'charms/dummy-storage/hooks/hooks'
=== added file 'charms/dummy-storage/hooks/install'
--- charms/dummy-storage/hooks/install 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/hooks/install 2017-03-16 02:26:57 +0000
@@ -0,0 +1,13 @@
1#!/bin/bash
2
3set -x
4
5juju-log -l INFO "Install"
6juju-log -l INFO "Data on drive: $(cat /srv/single-fs/test.txt)"
7
8for unit in $(storage-list); do
9 juju-log -l INFO "Storage details for ${unit}: $(storage-get -s $unit)"
10done
11
12# The storage-attached hook has fired so we can write some data there now.
13status-set maintenance "Installed" || true
014
=== added file 'charms/dummy-storage/hooks/multi-fs-storage-attached'
--- charms/dummy-storage/hooks/multi-fs-storage-attached 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/hooks/multi-fs-storage-attached 2017-03-16 02:26:57 +0000
@@ -0,0 +1,7 @@
1#!/bin/bash
2set -x
3
4juju-log -l INFO "Storage is attached."
5juju-log -l INFO "Storage details: $(storage-list)"
6
7status-set active "Started" || true
08
=== added file 'charms/dummy-storage/hooks/single-fs-storage-attached'
--- charms/dummy-storage/hooks/single-fs-storage-attached 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/hooks/single-fs-storage-attached 2017-03-16 02:26:57 +0000
@@ -0,0 +1,5 @@
1#!/bin/bash
2set -x
3
4juju-log -l INFO "Storage is attached."
5juju-log -l INFO "Hook details: $(storage-list)"
0\ No newline at end of file6\ No newline at end of file
17
=== added file 'charms/dummy-storage/hooks/start'
--- charms/dummy-storage/hooks/start 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/hooks/start 2017-03-16 02:26:57 +0000
@@ -0,0 +1,5 @@
1#!/bin/bash
2set -x
3
4juju-log -l INFO "Starting, checking what storage we have."
5juju-log -l INFO "Storage details: $(storage-list)"
06
=== added file 'charms/dummy-storage/metadata.yaml'
--- charms/dummy-storage/metadata.yaml 1970-01-01 00:00:00 +0000
+++ charms/dummy-storage/metadata.yaml 2017-03-16 02:26:57 +0000
@@ -0,0 +1,23 @@
1name: dummy-storage
2maintainer: Christopher Lee <chris.lee@canonical.com>
3summary: Dummy charm that utilises storage.
4description: This dummy charm is used for testing persistent storage.
5categories:
6 - misc
7series:
8 - xenial
9 - trusty
10 - precise
11storage:
12 single-fs:
13 type: filesystem
14 description: Single instance storage of filesystem type.
15 minimum-size: 10M
16 location: /srv/single-fs
17 multi-fs:
18 type: filesystem
19 description: Multiple storage instances of filesystem type.
20 minimum-size: 10M
21 location: /srv/multi-fs
22 multiple:
23 range: 0-2

Subscribers

People subscribed via source and target branches