Skip to content

Commit 6e25b4f

Browse files
authored
Merge pull request #47 from craigcomstock/ENT-8978
ENT-8978: Added support for aarch64/arm64 packages
2 parents 964429c + 8d99b7e commit 6e25b4f

File tree

9 files changed

+417
-16
lines changed

9 files changed

+417
-16
lines changed

cf_remote/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def _iterate_over_packages(tags=None, version=None, edition=None, download=False
283283
if version:
284284
release = releases.pick_version(version)
285285
print("Using {}:".format(release))
286+
log.debug("Looking for a release based on host tags: {}".format(tags))
286287
artifacts = release.find(tags)
287288

288289
if len(artifacts) == 0:

cf_remote/packages.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def add_tags_from_filename(self, filename):
8686
part = part.strip()
8787
if part == "x86":
8888
continue
89-
if part == "amd64" or part == "x86_64":
89+
if part == "amd64" or part == "x86_64" or part == "arm64":
9090
self.add_tag("64")
9191
try:
9292
_ = int(part)
@@ -97,13 +97,46 @@ def add_tags_from_filename(self, filename):
9797
else:
9898
self.add_tag("client")
9999
self.add_tag("agent")
100+
101+
# sorry, debian packages work great on ubuntu
102+
# if we don't have a specific ubuntu package, note which debian is equivalent
103+
# only add "ubuntu" tag if we know we have an equivalent debian :)
104+
if "debian11" in self.tags:
105+
self.add_tag("ubuntu20")
106+
self.add_tag("ubuntu")
107+
if "debian10" in self.tags:
108+
self.add_tag("ubuntu19")
109+
self.add_tag("ubuntu18")
110+
self.add_tag("ubuntu")
111+
if "debian9" in self.tags:
112+
self.add_tag("ubuntu17")
113+
self.add_tag("ubuntu16")
114+
self.add_tag("ubuntu")
115+
if "debian8" in self.tags:
116+
self.add_tag("ubuntu15")
117+
self.add_tag("ubuntu14")
118+
self.add_tag("ubuntu")
119+
if "debian7" in self.tags:
120+
self.add_tag("ubuntu13")
121+
self.add_tag("ubuntu12")
122+
self.add_tag("ubuntu11")
123+
self.add_tag("ubuntu")
124+
100125
parts = filename.split(".")
101126
if "x86_64" in parts:
102127
self.add_tag("x86_64")
103128
self.add_tag("64")
104129
if "amd64" in parts:
105130
self.add_tag("amd64")
106131
self.add_tag("64")
132+
if "arm64" in parts:
133+
self.add_tag("aarch64")
134+
self.add_tag("64")
135+
log.debug(
136+
"After looking at filename {}, tags for this package are {}".format(
137+
filename, self.tags
138+
)
139+
)
107140

108141
def __str__(self):
109142
return self.filename + " ({})".format(" ".join(self.tags))
@@ -115,7 +148,7 @@ def __repr__(self):
115148
def filter_artifacts(artifacts, tags, extension):
116149
if extension:
117150
artifacts = [a for a in artifacts if a.extension == extension]
118-
log.debug("Looking for tags: {}".format(tags))
151+
log.debug("Looking for host tags: {}".format(tags))
119152
log.debug("In artifacts: {}".format(artifacts))
120153
for tag in tags or []:
121154
tag = canonify(tag)
@@ -124,6 +157,9 @@ def filter_artifacts(artifacts, tags, extension):
124157
# since we are overwriting artifacts
125158
if len(new_artifacts) > 0:
126159
artifacts = new_artifacts
160+
log.debug(
161+
"Artifacts filtered on canonified tag {} are {}".format(tag, new_artifacts)
162+
)
127163

128164
log.debug("Found artifacts: {}".format(artifacts))
129165
return artifacts
@@ -135,12 +171,13 @@ def __init__(self, data):
135171
self.version = data["version"]
136172
self.url = data["URL"]
137173
self.lts = data["lts_branch"] if "lts_branch" in data else None
138-
self.extended_data = None
174+
self.extended_data = data["data"] if "data" in data else None
139175
self.artifacts = None
140176
self.default = False
141177

142178
def init_download(self):
143-
self.extended_data = get_json(self.url)
179+
if self.extended_data is None:
180+
self.extended_data = get_json(self.url)
144181
artifacts = self.extended_data["artifacts"]
145182
self.artifacts = []
146183
for header in artifacts:
@@ -150,7 +187,7 @@ def init_download(self):
150187
self.artifacts.append(artifact)
151188

152189
def find(self, tags, extension=None):
153-
if not self.extended_data:
190+
if self.extended_data is None:
154191
self.init_download()
155192
return filter_artifacts(self.artifacts, tags, extension)
156193

cf_remote/remote.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def _package_from_list(tags, extension, packages):
316316

317317

318318
def _package_from_releases(tags, extension, version, edition, remote_download):
319+
log.debug("Looking for a package from releases based on host tags: {}".format(tags))
319320
releases = Releases(edition)
320321
release = releases.default
321322
if version:
@@ -360,7 +361,9 @@ def get_package_from_host_info(
360361
if edition == "enterprise":
361362
tags.append("hub" if hub else "agent")
362363

363-
tags.append("64" if arch in ("x86_64", "amd64") else arch)
364+
tags.append("64" if arch in ("x86_64", "amd64", "aarch64") else arch)
365+
if arch == "aarch64":
366+
tags.append("arm64")
364367
if arch in ("i386", "i486", "i586", "i686"):
365368
tags.append("32")
366369

@@ -375,7 +378,7 @@ def get_package_from_host_info(
375378
if package_tags is not None:
376379
tags.extend(tag for tag in package_tags if tag != "msi")
377380

378-
if packages is None: # No commandd line argument given
381+
if packages is None: # No command line argument given
379382
package = _package_from_releases(
380383
tags, extension, version, edition, remote_download
381384
)

cf_remote/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ def get_package_name(url):
8989
return url.rsplit("/", 1)[-1]
9090

9191

92+
def parse_json(text):
93+
return json.loads(text, object_pairs_hook=OrderedDict)
94+
95+
9296
def read_json(path):
9397
try:
9498
with open(path, "r") as f:
95-
return json.loads(f.read(), object_pairs_hook=OrderedDict)
99+
return parse_json(f.read())
96100
except FileNotFoundError:
97101
return None
98102

cf_remote/web.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import fcntl
33
import urllib.request
44
import requests
5-
from cf_remote.utils import write_json, mkdir
5+
from cf_remote.utils import write_json, mkdir, parse_json
66
from cf_remote import log
77
from cf_remote.paths import cf_remote_dir, cf_remote_packages_dir
88

99

1010
def get_json(url):
1111
r = requests.get(url)
1212
assert r.status_code >= 200 and r.status_code < 300
13-
data = r.json()
13+
data = parse_json(r.text)
1414

1515
filename = os.path.basename(url)
1616
dir = cf_remote_dir("json")

run_tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set -e
2+
set -x
3+
black --check cf_remote/*.py || true
4+
black --check tests/*.py || true
5+
if [ -z "$1" ]; then
6+
python3 -m coverage run -m pytest
7+
python3 -m coverage html
8+
else
9+
# for debugging, getting all output, and running a single test method:
10+
python3 -m pytest -k "$1" --show-capture=all -vv
11+
fi

0 commit comments

Comments
 (0)