Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Wrap expectations in test_that()
  Fix issues with blobs #65
  Fix errors in blob functions #65
  First example azureCreateHDI function
  New ARM test script test-6-ARM.R
  • Loading branch information
andrie committed May 31, 2017
2 parents 48b1d87 + 2b986cc commit c68ed67
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.rxproj.user
*.suo
*.sln
.Rproj.user
283 changes: 104 additions & 179 deletions R/AzureBlob.R

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions R/AzureStorageAccount.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ azureSAGetKey <- function(azureActiveContext, storageAccount,

URL <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
"/resourceGroups/", resourceGroup,
"/providers/Microsoft.Storage/storageAccounts/",
storageAccount, "/listkeys?api-version=2016-01-01")
"/providers/Microsoft.Storage/storageAccounts/", storageAccount,
"/listkeys?api-version=2016-01-01")

r <- POST(URL, azureApiHeaders(azToken), verbosity)
stopWithAzureError(r)
Expand Down
14 changes: 12 additions & 2 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,23 @@ on_failure(is_valid_storage_account) <- function(call, env) {
# --- container

is_container <- function(x) {
is.character(x) && length(x) >= 1
is.character(x) && length(x) == 1 && nchar(x) > 0
}

on_failure(is_container) <- function(call, env) {
"Provide a valid container, or set using createAzureContext()"
}
7

# --- directory

is_directory <- function(x) {
is.character(x) && length(x) == 1
}

on_failure(is_directory) <- function(call, env) {
"Provide a valid directory, or set using createAzureContext()"
}

# --- storage_key

is_storage_key <- function(x) {
Expand Down
11 changes: 11 additions & 0 deletions inst/examples/example_azureCreateHDI.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\dontrun{
library(AzureSMR)

azureCreateHDI(asc, resourceGroup = resourceGroup_name, clustername = "azuresmr_hdi_test",
storageAccount = "azuresmrhditestsa",
adminUser = "hdiadmin", adminPassword = "Azuresmr_password1",
sshUser = "sssUser_test1", sshPassword = "sshUser_password",
kind = "rserver",
debug = TRUE
)
}
4 changes: 2 additions & 2 deletions man/azureBlobLS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/azureListStorageBlobs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test-2-resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ test_that("Can create container", {
context(" - blob")
test_that("Can put, list, get and delete a blob", {
skip_if_missing_config(settingsfile)
expect_warning({
res <- azureListStorageBlobs(asc, container = "tempcontainer")
})
expect_warning({
res <- azureListStorageBlobs(asc, container = "tempcontainer")
})
expect_is(res, "data.frame")
expect_equal(ncol(res), 5)
expect_equal(nrow(res), 0)
Expand Down
103 changes: 103 additions & 0 deletions tests/testthat/test-6-ARM.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
if (interactive()) library("testthat")

settingsfile <- system.file("tests/testthat/config.json", package = "AzureSMR")
config <- read.AzureSMR.config(settingsfile)

# ------------------------------------------------------------------------

context("ARM")

asc <- createAzureContext()
with(config,
setAzureContext(asc, tenantID = tenantID, clientID = clientID, authKey = authKey)
)

azureAuthenticate(asc, verbose = FALSE)

timestamp <- format(Sys.time(), format = "%y%m%d%H%M")
resourceGroup_name <- paste0("AzureSMtest_", timestamp)

test_that("Can create resource group", {
skip_if_missing_config(settingsfile)

res <- azureCreateResourceGroup(asc, location = "centralus", resourceGroup = resourceGroup_name)
expect_true(res)

wait_for_azure(
resourceGroup_name %in% azureListRG(asc)$resourceGroup
)
expect_true(resourceGroup_name %in% azureListRG(asc)$resourceGroup)
})


paramJSON1 <- '"parameters": {"storageAccountType": {"value": "Standard_GRS"}}'

templateJSON1 <- '
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS",
"Premium_LRS"
],
"metadata": {"description": "Storage Account type"}
}
},
"variables": {"storageAccountName": "[uniquestring(resourceGroup().id)]"},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[uniquestring(resourceGroup().id)]",
"apiVersion": "2016-01-01",
"location": "[resourceGroup().location]",
"sku": {"name": "Standard_GRS"},
"kind": "Storage",
"properties": {}
}
],
"outputs": {"storageAccountName": {"type": "string","value": "[uniquestring(resourceGroup().id)]"}}
}
'

paramJSON2 <- '
"parameters" : {
"vmssName": {"value": "azuresmrvmss"},
"instanceCount": {"value": 2},
"adminUsername": {"value": "ubuntu"},
"adminPassword": {"value": "Password123"}
}'

context(" - deploy 1")
test_that("Can create resource from json", {
res <- azureDeployTemplate(asc, deplname = "Deploy1",
templateJSON = templateJSON1,
paramJSON = paramJSON1,
resourceGroup = resourceGroup_name,
verbose = FALSE)
expect_true(res)
})


context(" - deploy 2")
test_that("Can create resource from URL", {
tempURL = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-vmss-linux-jumpbox/azuredeploy.json"
res <- azureDeployTemplate(asc, deplname = "Deploy2",
templateURL = tempURL,
paramJSON = paramJSON2,
resourceGroup = resourceGroup_name,
verbose = FALSE)
expect_true(res)
})

test_that("Can delete resource group", {
skip_if_missing_config(settingsfile)

azureDeleteResourceGroup(asc, resourceGroup = resourceGroup_name)

})

0 comments on commit c68ed67

Please sign in to comment.