Пример #1
0
 private void InvokePhaseChanged(OperationPhase p1, OperationPhase p2)
 {
     if (PhaseChanged != null)
     {
         PhaseChanged(p1, p2);
     }
 }
Пример #2
0
    public async Task RemoveTests(OperationPhase operationPhase)
    {
        using (var scope = Fixture.Container.BeginLifetimeScope())
        {
            var cl            = scope.Resolve <HttpClient>();
            var azure         = scope.ResolveKeyed <IAzure>(EswDevOpsSdk.GetEnvironment());
            var resourceGroup = await EnsureResourceGroupExists(azure, TestResourceGroupName, Region.EuropeNorth);

            var scaleSet = await GetScaleSet(azure);
            await Prepare(azure, operationPhase, resourceGroup, scaleSet, IdentityName);

            var identity = await FindIdentity(azure, resourceGroup, IdentityName);

            var msi = CreateMangedIdentityAssignment();
            await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ManagedIdentity", "Remove", msi);

            var deletedIdentity = await FindIdentity(azure, resourceGroup, IdentityName);

            deletedIdentity.Should().BeNull($"identity {IdentityName} should be deleted.");
            if (identity != null)
            {
                var updatedScaleSet = await GetScaleSet(azure);

                if (updatedScaleSet.ManagedServiceIdentityType == ResourceIdentityType.SystemAssignedUserAssigned ||
                    updatedScaleSet.ManagedServiceIdentityType == ResourceIdentityType.UserAssigned)
                {
                    updatedScaleSet.UserAssignedManagedServiceIdentityIds.Should().NotBeNull();
                    updatedScaleSet.UserAssignedManagedServiceIdentityIds.Should().NotContain(identity.Id);
                }

                // TODO: if possible check whether the managed identity had been unassigned from the scale set before it has been deleted.
            }
        }
    }
Пример #3
0
 /// <summary>
 /// Update the phase, progress, filesprocessed, filesizeprocessed, filecount, filesize and countingfiles.
 /// </summary>
 /// <param name="phase">Phase.</param>
 /// <param name="progress">Progress.</param>
 /// <param name="filesprocessed">Filesprocessed.</param>
 /// <param name="filesizeprocessed">Filesizeprocessed.</param>
 /// <param name="filecount">Filecount.</param>
 /// <param name="filesize">Filesize.</param>
 /// <param name="countingfiles">True if the filecount and filesize is incomplete, false otherwise</param>
 public void UpdateOverall(out OperationPhase phase, out float progress, out long filesprocessed, out long filesizeprocessed, out long filecount, out long filesize, out bool countingfiles)
 {
     lock (m_lock)
     {
         phase             = m_phase;
         filesize          = m_filesize;
         progress          = m_progress;
         filesprocessed    = m_filesprocessed;
         filesizeprocessed = m_filesizeprocessed;
         filecount         = m_filecount;
         countingfiles     = m_countingFiles;
     }
 }
Пример #4
0
    private async Task Prepare(IAzure azure, OperationPhase phase, IResourceGroup resourceGroup,
                               IVirtualMachineScaleSet scaleSet, string identityName)
    {
        var identity = await FindIdentity(azure, resourceGroup, identityName);

        var isAssigned = identity != null && IsIdentityAssigned(scaleSet, identity);

        switch (phase)
        {
        case OperationPhase.IdentityNotCreated:
            if (isAssigned)
            {
                await scaleSet.Update()
                .WithoutUserAssignedManagedServiceIdentity(identity.Id)
                .ApplyAsync();
            }
            if (identity != null)
            {
                await azure.Identities.DeleteByIdAsync(identity.Id);
            }
            break;

        case OperationPhase.IdentityCreatedAndNotAssigned:
            if (identity == null)
            {
                identity = await CreateIdentity(azure, resourceGroup, identityName);
            }

            if (isAssigned)
            {
                await scaleSet.Update()
                .WithoutUserAssignedManagedServiceIdentity(identity.Id)
                .ApplyAsync();
            }
            break;

        case OperationPhase.IdentityAssigned:
            if (identity == null)
            {
                identity = await CreateIdentity(azure, resourceGroup, identityName);
            }

            if (!isAssigned)
            {
                await scaleSet.Update()
                .WithExistingUserAssignedManagedServiceIdentity(identity)
                .ApplyAsync();
            }
            break;
        }
    }
Пример #5
0
        public void UpdatePhase(OperationPhase phase)
        {
            OperationPhase prev_phase;

            lock (m_lock)
            {
                prev_phase      = m_phase;
                m_phase         = phase;
                m_curfilename   = null;
                m_curfilesize   = 0;
                m_curfileoffset = 0;
            }

            if (prev_phase != phase && PhaseChanged != null)
            {
                PhaseChanged(phase, prev_phase);
            }
        }
Пример #6
0
    public async Task AddTest(OperationPhase operationPhase)
    {
        using (var scope = Fixture.Container.BeginLifetimeScope())
        {
            var cl            = scope.Resolve <HttpClient>();
            var azure         = scope.ResolveKeyed <IAzure>(EswDevOpsSdk.GetEnvironment());
            var resourceGroup = await EnsureResourceGroupExists(azure, TestResourceGroupName, Region.EuropeNorth);

            var scaleSet = await GetScaleSet(azure);
            await Prepare(azure, operationPhase, resourceGroup, scaleSet, IdentityName);

            var msi           = CreateMangedIdentityAssignment();
            var actorResponse = await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ManagedIdentity", "Add", msi);

            actorResponse.Should().NotBeNull();
            actorResponse.IdentityId.Should().NotBeNullOrEmpty();
            actorResponse.State.Should().Be(EntityStateEnum.Created);

            var policy = Policy
                         .Handle <CloudException>()
                         .OrResult <IIdentity>(x => x == null)
                         .WaitAndRetryAsync(3, retryAttempt =>
                                            TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                                            );

            var capturedIdentity =
                await policy.ExecuteAndCaptureAsync(() => azure.Identities.GetByIdAsync(actorResponse.IdentityId));

            capturedIdentity.Result.Should().NotBeNull(
                $"the identity {actorResponse.IdentityId} should be created in {azure.SubscriptionId} subscription");
            capturedIdentity.Result.Name.Should().Be(msi.IdentityName);
            capturedIdentity.Result.ResourceGroupName.Should().Be(msi.ResourceGroupName);

            var modifiedScaleSet = await GetScaleSet(azure);

            var isAssigned = IsIdentityAssigned(modifiedScaleSet, capturedIdentity.Result);
            isAssigned.Should()
            .BeTrue($"the identity {capturedIdentity.Result.Id} should be assigned to the scale set {modifiedScaleSet.Id}");
        }
    }
Пример #7
0
 private void InvokePhaseChanged(OperationPhase p1, OperationPhase p2)
 {
     if (PhaseChanged != null)
         PhaseChanged(p1, p2);
 }
Пример #8
0
 /// <summary>
 /// Update the phase, progress, filesprocessed, filesizeprocessed, filecount, filesize and countingfiles.
 /// </summary>
 /// <param name="phase">Phase.</param>
 /// <param name="progress">Progress.</param>
 /// <param name="filesprocessed">Filesprocessed.</param>
 /// <param name="filesizeprocessed">Filesizeprocessed.</param>
 /// <param name="filecount">Filecount.</param>
 /// <param name="filesize">Filesize.</param>
 /// <param name="countingfiles">True if the filecount and filesize is incomplete, false otherwise</param>
 public void UpdateOverall(out OperationPhase phase, out float progress, out long filesprocessed, out long filesizeprocessed, out long filecount, out long filesize, out bool countingfiles)
 {
     lock(m_lock)
     {
         phase = m_phase;
         filesize = m_filesize;
         progress = m_progress;
         filesprocessed = m_filesprocessed;
         filesizeprocessed = m_filesizeprocessed;
         filecount = m_filecount;
         countingfiles = m_countingFiles;
     }
 }
Пример #9
0
 public void UpdatePhase(OperationPhase phase)
 {
     OperationPhase prev_phase;
     lock(m_lock)
     {
         prev_phase = m_phase;
         m_phase = phase;
         m_curfilename = null;
         m_curfilesize = 0;
         m_curfileoffset = 0;
     }
     
     if (prev_phase != phase && PhaseChanged != null)
         PhaseChanged(phase, prev_phase);
 }
Пример #10
0
 public SubOperation(Operation source, OperationPhase overridingPhase = OperationPhase.None)
 {
     value = source;
     this.overridingPhase = this.overridingPhase;
 }