Merge lp:~jsing/juju-deployer/resources-support into lp:juju-deployer

Proposed by Joel Sing
Status: Merged
Merged at revision: 209
Proposed branch: lp:~jsing/juju-deployer/resources-support
Merge into: lp:juju-deployer
Diff against target: 197 lines (+71/-11)
8 files modified
deployer/action/importer.py (+1/-0)
deployer/env/base.py (+9/-2)
deployer/service.py (+4/-0)
deployer/tests/test_data/wiki-resources.yaml (+14/-0)
deployer/tests/test_guiserver.py (+3/-3)
deployer/tests/test_importer.py (+26/-4)
deployer/tests/test_service.py (+2/-0)
doc/config.rst (+12/-2)
To merge this branch: bzr merge lp:~jsing/juju-deployer/resources-support
Reviewer Review Type Date Requested Status
Tim Van Steenburgh (community) Approve
Review via email: mp+316538@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

This LGTM but I hit one error in the tests:

======================================================================
ERROR: test_importer_with_resources (deployer.tests.test_importer.ImporterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tvansteenburgh/src/juju-deployer/.tox/py35/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/tvansteenburgh/src/juju-deployer/deployer/tests/test_importer.py", line 74, in test_importer_with_resources
    os.path.join(self.test_data_dir, 'wiki-resources.yaml')])
  File "/home/tvansteenburgh/src/juju-deployer/deployer/config.py", line 34, in __init__
    self.load()
  File "/home/tvansteenburgh/src/juju-deployer/deployer/config.py", line 92, in load
    for fp in self._resolve_included():
  File "/home/tvansteenburgh/src/juju-deployer/deployer/config.py", line 141, in _resolve_included
    [files.extend(self._includes(cf)) for cf in self.config_files]
  File "/home/tvansteenburgh/src/juju-deployer/deployer/config.py", line 141, in <listcomp>
    [files.extend(self._includes(cf)) for cf in self.config_files]
  File "/home/tvansteenburgh/src/juju-deployer/deployer/config.py", line 123, in _includes
    d = self._yaml_load(config_file)
  File "/home/tvansteenburgh/src/juju-deployer/deployer/config.py", line 51, in _yaml_load
    with open(config_file) as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/home/tvansteenburgh/src/juju-deployer/deployer/tests/test_data/wiki-resources.yaml'

Is there a wiki-resources.yaml file that didn't get included in the commit?

review: Needs Fixing
209. By Joel Sing

[jsing] Add support for deploying resources with juju.

Revision history for this message
Joel Sing (jsing) wrote :

Yup, appears to have been a bzr add fail... fixed.

PTAL

Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

Thanks, LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'deployer/action/importer.py'
--- deployer/action/importer.py 2016-12-22 22:25:54 +0000
+++ deployer/action/importer.py 2017-03-01 03:31:40 +0000
@@ -201,6 +201,7 @@
201 charm.repo_path or self.deployment.repo_path,201 charm.repo_path or self.deployment.repo_path,
202 svc.config,202 svc.config,
203 svc.constraints,203 svc.constraints,
204 svc.resources,
204 svc.storage,205 svc.storage,
205 num_units,206 num_units,
206 placement.get(0),207 placement.get(0),
207208
=== modified file 'deployer/env/base.py'
--- deployer/env/base.py 2016-12-24 14:25:49 +0000
+++ deployer/env/base.py 2017-03-01 03:31:40 +0000
@@ -68,8 +68,8 @@
68 self.get_cli_status()68 self.get_cli_status()
69 self.log.info(" Bootstrap complete")69 self.log.info(" Bootstrap complete")
7070
71 def deploy(self, name, charm_url, repo=None, config=None,71 def deploy(self, name, charm_url, repo=None, config=None, constraints=None,
72 constraints=None, storage=None, num_units=1, force_machine=None,72 resources=None, storage=None, num_units=1, force_machine=None,
73 series=None):73 series=None):
74 params = self._named_env(["juju", "deploy"])74 params = self._named_env(["juju", "deploy"])
75 with temp_file() as fh:75 with temp_file() as fh:
@@ -85,6 +85,13 @@
85 '{}={}'.format(k, v) for k, v in constraints.items()85 '{}={}'.format(k, v) for k, v in constraints.items()
86 ])86 ])
87 params.extend(['--constraints', constraints])87 params.extend(['--constraints', constraints])
88 if resources:
89 if not isinstance(resources, dict):
90 raise DeploymentError(
91 "resources must be specified as a dictionary")
92 for key, value in resources.items():
93 params.append("--resource")
94 params.append("{}={}".format(key, value))
88 if storage:95 if storage:
89 if not isinstance(storage, dict):96 if not isinstance(storage, dict):
90 raise DeploymentError(97 raise DeploymentError(
9198
=== modified file 'deployer/service.py'
--- deployer/service.py 2016-12-22 22:25:54 +0000
+++ deployer/service.py 2017-03-01 03:31:40 +0000
@@ -55,6 +55,10 @@
55 return int(self.svc_data.get('num_units', 1))55 return int(self.svc_data.get('num_units', 1))
5656
57 @property57 @property
58 def resources(self):
59 return self.svc_data.get('resources', None)
60
61 @property
58 def storage(self):62 def storage(self):
59 return self.svc_data.get('storage', None)63 return self.svc_data.get('storage', None)
6064
6165
=== added file 'deployer/tests/test_data/wiki-resources.yaml'
--- deployer/tests/test_data/wiki-resources.yaml 1970-01-01 00:00:00 +0000
+++ deployer/tests/test_data/wiki-resources.yaml 2017-03-01 03:31:40 +0000
@@ -0,0 +1,14 @@
1wiki:
2 series: precise
3 services:
4 wiki:
5 charm: cs:precise/mediawiki
6 options:
7 name: $hi_world _are_you_there? {guess_who}
8 resources:
9 config: ./docs/cfg.xml
10 tarball: /some/file.tgz
11 db:
12 charm: cs:precise/mysql
13 relations:
14 - [wiki, db]
015
=== modified file 'deployer/tests/test_guiserver.py'
--- deployer/tests/test_guiserver.py 2016-12-22 22:52:22 +0000
+++ deployer/tests/test_guiserver.py 2017-03-01 03:31:40 +0000
@@ -283,14 +283,14 @@
283 mock.call.status(),283 mock.call.status(),
284 mock.call.deploy(284 mock.call.deploy(
285 'mysql', 'cs:precise/mysql-28', '', None,285 'mysql', 'cs:precise/mysql-28', '', None,
286 {'arch': 'i386', 'cpu-cores': 4, 'mem': '4G'}, None, 2, None,286 {'arch': 'i386', 'cpu-cores': 4, 'mem': '4G'},
287 'precise'),287 None, None, 2, None, 'precise'),
288 mock.call.set_annotation(288 mock.call.set_annotation(
289 'mysql', {'gui-y': '164.547', 'gui-x': '494.347'}),289 'mysql', {'gui-y': '164.547', 'gui-x': '494.347'}),
290 mock.call.deploy(290 mock.call.deploy(
291 'wordpress', 'cs:precise/wordpress-20', '',291 'wordpress', 'cs:precise/wordpress-20', '',
292 {'debug': 'no', 'engine': 'nginx', 'tuning': 'single'},292 {'debug': 'no', 'engine': 'nginx', 'tuning': 'single'},
293 None, None, 1, None, 'precise'),293 None, None, None, 1, None, 'precise'),
294 mock.call.set_annotation(294 mock.call.set_annotation(
295 'wordpress', {'gui-y': '414.547', 'gui-x': '425.347'}),295 'wordpress', {'gui-y': '414.547', 'gui-x': '425.347'}),
296 mock.call.add_units('mysql', 2),296 mock.call.add_units('mysql', 2),
297297
=== modified file 'deployer/tests/test_importer.py'
--- deployer/tests/test_importer.py 2016-12-24 14:25:49 +0000
+++ deployer/tests/test_importer.py 2017-03-01 03:31:40 +0000
@@ -63,9 +63,31 @@
63 env.method_calls[3], mock.call.deploy(63 env.method_calls[3], mock.call.deploy(
64 'wiki', 'cs:precise/mediawiki',64 'wiki', 'cs:precise/mediawiki',
65 os.environ.get("JUJU_REPOSITORY", ""),65 os.environ.get("JUJU_REPOSITORY", ""),
66 config, None, None, 1, None, 'precise'))66 config, None, None, None, 1, None, 'precise'))
67 env.add_relation.assert_called_once_with('wiki', 'db')67 env.add_relation.assert_called_once_with('wiki', 'db')
6868
69 @skip_if_offline
70 @mock.patch('deployer.action.importer.time')
71 def test_importer_with_resources(self, mock_time):
72 mock_time.time.return_value = 0
73 stack = ConfigStack([
74 os.path.join(self.test_data_dir, 'wiki-resources.yaml')])
75 deploy = stack.get('wiki')
76 env = mock.MagicMock()
77 importer = Importer(env, deploy, self.options)
78 importer.run()
79
80 config = {'name': '$hi_world _are_you_there? {guess_who}'}
81 self.assertEqual(
82 env.method_calls[3], mock.call.deploy(
83 'wiki', 'cs:precise/mediawiki',
84 os.environ.get("JUJU_REPOSITORY", ""),
85 config, None,
86 {"config": "./docs/cfg.xml", "tarball": "/some/file.tgz"},
87 None, 1, None, 'precise'))
88 env.add_relation.assert_called_once_with('wiki', 'db')
89
90 @skip_if_offline
69 @skip_if_offline91 @skip_if_offline
70 @mock.patch('deployer.action.importer.time')92 @mock.patch('deployer.action.importer.time')
71 def test_importer_with_storage(self, mock_time):93 def test_importer_with_storage(self, mock_time):
@@ -82,7 +104,7 @@
82 env.method_calls[3], mock.call.deploy(104 env.method_calls[3], mock.call.deploy(
83 'wiki', 'cs:precise/mediawiki',105 'wiki', 'cs:precise/mediawiki',
84 os.environ.get("JUJU_REPOSITORY", ""),106 os.environ.get("JUJU_REPOSITORY", ""),
85 config, None, {"web-data": "cinder,10G,1"},107 config, None, None, {"web-data": "cinder,10G,1"},
86 1, None, 'precise'))108 1, None, 'precise'))
87 env.add_relation.assert_called_once_with('wiki', 'db')109 env.add_relation.assert_called_once_with('wiki', 'db')
88110
89111
=== modified file 'deployer/tests/test_service.py'
--- deployer/tests/test_service.py 2016-12-22 22:25:54 +0000
+++ deployer/tests/test_service.py 2017-03-01 03:31:40 +0000
@@ -21,6 +21,7 @@
21 'constraints': "instance-type=m1.small",21 'constraints': "instance-type=m1.small",
22 'options': {"services": "include-file://stack-include.yaml"},22 'options': {"services": "include-file://stack-include.yaml"},
23 'num_units': 10,23 'num_units': 10,
24 'resources': {"config": "./docs/cfg.xml"},
24 'storage': {"data": "ebs,10G,1"}}25 'storage': {"data": "ebs,10G,1"}}
25 s = Service('db', data)26 s = Service('db', data)
26 self.assertEquals(s.num_units, 10)27 self.assertEquals(s.num_units, 10)
@@ -28,4 +29,5 @@
28 self.assertEquals(29 self.assertEquals(
29 s.config,30 s.config,
30 {"services": "include-file://stack-include.yaml"})31 {"services": "include-file://stack-include.yaml"})
32 self.assertEquals(s.resources, {"config": "./docs/cfg.xml"})
31 self.assertEquals(s.storage, {"data": "ebs,10G,1"})33 self.assertEquals(s.storage, {"data": "ebs,10G,1"})
3234
=== modified file 'doc/config.rst'
--- doc/config.rst 2016-12-23 16:54:49 +0000
+++ doc/config.rst 2017-03-01 03:31:40 +0000
@@ -36,6 +36,8 @@
36 tuning: optimized36 tuning: optimized
37 engine: apache37 engine: apache
38 icon: include-base64://file.ico38 icon: include-base64://file.ico
39 resources:
40 config: ./doc/cfg.xml
39 storage:41 storage:
40 data-block: "ebs,1024G,3"42 data-block: "ebs,1024G,3"
41 43
@@ -54,12 +56,20 @@
54include-base64://path-to-file. Relative paths are resolved56include-base64://path-to-file. Relative paths are resolved
55relative to the config file.57relative to the config file.
5658
59Service resources are specified as a dictionary with keys as the label
60and the value being the path of the file containing the resource that
61is to be be passed to Juju. This matches the Juju cli syntax,
62`juju deploy <charm> --resource <label>=<file>`. NOTE: resources
63status is not displayed in the diff command as it is not in the Juju
64status data. For this same reason resources are only specified for new
65services and are not added to already existing services.
66
57Service storage is specified as a dictionary with keys as the label67Service storage is specified as a dictionary with keys as the label
58and the value being the pool,size,count string that should be passed68and the value being the pool,size,count string that is to be passed
59to Juju. This matches the Juju cli syntax,69to Juju. This matches the Juju cli syntax,
60`juju deploy <charm> --storage <label>=<pool>,<size>,<count>`. Also70`juju deploy <charm> --storage <label>=<pool>,<size>,<count>`. Also
61like the cli, size and count are optional parameters. NOTE: storage71like the cli, size and count are optional parameters. NOTE: storage
62status is not displayed in the diff command as isn't in the the Juju72status is not displayed in the diff command as it is not in the Juju
63status data. For this same reason storage is only specified for new73status data. For this same reason storage is only specified for new
64services and is not added to already existing services.74services and is not added to already existing services.
6575

Subscribers

People subscribed via source and target branches