Updated README
Updated storage account integration test
This commit is contained in:
Родитель
e6a5f60bc8
Коммит
c818562fba
15
README.md
15
README.md
|
@ -378,8 +378,7 @@ params = {
|
|||
:vm_user => 'azureuser',
|
||||
:image => '5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-63APR20130415',
|
||||
:password => 'Password',
|
||||
:location => 'West US',
|
||||
:affinity_group_name => 'affinity1'
|
||||
:location => 'West US'
|
||||
}
|
||||
options = {
|
||||
:storage_account_name => 'storage_suse',
|
||||
|
@ -391,9 +390,17 @@ options = {
|
|||
:certificate_file => 'c:/certificate.pem', #required for ssh or winrm(https) certificate.
|
||||
:ssh_port => 2222,
|
||||
:vm_size => 'Small', #valid choices are (ExtraSmall, Small, Medium, Large, ExtraLarge, A6, A7)
|
||||
:virtual_network_name => 'xplattestvnet'
|
||||
:affinity_group_name => 'affinity1',
|
||||
:virtual_network_name => 'xplattestvnet',
|
||||
:subnet_name => 'subnet1'
|
||||
}
|
||||
virtual_machine_service.create_virtual_machine(params, options)
|
||||
virtual_machine_service.create_virtual_machine(params,options,add_role=false)
|
||||
# Here add_role is used as a flag to create multiple roles under the same cloud service. This parameter is false
|
||||
# by default. Atleast a single deployment should be created under a hosted service prior to setting this flag.
|
||||
|
||||
#API usage to add new roles under cloud service creating VM
|
||||
|
||||
virtual_machine_service.create_virtual_machine(params,options,add_role=true)
|
||||
|
||||
#Get a list of available virtual machine images
|
||||
virtual_machine_image_service = Azure::VirtualMachineImageManagementService.new
|
||||
|
|
|
@ -130,7 +130,7 @@ module Azure
|
|||
request = SqlManagementHttpRequest.new(method, request_path, body)
|
||||
request.headers['x-ms-version'] = '1.0'
|
||||
request.uri = URI.parse(Azure.config.sql_database_management_endpoint + Azure.config.subscription_id + request_path)
|
||||
# SQL Server authentication Endpoint throws errors for this operation. Need to re-visit
|
||||
# Management certificate authentication Endpoint throws errors for this operation. Need to re-visit
|
||||
# this once the Azure API is working.
|
||||
|
||||
request.call
|
||||
|
|
|
@ -1,289 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require "test_helper"
|
||||
require 'azure/storage_management/storage_account'
|
||||
|
||||
describe Azure::StorageManagementService do
|
||||
|
||||
subject { Azure::StorageManagementService.new }
|
||||
let(:request_path) {'/services/storageservices'}
|
||||
let(:method) { :post }
|
||||
let(:mock_request){ mock() }
|
||||
let(:get_storage_account_properties) { Fixtures["get_storage_account_properties_new"] }
|
||||
let(:responseStorageProps) {
|
||||
responseStorageProps = mock()
|
||||
responseStorageProps.stubs(:body).returns(get_storage_account_properties)
|
||||
responseStorageProps
|
||||
}
|
||||
let(:responseStorageProps_body) {Nokogiri::XML responseStorageProps.body}
|
||||
let(:create_storage_name_error) { Fixtures["create_storage_name_error"] }
|
||||
let(:response) {
|
||||
response = mock()
|
||||
response.stubs(:body).returns(create_storage_name_error)
|
||||
response
|
||||
}
|
||||
let(:response_body) {Nokogiri::XML response.body}
|
||||
|
||||
let(:create_storage_location_error) { Fixtures["create_storage_location_error"] }
|
||||
let(:responseLoc) {
|
||||
responseLoc = mock()
|
||||
responseLoc.stubs(:body).returns(create_storage_location_error)
|
||||
responseLoc
|
||||
}
|
||||
let(:responseLoc_body) {Nokogiri::XML responseLoc.body}
|
||||
let(:create_storage_desc_error) { Fixtures["create_storage_desc_error"] }
|
||||
let(:responseDescErr) {
|
||||
responseDescErr = mock()
|
||||
responseDescErr.stubs(:body).returns(create_storage_desc_error)
|
||||
responseDescErr
|
||||
}
|
||||
let(:responseDescErr_body) {Nokogiri::XML responseDescErr.body}
|
||||
|
||||
let(:create_storage_extendedprop_error) { Fixtures["create_storage_extendedprop_error"] }
|
||||
let(:responseExtndErr) {
|
||||
responseExtndErr = mock()
|
||||
responseExtndErr.stubs(:body).returns(create_storage_extendedprop_error)
|
||||
responseExtndErr
|
||||
}
|
||||
let(:responseExtndErr_body) {Nokogiri::XML responseExtndErr.body}
|
||||
let(:create_storage_extendedpropname_error) { Fixtures["create_storage_extendedpropname_error"] }
|
||||
let(:responseExtndNameErr) {
|
||||
responseExtndNameErr = mock()
|
||||
responseExtndNameErr.stubs(:body).returns(create_storage_extendedpropname_error)
|
||||
responseExtndNameErr
|
||||
}
|
||||
|
||||
let(:responseExtndNameErr_body) {Nokogiri::XML responseExtndNameErr.body}
|
||||
|
||||
let(:create_storage_label_error) { Fixtures["create_storage_label_error"] }
|
||||
let(:responseLabelErr) {
|
||||
responseLabelErr = mock()
|
||||
responseLabelErr.stubs(:body).returns(create_storage_label_error)
|
||||
responseLabelErr
|
||||
}
|
||||
|
||||
let(:responseLabelErr_body) {Nokogiri::XML responseLabelErr.body}
|
||||
let(:paramsLocInvalid){
|
||||
{
|
||||
:location => "West US",
|
||||
}
|
||||
}
|
||||
let(:paramsLoc){
|
||||
{
|
||||
:location => "West US",
|
||||
}
|
||||
}
|
||||
let(:paramsDesc){
|
||||
{
|
||||
:description => "Description",
|
||||
:location => "West US",
|
||||
}
|
||||
}
|
||||
let(:paramsDescInvalid){
|
||||
{
|
||||
:location => "West US",
|
||||
:description => "..............................................................................................................................................................................................................................................................................................................",
|
||||
}
|
||||
}
|
||||
let(:paramsAffinityGrp){
|
||||
{
|
||||
:affinity_group_name => "agbabu1"
|
||||
}
|
||||
}
|
||||
let(:paramslocGeoTrue){
|
||||
{
|
||||
:location => "West US",
|
||||
:geo_replication_enabled => 'true',
|
||||
}
|
||||
}
|
||||
let(:paramslocGeoFalse){
|
||||
{
|
||||
:location => "West US",
|
||||
:geo_replication_enabled => 'false',
|
||||
}
|
||||
}
|
||||
let(:paramsExtendedPropsValue){
|
||||
{
|
||||
:location => "West US",
|
||||
:extended_properties =>{:blobs =>'verbose...............................................
|
||||
........................................................................................
|
||||
.........................This is a lengthy value...............................................................
|
||||
........................................................................................
|
||||
',:test =>'test'},
|
||||
}
|
||||
}
|
||||
let(:paramsExtendedProps){
|
||||
{
|
||||
:location => "West US",
|
||||
:extended_properties =>{:blobs =>'verbose',:test =>'test'},
|
||||
}
|
||||
}
|
||||
let(:paramsExtendedPropsName){
|
||||
{
|
||||
:location => "West US",
|
||||
:extended_properties =>{:blobnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnns =>'verbose',:test =>'test'},
|
||||
}
|
||||
}
|
||||
let(:paramsLabel){
|
||||
{
|
||||
:location => "West US",
|
||||
:label => "ValidLabel"
|
||||
}
|
||||
}
|
||||
|
||||
let(:paramsLabelInvalid){
|
||||
{
|
||||
:location => "West US",
|
||||
:label => "ValidLabel.................................................................................................................
|
||||
............................................
|
||||
...................................
|
||||
...............................",
|
||||
}
|
||||
}
|
||||
before{
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
}
|
||||
|
||||
describe "#create_storage_account" do
|
||||
|
||||
it "Create storage account with long name" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('longstoragename..............................................').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.create_storage_account 'longstoragename..............................................'
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^The name is not a valid storage account name. Storage account names must be between 3 and 24 characters in\nlength and use numbers and lower-case letters only.*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
it "Create storage account name with spl characters" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('%^%$$^$^').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.create_storage_account '%^%$$^$^'
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^The name is not a valid storage account name. Storage account names must be between 3 and 24 characters in
|
||||
length and use numbers and lower-case letters only.*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
it "Create storage account with valid name and invalid location" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('invalidlocation').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseLoc
|
||||
subject.create_storage_account('invalidlocation',paramsLocInvalid)
|
||||
msg = responseLoc_body.at('Error')
|
||||
assert_match(/^The location constraint is not valid*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
|
||||
it "Create valid storage account with only name and valid location" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns 'succeeded'
|
||||
subject.create_storage_account('storageacc',paramsLoc)
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account_properties).with('storageacc').returns(responseStorageProps)
|
||||
subject.get_storage_account_properties('storageacc')
|
||||
msg = responseStorageProps_body.at('StorageServiceProperties')
|
||||
assert_match(/^Created*/, msg.at('Status').text)
|
||||
end
|
||||
|
||||
it "Create valid storage account with only name and valid description" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validdesc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseLoc
|
||||
subject.create_storage_account('validdesc',paramsDesc)
|
||||
msg = responseLoc_body.at('Error')
|
||||
assert_match(/^The location constraint is not valid*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
it "Create valid storage account with only name, location and long description" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('longdesc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseDescErr_body
|
||||
subject.create_storage_account('longdesc',paramsDescInvalid)
|
||||
msg = responseDescErr_body.at('Error')
|
||||
assert_match(/^The description is too long*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
it "Create storage account with name and affinity group" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns ""
|
||||
subject.create_storage_account('storageacc',paramsAffinityGrp)
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account_properties).with('storageacc').returns(responseStorageProps)
|
||||
subject.get_storage_account_properties('storageacc')
|
||||
msg = responseStorageProps_body.at('StorageServiceProperties')
|
||||
assert_match(/^Created*/, msg.at('Status').text)
|
||||
assert_match(/^agbabu1*/, msg.at('AffinityGroup').text)
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and geo_replication_enabled true" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns ""
|
||||
subject.create_storage_account('storageacc',paramslocGeoTrue)
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account_properties).with('storageacc').returns(responseStorageProps)
|
||||
subject.get_storage_account_properties('storageacc')
|
||||
msg = responseStorageProps_body.at('StorageServiceProperties')
|
||||
assert_match(/^Created*/, msg.at('Status').text)
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and geo_replication_enabled false" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns ""
|
||||
subject.create_storage_account('storageacc',paramslocGeoFalse)
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account_properties).with('storageacc').returns(responseStorageProps)
|
||||
subject.get_storage_account_properties('storageacc')
|
||||
msg = responseStorageProps_body.at('StorageServiceProperties')
|
||||
assert_match(/^Created*/, msg.at('Status').text)
|
||||
assert_match(/^false*/, msg.at('GeoReplicationEnabled').text)
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and extended properties" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns "succeeded"
|
||||
msg = subject.create_storage_account('storageacc',paramsExtendedProps)
|
||||
assert_match(/^succeeded*/, msg)
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and lengthy extended property value" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseExtndErr
|
||||
subject.create_storage_account('storageacc',paramsExtendedPropsValue)
|
||||
msg = responseExtndErr_body.at('Error')
|
||||
assert_match(/^verbose...............................................
|
||||
........................................................................................
|
||||
.........................This is a lengthy value...............................................................
|
||||
........................................................................................ value is too long. Only 255 characters are permitted*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and lengthy extended property name" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseExtndNameErr
|
||||
subject.create_storage_account('storageacc',paramsExtendedPropsName)
|
||||
msg = responseExtndNameErr_body.at('Error')
|
||||
assert_match(/^Extended property name blobnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
|
||||
nnnnnnnnns is too long. Only 64 characters are permitted.*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and label" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns ""
|
||||
subject.create_storage_account('storageacc',paramsLabel)
|
||||
msg = responseExtndNameErr_body.at('Error')
|
||||
assert_match(/^*/, "")
|
||||
end
|
||||
|
||||
it "Create storage account with name, location and lengthy label" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('storageacc').returns(false)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseLabelErr
|
||||
subject.create_storage_account('storageacc',paramsLabelInvalid)
|
||||
msg = responseLabelErr_body.at('Error')
|
||||
assert_match(/^The label is not a valid storage account label.*/, msg.at('Message').text)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,59 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require "test_helper"
|
||||
require 'azure/storage_management/storage_account'
|
||||
|
||||
describe Azure::StorageManagementService do
|
||||
|
||||
subject { Azure::StorageManagementService.new }
|
||||
let(:request_path) {'/services/storageservices'}
|
||||
let(:method) { :post }
|
||||
let(:mock_request){ mock() }
|
||||
let(:delete_storage_error) { Fixtures["delete_storage_error"] }
|
||||
let(:responseResourceNotFound) {
|
||||
responseResourceNotFound = mock()
|
||||
responseResourceNotFound.stubs(:body).returns(delete_storage_error)
|
||||
responseResourceNotFound
|
||||
}
|
||||
let(:responseResourceNotFound_body) {Nokogiri::XML responseResourceNotFound.body}
|
||||
let(:delete_storage_container_error) { Fixtures["delete_storage_container_error"] }
|
||||
let(:responseBadRequest) {
|
||||
responseBadRequest = mock()
|
||||
responseBadRequest.stubs(:body).returns(delete_storage_container_error)
|
||||
responseBadRequest
|
||||
}
|
||||
let(:responseBadRequest_body) {Nokogiri::XML responseBadRequest.body}
|
||||
|
||||
before{
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
}
|
||||
|
||||
describe "#delete_storage_account" do
|
||||
|
||||
it "Delete non existing storage account" do
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseResourceNotFound_body
|
||||
subject.delete_storage_account 'invalidstorageacc'
|
||||
msg = responseResourceNotFound_body.at('Error')
|
||||
assert_match(/^ResourceNotFound*/, msg.at('Code').text)
|
||||
end
|
||||
|
||||
it "Delete storage account with containers having disks" do
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns responseBadRequest_body
|
||||
subject.delete_storage_account 'storagewithcontainer'
|
||||
msg = responseBadRequest_body.at('Error')
|
||||
assert_match(/^BadRequest*/, msg.at('Code').text)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require "test_helper"
|
||||
require 'azure/storage_management/storage_account'
|
||||
|
||||
describe Azure::StorageManagementService do
|
||||
|
||||
subject { Azure::StorageManagementService.new }
|
||||
let(:request_path) {'/services/storageservices'}
|
||||
let(:method) { :get }
|
||||
let(:mock_request){ mock() }
|
||||
let(:get_storage_account_properties) { Fixtures["get_storage_account_properties_new"] }
|
||||
let(:responseStorageProps) {
|
||||
responseStorageProps = mock()
|
||||
responseStorageProps.stubs(:body).returns(get_storage_account_properties)
|
||||
responseStorageProps
|
||||
}
|
||||
let(:responseStorageProps_body) {Nokogiri::XML responseStorageProps.body}
|
||||
|
||||
before{
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
}
|
||||
|
||||
describe "#create_storage_account" do
|
||||
|
||||
it "Get storage account properties" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account_properties).with('storageacc').returns(responseStorageProps)
|
||||
subject.get_storage_account_properties('storageacc')
|
||||
msg = responseStorageProps_body.at('StorageServiceProperties')
|
||||
#Description assertion fails as there is a bug in RDFE for the description value not getting updated accordingly
|
||||
# assert_match(/^Description*/, msg.at('Description').text)
|
||||
assert_match(/^agbabu1*/, msg.at('AffinityGroup').text)
|
||||
assert_match(/^VmFsaWRMYWJlbA==*/, msg.at('Label').text)
|
||||
#assert_match(/^Created*/, msg.at('Created').text)
|
||||
assert_match(/^false*/, msg.at('GeoReplicationEnabled').text)
|
||||
#assert_match(/^false*/, msg.at('GeoPrimaryRegion').text)
|
||||
#msg = responseStorageProps_body.at('ExtendedProperty')
|
||||
#assert_match(/^verbose*/, msg.at('blob').text)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require 'test_helper'
|
||||
|
||||
describe Azure::StorageManagementService do
|
||||
|
||||
subject { Azure::StorageManagementService.new }
|
||||
let(:request_path) { '/services/storageservices' }
|
||||
let(:get_storage_accounts_xml) { Fixtures['get_storage_properties'] }
|
||||
let(:method) { :get }
|
||||
let(:mock_request) { mock }
|
||||
let(:response) do
|
||||
response = mock
|
||||
response.stubs(:body).returns(get_storage_accounts_xml)
|
||||
response
|
||||
end
|
||||
let(:get_storage_account_error_xml) { Fixtures['get_storage_account_error'] }
|
||||
let(:response1) do
|
||||
response1 = mock
|
||||
response1.stubs(:body).returns(get_storage_account_error_xml)
|
||||
response1
|
||||
end
|
||||
let(:response_body) { Nokogiri::XML response.body }
|
||||
before do
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
end
|
||||
|
||||
describe '#get_storage_account' do
|
||||
it 'Get storage account by specifying null' do
|
||||
result = subject.get_storage_account nil
|
||||
result.must_equal false
|
||||
end
|
||||
|
||||
it 'Get storage account with valid name' do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validname').returns(true)
|
||||
result = subject.get_storage_account 'validname'
|
||||
result.must_equal true
|
||||
end
|
||||
|
||||
it 'Get storage account with invalid name - spl characters' do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('invalidname@@@@@@@@@@@@@@@@@@').returns(false)
|
||||
result = subject.get_storage_account 'invalidname@@@@@@@@@@@@@@@@@@'
|
||||
result.must_equal false
|
||||
end
|
||||
|
||||
it 'Get storage account with invalid name - long name' do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('invalidname....................................').returns(false)
|
||||
result = subject.get_storage_account 'invalidname....................................'
|
||||
result.must_equal false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,160 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2015 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require 'integration/test_helper'
|
||||
|
||||
describe Azure::StorageManagementService do
|
||||
subject { Azure::StorageManagementService.new }
|
||||
affinity_name = random_string('affinity-group-', 10)
|
||||
Azure::BaseManagementService.new.create_affinity_group(
|
||||
affinity_name,
|
||||
'West US',
|
||||
'Label Name'
|
||||
)
|
||||
StorageName = random_string('storagetest', 10)
|
||||
opts = {
|
||||
affinity_group_name: affinity_name,
|
||||
label: 'storagelabel',
|
||||
description: 'This is a storage account',
|
||||
geo_replication_enabled: 'true'
|
||||
}
|
||||
Azure::StorageManagementService.new.create_storage_account(StorageName, opts)
|
||||
|
||||
let(:affinity_group_name) { affinity_name }
|
||||
let(:storage_name) { Time.now.getutc.to_i.to_s }
|
||||
let(:location) { 'West US' }
|
||||
let(:label) { 'Label Name' }
|
||||
let(:options) { { description: 'sample description' } }
|
||||
|
||||
before do
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
end
|
||||
|
||||
it 'list storage accounts' do
|
||||
storagelist = subject.list_storage_accounts
|
||||
storagelist.wont_be_nil
|
||||
storagelist.must_be_kind_of Array
|
||||
end
|
||||
|
||||
it 'get storage account' do
|
||||
storage = subject.get_storage_account('nonexistentstorage')
|
||||
storage.must_equal false
|
||||
end
|
||||
|
||||
it 'create storage account' do
|
||||
options = {
|
||||
affinity_group_name: affinity_group_name,
|
||||
label: 'storagelabel',
|
||||
description: 'This is a storage account',
|
||||
geo_replication_enabled: 'false'
|
||||
}
|
||||
subject.create_storage_account(storage_name, options)
|
||||
present = subject.get_storage_account(storage_name)
|
||||
present.must_equal true
|
||||
# Test for delete storage account
|
||||
subject.delete_storage_account(storage_name)
|
||||
present = subject.get_storage_account(storage_name)
|
||||
present.must_equal false
|
||||
end
|
||||
|
||||
it 'get storage account' do
|
||||
storage_name = StorageName
|
||||
present = subject.get_storage_account(storage_name)
|
||||
present.must_equal true
|
||||
end
|
||||
|
||||
it 'get storage account properties' do
|
||||
storage_name = StorageName
|
||||
storage = subject.get_storage_account_properties(storage_name)
|
||||
storage.name.must_equal storage_name
|
||||
storage.label.must_equal 'storagelabel'
|
||||
storage.geo_replication_enabled.must_equal 'true'
|
||||
end
|
||||
|
||||
it 'update storage account' do
|
||||
options = {
|
||||
label: 'labelchanged',
|
||||
description: 'description changed'
|
||||
}
|
||||
storage_name = StorageName
|
||||
subject.update_storage_account(storage_name, options)
|
||||
storage = subject.get_storage_account_properties(storage_name)
|
||||
storage.name.must_equal storage_name
|
||||
storage.label.must_equal 'labelchanged'
|
||||
subject.update_storage_account(storage_name, opts)
|
||||
end
|
||||
|
||||
it 'get storage account properties error' do
|
||||
storage_name = 'invalidstorage'
|
||||
exception = assert_raises(RuntimeError) do
|
||||
subject.get_storage_account_properties(storage_name)
|
||||
end
|
||||
assert_match(/The storage account 'invalidstorage' was not found/, exception.message)
|
||||
end
|
||||
|
||||
it 'create storage account with invalid storage name' do
|
||||
options = {
|
||||
affinity_group_name: 'affinitygrouptest',
|
||||
label: 'storagelabel',
|
||||
description: 'This is a storage account',
|
||||
geo_replication_enabled: 'false'
|
||||
}
|
||||
storage_name = 'ba'
|
||||
exception = assert_raises(RuntimeError) do
|
||||
subject.create_storage_account(storage_name, options)
|
||||
end
|
||||
assert_match(/Storage account names must be between 3 and 24/, exception.message)
|
||||
end
|
||||
|
||||
it 'create storage account with invalid location' do
|
||||
options = {
|
||||
location: 'West1 US',
|
||||
label: 'storagelabel',
|
||||
description: 'This is a storage account',
|
||||
geo_replication_enabled: 'false'
|
||||
}
|
||||
exception = assert_raises(RuntimeError) do
|
||||
subject.create_storage_account(storage_name, options)
|
||||
end
|
||||
assert_match('The location constraint is not valid', exception.message)
|
||||
end
|
||||
|
||||
it 'create storage account with invalid affinity group' do
|
||||
options = {
|
||||
affinity_group_name: 'invalidaffinitygroup',
|
||||
label: 'storagelabel',
|
||||
description: 'This is a storage account',
|
||||
geo_replication_enabled: 'false'
|
||||
}
|
||||
exception = assert_raises(RuntimeError) do
|
||||
subject.create_storage_account(storage_name, options)
|
||||
end
|
||||
assert_match('The affinity group does not exist.', exception.message)
|
||||
end
|
||||
|
||||
it 'update storage account with non existent storage name' do
|
||||
options = {
|
||||
label: 'labelchanged',
|
||||
description: 'description changed'
|
||||
}
|
||||
storage_name = 'storage_nonexistent'
|
||||
storage = subject.update_storage_account(storage_name, options)
|
||||
assert_match(/Storage Account 'storage_nonexistent' does not exist. Skipped.../, storage)
|
||||
end
|
||||
|
||||
it 'delete storage account that does not exist' do
|
||||
msg = subject.delete_storage_account('invalidstorageaccount')
|
||||
assert_match(/The storage account 'invalidstorageaccount' was not found./, msg)
|
||||
end
|
||||
end
|
|
@ -1,126 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require "test_helper"
|
||||
require 'azure/storage_management/storage_account'
|
||||
|
||||
describe Azure::StorageManagementService do
|
||||
|
||||
subject { Azure::StorageManagementService.new }
|
||||
let(:request_path) {'/services/storageservices'}
|
||||
let(:method) { :post }
|
||||
let(:mock_request){ mock() }
|
||||
let(:update_storage_error) { Fixtures["update_storage_error"] }
|
||||
let(:response) {
|
||||
response = mock()
|
||||
response.stubs(:body).returns(update_storage_error)
|
||||
response
|
||||
}
|
||||
let(:response_body) {Nokogiri::XML response.body}
|
||||
let(:params){
|
||||
{
|
||||
:label => "SampleLabel",
|
||||
:description => "SampleDescription"
|
||||
}
|
||||
}
|
||||
let(:params1){
|
||||
{
|
||||
:label => "SampleLabel",
|
||||
:geo_replication_enabled => 'invalid',
|
||||
}
|
||||
}
|
||||
let(:params2){
|
||||
{
|
||||
:label => "SampleLabel",
|
||||
:description => '.'*1000,
|
||||
:geo_replication_enabled => 'invalid',
|
||||
}
|
||||
}
|
||||
let(:params3){
|
||||
{
|
||||
:label => '.'*1000,
|
||||
:description => "sampledescription",
|
||||
:geo_replication_enabled => 'invalid',
|
||||
}
|
||||
}
|
||||
let(:params4){
|
||||
{
|
||||
:label => '@#@#@#@#@',
|
||||
:description => nil,
|
||||
:geo_replication_enabled => nil,
|
||||
}
|
||||
}
|
||||
|
||||
before{
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
}
|
||||
|
||||
describe "update_storage_account" do
|
||||
|
||||
it "Update non existing storage account" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('nonexistantstorageacc').returns(false)
|
||||
msg = subject.update_storage_account('nonexistantstorageacc',params)
|
||||
assert_match(/^Storage Account 'nonexistantstorageacc' does not exist. Skipped...*/, msg)
|
||||
end
|
||||
|
||||
|
||||
it "Update invalid geo_replication_enabled value" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validstoragename').returns(true)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.update_storage_account('validstoragename',params1)
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^InvalidXmlRequest*/, msg.at('Code').text)
|
||||
end
|
||||
|
||||
|
||||
it "Update long description" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validstoragename').returns(true)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.update_storage_account('validstoragename',params2)
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^InvalidXmlRequest*/, msg.at('Code').text)
|
||||
end
|
||||
|
||||
it "Update long label" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validstoragename').returns(true)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.update_storage_account('validstoragename',params3)
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^InvalidXmlRequest*/, msg.at('Code').text)
|
||||
end
|
||||
|
||||
it "Update long description" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validstoragename').returns(true)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.update_storage_account('validstoragename',params2)
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^InvalidXmlRequest*/, msg.at('Code').text)
|
||||
end
|
||||
|
||||
it "Update label with spl characters" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validstoragename').returns(true)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns response_body
|
||||
subject.update_storage_account('validstoragename',params3)
|
||||
msg = response_body.at('Error')
|
||||
assert_match(/^InvalidXmlRequest*/, msg.at('Code').text)
|
||||
end
|
||||
|
||||
it "Update valid geo_location_enabled" do
|
||||
Azure::StorageManagementService.any_instance.stubs(:get_storage_account).with('validstoragename').returns(true)
|
||||
ManagementHttpRequest.any_instance.expects(:call).returns ""
|
||||
subject.update_storage_account('validstoragename',params3)
|
||||
assert_match(/^*/, "")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -84,6 +84,15 @@ class VirtualMachineNameGenerator
|
|||
end
|
||||
end
|
||||
|
||||
# Delete storage account
|
||||
storage_service = Azure::StorageManagementService.new
|
||||
storage_accounts = storage_service.list_storage_accounts
|
||||
storage_accounts.each do |storage_account|
|
||||
if storage_account.name.include?('storagetest')
|
||||
storage_service.delete_storage_account(storage_account.name) rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
# Delete affinity groups
|
||||
affinity_group_service = Azure::BaseManagementService.new
|
||||
affinity_groups = affinity_group_service.list_affinity_groups
|
||||
|
@ -95,14 +104,6 @@ class VirtualMachineNameGenerator
|
|||
end
|
||||
end
|
||||
|
||||
# Delete storage account
|
||||
storage_service = Azure::StorageManagementService.new
|
||||
storage_accounts = storage_service.list_storage_accounts
|
||||
storage_accounts.each do |storage_account|
|
||||
if storage_account.name.include?('storagetest')
|
||||
storage_service.delete_storage_account(storage_account.name) rescue nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче