Skip to content

Refactor/libvirt resource - #233

Merged
asfgit merged 36 commits into
apache:masterfrom
schubergphilis:refactor/libvirt_resource
May 13, 2015
Merged

asfgit merged 36 commits into
apache:masterfrom
schubergphilis:refactor/libvirt_resource

Conversation

@wilderrodrigues

Copy link
Copy Markdown
Contributor

This PR contains the refactor of the LibvirtComputingResource. The motivation behind this effort is to increase maintainability and testability of the code.

The LibvirtComputingResource went from 5.5k to 3.3k lines of code. The unit tests went from 300 to 5050 lines of code, covering 23.3% of the whole KVM plugin (instead of the previous 4%).

All the code extracted from the LibvirtComputingResource has 64.8% coverage.

This has already been rebased and built. I'm creating the PR now but will test it against a KVM hypervisor before it gets pushed towards the Master branch.

Cheers,
Wilder

  - Adding LibvirtStopCommandWrapper
  - LibvirtRequestWrapper
  - 1 unit tests

Refactored the RequestWrapper to make it better.
  - Changes also applied to the CitrixRequestWrapper
  - Adding LibvirtGetVmStatsCommandWrapper
  - 3 unit tests

Refactored the LibvirtConnectiobn by surrounding it with an wrapper.
  - Make it easier to cover the static/native calls
  - Added better coverage to StopCommand tests
  - Adding LibvirtGetVmDiskStatsCommandWrapper
  - 1 unit test

Added getConnection() to LibvirtConnectionWrapper
  - Adding LibvirtRebootCommandWrapper and LibVirtRebootRouterCommandWrapper
  - 2 unit tests added
  - KVM hypervisor with 10.5% coverage
  - Adding LibvirtGetHosStatsCommandWrapper
  - 1 unit test added
  - KVM hypervisor with 10.5% coverage

Tests are a bit limited on this one becuause of the current implementation. Would clean it up later in a separate branch
…ingResource

    - It's not used and if so would cause an infinite loop.
  - Adding LibvirtCheckHealthCommandWrapper and LibvirtPrepareForMigrationCommandWrapper
  - 2 unit tests added
  - KVM hypervisor plugin with 10.8% coverage
  - Adding LibvirtMigrateCommandWrapper
  - 1 unit tests added
  - KVM hypervisor plugin with 10.9% coverage
  - Adding LibvirtPingTestCommandWrapper
  - 3 unit tests added
  - KVM hypervisor plugin with 11.2% coverage
  - Adding LibvirtAttachIsoCommandWrapper, LibvirtAttachIsoCommandWrapper and LibvirtAttachIsoCommandWrapper
  - 7 unit tests added
  - KVM hypervisor plugin with 11.5% coverage
  - Adding LibvirtAttachVolumeCommandWrapper
  - 3 unit tests added
  - KVM hypervisor plugin with 11.7% coverage
  - Adding LibvirtCheckConsoleProxyLoadCommandWrapper, LibvirtConsoleProxyLoadCommandWrapper, LibvirtWatchConsoleProxyLoadCommandWrapperand CitrixConsoleProxyLoadCommandWrapper
  - 2 unit tests added
  - KVM hypervisor plugin with 12% coverage

Refactored the CommandWrapper interface in order to remove the esecuteProxyLoadScan, which is now
implemented bu subclasses.
  - Adding LibvirtGetVncPortCommandWrapper
  - 2 unit tests added
  - KVM hypervisor plugin with 12.1% coverage
  - Adding LibvirtModifySshKeysCommandWrapper
  - 1 unit test added
  - KVM hypervisor plugin with 12.3% coverage
  - Adding LibvirtCreateCommandWrapper and LibvirtMaintainCommandWrapper
  - 4 unit tests added
  - KVM hypervisor plugin with 12.7% coverage
  - Adding LibvirtDestroyCommandWrapper
  - 2 unit tests added
  - KVM hypervisor plugin with 12.9% coverage
  - Adding LibvirtPrimaryStorageDownloadCommandWrapper
  - 4 unit tests added
  - KVM hypervisor plugin with 13.3% coverage
  - Adding LibvirtDeleteStoragePoolCommandWrapper, LibvirtGetStorageStatsCommandWrapper and LibvirtUpgradeSnapshotCommandWrapper
  - 7 unit tests added
  - KVM hypervisor plugin with 13.6% coverage
  - Adding LibvirtOvsDestroyBridgeCommandWrapper, LibvirtOvsSetupBridgeCommandWrapper
  - 4 unit tests added
  - KVM hypervisor plugin with 13.9% coverage

More tests added to cover LibvirtPrepareForMigrationCommandWrapper
  - Coverage of this wrapper broght from 37% to 90.6%
  - 4 new tests added
  - Adding 7 new command wrappers
  - 10 unit tests added
  - KVM hypervisor plugin with 14.8% coverage
  - Adding 4 new command wrappers
  - 12 unit tests added
  - KVM hypervisor plugin with 15.5% coverage
  - Adding LibvirtCheckOnHostCommandWrapper and LibvirtOvsCreateTunnelCommandWrapper
  - 4 unit tests added
  - KVM hypervisor plugin with 16.2% coverage
  - Adding LibvirtCreateVolumeFromSnapshotCommandWrapper, LibvirtFenceCommandWrapper and LibvirtSecurityGroupRulesCommandWrapper
  - 6 unit tests added
  - KVM hypervisor plugin with 17.2% coverage
  - Adding LibvirtNetworkUsageCommandWrapper, LibvirtPlugNicCommandWrapper and LibvirtUnPlugNicCommandWrapper
  - 9 unit tests added
  - KVM hypervisor plugin with 18.3% coverage
  - Adding LibvirtBackupSnapshotCommandWrapper, LibvirtCreatePrivateTemplateFromVolumeCommandWrapper and LibvirtManageSnapshotCommandWrapper
  - 3 unit tests added
  - KVM hypervisor plugin with 18.3% coverage

Less tests added to those classes because the code is quite complex and way too long.
The tests added are just covering the new flow, to make sure it works fine. I will come back to those classes later.
  - Adding LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper
  - 5 unit tests added
  - KVM hypervisor plugin with 19.5% coverage
  - Gave it a better, more suggestive, name since I now added other methods to the class.
  - It makes easier to mock objects and get a better coverage of the classes
  - Adding LibvirtCopyVolumeCommandWrapper

Refactoring the LibvirtUtilitiesHelper
  - Changing method name

Did not add any test to this commit due to the refactor mentioned abot.
Will proceed and add the tests

i# Please enter the commit message for your changes. Lines starting
  - 5 unit tests added
  - KVM hypervisor plugin with 20.1% coverage
@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Please, do not merge it before I test it with a KVM hypervisor.

Cheers,
Wilder

@asfbot

asfbot commented May 6, 2015

Copy link
Copy Markdown

cloudstack-pull-requests #117 FAILURE
Looks like there's a problem with this pull request

@mlsorensen

Copy link
Copy Markdown
Contributor

Yeah, I think this is a big enough change that we should give all KVM "stakeholders" an opportunity to review and test before merge. At least the committers, but anyone who wants to participate, of course. Mike T, Wido, myself, Lucian, Andrija, just to try to get an array of use cases and storage types represented. Hopefully at least someone who uses OVS and vxlan.

@asfbot

asfbot commented May 7, 2015

Copy link
Copy Markdown

Daan Hoogland on mike.tutkowski@solidfire.com replies:
this to explicitly invite them to look.

Op do 7 mei 2015 om 00:57 schreef mlsorensen git@git.apache.org:

@asfbot

asfbot commented May 7, 2015

Copy link
Copy Markdown

Nux! on daan.hoogland@gmail.com replies:
Yes, big changes indeed, I'll definitely want to test.
Thanks Wilder!

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Thanks, guys.

Would be really nice to test it ASAP so we avoid another rebase.

Most of the changes are purely structural, I tried my best to keep the behaviour as it is. If you look at the wrappers, they have the same content that the methods had when inside the LibvirtComputingResource. Are there changes in the behaviour? Yes, a few. For example, in few methods we had try/catch blocks with e.printStackTrace() and after that still returning true (as a successful operation). There were also methods returning always true and that return was being ignored. Those kind of things I changed.

Right now I'm busy getting my KVM environment test up and running. I will test the changes with OVS and VLAN and send a report to the list. My plan is to do it today/tomorrow

After the code reaches master, I will change the flyweight implementation in order to use the Annotations (suggested by @mlsorensen) and also increase UT coverage.

If you would have time to test it this week it would be very appreciated.

Cheers,
Wilder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

li_n_bvirt - typo?

@K0zka

K0zka commented May 7, 2015

Copy link
Copy Markdown
Contributor

looks nice 👍

@yadvr

yadvr commented May 7, 2015

Copy link
Copy Markdown
Member

Looks good, I guess Travis is sort of green (with on failing test due to timeout). I will help test it tonight or tomorrow.

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Thanks, @bhaisaab and @K0zka :)

Yep, "linbvirt" is a typo. :( When I apply the annotations (after the merge) I will rename it. :)

Cheers,
Wilder

…lass

  - The test was okay, but when running in an environment where a /root/.ssh/id_rsa existed, it would return true then fail
  - We now mock the calls to methods that return the key paths, instead of relying in the static variables
@asfbot

asfbot commented May 8, 2015

Copy link
Copy Markdown

cloudstack-pull-requests #124 UNSTABLE
Looks like there's a problem with this pull request

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Hi @mlsorensen @bhaisaab

Did you guys have time to test this PR?

My KVM environment is up and running and I just started testing. I will send a report soon.

Cheers,
Wilder

@asfbot

asfbot commented May 11, 2015

Copy link
Copy Markdown

Marcus on dev@cloudstack.apache.org replies:
Unfortunately, no. It seems the upgrade from 4.5 to this branch in my dev
environment has left the management server unstartable, presumably due to
systemd changes. I now have a broken link in
/etc/rc5.d/S80cloudstack-management, and systemd complaining:

Process /usr/sbin/cloudstack-management could not be executed

with no /usr/sbin/cloudstack-management to be found

Unrelated issues, I know, but I'll work through them.

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Okay.... but thanks a lot for start looking into it, @mlsorensen.

My env was a bit bumpy today and I did no manage to do all I had planned for, but I'm moving on with the tests just to identify performance improvements for our current test environment. It's taking about 10min to start a VM... so, running a test list test_accounts.py takes a very long time.

I will keep you up to date.

Cheers,
Wilder

@mlsorensen

Copy link
Copy Markdown
Contributor

Yeah, I got past tomcat and other systemd switchover issues on > 4.5 code, but then ran into other issues. The mgmt server configs got all messed up by the new RPMs. I got the server xml worked out but it couldn't connect to the db, 'access denied for cloud@localhost'. It doesn't seem to even be reading my db.properties. Mainly master teething issues around upgrade, I presume, but I've spent too much time on it today. I'll try a fresh install later.

One thing in particular I'd like to see tested is live migration. If I don't manage to test this please do at least this one.

@serverchief

Copy link
Copy Markdown
Contributor

@mlsorensen
"I got the server xml worked out but it couldn't connect to the db, 'access denied for cloud@localhost'"

I've seen this before as well when testing 4.5 upgrades. I'd check permissions on files cloudstack touches, for me it was permission related and it was not reading db.properties file like you mentioned.

@yadvr

yadvr commented May 12, 2015

Copy link
Copy Markdown
Member

@wilderrodrigues any update on this PR, if it's well tested, let's merge it?

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

@bhaisaab

I'm testing since yesterday. My KVM environment is a bit slow, but all the tests are going okay.

Please check the partial report below (last just wait a couple of hours then merge it):

Hi all,

I took some time to run integration/smoke tests on the LibVirt refactor I finished last week. All the test went well, as detailed in the report below.

More information about my environment and what was covered.

Environment:

Centos7 + KVM + Qemu
MySQL/MariaDB 5.5.41
Management Server running CentOS 7
Component/Smoke tests: https://github.com/apache/cloudstack (test/integration/component and smoke)
Storage type: NFS shared
Isolation method: VLAN

Test Create Account and user for that account ... === TestName: test_01_create_account | Status : SUCCESS ===
ok
Test Sub domain allowed to launch VM when a Domain ... === TestName: test_01_add_vm_to_subdomain | Status : SUCCESS ===
ok
Test delete domain without force option ... === TestName: test_DeleteDomain | Status : SUCCESS ===
ok
Test delete domain with force option ... === TestName: test_forceDeleteDomain | Status : SUCCESS ===
ok
Test to verify Non Root admin previleges ... === TestName: test_01_non_root_admin_Privileges | Status : SUCCESS ===
ok
Test Remove one user from the account ... === TestName: test_01_user_remove_VM_running | Status : SUCCESS ===
ok
Test to verify service offerings at same level in hierarchy ... === TestName: test_01_service_offering_hierarchy | Status : SUCCESS ===
ok
Test to verify service offerings at same level in hierarchy ... === TestName: test_01_service_offering_siblings | Status : SUCCESS ===
ok
Test to verify template at same level in hierarchy ... === TestName: test_01_template_hierarchy | Status : SUCCESS ===
ok
Test update admin details ... === TestName: test_updateAdminDetails | Status : SUCCESS ===
ok
Test update domain admin details ... === TestName: test_updateDomainAdminDetails | Status : SUCCESS ===
ok
Test user update API ... === TestName: test_updateUserDetails | Status : SUCCESS ===
ok
Test login API with domain ... === TestName: test_LoginApiDomain | Status : SUCCESS ===
ok
Test if Login API does not return UUID's ... === TestName: test_LoginApiUuidResponse | Status : SUCCESS ===
ok


Ran 14 tests in 7517.316s

OK
/tmp//MarvinLogs/test_accounts_RWB0RK/results.txt

Test advanced zone virtual router ... === TestName: test_advZoneVirtualRouter | Status : SUCCESS ===
ok
Test Deploy Virtual Machine ... === TestName: test_deploy_vm | Status : SUCCESS ===
ok
Test Multiple Deploy Virtual Machine ... === TestName: test_deploy_vm_multiple | Status : SUCCESS ===
ok
Test Stop Virtual Machine ... === TestName: test_01_stop_vm | Status : SUCCESS ===
ok
Test Start Virtual Machine ... === TestName: test_02_start_vm | Status : SUCCESS ===
ok
Test Reboot Virtual Machine ... === TestName: test_03_reboot_vm | Status : SUCCESS ===
ok
Test destroy Virtual Machine ... === TestName: test_06_destroy_vm | Status : SUCCESS ===
ok
Test recover Virtual Machine ... === TestName: test_07_restore_vm | Status : SUCCESS ===
ok
Test migrate VM ... SKIP: At least two hosts should be present in the zone for migration
Test destroy(expunge) Virtual Machine ... === TestName: test_09_expunge_vm | Status : SUCCESS ===
ok


Ran 10 tests in 2936.289s

OK (SKIP=1)
/tmp//MarvinLogs/test_vm_life_cycle_F2MIF6/results.txt

====Trying SSH Connection: Host:192.168.22.21 User:root Port:22 RetryCnt:60===
===SSH to Host 192.168.22.21 port : 22 SUCCESSFUL===
{Cmd: ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no -oUserKnownHostsFile=/dev/null -p 3922 169.254.2.152 service dnsmasq status via Host: 192.168.22.21} {returns: [u'Checking DNS forwarder and DHCP server: dnsmasq(running).']}
====Trying SSH Connection: Host:192.168.22.21 User:root Port:22 RetryCnt:60===
====Trying SSH Connection: Host:192.168.22.21 User:root Port:22 RetryCnt:60===
===SSH to Host 192.168.22.21 port : 22 SUCCESSFUL===
===SSH to Host 192.168.22.21 port : 22 SUCCESSFUL===
{Cmd: ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no -oUserKnownHostsFile=/dev/null -p 3922 169.254.2.152 service haproxy status via Host: 192.168.22.21} {returns: [u'haproxy is running.']}
{Cmd: ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no -oUserKnownHostsFile=/dev/null -p 3922 169.254.2.152 service haproxy status via Host: 192.168.22.21} {returns: [u'haproxy is running.']}

Test router internal advanced zone ... === TestName: test_02_router_internal_adv | Status : SUCCESS ===
ok
Test restart network ... === TestName: test_03_restart_network_cleanup | Status : SUCCESS ===
ok
Test router basic setup ... === TestName: test_05_router_basic | Status : SUCCESS ===
ok
Test router advanced setup ... === TestName: test_06_router_advanced | Status : SUCCESS ===
ok
Test stop router ... === TestName: test_07_stop_router | Status : SUCCESS ===
ok
Test start router ... === TestName: test_08_start_router | Status : SUCCESS ===
ok
Test reboot router ... === TestName: test_09_reboot_router | Status : SUCCESS ===
ok


Ran 7 tests in 1995.909s

OK
/tmp//MarvinLogs/test_routers_QV22YU/results.txt

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

@bhaisaab @mlsorensen

I just sent the test report to your emails.

I'm fully confident with the changes and would like to suggest a merge of the PR.

Thanks in advance.

Cheers,
Wilder

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Hi @bhaisaab ,

Is that okay if I merge the PR? It's been here for 7 days and has been tested.

Cheers,
Wilder

@yadvr

yadvr commented May 13, 2015

Copy link
Copy Markdown
Member

@wilderrodrigues thanks for sharing the test reports, while I've not personally tested. Looks good, please go ahead.

@asfgit
asfgit merged commit f575206 into apache:master May 13, 2015
@karuturi

Copy link
Copy Markdown
Member

@wilderrodrigues build-master-jdk18 is failing in jenkins. http://jenkins.buildacloud.org/job/build-master-jdk18/38/
It fails on the below test
com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.testGetHostStatsCommand

@kishankavala

Copy link
Copy Markdown
Contributor

Test set: com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest

Tests run: 143, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.744 sec <<< FAILURE! - in com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest
testGetHostStatsCommand(com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest) Time elapsed: 0.185 sec <<< ERROR!
java.lang.Exception: Unexpected exception, expected<java.lang.NumberFormatException> but was<java.lang.NullPointerException>
at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetHostStatsCommandWrapper.execute(LibvirtGetHostStatsCommandWrapper.java:77)
at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetHostStatsCommandWrapper.execute(LibvirtGetHostStatsCommandWrapper.java:34)
at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper.execute(LibvirtRequestWrapper.java:182)
at com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.testGetHostStatsCommand(LibvirtComputingResourceTest.java:930)

@kishankavala

Copy link
Copy Markdown
Contributor

@wilderrodrigues Sorry, I could not test the PR earlier. I see the following issues while trying to bring up my KVM setup:

  1. LibvirtUtilitiesHelper NPE. This could be due to spring configuration. LibvirtUtilitiesHelper ws not injected.

2015-05-14 00:00:05,362 DEBUG kvm.resource.LibvirtComputingResource Execption while executing command com.cloud.agent.api.StartCommand
java.lang.NullPointerException
at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtStartCommandWrapper.execute(LibvirtStartCommandWrapper.java:72)
at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtStartCommandWrapper.execute(LibvirtStartCommandWrapper.java:45)
at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper.execute(LibvirtRequestWrapper.java:182)
at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.executeRequest(LibvirtComputingResource.java:1251)
at com.cloud.agent.Agent.processRequest(Agent.java:503)
at com.cloud.agent.Agent$AgentRequestHandler.doTask(Agent.java:808)
at com.cloud.utils.nio.Task.run(Task.java:84)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

  1. executeRequest in LibvirtComputingResource is not logging any exception. It return Unsupported command answer. This makes it difficult to debug exceptions thrown during command execution,

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Hi @kishankavala,

I will have a look at that, although that's pretty weird since I have tested on a KVM environment as well. Don't see why the bean would have been injected for me and not for you.

Have you done a full clean/install of the latest source?

Cheers,
Wilder

@wilderrodrigues

Copy link
Copy Markdown
Contributor Author

Hi @karuturi,

I had a look and it has more to do with the hard coded paths in the code (which were already present) and the setup of the machine where the Java8 builds run.

Good it failed, because that code has never been tested before.

I will make the test better and push a fix asap.

Thanks for the heads up.

Cheers,
Wilder

yadvr pushed a commit that referenced this pull request Jan 20, 2021
Fixes #245
Fixes #233

In info card, routing should be done based on user role. User accounts should not be routed to the domain, zone info. And domain admin accounts should not be routed to zone info.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
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.

9 participants