Migrate to python3 only charm

Change-Id: Ia4bcf570d40083625358fdd4fea14202ff3d89af
This commit is contained in:
Alex Kavanagh 2019-01-30 10:57:27 +00:00
parent a070870967
commit 834cde35ec
167 changed files with 146 additions and 58 deletions

View File

@ -1,4 +1,3 @@
- project:
templates:
- python-charm-jobs
- openstack-python35-jobs-nonvoting
- python35-charm-jobs

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# Copyright 2016 Canonical Ltd
#
@ -17,13 +17,23 @@
import os
import sys
sys.path.append('hooks/')
_path = os.path.dirname(os.path.realpath(__file__))
_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
_root = os.path.abspath(os.path.join(_path, '..'))
def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_hooks)
_add_path(_root)
from charmhelpers.core.hookenv import action_fail
from cinder_utils import (
pause_unit_helper,
resume_unit_helper,
register_configs,
resume_unit_helper,
)
import cinder_manage
@ -57,7 +67,7 @@ def main(args):
try:
action = ACTIONS[action_name]
except KeyError:
return "Action %s undefined" % action_name
return "Action {} undefined".format(action_name)
else:
try:
action(args)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2016 Canonical Ltd
#
@ -14,21 +14,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import subprocess
import sys
import traceback
import subprocess
sys.path.append('hooks/')
_path = os.path.dirname(os.path.realpath(__file__))
_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
_root = os.path.abspath(os.path.join(_path, '..'))
def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_hooks)
_add_path(_root)
from charmhelpers.contrib.openstack.utils import (
os_release,
CompareOpenStackReleases,
os_release,
)
from charmhelpers.core.hookenv import (
action_set,
action_fail,
action_get,
action_set,
log,
)
@ -50,14 +62,42 @@ class CinderService():
def cinder_manage_remove(binary, hostname):
return subprocess.check_call(["cinder-manage", "service", "remove", binary,
hostname])
"""Call cinder-manage service remove <binary> <hostname>
:param binary: The binary (executable) for the service to remove
:type binary: str
:param hostname: The host name associated with the binary
:type hostname: str
:returns: 0 if the cinder-manage service command succeeds
:rtype: int
:raises: subprocess.CalledProcessError if the call fails
"""
return (subprocess
.check_call(["cinder-manage",
"service",
"remove",
binary,
hostname]))
def cinder_manage_volume_update_host(currenthost, newhost):
return subprocess.check_call(["cinder-manage", "volume", "update_host",
"--currenthost", currenthost,
"--newhost", newhost])
"""Call cinder-manage volume update_host --currenthost <current-host> \\
--newhost <newhost>
:param currenthost: the hostname to update to newhost
:type currenthost: str
:param newhost: the new name to update the host to
:type newhost: str
:returns: 0 if the cinder-manage volume command succeeds
:rtype: int
:raises: subprocess.CalledProcessError if the call fails
"""
return (subprocess
.check_call(["cinder-manage",
"volume",
"update_host",
"--currenthost", currenthost,
"--newhost", newhost]))
def cinder_manage_service_list():
@ -83,15 +123,16 @@ def remove_services(args):
removed_services = []
for service in services:
log("Removing binary:%s, hostname:%s" % (service.binary, service.host))
log("Removing binary:{}, hostname:{}"
.format(service.binary, service.host))
try:
if CompareOpenStackReleases(os_release("cinder")) >= "liberty":
cinder_manage_remove(service.binary, service.host)
else:
action_fail("Cannot remove service: %s" % service.host)
action_fail("Cannot remove service: {}".format(service.host))
except:
action_set({'traceback': traceback.format_exc()})
action_fail("Cannot remove service: %s" % service.host)
action_fail("Cannot remove service: {}".format(service.host))
else:
removed_services.append(service.host)
@ -108,10 +149,8 @@ def _rename_volume_host(currenthost, newhost):
action_set({'traceback': traceback.format_exc()})
action_fail("Cannot update host {}".format(currenthost))
else:
action_fail(
"Cannot update host attribute from {}, {} not found".format(
currenthost,
currenthost))
action_fail("Cannot update host attribute from {}, {} not found"
.format(currenthost, currenthost))
def rename_volume_host(args):

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# Copyright 2016 Canonical Ltd
#
@ -14,10 +14,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import uuid
sys.path.append('hooks/')
_path = os.path.dirname(os.path.realpath(__file__))
_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
_root = os.path.abspath(os.path.join(_path, '..'))
def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_hooks)
_add_path(_root)
from charmhelpers.contrib.openstack.utils import (
do_action_openstack_upgrade,

View File

@ -1,5 +1,5 @@
repo: https://github.com/juju/charm-helpers
destination: hooks/charmhelpers
destination: charmhelpers
include:
- core
- osplatform

Some files were not shown because too many files have changed in this diff Show More