def setUp(self): clear_doms() self.guid = uuid.uuid4() self.run_dir = tempfile.mkdtemp() self.net_dir = os.path.join(self.run_dir, 'etc', 'net.d') os.makedirs(self.net_dir) self.cont_dir = os.path.join(self.run_dir, 'containers') os.makedirs(self.cont_dir) self.exes = FakeCommands() self.svdsm = FakeSuperVdsm(self.exes) self.patch = Patch([ (vdsm.virt.containers.xmlfile, 'STATE_DIR', os.path.join(self.run_dir, 'containers')), (vdsm.virt.containers.command, 'supervdsm', self.svdsm), (vdsm.virt.containers.command, '_SYSTEMCTL', self.exes.systemctl), (vdsm.virt.containers.docker, '_DOCKER', self.exes.docker), ]) self.patch.apply() vdsm.virt.containers.docker.setup_network('test', 'brtest', 'eth1', '192.168.0.1', '192.168.0.0', '24')
def setUp(self): self.pid = 0 testdir = os.path.dirname(os.path.abspath(__file__)) self.root = os.path.join(testdir, 'fake') self.procfsroot = os.path.join(self.root, vdsm.virt.containers.cgroups.PROCFS) self.cgroupfsroot = os.path.join(self.root, vdsm.virt.containers.cgroups.CGROUPFS) with move_into(self.root): cgroupsdata = os.path.join(self.root, 'cgroups.tgz') with gzip.GzipFile(cgroupsdata) as gz: tar = tarfile.TarFile(fileobj=gz) tar.extractall() self.patch = Patch([ (vdsm.virt.containers.cgroups, '_PROCBASE', self.procfsroot), (vdsm.virt.containers.cgroups, '_CGROUPBASE', self.cgroupfsroot), ]) self.patch.apply()
def setUp(self): """ Prepares a workdir and set of files for the TestCase. Avoid requiring root privileges for os.chown call by mkimage._commonCleanFs. Avoid errors creating _P_PAYLOAD_IMAGES """ self.tempdir = mkdtemp(prefix="vdsm-mkimage-tests") self.workdir = os.path.join(self.tempdir, "work") os.mkdir(self.workdir) self.img_dir = os.path.join(self.tempdir, "images") os.mkdir(self.img_dir) self.files = {} self.expected_results = {} self.subdir = os.path.join('a', 'subdirectory', 'for', 'testing') for i in range(5): content = os.urandom(1024) encoded_content = b64encode(content) # the base64-encoded file contents are actually read from the # domain XML, so they're unicode strings in py3 if six.PY3: encoded_content = encoded_content.decode("utf-8") filename = "test_%d" % i longpath = os.path.join(self.subdir, filename) self.expected_results[filename] = content self.files[filename] = encoded_content self.expected_results[longpath] = content self.files[longpath] = encoded_content self.patch = Patch([ (mkimage, "DISKIMAGE_USER", -1), (mkimage, "DISKIMAGE_GROUP", -1), (mkimage, "_P_PAYLOAD_IMAGES", self.img_dir), ]) # Must be last; if setUp fails, tearDown is not invoked self.patch.apply()
def setUp(self): self.connection = vmfakecon.Connection() self.patch = Patch([ (libvirtconnection, 'get', lambda: self.connection) ]) self.patch.apply()
def __init__(self, now): self.now = now self.patch = Patch([ (utils, 'monotonic_time', self.monotonic_time), (time, 'sleep', self.sleep), ])