def test_teflo_load_from_yaml_05(): data = list() data.append(template_render('../assets/correct_include_descriptor.yml', os.environ)) data.append(template_render('../assets/common.yml', os.environ)) teflo = Teflo(data_folder='/tmp') teflo.load_from_yaml(data) assert teflo.scenario.child_scenarios
def notify(self): """ Implementation of the notify method for generating the notification and sending it to the webhook :return: """ if not self.body and not self.body_tmpl: if getattr(self.notification, 'on_start'): self.logger.info("Using teflo's onstart webhook template") self.body = template_render(os.path.abspath(os.path.join(os.path.dirname(__file__), self.onstart_temp)), generate_default_template_vars(self.scenario, self.notification)) else: self.logger.info("Using teflo's generic webhook template") self.body = template_render(os.path.abspath(os.path.join(os.path.dirname(__file__), self.default_cbn_template)), generate_default_template_vars(self.scenario, self.notification)) elif not self.body and self.body_tmpl: self.logger.info('Using user provided webhook template') # this var_dict consists of scenario object and scenario_vars which are all the variables # used by teflo along with environment variables var_dict = generate_default_template_vars(self.scenario, self.notification) self.body = template_render(os.path.abspath(os.path.join(getattr(self.notification, 'workspace'), self.body_tmpl)), var_dict) elif self.body and not self.body_tmpl: self.logger.debug("Only message body is provided without any template") self.body = str({'text': self.body}) if self.url: self.logger.info('Sending notification using %s' % self.__plugin_name__) self.send_message() else: raise TefloNotifierError('No url was set for the Webhook Notifier in the teflo.cfg.')
def test_teflo_load_from_yaml_04(): data = list() data.append(template_render('../assets/descriptor.yml', os.environ)) teflo = Teflo(data_folder='/tmp') teflo.load_from_yaml(data)
def test_teflo_load_from_yaml_03(): data = list() data.append(template_render('../assets/descriptor.yml', os.environ)) teflo = Teflo(data_folder='/tmp') teflo.config['CREDENTIALS'] = [{'name': 'provider'}] teflo.load_from_yaml(data)
def _build_pinfile(cls, asset_name, workspace, resource_grp, pindict): # check for template data temp_data = {} temp_data.update(os.environ) if 'template_data' in resource_grp and resource_grp.get( 'template_data', False): td = resource_grp.pop('template_data') if 'file' in td: temp_data.update( file_mgmt( 'r', os.path.abspath(os.path.join(workspace, td.get('file'))))) if 'vars' in td: temp_data.update(td.get('vars')) if 'pinfile' in resource_grp and resource_grp.get('pinfile', False): topo_path = os.path.abspath( os.path.join(workspace, resource_grp.get('pinfile').get('path'))) targets = resource_grp.get('pinfile').get('targets', []) pindata = yaml.safe_load(template_render(topo_path, temp_data)) for target in pindata: if isinstance( pindata.get(target).get('topology'), string_types): tp = os.path.abspath( os.path.join(workspace, os.path.dirname(topo_path))) tp = os.path.join( tp, os.path.join('topologies', pindata.get(target).get('topology'))) # apply template_data tpd = yaml.safe_load(template_render(tp, temp_data)) pindata.get(target).update(topology=tpd) if pindata.get(target).get('layout', False) and isinstance( pindata.get(target).get('layout'), string_types): tp = os.path.abspath( os.path.join(workspace, os.path.dirname(topo_path))) tp = os.path.join( tp, os.path.join('layouts', pindata.get(target).get('layout'))) # apply template_data tpd = yaml.safe_load(template_render(tp, temp_data)) pindata.get(target).update(layout=tpd) if pindata.get(target).get('hooks', False) and isinstance( pindata.get(target).get('hooks'), string_types): tp = os.path.abspath( os.path.join(workspace, os.path.dirname(topo_path))) tp = os.path.join( tp, os.path.join('hooks', pindata.get(target).get('hooks'))) # apply template_data tpd = yaml.safe_load(template_render(tp, temp_data)) pindata.get(target).update(hooks=tpd) if targets: pindata = { t: v for t, v in pindata.items() if t in targets or t == 'cfgs' } return pindata if 'cfgs' in resource_grp and resource_grp.get('cfgs', False): pindict.update(cfgs=resource_grp.pop('cfgs')) if 'resource_definitions' in resource_grp and resource_grp.get( 'resource_definitions', False): count = 0 rs_count = len(resource_grp.get('resource_definitions')) for res in resource_grp.get('resource_definitions'): if not res.get('recipesets', False): # Need this since azure_vm does not use name as a key if 'azure_vm' == res.get('role', ''): if not res.get('vm_name', False) and rs_count > 1: res.update( dict(vm_name=asset_name + '_' + str(count))) count += 1 elif not res.get('vm_name', False): res.update(dict(vm_name=asset_name)) else: if not res.get('name', False) and rs_count > 1: res.update(dict(name=asset_name + '_' + str(count))) count += 1 elif not res.get('name', False): res.update(dict(name=asset_name)) else: # this logic is for bkr assets. The name key is in the recipeset dict not in res def # dict unlike the other providers. for rs in res.get('recipesets'): if not rs.get('name', False) and rs_count > 1: rs.update(dict(name=asset_name + '_' + str(count))) count += 1 elif not rs.get('name', False): rs.update(dict(name=asset_name)) resource_grp.update(dict(resource_group_name='cbn-group')) pindict['teflo']['topology'] = dict(topology_name='cbn-topo', resource_groups=[resource_grp]) if 'topology' in resource_grp and resource_grp.get('topology', False) \ and isinstance(resource_grp.get('topology'), string_types): topo_path = os.path.abspath( os.path.join(workspace, resource_grp.get('topology'))) # apply template_data pindata = yaml.safe_load(template_render(topo_path, temp_data)) pindict['teflo']['topology'] = pindata if 'layout' in resource_grp and resource_grp.get('layout', False): if isinstance(resource_grp.get('layout'), string_types): topo_path = os.path.abspath( os.path.join(workspace, resource_grp.pop('layout'))) # apply template_data pindata = yaml.safe_load(template_render(topo_path, temp_data)) pindict['teflo']['layout'] = pindata if isinstance(resource_grp.get('layout'), dict): pindict['teflo']['layout'] = resource_grp.pop('layout') else: pindict.get('teflo').pop('layout') if 'hooks' in resource_grp and resource_grp.get('hooks', False): if isinstance(resource_grp.get('hooks'), string_types): topo_path = os.path.abspath( os.path.join(workspace, resource_grp.pop('hooks'))) # apply template_data pindata = yaml.safe_load(template_render(topo_path, temp_data)) pindict['teflo']['hooks'] = pindata if isinstance(resource_grp.get('hooks'), dict): pindict['teflo']['hooks'] = resource_grp.pop('hooks') else: pindict.get('teflo').pop('hooks') return pindict