Repository: ManageIQ/integration_tests

Issue:
Unable to set and unset ownership for Cloud instances
https://paste.fedoraproject.org/paste/3TABZclj2Buyh8p5kHH2wg

This issue happens with Cloud instances only and not infra VMs.


Discussion:
@nachandr the linked paste has been removed it looks like.

This should at least be partially addressed in the framework in #4872, which I will be trying to get updated and merged in this sprint (Cowbell).
@nachandr I'm unable to reproduce any failures with cloud.instance 'SetOwnership' navigation or form filling in the framework.

Can you comment on what the original failure was, or was that fedoraproject pastebin the only record?

I'm going to close this issue without any fixes if I don't hear back from you by Aug 22nd
```
2017-08-18 00:09:22,406 [E] @pytest.yield_fixture(scope="module")
    def vm_ownership(clean_setup_provider, provider):
        # In these tests, chargeback reports are filtered on VM owner.So,VMs have to be
        # assigned ownership.
        vm_name = provider.data['cap_and_util']['chargeback_vm']

        if not provider.mgmt.does_vm_exist(vm_name):
            pytest.skip("Skipping test, cu-24x7 VM does not exist")
        if not provider.mgmt.is_vm_running(vm_name):
            provider.mgmt.start_vm(vm_name)
            provider.mgmt.wait_vm_running(vm_name)

        cb_group = ac.Group(description='EvmGroup-user')
        user = ac.User(name=provider.name + fauxfactory.gen_alphanumeric(),
            credential=new_credential(),
            email='abc@example.com',
            group=cb_group,
            cost_center='Workload',
            value_assign='Database')

        vm = VM.factory(vm_name, provider)

        try:
            user.create()
>           vm.set_ownership(user=user.name)

cfme/tests/intelligence/reports/test_validate_chargeback_report.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def set_ownership(self, user=None, group=None, click_cancel=False, click_reset=False):
        """Set ownership of the VM/Instance or Template/Image"""
>       sel.click(self.find_quadicon(False, False, False, use_search=False))
E       TypeError: find_quadicon() takes exactly 1 argument (5 given)

cfme/common/vm.py:481: TypeError (fixtures/log.py:70)
2017-08-18 00:09:23,472 [I] (rest-api) [RESTAPI] GET https://10.8.197.179/api/providers {} (/home/nachandr/virtualenv/lib/python2.7/site-packages/manageiq_client/api.py:84)
```
@nachandr provided the log snippet above, thanks!

The common method is still using find_quadicon and isn't handling the difference between web_ui infra.vm's and widgetastic cloud.instances
May wait until #5113 is complete to address this update in `cfme/common/vm.py`, if its not already addressed there.

Resolving patch:
diff --git a/cfme/cloud/instance/__init__.py b/cfme/cloud/instance/__init__.py
--- a/cfme/cloud/instance/__init__.py
+++ b/cfme/cloud/instance/__init__.py
@@ -423,6 +423,65 @@ def power_control_from_cfme(self, *args, **kwargs):
         view.toolbar.power.item_select(kwargs.get('option'),
                                        handle_alert=not kwargs.get('cancel', False))
 
+    def set_ownership(self, user=None, group=None, click_cancel=False, click_reset=False):
+        """Set instance ownership
+
+        TODO: collapse this back to common.vm after both subclasses converted to widgetastic
+        Args:
+            user (str): username for ownership
+            group (str): groupname for ownership
+            click_cancel (bool): Whether to cancel form submission
+            click_reset (bool): Whether to reset form after filling
+        """
+        view = navigate_to(self, 'SetOwnership')
+        fill_result = view.form.fill({
+            'user_name': user,
+            'group_name': group})
+        if not fill_result:
+            view.flash.assert_no_error()
+            view.form.cancel_button.click()
+            view = self.create_view(InstanceDetailsView)
+            view.flash.assert_success_message('Set Ownership was cancelled by the user')
+            view.flash.assert_no_error()
+            return
+
+        # Only if form changed
+        if click_reset:
+            view.form.reset_button.click()
+            view.flash.assert_message('All changes have been reset', 'warning')
+            # Cancel after reset
+            assert view.form.is_displayed
+            view.form.cancel_button.click()
+        elif click_cancel:
+            view.form.cancel_button.click()
+            view.flash.assert_success_message('Set Ownership was cancelled by the user')
+            view.flash.assert_no_error()
+        else:
+            # save the form
+            view.form.save_button.click()
+            view = self.create_view(InstanceDetailsView)
+            view.flash.assert_success_message('Ownership saved for selected {}'
+                                              .format(self.VM_TYPE))
+            view.flash.assert_no_error()
+
+    def unset_ownership(self):
+        """Remove user ownership and return group to EvmGroup-Administrator"""
+        view = navigate_to(self, 'SetOwnership')
+        fill_result = view.form.fill({
+            'user_name': '<No Owner>', 'group_name': 'EvmGroup-administrator'
+        })
+        if fill_result:
+            view.form.save_button.click()
+            msg = 'Ownership saved for selected {}'.format(self.VM_TYPE)
+        else:
+            view.form.cancel_button.click()
+            logger.warning('No change during unset_ownership')
+            msg = 'Set Ownership was cancelled by the user'
+
+        view = self.create_view(InstanceDetailsView)
+        view.flash.assert_no_error()
+        view.flash.assert_success_message(msg)
+
 
 @navigator.register(Instance, 'All')
 class All(CFMENavigateStep):


Test patch: