本文整理汇总了Python中dockertest.dockercmd.NoFailDockerCmd类的典型用法代码示例。如果您正苦于以下问题:Python NoFailDockerCmd类的具体用法?Python NoFailDockerCmd怎么用?Python NoFailDockerCmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NoFailDockerCmd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_once
def run_once(self):
super(events, self).run_once()
dc = self.stuff['dc']
# Start listening
self.stuff['events_cmd'].execute()
# Do something to make new events
cmdresult = self.stuff['nfdc'].execute()
cid = self.stuff['nfdc_cid'] = cmdresult.stdout.strip()
while True:
_json = dc.json_by_long_id(cid)
if len(_json) > 0 and _json[0]["State"]["Running"]:
self.loginfo("Waiting for test container to exit...")
time.sleep(3)
else:
break
if self.config['rm_after_run']:
self.loginfo("Removing test container...")
try:
dc.kill_container_by_long_id(cid)
except ValueError:
pass # container isn't running, this is fine.
dcmd = NoFailDockerCmd(self, 'rm', ['--force', '--volumes', cid])
dcmd.execute()
# No way to know how long async events take to pass through :S
self.loginfo("Sleeping %s seconds for events to catch up",
self.config['wait_stop'])
time.sleep(self.config['wait_stop'])
# Kill off docker events after 1 second
events_cmd = self.stuff['events_cmd']
self.stuff['events_cmdresult'] = events_cmd.wait(timeout=1)
示例2: lookup_image_id
def lookup_image_id(self, image_name, image_tag):
# FIXME: We need a standard way to do this
image_id = None
# Any API failures must not be fatal
if DOCKERAPI:
client = docker.Client()
results = client.images(name=image_name)
image = None
if len(results) == 1:
image = results[0]
# Could be unicode strings
if ((str(image['Repository']) == image_name) and
(str(image['Tag']) == image_tag)):
image_id = image.get('Id')
if ((image_id is None) or (len(image_id) < 12)):
logging.error("Could not lookup image %s:%s Id using "
"docker python API Data: '%s'",
image_name, image_tag, str(image))
image_id = None
# Don't have DOCKERAPI or API failed (still need image ID)
if image_id is None:
subargs = ['--quiet', image_name]
dkrcmd = NoFailDockerCmd(self.parent_subtest, 'images', subargs)
# fail -> raise exception
cmdresult = dkrcmd.execute()
stdout_strip = cmdresult.stdout.strip()
# TODO: Better image ID validity check?
if len(stdout_strip) == 12:
image_id = stdout_strip
else:
self.loginfo("Error retrieving image id, unexpected length")
if image_id is not None:
self.loginfo("Found image Id '%s'", image_id)
return image_id
示例3: run_once
def run_once(self):
super(memory_base, self).run_once()
for subargs in self.sub_stuff['subargs']:
if self.config['expect_success'] == "PASS":
memory_container = NoFailDockerCmd(self,
'run -d -t',
subargs).execute()
long_id = self.container_json(str(subargs[0]).split('=')[1],
'Id')
memory_arg = self.get_value_from_arg(
self.get_arg_from_arglist(subargs, '-m'), ' ', 1)
memory = self.split_unit(memory_arg)
memory_value = memory[0]
memory_unit = memory[1]
cgpath = self.config['cgroup_path']
cgvalue = self.config['cgroup_key_value']
cgroup_memory = self.read_cgroup(long_id, cgpath, cgvalue)
self.sub_stuff['result'].append(self.check_memory(
memory_value, cgroup_memory, memory_unit))
else:
memory_container = MustFailDockerCmd(self,
'run',
subargs)
# throws exception if exit_status == 0
self.sub_stuff['result'] = memory_container.execute()
示例4: init_ei_dockercmd
def init_ei_dockercmd(self, export_arg_csv, import_arg_csv):
# Never execute()'d, just used for command property
import_dkrcmd = DockerCmd(self, "import", import_arg_csv.split(','))
# Actually executed command
export_args = export_arg_csv.split(',')
export_args.append(import_dkrcmd.command)
export_import_dkrcmd = NoFailDockerCmd(self, "export", export_args)
export_import_dkrcmd.verbose = True
self.sub_stuff['export_import_dkrcmd'] = export_import_dkrcmd
示例5: cleanup
def cleanup(self):
super(psa, self).cleanup()
cid = self.stuff.get('container_id')
if self.config['remove_after_test'] and cid is not None:
self.logdebug("Cleaning container %s", cid)
# We need to know about this breaking anyway, let it raise!
nfdc = NoFailDockerCmd(self, "rm", ['--force',
'--volumes', cid])
nfdc.execute()
示例6: initialize
def initialize(self):
super(diff_base, self).initialize()
dc = DockerContainers(self.parent_subtest)
name = self.sub_stuff['name'] = dc.get_unique_name()
fin = DockerImage.full_name_from_defaults(self.config)
subargs = ['--name=%s' % (name), fin]
subargs = subargs + self.config['command'].split(',')
nfdc = NoFailDockerCmd(self, 'run', subargs)
nfdc.execute()
示例7: run_once
def run_once(self):
super(syslog, self).run_once()
subargs = [self.stuff['name'],
self.stuff['params'],
self.stuff['fin'],
self.stuff['testcmds']]
nfdc = NoFailDockerCmd(self, "run", subargs)
self.stuff['cmdresults'] = nfdc.execute()
示例8: run_once
def run_once(self):
super(help_base, self).run_once() # Prints out basic info
for option in self.sub_stuff['success_option_list']:
# No successful command should throw an exception
dkrcmd = NoFailDockerCmd(self.parent_subtest, option)
self.sub_stuff["success_cmdresults"].append(dkrcmd.execute())
for option in self.sub_stuff['failure_option_list']:
# These are likely to return non-zero
dkrcmd = DockerCmd(self.parent_subtest, option)
self.sub_stuff['failure_cmdresults'].append(dkrcmd.execute())
示例9: cleanup
def cleanup(self):
super(psa, self).cleanup()
# Auto-converts "yes/no" to a boolean
if ( (self.config['remove_after_test']) and
(self.stuff.get('container_id') is not None) ):
long_id = self.stuff['container_id']
# We need to know about this breaking anyway, let it raise!
nfdc = NoFailDockerCmd(self, "rm", ['--force',
'--volumes', long_id])
nfdc.execute()
示例10: run_once
def run_once(self):
super(cp, self).run_once()
#build arg list and execute command
subargs = [self.stuff['container_name'] + ":" + self.stuff['cpfile']]
subargs.append(self.tmpdir)
nfdc = NoFailDockerCmd(self, "cp", subargs,
timeout=self.config['docker_timeout'])
nfdc.execute()
copied_path = "%s/%s" % (self.tmpdir,
self.stuff['cpfile'].split('/')[-1])
self.stuff['copied_path'] = copied_path
示例11: run_once
def run_once(self):
super(insert, self).run_once()
fin = DockerImage.full_name_from_defaults(self.config)
file_path = "/tmp/" + utils.generate_random_string(8)
self.stuff['file_path'] = file_path
subargs = [fin,
self.config['file_url'],
file_path]
nfdc = NoFailDockerCmd(self, "insert", subargs,
timeout=self.config['docker_timeout'])
cmdresult = nfdc.execute()
inserted_image = cmdresult.stdout.split()[-1].strip()
self.stuff['inserted_image'] = inserted_image
示例12: container_json
def container_json(self, name, content):
"""
Return container's json value.
:param name: An existing container's name
:param content: What the json value need get
"""
inspect_id_args = ['--format={{.%s}}' % content]
inspect_id_args.append(name)
container_json = NoFailDockerCmd(self.parent_subtest,
'inspect',
inspect_id_args)
content_value = container_json.execute().stdout.strip()
return content_value
示例13: create_simple_container
def create_simple_container(subtest):
fin = DockerImage.full_name_from_defaults(subtest.config)
name = utils.generate_random_string(12)
subargs = ["--name=%s" % (name),
fin,
"/bin/bash",
"-c",
"'/bin/true'"]
nfdc = NoFailDockerCmd(subtest.parent_subtest, 'run', subargs)
nfdc.execute()
if not subtest.sub_stuff or not subtest.sub_stuff['containers']:
subtest.sub_stuff['containers'] = [name]
else:
subtest.sub_stuff['containers'] += [name]
return name
示例14: initialize
def initialize(self):
super(restart_base, self).initialize()
config.none_if_empty(self.config)
self.sub_stuff['container_id'] = None
self.sub_stuff['restart_cmd'] = None
self.sub_stuff['stop_cmd'] = None
self.sub_stuff['restart_result'] = None
self.sub_stuff['stop_result'] = None
containers = DockerContainers(self.parent_subtest)
# Container
if self.config.get('run_options_csv'):
subargs = [arg for arg in
self.config['run_options_csv'].split(',')]
else:
subargs = []
image = DockerImage.full_name_from_defaults(self.config)
subargs.append(image)
subargs.append("bash")
subargs.append("-c")
subargs.append(self.config['exec_cmd'])
container = NoFailDockerCmd(self, 'run', subargs)
cont_id = container.execute().stdout.strip()
self.sub_stuff['container_id'] = cont_id
container = containers.list_containers_with_cid(cont_id)
if container == []:
raise xceptions.DockerTestNAError("Fail to get docker with id: %s"
% cont_id)
# Prepare the "restart" command
if self.config.get('restart_options_csv'):
subargs = [arg for arg in
self.config['restart_options_csv'].split(',')]
else:
subargs = []
subargs.append(cont_id)
self.sub_stuff['restart_cmd'] = NoFailDockerCmd(self, 'restart',
subargs)
# Prepare the "stop" command
if self.config.get('stop_options_csv'):
subargs = [arg for arg in
self.config['stop_options_csv'].split(',')]
else:
subargs = []
subargs.append(cont_id)
self.sub_stuff['stop_cmd'] = NoFailDockerCmd(self, 'stop', subargs)
示例15: run_once
def run_once(self):
super(workdir, self).run_once()
for name, _dir in self.stuff['good_dirs'].items():
subargs = ['--workdir=%s' % _dir]
subargs.append('--name=%s' % name)
subargs.append(self.stuff['fin'])
subargs.append('pwd')
nfdc = NoFailDockerCmd(self, 'run', subargs)
self.stuff['cmdresults'][name] = nfdc.execute()
for name, _dir in self.stuff['bad_dirs'].items():
subargs = ['--workdir=%s' % _dir]
subargs.append('--name=%s' % name)
subargs.append(self.stuff['fin'])
subargs.append('pwd')
dc = DockerCmd(self, 'run', subargs)
self.stuff['cmdresults'][name] = dc.execute()