Esempio n. 1
0
def clear_resources(debug):
    start_logging(debug)

    try:
        validate_resources(raiseException=True)
    except Exception:                   #pylint: disable=W0703 
        sys.exit('ERROR: Unable to clear resources because of validation error')

    data_root = config.runtime.default.data_root

    print '\nClearing resources...'
    for resource in all_files(os.path.join(data_root, 
                                           'resources')):
        print 'Clearing %s...' % resource,
        try:
            contents = load(resource, CONTENT_TYPE_YAML,
                            'clear_resource')
            for key in contents:
                contents[key] = 'None'
            dump(contents, resource, CONTENT_TYPE_YAML,
                 'clear_resource')
            print 'Ok!'            
        except Exception as exc:        #pylint: disable=W0703            
            print '\nERROR: Failed to clear %s\n%s' % \
                (resource, exc)
Esempio n. 2
0
 def test_stress(cls):
     # stress test writing and loading the same file over and
     # over again and make sure the file does not get corrupted
     # in the process
     index = 0
     while index < 100:
         index += 1
         data = get_data()
         serializers.dump(data, TMP_FILE, CONTENT_TYPE_JSON)
         assert serializers.load(TMP_FILE, CONTENT_TYPE_JSON) == data
 def test_stress(cls):
     # stress test writing and loading the same file over and
     # over again and make sure the file does not get corrupted
     # in the process
     index = 0
     while index < 100:
         index += 1
         data = get_data()
         serializers.dump(data, TMP_FILE, 
                          CONTENT_TYPE_JSON)
         assert serializers.load(TMP_FILE, 
                                 CONTENT_TYPE_JSON) == data
Esempio n. 4
0
 def dump(self, pool):
     file_path = os.path.join(self.file_path, pool)
     dump(self, file_path, CONTENT_TYPE_YAML, self.node_id)
Esempio n. 5
0
 def dump(self, pool):
     log.debug('%s: writing resource pool \'%s\': %s' % 
               (self.node_id, pool, self.data))
     file_path = os.path.join(self.file_path, pool)
     dump(self, file_path, CONTENT_TYPE_YAML, self.node_id,
          lock=True)
Esempio n. 6
0
 def dump(self, pool):
     file_path = os.path.join(self.file_path, pool)
     dump(self, file_path, CONTENT_TYPE_YAML, self.node_id)