Add DockerCommand driver
Introduces a new snapshot driver that is the same as Command driver but prepends 'docker exec ' to each command in the object. Change-Id: I8bf939bdb5a489982bc38257a245b4233103a07a Related-Bug: #1515517
This commit is contained in:
parent
b4a1c1fa2b
commit
f45f78f4aa
|
@ -57,6 +57,7 @@ class Driver(object):
|
|||
"postgres": Postgres,
|
||||
"xmlrpc": XmlRpc,
|
||||
"command": Command,
|
||||
"docker_command": DockerCommand,
|
||||
"offline": Offline,
|
||||
}.get(driver_type, cls)(data, conf)
|
||||
|
||||
|
@ -293,6 +294,16 @@ class Command(Driver):
|
|||
f.write(out.stderr)
|
||||
|
||||
|
||||
class DockerCommand(Command):
|
||||
def __init__(self, data, conf):
|
||||
super(DockerCommand, self).__init__(data, conf)
|
||||
self.cmds = [
|
||||
"docker exec "
|
||||
"$(docker ps -q --filter 'name={0}' --format '{{.Names}}') "
|
||||
"{1}".format(cnt, cmd)
|
||||
for cnt in data["containers"] for cmd in self.cmds]
|
||||
|
||||
|
||||
class Offline(Driver):
|
||||
|
||||
def __init__(self, data, conf):
|
||||
|
|
|
@ -332,6 +332,29 @@ class TestCommand(base.BaseTestCase):
|
|||
file_handle_mock.write.call_args_list)
|
||||
|
||||
|
||||
class TestDockerCommand(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
self.conf = mock.Mock()
|
||||
self.conf.target = '/some/dir'
|
||||
|
||||
def test_init(self):
|
||||
data = {
|
||||
"command": ["cmd1", "cmd2"],
|
||||
"containers": ["cont1", "cont2"],
|
||||
}
|
||||
driver_inst = shotgun.driver.DockerCommand(data, self.conf)
|
||||
template_str = (
|
||||
"docker exec "
|
||||
"$(docker ps -q --filter 'name={0}' --format '{{.Names}}') {1}")
|
||||
expected = [
|
||||
template_str.format("cont1", "cmd1"),
|
||||
template_str.format("cont1", "cmd2"),
|
||||
template_str.format("cont2", "cmd1"),
|
||||
template_str.format("cont2", "cmd2"),
|
||||
]
|
||||
self.assertListEqual(expected, driver_inst.cmds)
|
||||
|
||||
|
||||
class TestOffline(base.BaseTestCase):
|
||||
|
||||
@mock.patch('shotgun.driver.open', create=True,
|
||||
|
|
Loading…
Reference in New Issue