Ejemplo n.º 1
0
    def __init__(self, paths, strict_mode):
        """
        Constructs schema object based on yaml files provided as
        list of paths and a mode which determines request/response
        validation behavior. Usually it is based on api_strict_mode
        property from config.py
        """
        self._strict_mode = strict_mode
        self._methods = {}
        self._types = {}
        try:
            for path in paths:
                pickle_path = _get_pickle_schema_path(path)

                if not os.path.exists(pickle_path):
                    with open(path) as f:
                        loaded_schema = _load_yaml_file(f)
                else:
                    with io.open(pickle_path, 'rb') as f:
                        loaded_schema = pickle.load(f)

                types = loaded_schema.pop('types')
                self._types.update(types)
                self._methods.update(loaded_schema)
        except EnvironmentError:
            raise SchemaNotFound("Unable to find API schema file")
Ejemplo n.º 2
0
    def test_save(self):

        with self.setup_env() as (testvm, tmpdir):
            rec = recovery.File(testvm.id)
            rec.save(testvm)

            with open(os.path.join(tmpdir, rec.name), 'rb') as f:
                self.assertTrue(pickle.load(f))
Ejemplo n.º 3
0
    def test_save(self):

        with self.setup_env() as (testvm, tmpdir):
            rec = recovery.File(testvm.id)
            rec.save(testvm)

            with open(os.path.join(tmpdir, rec.name), 'rb') as f:
                self.assertTrue(pickle.load(f))
Ejemplo n.º 4
0
 def load(self, cif):
     self._log.debug("recovery: trying with VM %s", self._vmid)
     try:
         with open(self._path) as src:
             params = pickle.load(src)
         self._set_elapsed_time(params)
         res = cif.createVm(params, vmRecover=True)
     except Exception:
         self._log.exception("Error recovering VM: %s", self._vmid)
         return False
     else:
         if response.is_error(res):
             return False
         return True
Ejemplo n.º 5
0
 def load(self, cif):
     self._log.debug("recovery: trying with VM %s", self._vmid)
     try:
         with open(self._path) as src:
             params = pickle.load(src)
         self._set_elapsed_time(params)
         res = cif.createVm(params, vmRecover=True)
     except Exception:
         self._log.exception("Error recovering VM: %s", self._vmid)
         return False
     else:
         if response.is_error(res):
             return False
         return True
Ejemplo n.º 6
0
    def __init__(self, schema_types, strict_mode):
        """
        Constructs schema object based on an iterable of schema type
        enumerations and a mode which determines request/response
        validation behavior. Usually it is based on api_strict_mode
        property from config.py
        """
        self._strict_mode = strict_mode
        self._methods = {}
        self._types = {}
        try:
            for schema_type in schema_types:
                with io.open(schema_type.path(), 'rb') as f:
                    loaded_schema = pickle.load(f)

                types = loaded_schema.pop('types')
                self._types.update(types)
                self._methods.update(loaded_schema)
        except EnvironmentError:
            raise SchemaNotFound("Unable to find API schema file")