def make_config(self, text): """ Create a temporary file instance and returns a Configuration with it. """ self._testfile = makeTempFile(text) conf = Configuration.create_from_model(self._testfile.name) return conf
def makeConfFileSystem(self, text): """ Create a temporary file instance and returns a FileSystem with it. """ self._testfile = makeTempFile(text) fsconf = FileSystem.create_from_model(self._testfile.name) return fsconf
def makeTempTuningModel(self, text): """ Create a temporary file instance and returns a TuningModel with it. """ self.f = makeTempFile(text) model = TuningModel(filename=self.f.name) return model
def testSaveModelToFile(self): """save a ModelFile to a file""" testfile = makeTempFile("""foo: my test bar: 3 foo: another bar: 1 bar: 2""") # Create a model model = ModelFile() model.add_element("foo", check="string", multiple=True) model.add_element("bar", check="digit", multiple=True) # Load a test file model.load(testfile.name) # Save it to a new file filename = makeTempFilename() model.save(filename, "# Some header") # Reload the file in another model model2 = model.emptycopy() model2.load(filename) os.unlink(filename) # Compare the two files. They should have no difference added, changed, removed = model.diff(model2) self.assertTrue(len(changed) == len(added) == len(removed) == 0)
def testLoadModelFromFile(self): """load a ModelFile from file""" model = ModelFile() model.add_element("foo", check="string", multiple=True) model.add_element("bar", check="digit", multiple=True) testfile = makeTempFile("""foo: my test bar: 3 foo: another bar: 1 bar: 2""") model.load(testfile.name) self.assertEqual(model.get('foo'), ['my test', 'another']) self.assertEqual(model.get('bar'), [3, 1, 2]) # Bad file syntax testfile = makeTempFile("""foo bad file""") self.assertRaises(ModelFileValueError, model.load, testfile.name)
def make_fs_with_backend(self, backend, text): """ Create a FileSystem instance from text with a specific backend instance. """ self._testfile = makeTempFile(text) fs = FileSystem(self._testfile.name) fs.backend = backend fs.setup_target_devices() return fs
def setUp(self): FSUtilsTest.setUp(self) tmpfile = makeTempFile(""" fs_name: param nid_map: nodes=foo[1-10] nids=foo[1-10]@tcp client: node=foo[7-10] mgt: node=foo1 dev=/dev/sda mdt: node=foo1 dev=/dev/sdb ost: node=foo2 dev=/dev/sdc ha_node=foo3 ha_node=foo4 #index 0 ost: node=foo2 dev=/dev/sdd ha_node=foo4 ha_node=foo3 #index 1 ost: node=foo3 dev=/dev/sdc ha_node=foo2 ha_node=foo4 #index 2 ost: node=foo3 dev=/dev/sdd ha_node=foo4 ha_node=foo2 #index 3 router: node=foo[5-6] mount_path: /param """) self.fsconf, self.fs = create_lustrefs(tmpfile.name)
def setUp(self): FSUtilsTest.setUp(self) tmpfile = makeTempFile( """ fs_name: param nid_map: nodes=foo[1-13] nids=foo[1-13]@tcp client: node=foo[8-11] mgt: node=foo1 dev=/dev/sda mdt: node=foo1 dev=/dev/sdb ost: node=foo2 dev=/dev/sdc ha_node=foo3 ha_node=foo4 #index 0 ost: node=foo2 dev=/dev/sdd ha_node=foo4 ha_node=foo3 #index 1 ost: node=foo3 dev=/dev/sdc ha_node=foo2 ha_node=foo4 #index 2 ost: node=foo3 dev=/dev/sdd ha_node=foo4 ha_node=foo2 #index 3 ost: node=foo5 dev=/dev/sde ha_node=foo6 ha_node=foo7 #index 4 ost: node=foo5 dev=/dev/sdf ha_node=foo7 ha_node=foo6 #index 5 ost: node=foo6 dev=/dev/sde ha_node=foo5 ha_node=foo7 #index 6 ost: node=foo6 dev=/dev/sdf ha_node=foo7 ha_node=foo5 #index 7 router: node=foo[12-13] mount_path: /param """ ) self.fsconf, self.fs = create_lustrefs(tmpfile.name)
def testTooLongFSName(self): """Model with a too long fsname""" testfile = makeTempFile("""fs_name: too_long_name""") model = Model() self.assertRaises(ModelFileValueError, model.load, testfile.name)
def makeTempModel(self, txt): """helper method for creating a temp file and loading it as Model""" self._testfile = makeTempFile(txt) model = Model() model.load(self._testfile.name) return model
def _compare(self, orig, new): tmpfile = makeTempFile(textwrap.dedent(orig)) origconf = FileSystem(tmpfile.name) newfile = makeTempFile(textwrap.dedent(new)) newconf = FileSystem(newfile.name) return origconf.compare(newconf)
def make_temp_fs(self, txt): self._fsfile = makeTempFile(txt) self._conf = Configuration.create_from_model(self._fsfile.name) self._model = self._conf._fs.model
def make_temp_conf(self, txt): self._storagefile = makeTempFile(txt) Globals().replace('storage_file', self._storagefile.name)
def _compare(self, orig, new): tmpfile = makeTempFile(orig) origconf = FileSystem(tmpfile.name) newfile = makeTempFile(new) newconf = FileSystem(newfile.name) return origconf.compare(newconf)