d1fd13261f
All contributors to this charm have agreed to the switch from GPL v3 to Apache 2.0; switch to Apache-2.0 license as agreed so we can move forward with official project status. Change-Id: Iaee75f59fe51f01da18aa2703a46c3885ade73c0
75 lines
2.9 KiB
Python
75 lines
2.9 KiB
Python
# Copyright 2016 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.
|
|
|
|
from mock import patch
|
|
import os
|
|
|
|
os.environ['JUJU_UNIT_NAME'] = 'keystone'
|
|
|
|
import openstack_upgrade
|
|
|
|
from test_utils import (
|
|
CharmTestCase
|
|
)
|
|
|
|
TO_PATCH = [
|
|
'do_openstack_upgrade',
|
|
'os',
|
|
]
|
|
|
|
|
|
class TestKeystoneUpgradeActions(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(TestKeystoneUpgradeActions, self).setUp(openstack_upgrade,
|
|
TO_PATCH)
|
|
|
|
# NOTE(ajkavangh) patching charmhelpers here almost certainly means that
|
|
# these tests are in the wrong place and should be moved. In general
|
|
# tests should only patch objects IN the file under test. Anywhere else
|
|
# creates dependencies that make the code harder to maintain (e.g. here,
|
|
# changes to charmhelpers might break these tests).
|
|
@patch.object(openstack_upgrade, 'register_configs')
|
|
@patch('charmhelpers.contrib.openstack.utils.config')
|
|
@patch('charmhelpers.contrib.openstack.utils.action_set')
|
|
@patch('charmhelpers.contrib.openstack.utils.git_install_requested')
|
|
@patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available')
|
|
def test_openstack_upgrade_true(self, upgrade_avail, git_requested,
|
|
action_set, config, reg_configs):
|
|
git_requested.return_value = False
|
|
upgrade_avail.return_value = True
|
|
config.return_value = True
|
|
|
|
openstack_upgrade.openstack_upgrade()
|
|
|
|
self.assertTrue(self.do_openstack_upgrade.called)
|
|
self.os.execl.assert_called_with('./hooks/config-changed-postupgrade',
|
|
'')
|
|
|
|
@patch.object(openstack_upgrade, 'register_configs')
|
|
@patch('charmhelpers.contrib.openstack.utils.config')
|
|
@patch('charmhelpers.contrib.openstack.utils.action_set')
|
|
@patch('charmhelpers.contrib.openstack.utils.git_install_requested')
|
|
@patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available')
|
|
def test_openstack_upgrade_false(self, upgrade_avail, git_requested,
|
|
action_set, config, reg_configs):
|
|
git_requested.return_value = False
|
|
upgrade_avail.return_value = True
|
|
config.return_value = False
|
|
|
|
openstack_upgrade.openstack_upgrade()
|
|
|
|
self.assertFalse(self.do_openstack_upgrade.called)
|
|
self.assertFalse(self.os.execl.called)
|