Fix action Apply ignoring managed-by arg

From the very beginning (06036fd6db), the
action apply was ignoring the passed --managed-by values and was always
taking defaults ('paunch').

Fix this and provide no upgrade/update impact, which is for whatever
--managed-by value given to paunch, perform all checks and searches
also for that historically "wrong" value 'paunch':

* if a container needs to be (re)started by a new 'managed-by', make sure
  it can be found by the default 'paunch' value as well, then reset its
  managed-by to the desired value.

Closes-bug: #1853812

Change-Id: If129bbc1ff32941d06ff480f26870b10840591e0
Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
(cherry picked from commit 12ccf36b0e)
This commit is contained in:
Bogdan Dobrelya 2019-11-28 15:31:55 +01:00
parent 2875dadd2c
commit 40aba310e8
3 changed files with 84 additions and 10 deletions

View File

@ -95,7 +95,7 @@ class Apply(command.Command):
stdout, stderr, rc = paunch.apply(
parsed_args.config_id,
config,
managed_by='paunch',
managed_by=parsed_args.managed_by,
labels=labels,
cont_cmd=parsed_args.default_runtime,
log_level=log_level,

View File

@ -76,9 +76,20 @@ class BaseRunner(object):
'--format', fmt
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0:
return set()
return set(cmd_stdout.split())
results = cmd_stdout.split()
if returncode != 0 or not results or results == ['']:
# NOTE(bogdando): also look by the historically used to
# be always specified defaults, we must also identify such configs
cmd = [
self.cont_cmd, 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--format', fmt
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0:
return set()
results += cmd_stdout.split()
return set(results)
def containers_in_config(self, conf_id):
cmd = [
@ -87,10 +98,21 @@ class BaseRunner(object):
'--filter', 'label=config_id=%s' % conf_id
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0:
return []
results = cmd_stdout.split()
if returncode != 0 or not results or results == ['']:
# NOTE(bogdando): also look by the historically used to
# be always specified defaults, we must also identify such configs
cmd = [
self.cont_cmd, 'ps', '-q', '-a',
'--filter', 'label=managed_by=paunch',
'--filter', 'label=config_id=%s' % conf_id
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0:
return []
results += cmd_stdout.split()
return [c for c in cmd_stdout.split()]
return [c for c in results]
def inspect(self, name, output_format=None, o_type='container',
quiet=False):
@ -232,9 +254,26 @@ class BaseRunner(object):
'--format', '{{.Names}} %s' % fmt
))
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0:
return
for line in cmd_stdout.split("\n"):
results = cmd_stdout.split("\n")
if returncode != 0 or not results or results == ['']:
# NOTE(bogdando): also look by the historically used to
# be always specified defaults, we must also identify such configs
cmd = [
self.cont_cmd, 'ps', '-a',
'--filter', 'label=managed_by=paunch'
]
if conf_id:
cmd.extend((
'--filter', 'label=config_id=%s' % conf_id
))
cmd.extend((
'--format', '{{.Names}} %s' % fmt
))
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0:
return
results += cmd_stdout.split("\n")
for line in results:
if line:
yield line.split()

View File

@ -62,8 +62,11 @@ class TestBaseBuilder(base.TestCase):
('Pulled centos:7', 'ouch', 1), # pull centos:6 fails
('Pulled centos:7', '', 0), # pull centos:6 succeeds
('', '', 0), # ps for delete_missing_and_updated container_names
('', '', 0), # ps2 for delete_missing_and_updated container_names
('', '', 0), # ps for after delete_missing_and_updated renames
('', '', 0), # ps2 for after delete_missing_and_updated renames
('', '', 0), # ps to only create containers which don't exist
('', '', 0), # ps2 to only create containers which don't exist
('Created one-12345678', '', 0),
('Created two-12345678', '', 0),
('Created three-12345678', '', 0),
@ -119,6 +122,14 @@ class TestBaseBuilder(base.TestCase):
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps2 for delete_missing_and_updated container_names
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--filter', 'label=config_id=foo',
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps for after delete_missing_and_updated renames
mock.call(
['docker', 'ps', '-a',
@ -126,6 +137,13 @@ class TestBaseBuilder(base.TestCase):
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps2 for after delete_missing_and_updated renames
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps to only create containers which don't exist
mock.call(
['docker', 'ps', '-a',
@ -134,6 +152,14 @@ class TestBaseBuilder(base.TestCase):
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps2 to only create containers which don't exist
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--filter', 'label=config_id=foo',
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# run one
mock.call(
['docker', 'run', '--name', 'one-12345678',
@ -232,6 +258,8 @@ three-12345678 three''', '', 0),
('{"start_order": 2, "image": "centos:7"}', '', 0),
# ps for after delete_missing_and_updated renames
('', '', 0),
# ps2 for after delete_missing_and_updated renames
('', '', 0),
# ps to only create containers which don't exist
('three-12345678 three', '', 0),
('Created one-12345678', '', 0),
@ -287,6 +315,13 @@ three-12345678 three''', '', 0),
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps2 for after delete_missing_and_updated renames
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--format', '{{.Names}} {{.Label "container_name"}}'],
mock.ANY
),
# ps to only create containers which don't exist
mock.call(
['docker', 'ps', '-a',