Skip to content

Commit

Permalink
feat(bakery/azure): Adding changes to scrape sharedimage gallery name…
Browse files Browse the repository at this point in the history
… from logs (#561)

- Add unit tests
  • Loading branch information
hkumarsulochana committed Feb 10, 2021
1 parent 0a10984 commit 0a782e9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class AzureBakeHandler extends CloudProviderBakeHandler{

private static final String IMAGE_NAME_TOKEN = "ManagedImageName: "
private static final String IMAGE_ID_TOKEN = "ManagedImageId: "
private static final String SIG_IMAGE_ID_TOKEN = "ManagedImageSharedImageGalleryId: "

ImageNameFactory imageNameFactory = new ImageNameFactory()

Expand Down Expand Up @@ -65,10 +66,14 @@ public class AzureBakeHandler extends CloudProviderBakeHandler{
// Sample for the image name and image id in logs
// ManagedImageName: hello-karyon-rxnetty-all-20190128114007-ubuntu-1604
// ManagedImageId: /subscriptions/faab228d-df7a-4086-991e-e81c4659d41a/resourceGroups/zhqqi-sntest/providers/Microsoft.Compute/images/hello-karyon-rxnetty-all-20190128114007-ubuntu-1604
// ManagedImageSharedImageGalleryId: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/galleries/test-gallery/images/test-image/versions/1.0.9

if (line.startsWith(IMAGE_NAME_TOKEN)) {
imageName = line.substring(IMAGE_NAME_TOKEN.size())
} else if (line.startsWith(IMAGE_ID_TOKEN)) {
ami = line.substring(IMAGE_ID_TOKEN.size())
} else if (line.startsWith(SIG_IMAGE_ID_TOKEN)) {
ami = line.substring(SIG_IMAGE_ID_TOKEN.size())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,78 @@ class AzureBakeHandlerSpec extends Specification implements TestDefaults{
}
}

void 'can scrape packer logs for image name in SIG'() {
setup:
@Subject
AzureBakeHandler azureBakeHandler = new AzureBakeHandler()

when:
def logsContent =
"==> azure-arm: Deleting the temporary OS disk ...\n" +
"==> azure-arm: -> OS Disk : 'https://lgpackervms.blob.core.windows.net/images/pkroswfvmtp50x8.vhd'\n" +
"==> azure-arm:\n" +
"==> azure-arm: Cleanup requested, deleting resource group ...\n" +
"==> azure-arm: Error deleting resource group. Please delete it manually.\n" +
"==> azure-arm:\n" +
"==> azure-arm: Name: packer-Resource-Group-wfvmtp50x8\n" +
"==> azure-arm: Error: azure#updatePollingState: Azure Polling Error - Unable to obtain polling URI for DELETE : StatusCode=0\n" +
"==> azure-arm: Resource group has been deleted.\n" +
"Build 'azure-arm' finished.\n" +
"\n" +
"==> Builds finished. The artifacts of successful builds are:\n" +
"--> azure-arm: Azure.ResourceManagement.VMImage:\n" +
"\n" +
"StorageAccountLocation: westus\n" +
"ManagedImageName: pkroswfvmtp50x8\n" +
"ManagedImageSharedImageGalleryId: pkroswfvmtp50x8id"


Bake bake = azureBakeHandler.scrapeCompletedBakeResults(null, "123", logsContent)

then:
with (bake) {
id == "123"
ami == "pkroswfvmtp50x8id"
image_name == "pkroswfvmtp50x8"
}
}

void 'can scrape packer logs for image name for windows in SIG'() {
setup:
@Subject
AzureBakeHandler azureBakeHandler = new AzureBakeHandler()

when:
def logsContent =
"==> azure-arm: Deleting the temporary OS disk ...\n" +
"==> azure-arm: -> OS Disk : 'https://lgpackervms.blob.core.windows.net/images/pkroswfvmtp50x8.vhd'\n" +
"==> azure-arm:\n" +
"==> azure-arm: Cleanup requested, deleting resource group ...\n" +
"==> azure-arm: Error deleting resource group. Please delete it manually.\n" +
"==> azure-arm:\n" +
"==> azure-arm: Name: packer-Resource-Group-wfvmtp50x8\n" +
"==> azure-arm: Error: azure#updatePollingState: Azure Polling Error - Unable to obtain polling URI for DELETE : StatusCode=0\n" +
"==> azure-arm: Resource group has been deleted.\n" +
"Build 'azure-arm' finished.\n" +
"\n" +
"==> Builds finished. The artifacts of successful builds are:\n" +
"--> azure-arm: Azure.ResourceManagement.VMImage:\n" +
"\n" +
"StorageAccountLocation: westus\n" +
"ManagedImageName: pkroswfvmtp50x8\n" +
"ManagedImageSharedImageGalleryId: pkroswfvmtp50x8id"


Bake bake = azureBakeHandler.scrapeCompletedBakeResults(null, "123", logsContent)

then:
with (bake) {
id == "123"
ami == "pkroswfvmtp50x8id"
image_name == "pkroswfvmtp50x8"
}
}

void 'template file name data is serialized as expected'() {
setup:
@Subject
Expand Down

0 comments on commit 0a782e9

Please sign in to comment.