Ejemplo n.º 1
0
    def test_acquire_lease_on_sharesnapshot(self, storage_account_name,
                                            storage_account_key):
        self._setup(storage_account_name, storage_account_key)
        share = self._get_share_reference("testshare1")

        # Act
        share.create_share()
        snapshot = share.create_snapshot()

        snapshot_client = ShareClient(self.account_url(storage_account_name,
                                                       "file"),
                                      share_name=share.share_name,
                                      snapshot=snapshot,
                                      credential=storage_account_key)

        share_lease = share.acquire_lease()
        share_snapshot_lease = snapshot_client.acquire_lease()

        # Assert
        with self.assertRaises(HttpResponseError):
            share.get_share_properties(lease=share_snapshot_lease)

        with self.assertRaises(HttpResponseError):
            snapshot_client.get_share_properties(lease=share_lease)

        self.assertIsNotNone(snapshot['snapshot'])
        self.assertIsNotNone(snapshot['etag'])
        self.assertIsNotNone(snapshot['last_modified'])
        self.assertIsNotNone(share_lease)
        self.assertIsNotNone(share_snapshot_lease)
        self.assertNotEqual(share_lease, share_snapshot_lease)

        share_snapshot_lease.release()
        share_lease.release()
        self._delete_shares(share.share_name)
Ejemplo n.º 2
0
    def test_create_snapshot_with_metadata(self, storage_account_name,
                                           storage_account_key):
        self._setup(storage_account_name, storage_account_key)
        share = self._get_share_reference()
        metadata = {"test1": "foo", "test2": "bar"}
        metadata2 = {"test100": "foo100", "test200": "bar200"}

        # Act
        created = share.create_share(metadata=metadata)
        snapshot = share.create_snapshot(metadata=metadata2)

        share_props = share.get_share_properties()
        snapshot_client = ShareClient(self.account_url(storage_account_name,
                                                       "file"),
                                      share_name=share.share_name,
                                      snapshot=snapshot,
                                      credential=storage_account_key)
        snapshot_props = snapshot_client.get_share_properties()
        # Assert
        self.assertTrue(created)
        self.assertIsNotNone(snapshot['snapshot'])
        self.assertIsNotNone(snapshot['etag'])
        self.assertIsNotNone(snapshot['last_modified'])
        self.assertEqual(share_props.metadata, metadata)
        self.assertEqual(snapshot_props.metadata, metadata2)
        self._delete_shares(share.share_name)
Ejemplo n.º 3
0
    def test_create_snapshot_with_metadata(self):
        # Arrange
        share = self._get_share_reference()
        metadata = {"test1": "foo", "test2": "bar"}
        metadata2 = {"test100": "foo100", "test200": "bar200"}

        # Act
        created = share.create_share(metadata=metadata)
        snapshot = share.create_snapshot(metadata=metadata2)

        share_props = share.get_share_properties()
        snapshot_client = ShareClient(
            self.get_file_url(),
            share_name=share.share_name,
            snapshot=snapshot,
            credential=self.settings.STORAGE_ACCOUNT_KEY)
        snapshot_props = snapshot_client.get_share_properties()
        # Assert
        self.assertTrue(created)
        self.assertIsNotNone(snapshot['snapshot'])
        self.assertIsNotNone(snapshot['etag'])
        self.assertIsNotNone(snapshot['last_modified'])
        self.assertEqual(share_props.metadata, metadata)
        self.assertEqual(snapshot_props.metadata, metadata2)
        self._delete_shares(share.share_name)