Skip to content

Commit

Permalink
add dummy storage charms for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
evanson committed Sep 2, 2022
1 parent a18bf5b commit 57a8b9a
Show file tree
Hide file tree
Showing 43 changed files with 691 additions and 285 deletions.
6 changes: 6 additions & 0 deletions testcharms/charms/dummy-storage-fs/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options:
# Will be tokens for each storage type.
data-token:
type: string
default: ''
description: Token used to prove data stored is persistent
59 changes: 59 additions & 0 deletions testcharms/charms/dummy-storage-fs/hooks/config-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -x

juju-log -l INFO "Getting file fs token details."
status-set maintenance "Getting file fs token details." || true

function set_token() {
token_name=$1 # i.e. data-token
fs_path=$2 # i.e. /srv/data/

token="$(config-get $token_name)"
token_file="$fs_path/token"

juju-log -l INFO "Token file: $token_file"

if [ -f $token_file ]; then
juju-log -l INFO "Using stored token details."

# If we have a token and we have a token file, check the contents if the differ update it otherwise use it.
current_file_token=$(cat $token_file | grep "$token_name" | head -1 | cut -d":" -f2)
if [ "$current_file_token" != "$token" ]; then
token=$token
else
token=$(cat $token_file)
fi
fi

if [[ -z $token ]]; then
fs_token="not set"
juju-log -l WARNING "$fs_token"
else
fs_token="$token"
echo "$token" > $token_file
juju-log -l INFO "$fs_token"
fi

# Return the token value.
echo "$fs_token"
}

# Clear any previous tokens or state.
echo > /tmp/status

# First the single token
data_token=$(set_token "data-token" "/srv/data")

juju-log -l INFO "Setting single token details."
echo "data-token:$data_token" >> /tmp/status

## Then the multi-fs token
#for unit in $(storage-list multi-fs); do
# fs_path=$(storage-get -s $unit | grep "^location:\ " | cut -d: -f2 | tr -d ' ')
# multi_fs_token=$(set_token "multi-fs-token" "$fs_path")
# juju-log -l INFO "Setting multi token details."
# unit_token_number=$(echo $unit | cut -f2 -d"/")
# echo "multi-fs-token/$unit_token_number:$multi_fs_token" >> /tmp/status
#done

status-set active "Stored token: /tmp/status" || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x

juju-log -l INFO "Storage is attached."
juju-log -l INFO "Storage details: $(storage-list)"

status-set active "Started" || true
Empty file.
16 changes: 16 additions & 0 deletions testcharms/charms/dummy-storage-fs/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -x

status-set maintenance "Removing sshguard" || true
sudo apt-get remove sshguard || true

juju-log -l INFO "Install"
juju-log -l INFO "Data on drive: $(cat /srv/data/test.txt)"

for unit in $(storage-list); do
juju-log -l INFO "Storage details for ${unit}: $(storage-get -s $unit)"
done

# The storage-attached hook has fired so we can write some data there now.
status-set maintenance "Installed" || true
5 changes: 5 additions & 0 deletions testcharms/charms/dummy-storage-fs/hooks/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -x

juju-log -l INFO "Starting, checking what storage we have."
juju-log -l INFO "Storage details: $(storage-list)"
25 changes: 25 additions & 0 deletions testcharms/charms/dummy-storage-fs/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: dummy-storage-fs
maintainer:
- Christopher Lee <chris.lee@canonical.com>
- Burton Swan <burton.swan@canonical.com>
- Evanson Mwangi <evanson.wainaina@canonical.com>
summary: Dummy charm that utilises storage.
description: This dummy-storage-fs charm is used for testing charm storage.
categories:
- misc
series:
- trusty
- xenial
- artful
- bionic
- eoan
- focal
- jammy

storage:
data:
type: filesystem
description: junk storage
minimum-size: 100M
location: /srv/data

6 changes: 6 additions & 0 deletions testcharms/charms/dummy-storage-lp/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options:
# Will be tokens for each storage type.
data-token:
type: string
default: ''
description: Token used to prove data stored is persistent
59 changes: 59 additions & 0 deletions testcharms/charms/dummy-storage-lp/hooks/config-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -x

juju-log -l INFO "Getting file fs token details."
status-set maintenance "Getting file fs token details." || true

function set_token() {
token_name=$1 # i.e. data-token
fs_path=$2 # i.e. /srv/data/

token="$(config-get $token_name)"
token_file="$fs_path/token"

juju-log -l INFO "Token file: $token_file"

if [ -f $token_file ]; then
juju-log -l INFO "Using stored token details."

# If we have a token and we have a token file, check the contents if the differ update it otherwise use it.
current_file_token=$(cat $token_file | grep "$token_name" | head -1 | cut -d":" -f2)
if [ "$current_file_token" != "$token" ]; then
token=$token
else
token=$(cat $token_file)
fi
fi

if [[ -z $token ]]; then
fs_token="not set"
juju-log -l WARNING "$fs_token"
else
fs_token="$token"
echo "$token" > $token_file
juju-log -l INFO "$fs_token"
fi

# Return the token value.
echo "$fs_token"
}

# Clear any previous tokens or state.
echo > /tmp/status

# First the single token
data_token=$(set_token "data-token" "/srv/data")

juju-log -l INFO "Setting single token details."
echo "data-token:$data_token" >> /tmp/status

## Then the multi-fs token
#for unit in $(storage-list multi-fs); do
# fs_path=$(storage-get -s $unit | grep "^location:\ " | cut -d: -f2 | tr -d ' ')
# multi_fs_token=$(set_token "multi-fs-token" "$fs_path")
# juju-log -l INFO "Setting multi token details."
# unit_token_number=$(echo $unit | cut -f2 -d"/")
# echo "multi-fs-token/$unit_token_number:$multi_fs_token" >> /tmp/status
#done

status-set active "Stored token: /tmp/status" || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x

juju-log -l INFO "Storage is attached."
juju-log -l INFO "Storage details: $(storage-list)"

status-set active "Started" || true
Empty file.
16 changes: 16 additions & 0 deletions testcharms/charms/dummy-storage-lp/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -x

status-set maintenance "Removing sshguard" || true
sudo apt-get remove sshguard || true

juju-log -l INFO "Install"
juju-log -l INFO "Data on drive: $(cat /srv/data/test.txt)"

for unit in $(storage-list); do
juju-log -l INFO "Storage details for ${unit}: $(storage-get -s $unit)"
done

# The storage-attached hook has fired so we can write some data there now.
status-set maintenance "Installed" || true
5 changes: 5 additions & 0 deletions testcharms/charms/dummy-storage-lp/hooks/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -x

juju-log -l INFO "Starting, checking what storage we have."
juju-log -l INFO "Storage details: $(storage-list)"
24 changes: 24 additions & 0 deletions testcharms/charms/dummy-storage-lp/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: dummy-storage-lp
maintainer:
- Christopher Lee <chris.lee@canonical.com>
- Burton Swan <burton.swan@canonical.com>
- Evanson Mwangi <evanson.wainaina@canonical.com>
summary: Dummy charm that utilises storage.
description: This dummy-storage-fs charm is used for testing charm storage.
categories:
- misc
series:
- trusty
- xenial
- artful
- bionic
- eoan
- focal
- jammy

storage:
disks:
type: block
multiple:
range: 0-10

6 changes: 6 additions & 0 deletions testcharms/charms/dummy-storage-mp/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options:
# Will be tokens for each storage type.
data-token:
type: string
default: ''
description: Token used to prove data stored is persistent
59 changes: 59 additions & 0 deletions testcharms/charms/dummy-storage-mp/hooks/config-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -x

juju-log -l INFO "Getting file fs token details."
status-set maintenance "Getting file fs token details." || true

function set_token() {
token_name=$1 # i.e. data-token
fs_path=$2 # i.e. /srv/data/

token="$(config-get $token_name)"
token_file="$fs_path/token"

juju-log -l INFO "Token file: $token_file"

if [ -f $token_file ]; then
juju-log -l INFO "Using stored token details."

# If we have a token and we have a token file, check the contents if the differ update it otherwise use it.
current_file_token=$(cat $token_file | grep "$token_name" | head -1 | cut -d":" -f2)
if [ "$current_file_token" != "$token" ]; then
token=$token
else
token=$(cat $token_file)
fi
fi

if [[ -z $token ]]; then
fs_token="not set"
juju-log -l WARNING "$fs_token"
else
fs_token="$token"
echo "$token" > $token_file
juju-log -l INFO "$fs_token"
fi

# Return the token value.
echo "$fs_token"
}

# Clear any previous tokens or state.
echo > /tmp/status

# First the single token
data_token=$(set_token "data-token" "/srv/data")

juju-log -l INFO "Setting single token details."
echo "data-token:$data_token" >> /tmp/status

## Then the multi-fs token
#for unit in $(storage-list multi-fs); do
# fs_path=$(storage-get -s $unit | grep "^location:\ " | cut -d: -f2 | tr -d ' ')
# multi_fs_token=$(set_token "multi-fs-token" "$fs_path")
# juju-log -l INFO "Setting multi token details."
# unit_token_number=$(echo $unit | cut -f2 -d"/")
# echo "multi-fs-token/$unit_token_number:$multi_fs_token" >> /tmp/status
#done

status-set active "Stored token: /tmp/status" || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x

juju-log -l INFO "Storage is attached."
juju-log -l INFO "Storage details: $(storage-list)"

status-set active "Started" || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x

juju-log -l INFO "Storage is attached."
juju-log -l INFO "Storage details: $(storage-list)"

status-set active "Started" || true
Empty file.
16 changes: 16 additions & 0 deletions testcharms/charms/dummy-storage-mp/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -x

status-set maintenance "Removing sshguard" || true
sudo apt-get remove sshguard || true

juju-log -l INFO "Install"
juju-log -l INFO "Data on drive: $(cat /srv/data/test.txt)"

for unit in $(storage-list); do
juju-log -l INFO "Storage details for ${unit}: $(storage-get -s $unit)"
done

# The storage-attached hook has fired so we can write some data there now.
status-set maintenance "Installed" || true
5 changes: 5 additions & 0 deletions testcharms/charms/dummy-storage-mp/hooks/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -x

juju-log -l INFO "Starting, checking what storage we have."
juju-log -l INFO "Storage details: $(storage-list)"
29 changes: 29 additions & 0 deletions testcharms/charms/dummy-storage-mp/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: dummy-storage-mp
maintainer:
- Christopher Lee <chris.lee@canonical.com>
- Burton Swan <burton.swan@canonical.com>
- Evanson Mwangi <evanson.wainaina@canonical.com>
summary: Dummy charm that utilises storage.
description: This dummy-storage-fs charm is used for testing charm storage.
categories:
- misc
series:
- trusty
- xenial
- artful
- bionic
- eoan
- focal
- jammy

storage:
data:
type: filesystem
description: junk storage
minimum-size: 100M
location: /srv/data
disks:
type: block
multiple:
range: 0-10

6 changes: 6 additions & 0 deletions testcharms/charms/dummy-storage-np/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options:
# Will be tokens for each storage type.
data-token:
type: string
default: ''
description: Token used to prove data stored is persistent

0 comments on commit 57a8b9a

Please sign in to comment.