Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add juju storage support for initial charm deploy. #169

Merged
merged 2 commits into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions amulet/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def load(self, deploy_cfg, deployment_name=None):
branch=service_config.get('branch', None),
constraints=constraints,
placement=service_config.get('to', None),
series=self.series
series=self.series,
storage=service_config.get('storage')
)

if service_config.get('options'):
Expand All @@ -169,7 +170,8 @@ def add(self, service_name,
constraints=None,
branch=None,
placement=None,
series=None):
series=None,
storage=None):
"""Add a new service to the deployment schema.

:param service_name: Name of the service to deploy.
Expand All @@ -185,6 +187,8 @@ def add(self, service_name,
"lxc:wordpress/0 - Deploy to lxc container on first wordpress unit

:param series: Series of charm to deploy, e.g. precise, trusty, xenial
:param storage: Storage configuration as a dictionary with key the
label and value being the pool,size,count string used by Juju.

Example::

Expand All @@ -193,6 +197,7 @@ def add(self, service_name,
d.add('wordpress')
d.add('second-wp', charm='wordpress')
d.add('personal-wp', charm='~marcoceppi/wordpress', units=2)
d.add('postgresql', storage={'pgdata', 'rootfs,50M'})

"""
if self.deployed:
Expand All @@ -204,6 +209,11 @@ def add(self, service_name,
service = self.services[service_name] = {}
service['series'] = series or self.series

if storage is not None:
if not isinstance(storage, dict):
raise ValueError('Storage must be specified as a dict')
service['storage'] = storage

charm = self.charm_cache.fetch(
service_name, charm, branch=branch, series=service['series'])

Expand Down
25 changes: 21 additions & 4 deletions tests/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ def test_load(self):
d = Deployment(juju_env='gojuju')
schema = '{"mybundle": {"series": "raring", "services": {"wordpress": \
{"branch": "lp:~charmers/charms/precise/wordpress/trunk", \
"expose": true}, "mysql": {"options": {"tuning": \
"fastest"}, "constraints": "mem=2G cpu-cores=2", \
"branch": "lp:~charmers/charms/precise/mysql/trunk"}}, \
"relations": [["mysql:db", "wordpress:db"]]}}'
"expose": true, "storage": {"wp-data": "rootfs,100M"}}, \
"mysql": {"options": {"tuning": "fastest"}, "constraints": \
"mem=2G cpu-cores=2", "branch": \
"lp:~charmers/charms/precise/mysql/trunk"}}, "relations": \
[["mysql:db", "wordpress:db"]]}}'
dmap = json.loads(schema)
with patch.object(d, 'add') as add:
with patch.object(d, 'configure') as configure:
Expand All @@ -63,13 +64,15 @@ def test_load(self):
call('wordpress',
placement=None,
series='raring',
storage={"wp-data": "rootfs,100M"},
units=1,
branch='lp:~charmers/charms/precise/wordpress/trunk',
constraints=None,
charm=None),
call('mysql',
placement=None,
series='raring',
storage=None,
units=1,
branch='lp:~charmers/charms/precise/mysql/trunk',
constraints={'mem': '2G', 'cpu-cores': '2'},
Expand Down Expand Up @@ -157,6 +160,20 @@ def test_add_constraints(self, mcharm):
'cpu-power=0 cpu-cores=4 mem=512M',
'num_units': 2}}, d.services)

@patch('amulet.charm.CharmCache.get_charm')
def test_add_storage(self, mcharm):
charm = mcharm.return_value
charm.subordinate = False
charm.code_source = {'location': 'lp:charms/charm'}
charm.url = None

d = Deployment(juju_env='gojuju')
d.add('charm', storage={"mystorage": "ebs,10g,1"})
self.assertEqual({'charm': {'branch': 'lp:charms/charm',
'num_units': 1,
'series': 'precise',
'storage': {"mystorage": "ebs,10g,1"}}}, d.services)

def _make_mock_status(self, d):
def _mock_status(juju_env):
status = dict(services={}, machines={})
Expand Down