def test_assign_snapshot_policy_to_volume(self):
        # create volume and snapshot policy
        create_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1,
                      TEST_VOL_1)
        snapshot_policy = create_snapshot_policy(self.client,
                                                 TEST_SNAPSHOT_POLICY_1)
        # assign the snapshot policy to the volume
        snapshot = VolumeSnapshotProperties(
            snapshot_policy_id=snapshot_policy.id)
        data_protection = VolumePatchPropertiesDataProtection(
            snapshot=snapshot)
        volume_patch = VolumePatch(data_protection=data_protection)
        volume = self.client.volumes.begin_update(TEST_RG, TEST_ACC_1,
                                                  TEST_POOL_1, TEST_VOL_1,
                                                  volume_patch).result()

        self.assertEqual(volume.data_protection.snapshot.snapshot_policy_id,
                         snapshot_policy.id)

        # cleanup
        delete_volume(self.client,
                      TEST_RG,
                      TEST_ACC_1,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      live=self.is_live)
        delete_snapshot_policy(self.client,
                               TEST_SNAPSHOT_POLICY_1,
                               live=self.is_live)
        delete_pool(self.client,
                    TEST_RG,
                    TEST_ACC_1,
                    TEST_POOL_1,
                    live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
    def test_get_vault(self):
        create_volume(self.client,
                      CBS_RESOURCE_GROUP,
                      CBS_ACCOUNT,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      location=CBS_LOCATION,
                      vnet=CBS_VNET)
        vaults = self.client.vaults.list(CBS_RESOURCE_GROUP, CBS_ACCOUNT)
        self.assertEqual(len(list(vaults)), 1)

        # clean up
        delete_volume(self.client,
                      CBS_RESOURCE_GROUP,
                      CBS_ACCOUNT,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      live=self.is_live)
        delete_pool(self.client,
                    CBS_RESOURCE_GROUP,
                    CBS_ACCOUNT,
                    TEST_POOL_1,
                    live=self.is_live)
        delete_account(self.client,
                       CBS_RESOURCE_GROUP,
                       CBS_ACCOUNT,
                       live=self.is_live)
    def test_get_vault(self):
        create_volume(self.client)
        vaults = self.client.vaults.list(TEST_RG, TEST_ACC_1)
        self.assertEqual(len(list(vaults)), 1)

        # clean up
        delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live)
        delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
Beispiel #4
0
def create_snapshot(client,
                    rg=TEST_RG,
                    account_name=TEST_ACC_1,
                    pool_name=TEST_POOL_1,
                    volume_name=TEST_VOL_1,
                    snapshot_name=TEST_SNAPSHOT_1,
                    location=LOCATION,
                    snapshot_only=False):
    if not snapshot_only:
        volume = create_volume(client, rg, account_name, pool_name,
                               volume_name)
        # be sure the volume is really available
        wait_for_volume(client, rg, account_name, pool_name, volume_name)
    else:
        # we need to get the volume id if we didn't just create it
        volume = client.volumes.get(rg, account_name, pool_name, volume_name)

    snapshot = client.snapshots.create(
        rg,
        account_name,
        pool_name,
        volume_name,
        snapshot_name,
        location=location,
        file_system_id=volume.file_system_id).result()

    return snapshot
Beispiel #5
0
    def test_assign_snapshot_policy_to_volume(self):
        # this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
        set_custom_default_matcher(
            compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
        )
        # create volume and snapshot policy
        create_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1)
        snapshot_policy = create_snapshot_policy(self.client, TEST_SNAPSHOT_POLICY_1)
        # assign the snapshot policy to the volume
        snapshot = VolumeSnapshotProperties(snapshot_policy_id=snapshot_policy.id)
        data_protection = VolumePatchPropertiesDataProtection(snapshot=snapshot)
        volume_patch = VolumePatch(data_protection=data_protection)
        volume = self.client.volumes.begin_update(TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, volume_patch).result()

        assert volume.data_protection.snapshot.snapshot_policy_id == snapshot_policy.id

        # cleanup
        delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live)
        delete_snapshot_policy(self.client, TEST_SNAPSHOT_POLICY_1, live=self.is_live)
        delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
def create_snapshot(client, rg=TEST_RG, account_name=TEST_ACC_1, pool_name=TEST_POOL_1, volume_name=TEST_VOL_1, snapshot_name=TEST_SNAPSHOT_1, location=LOCATION, snapshot_only=False):
    if not snapshot_only:
        volume = create_volume(client, rg, account_name, pool_name, volume_name)
        # be sure the volume is really available
        wait_for_volume(client, rg, account_name, pool_name, volume_name)
    else:
        # we need to get the volume id if we didn't just create it
        volume = client.volumes.get(rg, account_name, pool_name, volume_name)

    snapshot_body = Snapshot(location=location, file_system_id=volume.file_system_id)
    snapshot = client.snapshots.create(snapshot_body, rg, account_name, pool_name, volume_name, snapshot_name).result()

    return snapshot
Beispiel #7
0
    def test_list_mount_target(self):
        volume = create_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1,
                               TEST_VOL_1)
        self.assertEqual(volume.name,
                         TEST_ACC_1 + '/' + TEST_POOL_1 + '/' + TEST_VOL_1)

        mount_target_list = self.client.mount_targets.list(
            TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1)
        self.assertEqual(len(list(mount_target_list)), 1)

        delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1,
                      TEST_VOL_1)
        delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1)
        delete_account(self.client, TEST_RG, TEST_ACC_1)
def create_backup(client,
                  backup_name=TEST_BACKUP_1,
                  rg=BACKUP_RG,
                  account_name=TEST_ACC_1,
                  pool_name=TEST_POOL_1,
                  volume_name=TEST_VOL_1,
                  location=BACKUP_LOCATION,
                  backup_only=False,
                  live=False):
    if not backup_only:
        create_volume(client,
                      rg,
                      account_name,
                      pool_name,
                      volume_name,
                      location,
                      vnet=BACKUP_VNET,
                      live=live)
        wait_for_volume(client, rg, account_name, pool_name, volume_name, live)

    vaults = client.vaults.list(rg, account_name)
    volume_patch = VolumePatch(data_protection={
        "backup": {
            "vaultId": vaults.next().id,
            "backupEnabled": True
        }
    })
    client.volumes.begin_update(BACKUP_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1,
                                volume_patch).result()
    backup_body = Backup(location=location)
    backup = client.backups.begin_create(rg, account_name, pool_name,
                                         volume_name, backup_name,
                                         backup_body).result()
    wait_for_backup_created(client, rg, account_name, pool_name, volume_name,
                            backup_name, live)
    return backup
    def test_get_vault(self):
        # this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
        set_custom_default_matcher(
            compare_bodies=False,
            excluded_headers=
            "Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
        )
        create_volume(self.client)
        vaults = self.client.vaults.list(TEST_RG, TEST_ACC_1)
        assert len(list(vaults)) == 1

        # clean up
        delete_volume(self.client,
                      TEST_RG,
                      TEST_ACC_1,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      live=self.is_live)
        delete_pool(self.client,
                    TEST_RG,
                    TEST_ACC_1,
                    TEST_POOL_1,
                    live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
    def test_list_mount_target(self):
        volume = create_volume(self. client,TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1)
        self.assertEqual(volume.name, TEST_ACC_1 + '/' + TEST_POOL_1 + '/' + TEST_VOL_1)

        mount_target_list = self.client.mount_targets.list(
            TEST_RG,
            TEST_ACC_1,
            TEST_POOL_1,
            TEST_VOL_1
        )
        self.assertEqual(len(list(mount_target_list)), 1)

        delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1)
        delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1)
        delete_account(self.client, TEST_RG, TEST_ACC_1)