6671969b97
The charm uses a hardcoded channel declared in src/layer.yaml with the value 1.0/stable, this prevents users from overriding it. This became a blocker with the release of octavia-diskimage-retrofit 2.0 in the `2.0` track to support Ubuntu Noble 24.04, the snap migrated to core24[0][1] This change introduces a new configuration option that defaults to null, this will allow the charm to use the 1.0/stable channel when running on Jammy and 2.0/stable when running on Noble. Existing environments running on Jammy will see no behavior change, and no operator's intervention is needed when upgrading. [0] https://github.com/openstack-charmers/octavia-diskimage-retrofit/pull/44 [1] https://github.com/openstack-charmers/octavia-diskimage-retrofit/pull/46 Change-Id: I1ccba9de844f7900c9a8517fff4de2f8c4019871 Signed-off-by: Felipe Reyes <felipe.reyes@canonical.com> Co-Authored-by: Hemanth Nakkina <hemanth.nakkina@canonical.com> Change-Id: I1ccba9de844f7900c9a8517fff4de2f8c4019871 Signed-off-by: Hemanth Nakkina <hemanth.nakkina@canonical.com>
106 lines
3.9 KiB
Python
106 lines
3.9 KiB
Python
# Copyright 2019 Canonical Ltd
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
import reactive.octavia_diskimage_retrofit_handlers as handlers
|
|
|
|
import charms_openstack.test_utils as test_utils
|
|
|
|
|
|
class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|
|
|
def test_hooks(self):
|
|
defaults = [
|
|
'charm.installed',
|
|
'config.changed',
|
|
'update-status',
|
|
'upgrade-charm',
|
|
]
|
|
hook_set = {
|
|
'when': {
|
|
'request_credentials': (
|
|
'identity-credentials.connected',),
|
|
'credentials_available': (
|
|
'identity-credentials.available',),
|
|
'build': (
|
|
'octavia-diskimage-retrofit.build',),
|
|
},
|
|
'when_any': {
|
|
'retrofit_by_cron': (
|
|
'config.changed.auto-retrofit',
|
|
'config.changed.frequency',),
|
|
},
|
|
'when_not': {
|
|
'request_credentials': (
|
|
'identity-credentials.available',),
|
|
'snap_install': (
|
|
'snap.installed.octavia-diskimage-retrofit',),
|
|
},
|
|
}
|
|
# test that the hooks were registered via the
|
|
# reactive.barbican_handlers
|
|
self.registered_hooks_test_helper(handlers, hook_set, defaults)
|
|
|
|
|
|
class TestOctaviaDiskimageRetrofitHandlers(test_utils.PatchHelper):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.charm_instance = mock.MagicMock()
|
|
self.patch_object(handlers.charm, 'provide_charm_instance',
|
|
new=mock.MagicMock())
|
|
self.provide_charm_instance().__enter__.return_value = \
|
|
self.charm_instance
|
|
self.provide_charm_instance().__exit__.return_value = None
|
|
|
|
def test_request_credentials(self):
|
|
self.patch_object(handlers.reactive, 'endpoint_from_flag')
|
|
self.endpoint_from_flag.return_value = 'endpoint'
|
|
handlers.request_credentials()
|
|
self.endpoint_from_flag.assert_called_once_with(
|
|
'identity-credentials.connected')
|
|
self.charm_instance.request_credentials.assert_called_once_with(
|
|
'endpoint')
|
|
self.charm_instance.assess_status.assert_called_once_with()
|
|
|
|
def test_credentials_available(self):
|
|
handlers.credentials_available()
|
|
self.charm_instance.assess_status.assert_called_once_with()
|
|
|
|
|
|
class TestValidateSnapRisk(unittest.TestCase):
|
|
|
|
def test_valid_risk_only(self):
|
|
for risk in ('stable', 'candidate', 'beta', 'edge'):
|
|
with self.subTest(risk=risk):
|
|
self.assertTrue(handlers.validate_snap_risk(risk))
|
|
|
|
def test_valid_channel_with_track(self):
|
|
self.assertTrue(handlers.validate_snap_risk('0.10/stable'))
|
|
self.assertTrue(handlers.validate_snap_risk('latest/edge'))
|
|
self.assertTrue(handlers.validate_snap_risk('1.0/candidate'))
|
|
self.assertTrue(handlers.validate_snap_risk('2/beta'))
|
|
|
|
def test_invalid_risk_only(self):
|
|
self.assertFalse(handlers.validate_snap_risk('invalid'))
|
|
self.assertFalse(handlers.validate_snap_risk(''))
|
|
self.assertFalse(handlers.validate_snap_risk('stable/edge'))
|
|
|
|
def test_invalid_risk_with_track(self):
|
|
self.assertFalse(handlers.validate_snap_risk('0.10/invalid'))
|
|
self.assertFalse(handlers.validate_snap_risk('latest/'))
|
|
self.assertFalse(handlers.validate_snap_risk('latest/nightly'))
|