Skip to content

Commit

Permalink
mgmt, netapp, update live test (#42479)
Browse files Browse the repository at this point in the history
* mgmt, netapp, update live test

* format

* use ProviderRegistrationPolicy

* update databricks

* update computefleet
  • Loading branch information
weidongxu-microsoft authored Oct 21, 2024
1 parent 378c49b commit 9a00d22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@
import com.azure.resourcemanager.network.models.LoadBalancerSkuType;
import com.azure.resourcemanager.network.models.Network;
import com.azure.resourcemanager.network.models.TransportProtocol;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import com.azure.resourcemanager.resources.models.Provider;
import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;

Expand All @@ -67,39 +63,31 @@ public class ComputeFleetManagerTests extends TestProxyTestBase {
private String resourceGroupName = "rg" + randomPadding();
private ComputeFleetManager computeFleetManager = null;
private NetworkManager networkManager = null;
private ResourceManager resourceManager;
private boolean testEnv;

@Override
public void beforeTest() {
final TokenCredential credential = new AzurePowerShellCredentialBuilder().build();
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);

computeFleetManager = ComputeFleetManager
.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile);

networkManager = NetworkManager
.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile);

resourceManager = ResourceManager
.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile)
.withDefaultSubscription();

canRegisterProviders(Arrays.asList("Microsoft.AzureFleet"));
computeFleetManager = ComputeFleetManager
.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.withPolicy(new ProviderRegistrationPolicy(networkManager.resourceManager()))
.authenticate(credential, profile);

// use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI
String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);
if (testEnv) {
resourceGroupName = testResourceGroup;
} else {
resourceManager.resourceGroups()
networkManager.resourceManager().resourceGroups()
.define(resourceGroupName)
.withRegion(REGION)
.create();
Expand All @@ -109,7 +97,7 @@ public void beforeTest() {
@Override
protected void afterTest() {
if (!testEnv) {
resourceManager.resourceGroups().beginDeleteByName(resourceGroupName);
networkManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroupName);
}
}

Expand Down Expand Up @@ -264,18 +252,4 @@ public void testCreateComputeFleet() {
private static String randomPadding() {
return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000));
}

private void canRegisterProviders(List<String> providerNamespaces) {
providerNamespaces.forEach(providerNamespace -> {
Provider provider = resourceManager.providers().getByName(providerNamespace);
if (!"Registered".equalsIgnoreCase(provider.registrationState())
&& !"Registering".equalsIgnoreCase(provider.registrationState())) {
provider = resourceManager.providers().register(providerNamespace);
}
while (!"Registered".equalsIgnoreCase(provider.registrationState())) {
ResourceManagerUtils.sleep(Duration.ofSeconds(5));
provider = resourceManager.providers().getByName(provider.namespace());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.resourcemanager.databricks.models.Sku;
import com.azure.resourcemanager.databricks.models.Workspace;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -37,15 +38,16 @@ public void beforeTest() {
final TokenCredential credential = new AzurePowerShellCredentialBuilder().build();
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);

databricksManager = AzureDatabricksManager
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile);

resourceManager = ResourceManager
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile)
.withDefaultSubscription();

databricksManager = AzureDatabricksManager
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.withPolicy(new ProviderRegistrationPolicy(resourceManager))
.authenticate(credential, profile);

// use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI
String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.azure.identity.AzurePowerShellCredentialBuilder;
import com.azure.resourcemanager.netapp.models.NetAppAccount;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -34,15 +35,16 @@ public void beforeTest() {
final TokenCredential credential = new AzurePowerShellCredentialBuilder().build();
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);

netAppFilesManager = NetAppFilesManager.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile);

resourceManager = ResourceManager.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.authenticate(credential, profile)
.withDefaultSubscription();

netAppFilesManager = NetAppFilesManager.configure()
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
.withPolicy(new ProviderRegistrationPolicy(resourceManager))
.authenticate(credential, profile);

// use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI
String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);
Expand Down

0 comments on commit 9a00d22

Please sign in to comment.