def test_deleteEmptyPackage(self, useApikey): """Tests if functions_delete_package deletes uploaded package that is empty.""" params = [ '-c', os.path.join(self.dataBasePath, 'exampleFunctionsEmpty.cfg'), '--cloudfunctions_package', self.package, '--cloudfunctions_namespace', self.namespace, '--cloudfunctions_url', self.cloudFunctionsUrl, '--cloudfunctions_package', self.package ] if useApikey: params.extend(['--cloudfunctions_apikey', self.apikey]) else: params.extend([ '--cloudfunctions_username', self.username, '--cloudfunctions_password', self.password ]) functions_deploy.main(params) self._checkPackageExists() # delete package self.t_noException([params]) self._checkPackageDeleted()
def test_wrongCloudfunctionsUrl(self, useApikey): """Tests if functions_delete_package errors while deleting with wrong cloud functions url.""" params = [ '-c', os.path.join(self.dataBasePath, 'exampleFunctions.cfg'), '--cloudfunctions_package', self.package, '--cloudfunctions_namespace', self.namespace ] if useApikey: params.extend(['--cloudfunctions_apikey', self.apikey]) else: params.extend([ '--cloudfunctions_username', self.username, '--cloudfunctions_password', self.password ]) # Correct params for deploy paramsDeploy = list(params) paramsDeploy.extend(['--cloudfunctions_url', self.cloudFunctionsUrl]) # Wrong params for delete paramsDelete = list(params) paramsDelete.extend([ '--cloudfunctions_url', self.cloudFunctionsUrl + str(uuid.uuid4()) ]) # Pass functions_deploy.main(paramsDeploy) self._checkPackageExists() # Fail self.t_exitCodeAndLogMessage( 1, "The resource could not be found. Check your cloudfunctions url and namespace.", [paramsDelete])
def test_deleteNonEmptyPackageWithSequence(self, useApikey): """Tests if functions_delete_package deletes uploaded package that is not empty and has a sequence.""" params = [ '-c', os.path.join(self.dataBasePath, 'exampleFunctions.cfg'), '--cloudfunctions_package', self.package, '--cloudfunctions_namespace', self.namespace, '--cloudfunctions_url', self.cloudFunctionsUrl ] if useApikey: params.extend(['--cloudfunctions_apikey', self.apikey]) else: params.extend([ '--cloudfunctions_username', self.username, '--cloudfunctions_password', self.password ]) functions_deploy.main(params) self._checkPackageExists() sequenceUrl = self.actionsUrl + self.package + '/testSequence' functionsDir = os.path.join(self.dataBasePath, 'example_functions') functionFileNames = [ os.path.basename(os.path.join(functionsDir, f)) for f in os.listdir(functionsDir) ] # Use fully qualified names! functionNames = [ self.namespace + '/' + self.package + '/' + os.path.splitext(fileName)[0] for fileName in functionFileNames ] payload = { 'exec': { 'kind': 'sequence', 'binary': False, 'components': functionNames } } # Connect the functions into a sequence response = requests.put(sequenceUrl, auth=(self.username, self.password), headers={'Content-Type': 'application/json'}, data=json.dumps(payload), verify=False) # Fail if sequence upload failed response.raise_for_status() # delete package self.t_noException([params]) self._checkPackageDeleted()
def test_wrongCredentials(self, useApikey): """Tests if functions_delete_package errors while deleting with wrong credentials.""" params = [ '-c', os.path.join(self.dataBasePath, 'exampleFunctions.cfg'), '--cloudfunctions_package', self.package, '--cloudfunctions_namespace', self.namespace, '--cloudfunctions_url', self.cloudFunctionsUrl ] # Correct params for deploy paramsDeploy = list(params) if useApikey: paramsDeploy.extend(['--cloudfunctions_apikey', self.apikey]) else: paramsDeploy.extend([ '--cloudfunctions_username', self.username, '--cloudfunctions_password', self.password ]) # Wrong params for delete paramsDelete = list(params) randomUsername = str(uuid.uuid4()) randomPassword = str(uuid.uuid4()) if useApikey: paramsDelete.extend([ '--cloudfunctions_apikey', randomUsername + ':' + randomPassword ]) else: paramsDelete.extend([ '--cloudfunctions_username', randomUsername, '--cloudfunctions_password', randomPassword ]) # Pass functions_deploy.main(paramsDeploy) self._checkPackageExists() # Fail self.t_exitCodeAndLogMessage( 1, "Authorization error. Check your credentials.", [paramsDelete])
def callfunc(self, *args, **kwargs): functions_deploy.main(*args, **kwargs)
def main(argv): scriptsPath=os.path.dirname(__file__) defaultParamList=['shared.cfg', 'private.cfg'] parser = argparse.ArgumentParser(description='This script executes all the steps needed for building and deployment of the WeatherFrog application.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-c', '--config', help='configuaration file', action='append') parser.add_argument('-v','--verbose', required=False, help='verbosity', action='store_true') parser.add_argument('--log', type=str.upper, default=None, choices=list(logging._levelToName.values())) args = parser.parse_args(argv) if __name__ == '__main__': setLoggerConfig(args.log, args.verbose) logger.info('STARTING: ' + os.path.basename(__file__)) logger.info('Using WAW directory: ' + os.path.dirname(__file__)) logger.verbose('THIS IS VERBOSE') #Assemble command line parameters out of parameters or defaults paramsAll = [] if hasattr(args, 'config') and args.config != None: # if config files provided - ignore defaults for strParamsItem in args.config: if os.path.isfile(strParamsItem): paramsAll += ['-c', strParamsItem] else: logger.error('Configuration file %s not found.', strParamsItem) exit(1) else: # create list of default config files for strParamsItem in defaultParamList: if os.path.isfile(strParamsItem): paramsAll += ['-c', strParamsItem] else: logger.warning('Default configuration file %s was not found, ignoring.', strParamsItem) if len(paramsAll) == 0: logger.error('Please provide at least one configuration file.') exit(1) #Execute all steps logger.verbose('python clean_generated.py '+' '.join(paramsAll)) clean_generated.main(paramsAll) logger.verbose('python dialog_xls2xml.py '+' '.join(paramsAll)) dialog_xls2xml.main(paramsAll) logger.verbose('python dialog_xml2json.py '+' '.join(paramsAll)) dialog_xml2json.main(paramsAll) logger.verbose('python entities_csv2json.py '+' '.join(paramsAll)) entities_csv2json.main(paramsAll) logger.verbose('python intents_csv2json.py '+' '.join(paramsAll)) intents_csv2json.main(paramsAll) logger.verbose('python clean_generated.py '+' '.join(paramsAll)) dialog_xml2json.main(paramsAll) logger.verbose('python workspace_compose.py '+' '.join(paramsAll)) workspace_compose.main(paramsAll) logger.verbose('python workspace_addjson.py '+' '.join(paramsAll)) workspace_addjson.main(paramsAll) logger.verbose('python workspace_deploy.py '+' '.join(paramsAll)) workspace_deploy.main(paramsAll) logger.verbose('python functions_deploy.py '+' '.join(paramsAll)) functions_deploy.main(paramsAll) logger.info('FINISHING: ' + os.path.basename(__file__))