Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
prepend project names with API user's id (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
aerickson committed Oct 8, 2020
1 parent bfe6d2a commit f4d562a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
4 changes: 2 additions & 2 deletions config/config.yml
Expand Up @@ -2,8 +2,8 @@ projects:
defaults:
os_type: ANDROID
project_type: APPIUM_ANDROID_SERVER_SIDE
application_file: aerickson-Testdroid.apk
test_file: aerickson-empty-test.zip
application_file: relops-testdroid-sample-app.apk
test_file: relops-empty-test.zip
timeout: 0
scheduler: SINGLE
archivingStrategy: DAYS
Expand Down
58 changes: 49 additions & 9 deletions mozilla_bitbar_devicepool/configuration.py
Expand Up @@ -32,6 +32,7 @@
"devices": {},
"files": {},
"frameworks": {},
"me": {},
"projects": {},
"test_runs": {},
}
Expand Down Expand Up @@ -66,6 +67,18 @@ def get_filespath():
return FILESPATH


def get_me_id():
"""Returns the Bitbar User ID that the application is using.
"""

if BITBAR_CACHE["me"] == {}:
BITBAR_CACHE["me"] = TESTDROID.get_me()
# use 'id'
# - not 'mainUserId' (user's can create sub-users)
# - not 'accountId' (the organization's id))
return BITBAR_CACHE["me"]["id"]


def ensure_filenames_are_unique(config):
seen_filenames = []
# TODO: break extraction of filenames out for easier testing
Expand Down Expand Up @@ -206,10 +219,20 @@ def configure_device_groups(update_bitbar=False):
)
elif len(bitbar_device_groups) == 1:
bitbar_device_group = bitbar_device_groups[0]
logger.debug(
"configure_device_groups: configuring group {} to use {}".format(
device_group_name, bitbar_device_group
)
)
else:
# no such device group. create it.
if update_bitbar:
bitbar_device_group = create_device_group(device_group_name)
logger.debug(
"configure_device_groups: configuring group {} to use newly created group {}".format(
device_group_name, bitbar_device_group
)
)
else:
raise Exception(
"device group {} does not exist but can not create.".format(
Expand Down Expand Up @@ -293,24 +316,41 @@ def configure_projects(update_bitbar=False):
logger.info("{}: configuring...".format(log_header))

project_config = projects_config[project_name]
bitbar_projects = get_projects(name=project_name)

# for the project name at bitbar, add user id to the project_name
# - prevents collision with other users' projects and allows us to
# avoid having to share projects
api_user_id = get_me_id()
user_project_name = "%s-%s" % (api_user_id, project_name)

bitbar_projects = get_projects(name=user_project_name)
if len(bitbar_projects) > 1:
raise DuplicateProjectException(
"project {} has {} duplicates".format(
project_name, len(bitbar_projects) - 1
"project {} ({}) has {} duplicates".format(
project_name, user_project_name, len(bitbar_projects) - 1
)
)
elif len(bitbar_projects) == 1:
bitbar_project = bitbar_projects[0]
logger.debug(
"configure_projects: using project {} ({})".format(
bitbar_project, user_project_name
)
)
else:
if update_bitbar:
bitbar_project = create_project(
project_name, project_type=project_config["project_type"]
user_project_name, project_type=project_config["project_type"]
)
logger.debug(
"configure_projects: created project {} ({})".format(
bitbar_project, user_project_name
)
)
else:
raise Exception(
"Project {} does not exist, but not creating as not configured to update bitbar!".format(
project_name
"Project {} ({}) does not exist, but not creating as not configured to update bitbar!".format(
project_name, user_project_name
)
)

Expand Down Expand Up @@ -366,7 +406,7 @@ def configure_projects(update_bitbar=False):
if update_bitbar:
bitbar_project = update_project(
bitbar_project["id"],
project_name,
user_project_name,
archiving_item_count=project_config["archivingItemCount"],
archiving_strategy=project_config["archivingStrategy"],
description=project_config["description"],
Expand All @@ -390,8 +430,8 @@ def configure_projects(update_bitbar=False):
)
)
raise Exception(
"The remote configuration for {} differs from the local configuration, but not configured to update bitbar!".format(
project_name
"The remote configuration for {} ({}) differs from the local configuration, but not configured to update bitbar!".format(
project_name, user_project_name
)
)

Expand Down
4 changes: 1 addition & 3 deletions mozilla_bitbar_devicepool/main.py
Expand Up @@ -17,9 +17,7 @@
from mozilla_bitbar_devicepool.test_run_manager import TestRunManager
from mozilla_bitbar_devicepool.util.network import download_file

testdroid_apk_url = (
"https://github.com/bitbar/bitbar-samples/blob/master/apps/builds/Testdroid.apk"
)
testdroid_apk_url = "https://github.com/bitbar/test-samples/raw/master/apps/android/testdroid-sample-app.apk"


def download_testdroid_apk(args):
Expand Down
5 changes: 4 additions & 1 deletion mozilla_bitbar_devicepool/test_run_manager.py
Expand Up @@ -226,7 +226,10 @@ def process_active_runs(self):
return

for item in result:
project_name = item["projectName"]
# remove user id from this (see configuration.py:configure_projects)
project_name = item["projectName"].replace(
"%s-" % (configuration.get_me_id()), ""
)
# only accumulate for projects in our config
if project_name in bitbar_projects:
accumulation_dict[project_name].append(item)
Expand Down

0 comments on commit f4d562a

Please sign in to comment.