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

Proposed by Curtis Hovey on 2017-03-15
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 on 2017-03-22
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.
Curtis Hovey (sinzui) wrote :

I have a question in line and a few suggestions

review: Needs Information (code)
78. By Christopher Lee on 2017-03-16

Remove missleading 'blocked' term from status.

79. By Christopher Lee on 2017-03-16

Remove and shuffle series.

80. By Christopher Lee on 2017-03-16

Remove revision file.

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
1=== added directory 'charms/dummy-storage'
2=== added file 'charms/dummy-storage/config.yaml'
3--- charms/dummy-storage/config.yaml 1970-01-01 00:00:00 +0000
4+++ charms/dummy-storage/config.yaml 2017-03-16 02:26:57 +0000
5@@ -0,0 +1,10 @@
6+options:
7+ # Will be tokens for each storage type.
8+ single-fs-token:
9+ type: string
10+ default: ''
11+ description: Token used to prove data stored is persistent
12+ multi-fs-token:
13+ type: string
14+ default: ''
15+ description: Token used to prove data stored is persistent
16
17=== added directory 'charms/dummy-storage/hooks'
18=== added file 'charms/dummy-storage/hooks/config-changed'
19--- charms/dummy-storage/hooks/config-changed 1970-01-01 00:00:00 +0000
20+++ charms/dummy-storage/hooks/config-changed 2017-03-16 02:26:57 +0000
21@@ -0,0 +1,59 @@
22+#!/bin/bash
23+set -x
24+
25+juju-log -l INFO "Getting file fs token details."
26+status-set maintenance "Getting file fs token details." || true
27+
28+function set_token() {
29+ token_name=$1 # i.e. single-fs-token
30+ fs_path=$2 # i.e. /srv/single-fs/ or /srv/multi-fs/multi-fs/13
31+
32+ token="$(config-get $token_name)"
33+ token_file="$fs_path/token"
34+
35+ juju-log -l INFO "Token file: $token_file"
36+
37+ if [ -f $token_file ]; then
38+ juju-log -l INFO "Using stored token details."
39+
40+ # If we have a token and we have a token file, check the contents if the differ update it otherwise use it.
41+ current_file_token=$(cat $token_file | grep "$token_name" | head -1 | cut -d":" -f2)
42+ if [ "$current_file_token" != "$token" ]; then
43+ token=$token
44+ else
45+ token=$(cat $token_file)
46+ fi
47+ fi
48+
49+ if [[ -z $token ]]; then
50+ fs_token="not set"
51+ juju-log -l WARNING "$fs_token"
52+ else
53+ fs_token="$token"
54+ echo "$token" > $token_file
55+ juju-log -l INFO "$fs_token"
56+ fi
57+
58+ # Return the token value.
59+ echo "$fs_token"
60+}
61+
62+# Clear any previous tokens or state.
63+echo > /tmp/status
64+
65+# First the single token
66+single_fs_token=$(set_token "single-fs-token" "/srv/single-fs")
67+
68+juju-log -l INFO "Setting single token details."
69+echo "single-fs-token:$single_fs_token" >> /tmp/status
70+
71+# Then the multi-fs token
72+for unit in $(storage-list multi-fs); do
73+ fs_path=$(storage-get -s $unit | grep "^location:\ " | cut -d: -f2 | tr -d ' ')
74+ multi_fs_token=$(set_token "multi-fs-token" "$fs_path")
75+ juju-log -l INFO "Setting multi token details."
76+ unit_token_number=$(echo $unit | cut -f2 -d"/")
77+ echo "multi-fs-token/$unit_token_number:$multi_fs_token" >> /tmp/status
78+done
79+
80+status-set active "Stored token: /tmp/status" || true
81
82=== added file 'charms/dummy-storage/hooks/hooks'
83=== added file 'charms/dummy-storage/hooks/install'
84--- charms/dummy-storage/hooks/install 1970-01-01 00:00:00 +0000
85+++ charms/dummy-storage/hooks/install 2017-03-16 02:26:57 +0000
86@@ -0,0 +1,13 @@
87+#!/bin/bash
88+
89+set -x
90+
91+juju-log -l INFO "Install"
92+juju-log -l INFO "Data on drive: $(cat /srv/single-fs/test.txt)"
93+
94+for unit in $(storage-list); do
95+ juju-log -l INFO "Storage details for ${unit}: $(storage-get -s $unit)"
96+done
97+
98+# The storage-attached hook has fired so we can write some data there now.
99+status-set maintenance "Installed" || true
100
101=== added file 'charms/dummy-storage/hooks/multi-fs-storage-attached'
102--- charms/dummy-storage/hooks/multi-fs-storage-attached 1970-01-01 00:00:00 +0000
103+++ charms/dummy-storage/hooks/multi-fs-storage-attached 2017-03-16 02:26:57 +0000
104@@ -0,0 +1,7 @@
105+#!/bin/bash
106+set -x
107+
108+juju-log -l INFO "Storage is attached."
109+juju-log -l INFO "Storage details: $(storage-list)"
110+
111+status-set active "Started" || true
112
113=== added file 'charms/dummy-storage/hooks/single-fs-storage-attached'
114--- charms/dummy-storage/hooks/single-fs-storage-attached 1970-01-01 00:00:00 +0000
115+++ charms/dummy-storage/hooks/single-fs-storage-attached 2017-03-16 02:26:57 +0000
116@@ -0,0 +1,5 @@
117+#!/bin/bash
118+set -x
119+
120+juju-log -l INFO "Storage is attached."
121+juju-log -l INFO "Hook details: $(storage-list)"
122\ No newline at end of file
123
124=== added file 'charms/dummy-storage/hooks/start'
125--- charms/dummy-storage/hooks/start 1970-01-01 00:00:00 +0000
126+++ charms/dummy-storage/hooks/start 2017-03-16 02:26:57 +0000
127@@ -0,0 +1,5 @@
128+#!/bin/bash
129+set -x
130+
131+juju-log -l INFO "Starting, checking what storage we have."
132+juju-log -l INFO "Storage details: $(storage-list)"
133
134=== added file 'charms/dummy-storage/metadata.yaml'
135--- charms/dummy-storage/metadata.yaml 1970-01-01 00:00:00 +0000
136+++ charms/dummy-storage/metadata.yaml 2017-03-16 02:26:57 +0000
137@@ -0,0 +1,23 @@
138+name: dummy-storage
139+maintainer: Christopher Lee <chris.lee@canonical.com>
140+summary: Dummy charm that utilises storage.
141+description: This dummy charm is used for testing persistent storage.
142+categories:
143+ - misc
144+series:
145+ - xenial
146+ - trusty
147+ - precise
148+storage:
149+ single-fs:
150+ type: filesystem
151+ description: Single instance storage of filesystem type.
152+ minimum-size: 10M
153+ location: /srv/single-fs
154+ multi-fs:
155+ type: filesystem
156+ description: Multiple storage instances of filesystem type.
157+ minimum-size: 10M
158+ location: /srv/multi-fs
159+ multiple:
160+ range: 0-2

Subscribers

People subscribed via source and target branches