azure 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,11 @@ describe Azure::VirtualMachineImageManagementService do
36
36
  describe "#list_virtual_machine_images" do
37
37
 
38
38
  before {
39
- ManagementHttpRequest.stubs(:new).with(method, request_path, nil).returns(mock_request)
39
+ ManagementHttpRequest.stubs(:new).with(
40
+ method,
41
+ request_path,
42
+ nil
43
+ ).returns(mock_request)
40
44
  mock_request.expects(:call).returns(response_body)
41
45
  }
42
46
 
@@ -46,14 +50,15 @@ describe Azure::VirtualMachineImageManagementService do
46
50
 
47
51
  it "sets the properties of the virtual machine images" do
48
52
  virtual_machine_image = subject.list_virtual_machine_images.first
49
- virtual_machine_image.name.must_equal '0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.2-x64-v5.8.8.1'
53
+ virtual_machine_image.name.must_equal 'RightImage-CentOS-6.2-x64-v5.8.8.1'
50
54
  end
51
55
 
52
56
  it "returns a list of virtual machine images from server" do
53
57
  results = subject.list_virtual_machine_images
54
58
  results.must_be_kind_of Array
55
59
  results.length.must_equal 12
56
- results.first.must_be_kind_of Azure::VirtualMachineImageManagement::VirtualMachineImage
60
+ image_klass = Azure::VirtualMachineImageManagement::VirtualMachineImage
61
+ results.first.must_be_kind_of image_klass
57
62
  end
58
63
  end
59
64
 
@@ -12,27 +12,27 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "test_helper"
15
+ require 'test_helper'
16
16
 
17
17
  describe Azure::VirtualMachineManagement::Serialization do
18
18
  subject { Azure::VirtualMachineManagement::Serialization }
19
19
 
20
- let(:virtual_machine_xml) { Nokogiri::XML(Fixtures["virtual_machine"]) }
21
- let(:cloud_service_name) { 'cloud-service-1' }
20
+ let(:vm_xml) { Nokogiri::XML(Fixtures['virtual_machine']) }
21
+ let(:csn) { 'cloud-service-1' }
22
22
 
23
- describe "#virtual_machines_from_xml" do
23
+ describe '#virtual_machines_from_xml' do
24
24
 
25
- it "accepts an XML string" do
26
- subject.virtual_machines_from_xml(virtual_machine_xml,cloud_service_name)
25
+ it 'accepts an XML string' do
26
+ subject.virtual_machines_from_xml(vm_xml, csn)
27
27
  end
28
28
 
29
- it "returns an Array of VirtualMachine instances" do
30
- result = subject.virtual_machines_from_xml(virtual_machine_xml,cloud_service_name).first
29
+ it 'returns an Array of VirtualMachine instances' do
30
+ result = subject.virtual_machines_from_xml(vm_xml, csn).first
31
31
  result.must_be_kind_of Azure::VirtualMachineManagement::VirtualMachine
32
32
  end
33
33
 
34
34
  it "returns a virtual_machine, with it's attribute populated" do
35
- virtual_machine = subject.virtual_machines_from_xml(virtual_machine_xml,cloud_service_name).first
35
+ virtual_machine = subject.virtual_machines_from_xml(vm_xml, csn).first
36
36
  virtual_machine.vm_name.must_equal 'instance-name'
37
37
  virtual_machine.role_size.must_equal 'Small'
38
38
  virtual_machine.hostname.must_equal 'host-name'
@@ -43,18 +43,36 @@ describe Azure::VirtualMachineManagement::Serialization do
43
43
  end
44
44
 
45
45
  it "returns a virtual_machine, with it's tcp_endpoints attribute" do
46
- virtual_machine = subject.virtual_machines_from_xml(virtual_machine_xml,cloud_service_name).first
46
+ virtual_machine = subject.virtual_machines_from_xml(vm_xml, csn).first
47
47
  virtual_machine.tcp_endpoints.must_be_kind_of Array
48
- virtual_machine.tcp_endpoints.must_include({"Name"=>"SSH", "Vip"=>"137.116.17.187", "PublicPort"=>"22", "LocalPort"=>"22"})
49
- virtual_machine.tcp_endpoints.must_include({"Name"=>"tcp-port-80", "Vip"=>"137.116.17.187", "PublicPort"=>"80", "LocalPort"=>"80"})
50
- virtual_machine.tcp_endpoints.must_include({"Name"=>"tcp-port-3889", "Vip"=>"137.116.17.187", "PublicPort"=>"3889", "LocalPort"=>"3889"})
48
+ virtual_machine.tcp_endpoints.must_include(
49
+ name: 'SSH',
50
+ vip: '137.116.17.187',
51
+ public_port: '22',
52
+ local_port: '22',
53
+ protocol: 'tcp'
54
+ )
55
+ virtual_machine.tcp_endpoints.must_include(
56
+ name: 'tcp-port-80',
57
+ vip: '137.117.17.187',
58
+ public_port: '80',
59
+ local_port: '80',
60
+ protocol: 'tcp'
61
+ )
62
+ virtual_machine.tcp_endpoints.must_include(
63
+ name: 'tcp-port-3889',
64
+ vip: '137.116.17.187',
65
+ public_port: '3889',
66
+ local_port: '3889',
67
+ protocol: 'tcp'
68
+ )
51
69
  end
52
70
 
53
71
  end
54
72
 
55
- describe "#shutdown_virtual_machine_to_xml" do
73
+ describe '#shutdown_virtual_machine_to_xml' do
56
74
 
57
- it "returns an xml for virtual machine shutdown" do
75
+ it 'returns an xml for virtual machine shutdown' do
58
76
  result = subject.shutdown_virtual_machine_to_xml
59
77
  result.must_be_kind_of String
60
78
  doc = Nokogiri::XML(result)
@@ -64,9 +82,9 @@ describe Azure::VirtualMachineManagement::Serialization do
64
82
 
65
83
  end
66
84
 
67
- describe "#start_virtual_machine_to_xml" do
85
+ describe '#start_virtual_machine_to_xml' do
68
86
 
69
- it "returns an xml for start virtual machine" do
87
+ it 'returns an xml for start virtual machine' do
70
88
  result = subject.start_virtual_machine_to_xml
71
89
  result.must_be_kind_of String
72
90
  doc = Nokogiri::XML(result)
@@ -75,45 +93,114 @@ describe Azure::VirtualMachineManagement::Serialization do
75
93
 
76
94
  end
77
95
 
78
- describe "#deployment_to_xml" do
79
- let(:params){
96
+ describe '#restart_virtual_machine_to_xml' do
97
+
98
+ it 'returns an xml for restart virtual machine' do
99
+ result = subject.restart_virtual_machine_to_xml
100
+ result.must_be_kind_of String
101
+ doc = Nokogiri::XML(result)
102
+ doc.css('OperationType').text.must_equal 'RestartRoleOperation'
103
+ end
104
+
105
+ end
106
+
107
+ describe '#deployment_to_xml' do
108
+ let(:params)do
80
109
  {
81
- :vm_name => 'virtual-machine-name',
82
- :vm_user => 'username',
83
- :image => 'linux_image',
84
- :password => 'password',
85
- :location => 'West US'
110
+ vm_name: 'virtual-machine-name',
111
+ vm_user: 'username',
112
+ image: 'linux_image',
113
+ password: 'password',
114
+ location: 'West US'
86
115
  }
87
- }
116
+ end
88
117
 
89
- let(:options) {
118
+ let(:options) do
90
119
  {
91
- :storage_account_name => 'storageaccountname',
92
- :cloud_service_name => 'cloud-service-name',
93
- :tcp_endpoints => '80,3389:3390,85:85',
94
- :availability_set_name => 'aval-set'
120
+ storage_account_name: 'storageaccountname',
121
+ cloud_service_name: 'cloud-service-name',
122
+ tcp_endpoints: '80,3389:3390,85:85',
123
+ availability_set_name: 'aval-set'
95
124
  }
96
- }
125
+ end
97
126
 
98
- it "returns an VirtualMachine object with correct tcp endpoints" do
127
+ it 'returns an VirtualMachine object with correct tcp endpoints' do
128
+ params[:certificate] = { fingerprint: 'CFB8C256D2986559C630547F2D0' }
99
129
  result = subject.deployment_to_xml params, options
100
130
  doc = Nokogiri::XML(result)
101
131
  endpoints = doc.css('Deployment RoleList ConfigurationSet InputEndpoints InputEndpoint')
102
132
  tcp_endpoints = []
103
133
  endpoints.each do |endpoint|
104
- hash = Hash.new
105
- hash['Name'] = xml_content(endpoint, 'Name')
106
- hash['PublicPort'] = xml_content(endpoint, 'Port')
107
- hash['LocalPort'] = xml_content(endpoint, 'LocalPort')
108
- tcp_endpoints << hash
134
+ ep = {}
135
+ ep[:name] = xml_content(endpoint, 'Name')
136
+ ep[:public_port] = xml_content(endpoint, 'Port')
137
+ ep[:local_port] = xml_content(endpoint, 'LocalPort')
138
+ tcp_endpoints << ep
109
139
  end
110
140
  doc.css('Deployment RoleList AvailabilitySetName').text.must_equal 'aval-set'
111
141
  result.must_be_kind_of String
112
- tcp_endpoints.must_include({"Name"=>"TCP-PORT-80", "PublicPort"=>"80", "LocalPort"=>"80"})
113
- tcp_endpoints.must_include({"Name"=>"TCP-PORT-3390", "PublicPort"=>"3390", "LocalPort"=>"3389"})
114
- tcp_endpoints.must_include({"Name"=>"TCP-PORT-85", "PublicPort"=>"85", "LocalPort"=>"85"})
142
+ tcp_endpoints.must_include(
143
+ name: 'TCP-PORT-80',
144
+ public_port: '80',
145
+ local_port: '80'
146
+ )
147
+ tcp_endpoints.must_include(
148
+ name: 'TCP-PORT-3390',
149
+ public_port: '3390',
150
+ local_port: '3389'
151
+ )
152
+ tcp_endpoints.must_include(
153
+ name: 'TCP-PORT-85',
154
+ public_port: '85',
155
+ local_port: '85'
156
+ )
157
+ end
158
+ end
159
+
160
+ describe '#add_data_disk_to_xml' do
161
+
162
+ let(:options) do
163
+ { disk_size: 100 }
164
+ end
165
+ let(:media_link) { 'https://sta.blob.managment.core.net/vhds/1234.vhd' }
166
+ let(:lun) { 5 }
167
+ before do
168
+ Loggerx.expects(:puts).returns(nil).at_least(0)
169
+ end
170
+
171
+ it 'returns an xml for newly created data disk' do
172
+ result = subject.add_data_disk_to_xml(lun, media_link , options)
173
+ doc = Nokogiri::XML(result)
174
+ disk_size = doc.css('DataVirtualHardDisk LogicalDiskSizeInGB').text
175
+ media_link = doc.css('DataVirtualHardDisk MediaLink').text
176
+ disk_name = doc.css('DataVirtualHardDisk DiskName').text
177
+ result.must_be_kind_of String
178
+ doc.css('DataVirtualHardDisk Lun').text.must_equal lun.to_s
179
+ disk_size.must_equal options[:disk_size].to_s
180
+ media_link.wont_be_empty
181
+ disk_name.must_be_empty
115
182
  end
116
183
 
184
+ it 'returns an xml for existing data disk' do
185
+ options[:import] = true
186
+ options[:disk_name] = 'disk_name'
187
+ result = subject.add_data_disk_to_xml(lun, media_link , options)
188
+ doc = Nokogiri::XML(result)
189
+ media_link = doc.css('DataVirtualHardDisk MediaLink').text
190
+ disk_name = doc.css('DataVirtualHardDisk DiskName').text
191
+ result.must_be_kind_of String
192
+ doc.css('DataVirtualHardDisk Lun').text.must_equal lun.to_s
193
+ media_link.must_be_empty
194
+ disk_name.wont_be_empty
195
+ end
196
+
197
+ it 'raise error when disk name is empty' do
198
+ options[:import] = true
199
+ exception = assert_raises(RuntimeError) do
200
+ subject.add_data_disk_to_xml(lun, media_link , options)
201
+ end
202
+ assert_match(/The data disk name is not valid/i, exception.message)
203
+ end
117
204
  end
118
205
 
119
206
  end
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "test_helper"
15
+ require 'test_helper'
16
16
 
17
17
  describe Azure::VirtualMachineManagementService do
18
18
  VirtualMachine = Azure::VirtualMachineManagement::VirtualMachine
@@ -21,91 +21,91 @@ describe Azure::VirtualMachineManagementService do
21
21
  Azure::VirtualMachineManagementService.new
22
22
  end
23
23
 
24
- before{
24
+ before do
25
25
  Loggerx.stubs(:info).returns(nil)
26
- }
26
+ end
27
27
 
28
- let(:params){
28
+ let(:params)do
29
29
  {
30
- :vm_name => 'instance1',
31
- :vm_user => 'root',
32
- :image => "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-63APR20130415",
33
- :password => 'root',
34
- :location => 'West US'
30
+ vm_name: 'instance1',
31
+ vm_user: 'root',
32
+ image: '5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-63APR20130415',
33
+ password: 'root',
34
+ location: 'West US'
35
35
  }
36
- }
36
+ end
37
37
 
38
- let(:windows_params){
38
+ let(:windows_params)do
39
39
  {
40
- :vm_name => 'instance1',
41
- :vm_user => 'administrator',
42
- :image => "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201304.01-en.us-127GB.vhd",
43
- :password => 'Admin123',
44
- :location => 'West US'
40
+ vm_name: 'instance1',
41
+ vm_user: 'administrator',
42
+ image: 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201304.01-en.us-127GB.vhd',
43
+ password: 'Admin123',
44
+ location: 'West US'
45
45
  }
46
- }
46
+ end
47
47
 
48
48
  let(:location_request_path) { '/locations' }
49
49
  let(:locations_xml) { Fixtures['list_locations'] }
50
- let(:location_response) {
51
- response = mock()
50
+ let(:location_response) do
51
+ response = mock
52
52
  response.stubs(:body).returns(locations_xml)
53
53
  response
54
- }
54
+ end
55
55
  let(:location_response_body) { Nokogiri::XML location_response.body }
56
56
 
57
- describe "#list_virtual_machines" do
57
+ describe '#list_virtual_machines' do
58
58
  let(:request_path) { '/services/hostedservices' }
59
- let(:cloud_services_xml) { Fixtures["list_cloud_services"] }
60
- let(:virtual_machine_xml) { Fixtures["virtual_machine"] }
61
- let(:deployment_error_xml) { Fixtures["deployment_error"] }
62
- let(:virtual_networks_xml) { Fixtures["list_virtual_networks"] }
59
+ let(:cloud_services_xml) { Fixtures['list_cloud_services'] }
60
+ let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
61
+ let(:deployment_error_xml) { Fixtures['deployment_error'] }
62
+ let(:virtual_networks_xml) { Fixtures['list_virtual_networks'] }
63
63
 
64
64
  let(:method) { :get }
65
65
 
66
- let(:mock_cloud_service_request){ mock() }
67
- let(:mock_virtual_machine_request){ mock() }
68
- let(:mock_virtual_network_request){ mock() }
66
+ let(:mock_cloud_service_request) { mock }
67
+ let(:mock_virtual_machine_request) { mock }
68
+ let(:mock_virtual_network_request) { mock }
69
69
 
70
- let(:cloud_service_response) {
71
- cloud_service_response = mock()
70
+ let(:cloud_service_response) do
71
+ cloud_service_response = mock
72
72
  cloud_service_response.stubs(:body).returns(cloud_services_xml)
73
73
  cloud_service_response
74
- }
74
+ end
75
75
 
76
- let(:virtual_machine_response) {
77
- virtual_machine_response = mock()
76
+ let(:virtual_machine_response) do
77
+ virtual_machine_response = mock
78
78
  virtual_machine_response.stubs(:body).returns(virtual_machine_xml)
79
79
  virtual_machine_response
80
- }
80
+ end
81
81
 
82
- let(:deployment_error_response) {
83
- http_error_response = mock()
82
+ let(:deployment_error_response) do
83
+ http_error_response = mock
84
84
  http_error_response.stubs(:body).returns(deployment_error_xml)
85
85
  http_error_response
86
- }
86
+ end
87
87
 
88
- let(:virtual_networks_response) {
89
- virtual_networks_response = mock()
88
+ let(:virtual_networks_response) do
89
+ virtual_networks_response = mock
90
90
  virtual_networks_response.stubs(:body).returns(virtual_networks_xml)
91
91
  virtual_networks_response
92
- }
92
+ end
93
93
 
94
94
  let(:cloud_service_response_body) { Nokogiri::XML cloud_service_response.body }
95
95
  let(:virtual_machine_response_body) { Nokogiri::XML virtual_machine_response.body }
96
96
  let(:virtual_networks_response_body) { Nokogiri::XML virtual_networks_response.body }
97
97
 
98
- before {
98
+ before do
99
99
  ManagementHttpRequest.stubs(:new).with(method, request_path, nil).returns(mock_cloud_service_request)
100
100
  mock_cloud_service_request.expects(:call).returns(cloud_service_response_body)
101
- ManagementHttpRequest.stubs(:new).with(method, "/services/hostedservices/cloud-service-1/deploymentslots/production").returns(mock_virtual_machine_request)
101
+ ManagementHttpRequest.stubs(:new).with(method, '/services/hostedservices/cloud-service-1/deploymentslots/production').returns(mock_virtual_machine_request)
102
102
  mock_virtual_machine_request.stubs(:warn=).returns(true).twice
103
- ManagementHttpRequest.stubs(:new).with(method, "/services/hostedservices/cloud-service-2/deploymentslots/production").returns(mock_virtual_machine_request)
103
+ ManagementHttpRequest.stubs(:new).with(method, '/services/hostedservices/cloud-service-2/deploymentslots/production').returns(mock_virtual_machine_request)
104
104
  mock_virtual_machine_request.expects(:call).twice.returns(virtual_machine_response_body).returns(Nokogiri::XML deployment_error_response.body)
105
105
  ManagementHttpRequest.stubs(:new).with(method, '/services/networking/virtualnetwork', nil).returns(mock_virtual_network_request)
106
- }
106
+ end
107
107
 
108
- it "assembles a URI for the request" do
108
+ it 'assembles a URI for the request' do
109
109
  subject.list_virtual_machines
110
110
  end
111
111
 
@@ -120,7 +120,7 @@ describe Azure::VirtualMachineManagementService do
120
120
  virtual_machine.virtual_network_name.must_equal 'test-virtual-network'
121
121
  end
122
122
 
123
- it "returns a list of virtual machines for the subscription" do
123
+ it 'returns a list of virtual machines for the subscription' do
124
124
  results = subject.list_virtual_machines
125
125
  results.must_be_kind_of Array
126
126
  results.length.must_equal 1
@@ -130,245 +130,296 @@ describe Azure::VirtualMachineManagementService do
130
130
  it "returns a virtual_machine, with it's tcp_endpoints attribute" do
131
131
  virtual_machine = subject.list_virtual_machines.first
132
132
  virtual_machine.tcp_endpoints.must_be_kind_of Array
133
- virtual_machine.tcp_endpoints.must_include({"Name"=>"SSH", "Vip"=>"137.116.17.187", "PublicPort"=>"22", "LocalPort"=>"22"})
134
- virtual_machine.tcp_endpoints.must_include({"Name"=>"tcp-port-80", "Vip"=>"137.116.17.187", "PublicPort"=>"80", "LocalPort"=>"80"})
135
- virtual_machine.tcp_endpoints.must_include({"Name"=>"tcp-port-3889", "Vip"=>"137.116.17.187", "PublicPort"=>"3889", "LocalPort"=>"3889"})
133
+ virtual_machine.tcp_endpoints.must_include(
134
+ name: 'SSH',
135
+ vip: '137.116.17.187',
136
+ public_port: '22',
137
+ local_port: '22',
138
+ protocol: 'tcp'
139
+ )
140
+ virtual_machine.tcp_endpoints.must_include(
141
+ name: 'tcp-port-80',
142
+ vip: '137.117.17.187',
143
+ public_port: '80',
144
+ local_port: '80',
145
+ protocol: 'tcp'
146
+ )
147
+ virtual_machine.tcp_endpoints.must_include(
148
+ name: 'tcp-port-3889',
149
+ vip: '137.116.17.187',
150
+ public_port: '3889',
151
+ local_port: '3889',
152
+ protocol: 'tcp'
153
+ )
136
154
  end
137
155
  end
138
156
 
139
- describe "#get_virtual_machine" do
157
+ describe '#get_virtual_machine' do
140
158
 
141
- before {
159
+ before do
142
160
  virtual_machine = VirtualMachine.new do |virtual_machine|
143
161
  virtual_machine.vm_name = 'instance-name'
144
162
  virtual_machine.cloud_service_name = 'cloud-service-1'
145
163
  end
146
- Azure::VirtualMachineManagementService.any_instance.stubs(:list_virtual_machines).returns([virtual_machine])
147
- }
164
+ Azure::VirtualMachineManagementService.any_instance.stubs(
165
+ :list_virtual_machines
166
+ ).returns([virtual_machine])
167
+ end
148
168
 
149
- it "return nil if virtual machine and cloud server does not exist " do
150
- virtual_machine = subject.get_virtual_machine 'name','cloud-service'
169
+ it 'return nil if virtual machine and cloud server does not exist ' do
170
+ virtual_machine = subject.get_virtual_machine 'name', 'cloud-service'
151
171
  virtual_machine.must_equal nil
152
172
  end
153
173
 
154
- it "return nil if virtual machine or cloud server does not exist " do
155
- virtual_machine = subject.get_virtual_machine 'name','cloud-service-1'
174
+ it 'return nil if virtual machine or cloud server does not exist ' do
175
+ virtual_machine = subject.get_virtual_machine 'name', 'cloud-service-1'
156
176
  virtual_machine.must_equal nil
157
- virtual_machine = subject.get_virtual_machine 'instance-name','cloud_service_name'
177
+ virtual_machine = subject.get_virtual_machine 'instance-name', 'cloud_service_name'
158
178
  virtual_machine.must_equal nil
159
179
  end
160
180
 
161
- it "return virtual machine instance if virtual machine name and cloud server name are valid " do
162
- virtual_machine = subject.get_virtual_machine 'instance-name','cloud-service-1'
181
+ it 'return virtual machine instance if virtual machine name and cloud server name are valid ' do
182
+ virtual_machine = subject.get_virtual_machine 'instance-name', 'cloud-service-1'
163
183
  virtual_machine.must_be_kind_of VirtualMachine
164
184
  end
165
185
  end
166
186
 
167
- describe "#create_virtual_machine" do
168
- let(:images_request_path) {'/services/images'}
169
- let(:images_xml) { Fixtures["list_images"] }
170
- let(:virtual_machine_xml) { Fixtures["virtual_machine"] }
187
+ describe '#create_virtual_machine' do
188
+ let(:images_request_path) { '/services/images' }
189
+ let(:images_xml) { Fixtures['list_images'] }
190
+ let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
171
191
  let(:method) { :get }
172
- let(:mock_request){ mock() }
192
+ let(:mock_request) { mock }
173
193
 
174
- let(:os_response_body) {
175
- response = mock()
194
+ let(:os_response_body) do
195
+ response = mock
176
196
  response.stubs(:body).returns(images_xml)
177
197
  Nokogiri::XML response.body
178
- }
198
+ end
179
199
 
180
- before {
181
- ManagementHttpRequest.stubs(:new).with(method, images_request_path, nil).returns(mock_request)
200
+ before do
201
+ ManagementHttpRequest.stubs(:new).with(
202
+ method,
203
+ images_request_path,
204
+ nil
205
+ ).returns(mock_request)
182
206
  mock_request.expects(:call).returns(os_response_body)
183
- mock_request = mock()
184
- ManagementHttpRequest.stubs(:new).with(method, location_request_path, nil).returns(mock_request)
207
+ mock_request = mock
208
+ ManagementHttpRequest.stubs(:new).with(
209
+ method,
210
+ location_request_path,
211
+ nil
212
+ ).returns(mock_request)
185
213
  mock_request.expects(:call).returns(location_response_body).at_least(0)
186
214
  Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
187
215
  Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
188
216
  Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
189
- mock_request = mock()
190
- ManagementHttpRequest.expects(:new).with(:post,anything, anything).returns(mock_request)
217
+ mock_request = mock
218
+ ManagementHttpRequest.expects(:new).with(
219
+ :post,
220
+ anything,
221
+ anything
222
+ ).returns(mock_request)
191
223
  mock_request.expects(:call).returns(nil)
192
- virtual_machine = VirtualMachine.new do |virtual_machine|
193
- virtual_machine.vm_name = 'instance-name'
194
- virtual_machine.ipaddress = '192.168.1.1'
224
+ virtual_machine = VirtualMachine.new do |vm|
225
+ vm.vm_name = 'instance-name'
226
+ vm.ipaddress = '192.168.1.1'
195
227
  end
196
- Azure::VirtualMachineManagementService.stubs(:get_virtual_machine).returns(virtual_machine)
197
- }
228
+ Azure::VirtualMachineManagementService.stubs(
229
+ :get_virtual_machine
230
+ ).returns(virtual_machine)
231
+ end
198
232
 
199
- it "should set options hash with valid cloud_service_name, deployment_name, storage_account_name." do
233
+ it 'should set options hash with valid cloud_service_name, deployment_name, storage_account_name.' do
200
234
  options = {}
201
- virtual_machine = subject.create_virtual_machine(params, options)
202
- options[:cloud_service_name].wont_be_nil
235
+ subject.create_virtual_machine(params, options)
236
+ csn = options[:cloud_service_name]
237
+ csn.wont_be_nil
203
238
  options[:storage_account_name].wont_be_nil
204
239
  options[:deployment_name].wont_be_nil
205
240
  options[:os_type].must_equal 'Linux'
206
- assert_match(/^#{params[:vm_name]+'-service'}*/, "#{options[:cloud_service_name]}")
241
+ assert_match(/^#{params[:vm_name] + '-service'}*/, csn)
207
242
  end
208
243
 
209
- it "should set options hash with valid cloud service name." do
244
+ it 'should set options hash with valid cloud service name.' do
210
245
  options = {
211
- :storage_account_name =>'storage_account_name',
212
- :deployment_name =>'unique_deployment_name',
213
- :tcp_endpoints => '80,3889:3889'
246
+ storage_account_name: 'storage_account_name',
247
+ deployment_name: 'unique_deployment_name',
248
+ tcp_endpoints: '80,3889:3889'
214
249
  }
215
- virtual_machine = subject.create_virtual_machine(params, options)
216
- options[:cloud_service_name].wont_be_nil
217
- assert_match(/^#{params[:vm_name]+'-service-'}*/, "#{options[:cloud_service_name]}")
250
+ subject.create_virtual_machine(params, options)
251
+ csn = options[:cloud_service_name]
252
+ csn.wont_be_nil
253
+ assert_match(/^#{params[:vm_name] + '-service-'}*/, csn)
218
254
  options[:os_type].must_equal 'Linux'
219
255
  end
220
256
 
221
257
  end
222
258
 
223
- describe "#create_virtual_machine with invalid parameters for windows machine" do
259
+ describe '#create_virtual_machine with invalid parameters for windows machine' do
224
260
  let(:images_request_path) { '/services/images' }
225
- let(:windows_images_xml) { Fixtures["list_images"] }
226
- let(:virtual_machine_xml) { Fixtures["virtual_machine"] }
261
+ let(:windows_images_xml) { Fixtures['list_images'] }
262
+ let(:virtual_machine_xml) { Fixtures['virtual_machine'] }
227
263
  let(:method) { :get }
228
- let(:mock_request){ mock() }
229
- let(:os_response_body) {
230
- response = mock()
264
+ let(:mock_request) { mock }
265
+ let(:os_response_body) do
266
+ response = mock
231
267
  response.stubs(:body).returns(windows_images_xml)
232
268
  Nokogiri::XML response.body
233
- }
269
+ end
234
270
 
235
- before {
236
- ManagementHttpRequest.stubs(:new).with(method, images_request_path, nil).returns(mock_request)
271
+ before do
272
+ ManagementHttpRequest.stubs(:new).with(
273
+ method,
274
+ images_request_path,
275
+ nil
276
+ ).returns(mock_request)
237
277
  mock_request.expects(:call).returns(os_response_body)
238
- mock_request = mock()
239
- ManagementHttpRequest.stubs(:new).with(method, location_request_path, nil).returns(mock_request)
278
+ mock_request = mock
279
+ ManagementHttpRequest.stubs(:new).with(
280
+ method,
281
+ location_request_path,
282
+ nil
283
+ ).returns(mock_request)
240
284
  mock_request.expects(:call).returns(location_response_body).at_least(0)
241
285
  Azure::CloudServiceManagementService.any_instance.stubs(:create_cloud_service)
242
286
  Azure::CloudServiceManagementService.any_instance.stubs(:upload_certificate)
243
287
  Azure::StorageManagementService.any_instance.stubs(:create_storage_account)
244
288
  Loggerx.expects(:puts).returns(nil).at_least(0)
245
- mock_request = mock()
246
- ManagementHttpRequest.expects(:new).with(:post,anything, anything).returns(mock_request).at_least(0)
289
+ mock_request = mock
290
+ ManagementHttpRequest.expects(:new).with(
291
+ :post,
292
+ anything,
293
+ anything
294
+ ).returns(mock_request).at_least(0)
247
295
  mock_request.expects(:call).returns(nil).at_least(0)
248
296
  virtual_machine_obj = VirtualMachine.new do |virtual_machine|
249
297
  virtual_machine.vm_name = 'windows-instance'
250
298
  virtual_machine.ipaddress = '192.168.1.1'
251
299
  end
252
- Azure::VirtualMachineManagementService.any_instance.stubs(:get_virtual_machine).returns(virtual_machine_obj)
253
- }
300
+ Azure::VirtualMachineManagementService.any_instance.stubs(
301
+ :get_virtual_machine
302
+ ).returns(virtual_machine_obj)
303
+ end
254
304
 
255
- it "should set options os_type with windows." do
305
+ it 'should set options os_type with windows.' do
256
306
  options = {}
257
- virtual_machine = subject.create_virtual_machine(windows_params, options)
258
- options[:cloud_service_name].wont_be_nil
307
+ subject.create_virtual_machine(windows_params, options)
308
+ csn = options[:cloud_service_name]
309
+ csn.wont_be_nil
259
310
  options[:storage_account_name].wont_be_nil
260
311
  options[:deployment_name].wont_be_nil
261
312
  options[:os_type].must_equal 'Windows'
262
- assert_match(/^#{params[:vm_name]+'-service'}*/, "#{options[:cloud_service_name]}")
313
+ assert_match(/^#{params[:vm_name] + '-service'}*/, csn)
263
314
  end
264
315
 
265
- it "throws error when vm_user is not given" do
316
+ it 'throws error when vm_user is not given' do
266
317
  windows_params.delete(:vm_user)
267
318
  options = {}
268
319
  virtual_machine = subject.create_virtual_machine(windows_params, options)
269
320
  assert_match(/You did not provide a valid 'vm_user' value*/, virtual_machine)
270
321
  end
271
322
 
272
- it "self-signed certificate is generated by vm and used for the virtual machine when certificate path is not given." do
273
- options = {
274
- :winrm_transport => ['https','http']
275
- }
323
+ it 'self-signed certificate is generated by vm and used for the virtual machine when certificate path is not given.' do
324
+ options = { winrm_transport: %w(https http) }
276
325
  virtual_machine = subject.create_virtual_machine(windows_params, options)
277
326
  virtual_machine.wont_be_nil
278
327
  end
279
328
 
280
- it "throws error when certificate path is not invalid." do
329
+ it 'throws error when certificate path is not invalid.' do
281
330
  options = {
282
- :winrm_transport => ['https','http'],
283
- :private_key_file => 'f:/invalid_path/private_key' ,
284
- :certificate_file => 'f:/invalid_path/certificate.pem'
331
+ winrm_transport: %w(https http),
332
+ private_key_file: 'f:/invalid_path/private_key' ,
333
+ certificate_file: 'f:/invalid_path/certificate.pem'
285
334
  }
286
335
  virtual_machine = subject.create_virtual_machine(windows_params, options)
287
336
  assert_match(/No such file or directory -*/, virtual_machine)
288
337
  end
289
338
 
290
- it "should not throws certificate error when wirnm_transport is http" do
339
+ it 'should not throws certificate error when wirnm_transport is http' do
291
340
  options = {
292
- :winrm_transport => ['http'],
293
- :private_key_file => 'f:/invalid_path/private_key' ,
294
- :certificate_file => 'f:/invalid_path/certificate.pem'
341
+ winrm_transport: ['http'],
342
+ private_key_file: 'f:/invalid_path/private_key' ,
343
+ certificate_file: 'f:/invalid_path/certificate.pem'
295
344
  }
296
345
  virtual_machine = subject.create_virtual_machine(windows_params, options)
297
- virtual_machine.must_be_kind_of Azure::VirtualMachineManagement::VirtualMachine
346
+ virtual_machine.must_be_kind_of VirtualMachine
298
347
  virtual_machine.wont_be_nil
299
348
  end
300
349
 
301
- it "throws error when location is not given" do
350
+ it 'throws error when location is not given' do
302
351
  params.delete(:location)
303
352
  virtual_machine = subject.create_virtual_machine(params)
304
- assert_match(/You did not provide a valid 'location' value*/, virtual_machine)
353
+ error_msg = "You did not provide a valid 'location' value"
354
+ assert_match(/#{error_msg}*/, virtual_machine)
305
355
  end
306
356
 
307
- it "throws error when wrong location is given" do
308
- params.merge!(:location => 'wrong location')
357
+ it 'throws error when wrong location is given' do
358
+ params.merge!(location: 'wrong location')
309
359
  virtual_machine = subject.create_virtual_machine(params)
310
360
  assert_match(/Value 'wrong location' specified for parameter 'location' is invalid.*/, virtual_machine)
311
361
  end
312
362
 
313
- it "throws error when empty location is given" do
314
- params.merge!(:location => nil)
363
+ it 'throws error when empty location is given' do
364
+ params.merge!(location: nil)
315
365
  virtual_machine = subject.create_virtual_machine(params)
316
366
  assert_match(/You did not provide a valid 'location' value*/, virtual_machine)
317
367
  end
318
368
 
319
- it "location should be case insensitive" do
320
- params.merge!(:location => 'west us')
369
+ it 'location should be case insensitive' do
370
+ params.merge!(location: 'west us')
321
371
  subject.create_virtual_machine(params)
322
372
  end
323
373
 
324
- it "throw error when available_services has not persistentvmrole for given location" do
325
- params.merge!(:location => 'West Europe')
374
+ it 'throw error when available_services has not persistentvmrole for given location' do
375
+ params.merge!(location: 'West Europe')
326
376
  msg = subject.create_virtual_machine(params)
327
377
  assert_match(/Persistentvmrole not enabled for "West Europe"*/, msg)
328
378
  end
329
379
 
330
- it "vm_size should be case sensitive" do
380
+ it 'vm_size should be case sensitive' do
331
381
  options = {
332
- :vm_size => 'extralarge'
382
+ vm_size: 'extralarge'
333
383
  }
334
384
  msg = subject.create_virtual_machine(params, options)
335
- assert_match(/Value 'extralarge' specified for parameter 'vm_size' is invalid/,msg)
385
+ assert_match(/Value 'extralarge' specified for parameter 'vm_size' is invalid/, msg)
336
386
  end
337
387
 
338
- it "throws error when wrong role size is given" do
388
+ it 'throws error when wrong role size is given' do
339
389
  options = {
340
- :vm_size => 'wrong size'
390
+ vm_size: 'wrong size'
341
391
  }
342
392
  virtual_machine = subject.create_virtual_machine(params, options)
343
- assert_match(/Value 'wrong size' specified for parameter 'vm_size' is invalid.*/, virtual_machine)
393
+ error_msg = "'wrong size' specified for parameter 'vm_size' is invalid."
394
+ assert_match(/#{error_msg}*/, virtual_machine)
344
395
  end
345
396
 
346
- it "should not throw any error if role size is empty" do
397
+ it 'should not throw any error if role size is empty' do
347
398
  options = {
348
- :vm_size => ''
399
+ vm_size: ''
349
400
  }
350
401
  subject.create_virtual_machine(params, options)
351
402
  end
352
403
  end
353
404
 
354
- describe "#get_os_type" do
355
- let(:images_xml) { Fixtures["list_images"] }
356
- let(:mock_request){ mock() }
357
- let(:response) {
358
- response = mock()
405
+ describe '#get_os_type' do
406
+ let(:images_xml) { Fixtures['list_images'] }
407
+ let(:mock_request) { mock }
408
+ let(:response) do
409
+ response = mock
359
410
  response.stubs(:body).returns(images_xml)
360
411
  response
361
- }
362
- let(:response_body) {Nokogiri::XML response.body}
412
+ end
413
+ let(:response_body) { Nokogiri::XML response.body }
363
414
 
364
- before {
415
+ before do
365
416
  ManagementHttpRequest.any_instance.expects(:call).returns response_body
366
417
  subject.class.send(:public, *subject.class.private_instance_methods)
367
418
  Loggerx.expects(:puts).returns(nil).at_least(0)
368
- }
419
+ end
369
420
 
370
- it "returns os type of given virtual machine image" do
371
- result = subject.get_os_type '0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.2-x64-v5.8.8.1'
421
+ it 'returns os type of given virtual machine image' do
422
+ result = subject.get_os_type 'RightImage-CentOS-6.2-x64-v5.8.8.1'
372
423
  result.must_equal 'Linux'
373
424
  end
374
425
 
@@ -376,7 +427,8 @@ describe Azure::VirtualMachineManagementService do
376
427
  exception = assert_raises(RuntimeError) do
377
428
  subject.get_os_type 'invalid-image-name'
378
429
  end
379
- assert_match(/The virtual machine image source is not valid/i, exception.message)
430
+ error_msg = 'The virtual machine image source is not valid'
431
+ assert_match(/#{error_msg}/i, exception.message)
380
432
  end
381
433
  end
382
434