Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making changes for ForemanAzureRM with azure-sdk-for-ruby #36

Merged
merged 1 commit into from
Aug 19, 2019

Conversation

apuntamb
Copy link
Member

This PR is a WIP task. It deals with making changes to the foreman_azure_rm code base in alignment with the azure sdk for ruby. This PR is the first step towards using the azure-sdk instead of fog libraries.
This PR is expected to have couple of changes either with respect to functionalities or refactoring during it's review phase.
This PR shall allow user to:

  • Create an AzureRM compute resource.
  • Test Connection.
  • Create Images required for creating OS in AzureRM.
  • Create a Host to be able to deploy on AzureRM compute resource.

Although a host and other resources such as OSdisk, NIC, PIP and VM will be created and seen on the Azure portal, yet, the orchestration steps from Foreman are still in progress to be successful.

@apuntamb apuntamb requested a review from ShimShtein June 15, 2019 07:37
@apuntamb apuntamb added the WIP label Jun 15, 2019
@apuntamb apuntamb force-pushed the new_azurerm_codebase branch 3 times, most recently from 18d66a4 to fb0a65b Compare June 27, 2019 15:24
@apuntamb
Copy link
Member Author

As an update, the PR now completes the orchestration steps successfully with both User data and Finish template approach along with password and ssh-key based authentication mechanisms. However, the PR is still in WIP state as the code still needs refining.

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch 3 times, most recently from ee7c325 to a407146 Compare July 3, 2019 13:14
lib/foreman_azure_rm/azure_sdk_adapter.rb Outdated Show resolved Hide resolved
lib/foreman_azure_rm/azure_sdk_adapter.rb Outdated Show resolved Hide resolved
lib/foreman_azure_rm/azure_sdk_adapter.rb Outdated Show resolved Hide resolved
lib/foreman_azure_rm/azure_sdk_adapter.rb Outdated Show resolved Hide resolved
lib/foreman_azure_rm/azure_sdk_adapter.rb Outdated Show resolved Hide resolved
@apuntamb apuntamb force-pushed the new_azurerm_codebase branch 2 times, most recently from 5861fa1 to c3372fe Compare July 4, 2019 07:42
@vijay8451
Copy link

vijay8451 commented Jul 10, 2019

@apuntamb

QE Testing status:

Pass:

  1. Azure CR can be created
  2. Azure CR can be Updated
  3. Azure CR can be deleted
  4. 'Test Connection' to Azure successful
  5. Azure CR VMs can be displayed
  6. Azure CR Compute Profile can be displayed
  7. Azure CR image can be created
  8. Azure CR image can be updated
  9. Azure CR image can be deleted
  10. Image with 'user_data' check enabled is created
  11. Able to list the created image under CR

Fail/Blocked:

  1. VM is being provisioned using CR. => Azure subnet does not display the list of available subnet in selected Azure Region and it is blocking the create host :
    screenshots

Note: Will test more scenarios around it once above one unblocked for me.

Copy link
Member

@ShimShtein ShimShtein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to make sure the tests are running correctly. Right now Travis fails to load the tests:

/home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/definition_proxy.rb:97:in `method_missing': undefined method 'provider' in 'azure_cr' factory (NoMethodError)
	from /home/travis/build/theforeman/foreman_azure_rm/test/factories/azure.rb:3:in `block (2 levels) in <top (required)>'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:18:in `instance_eval'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:18:in `factory'
	from /home/travis/build/theforeman/foreman_azure_rm/test/factories/azure.rb:2:in `block in <top (required)>'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:49:in `instance_eval'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:49:in `run'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:7:in `define'
	from /home/travis/build/theforeman/foreman_azure_rm/test/factories/azure.rb:1:in `<top (required)>'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:20:in `block (2 levels) in find_definitions'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:19:in `each'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:19:in `block in find_definitions'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:15:in `each'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:15:in `find_definitions'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/factory_bot-5.0.2/lib/factory_bot/reload.rb:6:in `reload'
	from /home/travis/build/theforeman/foreman_azure_rm/test/test_plugin_helper.rb:6:in `<top (required)>'
	from /home/travis/build/theforeman/foreman_azure_rm/test/functional/azure_rm_test.rb:1:in `require_relative'
	from /home/travis/build/theforeman/foreman_azure_rm/test/functional/azure_rm_test.rb:1:in `<top (required)>'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/rake-12.3.2/lib/rake/rake_test_loader.rb:17:in `require'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/rake-12.3.2/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/rake-12.3.2/lib/rake/rake_test_loader.rb:5:in `select'
	from /home/travis/.rvm/gems/ruby-2.3.8/gems/rake-12.3.2/lib/rake/rake_test_loader.rb:5:in `<main>'

end

def vm_size=(setvsize)
@azure_vm.hardware_profile.vm_size = setvsize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to initialize hardware_profile in case it was not initialized before . Especially when setting up an empty instance.

@azure_vm.hardware_profile.vm_size = setvsize
end

def platform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same comment for all properties here: we should implement all getters either by using delegate or by implementing them manually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are defining only foreman specific methods in AzureRMCompute class, hence removing the other methods and added delegation for id and name methods.

end

def os_disk_size=(setosdisk)
@azure_vm.os_disk.disk_size_gb = setosdisk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to initialize os_disk in case it is not initialized before.

app/models/foreman_azure_rm/azure_rm_compute.rb Outdated Show resolved Hide resolved
app/models/foreman_azure_rm/azure_rm_compute.rb Outdated Show resolved Hide resolved
app/models/foreman_azure_rm/azure_rm_compute.rb Outdated Show resolved Hide resolved
foreman_azure_rm.gemspec Outdated Show resolved Hide resolved
# List all VMs in a resource group
virtual_machines = compute_client.virtual_machines.list(rg_name)
rg_vms = []
virtual_machines.each do |vm|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can return virtual_machines directly.

@apuntamb
Copy link
Member Author

@vijay8451 Are you selecting the Image first from Operating System tab or directly visiting Virtual Machine or Network Interfaces tab?

@vijay8451
Copy link

@vijay8451 Are you selecting the Image first from Operating System tab or directly visiting Virtual Machine or Network Interfaces tab?

@apuntamb it is like this:
Create Host => OS tab => VM tab to select minimal details => Interface to select Domain and subnet

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch 2 times, most recently from 7545f94 to fd13ec6 Compare July 11, 2019 12:18
@apuntamb
Copy link
Member Author

apuntamb commented Jul 11, 2019

@apuntamb it is like this:
Create Host => OS tab => VM tab to select minimal details => Interface to select Domain and subnet

@vijay8451 Now, it should work as expected. I've pushed the changes.

@vijay8451
Copy link

vijay8451 commented Jul 12, 2019

@vijay8451 Now, it should work as expected. I've pushed the changes.

@apuntamb I am able to list the subnet and same is showing over Azure Portal 👍

test "should create a compute resource and return edit page" do
test_client = Fog::Resources::AzureRM.new(
test_sdk = ForemanAzureRM::AzureSDKAdapter.new(
Copy link
Member Author

@apuntamb apuntamb Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShimShtein Do you think this test_sdk object should be defined outside the test so that other tests would use it too? Can we do:

test_sdk = ForemanAzureRM::AzureSDKAdapter.new(
        tenant_id: '',
        client_id: '',
        client_secret: '',
        subscription_id: ''
)
test "should create a compute resource and return edit page" do
.......
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make the sdk mock available in all tests through a class variable in setup block:

class ComputeResourcesControllerTest
  setup do
      @test_sdk = mock('test_sdk') #creates an empty object
      ForemanAzureRM::AzureRM.any_instance.stubs(:sdk).returns(test_sdk)
      @test_resource_client = mock('resource_client')
      test_sdk.stubs(:resource_client).returns(test_resource_client)
  end

  test 'do some tests'
    @test_resource_client.stubs(:rgs).returns([])
     # ...
  end

  test 'do other tests'
    @test_resource_client.stubs(:rgs).returns(['a', 'b', 'c'])
     # ...
  end
end

app/models/foreman_azure_rm/azure_rm.rb Outdated Show resolved Hide resolved
response = sdk.create_or_update_vm(vm_hash[:resource_group], vm_hash[:name], vm_create_params)

rescue MsRestAzure::AzureOperationError => e
puts "**********FAILURE!!!***********"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should ignore Azure exceptions here

app/models/foreman_azure_rm/azure_rm.rb Outdated Show resolved Hide resolved
@@ -4,19 +4,18 @@ module ForemanAzureRM
class ComputeResourcesControllerTest < ActionController::TestCase
tests ::ComputeResourcesController

setup { Fog.mock! }
teardown { Fog.unmock! }

test "should create a compute resource and return edit page" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the test is a bit misleading here, it does not create a compute resource. I displays valid edit form for existing compute resource.

ForemanAzureRM::AzureRM.any_instance.stubs(:sdk).returns(test_sdk)
test_resource_client = Object.new
test_sdk.stubs(:resource_client).returns(test_resource_client)
test_resource_client.stubs(:rgs).returns([])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a common case that resource groups would return an empty array? If it is, I would suggest adding another test with a non-empty array and validates that we are displaying the groups correctly. If this is an edge case - we can probably modify the current test to work with non-empty array.

test "should create a compute resource and return edit page" do
test_client = Fog::Resources::AzureRM.new(
test_sdk = ForemanAzureRM::AzureSDKAdapter.new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make the sdk mock available in all tests through a class variable in setup block:

class ComputeResourcesControllerTest
  setup do
      @test_sdk = mock('test_sdk') #creates an empty object
      ForemanAzureRM::AzureRM.any_instance.stubs(:sdk).returns(test_sdk)
      @test_resource_client = mock('resource_client')
      test_sdk.stubs(:resource_client).returns(test_resource_client)
  end

  test 'do some tests'
    @test_resource_client.stubs(:rgs).returns([])
     # ...
  end

  test 'do other tests'
    @test_resource_client.stubs(:rgs).returns(['a', 'b', 'c'])
     # ...
  end
end

@vijay8451
Copy link

vijay8451 commented Jul 15, 2019

@apuntamb
QE Test status:

Fails:

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch from fd13ec6 to 4fb4ddf Compare July 19, 2019 13:31
@vijay8451
Copy link

@apuntamb
QE tests status:

Pass:

  • Able to provisoin VM using Finish template and status shows installed.
  • Able to login with user added/specified during Host create.

Fails/Issues:

  • Bug #27365 (Create host with username+SSHKey fails with error 'undefined method `id' for nil:NilClass')
  • Bug #26499 (on Foreman UI=> VM properties widget is overlapping)
  • Bug #26483 (VM 'Platform/Region/Vm size/' value always shows 'N/A' after VM create.)
  • Bug #27364 (Azure Region list shows less than from portal list)

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch 2 times, most recently from e909759 to cf8f40f Compare July 22, 2019 12:17
@apuntamb
Copy link
Member Author

UPDATE:
In this latest commit, there is no explicit require statement in any file. So, I assume for testing/reviewing, the gems viz. azure_mgmt_compute, resources, network and storage should be added to the foreman's bundler.d/Gemfile.local before starting the server.

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch 3 times, most recently from 62eb81f to ae083ef Compare August 6, 2019 16:17
Copy link
Member

@ShimShtein ShimShtein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apuntamb, we need to make Travis green again before we merge this PR.

Issue created: #37 to track one major refactor.
Probably will add a lot of smaller refactoring issues later.

@vijay8451 Could you please make a round of testing before I merge the PR? I don't see any major changes to the code anymore. There is only the issue with Travis, but it shouldn't make any difference as for testing.

@vijay8451
Copy link

@ShimShtein @apuntamb Thanks for the update. I'll start testing part on below but it would great to have update on:
What are the Azure redmine issues fixed under recent reflector ?

@apuntamb
Copy link
Member Author

@ShimShtein thanks for the review. I'll start fixing Travis errors now, let's see why it goes red. Also, about the refactor issue you've created, I'll now take a look at it.

@apuntamb
Copy link
Member Author

@vijay8451 I'll start marking redmine issues (if any) that you should take a look while testing.

@apuntamb
Copy link
Member Author

@vijay8451 please take a look at the #27271 tracker that has issues linked which are ready for testing.

@apuntamb
Copy link
Member Author

apuntamb commented Aug 13, 2019

@vijay8451 For your reference, this PR will cover the following use cases:

  • Create an AzureRM compute resource.
  • Test Connection.
  • Create Images required for creating OS in AzureRM.
  • Create a Host to be able to deploy on AzureRM compute resource.
  • Create a single NIC, single disk (the default vm size that is selected), create public/private IP for the VM.
  • Create a VM with 'password' or 'sshkey'.
  • Create a VM with or without 'script command'. Eg: "touch ~/hello.txt".
  • Destroy VM.
  • List all the VMs under VM tab on Compute Resources page.

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch from ae083ef to 56758ed Compare August 13, 2019 10:40
@vijay8451
Copy link

vijay8451 commented Aug 14, 2019

@apuntamb @ShimShtein

QE Test Status:

Pass:

Azure CR can be created. => Pass
Azure CR can be Updated => Pass
Azure CR can be deleted. => Pass
'Test Connection' to Azure successful. => Pass
Azure CR image can be created => Pass
Azure CR image can be updated => Pass
Azure CR image can be deleted => Pass
Image with 'user_data' check enabled is created. => Pass
Able to list the created image under CR. => Pass
VM is being provisioned using CR. => Pass
Able to list the Azure Region/Resource Group/VM Size/Platform/Subnet. => Partial Pass[Pending issue: https://projects.theforeman.org/issues/27364]
VM provisioned is listed in CR. => Pass
Hostname in provisioned VM is set correctly. => Pass
Provisioned VM can be deleted. => Pass
Post-install scripts are being executed on provisioned VM. => Pass
SSH Keys of user are being added to the provisioned VM.
External IP is being associated to provisioned VM. => Pass
VM should be provisioned with 'User-data template/cloud-init' and shows' Installed' status on Satellite => Partial Pass[facing some issue around User data]
VM should be provisioned with 'Finish template' and shows'Installed' status on Satellite => Pass
VM should provisioned with username+password => Pass
VM should provisioned with username+SSH-Key => Pass

New Issues/Failed tests:

Two times ask for non-root user details : https://projects.theforeman.org/issues/27618
Compute Resourse: Name difference: https://projects.theforeman.org/issues/27619
Compute Resourse: VM list table missing Label 'Action' on top of 'Power on/Off delete' Button : https://projects.theforeman.org/issues/27620
Click on 'Compute profile' fails with undefined method `reflect_on_association' for ForemanAzureRM::AzureRMCompute:Class: https://projects.theforeman.org/issues/27621
After edit the created Image provided password gets blank: https://projects.theforeman.org/issues/27622
Managed Image ID or Marketplace URN does not have validation to check provided URN is real exists or not.: https://projects.theforeman.org/issues/27623
VM can power off/on. => Failed due to already exists Bugs[https://projects.theforeman.org/issues/27304, https://projects.theforeman.org/issues/27305]
VM Edit: Able to click on edit however 'Virtual Machine' and 'Interface' shows values deselected : https://projects.theforeman.org/issues/27303

Others:

Requires to comment line 15(Faraday::default_adapter=:excon) in lib/foreman_azure_rm/engine.rb to create CR.

Open Questions/Queries:

  1. Why custom URI script running through root user only ? as it's excepted to be run through non-root user created only ..
  2. Why UserData/Cloud-init created VM has Compute Resource ssh-key copied to root and nonroot users authorized_keys ? and which one is expected one?
  3. Currently userdata template is not executing on created VM.

add_attribute(:user) { 'azurermuser' }
add_attribute(:password) { 'azurermpassword' }
add_attribute(:url) { 'http://azurerm.example.com' }
add_attribute(:uuid) { 'azurermuuid' }
Copy link

@vijay8451 vijay8451 Aug 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much helpful , if use the mock data format as using in actually:

i.e. add_attribute(:uuid) { 'a0a086e2-da7a-4059-aafe-9cc07cc519cd' }

same for user, password, url.

@apuntamb apuntamb force-pushed the new_azurerm_codebase branch from 56758ed to 5c4500d Compare August 14, 2019 11:21
@apuntamb
Copy link
Member Author

@vijay8451 Thanks for bringing the issues into our notice.
I would like you to test User data template with the latest commit. It is working for me. Let me know if you still face any issues.

@vijay8451
Copy link

@apuntamb

Below are working now:

  1. Userdata
  2. URI script running through non-root user

Below is an open one only:

  1. Why UserData/Cloud-init created VM has Compute Resource ssh-key copied to root and nonroot users authorized_keys ? and which one is expected one?

Note: Just to clear, other reported issues are required to fix as well but currently not a blocker for this PR.

@ShimShtein ShimShtein merged commit 590fb36 into theforeman:master Aug 19, 2019
@ShimShtein
Copy link
Member

Thanks, @apuntamb and @vijay8451!
I am confident enough to merge this new version. Now we have a lot of work in fixing bugs and adding missing functionality, but at least we have a good place to start with.

@ShimShtein
Copy link
Member

@vijay8451, about the ssh keys issue: from what I see, if you set up admin user instead of root, it does put the certificate in both, but it disables ssh login by the .sss/auth_keys file. It creates a no-login session for root user:

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"azureuser\" rather than the user \"root\".';echo;sleep 10" ssh-rsa ...

I think it's functionality that is provided by Azure.

@vijay8451
Copy link

@ShimShtein thanks ..
ACK From QE ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants