Other helper functions and utilities¶
-
exception
conu.utils.CommandDoesNotExistException¶ Requested command is not present on the system
-
conu.utils.check_docker_command_works()¶ Verify that dockerd and docker binary works fine. This is performed by calling docker version, which also checks server API version.
Returns: bool, True if all is good, otherwise ConuException or CommandDoesNotExistException is thrown
-
conu.utils.check_port(port, host, timeout=10)¶ connect to port on host and return True on success
Parameters: - port – int, port to check
- host – string, host address
- timeout – int, number of seconds spent trying
Returns: bool
-
conu.utils.command_exists(command, noop_invocation, exc_msg)¶ Verify that the provided command exists. Raise CommandDoesNotExistException in case of an error or if the command does not exist.
Parameters: - command – str, command to check (python 3 only)
- noop_invocation – list of str, command to check (python 2 only)
- exc_msg – str, message of exception when command does not exist
Returns: bool, True if everything’s all right (otherwise exception is thrown)
-
conu.utils.get_selinux_status()¶ get SELinux status of host
Returns: string, one of Enforced, Permissive, Disabled
-
conu.utils.graceful_get(d, *args)¶ Obtain values from dicts and lists gracefully. Example:
print(graceful_get({"a": [{1: 2}, {"b": "c"}]}, "a", "b")) c
Parameters: - d – collection (usually a dict or list)
- args – list of keys which are used as a lookup
Returns: the value from your collection
-
conu.utils.is_selinux_disabled()¶ check if SELinux is disabled
Returns: bool, True if disabled, False otherwise
-
conu.utils.mkdtemp()¶ calls tempfile.mkdtemp, the temporary directory is prefixed with ‘conu-‘
Returns: str, path to the directory
-
conu.utils.mkstemp(dir=None)¶ calls tempfile.mkstemp, the temporary file is prefixed with ‘conu-‘
Parameters: dir – str, path to dir where the temporary file should be created Returns: tuple, (fd, filename)
-
conu.utils.random_str(size=10)¶ create random string of selected size
Parameters: size – int, length of the string Returns: the string
-
conu.utils.random_tmp_filename()¶ generate string which can be used as a filename for temporary file
-
conu.utils.run_cmd(cmd, return_output=False, **kwargs)¶ run provided command on host system using the same user as you invoked this code, raises subprocess.CalledProcessError if it fails
Parameters: - cmd – list of str
- return_output – bool, return output of the command
- kwargs – pass keyword arguments to subprocess.check_* functions; for more info, please check help(subprocess.Popen)
Returns: None or str