def test_get_helper(self):
     client = dict()
     k8svirt_obj = helper.get_helper(client, 'virtual_machine_instance')
     assert isinstance(k8svirt_obj, helper.VirtualMachineInstanceHelper)
     k8svirt_obj = helper.get_helper(client, 'virtual_machine')
     assert isinstance(k8svirt_obj, helper.VirtualMachineHelper)
     k8svirt_obj = helper.get_helper(
         client, 'virtual_machine_instance_replica_set')
     assert isinstance(
         k8svirt_obj, helper.VirtualMachineInstanceReplicaSetHelper)
     k8svirt_obj = helper.get_helper(
         client, 'virtual_machine_instance_preset')
     assert isinstance(
         k8svirt_obj, helper.VirtualMachineInstancePreSetHelper)
    def execute_module(self):
        """ Method for handling module's actions """
        if not self.api_version:
            self.fail_json(
                msg=("Error: missing api_version. Use the api_version ",
                     "parameter of specify it as part of a ",
                     "resource_definition."))
        elif not self.kind:
            self.fail_json(
                msg=("Error: missing kind. Use the kind parameter ",
                     "or specify it as part of a resource_definition."))
        else:
            self.api_version = str(self.api_version).lower()
            self.kind = to_snake(self.kind)
            state = self.params.get('state')
            self._api_client = self.authenticate()
            self._helper = get_helper(self._api_client, self.kind)
            existing = self.__get_object()

            if state == 'present':
                if existing and self.params.get('force'):
                    meta = self.__replace()
                    self.exit_json(changed=True, result=dict(meta.to_dict()))
                elif existing:
                    self.exit_json(changed=False, result=dict())
                else:
                    meta = self.__create()
                    self.exit_json(changed=True, result=dict(meta.to_dict()))
            elif state == 'absent':
                if existing:
                    self.__delete()
                    self.exit_json(changed=True, result=dict())
                else:
                    self.exit_json(changed=False, result=dict())
 def execute_module(self):
     """ Gather the actual facts """
     self._api_client = self.authenticate()
     kind = to_snake(self.params.get('kind'))
     res_helper = get_helper(self._api_client, kind)
     try:
         self._kubevirt_obj = res_helper.list(
             namespace=self.params.get('namespace'),
             name=self.params.get('name'),
             field_selectors=self.params['field_selectors'],
             label_selectors=self.params['label_selectors'])
         self._kubevirt_obj = copy.deepcopy(self.__resource_cleanup())
         return self._kubevirt_obj
     except ApiException as exc:
         self.fail_json(msg='Failed to retrieve requested object',
                        error=str(exc))
 def test_get_helper_raise_exception(self):
     with pytest.raises(Exception) as excinfo:
         helper.get_helper({}, 'non_existent_resource')
     assert 'Unknown kind non_existent_resource' in str(excinfo.value)