From ed14d0ae30feb7030adae4cdbf580258143ac52c Mon Sep 17 00:00:00 2001 From: Kamil Sobol <61715331+kasobol-msft@users.noreply.github.com> Date: Fri, 25 Jun 2021 11:48:02 -0700 Subject: [PATCH] [Storage] Verify versions at release. (#22572) * print devops variables? * add tests. --- .../blob/BlobServiceVersionTest.groovy | 13 +++ .../common/test/shared/DevopsPipeline.java | 79 +++++++++++++++++++ .../test/shared/ServiceVersionSpec.groovy | 44 +++++++++++ .../src/test/resources/SpockConfig.groovy | 10 +++ .../DataLakeServiceVersionTest.groovy | 13 +++ .../file/share/ShareServiceVersionTest.groovy | 13 +++ .../queue/QueueServiceVersionTest.groovy | 13 +++ 7 files changed, 185 insertions(+) create mode 100644 sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobServiceVersionTest.groovy create mode 100644 sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/DevopsPipeline.java create mode 100644 sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/ServiceVersionSpec.groovy create mode 100644 sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeServiceVersionTest.groovy create mode 100644 sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareServiceVersionTest.groovy create mode 100644 sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueServiceVersionTest.groovy diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobServiceVersionTest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobServiceVersionTest.groovy new file mode 100644 index 0000000000000..561e8ff4b8623 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobServiceVersionTest.groovy @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.blob + +import com.azure.storage.common.test.shared.ServiceVersionSpec + +class BlobServiceVersionTest extends ServiceVersionSpec { + @Override + protected Class getServiceVersionClass() { + return BlobServiceVersion.class + } +} diff --git a/sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/DevopsPipeline.java b/sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/DevopsPipeline.java new file mode 100644 index 0000000000000..f387a859c6899 --- /dev/null +++ b/sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/DevopsPipeline.java @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.common.test.shared; + +import java.util.Optional; + +public final class DevopsPipeline { + + private static final DevopsPipeline INSTANCE = readFromEnvironment(); + + private final String jobName; + private final String buildId; + private final String definitionName; + private final String buildReason; + private final String teamProject; + private final boolean setsDevVersion; + + private DevopsPipeline(String jobName, String buildId, String definitionName, String buildReason, + String teamProject, boolean setsDevVersion) { + this.jobName = jobName; + this.buildId = buildId; + this.definitionName = definitionName; + this.buildReason = buildReason; + this.teamProject = teamProject; + this.setsDevVersion = setsDevVersion; + } + + public static Optional getInstance() { + return Optional.ofNullable(INSTANCE); + } + + private static DevopsPipeline readFromEnvironment() { + boolean isRunningOnAgent = Boolean.parseBoolean( + System.getenv().getOrDefault("TF_BUILD", "false")); + if (isRunningOnAgent) { + String jobName = System.getenv("AGENT_JOBNAME"); + String buildId = System.getenv("BUILD_BUILDID"); + String definitionName = System.getenv("BUILD_DEFINITIONNAME"); + String buildReason = System.getenv("BUILD_REASON"); + String teamProject = System.getenv("SYSTEM_TEAMPROJECT"); + String setDevVersionString = System.getenv("SETDEVVERSION"); + boolean setDevVersion = Boolean.parseBoolean(setDevVersionString); + return new DevopsPipeline(jobName, buildId, definitionName, buildReason, teamProject, setDevVersion); + } else { + return null; + } + } + + public String getJobName() { + return jobName; + } + + public String getBuildId() { + return buildId; + } + + public String getDefinitionName() { + return definitionName; + } + + public String getBuildReason() { + return buildReason; + } + + public String getTeamProject() { + return teamProject; + } + + public boolean getSetsDevVersion() { + return setsDevVersion; + } + + public boolean releasesToMavenCentral() { + return definitionName.equals("java - storage") + && buildReason.equalsIgnoreCase("manual") + && !setsDevVersion; + } +} diff --git a/sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/ServiceVersionSpec.groovy b/sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/ServiceVersionSpec.groovy new file mode 100644 index 0000000000000..2aef747ef60c3 --- /dev/null +++ b/sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/ServiceVersionSpec.groovy @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.common.test.shared + +import com.azure.storage.common.implementation.Constants +import spock.lang.IgnoreIf +import spock.lang.Specification + +abstract class ServiceVersionSpec extends Specification { + + protected abstract Class getServiceVersionClass(); + + @IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) }) + def "getLatest points to latest"() { + when: + Class clazz = getServiceVersionClass() + def lastVersion = clazz.getEnumConstants().last() + def latestVersion = clazz.getLatest() + + then: + latestVersion == lastVersion + } + + @IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) }) + def "Sas version should match last when we release"() { + when: + Class clazz = getServiceVersionClass() + def latestVersion = clazz.getLatest() + + then: + Constants.SAS_SERVICE_VERSION == latestVersion.getVersion() + } + + @IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) }) + def "Header version should match last when we release"() { + when: + Class clazz = getServiceVersionClass() + def latestVersion = clazz.getLatest() + + then: + Constants.HeaderConstants.TARGET_STORAGE_VERSION == latestVersion.getVersion() + } +} diff --git a/sdk/storage/azure-storage-common/src/test/resources/SpockConfig.groovy b/sdk/storage/azure-storage-common/src/test/resources/SpockConfig.groovy index 6d1e02add6c51..5707c42edcea1 100644 --- a/sdk/storage/azure-storage-common/src/test/resources/SpockConfig.groovy +++ b/sdk/storage/azure-storage-common/src/test/resources/SpockConfig.groovy @@ -5,6 +5,16 @@ def numberOfProcessors = Runtime.getRuntime().availableProcessors() printf("Parallelization is enabled=%b, factor=%.2f, processors=%d config=%s%n", isParallelEnabled, factor, numberOfProcessors, this.class.protectionDomain.codeSource.location) +def isRunningOnAgent = System.getenv().getOrDefault("TF_BUILD", "false").toBoolean() +if (isRunningOnAgent) { + printf("%s=%s%n", "AGENT_JOBNAME", System.getenv("AGENT_JOBNAME")) + printf("%s=%s%n", "BUILD_BUILDID", System.getenv("BUILD_BUILDID")) + printf("%s=%s%n", "BUILD_DEFINITIONNAME", System.getenv("BUILD_DEFINITIONNAME")) + printf("%s=%s%n", "BUILD_REASON", System.getenv("BUILD_REASON")) + printf("%s=%s%n", "SYSTEM_TEAMPROJECT", System.getenv("SYSTEM_TEAMPROJECT")) + printf("%s=%s%n", "SETDEVVERSION", System.getenv("SETDEVVERSION")) +} + runner { parallel { enabled isParallelEnabled diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeServiceVersionTest.groovy b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeServiceVersionTest.groovy new file mode 100644 index 0000000000000..452e77ddcf4c3 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeServiceVersionTest.groovy @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.file.datalake + +import com.azure.storage.common.test.shared.ServiceVersionSpec + +class DataLakeServiceVersionTest extends ServiceVersionSpec { + @Override + protected Class getServiceVersionClass() { + return DataLakeServiceVersion.class + } +} diff --git a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareServiceVersionTest.groovy b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareServiceVersionTest.groovy new file mode 100644 index 0000000000000..8280a7812b7f0 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareServiceVersionTest.groovy @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.file.share + +import com.azure.storage.common.test.shared.ServiceVersionSpec + +class ShareServiceVersionTest extends ServiceVersionSpec { + @Override + protected Class getServiceVersionClass() { + return ShareServiceVersion.class + } +} diff --git a/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueServiceVersionTest.groovy b/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueServiceVersionTest.groovy new file mode 100644 index 0000000000000..0792bcf0b507e --- /dev/null +++ b/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueServiceVersionTest.groovy @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.queue + +import com.azure.storage.common.test.shared.ServiceVersionSpec + +class QueueServiceVersionTest extends ServiceVersionSpec { + @Override + protected Class getServiceVersionClass() { + return QueueServiceVersion.class + } +}