Skip to content

Commit

Permalink
Addresses minor issues related to PR #274: (#276)
Browse files Browse the repository at this point in the history
- Eliminated unnecessary directory walk in init_template()
Other:
- Fixed bug in validate_template(), i.e., dereferencing non-existent
  'id' member when cluster_template_d field is undefined
- Clarification of 'devices' file usage in templates/README.md
  • Loading branch information
keith-ratcliffe authored and ctubbsii committed Aug 27, 2019
1 parent 496d73f commit 4f1a4ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
3 changes: 2 additions & 1 deletion conf/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ automatically by simply adding them to the **ec2** section of

The *devices* file contains the user-defined mapping of storage
devices and mount points for all data (i.e., non-root) volumes in your
cluster.
cluster. Muchos Ansible scripts leverage this information to prepare
all data volumes during the cluster `setup` phase.

Two (and only two) device mappings should exist within *devices*:
* One map to represent your **worker** device mounts, and
Expand Down
2 changes: 1 addition & 1 deletion conf/templates/user/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*
*
25 changes: 9 additions & 16 deletions lib/muchos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,14 @@ def print_property(self, key):
exit("Property '{0}' was not found".format(key))

def init_template(self, templates_path):
if not self.has_option('ec2', 'cluster_template'):
return

template_id = self.get('ec2', 'cluster_template')
for root, dirs, files in os.walk(templates_path):
for dir_name in dirs:
if dir_name == template_id:
self.cluster_template_d = {'id': template_id}
template_dir = os.path.join(root, dir_name)
self.load_template_ec2_requests(template_dir)
self.load_template_device_map(template_dir)
break
break

self.validate_template()
if self.has_option('ec2', 'cluster_template'):
template_id = self.get('ec2', 'cluster_template')
template_path = os.path.join(templates_path, template_id)
if os.path.exists(template_path):
self.cluster_template_d = {'id': template_id}
self.load_template_ec2_requests(template_path)
self.load_template_device_map(template_path)
self.validate_template()

def load_template_ec2_requests(self, template_dir):
for json_path in glob.glob(os.path.join(template_dir, '*.json')):
Expand All @@ -374,7 +367,7 @@ def load_template_device_map(self, template_dir):

def validate_template(self):
if not self.cluster_template_d:
exit("ERROR - Template '{0}' is not defined!".format(self.cluster_template_d['id']))
exit("ERROR - Template '{0}' is not defined!".format(self.get('ec2', 'cluster_template')))

if 'worker' not in self.cluster_template_d:
exit("ERROR - '{0}' template config is invalid. No 'worker' launch request is defined".format(
Expand Down

0 comments on commit 4f1a4ae

Please sign in to comment.