summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hooks/charmhelpers/contrib/openstack/amulet/utils.py3
-rw-r--r--hooks/charmhelpers/contrib/openstack/context.py8
-rw-r--r--hooks/charmhelpers/contrib/openstack/utils.py30
-rw-r--r--hooks/charmhelpers/core/hookenv.py3
-rw-r--r--hooks/charmhelpers/fetch/__init__.py2
-rw-r--r--hooks/charmhelpers/fetch/bzrurl.py4
-rw-r--r--hooks/charmhelpers/fetch/giturl.py4
-rw-r--r--hooks/charmhelpers/fetch/ubuntu.py20
-rwxr-xr-xhooks/nova_cc_hooks.py24
l---------hooks/post-series-upgrade1
l---------hooks/pre-series-upgrade1
-rw-r--r--unit_tests/test_nova_cc_hooks.py1
12 files changed, 95 insertions, 6 deletions
diff --git a/hooks/charmhelpers/contrib/openstack/amulet/utils.py b/hooks/charmhelpers/contrib/openstack/amulet/utils.py
index 6637865..936b403 100644
--- a/hooks/charmhelpers/contrib/openstack/amulet/utils.py
+++ b/hooks/charmhelpers/contrib/openstack/amulet/utils.py
@@ -1013,6 +1013,9 @@ class OpenStackAmuletUtils(AmuletUtils):
1013 cmd, code, output)) 1013 cmd, code, output))
1014 amulet.raise_status(amulet.FAIL, msg=msg) 1014 amulet.raise_status(amulet.FAIL, msg=msg)
1015 1015
1016 # For mimic ceph osd lspools output
1017 output = output.replace("\n", ",")
1018
1016 # Example output: 0 data,1 metadata,2 rbd,3 cinder,4 glance, 1019 # Example output: 0 data,1 metadata,2 rbd,3 cinder,4 glance,
1017 for pool in str(output).split(','): 1020 for pool in str(output).split(','):
1018 pool_id_name = pool.split(' ') 1021 pool_id_name = pool.split(' ')
diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py
index ca91396..92cb742 100644
--- a/hooks/charmhelpers/contrib/openstack/context.py
+++ b/hooks/charmhelpers/contrib/openstack/context.py
@@ -1519,6 +1519,14 @@ class NeutronAPIContext(OSContextGenerator):
1519 'rel_key': 'enable-qos', 1519 'rel_key': 'enable-qos',
1520 'default': False, 1520 'default': False,
1521 }, 1521 },
1522 'enable_nsg_logging': {
1523 'rel_key': 'enable-nsg-logging',
1524 'default': False,
1525 },
1526 'nsg_log_output_base': {
1527 'rel_key': 'nsg-log-output-base',
1528 'default': None,
1529 },
1522 } 1530 }
1523 ctxt = self.get_neutron_options({}) 1531 ctxt = self.get_neutron_options({})
1524 for rid in relation_ids('neutron-plugin-api'): 1532 for rid in relation_ids('neutron-plugin-api'):
diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py
index 24f5b80..ae48d6b 100644
--- a/hooks/charmhelpers/contrib/openstack/utils.py
+++ b/hooks/charmhelpers/contrib/openstack/utils.py
@@ -186,7 +186,7 @@ SWIFT_CODENAMES = OrderedDict([
186 ('queens', 186 ('queens',
187 ['2.16.0', '2.17.0']), 187 ['2.16.0', '2.17.0']),
188 ('rocky', 188 ('rocky',
189 ['2.18.0']), 189 ['2.18.0', '2.19.0']),
190]) 190])
191 191
192# >= Liberty version->codename mapping 192# >= Liberty version->codename mapping
@@ -1733,3 +1733,31 @@ def is_unit_upgrading_set():
1733 return not(not(kv.get('unit-upgrading'))) 1733 return not(not(kv.get('unit-upgrading')))
1734 except Exception: 1734 except Exception:
1735 return False 1735 return False
1736
1737
1738def series_upgrade_prepare(pause_unit_helper=None, configs=None):
1739 """ Run common series upgrade prepare tasks.
1740
1741 :param pause_unit_helper: function: Function to pause unit
1742 :param configs: OSConfigRenderer object: Configurations
1743 :returns None:
1744 """
1745 set_unit_upgrading()
1746 if pause_unit_helper and configs:
1747 if not is_unit_paused_set():
1748 pause_unit_helper(configs)
1749
1750
1751def series_upgrade_complete(resume_unit_helper=None, configs=None):
1752 """ Run common series upgrade complete tasks.
1753
1754 :param resume_unit_helper: function: Function to resume unit
1755 :param configs: OSConfigRenderer object: Configurations
1756 :returns None:
1757 """
1758 clear_unit_paused()
1759 clear_unit_upgrading()
1760 if configs:
1761 configs.write_all()
1762 if resume_unit_helper:
1763 resume_unit_helper(configs)
diff --git a/hooks/charmhelpers/core/hookenv.py b/hooks/charmhelpers/core/hookenv.py
index 6880007..9abf2a4 100644
--- a/hooks/charmhelpers/core/hookenv.py
+++ b/hooks/charmhelpers/core/hookenv.py
@@ -48,6 +48,7 @@ INFO = "INFO"
48DEBUG = "DEBUG" 48DEBUG = "DEBUG"
49TRACE = "TRACE" 49TRACE = "TRACE"
50MARKER = object() 50MARKER = object()
51SH_MAX_ARG = 131071
51 52
52cache = {} 53cache = {}
53 54
@@ -98,7 +99,7 @@ def log(message, level=None):
98 command += ['-l', level] 99 command += ['-l', level]
99 if not isinstance(message, six.string_types): 100 if not isinstance(message, six.string_types):
100 message = repr(message) 101 message = repr(message)
101 command += [message] 102 command += [message[:SH_MAX_ARG]]
102 # Missing juju-log should not cause failures in unit tests 103 # Missing juju-log should not cause failures in unit tests
103 # Send log output to stderr 104 # Send log output to stderr
104 try: 105 try:
diff --git a/hooks/charmhelpers/fetch/__init__.py b/hooks/charmhelpers/fetch/__init__.py
index 480a627..8572d34 100644
--- a/hooks/charmhelpers/fetch/__init__.py
+++ b/hooks/charmhelpers/fetch/__init__.py
@@ -84,6 +84,7 @@ module = "charmhelpers.fetch.%s" % __platform__
84fetch = importlib.import_module(module) 84fetch = importlib.import_module(module)
85 85
86filter_installed_packages = fetch.filter_installed_packages 86filter_installed_packages = fetch.filter_installed_packages
87filter_missing_packages = fetch.filter_missing_packages
87install = fetch.apt_install 88install = fetch.apt_install
88upgrade = fetch.apt_upgrade 89upgrade = fetch.apt_upgrade
89update = _fetch_update = fetch.apt_update 90update = _fetch_update = fetch.apt_update
@@ -96,6 +97,7 @@ if __platform__ == "ubuntu":
96 apt_update = fetch.apt_update 97 apt_update = fetch.apt_update
97 apt_upgrade = fetch.apt_upgrade 98 apt_upgrade = fetch.apt_upgrade
98 apt_purge = fetch.apt_purge 99 apt_purge = fetch.apt_purge
100 apt_autoremove = fetch.apt_autoremove
99 apt_mark = fetch.apt_mark 101 apt_mark = fetch.apt_mark
100 apt_hold = fetch.apt_hold 102 apt_hold = fetch.apt_hold
101 apt_unhold = fetch.apt_unhold 103 apt_unhold = fetch.apt_unhold
diff --git a/hooks/charmhelpers/fetch/bzrurl.py b/hooks/charmhelpers/fetch/bzrurl.py
index 07cd029..c4ab3ff 100644
--- a/hooks/charmhelpers/fetch/bzrurl.py
+++ b/hooks/charmhelpers/fetch/bzrurl.py
@@ -13,7 +13,7 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import os 15import os
16from subprocess import check_call 16from subprocess import STDOUT, check_output
17from charmhelpers.fetch import ( 17from charmhelpers.fetch import (
18 BaseFetchHandler, 18 BaseFetchHandler,
19 UnhandledSource, 19 UnhandledSource,
@@ -55,7 +55,7 @@ class BzrUrlFetchHandler(BaseFetchHandler):
55 cmd = ['bzr', 'branch'] 55 cmd = ['bzr', 'branch']
56 cmd += cmd_opts 56 cmd += cmd_opts
57 cmd += [source, dest] 57 cmd += [source, dest]
58 check_call(cmd) 58 check_output(cmd, stderr=STDOUT)
59 59
60 def install(self, source, dest=None, revno=None): 60 def install(self, source, dest=None, revno=None):
61 url_parts = self.parse_url(source) 61 url_parts = self.parse_url(source)
diff --git a/hooks/charmhelpers/fetch/giturl.py b/hooks/charmhelpers/fetch/giturl.py
index 4cf21bc..070ca9b 100644
--- a/hooks/charmhelpers/fetch/giturl.py
+++ b/hooks/charmhelpers/fetch/giturl.py
@@ -13,7 +13,7 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import os 15import os
16from subprocess import check_call, CalledProcessError 16from subprocess import check_output, CalledProcessError, STDOUT
17from charmhelpers.fetch import ( 17from charmhelpers.fetch import (
18 BaseFetchHandler, 18 BaseFetchHandler,
19 UnhandledSource, 19 UnhandledSource,
@@ -50,7 +50,7 @@ class GitUrlFetchHandler(BaseFetchHandler):
50 cmd = ['git', 'clone', source, dest, '--branch', branch] 50 cmd = ['git', 'clone', source, dest, '--branch', branch]
51 if depth: 51 if depth:
52 cmd.extend(['--depth', depth]) 52 cmd.extend(['--depth', depth])
53 check_call(cmd) 53 check_output(cmd, stderr=STDOUT)
54 54
55 def install(self, source, branch="master", dest=None, depth=None): 55 def install(self, source, branch="master", dest=None, depth=None):
56 url_parts = self.parse_url(source) 56 url_parts = self.parse_url(source)
diff --git a/hooks/charmhelpers/fetch/ubuntu.py b/hooks/charmhelpers/fetch/ubuntu.py
index 19aa6ba..ec08cbc 100644
--- a/hooks/charmhelpers/fetch/ubuntu.py
+++ b/hooks/charmhelpers/fetch/ubuntu.py
@@ -189,6 +189,18 @@ def filter_installed_packages(packages):
189 return _pkgs 189 return _pkgs
190 190
191 191
192def filter_missing_packages(packages):
193 """Return a list of packages that are installed.
194
195 :param packages: list of packages to evaluate.
196 :returns list: Packages that are installed.
197 """
198 return list(
199 set(packages) -
200 set(filter_installed_packages(packages))
201 )
202
203
192def apt_cache(in_memory=True, progress=None): 204def apt_cache(in_memory=True, progress=None):
193 """Build and return an apt cache.""" 205 """Build and return an apt cache."""
194 from apt import apt_pkg 206 from apt import apt_pkg
@@ -248,6 +260,14 @@ def apt_purge(packages, fatal=False):
248 _run_apt_command(cmd, fatal) 260 _run_apt_command(cmd, fatal)
249 261
250 262
263def apt_autoremove(purge=True, fatal=False):
264 """Purge one or more packages."""
265 cmd = ['apt-get', '--assume-yes', 'autoremove']
266 if purge:
267 cmd.append('--purge')
268 _run_apt_command(cmd, fatal)
269
270
251def apt_mark(packages, mark, fatal=False): 271def apt_mark(packages, mark, fatal=False):
252 """Flag one or more packages using apt-mark.""" 272 """Flag one or more packages using apt-mark."""
253 log("Marking {} as {}".format(packages, mark)) 273 log("Marking {} as {}".format(packages, mark))
diff --git a/hooks/nova_cc_hooks.py b/hooks/nova_cc_hooks.py
index 89d108d..c6c1305 100755
--- a/hooks/nova_cc_hooks.py
+++ b/hooks/nova_cc_hooks.py
@@ -66,6 +66,8 @@ from charmhelpers.contrib.openstack.utils import (
66 pausable_restart_on_change as restart_on_change, 66 pausable_restart_on_change as restart_on_change,
67 is_unit_paused_set, 67 is_unit_paused_set,
68 CompareOpenStackReleases, 68 CompareOpenStackReleases,
69 series_upgrade_prepare,
70 series_upgrade_complete,
69) 71)
70 72
71from charmhelpers.contrib.openstack.neutron import ( 73from charmhelpers.contrib.openstack.neutron import (
@@ -112,6 +114,8 @@ from nova_cc_utils import (
112 assess_status, 114 assess_status,
113 update_aws_compat_services, 115 update_aws_compat_services,
114 serial_console_settings, 116 serial_console_settings,
117 pause_unit_helper,
118 resume_unit_helper,
115) 119)
116 120
117from charmhelpers.contrib.hahelpers.cluster import ( 121from charmhelpers.contrib.hahelpers.cluster import (
@@ -282,6 +286,12 @@ def install():
282@restart_on_change(restart_map(), stopstart=True) 286@restart_on_change(restart_map(), stopstart=True)
283@harden() 287@harden()
284def config_changed(): 288def config_changed():
289 # if we are paused, delay doing any config changed hooks.
290 # It is forced on the resume.
291 if is_unit_paused_set():
292 log("Unit is pause or upgrading. Skipping config_changed", "WARN")
293 return
294
285 # neutron-server runs if < juno. Neutron-server creates mysql tables 295 # neutron-server runs if < juno. Neutron-server creates mysql tables
286 # which will subsequently cause db migrations to fail if >= juno. 296 # which will subsequently cause db migrations to fail if >= juno.
287 # Disable neutron-server if >= juno 297 # Disable neutron-server if >= juno
@@ -1133,6 +1143,20 @@ def update_status():
1133 log('Updating status.') 1143 log('Updating status.')
1134 1144
1135 1145
1146@hooks.hook('pre-series-upgrade')
1147def pre_series_upgrade():
1148 log("Running prepare series upgrade hook", "INFO")
1149 series_upgrade_prepare(
1150 pause_unit_helper, CONFIGS)
1151
1152
1153@hooks.hook('post-series-upgrade')
1154def post_series_upgrade():
1155 log("Running complete series upgrade hook", "INFO")
1156 series_upgrade_complete(
1157 resume_unit_helper, CONFIGS)
1158
1159
1136def main(): 1160def main():
1137 try: 1161 try:
1138 hooks.execute(sys.argv) 1162 hooks.execute(sys.argv)
diff --git a/hooks/post-series-upgrade b/hooks/post-series-upgrade
new file mode 120000
index 0000000..f670241
--- /dev/null
+++ b/hooks/post-series-upgrade
@@ -0,0 +1 @@
nova_cc_hooks.py \ No newline at end of file
diff --git a/hooks/pre-series-upgrade b/hooks/pre-series-upgrade
new file mode 120000
index 0000000..f670241
--- /dev/null
+++ b/hooks/pre-series-upgrade
@@ -0,0 +1 @@
nova_cc_hooks.py \ No newline at end of file
diff --git a/unit_tests/test_nova_cc_hooks.py b/unit_tests/test_nova_cc_hooks.py
index 489b6c5..8d62647 100644
--- a/unit_tests/test_nova_cc_hooks.py
+++ b/unit_tests/test_nova_cc_hooks.py
@@ -115,6 +115,7 @@ class NovaCCHooksTests(CharmTestCase):
115 self.config.side_effect = self.test_config.get 115 self.config.side_effect = self.test_config.get
116 self.relation_get.side_effect = self.test_relation.get 116 self.relation_get.side_effect = self.test_relation.get
117 self.charm_dir.return_value = '/var/lib/juju/charms/nova/charm' 117 self.charm_dir.return_value = '/var/lib/juju/charms/nova/charm'
118 self.is_unit_paused_set.return_value = False
118 119
119 def tearDown(self): 120 def tearDown(self):
120 try: 121 try: