Skip to content

Commit 282b440

Browse files
committed
Add Sunbeam support to OpenStack plugin
Also: * fixes Juju units summary to include charm revision where charm has no repo-info file. * adds snap channel to summary output Resolves: #995
1 parent 1e51266 commit 282b440

File tree

12 files changed

+133
-52
lines changed

12 files changed

+133
-52
lines changed

examples/hotsos-example-kubernetes.summary.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ kubernetes:
4040
- kube-proxy (1)
4141
- kube-scheduler (1)
4242
snaps:
43-
- cdk-addons 1.23.0
44-
- core 16-2.54.2
45-
- core18 20211215
46-
- core20 20220114
47-
- kube-apiserver 1.23.3
48-
- kube-controller-manager 1.23.3
49-
- kube-proxy 1.23.3
50-
- kube-scheduler 1.23.3
51-
- kubectl 1.23.3
43+
- cdk-addons 1.23.0 (latest/stable)
44+
- core 16-2.54.2 (latest/stable)
45+
- core18 20211215 (latest/stable)
46+
- core20 20220114 (latest/stable)
47+
- kube-apiserver 1.23.3 (latest/stable)
48+
- kube-controller-manager 1.23.3 (latest/stable)
49+
- kube-proxy 1.23.3 (latest/stable)
50+
- kube-scheduler 1.23.3 (latest/stable)
51+
- kubectl 1.23.3 (latest/stable)
5252
dpkg:
5353
- vaultlocker 1.0.6-0ubuntu1
5454
flannel:

examples/hotsos-example-vault.summary.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ vault:
2626
- vault-mysql-router
2727
ps: []
2828
snaps:
29-
- vault 1.5.9
29+
- vault 1.5.9 (1.5/stable)

hotsos/core/host_helpers/packaging.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ def all_formatted(self):
654654
if not _all:
655655
return []
656656

657-
return [f"{name} {info['version']}" for name, info in _all.items()]
657+
return [f"{name} {info['version']} ({info['channel']})"
658+
for name, info in _all.items()]
658659

659660
@property
660661
def core(self):

hotsos/core/plugins/openstack/common.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DPKGVersion,
1414
InstallInfoBase,
1515
PebbleHelper,
16+
SnapPackageHelper,
1617
SystemdHelper,
1718
SSLCertificate,
1819
SSLCertificatesHelper,
@@ -22,6 +23,8 @@
2223
OSTProjectCatalog,
2324
OST_EOL_INFO,
2425
OST_REL_INFO,
26+
OST_SUNBEAM_REL_INFO,
27+
OST_SUNBEAM_SNAP_NAMES,
2528
)
2629
from hotsos.core.plugins.openstack.neutron import NeutronBase
2730
from hotsos.core.plugins.openstack.nova import NovaBase
@@ -47,26 +50,29 @@ class OpenStackInstallInfo(InstallInfoBase):
4750

4851
def __post_init__(self):
4952
service_exprs = self.project_catalog.service_exprs
50-
core_pkgs = self.project_catalog.packages_core_exprs
51-
other_pkgs = self.project_catalog.packages_dep_exprs
53+
snap_core_pkgs = self.project_catalog.snap_core_exprs
54+
core_pkgs = self.project_catalog.apt_core_exprs
55+
other_pkgs = self.project_catalog.apt_dep_exprs
5256

5357
self.apt = APTPackageHelper(core_pkgs=core_pkgs,
5458
other_pkgs=other_pkgs)
5559
self.docker = DockerImageHelper(core_pkgs=core_pkgs,
5660
other_pkgs=other_pkgs)
61+
self.snaps = SnapPackageHelper(core_snaps=snap_core_pkgs)
5762
self.pebble = PebbleHelper(service_exprs=service_exprs)
5863
self.systemd = SystemdHelper(service_exprs=service_exprs)
5964

6065
def mixin(self, _self):
6166
_self.apt = self.apt
6267
_self.docker = self.docker
6368
_self.pebble = self.pebble
69+
_self.snaps = self.snaps
6470
_self.systemd = self.systemd
6571

6672

67-
class OpenstackBase():
73+
class OpenstackBase(): # pylint: disable=too-many-instance-attributes
6874
"""
69-
Base class for Openstack checks.
75+
Base class for OpenStack checks.
7076
7177
Contains per-service information such as packages, versions, config etc.
7278
"""
@@ -77,19 +83,14 @@ def __init__(self, *args, **kwargs):
7783
OctaviaBase())
7884
self.project_catalog = OSTProjectCatalog()
7985
# Keep pylint happy
80-
self.apt = self.pebble = self.docker = self.systemd = None
86+
self.apt = self.pebble = self.docker = self.snaps = self.systemd = None
8187
OpenStackInstallInfo(project_catalog=self.project_catalog).mixin(self)
8288

8389
@cached_property
8490
def apt_source_path(self):
8591
return os.path.join(HotSOSConfig.data_root, 'etc/apt/sources.list.d')
8692

87-
@cached_property
88-
def installed_pkg_release_names(self):
89-
"""
90-
Get release name for each installed package that we are tracking and
91-
return as a list of names. The list should normally have length 1.
92-
"""
93+
def _get_apt_relnames(self):
9394
relnames = set()
9495
for pkg, values in OST_REL_INFO.items():
9596
if pkg in self.apt.core:
@@ -110,6 +111,23 @@ def installed_pkg_release_names(self):
110111
if r_lt:
111112
relnames.add(r_lt)
112113

114+
return relnames
115+
116+
@cached_property
117+
def installed_pkg_release_names(self):
118+
"""
119+
Get release name for each installed package that we are tracking and
120+
return as a list of names. The list should normally have length 1.
121+
"""
122+
if self.apt.core:
123+
relnames = self._get_apt_relnames()
124+
else:
125+
relnames = set()
126+
for pkg in OST_SUNBEAM_SNAP_NAMES:
127+
if pkg in self.snaps.core:
128+
ver = self.snaps.get_version(pkg)
129+
relnames.add(OST_SUNBEAM_REL_INFO[ver])
130+
113131
log.debug("release name(s) found: %s", ','.join(relnames))
114132
return list(relnames)
115133

@@ -277,7 +295,8 @@ def is_runnable(cls):
277295
278296
@return: True or False
279297
"""
280-
if OpenstackBase().apt.core:
298+
ost_common = OpenstackBase()
299+
if ost_common.apt.core or ost_common.snaps.core:
281300
return True
282301

283302
return False

hotsos/core/plugins/openstack/openstack.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@
280280
'stein': '1.0.0'}
281281
}
282282

283+
OST_SUNBEAM_SNAP_NAMES = ['openstack', 'openstack-hypervisor']
284+
285+
OST_SUNBEAM_REL_INFO = {
286+
'2025.1': 'epoxy',
287+
'2024.2': 'dalmation',
288+
'2024.1': 'caracal',
289+
'2023.2': 'bobcat',
290+
'2023.1': 'antelope',
291+
}
292+
283293
OST_EXCEPTIONS = {'barbican': BARBICAN_EXCEPTIONS + CASTELLAN_EXCEPTIONS +
284294
OSLO_MESSAGING_EXCEPTIONS,
285295
'cinder': CINDER_EXCEPTIONS + CASTELLAN_EXCEPTIONS +
@@ -496,6 +506,9 @@ class OSTProjectCatalog():
496506
'radvd',
497507
]
498508

509+
# ref: https://github.com/orgs/canonical/repositories?q=%22snap-open%22
510+
SNAP_DEPS_SUNBEAM = [r'openstack\S*']
511+
499512
def __init__(self):
500513
self._projects = {}
501514
self.add('aodh', config={'main': 'aodh.conf'},
@@ -621,15 +634,19 @@ def add(self, name, *args, **kwargs):
621634
self._projects[name] = OSTProject(params)
622635

623636
@cached_property
624-
def packages_core_exprs(self):
637+
def snap_core_exprs(self):
638+
return self.SNAP_DEPS_SUNBEAM
639+
640+
@cached_property
641+
def apt_core_exprs(self):
625642
core = set()
626643
for p in self.all.values():
627644
core.update(p.apt_params.core)
628645

629646
return list(core)
630647

631648
@cached_property
632-
def packages_dep_exprs(self):
649+
def apt_dep_exprs(self):
633650
deps = set(self.APT_DEPS_COMMON)
634651
for p in self.all.values():
635652
deps.update(p.apt_params.deps)

hotsos/plugin_extensions/juju/summary.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,17 @@ def summary_units(self):
136136
name, _, ver = u.name.rpartition('-')
137137
u_name = f"{name}/{ver}"
138138
unit_info[u_name] = {}
139-
if u.repo_info:
140-
c_name = u.charm_name
141-
if c_name:
142-
unit_info[u_name]['charm'] = {'name': c_name}
139+
c_name = u.charm_name
140+
if c_name:
141+
charm = {'name': c_name}
142+
unit_info[u_name]['charm'] = charm
143+
if u.repo_info:
143144
sha1 = u.repo_info.get('commit')
144-
unit_info[u_name]['charm']['repo-info'] = sha1
145-
if c_name in self.charms:
146-
unit_info[u_name]['charm']['version'] = \
147-
self.charms[c_name].version
145+
charm['repo-info'] = sha1
146+
147+
if c_name in self.charms:
148+
charm['version'] = \
149+
self.charms[c_name].version
148150

149151
if u.name in loginfo:
150152
unit_info[u_name]['logs'] = loginfo[u.name]

tests/unit/host_helpers/test_packaging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_all(self):
4949
self.assertEqual(obj.get_version("lxd"), "4.22")
5050

5151
def test_formatted(self):
52-
expected = ['core20 20220114']
52+
expected = ['core20 20220114 (latest/stable)']
5353
obj = host_pack.SnapPackageHelper(["core20"])
5454
self.assertEqual(obj.all_formatted, expected)
5555

tests/unit/test_juju.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ def test_get_unit_info(self):
185185
self.assertEqual(self.part_output_to_actual(inst.output)['units'],
186186
expected)
187187

188+
@utils.create_data_root(
189+
{('var/lib/juju/agents/unit-sunbeam-machine-1/'
190+
'state/deployer/manifests/'
191+
'ch_3a_amd64_2f_jammy_2f_sunbeam-machine-32'): ''})
192+
def test_get_unit_info_no_repo_info(self):
193+
expected = {'sunbeam-machine/1':
194+
{'charm': {'name': 'sunbeam-machine', 'version': 32}}}
195+
inst = summary.JujuSummary()
196+
self.assertEqual(self.part_output_to_actual(inst.output)['units'],
197+
expected)
198+
188199

189200
@utils.load_templated_tests('scenarios/juju')
190201
class TestJujuScenarios(JujuTestsBase):

tests/unit/test_kubernetes.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ def test_services(self):
6262
expected)
6363

6464
def test_snaps(self):
65-
result = ['cdk-addons 1.23.0',
66-
'core 16-2.54.2',
67-
'core18 20211215',
68-
'core20 20220114',
69-
'kube-apiserver 1.23.3',
70-
'kube-controller-manager 1.23.3',
71-
'kube-proxy 1.23.3',
72-
'kube-scheduler 1.23.3',
73-
'kubectl 1.23.3']
65+
result = ['cdk-addons 1.23.0 (latest/stable)',
66+
'core 16-2.54.2 (latest/stable)',
67+
'core18 20211215 (latest/stable)',
68+
'core20 20220114 (latest/stable)',
69+
'kube-apiserver 1.23.3 (latest/stable)',
70+
'kube-controller-manager 1.23.3 (latest/stable)',
71+
'kube-proxy 1.23.3 (latest/stable)',
72+
'kube-scheduler 1.23.3 (latest/stable)',
73+
'kubectl 1.23.3 (latest/stable)']
7474
inst = summary.KubernetesSummary()
7575
self.assertEqual(self.part_output_to_actual(inst.output)['snaps'],
7676
result)
@@ -97,10 +97,10 @@ def test_snaps_microk8s(self, mock_helper):
9797
mock_helper.return_value.snap_list_all.return_value = \
9898
SNAP_LIST_ALL_MICROK8S.splitlines()
9999
inst = summary.KubernetesSummary()
100-
result = ['core18 20230320',
101-
'core20 20230308',
102-
'core22 20230404',
103-
'microk8s v1.26.4']
100+
result = ['core18 20230320 (latest/stable)',
101+
'core20 20230308 (latest/stable)',
102+
'core22 20230404 (latest/stable)',
103+
'microk8s v1.26.4 (1.26/stable)']
104104
self.assertTrue(inst.is_runnable())
105105
self.assertEqual(self.part_output_to_actual(inst.output)['snaps'],
106106
result)

tests/unit/test_lxd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_summary_keys(self):
3131
'snap.lxd.user-daemon'],
3232
'transient': ['snap.lxd.workaround']}},
3333

34-
'snaps': ['lxd 4.22']}
34+
'snaps': ['lxd 4.22 (latest/stable)']}
3535
inst = summary.LXDSummary()
3636
self.assertEqual(self.part_output_to_actual(inst.output), expected)
3737

0 commit comments

Comments
 (0)