class JiraSession(object): def __init__(self, server, account, password): self.server = server self.account = account self.password = password self.jira_session = JIRA(server=self.server, basic_auth=(self.account, self.password)) def __enter__(self): assert self.jira_session.current_user() == self.account return self def __exit__(self, exc_type, exc_val, exc_tb): self.jira_session.close() def search_issues(self, jql): """ Search issues via JQL :param jql: :return: """ logging.info(u'JIRA Search: %s' % jql) return self.jira_session.search_issues(jql_str=jql, maxResults=128, json_result=True) def get_projects(self): """ Get jira projects :return: <key, name, id> """ logging.info(u'Get JIRA Projects') return self.jira_session.projects() def get_issue_types(self): """ Get jira issue types :return: <name, id> """ logging.info(u'Get JIRA Issue Types') return self.jira_session.issue_types() def get_issue_statuses(self): """ Get issue statuses :return: <name, id> """ logging.info(u'Get JIRA Issue Statuses') return self.jira_session.statuses() def get_user(self): """ Get jira user :return: """ logging.info(u'Get JIRA Current User') return self.jira_session.current_user()
class Query_Jira(): def __init__(self): # 初始化用户密码 self.jira = JIRA(server='https://×××.×××.com', basic_auth=('××××××', '××××××')) print('当前登录用户:', self.jira.user(self.jira.current_user())) # 按人员查询待办事项 def query_issue_by_person(self, name): # 待办任务 jql1 = 'project = IDEASDK AND assignee = ' + name + ' AND status in ("To Do","In Progress") AND createdDate > "2020/07/01" ORDER BY created DESC, priority DESC, updated DESC' issues1 = self.jira.search_issues(jql1) # 待确认任务 jql2 = 'project = IDEASDK AND reporter =' + name + ' AND status = Resolved AND createdDate > "2020/07/01" ORDER BY created DESC, priority DESC, updated DESC' issue2 = self.jira.search_issues(jql2) issues = issues1 + issue2 return issues def query_issue_pending(self): jql = 'project = IDEASDK AND status = pending AND createdDate > "2020/07/01" ORDER BY created DESC, updated ASC, status DESC, priority DESC' pending_issues = self.jira.search_issues(jql) return pending_issues
class JIRAClient(object): # pylint:disable=too-few-public-methods """A client for JIRA API.""" _ISSUE_JQL = 'project = {project_key} AND updated >= "{0}" ORDER BY key ASC' """JQL query format for listing all issues with worklogs to read.""" def __init__(self, config): # type: (dict) -> None """Initialize with credentials from the *config* dict.""" self._login = config['login'] self._jira = JIRA(config['url'], basic_auth=(config['email'], config['jira_token'])) user = self._jira.current_user() if self._login != user: raise click.ClickException( 'Logged in as {} but {} specified in config'.format( user, self._login)) self._project_key = config['project_key'] def _issues(self, query): # type: (str) -> Iterator[jira.Issue] """Issues iterator.""" issue_index = 1 while True: search_results = self._jira.search_issues(jql_str=query, startAt=issue_index, maxResults=50) for issue in search_results: yield issue issue_index += 51 if len(search_results) < 50: return def get_worklogs(self, from_date, username): # type: (date, Optional[str]) -> Iterator[Worklog] """ Return all recent worklogs for the specified user. :rtype: iterator :returns: yields Worklog instances """ for issue in self._issues( self._ISSUE_JQL.format(from_date, project_key=self._project_key)): for jira_worklog in self._jira.worklogs(issue): worklog = Worklog( id=int(jira_worklog.id), tempo_id=None, author=jira_worklog.author.name, time_spent_seconds=int(jira_worklog.timeSpentSeconds), issue=issue.key, started=arrow.get(jira_worklog.started), description=getattr(jira_worklog, 'comment', u''), ) if username and worklog.author != username: continue yield worklog
class JiraInit(object): @except_decorate("获取jira服务器错误,请确认能在网页中正确登录JIRA服务") def __init__(self,jurl,juser,jpasswd): self.jurl = jurl self.juser = juser self.jpasswd = jpasswd self.nowtime = datetime.datetime.now().strftime('%Y年%m月%d日') self.jr = JIRA(self.jurl,basic_auth=(self.juser,self.jpasswd)) @except_decorate("用户错误") def authuser(self): name = self.jr.current_user() logger().info(u"当前登录用户:%s" % name) # 查询项目是否存在 @except_decorate("未查询到项目") def ExistProject(self, jproject): projects = str(self.jr.projects()) if jproject in projects: logger().info("存在项目%s" % jproject) else: logger().error("不存在项目%s" % jproject) exit(2) @staticmethod def JqlProjrct(jproject): jproject_ql = "project = %s "%jproject return jproject_ql @staticmethod def JqlText(jversion): jtext_ql = "AND text ~ %s "%jversion return jtext_ql @staticmethod def JqlBugType(jbugtype): jbugtype_ql = "AND bug类型 = %s "%jbugtype return jbugtype_ql @staticmethod def JqlModel(jmodel): jmodel_ql = "AND component = %s "%jmodel return jmodel_ql #获取全部模块类型 def GetComponents(self,project): components = self.jr.project_components(project) return components
class JiraTestManager(object): """Used to instantiate and populate the JIRA instance with data used by the unit tests. Attributes: CI_JIRA_ADMIN (str): Admin user account name. CI_JIRA_USER (str): Limited user account name. max_retries (int): number of retries to perform for recoverable HTTP errors. """ # __metaclass__ = Singleton # __instance = None # # Singleton implementation # def __new__(cls, *args, **kwargs): # if not cls.__instance: # cls.__instance = super(JiraTestManager, cls).__new__( # cls, *args, **kwargs) # return cls.__instance # Implementing some kind of Singleton, to prevent test initialization # http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python/33201#33201 __shared_state = {} @retry(stop=stop_after_attempt(2)) def __init__(self): self.__dict__ = self.__shared_state if not self.__dict__: self.initialized = 0 try: if 'CI_JIRA_URL' in os.environ: self.CI_JIRA_URL = os.environ['CI_JIRA_URL'] self.max_retries = 5 else: self.CI_JIRA_URL = "https://pycontribs.atlassian.net" self.max_retries = 5 if 'CI_JIRA_ADMIN' in os.environ: self.CI_JIRA_ADMIN = os.environ['CI_JIRA_ADMIN'] else: self.CI_JIRA_ADMIN = 'ci-admin' if 'CI_JIRA_ADMIN_PASSWORD' in os.environ: self.CI_JIRA_ADMIN_PASSWORD = os.environ[ 'CI_JIRA_ADMIN_PASSWORD'] else: self.CI_JIRA_ADMIN_PASSWORD = '******' if 'CI_JIRA_USER' in os.environ: self.CI_JIRA_USER = os.environ['CI_JIRA_USER'] else: self.CI_JIRA_USER = '******' if 'CI_JIRA_USER_PASSWORD' in os.environ: self.CI_JIRA_USER_PASSWORD = os.environ[ 'CI_JIRA_USER_PASSWORD'] else: self.CI_JIRA_USER_PASSWORD = '******' self.CI_JIRA_ISSUE = os.environ.get('CI_JIRA_ISSUE', 'Bug') if OAUTH: self.jira_admin = JIRA( oauth={ 'access_token': 'hTxcwsbUQiFuFALf7KZHDaeAJIo3tLUK', 'access_token_secret': 'aNCLQFP3ORNU6WY7HQISbqbhf0UudDAf', 'consumer_key': CONSUMER_KEY, 'key_cert': KEY_CERT_DATA }) else: if self.CI_JIRA_ADMIN: self.jira_admin = JIRA( self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_ADMIN, self.CI_JIRA_ADMIN_PASSWORD), logging=False, validate=True, max_retries=self.max_retries) else: self.jira_admin = JIRA(self.CI_JIRA_URL, validate=True, logging=False, max_retries=self.max_retries) if self.jira_admin.current_user() != self.CI_JIRA_ADMIN: # self.jira_admin. self.initialized = 1 sys.exit(3) if OAUTH: self.jira_sysadmin = JIRA(oauth={ 'access_token': '4ul1ETSFo7ybbIxAxzyRal39cTrwEGFv', 'access_token_secret': 'K83jBZnjnuVRcfjBflrKyThJa0KSjSs2', 'consumer_key': CONSUMER_KEY, 'key_cert': KEY_CERT_DATA }, logging=False, max_retries=self.max_retries) else: if self.CI_JIRA_ADMIN: self.jira_sysadmin = JIRA( self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_ADMIN, self.CI_JIRA_ADMIN_PASSWORD), logging=False, validate=True, max_retries=self.max_retries) else: self.jira_sysadmin = JIRA(self.CI_JIRA_URL, logging=False, max_retries=self.max_retries) if OAUTH: self.jira_normal = JIRA( oauth={ 'access_token': 'ZVDgYDyIQqJY8IFlQ446jZaURIz5ECiB', 'access_token_secret': '5WbLBybPDg1lqqyFjyXSCsCtAWTwz1eD', 'consumer_key': CONSUMER_KEY, 'key_cert': KEY_CERT_DATA }) else: if self.CI_JIRA_ADMIN: self.jira_normal = JIRA( self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_USER, self.CI_JIRA_USER_PASSWORD), validate=True, logging=False, max_retries=self.max_retries) else: self.jira_normal = JIRA(self.CI_JIRA_URL, validate=True, logging=False, max_retries=self.max_retries) # now we need some data to start with for the tests # jira project key is max 10 chars, no letter. # [0] always "Z" # [1-6] username running the tests (hope we will not collide) # [7-8] python version A=0, B=1,.. # [9] A,B -- we may need more than one project """ `jid` is important for avoiding concurency problems when executing tests in parallel as we have only one test instance. jid length must be less than 9 characters because we may append another one and the JIRA Project key length limit is 10. Tests run in parallel: * git branches master or developer, git pr or developers running tests outside Travis * Travis is using "Travis" username https://docs.travis-ci.com/user/environment-variables/ """ self.jid = get_unique_project_name() self.project_a = self.jid + 'A' # old XSS self.project_a_name = "Test user=%s key=%s A" \ % (getpass.getuser(), self.project_a) self.project_b = self.jid + 'B' # old BULK self.project_b_name = "Test user=%s key=%s B" \ % (getpass.getuser(), self.project_b) self.project_c = self.jid + 'C' # For Service Desk self.project_c_name = "Test user=%s key=%s C" \ % (getpass.getuser(), self.project_c) # TODO(ssbarnea): find a way to prevent SecurityTokenMissing for On Demand # https://jira.atlassian.com/browse/JRA-39153 try: self.jira_admin.project(self.project_a) except Exception as e: logging.warning(e) pass else: try: self.jira_admin.delete_project(self.project_a) except Exception as e: pass try: self.jira_admin.project(self.project_b) except Exception as e: logging.warning(e) pass else: try: self.jira_admin.delete_project(self.project_b) except Exception as e: pass try: self.jira_admin.project(self.project_c) except Exception as e: logging.warning(e) pass else: try: self.jira_admin.delete_project(self.project_c) except Exception as e: pass # wait for the project to be deleted for i in range(1, 20): try: self.jira_admin.project(self.project_b) except Exception as e: break sleep(2) try: self.jira_admin.create_project(self.project_a, self.project_a_name) except Exception: # we care only for the project to exist pass self.project_a_id = self.jira_admin.project(self.project_a).id # except Exception as e: # logging.warning("Got %s" % e) # try: # assert self.jira_admin.create_project(self.project_b, # self.project_b_name) is True, "Failed to create %s" % # self.project_b try: self.jira_admin.create_project(self.project_b, self.project_b_name) except Exception: # we care only for the project to exist pass # Create project for Jira Service Desk try: self.jira_admin.create_project( self.project_c, self.project_c_name, template_name='IT Service Desk') except Exception: pass sleep(1) # keep it here as often JIRA will report the # project as missing even after is created self.project_b_issue1_obj = self.jira_admin.create_issue( project=self.project_b, summary='issue 1 from %s' % self.project_b, issuetype=self.CI_JIRA_ISSUE) self.project_b_issue1 = self.project_b_issue1_obj.key self.project_b_issue2_obj = self.jira_admin.create_issue( project=self.project_b, summary='issue 2 from %s' % self.project_b, issuetype={'name': self.CI_JIRA_ISSUE}) self.project_b_issue2 = self.project_b_issue2_obj.key self.project_b_issue3_obj = self.jira_admin.create_issue( project=self.project_b, summary='issue 3 from %s' % self.project_b, issuetype={'name': self.CI_JIRA_ISSUE}) self.project_b_issue3 = self.project_b_issue3_obj.key except Exception as e: logging.exception("Basic test setup failed") self.initialized = 1 py.test.exit("FATAL: %s\n%s" % (e, traceback.format_exc())) if not hasattr(self, 'jira_normal') or not hasattr( self, 'jira_admin'): py.test.exit("FATAL: WTF!?") self.initialized = 1 else: # already exist but we need to be sure it was initialized counter = 0 while not self.initialized: sleep(1) counter += 1 if counter > 60: logging.fatal( "Something is clearly not right with " + "initialization, killing the tests to prevent a " + "deadlock.") sys.exit(3)
class JiraSession(object): def __init__(self, server, account, password, verify=True): """ Init Jira Session :param server: :param account: :param password: :param verify: """ self.__server = server self.__account = account self.__password = password self.__jira_opts = { 'server': self.__server, 'verify': verify, } self.__session = JIRA(self.__jira_opts, basic_auth=(self.__account, self.__password)) def __enter__(self): assert self.__session.current_user() == self.__account return self def __exit__(self, exc_type, exc_val, exc_tb): self.__session.close() def get_user(self): """ Get jira user :return: """ logging.info(u'Get JIRA Current User') return self.__session.current_user() def search_issues(self, jql): """ Search issues via JQL :param jql: :return: """ logging.info(u'JIRA Search: %s' % jql) return self.__session.search_issues(jql_str=jql, maxResults=128, json_result=True) # def get_issue_count(self, jql: str, issue_summary: dict, issue_key: str): # """ # Search issues via JQL and return count # :param jql: # :param issue_summary: # :param issue_key: # :return: # """ # logging.info(u'JIRA Issue Count: %s' % jql) # issue_summary[issue_key] = int(self.search_issues(jql).get('total')) # return True def get_projects(self): """ Get jira projects :return: <key, name, id> """ logging.info(u'Get JIRA Projects') return self.__session.projects() def get_sprints(self): """ Get jira sprints :return: <name, id> """ logging.info(u'Get JIRA Sprints') jira_sprints = list() for board in self.__session.boards(): _sprints = self.__session.sprints(board.id) jira_sprints = jira_sprints + _sprints return jira_sprints def get_issue_fields(self): """ Get jira fields :return: [{'name':'','id':''}] """ logging.info(u'Get JIRA Fields') _fields = list() for _field in self.__session.fields(): _fields.append({'name': _field['name'], 'id': _field['id']}) return _fields def get_issue_types(self): """ Get jira issue types :return: <name, id> """ logging.info(u'Get JIRA Issue Types') return self.__session.issue_types() def get_issue_statuses(self): """ Get issue statuses :return: <name, id> """ logging.info(u'Get JIRA Issue Statuses') return self.__session.statuses() def get_project_versions(self, pid: str): """ Get project versions :param pid: :return: [<name, id>] """ logging.info(u'Get JIRA Project %s Versions' % pid) return self.__session.project_versions(project=pid)
def get_redirect_url(self, *args, **kwargs): # Step 1. Use the request token in the session to build a new client. consumer = oauth.Consumer(settings.OAUTH_CONSUMER_KEY, settings.OAUTH_CONSUMER_SECRET) token = oauth.Token( self.request.session['request_token']['oauth_token'], self.request.session['request_token']['oauth_token_secret']) client = oauth.Client(consumer, token) client.set_signature_method(SignatureMethod_RSA_SHA1()) # Step 2. Request the authorized access token from Jira. try: resp, content = client.request(settings.OAUTH_ACCESS_TOKEN_URL, "POST") except Exception: messages.add_message( self.request, messages.ERROR, 'Error: Connection to Jira failed. Please contact an Administrator' ) return '/' if resp['status'] != '200': messages.add_message( self.request, messages.ERROR, 'Error: Connection to Jira failed. Please contact an Administrator' ) return '/' access_token = dict(urllib.parse.parse_qsl(content.decode())) module_dir = os.path.dirname(__file__) # get current directory with open(module_dir + '/rsa.pem', 'r') as f: key_cert = f.read() oauth_dict = { 'access_token': access_token['oauth_token'], 'access_token_secret': access_token['oauth_token_secret'], 'consumer_key': settings.OAUTH_CONSUMER_KEY, 'key_cert': key_cert } jira = JIRA(server=settings.JIRA_URL, oauth=oauth_dict) username = jira.current_user() email = jira.user(username).emailAddress url = '/' # Step 3. Lookup the user or create them if they don't exist. try: user = User.objects.get(username=username) except User.DoesNotExist: # Save our permanent token and secret for later. user = User.objects.create_user( username=username, password=access_token['oauth_token_secret']) profile = UserProfile() profile.user = user profile.save() user.userprofile.email_addr = email url = reverse('account:settings') user.userprofile.oauth_token = access_token['oauth_token'] user.userprofile.oauth_secret = access_token['oauth_token_secret'] user.userprofile.save() user.set_password(access_token['oauth_token_secret']) user.save() user = authenticate(username=username, password=access_token['oauth_token_secret']) login(self.request, user) # redirect user to settings page to complete profile return url
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/4/16 17:33 # @Author : tanxw # @Desc : jira 使用 # pip install jira # jira模块使用 from jira import JIRA # 连接jira服务,需要在服务器上构建 # server,username,password jira = JIRA(server='http://192.168.43.199:8080', basic_auth=('root', 'a123456')) jira.user(jira.current_user()) projects = jira.projects() for project in projects: print(project)
from collections import Counter from jira import JIRA curdate = datetime.datetime.now() options = {'server': 'http://jira.server'} jira = JIRA(options) url = 'http://jira.konts.lv' authed_jira = JIRA(options, basic_auth=('username', 'password')) #boards = authed_jira.boards() #[print(board.name, 'board_id =', board.id) for board in boards] #board_id = 43 #print("Customer board: %s (%s)" % (boards[8].name, board_id)) print('Current user:'******'status in (Open, "In Progress","Workaround provided", Reopened) AND assignee in (kudelale) and due < endOfWeek() ORDER BY updatedDate DESC', maxResults=10000) #print('Issues for current user: '******'%Y-%m-%d') print('New date will be at: ', s) print('Total number of overdue issues: ', len(issues)) print(
logging.getLogger("jira").setLevel(logging.DEBUG) CI_JIRA_URL = os.environ["CI_JIRA_URL"] CI_JIRA_ADMIN = os.environ["CI_JIRA_ADMIN"] CI_JIRA_ADMIN_PASSWORD = os.environ["CI_JIRA_ADMIN_PASSWORD"] j = JIRA( CI_JIRA_URL, basic_auth=(CI_JIRA_ADMIN, CI_JIRA_ADMIN_PASSWORD), logging=True, validate=True, async_=True, async_workers=20, ) logging.info("Running maintenance as %s", j.current_user()) for p in j.projects(): logging.info("Deleting project %s", p) try: j.delete_project(p) except Exception as e: logging.error(e) for s in j.permissionschemes(): if " for Project" in s["name"]: logging.info("Deleting permission scheme: %s" % s["name"]) try: j.delete_permissionscheme(s["id"]) except JIRAError as e: logging.error(e.text)
class JiraTestManager(object): """ Used to instantiate and populate the JIRA instance with data used by the unit tests. Attributes: CI_JIRA_ADMIN (str): Admin user account name. CI_JIRA_USER (str): Limited user account name. max_retries (int): number of retries to perform for recoverable HTTP errors. """ __shared_state = {} def __init__(self): self.__dict__ = self.__shared_state if not self.__dict__: self.initialized = 0 try: if CI_JIRA_URL in os.environ: self.CI_JIRA_URL = os.environ['CI_JIRA_URL'] self.max_retries = 5 else: self.CI_JIRA_URL = "https://pycontribs.atlassian.net" self.max_retries = 5 if CI_JIRA_ADMIN in os.environ: self.CI_JIRA_ADMIN = os.environ['CI_JIRA_ADMIN'] else: self.CI_JIRA_ADMIN = 'ci-admin' if CI_JIRA_ADMIN_PASSWORD in os.environ: self.CI_JIRA_ADMIN_PASSWORD = os.environ[ 'CI_JIRA_ADMIN_PASSWORD'] else: self.CI_JIRA_ADMIN_PASSWORD = '******' if 'CI_JIRA_USER' in os.environ: self.CI_JIRA_USER = os.environ['CI_JIRA_USER'] else: self.CI_JIRA_USER = '******' if 'CI_JIRA_USER_PASSWORD' in os.environ: self.CI_JIRA_USER_PASSWORD = os.environ[ 'CI_JIRA_USER_PASSWORD'] else: self.CI_JIRA_USER_PASSWORD = '******' self.CI_JIRA_ISSUE = os.environ.get('CI_JIRA_ISSUE', 'Bug') if OAUTH: self.jira_admin = JIRA(oauth={ 'access_token': 'hTxcwsbUQiFuFALf7KZHDaeAJIo3tLUK', 'access_token_secret': 'aNCLQFP3ORNU6WY7HQISbqbhf0UudDAf', 'consumer_key': CONSUMER_KEY, 'key_cert': KEY_CERT_DATA}) else: if self.CI_JIRA_ADMIN: self.jira_admin = JIRA(self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_ADMIN, self.CI_JIRA_ADMIN_PASSWORD), logging=False, validate=True, max_retries=self.max_retries) else: self.jira_admin = JIRA(self.CI_JIRA_URL, validate=True, logging=False, max_retries=self.max_retries) if self.jira_admin.current_user() != self.CI_JIRA_ADMIN: # self.jira_admin. self.initialized = 1 sys.exit(3) if OAUTH: self.jira_sysadmin = JIRA(oauth={ 'access_token': '4ul1ETSFo7ybbIxAxzyRal39cTrwEGFv', 'access_token_secret': 'K83jBZnjnuVRcfjBflrKyThJa0KSjSs2', 'consumer_key': CONSUMER_KEY, 'key_cert': KEY_CERT_DATA}, logging=False, max_retries=self.max_retries) else: if self.CI_JIRA_ADMIN: self.jira_sysadmin = JIRA(self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_ADMIN, self.CI_JIRA_ADMIN_PASSWORD), logging=False, validate=True, max_retries=self.max_retries) else: self.jira_sysadmin = JIRA(self.CI_JIRA_URL, logging=False, max_retries=self.max_retries) if OAUTH: self.jira_normal = JIRA(oauth={ 'access_token': 'ZVDgYDyIQqJY8IFlQ446jZaURIz5ECiB', 'access_token_secret': '5WbLBybPDg1lqqyFjyXSCsCtAWTwz1eD', 'consumer_key': CONSUMER_KEY, 'key_cert': KEY_CERT_DATA}) else: if self.CI_JIRA_ADMIN: self.jira_normal = JIRA(self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_USER, self.CI_JIRA_USER_PASSWORD), validate=True, logging=False, max_retries=self.max_retries) else: self.jira_normal = JIRA(self.CI_JIRA_URL, validate=True, logging=False, max_retries=self.max_retries) # now we need some data to start with for the tests # jira project key is max 10 chars, no letter. # [0] always "Z" # [1-6] username running the tests (hope we will not collide) # [7-8] python version A=0, B=1,.. # [9] A,B -- we may need more than one project prefix = 'Z' + (re.sub("[^A-Z]", "", getpass.getuser().upper()))[0:6] + \ chr(ord('A') + sys.version_info[0]) + \ chr(ord('A') + sys.version_info[1]) self.project_a = prefix + 'A' # old XSS self.project_a_name = "Test user=%s python=%s.%s A" \ % (getpass.getuser(), sys.version_info[0], sys.version_info[1]) self.project_b_name = "Test user=%s python=%s.%s B" \ % (getpass.getuser(), sys.version_info[0], sys.version_info[1]) self.project_b = prefix + 'B' # old BULK try: self.jira_admin.project(self.project_a) except Exception as e: logging.warning(e) pass else: self.jira_admin.delete_project(self.project_a) try: self.jira_admin.project(self.project_b) except Exception as e: logging.warning(e) pass else: self.jira_admin.delete_project(self.project_b) self.jira_admin.create_project(self.project_a, self.project_a_name) self.project_a_id = self.jira_admin.project(self.project_a).id self.jira_admin.create_project(self.project_b, self.project_b_name) self.project_b_issue1_obj = self.jira_admin.create_issue(project=self.project_b, summary='issue 1 from %s' % self.project_b, issuetype=self.CI_JIRA_ISSUE) self.project_b_issue1 = self.project_b_issue1_obj.key self.project_b_issue2_obj = self.jira_admin.create_issue(project=self.project_b, summary='issue 2 from %s' % self.project_b, issuetype={'name': self.CI_JIRA_ISSUE}) self.project_b_issue2 = self.project_b_issue2_obj.key self.project_b_issue3_obj = self.jira_admin.create_issue(project=self.project_b, summary='issue 3 from %s' % self.project_b, issuetype={'name': self.CI_JIRA_ISSUE}) self.project_b_issue3 = self.project_b_issue3_obj.key except Exception as e: # exc_type, exc_value, exc_traceback = sys.exc_info() formatted_lines = traceback.format_exc().splitlines() msg = "Basic test setup failed: %s\n\t%s" % ( e, "\n\t".join(formatted_lines)) logging.fatal(msg) self.initialized = 1 pytest.exit("FATAL") self.initialized = 1 else: # already exist but we need to be sure it was initialized counter = 0 while not self.initialized: sleep(1) counter += 1 if counter > 60: logging.fatal("Something is clearly not right with " + "initialization, killing the tests to prevent a " + "deadlock.") sys.exit(3)