Skip to content

Commit

Permalink
fixed resource_group_name conflict in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
samvarankashyap committed Aug 29, 2016
1 parent 43226a8 commit 6b72cb4
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions library/schema_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
author: Samvaran Kashyap Rallabandi -
'''


from ansible.module_utils.basic import *
import datetime
import sys
Expand Down Expand Up @@ -78,19 +77,41 @@ def check_file_paths(module, *args):
if os.path.isdir(file_path):
module.fail_json(msg= "Recursive directory not supported %s " % (file_path))

def validate_grp_names(data):
res_grps = data['resource_groups']
res_grp_vars = data['resource_group_vars']
res_grp_names = [ x['resource_group_name'] for x in res_grps ]
res_grp_vars = [ x['resource_group_name'] for x in res_grp_vars ]
dup_grp_names = set([res_grp_names[i] for i in range(0,len(res_grp_names)) if res_grp_names[i]>1])
dup_grp_vars = set([res_grp_vars[i] for i in range(0,len(res_grp_vars)) if res_grp_vars[i]>1])
if len(dup_grp_vars) != 0 or len(dup_grp_names) != 0 :
return {"msg":"error: duplicate names found in resource_group_name attributes please check the results for duplicate names", "result":str(dup_grp_names)+str(dup_grp_vars)}
else:
return True

def validate_values(module,data_file_path):
data = open(data_file_path).read()
data = yaml.safe_load(data)
status = validate_grp_names(data)
if status != True:
module.fail_json(msg= "%s" % (json.dumps(status)))
else:
return status

def main():
module = AnsibleModule(
argument_spec={
'data': {'required': True, 'aliases': ['topology_file']},
'schema': {'required': True, 'aliases': ['topology_file']},
'data_format': {'required': False,'choices':['json','yaml','yml']},
'data': {'required': True, 'aliases': ['topology_file']},
'schema': {'required': True, 'aliases': ['topology_file']},
'data_format': {'required': False,'choices':['json','yaml','yml']},
},
required_one_of=[],
supports_check_mode=True
)
data_file_path = os.path.expanduser(module.params['data'])
schema_file_path = os.path.expanduser(module.params['schema'])
check_file_paths(module, data_file_path, schema_file_path)
validate_values(module,data_file_path)
schema_obj = JSONSchema(data_file_path, schema_file_path)
output = schema_obj.validate()
resp = {"path": data_file_path, "content":output}
Expand Down

0 comments on commit 6b72cb4

Please sign in to comment.