-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from djberg96/azure_backslash_to_forward_slash
Azure backslash to forward slash
- Loading branch information
Showing
2 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
db/migrate/20180424141617_azure_backslash_to_forward_slash.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
class AzureBackslashToForwardSlash < ActiveRecord::Migration[5.0] | ||
class Vm < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class OrchestrationStack < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class OrchestrationStackOutput < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class OrchestrationStackParameter < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class OrchestrationStackResource < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
class EventStream < ActiveRecord::Base | ||
self.inheritance_column = :_type_disabled | ||
end | ||
|
||
def up | ||
say_with_time("Updating Azure VM ems_ref, uid_ems and description") do | ||
Vm.where(:type => "ManageIQ::Providers::Azure::CloudManager::Vm") | ||
.update_all(" | ||
ems_ref = replace(ems_ref, '\\', '/'), | ||
uid_ems = replace(uid_ems, '\\', '/'), | ||
description = replace(description, '\\', '/') | ||
") | ||
end | ||
|
||
say_with_time("Updating Azure template ems_ref, uid_ems and description") do | ||
Vm.where(:type => "ManageIQ::Providers::Azure::CloudManager::Template") | ||
.update_all(" | ||
ems_ref = replace(ems_ref, '\\', '/'), | ||
uid_ems = replace(uid_ems, '\\', '/'), | ||
description = replace(description, '\\', '/') | ||
") | ||
end | ||
|
||
say_with_time("Updating Azure orchestration stack ems_ref") do | ||
OrchestrationStack | ||
.where(:type => "ManageIQ::Providers::Azure::CloudManager::OrchestrationStack") | ||
.update_all("ems_ref = replace(ems_ref, '\\', '/'), description = replace(description, '\\', '/')") | ||
end | ||
|
||
say_with_time("Updating Azure orchestration stack output ems_ref") do | ||
OrchestrationStackOutput | ||
.where(:stack_id => OrchestrationStack.where(:type => "ManageIQ::Providers::Azure::CloudManager::OrchestrationStack")) | ||
.update_all("ems_ref = replace(ems_ref, '\\', '/')") | ||
end | ||
|
||
say_with_time("Updating Azure orchestration stack parameter ems_ref") do | ||
OrchestrationStackParameter | ||
.where(:stack_id => OrchestrationStack.where(:type => "ManageIQ::Providers::Azure::CloudManager::OrchestrationStack")) | ||
.update_all("ems_ref = replace(ems_ref, '\\', '/')") | ||
end | ||
|
||
say_with_time("Updating Azure orchestration stack resource ems_ref") do | ||
OrchestrationStackResource | ||
.where(:stack_id => OrchestrationStack.where(:type => "ManageIQ::Providers::Azure::CloudManager::OrchestrationStack")) | ||
.update_all("ems_ref = replace(ems_ref, '\\', '/'), description = replace(description, '\\', '/')") | ||
end | ||
|
||
say_with_time("Updating Azure event stream ems_ref") do | ||
EventStream.where(:source => "AZURE").update_all("vm_ems_ref = replace(vm_ems_ref, '\\', '/')") | ||
end | ||
end | ||
end |
123 changes: 123 additions & 0 deletions
123
spec/migrations/20180424141617_azure_backslash_to_forward_slash_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
require_migration | ||
|
||
describe AzureBackslashToForwardSlash do | ||
let(:vm_stub) { migration_stub :Vm } | ||
let(:stack_stub) { migration_stub :OrchestrationStack } | ||
let(:stack_output_stub) { migration_stub :OrchestrationStackOutput } | ||
let(:stack_param_stub) { migration_stub :OrchestrationStackParameter } | ||
let(:stack_resource_stub) { migration_stub :OrchestrationStackResource } | ||
let(:event_stream_stub) { migration_stub :EventStream } | ||
|
||
migration_context :up do | ||
context "virtual machines" do | ||
it 'Converts backslashes to forward slashes for the ems_ref, uid_ems and description for vms' do | ||
vm = vm_stub.create!( | ||
:name => 'azure_test_vm', | ||
:ems_ref => 'xyz\some_group\microsoft.compute/virtualmachines\foo', | ||
:uid_ems => 'xyz\some_group\microsoft.compute/virtualmachines\foo', | ||
:type => 'ManageIQ::Providers::Azure::CloudManager::Vm', | ||
:description => 'some\description' | ||
) | ||
|
||
migrate | ||
vm.reload | ||
|
||
expect(vm.ems_ref).to eql('xyz/some_group/microsoft.compute/virtualmachines/foo') | ||
expect(vm.uid_ems).to eql('xyz/some_group/microsoft.compute/virtualmachines/foo') | ||
expect(vm.description).to eql('some/description') | ||
end | ||
|
||
it 'Converts backslashes to forward slashes for the ems_ref and description for templates' do | ||
template = vm_stub.create!( | ||
:name => 'azure_test_template', | ||
:ems_ref => 'xyz\some_group\microsoft.compute/virtualmachines\bar', | ||
:uid_ems => 'xyz\some_group\microsoft.compute/virtualmachines\bar', | ||
:type => 'ManageIQ::Providers::Azure::CloudManager::Template', | ||
:description => 'some\other\description' | ||
) | ||
|
||
migrate | ||
template.reload | ||
|
||
expect(template.ems_ref).to eql('xyz/some_group/microsoft.compute/virtualmachines/bar') | ||
expect(template.uid_ems).to eql('xyz/some_group/microsoft.compute/virtualmachines/bar') | ||
expect(template.description).to eql('some/other/description') | ||
end | ||
end | ||
|
||
context "orchestration" do | ||
let!(:stack) do | ||
stack_stub.create!( | ||
:name => 'azure_test_stack', | ||
:ems_ref => 'xyz/resourceGroups\foo\providers/Microsoft.Resources/deployments/stuff', | ||
:type => 'ManageIQ::Providers::Azure::CloudManager::OrchestrationStack' | ||
) | ||
end | ||
|
||
it 'Converts backslashes to forward slashes in the ems_ref column for orchestration stacks' do | ||
migrate | ||
stack.reload | ||
expect(stack.ems_ref).to eql('xyz/resourceGroups/foo/providers/Microsoft.Resources/deployments/stuff') | ||
end | ||
|
||
it 'Converts backslashes to forward slashes in the ems_ref column for orchestration stack output' do | ||
stack_output = stack_output_stub.create!( | ||
:stack_id => stack.id, | ||
:key => 'adminUserName', | ||
:value => 'me', | ||
:ems_ref => '/subscriptions/xyz/resourceGroups/some_group/providers/Microsoft.Resources/deployments/RedHat\adminUsername' | ||
) | ||
|
||
migrate | ||
stack_output.reload | ||
|
||
expect(stack_output.ems_ref).to eql('/subscriptions/xyz/resourceGroups/some_group/providers/Microsoft.Resources/deployments/RedHat/adminUsername') | ||
end | ||
|
||
it 'Converts backslashes to forward slashes in the ems_ref column for orchestration stack parameter' do | ||
stack_param = stack_param_stub.create!( | ||
:stack_id => stack.id, | ||
:name => 'location', | ||
:value => 'westus', | ||
:ems_ref => '/subscriptions/xyz/resourceGroups/some_group/providers/Microsoft.Resources/deployments/RedHat\location' | ||
) | ||
|
||
migrate | ||
stack_param.reload | ||
|
||
expect(stack_param.ems_ref).to eql('/subscriptions/xyz/resourceGroups/some_group/providers/Microsoft.Resources/deployments/RedHat/location') | ||
end | ||
|
||
it 'Converts backslashes to forward slashes in the ems_ref column for orchestration stack resource' do | ||
stack_resource = stack_resource_stub.create!( | ||
:stack_id => stack.id, | ||
:name => 'nsg', | ||
:logical_resource => 'something', | ||
:ems_ref => '/subscriptions/xyz\resourceGroups/some-group/providers/Microsoft.Network\networkSecurityGroups\nsg', | ||
:description => 'foo\bar' | ||
) | ||
|
||
migrate | ||
stack_resource.reload | ||
|
||
expect(stack_resource.ems_ref).to eql('/subscriptions/xyz/resourceGroups/some-group/providers/Microsoft.Network/networkSecurityGroups/nsg') | ||
expect(stack_resource.description).to eql('foo/bar') | ||
end | ||
end | ||
|
||
context "event streams" do | ||
it 'Converts backslashes to forward slashes in the vm_ems_ref column for event streams' do | ||
event_stream = event_stream_stub.create!( | ||
:vm_name => 'foo', | ||
:vm_ems_ref => 'xyz\some_group\microsoft.compute/virtualmachines\foo', | ||
:source => 'AZURE' | ||
) | ||
|
||
migrate | ||
event_stream.reload | ||
|
||
expect(event_stream.vm_ems_ref).to eql('xyz/some_group/microsoft.compute/virtualmachines/foo') | ||
end | ||
end | ||
end | ||
end |