Merge lp:~hduran-8/juju-ci-tools/add_storage_ci_tests into lp:juju-ci-tools

Proposed by Horacio Durán
Status: Work in progress
Proposed branch: lp:~hduran-8/juju-ci-tools/add_storage_ci_tests
Merge into: lp:juju-ci-tools
Prerequisite: lp:~hduran-8/juju-ci-tools/add_status_ci_tests
Diff against target: 184 lines (+175/-0)
2 files modified
assess_storage.py (+106/-0)
test_assess_storage.py (+69/-0)
To merge this branch: bzr merge lp:~hduran-8/juju-ci-tools/add_storage_ci_tests
Reviewer Review Type Date Requested Status
Juju Release Engineering Pending
Review via email: mp+262870@code.launchpad.net

Description of the change

Add storage CI tests.

Tests for Storage, they deploy the storagetest charm and then check that rootfs storage is mounted (by checking existence of the file storagetest writes upon attachment) and, if the strate is supported it also tests that platform specific storage has been attached.

To post a comment you must log in.
984. By Horacio Durán

Fixed typo in storage test

985. By Horacio Durán

Merged changes from status branch.

986. By Horacio Durán

Merged the tests with trunk

Unmerged revisions

986. By Horacio Durán

Merged the tests with trunk

985. By Horacio Durán

Merged changes from status branch.

984. By Horacio Durán

Fixed typo in storage test

983. By Horacio Durán

Corrected lint issues

982. By Horacio Durán

Added tests for storage

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'assess_storage.py'
2--- assess_storage.py 1970-01-01 00:00:00 +0000
3+++ assess_storage.py 2015-07-23 23:59:06 +0000
4@@ -0,0 +1,106 @@
5+#!/usr/bin/python
6+from __future__ import print_function
7+
8+__metaclass__ = type
9+
10+from os import remove as osremove
11+from os.path import (
12+ join as pjoin,
13+ isdir as pisdir,
14+ isfile as pisfile
15+)
16+from shutil import rmtree
17+from tempfile import mkdtemp
18+
19+from argparse import ArgumentParser
20+from utility import add_basic_testing_arguments
21+from jujupy import (
22+ make_client,
23+)
24+from utility import (
25+ print_now,
26+)
27+from deploy_stack import (
28+ boot_context,
29+ prepare_environment,
30+)
31+
32+
33+def parse_args():
34+ """Parse all arguments."""
35+ parser = ArgumentParser('Test storage attachment')
36+ add_basic_testing_arguments(parser)
37+ return parser.parse_args()
38+
39+
40+def main():
41+ args = parse_args()
42+ log_dir = args.logs
43+
44+ client = make_client(
45+ args.juju_path, args.debug, args.env, args.temp_env_name)
46+ # a list of folders to be cleaned up
47+ to_delete = []
48+
49+ series = args.series
50+ if series is None:
51+ series = 'precise'
52+ with boot_context(args.job_name, client, args.bootstrap_host,
53+ args.machine, series, args.agent_url, args.agent_stream,
54+ log_dir, args.keep_env, args.upload_tools):
55+ prepare_environment(
56+ client, already_bootstrapped=True, machines=args.machine)
57+
58+ client.get_status(60)
59+ env_type = client.env.config['type']
60+ if env_type == "ec2":
61+ client.juju("deploy", ('local:trusty/storagetest',
62+ '--storage', 'testnativefs=ebs,1G'))
63+ elif env_type == "maas":
64+ client.juju("deploy", ('local:trusty/storagetest',
65+ '--storage', 'testnativefs=maas,1G'))
66+ elif env_type == "openstack":
67+ client.juju("deploy", ('local:trusty/storagetest',
68+ '--storage', 'testnativefs=cinder,1G'))
69+ else:
70+ print_now("there is no native storage for this substrate")
71+
72+ # Wait for the deployment to finish.
73+ client.wait_for_started()
74+
75+ # At this point you have a juju bootstraped with a wordpress charm
76+ # deployed and active with the agent idle.
77+ test_storage(to_delete, client, "/mnt/testrootfs")
78+ if env_type in ("ec2", "maas", "openstack"):
79+ test_storage(to_delete, client, "/mnt/testnativefs")
80+
81+ for deletable in to_delete:
82+ try:
83+ if pisdir(deletable):
84+ rmtree(deletable)
85+ elif pisfile(deletable):
86+ osremove(deletable)
87+ else:
88+ raise Exception("Is not a file or directory")
89+ except Exception, e:
90+ print_now("cannot delete %s: %s" % [deletable, e])
91+
92+PROOF = "This text is the proof that storage-attached hook ran with"\
93+ " filesystem storage"
94+
95+
96+def test_storage(to_delete, client, mountpoint):
97+ tdir = mkdtemp()
98+ to_delete.append(tdir)
99+ client.juju("scp", ("--",
100+ "storagetest/0:%s/proof.txt" % mountpoint,
101+ tdir))
102+ with open(pjoin(tdir, "proof.txt"), "r") as proof:
103+ lines = proof.readlines()
104+ assert len(lines) == 1, "the proof file should have 1 line only"
105+ line = lines[0]
106+ assert line == PROOF, "The text is not the expected: %s" % line
107+
108+
109+if __name__ == '__main__':
110+ main()
111
112=== added file 'test_assess_storage.py'
113--- test_assess_storage.py 1970-01-01 00:00:00 +0000
114+++ test_assess_storage.py 2015-07-23 23:59:06 +0000
115@@ -0,0 +1,69 @@
116+__metaclass__ = type
117+
118+from os.path import (
119+ join as pjoin,
120+ isdir as pisdir,
121+ isfile as pisfile
122+)
123+
124+from os import remove as osremove
125+from shutil import rmtree, copy
126+from tempfile import mkdtemp
127+
128+from assess_storage import (
129+ PROOF,
130+ test_storage
131+)
132+
133+from unittest import TestCase
134+
135+
136+class FakeClient:
137+ def __init__(self, check=lambda x, y: None):
138+ self.command = ""
139+ self.command_args = ""
140+ self.check = check
141+
142+ def juju(self, command, command_args):
143+ self.command = command
144+ self.command_args = command_args
145+ self.check(command, command_args)
146+
147+
148+class TestStorageTester(TestCase):
149+
150+ def test_proof_is_there(self):
151+ to_delete = []
152+ try:
153+ tdir = mkdtemp()
154+ pfile = pjoin(tdir, "proof.txt")
155+
156+ with open(pfile, "w") as proof:
157+ proof.write(PROOF)
158+
159+ def check_scp(command, command_args):
160+ self.assertEqual(command, "scp")
161+ self.assertEqual(len(command_args), 3)
162+ self.assertEqual(command_args[0], "--")
163+ self.assertIn("/a/mount/point/proof.txt", command_args[1])
164+ self.assertTrue(pisdir(command_args[2]))
165+ copy(pfile, command_args[2])
166+ client = FakeClient(check_scp)
167+ test_storage(to_delete, client, "/a/mount/point")
168+ self.assertTrue(len(to_delete) == 1)
169+ self.assertTrue(pisdir(to_delete[0]))
170+ self.assertTrue(pisfile(pjoin(to_delete[0], "proof.txt")))
171+ except Exception, e:
172+ raise e
173+ finally:
174+ rmtree(mkdtemp())
175+ for deletable in to_delete:
176+ try:
177+ if pisdir(deletable):
178+ rmtree(deletable)
179+ elif pisfile(deletable):
180+ osremove(deletable)
181+ else:
182+ raise Exception("Is not a file or directory")
183+ except Exception, e:
184+ print("cannot delete %s: %s" % [deletable, e])

Subscribers

People subscribed via source and target branches