ITPLT-4737 Migrate remaining Marketplace tests to v3

This commit is contained in:
Lee Goolsbee
2026-09-04 11:20:53 -05:00
parent fdf9d08429
commit e263b3394c
9 changed files with 289 additions and 209 deletions

View File

@@ -4,41 +4,99 @@ from six.moves import urllib
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def get_latest():
req = urllib.request.Request("https://marketplace.atlassian.com/rest/2/products/key/jira-servicedesk/versions/latest")
MARKETPLACE_API_BASE_URL = "https://marketplace.atlassian.com/rest/3"
JSM_APP_KEY = "com.atlassian.servicedesk.application"
JSM_HOSTING_PREFERENCE = ("datacenter", "server")
def get_json(url):
req = urllib.request.Request(url)
req.add_header('User-Agent', 'ansible-httpget')
data = urllib.request.urlopen(req)
meta = json.loads(data.read().decode("UTF-8"))
return meta['name']
try:
return json.loads(data.read().decode("UTF-8"))
finally:
data.close()
def get_json_if_available(url):
try:
return get_json(url)
except urllib.error.HTTPError as error:
if error.code == 404:
return None
raise
def get_latest():
app_software_ids = []
for hosting in JSM_HOSTING_PREFERENCE:
app_software = get_json_if_available(
MARKETPLACE_API_BASE_URL
+ "/app-software/app-key/"
+ JSM_APP_KEY
+ "?hosting="
+ hosting)
if app_software is None:
continue
if not isinstance(app_software, list):
app_software = [app_software]
app_software_ids.extend(
item['appSoftwareId']
for item in app_software
if item.get('appSoftwareId') and item.get('archived') is False)
for app_software_id in dict.fromkeys(app_software_ids):
version_info = get_json_if_available(
MARKETPLACE_API_BASE_URL
+ "/app-software/"
+ app_software_id
+ "/versions?parentSoftwareId=jira&state=ACTIVE&limit=1")
if version_info and version_info.get('versions'):
return version_info['versions'][0]['versionNumber']
raise AssertionError(
"Marketplace returned no active JSM version for app key " + JSM_APP_KEY)
sd = get_latest()
def test_version_is_correct(host):
verfile = host.file('/media/atl/jira/shared/jira-servicedesk.version')
assert verfile.exists
assert verfile.content.decode("UTF-8").strip() == sd
def test_is_downloaded(host):
installer = host.file('/media/atl/downloads/servicedesk.'+sd+'-x64.bin')
assert installer.exists
assert installer.user == 'root'
def test_completed_lockfile(host):
lockfile = host.file('/media/atl/downloads/servicedesk.'+sd+'-x64.bin_completed')
assert lockfile.exists
assert lockfile.user == 'root'
def test_is_unpacked(host):
installer = host.file('/opt/atlassian/jira-servicedesk/'+sd)
assert installer.exists
assert installer.is_directory
assert installer.user == 'jira'
def test_plugin_is_present(host):
installer = host.file('/opt/atlassian/jira-servicedesk/current/atlassian-jira/WEB-INF/application-installation/jira-servicedesk-application/jira-servicedesk-application-'+sd+'.jar')
installer = host.file(
'/opt/atlassian/jira-servicedesk/current/atlassian-jira/WEB-INF/'
'application-installation/jira-servicedesk-application/'
'jira-servicedesk-application-' + sd + '.jar')
assert installer.exists
assert installer.user == 'jira'