Fix action_on_container function
It gets the method to be called directly from the container instance instead of assuming which library is implementing it. Change-Id: Id5fc83b760da294d233342385eb7656c29577e5b
This commit is contained in:
parent
9bfdee622b
commit
138ed62272
@ -1,12 +1,12 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import functools
|
import typing
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import pandas
|
import pandas
|
||||||
import podman1
|
|
||||||
import docker as dockerlib
|
import docker as dockerlib
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
@ -375,26 +375,34 @@ def get_overcloud_container(container_name=None, container_host=None,
|
|||||||
tobiko.fail('container {} not found!'.format(container_name))
|
tobiko.fail('container {} not found!'.format(container_name))
|
||||||
|
|
||||||
|
|
||||||
def action_on_container(action,
|
def action_on_container(action: str,
|
||||||
container_name=None, container_host=None,
|
container_name=None,
|
||||||
|
container_host=None,
|
||||||
partial_container_name=None):
|
partial_container_name=None):
|
||||||
"""take a container snd preform an action on it
|
"""take a container snd preform an action on it
|
||||||
actions are as defined in : podman/libs/containers.py:14/164"""
|
actions are as defined in : podman/libs/containers.py:14/164"""
|
||||||
|
|
||||||
|
LOG.debug(f"Executing '{action}' action on container "
|
||||||
|
f"'{container_name}@{container_host}'...")
|
||||||
container = get_overcloud_container(
|
container = get_overcloud_container(
|
||||||
container_name=container_name,
|
container_name=container_name,
|
||||||
container_host=container_host,
|
container_host=container_host,
|
||||||
partial_container_name=partial_container_name)
|
partial_container_name=partial_container_name)
|
||||||
|
|
||||||
|
container_class: typing.Type = type(container)
|
||||||
# we get the specified action as function from podman lib
|
# we get the specified action as function from podman lib
|
||||||
if container_runtime_module == podman:
|
action_method: typing.Optional[typing.Callable] = getattr(
|
||||||
container_function = getattr(
|
container_class, action, None)
|
||||||
podman1.libs.containers.Container, # pylint: disable=E1101
|
if action_method is None:
|
||||||
'{}'.format(action))
|
raise TypeError(f"Unsupported container action for class :"
|
||||||
else:
|
f" {container_class}")
|
||||||
container_function = getattr(
|
if not callable(action_method):
|
||||||
dockerlib.models.containers.Container, '{}'.format(action))
|
raise TypeError(
|
||||||
LOG.info('action_on_container: executing : {} on {}'.format(action,
|
f"Attribute '{container_class.__qualname__}.{action}' value "
|
||||||
container))
|
f" is not a method: {action_method!r}")
|
||||||
return container_function(container)
|
LOG.debug(f"Calling '{action_method}' action on container "
|
||||||
|
f"'{container}'")
|
||||||
|
return action_method(container)
|
||||||
|
|
||||||
|
|
||||||
def get_container_states_list(containers_list,
|
def get_container_states_list(containers_list,
|
||||||
|
Loading…
Reference in New Issue
Block a user