def copy_file(tpl_file, charm_dir, is_bundle=False, debug=False): c = Charm(charm_dir) if not c.is_charm(): raise Exception('%s is not a charm' % charm_dir) shutil.copy(os.path.join(CHARM_TPL, tpl_file), charm_dir)
def tests(charm_dir, is_bundle=False, debug=False, series='trusty'): c = Charm(charm_dir) if not c.is_charm(): raise Exception('Not a Charm') mdata = c.metadata() interfaces = {} deploy = [mdata['name']] relations = [] for rel_type in ['provides', 'requires']: if rel_type in mdata: interfaces[rel_type] = {} for rel, data in mdata[rel_type].items(): iface = data['interface'] if iface and iface not in interfaces[rel_type]: r = graph(iface, rel_type, series=series) # If we dont find an interface, do nothing if r is None: continue interfaces[rel_type][iface] = r deploy.append(r.name) relations.append(['%s:%s' % (mdata['name'], rel), r.name]) t = Template(file=os.path.join(TPL_DIR, 'tests', '99-autogen.tpl'), searchList=[{'deploy': deploy, 'relate': relations, 'series': series}]) if not os.path.exists(os.path.join(charm_dir, 'tests')): os.mkdir(os.path.join(charm_dir, 'tests')) with open(os.path.join(charm_dir, 'tests', '99-autogen'), 'w') as f: f.write(str(t)) if not os.path.exists(os.path.join(charm_dir, 'tests', '00-setup')): with open(os.path.join(charm_dir, 'tests', '00-setup'), 'w') as f: f.write("""#!/bin/bash sudo add-apt-repository ppa:juju/stable -y sudo apt-get update sudo apt-get install amulet python3-requests -y """) os.chmod(os.path.join(charm_dir, 'tests', '99-autogen'), 0o755) os.chmod(os.path.join(charm_dir, 'tests', '00-setup'), 0o755)