def init_volume(self, context): """ Create new dir on host, put a file in it, set $context context recursively and check it was set properly. :param context: Desired volume context :return: path to new directory """ if self.config['use_system_tmp']: tmp = '/var/tmp' else: tmp = self.tmpdir volume = tempfile.mkdtemp(prefix=self.__class__.__name__, dir=tmp) if docker_daemon.user_namespaces_enabled(): os.chown(volume, docker_daemon.user_namespaces_uid(), docker_daemon.user_namespaces_gid()) self.sub_stuff['volumes'].add(volume) host_file = os.path.join(volume, "hostfile") open(host_file, 'w').write("01") set_selinux_context(volume, context, True) _context = get_selinux_context(volume) self.failif(context not in _context, "Newly set context was not set" " properly (set %s, get %s)" % (context, _context)) self.check_context_recursive(volume, _context) return volume
def initialize(self): super(CpBase, self).initialize() set_selinux_context(self.tmpdir) dc = self.sub_stuff['dc'] = DockerContainers(self) self.sub_stuff['di'] = DockerImages(self) container_name = dc.get_unique_name() self.sub_stuff['container_name'] = container_name fqin = DockerImage.full_name_from_defaults(self.config) self.sub_stuff['fqin'] = fqin
def initialize(self): super(CpBase, self).initialize() set_selinux_context(self.tmpdir) dc = self.sub_stuff["dc"] = DockerContainers(self) self.sub_stuff["di"] = DockerImages(self) container_name = dc.get_unique_name() self.sub_stuff["container_name"] = container_name fqin = DockerImage.full_name_from_defaults(self.config) self.sub_stuff["fqin"] = fqin
def init_static_data(self): volume = self.sub_stuff["volume"] = self.tmpdir environment.set_selinux_context(volume, "svirt_sandbox_file_t") start_filename = os.path.join(volume, "start") self.sub_stuff["start_filename"] = start_filename ssfile = open(start_filename, "wb") init_time = str(self.parent_subtest.stuff["init_time"]) ssfile.write(init_time) ssfile.close()
def init_static_data(self): volume = self.sub_stuff['volume'] = self.tmpdir environment.set_selinux_context(volume, "svirt_sandbox_file_t") start_filename = os.path.join(volume, 'start') self.sub_stuff['start_filename'] = start_filename ssfile = open(start_filename, "w") init_time = str(self.parent_subtest.stuff['init_time']) ssfile.write(init_time) ssfile.close()
def initialize(self): super(CpBase, self).initialize() set_selinux_context(self.tmpdir) dc = self.sub_stuff['dc'] = DockerContainers(self, "cli") self.sub_stuff['di'] = DockerImages(self, "cli") container_name = dc.get_unique_name() self.sub_stuff['container_name'] = container_name fqin = DockerImage.full_name_from_defaults(self.config) self.sub_stuff['fqin'] = fqin
def init_volume(self, context): """ Create new dir on host, put a file in it, set $context context recursively and check it was set properly. :param context: Desired volume context :return: path to new directory """ if self.config['use_system_tmp']: tmp = '/var/tmp' else: tmp = self.tmpdir volume = tempfile.mkdtemp(prefix=self.__class__.__name__, dir=tmp) self.sub_stuff['volumes'].add(volume) host_file = os.path.join(volume, "hostfile") open(host_file, 'w').write("01") set_selinux_context(volume, context, True) _context = get_selinux_context(volume) self.failif(context not in _context, "Newly set context was not set" " properly (set %s, get %s)" % (context, _context)) self.check_context_recursive(volume, _context) return volume
def set_selinux_context(subtest, host_path): context = subtest.config['selinux_context'].strip() if context != '': environment.set_selinux_context(host_path, context)
def set_selinux_context(pwd, context=None, recursive=True): """ Wrapper around environment.set_selinux_context """ return environment.set_selinux_context(pwd, context, recursive)