Browse Source

Merge "Fix action Apply ignoring managed-by arg" into stable/rocky

changes/32/698932/1
Zuul Gerrit Code Review 5 months ago
parent
commit
2852a28e31
3 changed files with 80 additions and 10 deletions
  1. +1
    -1
      paunch/cmd.py
  2. +48
    -9
      paunch/runner.py
  3. +31
    -0
      paunch/tests/test_builder_compose1.py

+ 1
- 1
paunch/cmd.py View File

@@ -71,7 +71,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
)



+ 48
- 9
paunch/runner.py View File

@@ -53,9 +53,20 @@ class DockerRunner(object):
'--format', '{{.Label "config_id"}}'
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
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.docker_cmd, 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--format', '{{.Label "config_id"}}'
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
if returncode != 0:
return set()
results += cmd_stdout.split()
return set(results)

def containers_in_config(self, conf_id):
cmd = [
@@ -64,10 +75,21 @@ class DockerRunner(object):
'--filter', 'label=config_id=%s' % conf_id
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
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.docker_cmd, 'ps', '-q', '-a',
'--filter', 'label=managed_by=paunch',
'--filter', 'label=config_id=%s' % conf_id
]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
if returncode != 0:
return []
results += cmd_stdout.split()

return [c for c in cmd_stdout.split()]
return [c for c in results]

def remove_containers(self, conf_id):
for container in self.containers_in_config(conf_id):
@@ -94,9 +116,26 @@ class DockerRunner(object):
'--format', '{{.Names}} {{.Label "container_name"}}'
))
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
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.docker_cmd, 'ps', '-a',
'--filter', 'label=managed_by=paunch'
]
if conf_id:
cmd.extend((
'--filter', 'label=config_id=%s' % conf_id
))
cmd.extend((
'--format', '{{.Names}} {{.Label "container_name"}}'
))
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
if returncode != 0:
return
results += cmd_stdout.split("\n")
for line in results:
if line:
yield line.split()



+ 31
- 0
paunch/tests/test_builder_compose1.py View File

@@ -60,8 +60,11 @@ class TestComposeV1Builder(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),
@@ -116,12 +119,25 @@ class TestComposeV1Builder(base.TestCase):
'--filter', 'label=config_id=foo',
'--format', '{{.Names}} {{.Label "container_name"}}']
),
# 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"}}']
),
# ps for after delete_missing_and_updated renames
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=tester',
'--format', '{{.Names}} {{.Label "container_name"}}']
),
# ps2 for after delete_missing_and_updated renames
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--format', '{{.Names}} {{.Label "container_name"}}']
),
# ps to only create containers which don't exist
mock.call(
['docker', 'ps', '-a',
@@ -129,6 +145,13 @@ class TestComposeV1Builder(base.TestCase):
'--filter', 'label=config_id=foo',
'--format', '{{.Names}} {{.Label "container_name"}}']
),
# 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"}}']
),
# run one
mock.call(
['docker', 'run', '--name', 'one-12345678',
@@ -222,6 +245,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),
@@ -275,6 +300,12 @@ three-12345678 three''', '', 0),
'--filter', 'label=managed_by=tester',
'--format', '{{.Names}} {{.Label "container_name"}}']
),
# ps2 for after delete_missing_and_updated renames
mock.call(
['docker', 'ps', '-a',
'--filter', 'label=managed_by=paunch',
'--format', '{{.Names}} {{.Label "container_name"}}']
),
# ps to only create containers which don't exist
mock.call(
['docker', 'ps', '-a',


Loading…
Cancel
Save