Exemplo n.º 1
0
    def setUpClass(cls):
        cnf = AgkyraConfig()
        cloud_conf = cnf.get('cloud', 'test')
        if cloud_conf is None:
            print "Define a 'test' cloud in %s" % CONFIG_PATH
            exit()

        AUTHENTICATION_URL = cloud_conf['url']
        TOKEN = cloud_conf['token']

        cls.ID = "ΑΓΚΥΡΑTEST" + str(random.random()).split('.')[1]

        cls.LOCAL_ROOT_PATH = utils.join_path(TMP, cls.ID)

        cls.settings = SyncerSettings(
            auth_url=AUTHENTICATION_URL,
            auth_token=TOKEN,
            container=cls.ID,
            local_root_path=cls.LOCAL_ROOT_PATH,
            action_max_wait=5,
            ignore_ssl=True)

        cls.master = PithosFileClient(cls.settings)
        cls.slave = localfs_client.LocalfsFileClient(cls.settings)
        cls.s = FileSyncer(cls.settings, cls.master, cls.slave)
        cls.pithos = cls.master.endpoint
        cls.pithos.create_container(cls.ID)
        cls.db = database.get_db(cls.s.syncer_dbtuple)
        m = cls.s.get_next_message(block=True)
        assert isinstance(m, messaging.PithosSyncEnabled)
        m = cls.s.get_next_message(block=True)
        assert isinstance(m, messaging.LocalfsSyncEnabled)
Exemplo n.º 2
0
    def test_012_cachename(self):
        fil = "φ012"
        f_path = self.get_path(fil)
        with open(f_path, "w") as f:
            f.write("content")

        state = self.db.get_state(self.s.SLAVE, fil)
        handle = self.slave.prepare_target(state)
        hidden_filename = utils.join_path(
            handle.cache_hide_name, utils.hash_string(handle.objname))
        hidden_path = handle.get_path_in_cache(hidden_filename)
        self.assertFalse(os.path.isfile(hidden_path))

        client_db = database.get_db(self.slave.client_dbtuple)

        self.assertIsNone(client_db.get_cachename(hidden_filename))
        handle.move_file()

        self.assertTrue(os.path.isfile(hidden_path))
        self.assertIsNotNone(client_db.get_cachename(hidden_filename))
        handle.move_file()
        self.assertTrue(os.path.isfile(hidden_path))

        shutil.move(hidden_path, f_path)
        self.assertIsNotNone(client_db.get_cachename(hidden_filename))
        handle.move_file()
        self.assertTrue(os.path.isfile(hidden_path))

        # open file to cause busy error
        f = open(hidden_path, "r")
        with self.assertRaises(common.BusyError):
            handle.hide_file()